diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5880279d8e..361ff20c1b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,6 +18,10 @@ jobs: analyze: name: Analyze runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write strategy: fail-fast: false @@ -30,22 +34,21 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main - - - name: Set up JDK 8 - uses: actions/setup-java@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v4 with: - java-version: 8 + java-version: '17' distribution: 'temurin' cache: maven @@ -57,4 +60,4 @@ jobs: mvn -B package --file pom.xml -Dmaven.test.skip=true - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c6b7e0ba7f..769307d1f5 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,16 +16,16 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Check w/o SNAPSHOT when "bump version" if: ${{ contains(github.event.head_commit.message, 'bump version') }} run: grep "" pom.xml | head -1 | grep -v SNAPSHOT - - name: Set up JDK 8 - uses: actions/setup-java@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v4 with: - java-version: '8' + java-version: '17' distribution: 'temurin' cache: maven diff --git a/README.md b/README.md index d14cb2cac4..05af1cc5fb 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ [![Release](https://jitpack.io/v/umjammer/vavi-nio-file-jnode.svg)](https://jitpack.io/#umjammer/vavi-nio-file-jnode) [![Java CI](https://github.com/umjammer/vavi-nio-file-jnode/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-nio-file-jnode/actions/workflows/maven.yml) [![CodeQL](https://github.com/umjammer/vavi-nio-file-jnode/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/vavi-nio-file-jnode/actions/workflows/codeql-analysis.yml) -![Java](https://img.shields.io/badge/Java-8-b07219) +![Java](https://img.shields.io/badge/Java-17-b07219) [![Parent](https://img.shields.io/badge/Parent-vavi--apps--fuse-pink)](https://github.com/umjammer/vavi-apps-fuse) # vavi-nio-file-jnode A Java NIO FileSystem implementation based on [jnode](https://github.com/jnode/jnode). -## Status +all formats are mounted by fuse also! + +### Status | fs | list | upload | download | copy | move | rm | mkdir | cache | watch | comment | |------------------------------|------|--------|----------|------|------|-----|-------|-------|-------|-------------------------------------------------------| @@ -34,7 +36,21 @@ A Java NIO FileSystem implementation based on [jnode](https://github.com/jnode/j | vdisk (d88:pc98:n88) | 🚧 | | | | | | | | | not solid image is not supported by DeviceAPI | | vdisk (fdi:pc98:fat12) | ✅ | | | | | | | | | [virtual disk](vavi-nio-file-emu), partition | -## for emulator user +## Install + + * [maven](https://jitpack.io/#umjammer/vavi-nio-file-jnode) + +## Usage + +### JSR-203 & fuse + +```java + URI uri = URI.create("jnode:file:/foo/bar.nhd"); + fs = FileSystems.newFileSystem(uri, Collections.emptyList()); + Fuse fuse = Fuse.getFuse().mount(fs, MOUNT_POINT, Collections.emptyList()); +``` + +### for emulator user it's possible to mount old school japanese computer pc-9801's virtual disk by fuse. @@ -42,7 +58,11 @@ we can see nostalgic files `autoexec.bat`, `command.com`, `mifes...` etc. time stamps are so old lol. -![](https://lh3.googleusercontent.com/pw/AM-JKLVzJc46TaLOLtacSQdNJF-11XE6gw1eBN-57aIazw22VK1HHsPIoXNO3cVjHWnnEq36bjJxFBiRP3ipe57fXTfpITi8-FybMbTvpHXR-X2ZzQ2MI-HirwnI1PCyhpL6pUb8SDbCRBOyzr_sHRUKMxZB=w1024-h981-no?authuser=0) +mount nhd + +## References + + * [vavi-nio-file-emu](https://jitpack.io/#umjammer/vavi-nio-file-emu) ... PC-98 FAT ## TODO diff --git a/core/.checkstyle b/core/.checkstyle deleted file mode 100644 index de90363149..0000000000 --- a/core/.checkstyle +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/core/pom.xml b/core/pom.xml index 7f0d3ef625..3809787cda 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ vavi vavi-nio-file-jnode - 0.2.11v + 0.2.12 jnode-core @@ -13,17 +13,8 @@ - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - UTF-8 - - - + org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M7 -Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties @@ -38,12 +29,7 @@ org.apache.ant ant - 1.10.12 - - - - org.apache.logging.log4j - log4j-api + 1.10.14 @@ -66,16 +52,5 @@ junit-platform-suite-engine test - - - org.apache.logging.log4j - log4j-core - test - - - org.apache.logging.log4j - log4j-jul - test - diff --git a/core/src/main/java/org/jnode/driver/Device.java b/core/src/main/java/org/jnode/driver/Device.java index 0550a1fa95..882c4b4609 100644 --- a/core/src/main/java/org/jnode/driver/Device.java +++ b/core/src/main/java/org/jnode/driver/Device.java @@ -89,6 +89,7 @@ public final boolean isStarted() { * @param apiInterface * @param apiImplementation */ + @SuppressWarnings({"unchecked", "rawtypes"}) public final void registerAPI(Class apiInterface, T apiImplementation) { if (!apiInterface.isInstance(apiImplementation)) { throw new IllegalArgumentException("API implementation does not implement API interface"); diff --git a/core/src/main/java/org/jnode/nanoxml/XMLElement.java b/core/src/main/java/org/jnode/nanoxml/XMLElement.java index 23731ce064..dcadcdba88 100644 --- a/core/src/main/java/org/jnode/nanoxml/XMLElement.java +++ b/core/src/main/java/org/jnode/nanoxml/XMLElement.java @@ -37,14 +37,12 @@ import java.io.Writer; import java.util.ArrayList; import java.util.Collections; -import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.Vector; /** * XMLElement is a representation of an XML object. The object is able to parse @@ -102,8 +100,7 @@ * <cyberelf@mac.com> * @version $Name$, $Revision: 1950 $ */ -public class XMLElement -{ +public class XMLElement { /** * Serialization serial version ID. @@ -191,7 +188,7 @@ public class XMLElement *
  • The values are char arrays * */ - private Hashtable entities; + private Map entities; /** * The line number where the element starts. @@ -200,19 +197,19 @@ public class XMLElement *
    • lineNr >= 0 *
    */ - private int lineNr; + private final int lineNr; /** * true if the case of the element and attribute names * are case insensitive. */ - private boolean ignoreCase; + private final boolean ignoreCase; /** * true if the leading and trailing whitespace of #PCDATA * sections have to be ignored. */ - private boolean ignoreWhitespace; + private final boolean ignoreWhitespace; /** * Character read too much. @@ -257,15 +254,15 @@ public class XMLElement *
  • getName() => null * * - * @see XMLElement#XMLElement(java.util.Hashtable) + * @see XMLElement#XMLElement(java.util.Map) * XMLElement(Hashtable) * @see XMLElement#XMLElement(boolean) - * @see XMLElement#XMLElement(java.util.Hashtable,boolean) + * @see XMLElement#XMLElement(java.util.Map,boolean) * XMLElement(Hashtable, boolean) */ public XMLElement() { - this(new Hashtable(), false, true, true); + this(new HashMap<>(), false, true, true); } /** @@ -293,10 +290,10 @@ public XMLElement() * * @see XMLElement#XMLElement() * @see XMLElement#XMLElement(boolean) - * @see XMLElement#XMLElement(java.util.Hashtable,boolean) + * @see XMLElement#XMLElement(java.util.Map,boolean) * XMLElement(Hashtable, boolean) */ - public XMLElement(Hashtable entities) + public XMLElement(Map entities) { this(entities, false, true, true); } @@ -322,14 +319,14 @@ public XMLElement(Hashtable entities) *
    * * @see XMLElement#XMLElement() - * @see XMLElement#XMLElement(java.util.Hashtable) + * @see XMLElement#XMLElement(java.util.Map) * XMLElement(Hashtable) - * @see XMLElement#XMLElement(java.util.Hashtable,boolean) + * @see XMLElement#XMLElement(java.util.Map,boolean) * XMLElement(Hashtable, boolean) */ public XMLElement(boolean skipLeadingWhitespace) { - this(new Hashtable(), skipLeadingWhitespace, true, true); + this(new HashMap<>(), skipLeadingWhitespace, true, true); } /** @@ -360,12 +357,10 @@ public XMLElement(boolean skipLeadingWhitespace) * * @see XMLElement#XMLElement() * @see XMLElement#XMLElement(boolean) - * @see XMLElement#XMLElement(java.util.Hashtable) + * @see XMLElement#XMLElement(java.util.Map) * XMLElement(Hashtable) */ - public XMLElement(Hashtable entities, - boolean skipLeadingWhitespace) - { + public XMLElement(Map entities, boolean skipLeadingWhitespace) { this(entities, skipLeadingWhitespace, true, true); } @@ -397,15 +392,14 @@ public XMLElement(Hashtable entities, * * @see XMLElement#XMLElement() * @see XMLElement#XMLElement(boolean) - * @see XMLElement#XMLElement(java.util.Hashtable) + * @see XMLElement#XMLElement(java.util.Map) * XMLElement(Hashtable) - * @see XMLElement#XMLElement(java.util.Hashtable,boolean) + * @see XMLElement#XMLElement(java.util.Map,boolean) * XMLElement(Hashtable, boolean) */ - public XMLElement(Hashtable entities, + public XMLElement(Map entities, boolean skipLeadingWhitespace, - boolean ignoreCase) - { + boolean ignoreCase) { this(entities, skipLeadingWhitespace, true, ignoreCase); } @@ -448,11 +442,10 @@ public XMLElement(Hashtable entities, * * @see XMLElement#createAnotherElement() */ - protected XMLElement(Hashtable entities, + protected XMLElement(Map entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, - boolean ignoreCase) - { + boolean ignoreCase) { this.ignoreWhitespace = skipLeadingWhitespace; this.ignoreCase = ignoreCase; this.name = null; @@ -461,9 +454,7 @@ protected XMLElement(Hashtable entities, this.children = new ArrayList<>(); this.entities = entities; this.lineNr = 0; - Enumeration e = this.entities.keys(); - while (e.hasMoreElements()) { - Object key = e.nextElement(); + for (String key : this.entities.keySet()) { Object value = this.entities.get(key); if (value instanceof String) { value = ((String) value).toCharArray(); @@ -550,9 +541,7 @@ public void addChild(XMLElement child) * String, boolean) * getStringAttribute(String, Hashtable, String, boolean) */ - public void setAttribute(String name, - Object value) - { + public void setAttribute(String name, Object value) { if (this.ignoreCase) { name = name.toUpperCase(); } @@ -569,9 +558,7 @@ public void setAttribute(String name, * * @deprecated Use {@link #setAttribute(String, Object)} instead. */ - public void addProperty(String name, - Object value) - { + public void addProperty(String name, Object value) { this.setAttribute(name, value); } @@ -1598,8 +1585,8 @@ public void parseFromReader(Reader reader, { this.name = null; this.contents = ""; - this.attributes = new Hashtable(); - this.children = new Vector(); + this.attributes = new HashMap<>(); + this.children = new ArrayList<>(); this.charReadTooMuch = '\0'; this.reader = reader; this.parserLineNr = startingLineNr; @@ -2069,7 +2056,7 @@ public void write(Writer writer) writer.write('"'); } } - if ((this.contents != null) && (this.contents.length() > 0)) { + if ((this.contents != null) && (!this.contents.isEmpty())) { writer.write('>'); this.writeEncoded(writer, this.contents); writer.write('<'); writer.write('/'); @@ -2540,7 +2527,7 @@ protected void scanElement(XMLElement elt) } } } - if (buf.length() == 0) { + if (buf.isEmpty()) { while (ch != '/') { if (ch == '!') { ch = this.readChar(); diff --git a/core/src/main/java/org/jnode/util/AccessControllerUtils.java b/core/src/main/java/org/jnode/util/AccessControllerUtils.java deleted file mode 100644 index 8de4c1c597..0000000000 --- a/core/src/main/java/org/jnode/util/AccessControllerUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2003-2015 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.util; - -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -/** - * @author Ewout Prangsma (epr@users.sourceforge.net) - */ -public class AccessControllerUtils { - - /** - * Calls AccessController.doPrivileged and unwraps any exception wrapped - * in the PrivilegedActionException. - * - * @param action a typed action - * @return an instance of the action's type. - * @throws Exception - */ - public static T doPrivileged(PrivilegedExceptionAction action) throws Exception { - try { - return AccessController.doPrivileged(action); - } catch (PrivilegedActionException ex) { - throw ex.getException(); - } - } - -} diff --git a/core/src/main/java/org/jnode/util/ByteQueueProcessorThread.java b/core/src/main/java/org/jnode/util/ByteQueueProcessorThread.java index 77eef19847..af5ce788dc 100644 --- a/core/src/main/java/org/jnode/util/ByteQueueProcessorThread.java +++ b/core/src/main/java/org/jnode/util/ByteQueueProcessorThread.java @@ -20,24 +20,27 @@ package org.jnode.util; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; + /** * @author Ewout Prangsma (epr@users.sourceforge.net) */ public class ByteQueueProcessorThread extends Thread { - private static final Logger bootlog = LogManager.getLogger("bootlog"); + private static final Logger bootlog = System.getLogger("bootlog"); /** * The queue i'm processing */ private final ByteQueue queue; + /** * The actual processor */ private final ByteQueueProcessor processor; + private boolean stop; /** @@ -76,19 +79,19 @@ public void stopProcessor() { /** * Handle an exception thrown during the processing of the object. * - * @param ex + * @param ex exception */ protected void handleException(Exception ex) { - bootlog.error("Exception in ByteQueueProcessor: " + getName(), ex); + bootlog.log(Level.ERROR, "Exception in ByteQueueProcessor: " + getName(), ex); } /** * Handle an exception thrown during the processing of the object. * - * @param ex + * @param ex exception */ protected void handleError(Error ex) { - bootlog.error("Error in ByteQueueProcessor: " + getName(), ex); + bootlog.log(Level.ERROR, "Error in ByteQueueProcessor: " + getName(), ex); } /** @@ -117,5 +120,4 @@ public void run() { public ByteQueue getQueue() { return queue; } - } diff --git a/core/src/main/java/org/jnode/util/IOUtils.java b/core/src/main/java/org/jnode/util/IOUtils.java index 511c433633..503888b548 100644 --- a/core/src/main/java/org/jnode/util/IOUtils.java +++ b/core/src/main/java/org/jnode/util/IOUtils.java @@ -29,21 +29,24 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; -import org.apache.logging.log4j.LogManager; +import static java.lang.System.getLogger; + /** * Common utility code for higher-level operations on IO streams. Notwithstanding the * nominal access for the class and its methods, user (command) code should avoid using - * this class directly. You should program against the - * {@link org.jnode.shell.io.CommandIO} API instead. + * this class directly. * * @author crawley@jnode.org */ public class IOUtils { + + private static final Logger log = getLogger(IOUtils.class.getName()); + // FIXME ... these utils (in some cases) attempt to access non-public fields // of various stream classes in order to figure out what the underlying stream // is. Currently, we have to explicitly grant the calling application permissions @@ -121,71 +124,59 @@ public static Closeable findBaseStream(Closeable stream) { } private static InputStream findInputStream(final FilterInputStream inputStream) { - PrivilegedAction pa = () -> { - try { - Class cls = FilterInputStream.class; - Field field = cls.getDeclaredField("in"); - field.setAccessible(true); - Object in = field.get(inputStream); - field.setAccessible(false); - return (InputStream) in; - } catch (Exception ex) { - LogManager.getLogger(IOUtils.class).error("Cannot extract the 'in' field", ex); - return null; - } - }; - return AccessController.doPrivileged(pa); + try { + Class cls = FilterInputStream.class; + Field field = cls.getDeclaredField("in"); + field.setAccessible(true); + Object in = field.get(inputStream); + field.setAccessible(false); + return (InputStream) in; + } catch (Exception ex) { + log.log(Level.ERROR, "Cannot extract the 'in' field", ex); + return null; + } } private static OutputStream findOutputStream(final FilterOutputStream outputStream) { - PrivilegedAction pa = () -> { - try { - Class cls = FilterOutputStream.class; - Field field = cls.getDeclaredField("out"); - field.setAccessible(true); - Object out = field.get(outputStream); - return (OutputStream) out; - } catch (Exception ex) { - LogManager.getLogger(IOUtils.class).error("Cannot extract the 'out' field", ex); - return null; - } - }; - return AccessController.doPrivileged(pa); + try { + Class cls = FilterOutputStream.class; + Field field = cls.getDeclaredField("out"); + field.setAccessible(true); + Object out = field.get(outputStream); + return (OutputStream) out; + } catch (Exception ex) { + log.log(Level.ERROR, "Cannot extract the 'out' field", ex); + return null; + } } private static OutputStream findOutputStream(final OutputStreamWriter writer) { // This implementation is based on the knowledge that an OutputStreamWriter // uses the underlying OutputStream as its 'lock' object. - PrivilegedAction pa = () -> { - try { - Class cls = Writer.class; - Field field = cls.getDeclaredField("lock"); - field.setAccessible(true); - Object lock = field.get(writer); - return (OutputStream) lock; - } catch (Exception ex) { - LogManager.getLogger(IOUtils.class).error("Cannot extract the 'lock' field", ex); - return null; - } - }; - return AccessController.doPrivileged(pa); + try { + Class cls = Writer.class; + Field field = cls.getDeclaredField("lock"); + field.setAccessible(true); + Object lock = field.get(writer); + return (OutputStream) lock; + } catch (Exception ex) { + log.log(Level.ERROR, "Cannot extract the 'lock' field", ex); + return null; + } } private static InputStream findInputStream(final InputStreamReader reader) { // This implementation is based on the knowledge that an InputStreamReader // uses the underlying InputStream as its 'lock' object. - PrivilegedAction pa = () -> { - try { - Class cls = Reader.class; - Field field = cls.getDeclaredField("lock"); - field.setAccessible(true); - Object lock = field.get(reader); - return (InputStream) lock; - } catch (Exception ex) { - LogManager.getLogger(IOUtils.class).error("Cannot extract the 'lock' field", ex); - return null; - } - }; - return AccessController.doPrivileged(pa); + try { + Class cls = Reader.class; + Field field = cls.getDeclaredField("lock"); + field.setAccessible(true); + Object lock = field.get(reader); + return (InputStream) lock; + } catch (Exception ex) { + log.log(Level.ERROR, "Cannot extract the 'lock' field", ex); + return null; + } } } diff --git a/core/src/main/java/org/jnode/util/QueueProcessorThread.java b/core/src/main/java/org/jnode/util/QueueProcessorThread.java index 1a00268192..c78f1188d9 100644 --- a/core/src/main/java/org/jnode/util/QueueProcessorThread.java +++ b/core/src/main/java/org/jnode/util/QueueProcessorThread.java @@ -20,15 +20,15 @@ package org.jnode.util; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; /** * @author epr */ public class QueueProcessorThread extends Thread { - private static final Logger bootlog = LogManager.getLogger("bootlog"); + private static final Logger bootlog = System.getLogger("bootlog"); /** * The queue i'm processing @@ -83,7 +83,7 @@ public void stopProcessor() { * @param ex */ protected void handleException(Exception ex) { - bootlog.error("Exception in QueueProcessor: " + getName(), ex); + bootlog.log(Level.ERROR, "Exception in QueueProcessor: " + getName(), ex); } /** @@ -92,7 +92,7 @@ protected void handleException(Exception ex) { * @param ex */ protected void handleError(Error ex) { - bootlog.error("Error in QueueProcessor: " + getName(), ex); + bootlog.log(Level.ERROR, "Error in QueueProcessor: " + getName(), ex); } /** diff --git a/core/src/main/java/org/jnode/util/Version.java b/core/src/main/java/org/jnode/util/Version.java index be04f22ed1..7409ce83a1 100644 --- a/core/src/main/java/org/jnode/util/Version.java +++ b/core/src/main/java/org/jnode/util/Version.java @@ -105,7 +105,7 @@ public Version(String version) { revision = (parts.length > 3) ? Integer.parseInt(parts[3]) : Undefined; tag = (outerParts.length > 1) ? outerParts[1] : null; if (tag != null) { - if (tag.length() == 0) + if (tag.isEmpty()) throw new IllegalArgumentException("tag empty"); if (Character.isDigit(tag.charAt(0))) throw new IllegalArgumentException("tag starts with digit"); diff --git a/fs/.checkstyle b/fs/.checkstyle deleted file mode 100644 index b889bd04b2..0000000000 --- a/fs/.checkstyle +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/fs/pom.xml b/fs/pom.xml index ee014786a5..f5091b8914 100644 --- a/fs/pom.xml +++ b/fs/pom.xml @@ -5,7 +5,7 @@ vavi vavi-nio-file-jnode - 0.2.11v + 0.2.12 jnode-fs @@ -18,23 +18,13 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - 1.8 - 1.8 - UTF-8 - - org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M7 -Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties + -Dvavi.util.logging.VaviFormatter.extraClassMethod=vavi\.emu\.disk\.Disk\$1#log false @@ -57,24 +47,24 @@ vavi jnode-core - 0.2.11v + 0.2.12 vavi jnode-net - 0.2.11v + 0.2.12 com.github.umjammer - java7-fs-base - 0.0.13v + vavi-nio-file-base + 0.0.14v vavi vavi-nio-file-emu - 2.0.3 + 2.0.4 com.github.umjammer @@ -86,7 +76,7 @@ eu.agno3.jcifs jcifs-ng - 2.1.8 + 2.1.10 com.enterprisedt @@ -94,11 +84,6 @@ 1.5.3 - - org.apache.logging.log4j - log4j-api - - org.junit.jupiter junit-jupiter-api @@ -133,16 +118,5 @@ test-jar test - - - org.apache.logging.log4j - log4j-core - test - - - org.apache.logging.log4j - log4j-jul - test - diff --git a/fs/src/main/java/org/jnode/driver/block/FileDevice.java b/fs/src/main/java/org/jnode/driver/block/FileDevice.java index 08aa39dce8..ca7d275c8b 100644 --- a/fs/src/main/java/org/jnode/driver/block/FileDevice.java +++ b/fs/src/main/java/org/jnode/driver/block/FileDevice.java @@ -24,17 +24,14 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteBuffer; -import java.util.logging.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jnode.driver.Device; import org.jnode.partitions.PartitionTableEntry; import org.jnode.util.ByteBufferUtils; -import vavi.util.Debug; - /** * This class is a device wrapping a simple file * @@ -42,7 +39,7 @@ */ public class FileDevice extends Device implements FSBlockDeviceAPI { - private static final Logger logger = LogManager.getLogger(FileDevice.class); + private static final Logger log = System.getLogger(FileDevice.class.getName()); private RandomAccessFile raf; @@ -55,7 +52,7 @@ public class FileDevice extends Device implements FSBlockDeviceAPI { */ public void addOffset(long offset) { this.offset += offset; -Debug.printf(Level.FINE, "offset: %08x + %08x -> %08x", (this.offset - offset), offset, this.offset); +log.log(Level.DEBUG, String.format("offset: %08x + %08x -> %08x", (this.offset - offset), offset, this.offset)); } /** @@ -93,7 +90,7 @@ public long getLength() throws IOException { @Override public void read(long devOffset, ByteBuffer destBuf) throws IOException { raf.seek(devOffset + offset); -logger.debug(String.format("offset: %08x (%08x)", devOffset + offset, offset)); +log.log(Level.DEBUG, String.format("offset: %08x (%08x)", devOffset + offset, offset)); //TODO optimize it also to use ByteBuffer at lower level ByteBufferUtils.ByteArray destBA = ByteBufferUtils.toByteArray(destBuf); @@ -104,7 +101,7 @@ public void read(long devOffset, ByteBuffer destBuf) throws IOException { @Override public void write(long devOffset, ByteBuffer srcBuf) throws IOException { - //log.debug("fd.write devOffset=" + devOffset + ", length=" + length); + //log.log(Level.DEBUG, "fd.write devOffset=" + devOffset + ", length=" + length); raf.seek(devOffset + offset); //TODO optimize it also to use ByteBuffer at lower level @@ -124,11 +121,11 @@ public void flush() { */ public void setLength(long length) throws IOException { if (offset > 0) { - logger.warn("this device has virtual offset (" + offset + "), so length you sepcified might be different as your expectation."); + log.log(Level.WARNING, "this device has virtual offset (" + offset + "), so length you sepcified might be different as your expectation."); } raf.setLength(length); if (offset > 0) { - logger.warn("now real file length is " + length + ", virtual offset is " + offset); + log.log(Level.WARNING, "now real file length is " + length + ", virtual offset is " + offset); } } diff --git a/fs/src/main/java/org/jnode/driver/block/VirtualDiskDevice.java b/fs/src/main/java/org/jnode/driver/block/VirtualDiskDevice.java index facba17fcd..9d5c722409 100644 --- a/fs/src/main/java/org/jnode/driver/block/VirtualDiskDevice.java +++ b/fs/src/main/java/org/jnode/driver/block/VirtualDiskDevice.java @@ -25,7 +25,7 @@ */ public class VirtualDiskDevice extends Device implements FSBlockDeviceAPI { -// private static final Logger logger = LogManager.getLogger(VirtualDiskDevice.class); +// private static final Logger logger = System.getLogger(VirtualDiskDevice.class.getName()); /** for partition entry */ private long offset = 0; diff --git a/fs/src/main/java/org/jnode/fs/exfat/EntryTimes.java b/fs/src/main/java/org/jnode/fs/exfat/EntryTimes.java index 46817921a7..581223c520 100644 --- a/fs/src/main/java/org/jnode/fs/exfat/EntryTimes.java +++ b/fs/src/main/java/org/jnode/fs/exfat/EntryTimes.java @@ -22,18 +22,24 @@ package org.jnode.fs.exfat; import java.io.IOException; +import java.lang.System.Logger; import java.nio.ByteBuffer; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; -import org.apache.logging.log4j.LogManager; +import java.lang.System.Logger.Level; + +import static java.lang.System.getLogger; + /** * @author Matthias Treydte <waldheinz at gmail.com> */ final class EntryTimes { + private static final Logger log = getLogger(EntryTimes.class.getName()); + public static EntryTimes read(ByteBuffer src) throws IOException { /* read create date/time */ @@ -116,7 +122,7 @@ private static Date exfatToUnix(int date, int time, int cs, int tzOffset) { return cal.getTime(); } catch (Exception e) { - LogManager.getLogger(EntryTimes.class).error("Error getting entry times", e); + log.log(Level.ERROR, "Error getting entry times", e); return null; } } diff --git a/fs/src/main/java/org/jnode/fs/exfat/ExFatSuperBlock.java b/fs/src/main/java/org/jnode/fs/exfat/ExFatSuperBlock.java index 913c296a6f..c781614975 100644 --- a/fs/src/main/java/org/jnode/fs/exfat/ExFatSuperBlock.java +++ b/fs/src/main/java/org/jnode/fs/exfat/ExFatSuperBlock.java @@ -66,7 +66,7 @@ public static ExFatSuperBlock read(ExFatFileSystem fs) throws IOException { b.order(ByteOrder.LITTLE_ENDIAN); fs.getApi().read(0, b); - /* check OEM name */ + // check OEM name final byte[] oemBytes = new byte[OEM_NAME.length()]; b.position(0x03); @@ -77,19 +77,19 @@ public static ExFatSuperBlock read(ExFatFileSystem fs) throws IOException { throw new IOException("OEM name mismatch"); } - /* check fat count */ + // check fat count if ((b.get(0x6e) & 0xff) != 1) { throw new IOException("invalid FAT count"); } - /* check drive # */ + // check drive # if ((b.get(0x6f) & 0xff) != 0x80) { throw new IOException("invalid drive number"); } - /* check boot signature */ + // check boot signature if ((b.get(510) & 0xff) != 0x55 || (b.get(511) & 0xff) != 0xaa) throw new IOException("missing boot sector signature"); @@ -111,7 +111,7 @@ public static ExFatSuperBlock read(ExFatFileSystem fs) throws IOException { result.blocksPerClusterBits = b.get(0x6d); result.percentInUse = b.get(0x70); - /* check version */ + // check version if (result.fsVersionMajor != 1) { throw new IOException("unsupported version major " + @@ -225,5 +225,4 @@ public int getBytesPerCluster() { public byte getPercentInUse() { return percentInUse; } - } diff --git a/fs/src/main/java/org/jnode/fs/ext2/Ext2Directory.java b/fs/src/main/java/org/jnode/fs/ext2/Ext2Directory.java index 9ea44e1e25..8a3617e8fc 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/Ext2Directory.java +++ b/fs/src/main/java/org/jnode/fs/ext2/Ext2Directory.java @@ -26,8 +26,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSDirectoryId; import org.jnode.fs.FSEntry; import org.jnode.fs.FileSystemException; @@ -42,12 +42,12 @@ */ public class Ext2Directory extends AbstractFSDirectory implements FSDirectoryId { + private static final Logger log = System.getLogger(Ext2Entry.class.getName()); + protected INode iNode; protected Ext2Entry entry; - private final Logger log = LogManager.getLogger(getClass()); - /** * @param entry the Ext2Entry representing this directory */ @@ -63,17 +63,17 @@ public Ext2Directory(Ext2Entry entry) throws IOException { readOnly = true; //force readonly if ((iNode.getFlags() & Ext2Constants.EXT4_INODE_EXTENTS_FLAG) != 0) - log.debug("inode uses extents: " + entry); + log.log(Level.DEBUG, "inode uses extents: " + entry); if ((iNode.getFlags() & Ext2Constants.EXT4_HUGE_FILE_FL) != 0) - log.info("inode is for a huge-file: " + entry); + log.log(Level.INFO, "inode is for a huge-file: " + entry); if ((iNode.getFlags() & Ext2Constants.EXT2_INDEX_FL) != 0) - log.info("inode uses index: " + entry); + log.log(Level.INFO, "inode uses index: " + entry); } else { readOnly = fs.isReadOnly(); } setRights(true, !readOnly); - log.debug("directory size: " + iNode.getSize()); + log.log(Level.DEBUG, "directory size: " + iNode.getSize()); } /** @@ -248,9 +248,9 @@ private void addDirectoryRecord(Ext2DirectoryRecord dr) throws IOException, File //directoryRecords may not extend over block boundaries: //see if the new record fits in the same block after truncating the last record long remainingLength = fs.getBlockSize() - (lastPos % fs.getBlockSize()) - rec.getRecLen(); - log.debug("LAST-1 record: begins at: " + lastPos + ", length: " + lastLen); - log.debug("LAST-1 truncated length: " + rec.getRecLen()); - log.debug("Remaining length: " + remainingLength); + log.log(Level.DEBUG, "LAST-1 record: begins at: " + lastPos + ", length: " + lastLen); + log.log(Level.DEBUG, "LAST-1 truncated length: " + rec.getRecLen()); + log.log(Level.DEBUG, "Remaining length: " + remainingLength); if (remainingLength >= dr.getRecLen()) { //write back the last record truncated //TODO optimize it also to use ByteBuffer at lower level @@ -269,7 +269,7 @@ private void addDirectoryRecord(Ext2DirectoryRecord dr) throws IOException, File // dir.write(lastPos + rec.getRecLen(), dr.getData(), dr // .getOffset(), dr.getRecLen()); - log.debug("addDirectoryRecord(): LAST record: begins at: " + + log.log(Level.DEBUG, "addDirectoryRecord(): LAST record: begins at: " + (rec.getFileOffset() + rec.getRecLen()) + ", length: " + dr.getRecLen()); } else { //the new record must go to the next block @@ -283,7 +283,7 @@ private void addDirectoryRecord(Ext2DirectoryRecord dr) throws IOException, File dir.write(lastPos + lastLen, buf); // dir.write(lastPos + lastLen, dr.getData(), dr // .getOffset(), dr.getRecLen()); - log.debug("addDirectoryRecord(): LAST record: begins at: " + (lastPos + lastLen) + + log.log(Level.DEBUG, "addDirectoryRecord(): LAST record: begins at: " + (lastPos + lastLen) + ", length: " + dr.getRecLen()); } } else { //rec==null, ie. this is the first record in the directory @@ -292,7 +292,7 @@ private void addDirectoryRecord(Ext2DirectoryRecord dr) throws IOException, File ByteBuffer buf = ByteBuffer.wrap(dr.getData(), dr.getOffset(), dr.getRecLen()); dir.write(0, buf); //dir.write(0, dr.getData(), dr.getOffset(), dr.getRecLen()); - log.debug("addDirectoryRecord(): LAST record: begins at: 0, length: " + dr.getRecLen()); + log.log(Level.DEBUG, "addDirectoryRecord(): LAST record: begins at: 0, length: " + dr.getRecLen()); } //dir.flush(); @@ -445,7 +445,7 @@ protected FSEntryTable readEntries() throws IOException { while (it.hasNext()) { final FSEntry entry = it.next(); - log.debug("readEntries: entry=" + FSUtils.toString(entry, false)); + log.log(Level.DEBUG, "readEntries: entry=" + FSUtils.toString(entry, false)); entries.add(entry); } diff --git a/fs/src/main/java/org/jnode/fs/ext2/Ext2DirectoryRecord.java b/fs/src/main/java/org/jnode/fs/ext2/Ext2DirectoryRecord.java index 6f00fc7359..1792b4904c 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/Ext2DirectoryRecord.java +++ b/fs/src/main/java/org/jnode/fs/ext2/Ext2DirectoryRecord.java @@ -22,8 +22,8 @@ import java.util.Arrays; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FileSystemException; import org.jnode.util.LittleEndian; @@ -34,7 +34,9 @@ * @author Andras Nagy */ public class Ext2DirectoryRecord { - private final Logger log = LogManager.getLogger(getClass()); + + private static final Logger log = System.getLogger(Ext2DirectoryRecord.class.getName()); + /* * private int iNodeNr; private int recLen; private short nameLen; private * short type; private StringBuffer name; @@ -42,7 +44,7 @@ public class Ext2DirectoryRecord { private int offset; private byte[] data; private long fileOffset; - private Ext2FileSystem fs; + private final Ext2FileSystem fs; /** * @param data the data that makes up the directory block @@ -144,7 +146,7 @@ public synchronized String getName() { String name = ""; if (getINodeNr() != 0) { name = new String(data, offset + 8, getNameLen(), Ext2FileSystem.ENTRY_NAME_CHARSET); - log.debug("Ext2DirectoryRecord(): iNode=" + getINodeNr() + ", name=" + name); + log.log(Level.DEBUG, "Ext2DirectoryRecord(): iNode=" + getINodeNr() + ", name=" + name); } return name; } @@ -187,7 +189,7 @@ protected synchronized void truncateRecord() { if (newLength % 4 != 0) newLength += 4 - newLength % 4; setRecLen(newLength); - log.debug("truncateRecord(): newLength: " + newLength); + log.log(Level.DEBUG, "truncateRecord(): newLength: " + newLength); } /** @@ -201,7 +203,7 @@ protected synchronized void truncateRecord() { * filesystem block) */ protected synchronized void expandRecord(long beginning, long end) throws FileSystemException { - log.debug("expandRecord(" + beginning + ", " + end + ")"); + log.log(Level.DEBUG, "expandRecord(" + beginning + ", " + end + ")"); if (beginning + getNameLen() + 8 < end) { // the record fits in the block setRecLen((int) (end - beginning)); @@ -215,6 +217,6 @@ protected synchronized void expandRecord(long beginning, long end) throws FileSy } else { throw new FileSystemException("The directory record does not fit into the block!"); } - log.debug("expandRecord(): newLength: " + getRecLen()); + log.log(Level.DEBUG, "expandRecord(): newLength: " + getRecLen()); } } diff --git a/fs/src/main/java/org/jnode/fs/ext2/Ext2Entry.java b/fs/src/main/java/org/jnode/fs/ext2/Ext2Entry.java index d27e914faa..76e8b44894 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/Ext2Entry.java +++ b/fs/src/main/java/org/jnode/fs/ext2/Ext2Entry.java @@ -22,26 +22,29 @@ import java.io.IOException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntryLastAccessed; import org.jnode.fs.FSEntryLastChanged; import org.jnode.fs.spi.AbstractFSEntry; + /** + * In case of a directory, the data will be parsed to get the file-list + * by Ext2Directory. In case of a regular file, no more processing is + * needed. + *

    + * TODO: besides getFile() and getDirectory(), we will need + * getBlockDevice() getCharacterDevice(), etc. + *

    + * * @author Andras Nagy - *

    - * In case of a directory, the data will be parsed to get the file-list - * by Ext2Directory. In case of a regular file, no more processing is - * needed. - *

    - * TODO: besides getFile() and getDirectory(), we will need - * getBlockDevice() getCharacterDevice(), etc. */ public class Ext2Entry extends AbstractFSEntry implements FSEntryLastChanged, FSEntryLastAccessed { - private final Logger log = LogManager.getLogger(getClass()); + private static final Logger log = System.getLogger(Ext2Entry.class.getName()); + private INode iNode = null; private long directoryRecordId; private int type; @@ -53,7 +56,7 @@ public Ext2Entry(INode iNode, long directoryRecordId, String name, int type, Ext this.directoryRecordId = directoryRecordId; this.type = type; - log.debug("Ext2Entry(iNode, name): name=" + name + + log.log(Level.DEBUG, "Ext2Entry(iNode, name): name=" + name + (isDirectory() ? " is a directory " : "") + (isFile() ? " is a file " : "")); } diff --git a/fs/src/main/java/org/jnode/fs/ext2/Ext2File.java b/fs/src/main/java/org/jnode/fs/ext2/Ext2File.java index 87d9bfd596..32a76f0f2c 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/Ext2File.java +++ b/fs/src/main/java/org/jnode/fs/ext2/Ext2File.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.nio.ByteBuffer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSFileSlackSpace; import org.jnode.fs.FileSystemException; import org.jnode.fs.ReadOnlyFileSystemException; @@ -36,11 +36,11 @@ */ public class Ext2File extends AbstractFSFile implements FSFileSlackSpace { + private static final Logger log = System.getLogger(Ext2File.class.getName()); + String name; INode iNode; - private final Logger log = LogManager.getLogger(getClass()); - public Ext2File(Ext2Entry entry) { this((Ext2FileSystem) entry.getFileSystem(), entry.getINode(), entry.getName()); } @@ -53,7 +53,7 @@ public Ext2File(Ext2FileSystem fs, INode iNode, String name) { @Override public long getLength() { - // log.debug("getLength(): "+iNode.getSize()); + // log.log(Level.DEBUG, "getLength(): "+iNode.getSize()); return iNode.getSize(); } @@ -97,7 +97,7 @@ public void setLength(long length) throws IOException { else nextBlock = blockNr + 1; for (long i = iNode.getAllocatedBlockCount() - 1; i >= nextBlock; i--) { - log.debug("setLength(): freeing up block " + i + " of inode"); + log.log(Level.DEBUG, "setLength(): freeing up block " + i + " of inode"); iNode.freeDataBlock(i); } iNode.setSize(length); @@ -184,10 +184,8 @@ public void readImpl(long fileOffset, ByteBuffer destBuf) throws IOException { iNode.incLocked(); } - if (log.isDebugEnabled()) { - log.debug("File:" + name + " size:" + getLength() + " read offset: " + fileOffset + " len: " + log.log(Level.DEBUG, "File:" + name + " size:" + getLength() + " read offset: " + fileOffset + " len: " + dest.length); - } // a single inode may be represented by more than one Ext2Directory // instances, @@ -207,7 +205,7 @@ public void readImpl(long fileOffset, ByteBuffer destBuf) throws IOException { long blockOffset = (fileOffset + bytesRead) % blockSize; long copyLength = Math.min(len - bytesRead, blockSize - blockOffset); - log.debug("blockNr: " + blockNr + ", blockOffset: " + blockOffset + ", copyLength: " + log.log(Level.DEBUG, "blockNr: " + blockNr + ", blockOffset: " + blockOffset + ", copyLength: " + copyLength + ", bytesRead: " + bytesRead); System.arraycopy(iNode.getDataBlock(blockNr), (int) blockOffset, dest, off + (int) bytesRead, @@ -269,7 +267,7 @@ public void write(long fileOffset, ByteBuffer srcBuf) throws IOException { + getLength()); if (off + len > src.length) throw new IOException("src is shorter than what you want to write"); - log.debug("write(fileOffset=" + fileOffset + ", src, off, len=" + len + ")"); + log.log(Level.DEBUG, "write(fileOffset=" + fileOffset + ", src, off, len=" + len + ")"); final long blockSize = iNode.getExt2FileSystem().getBlockSize(); long blocksAllocated = iNode.getAllocatedBlockCount(); @@ -323,7 +321,7 @@ public void write(long fileOffset, ByteBuffer srcBuf) throws IOException { @Override public void flush() throws IOException { - log.debug("Ext2File.flush()"); + log.log(Level.DEBUG, "Ext2File.flush()"); iNode.update(); // update the group descriptors and superblock: needed if blocks have // been allocated or deallocated diff --git a/fs/src/main/java/org/jnode/fs/ext2/Ext2FileSystem.java b/fs/src/main/java/org/jnode/fs/ext2/Ext2FileSystem.java index 5e53fa4a39..bc2142d992 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/Ext2FileSystem.java +++ b/fs/src/main/java/org/jnode/fs/ext2/Ext2FileSystem.java @@ -27,8 +27,8 @@ import java.text.SimpleDateFormat; import java.util.Date; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; @@ -46,6 +46,8 @@ */ public class Ext2FileSystem extends AbstractFileSystem { + private static final Logger log = System.getLogger(Ext2FileSystem.class.getName()); + /** * The charset used to decode the file and directory names, assuming a default of UTF-8 for now. * See: http://unix.stackexchange.com/a/2111 @@ -66,8 +68,6 @@ public class Ext2FileSystem extends AbstractFileSystem { private MultipleMountProtection multipleMountProtection; - private final Logger log = LogManager.getLogger(getClass()); - // private Object groupDescriptorLock; // private Object superblockLock; @@ -142,7 +142,7 @@ public void read() throws FileSystemException { if (hasIncompatFeature(Ext2Constants.EXT4_FEATURE_INCOMPAT_MMP)) { // TODO: this should really update the MMP block now, and periodically, to indicate that the filesystem is in use - log.info(" file system has multi-mount protection, forcing readonly mode"); + log.log(Level.INFO, " file system has multi-mount protection, forcing readonly mode"); setReadOnly(true); try { @@ -152,7 +152,7 @@ public void read() throws FileSystemException { multipleMountProtection = new MultipleMountProtection(mmpBuffer.array()); if (multipleMountProtection.isInUse()) { - log.warn(" file system appears to be in use"); + log.log(Level.WARNING, " file system appears to be in use"); } } catch (Exception e) { @@ -161,12 +161,12 @@ public void read() throws FileSystemException { } if (hasIncompatFeature(Ext2Constants.EXT2_FEATURE_INCOMPAT_META_BG)) { - log.info(" Unsupported filesystem feature (META_BG) forces readonly mode"); + log.log(Level.INFO, " Unsupported filesystem feature (META_BG) forces readonly mode"); setReadOnly(true); } if (hasIncompatFeature(Ext2Constants.EXT4_FEATURE_INCOMPAT_FLEX_BG)) { - log.info(" filesystem feature (FLEX_BG) is currently only implemented for reading, " + + log.log(Level.INFO, " filesystem feature (FLEX_BG) is currently only implemented for reading, " + "forcing readonly mode"); setReadOnly(true); } @@ -174,39 +174,39 @@ public void read() throws FileSystemException { // an unsupported RO_COMPAT feature means that the filesystem can only // be mounted readonly if (hasROFeature(Ext2Constants.EXT2_FEATURE_RO_COMPAT_LARGE_FILE)) { - log.info(" Unsupported filesystem feature (LARGE_FILE) forces readonly mode"); + log.log(Level.INFO, " Unsupported filesystem feature (LARGE_FILE) forces readonly mode"); setReadOnly(true); } if (hasROFeature(Ext2Constants.EXT2_FEATURE_RO_COMPAT_BTREE_DIR)) { - log.info(" Unsupported filesystem feature (BTREE_DIR) forces readonly mode"); + log.log(Level.INFO, " Unsupported filesystem feature (BTREE_DIR) forces readonly mode"); setReadOnly(true); } if (hasROFeature(Ext2Constants.EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) { - log.info(" Unsupported filesystem feature (HUGE_FILE) forces readonly mode"); + log.log(Level.INFO, " Unsupported filesystem feature (HUGE_FILE) forces readonly mode"); setReadOnly(true); } if (hasROFeature(Ext2Constants.EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { - log.info(" Unsupported filesystem feature (GDT_CSUM) forces readonly mode"); + log.log(Level.INFO, " Unsupported filesystem feature (GDT_CSUM) forces readonly mode"); setReadOnly(true); } if (hasROFeature(Ext2Constants.EXT4_FEATURE_RO_COMPAT_DIR_NLINK)) { - log.info(" Unsupported filesystem feature (DIR_NLINK) forces readonly mode"); + log.log(Level.INFO, " Unsupported filesystem feature (DIR_NLINK) forces readonly mode"); setReadOnly(true); } if (hasROFeature(Ext2Constants.EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) { - log.info(" Unsupported filesystem feature (EXTRA_ISIZE) forces readonly mode"); + log.log(Level.INFO, " Unsupported filesystem feature (EXTRA_ISIZE) forces readonly mode"); setReadOnly(true); } // if the filesystem has not been cleanly unmounted, mount it readonly if (superblock.getState() == Ext2Constants.EXT2_ERROR_FS) { - log.info(" Filesystem has not been cleanly unmounted, mounting it readonly"); + log.log(Level.INFO, " Filesystem has not been cleanly unmounted, mounting it readonly"); setReadOnly(true); } // if the filesystem has been mounted R/W, set it to "unclean" if (!isReadOnly()) { - log.info(" mounting fs r/w"); + log.log(Level.INFO, " mounting fs r/w"); superblock.setState(Ext2Constants.EXT2_ERROR_FS); // Mount successfull, update some superblock informations. superblock.setMntCount(superblock.getMntCount() + 1); @@ -214,7 +214,7 @@ public void read() throws FileSystemException { superblock.setWTime(Ext2Utils.encodeDate(new Date())); } SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy"); - log.debug(" superblock: " + "\n" + " #Mount: " + superblock.getMntCount() + "\n" + " #MaxMount: " + log.log(Level.DEBUG, " superblock: " + "\n" + " #Mount: " + superblock.getMntCount() + "\n" + " #MaxMount: " + superblock.getMaxMntCount() + "\n" + " Last mount time: " + sdf.format(Ext2Utils.decodeDate(superblock.getMTime()).getTime()) + "\n" + " Last write time: " + sdf.format(Ext2Utils.decodeDate(superblock.getWTime()).getTime()) + "\n" + " #blocks: " @@ -225,7 +225,7 @@ public void read() throws FileSystemException { } public void create(BlockSize blockSize) throws FileSystemException { - log.info("Creating a new ext2 file system: " + blockSize); + log.log(Level.INFO, "Creating a new ext2 file system: " + blockSize); try { // create the superblock @@ -248,7 +248,7 @@ public void create(BlockSize blockSize) throws FileSystemException { // create the inode bitmap // fill the inode table with zeroes for (int i = 0; i < groupCount; i++) { - log.debug("creating group " + i); + log.log(Level.DEBUG, "creating group " + i); byte[] blockBitmap = new byte[blockSize.getSize()]; byte[] inodeBitmap = new byte[blockSize.getSize()]; @@ -285,7 +285,7 @@ public void create(BlockSize blockSize) throws FileSystemException { writeBlock(groupDescriptors[i].getInodeBitmap(), inodeBitmap, false); } - log.info("superblock.getBlockSize(): " + superblock.getBlockSize()); + log.log(Level.INFO, "superblock.getBlockSize(): " + superblock.getBlockSize()); buildRootEntry(); @@ -304,11 +304,11 @@ public void create(BlockSize blockSize) throws FileSystemException { * @throws IOException */ public void flush() throws IOException { - log.info("Flushing the contents of the filesystem"); + log.log(Level.INFO, "Flushing the contents of the filesystem"); // update the inodes synchronized (inodeCache) { try { - log.debug("inodecache size: " + inodeCache.size()); + log.log(Level.DEBUG, "inodecache size: " + inodeCache.size()); for (INode iNode : inodeCache.values()) { iNode.flush(); } @@ -328,7 +328,7 @@ public void flush() throws IOException { } } - log.info("Filesystem flushed"); + log.log(Level.INFO, "Filesystem flushed"); } protected void updateFS() throws IOException { @@ -391,7 +391,7 @@ public MultipleMountProtection getMultipleMountProtection() { */ public byte[] getBlock(long nr) throws IOException { if (isClosed()) throw new IOException("FS closed (fs instance: " + this + ")"); - // log.debug("blockCache size: "+blockCache.size()); + // log.log(Level.DEBUG, "blockCache size: "+blockCache.size()); int blockSize = superblock.getBlockSize(); Block result; @@ -416,7 +416,7 @@ public byte[] getBlock(long nr) throws IOException { // the block will be put in the cache only once in the second // synchronized block ByteBuffer data = ByteBuffer.allocate(blockSize); - log.debug("Reading block " + nr + " (offset: " + nr * blockSize + ") from disk"); + log.log(Level.DEBUG, "Reading block " + nr + " (offset: " + nr * blockSize + ") from disk"); getApi().read(nr * blockSize, data); // synchronize again @@ -466,7 +466,7 @@ public void writeBlock(long nr, byte[] data, boolean forceWrite) throws IOExcept // timedWrite(nr, data); block.setDirty(false); - log.debug("writing block " + nr + " to disk"); + log.log(Level.DEBUG, "writing block " + nr + " to disk"); } else block.setDirty(true); } else { // If the block was not in the cache, I see no reason to put it @@ -499,13 +499,13 @@ public void writeBlock(long nr, byte[] data, boolean forceWrite) throws IOExcept * TimeoutWatcher(Thread.currentThread()), TIMEOUT); try{ getApi().write(nr*getBlockSize(), data, 0, * (int)getBlockSize()); writeTimer.cancel(); }catch(IOException ioe) { //IDEDiskDriver will throw an IOException * with a cause of an InterruptedException //it the write is interrupted if(ioe.getCause() instanceof - * InterruptedException) { writeTimer.cancel(); log.debug("IDE driver interrupted during write operation: probably + * InterruptedException) { writeTimer.cancel(); log.log(Level.DEBUG, "IDE driver interrupted during write operation: probably * timeout"); finished = false; } } } } private void timedRead(long nr, byte[] data) throws IOException{ boolean * finished = false; Timer readTimer; while(!finished) { finished = true; readTimer = new Timer(); * readTimer.schedule(new TimeoutWatcher(Thread.currentThread()), TIMEOUT); try{ getApi().read( nr*getBlockSize(), * data, 0, (int)getBlockSize()); readTimer.cancel(); }catch(IOException ioe) { //IDEDiskDriver will throw an * IOException with a cause of an InterruptedException //it the write is interrupted if(ioe.getCause() instanceof - * InterruptedException) { readTimer.cancel(); log.debug("IDE driver interrupted during read operation: probably + * InterruptedException) { readTimer.cancel(); log.log(Level.DEBUG, "IDE driver interrupted during read operation: probably * timeout"); finished = false; } } } } */ @@ -524,7 +524,7 @@ public INode getINode(long iNodeNr) throws IOException, FileSystemException { Long key = iNodeNr; - log.debug("iNodeCache size: " + inodeCache.size()); + log.log(Level.DEBUG, "iNodeCache size: " + inodeCache.size()); synchronized (inodeCache) { // check if the inode is already in the cache @@ -635,7 +635,7 @@ protected INode createINode(int preferredBlockBroup, int fileFormat, int accessR // trigger a write to disk iNode.update(); - log.debug("** NEW INODE ALLOCATED: inode number: " + iNode.getINodeNr()); + log.log(Level.DEBUG, "** NEW INODE ALLOCATED: inode number: " + iNode.getINodeNr()); // put the inode into the cache synchronized (inodeCache) { @@ -795,9 +795,9 @@ public BlockReservation findFreeBlocks(int group, long threshold) throws IOExcep long firstNonMetadataBlock = iNodeTableBlock + INodeTable.getSizeInBlocks(this); int metadataLength = (int) (firstNonMetadataBlock - (superblock.getFirstDataBlock() + group * superblock.getBlocksPerGroup())); - log.debug("group[" + group + "].getInodeTable()=" + iNodeTableBlock + ", iNodeTable.getSizeInBlocks()=" + log.log(Level.DEBUG, "group[" + group + "].getInodeTable()=" + iNodeTableBlock + ", iNodeTable.getSizeInBlocks()=" + INodeTable.getSizeInBlocks(this)); - log.debug("metadata length for block group(" + group + "): " + metadataLength); + log.log(Level.DEBUG, "metadata length for block group(" + group + "): " + metadataLength); BlockReservation result; @@ -940,7 +940,7 @@ protected FSEntry buildRootEntry() throws IOException { } protected void handleFSError(Exception e) { - log.error("File system error", e); + log.log(Level.ERROR, "File system error", e); // mark the fs as having errors superblock.setState(Ext2Constants.EXT2_ERROR_FS); diff --git a/fs/src/main/java/org/jnode/fs/ext2/Ext2Print.java b/fs/src/main/java/org/jnode/fs/ext2/Ext2Print.java index 7fe3b4f9d3..0c54753a3f 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/Ext2Print.java +++ b/fs/src/main/java/org/jnode/fs/ext2/Ext2Print.java @@ -22,15 +22,15 @@ import java.nio.ByteBuffer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.block.BlockDeviceAPI; /** * @author Andras Nagy */ public class Ext2Print { - private static final Logger log = LogManager.getLogger("EXT2"); + private static final Logger log = System.getLogger("EXT2"); public static String hexFormat(int i) { String pad = "00000000"; @@ -68,7 +68,7 @@ public static void dumpData(BlockDeviceAPI api, int offset, int length) { System.out.print(hexFormat(i) + ": "); for (int j = 0; j < pageWidth; j++) if (i + j < length) { - log.info(hexFormat(data[i + j]) + " "); + log.log(Level.INFO, hexFormat(data[i + j]) + " "); if ((i + j) % 4 == 3) System.out.print(" - "); } diff --git a/fs/src/main/java/org/jnode/fs/ext2/GroupDescriptor.java b/fs/src/main/java/org/jnode/fs/ext2/GroupDescriptor.java index 73a156ef1a..f1589ba13c 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/GroupDescriptor.java +++ b/fs/src/main/java/org/jnode/fs/ext2/GroupDescriptor.java @@ -22,8 +22,8 @@ import java.io.IOException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.LittleEndian; /** @@ -31,13 +31,15 @@ * */ public class GroupDescriptor { + + private static final Logger log = System.getLogger(GroupDescriptor.class.getName()); + public static final int GROUPDESCRIPTOR_LENGTH = 32; private byte[] data; private Ext2FileSystem fs; private int groupNr; private boolean dirty; - private final Logger log = LogManager.getLogger(getClass()); public GroupDescriptor() { data = new byte[GROUPDESCRIPTOR_LENGTH]; @@ -120,7 +122,7 @@ public void create(int groupNr, Ext2FileSystem fs) { */ protected synchronized void updateGroupDescriptor() throws IOException { if (isDirty()) { - log.debug("Updating groupdescriptor copies"); + log.log(Level.DEBUG, "Updating groupdescriptor copies"); Superblock superblock = fs.getSuperblock(); for (int i = 0; i < fs.getGroupCount(); i++) { // check if there is a group descriptor table copy in the block diff --git a/fs/src/main/java/org/jnode/fs/ext2/INode.java b/fs/src/main/java/org/jnode/fs/ext2/INode.java index 538d7a61af..2f4c413867 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/INode.java +++ b/fs/src/main/java/org/jnode/fs/ext2/INode.java @@ -25,8 +25,8 @@ import java.util.Arrays; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FileSystemException; import org.jnode.fs.ext2.exception.UnallocatedBlockException; import org.jnode.fs.ext2.xattr.XAttrEntry; @@ -42,14 +42,15 @@ * @author Andras Nagy */ public class INode { - public static final int EXT2_GOOD_OLD_INODE_SIZE = 128; - private final Logger log = LogManager.getLogger(getClass()); + private final Logger log = System.getLogger(INode.class.getName()); + + public static final int EXT2_GOOD_OLD_INODE_SIZE = 128; /** * the data constituting the inode itself */ - private byte[] data; + private final byte[] data; private volatile boolean dirty; @@ -64,7 +65,7 @@ public class INode { */ INodeDescriptor desc = null; - private Ext2FileSystem fs; + private final Ext2FileSystem fs; /** * The cached extent header. @@ -94,7 +95,7 @@ public void read(byte[] data) { */ public void create(int fileFormat, int accessRights, int uid, int gid) { long time = System.currentTimeMillis() / 1000; - log.debug("TIME: " + time); + log.log(Level.DEBUG, "TIME: " + time); setUid(uid); setGid(gid); @@ -123,7 +124,7 @@ protected void finalize() throws Exception { * be saved to the disk */ public void flush() throws IOException, FileSystemException { - log.debug("Flush called for inode " + getINodeNr()); + log.log(Level.DEBUG, "Flush called for inode " + getINodeNr()); freePreallocatedBlocks(); update(); @@ -137,7 +138,7 @@ public void flush() throws IOException, FileSystemException { protected synchronized void update() throws IOException { try { if (dirty) { - log.debug(" ** updating inode **"); + log.log(Level.DEBUG, " ** updating inode **"); desc.getINodeTable().writeInodeData(desc.getIndex(), data); dirty = false; } @@ -309,7 +310,7 @@ private long indirectRead(long dataBlockNr, long offset, int indirectionLevel) */ private void indirectWrite(long dataBlockNr, long offset, long allocatedBlocks, long value, int indirectionLevel) throws IOException, FileSystemException { - log.debug("indirectWrite(blockNr=" + dataBlockNr + ", offset=" + offset + "...)"); + log.log(Level.DEBUG, "indirectWrite(blockNr=" + dataBlockNr + ", offset=" + offset + "...)"); byte[] data = fs.getBlock(dataBlockNr); if (indirectionLevel == 1) { //data is a (simple) indirect block @@ -349,7 +350,7 @@ private void indirectWrite(long dataBlockNr, long offset, long allocatedBlocks, */ private void indirectFree(long dataBlockNr, long offset, int indirectionLevel) throws IOException, FileSystemException { - log.debug("indirectFree(datablockNr=" + dataBlockNr + ", offset=" + offset + ", ind=" + + log.log(Level.DEBUG, "indirectFree(datablockNr=" + dataBlockNr + ", offset=" + offset + ", ind=" + indirectionLevel + ")"); if (indirectionLevel == 0) { fs.freeBlock(dataBlockNr); @@ -435,7 +436,7 @@ private long getDataBlockNrIndirect(long i) throws IOException { //get the direct blocks (0; 11) if (i < 12) { - log.debug("getDataBlockNr(): block nr: " + LittleEndian.getUInt32(data, 40 + (int) i * 4)); + log.log(Level.DEBUG, "getDataBlockNr(): block nr: " + LittleEndian.getUInt32(data, 40 + (int) i * 4)); return LittleEndian.getUInt32(data, 40 + (int) i * 4); } @@ -500,7 +501,7 @@ private void registerBlockIndex(long i, long blockNr) " (counts from 0), when INode contains only " + blockCount + " blocks"); } - log.debug("registering block #" + blockNr); + log.log(Level.DEBUG, "registering block #" + blockNr); setDirty(true); @@ -521,7 +522,7 @@ private void registerBlockIndex(long i, long blockNr) indirectBlockNr = findFreeBlock(allocatedBlocks++); Ext2Utils.set32(data, 40 + 12 * 4, indirectBlockNr); - //log.debug("reserved indirect block: "+indirectBlockNr); + //log.log(Level.DEBUG, "reserved indirect block: "+indirectBlockNr); //need to blank the block so that e2fsck does not complain byte[] zeroes = new byte[fs.getBlockSize()]; //blank the block @@ -548,7 +549,7 @@ private void registerBlockIndex(long i, long blockNr) doubleIndirectBlockNr = findFreeBlock(allocatedBlocks++); Ext2Utils.set32(data, 40 + 13 * 4, doubleIndirectBlockNr); - //log.debug("reserved double indirect block: + //log.log(Level.DEBUG, "reserved double indirect block: // "+doubleIndirectBlockNr); //need to blank the block so that e2fsck does not complain @@ -576,7 +577,7 @@ private void registerBlockIndex(long i, long blockNr) tripleIndirectBlockNr = findFreeBlock(allocatedBlocks++); Ext2Utils.set32(data, 40 + 13 * 4, tripleIndirectBlockNr); - //log.debug("reserved triple indirect block: + //log.log(Level.DEBUG, "reserved triple indirect block: // "+tripleIndirectBlockNr); //need to blank the block so that e2fsck does not complain @@ -604,9 +605,9 @@ private void registerBlockIndex(long i, long blockNr) private void freePreallocatedBlocks() throws FileSystemException, IOException { int preallocCount = desc.getPreallocCount(); if (preallocCount > 0) { - log.debug("Freeing preallocated blocks"); + log.log(Level.DEBUG, "Freeing preallocated blocks"); } else { - log.debug("No preallocated blocks in the inode"); + log.log(Level.DEBUG, "No preallocated blocks in the inode"); return; } @@ -757,7 +758,7 @@ public synchronized void allocateDataBlock(long i) throws FileSystemException, I long newBlock = findFreeBlock(i); - log.debug("Allocated new block " + newBlock); + log.log(Level.DEBUG, "Allocated new block " + newBlock); desc.setLastAllocatedBlockIndex(i); @@ -883,7 +884,7 @@ private long findFreeBlock(long index) throws IOException, FileSystemException { // **************** other persistent inode data ******************* public synchronized int getMode() { int iMode = LittleEndian.getUInt16(data, 0); - //log.debug("INode.getIMode(): "+Ext2Print.hexFormat(iMode)); + //log.log(Level.DEBUG, "INode.getIMode(): "+Ext2Print.hexFormat(iMode)); return iMode; } @@ -995,7 +996,7 @@ public synchronized long getBlocks() { } public synchronized void setBlocks(long count) { - log.debug("setBlocks(" + count + ")"); + log.log(Level.DEBUG, "setBlocks(" + count + ")"); Ext2Utils.set32(data, 28, count); setDirty(true); } diff --git a/fs/src/main/java/org/jnode/fs/ext2/Superblock.java b/fs/src/main/java/org/jnode/fs/ext2/Superblock.java index 02efe38c9c..4d4418ef38 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/Superblock.java +++ b/fs/src/main/java/org/jnode/fs/ext2/Superblock.java @@ -22,8 +22,8 @@ import java.io.IOException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FileSystemException; import org.jnode.util.LittleEndian; @@ -33,6 +33,9 @@ * @author Andras Nagy */ public class Superblock { + + private static final Logger log = System.getLogger(Superblock.class.getName()); + public static final int SUPERBLOCK_LENGTH = 1024; // some constants for the fs creation @@ -53,7 +56,6 @@ public class Superblock { private byte[] data; private boolean dirty; private Ext2FileSystem fs; - private final Logger log = LogManager.getLogger(getClass()); public Superblock() { data = new byte[SUPERBLOCK_LENGTH]; @@ -157,7 +159,7 @@ public void create(BlockSize blockSize, Ext2FileSystem fs) throws IOException { setPreallocBlocks(8); setPreallocDirBlocks(0); - log.debug("SuperBlock.create(): getBlockSize(): " + getBlockSize()); + log.log(Level.DEBUG, "SuperBlock.create(): getBlockSize(): " + getBlockSize()); } /** @@ -165,7 +167,7 @@ public void create(BlockSize blockSize, Ext2FileSystem fs) throws IOException { */ public synchronized void update() throws IOException { if (isDirty()) { - log.debug("Updating superblock copies"); + log.log(Level.DEBUG, "Updating superblock copies"); byte[] oldData; // update the main copy diff --git a/fs/src/main/java/org/jnode/fs/ext2/cache/Block.java b/fs/src/main/java/org/jnode/fs/ext2/cache/Block.java index 5aca9be660..859285ec6b 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/cache/Block.java +++ b/fs/src/main/java/org/jnode/fs/ext2/cache/Block.java @@ -22,15 +22,16 @@ import java.io.IOException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.ext2.Ext2FileSystem; /** * @author Andras Nagy */ public class Block { - private final Logger log = LogManager.getLogger(getClass()); + + private static final Logger log = System.getLogger(Block.class.getName()); protected byte[] data; boolean dirty = false; @@ -68,7 +69,7 @@ public void setData(byte[] data) { public void flush() throws IOException { if (dirty) { fs.writeBlock(blockNr, data, true); - log.debug("BLOCK FLUSHED FROM CACHE"); + log.log(Level.DEBUG, "BLOCK FLUSHED FROM CACHE"); } } @@ -83,10 +84,9 @@ public boolean isDirty() { /** * Set the dirty flag. - * @param b + * @param b the dirty flag */ public void setDirty(boolean b) { dirty = b; } - } diff --git a/fs/src/main/java/org/jnode/fs/ext2/cache/BlockCache.java b/fs/src/main/java/org/jnode/fs/ext2/cache/BlockCache.java index ab4a363120..81cdd68fa4 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/cache/BlockCache.java +++ b/fs/src/main/java/org/jnode/fs/ext2/cache/BlockCache.java @@ -21,25 +21,28 @@ package org.jnode.fs.ext2.cache; import java.io.IOException; +import java.io.Serial; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; /** * @author Andras Nagy */ public final class BlockCache extends LinkedHashMap { + + private static final Logger log = System.getLogger(BlockCache.class.getName()); + + @Serial private static final long serialVersionUID = 1L; // at most MAX_SIZE blocks fit in the cache static final int MAX_SIZE = 10; - private static final Logger log = LogManager.getLogger(BlockCache.class); - - private ArrayList cacheListeners; + private final ArrayList cacheListeners; public BlockCache(int initialCapacity, float loadFactor) { super(Math.min(MAX_SIZE, initialCapacity), loadFactor, true); @@ -51,7 +54,7 @@ public void addCacheListener(CacheListener listener) { } protected synchronized boolean removeEldestEntry(Map.Entry eldest) { - log.debug("BlockCache size: " + size()); + log.log(Level.DEBUG, "BlockCache size: " + size()); if (size() > MAX_SIZE) { try { eldest.getValue().flush(); @@ -61,7 +64,7 @@ protected synchronized boolean removeEldestEntry(Map.Entry eldest l.elementRemoved(event); } } catch (IOException e) { - log.error("Exception when flushing a block from the cache", e); + log.log(Level.ERROR, "Exception when flushing a block from the cache", e); } return true; } else { diff --git a/fs/src/main/java/org/jnode/fs/ext2/xattr/XAttrEntry.java b/fs/src/main/java/org/jnode/fs/ext2/xattr/XAttrEntry.java index 13a20cbb83..780b582068 100644 --- a/fs/src/main/java/org/jnode/fs/ext2/xattr/XAttrEntry.java +++ b/fs/src/main/java/org/jnode/fs/ext2/xattr/XAttrEntry.java @@ -3,8 +3,8 @@ import java.util.HashMap; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.ext2.Ext2FileSystem; import org.jnode.util.LittleEndian; @@ -18,7 +18,7 @@ public class XAttrEntry { /** * The logger. */ - private final Logger log = LogManager.getLogger(getClass()); + private static final Logger log = System.getLogger(XAttrEntry.class.getName()); /** * The minimum size of the entry structure. @@ -131,7 +131,7 @@ public String getName() { if (prefix != null) { name = prefix + name; } else { - log.warn("Unknown xattr prefix index: " + prefixIndex); + log.log(Level.WARNING, "Unknown xattr prefix index: " + prefixIndex); } } diff --git a/fs/src/main/java/org/jnode/fs/ext4/MultipleMountProtection.java b/fs/src/main/java/org/jnode/fs/ext4/MultipleMountProtection.java index 8044354146..5c5b46dc62 100644 --- a/fs/src/main/java/org/jnode/fs/ext4/MultipleMountProtection.java +++ b/fs/src/main/java/org/jnode/fs/ext4/MultipleMountProtection.java @@ -3,18 +3,19 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.LittleEndian; /** * A class for checking the ext4 multiple-mount protection (MMP) status. */ public class MultipleMountProtection { + /** * Logger */ - private static final Logger log = LogManager.getLogger(MultipleMountProtection.class); + private static final Logger log = System.getLogger(MultipleMountProtection.class.getName()); /** * The length of the MMP structure. @@ -44,32 +45,32 @@ public class MultipleMountProtection { /** * The sequence number. */ - private int sequenceNumber; + private final int sequenceNumber; /** * The time the MMP block was last updated. */ - private long time; + private final long time; /** * The host name of the node which opened the file system. */ - private String nodeName; + private final String nodeName; /** * The block device name of the file system. */ - private String blockDeviceName; + private final String blockDeviceName; /** * The recheck interval, in seconds. */ - private int checkInterval; + private final int checkInterval; /** * The checksum of the MMP block. */ - private int checksum; + private final int checksum; public MultipleMountProtection(byte[] data) throws IOException { int magic = LittleEndian.getInt32(data, 0); @@ -92,7 +93,7 @@ public MultipleMountProtection(byte[] data) throws IOException { */ public boolean isInUse() { if (sequenceNumber != MMP_SEQ_CLEAN) { - log.warn(String.format("File system appears to be in use from: %s:%s, seq:%x", nodeName, blockDeviceName, + log.log(Level.WARNING, String.format("File system appears to be in use from: %s:%s, seq:%x", nodeName, blockDeviceName, sequenceNumber)); return true; diff --git a/fs/src/main/java/org/jnode/fs/fat/FatDirEntry.java b/fs/src/main/java/org/jnode/fs/fat/FatDirEntry.java index de96b60624..bcaa36364e 100644 --- a/fs/src/main/java/org/jnode/fs/fat/FatDirEntry.java +++ b/fs/src/main/java/org/jnode/fs/fat/FatDirEntry.java @@ -242,7 +242,7 @@ public String getId() { } public String getName() { - if (ext.length() > 0) { + if (!ext.isEmpty()) { return name + "." + ext; } else { return name; diff --git a/fs/src/main/java/org/jnode/fs/fat/FatLfnDirectory.java b/fs/src/main/java/org/jnode/fs/fat/FatLfnDirectory.java index 995494b25e..1843275b26 100644 --- a/fs/src/main/java/org/jnode/fs/fat/FatLfnDirectory.java +++ b/fs/src/main/java/org/jnode/fs/fat/FatLfnDirectory.java @@ -208,7 +208,7 @@ public void flush() throws IOException { } public Iterator iterator() { - return new Iterator() { + return new Iterator<>() { Iterator it = shortNameIndex.values().iterator(); public boolean hasNext() { diff --git a/fs/src/main/java/org/jnode/fs/fat/FatUtils.java b/fs/src/main/java/org/jnode/fs/fat/FatUtils.java index e43c250aae..e516091996 100644 --- a/fs/src/main/java/org/jnode/fs/fat/FatUtils.java +++ b/fs/src/main/java/org/jnode/fs/fat/FatUtils.java @@ -20,8 +20,8 @@ package org.jnode.fs.fat; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.LittleEndian; /** @@ -32,6 +32,8 @@ */ public class FatUtils { + private static final Logger log = System.getLogger(FatUtils.class.getName()); + public static final int FIRST_CLUSTER = 2; /** @@ -124,7 +126,7 @@ public static String splitExt(String nameExt) { * @return the normalized DOS 8.3 name */ public static String normalizeName(String name, String ext) { - if (ext.length() > 0) { + if (!ext.isEmpty()) { return (name + "." + ext).toUpperCase(); } else { return name.toUpperCase(); @@ -212,9 +214,7 @@ public static void writeSubString(char[] src, int srcOffset, int ordinal, byte c LittleEndian.setInt16(dest, destOffset + 28, src[srcOffset + 11]); LittleEndian.setInt16(dest, destOffset + 30, src[srcOffset + 12]); - if (log.isDebugEnabled()) { - log.debug("<<< END writeSubString dest=\n" /* +FSUtils.toString(dest) */ + ">>>"); - } + log.log(Level.DEBUG, "<<< END writeSubString dest=\n" /* + FSUtils.toString(dest) */ + ">>>"); } public static byte getOrdinal(byte[] rawData, int offset) { @@ -234,53 +234,40 @@ public static byte getCheckSum(byte[] rawData, int offset) { * @param offset */ public static void appendSubstring(StringBuffer sb, byte[] rawData, int offset) { - if (log.isDebugEnabled()) { - log.debug("<<< BEGIN appendSubstring buffer=" + sb.toString() + ">>>"); - } + log.log(Level.DEBUG, "<<< BEGIN appendSubstring buffer=" + sb.toString() + ">>>"); int index = 12; char[] unicodechar = getUnicodeChars(rawData, offset); - if (log.isDebugEnabled()) { - log.debug("appendSubstring: unicodechar=" + new String(unicodechar)); - } + log.log(Level.DEBUG, "appendSubstring: unicodechar=" + new String(unicodechar)); while (unicodechar[index] == 0) index--; sb.append(unicodechar, 0, index + 1); - if (log.isDebugEnabled()) { - log.debug("<<< END appendSubstring buffer=" + sb + ">>>"); - } + log.log(Level.DEBUG, "<<< END appendSubstring buffer=" + sb + ">>>"); } /** * Return a part of a long file name read from the given byte array */ public static String getSubstring(byte[] rawData, int offset) { - if (log.isDebugEnabled()) { - log.debug("<<< BEGIN getSubString: rawData=" /* - * +FSUtils.toString(rawData, - * offset, 12) - */ + log.log(Level.DEBUG, "<<< BEGIN getSubString: rawData=" /* + FSUtils.toString(rawData, offset, 12) */ + " >>>"); - } - // log.debug("getSubString: rawData as + // log.log(Level.DEBUG, "getSubString: rawData as // chars="+FSUtils.toStringAsChars(rawData, offset, 12)); int index = 12; char[] unicodechar = getUnicodeChars(rawData, offset); while (unicodechar[index] == 0) index--; - // log.debug("getSubString: rawData.length="+rawData.length+" + // log.log(Level.DEBUG, "getSubString: rawData.length="+rawData.length+" // offset="+offset+" nbChars(index)="+index); String str = new String(unicodechar, 0, index); - if (log.isDebugEnabled()) { - log.debug("<<< END getSubString: return=" + str + " >>>"); - } + log.log(Level.DEBUG, "<<< END getSubString: return=" + str + " >>>"); return str; } @@ -305,7 +292,4 @@ static char[] getUnicodeChars(byte[] rawData, int offset) { unicodechar[12] = (char) LittleEndian.getUInt16(rawData, offset + 30); return unicodechar; } - - private static final Logger log = LogManager.getLogger(FatUtils.class); - } diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/HfsPlusDirectory.java b/fs/src/main/java/org/jnode/fs/hfsplus/HfsPlusDirectory.java index 12318f06b9..8ae0d329a7 100644 --- a/fs/src/main/java/org/jnode/fs/hfsplus/HfsPlusDirectory.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/HfsPlusDirectory.java @@ -26,8 +26,8 @@ import java.util.LinkedList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSDirectoryId; import org.jnode.fs.FSEntry; @@ -43,7 +43,7 @@ public class HfsPlusDirectory implements FSDirectory, FSDirectoryId { - private static final Logger log = LogManager.getLogger(HfsPlusDirectory.class); + private static final Logger log = System.getLogger(HfsPlusDirectory.class.getName()); /** * The directory entry @@ -82,7 +82,7 @@ public FSEntry addDirectory(String name) throws IOException { } FSEntry newEntry = createDirectoryEntry(name); setFreeEntry(newEntry); - log.debug("Directory " + name + " added"); + log.log(Level.DEBUG, "Directory " + name + " added"); return newEntry; } @@ -113,7 +113,7 @@ private FSEntry createFileEntry(final String name) throws IOException { * HFSPlusEntry newEntry = new HFSPlusFile(fs, this, name, * folderRecord); newEntry.setDirty(); * volumeHeader.setFileCount(volumeHeader.getFileCount() + 1); - * log.debug("New volume header :\n" + volumeHeader.toString()); + * log.log(Level.DEBUG, "New volume header :\n" + volumeHeader.toString()); */ return null; @@ -130,7 +130,7 @@ public void flush() throws IOException { // entries.resetDirty(); entry.resetDirty(); } - log.debug("Directory flushed."); + log.log(Level.DEBUG, "Directory flushed."); } @Override @@ -182,20 +182,20 @@ public void remove(String name) throws IOException { */ protected final void checkEntriesLoaded() { if (!isEntriesLoaded()) { - log.debug("checkEntriesLoaded : loading"); + log.log(Level.DEBUG, "checkEntriesLoaded : loading"); try { if (entry.getAccessRights().canRead()) { entries = readEntries(); - log.debug("Load " + entries.size() + " entrie(s)."); + log.log(Level.DEBUG, "Load " + entries.size() + " entrie(s)."); } else { // the next time, we will call checkEntriesLoaded() // we will retry to load entries entries = FSEntryTable.EMPTY_TABLE; - log.debug("checkEntriesLoaded : can't read, using EMPTY_TABLE"); + log.log(Level.DEBUG, "checkEntriesLoaded : can't read, using EMPTY_TABLE"); } entry.resetDirty(); } catch (IOException e) { - log.fatal("unable to read directory entries", e); + log.log(Level.ERROR, "unable to read directory entries", e); // the next time, we will call checkEntriesLoaded() // we will retry to load entries entries = FSEntryTable.EMPTY_TABLE; @@ -308,7 +308,7 @@ private FSEntry createDirectoryEntry(final String name) throws IOException { HfsPlusEntry newEntry = new HfsPlusEntry(getFileSystem(), this, name, node.getNodeRecord(0)); newEntry.setDirty(); volumeHeader.incrementFolderCount(); - log.debug("New volume header :\n" + volumeHeader); + log.log(Level.DEBUG, "New volume header :\n" + volumeHeader); volumeHeader.update(); return newEntry; @@ -323,7 +323,7 @@ private FSEntry createDirectoryEntry(final String name) throws IOException { private void setFreeEntry(FSEntry newEntry) throws IOException { checkEntriesLoaded(); if (entries.setFreeEntry(newEntry) >= 0) { - log.debug("setFreeEntry: free entry found !"); + log.log(Level.DEBUG, "setFreeEntry: free entry found !"); entry.setDirty(); flush(); } diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/HfsPlusFileSystem.java b/fs/src/main/java/org/jnode/fs/hfsplus/HfsPlusFileSystem.java index c61d239873..e296876d58 100755 --- a/fs/src/main/java/org/jnode/fs/hfsplus/HfsPlusFileSystem.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/HfsPlusFileSystem.java @@ -24,8 +24,8 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; @@ -42,7 +42,8 @@ import org.jnode.fs.spi.AbstractFileSystem; public class HfsPlusFileSystem extends AbstractFileSystem { - private final Logger log = LogManager.getLogger(getClass()); + + private static final Logger log = System.getLogger(HfsPlusFileSystem.class.getName()); /** * HFS volume header @@ -95,17 +96,17 @@ public HfsPlusFileSystem(Device device, boolean readOnly) */ public final void read() throws FileSystemException { volumeHeader = new SuperBlock(this, false); - log.debug(volumeHeader.toString()); + log.log(Level.DEBUG, volumeHeader.toString()); if (!volumeHeader.isAttribute(SuperBlock.HFSPLUS_VOL_UNMNT_BIT)) { - log.info(" Filesystem has not been cleanly unmounted, mounting it readonly"); + log.log(Level.INFO, " Filesystem has not been cleanly unmounted, mounting it readonly"); setReadOnly(true); } if (volumeHeader.isAttribute(SuperBlock.HFSPLUS_VOL_SOFTLOCK_BIT)) { - log.info(" Filesystem is marked locked, mounting it readonly"); + log.log(Level.INFO, " Filesystem is marked locked, mounting it readonly"); setReadOnly(true); } if (volumeHeader.isAttribute(SuperBlock.HFSPLUS_VOL_JOURNALED_BIT)) { - log.info(" Filesystem is journaled, write access is not supported. Mounting it readonly"); + log.log(Level.INFO, " Filesystem is journaled, write access is not supported. Mounting it readonly"); setReadOnly(true); } try { @@ -137,12 +138,12 @@ protected final FSFile createFile(final FSEntry entry) throws IOException { @Override public final HfsPlusEntry createRootEntry() throws IOException { - log.debug("Create root entry."); + log.log(Level.DEBUG, "Create root entry."); LeafRecord record = catalog.getRecord(CatalogNodeId.HFSPLUS_POR_CNID); if (record != null) { return new HfsPlusEntry(this, null, "/", record); } - log.error("Root entry : No record found."); + log.log(Level.ERROR, "Root entry : No record found."); return null; } @@ -244,17 +245,17 @@ public void create(HFSPlusParams params) throws FileSystemException { try { params.initializeDefaultsValues(this); volumeHeader.create(params); - log.debug("Volume header : \n" + volumeHeader.toString()); + log.log(Level.DEBUG, "Volume header : \n" + volumeHeader.toString()); long volumeBlockUsed = volumeHeader.getTotalBlocks() - volumeHeader.getFreeBlocks() - ((volumeHeader.getBlockSize() == 512) ? 2 : 1); // --- - log.debug("Write allocation bitmap bits to disk."); + log.log(Level.DEBUG, "Write allocation bitmap bits to disk."); writeAllocationFile((int) volumeBlockUsed); - log.debug("Write Catalog to disk."); + log.log(Level.DEBUG, "Write Catalog to disk."); Catalog catalog = new Catalog(params, this); catalog.update(); extentOverflow = new Extent(params); - log.debug("Write volume header to disk."); + log.log(Level.DEBUG, "Write volume header to disk."); volumeHeader.update(); flush(); } catch (IOException e) { diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/SuperBlock.java b/fs/src/main/java/org/jnode/fs/hfsplus/SuperBlock.java index d41d099aa4..f05818a276 100755 --- a/fs/src/main/java/org/jnode/fs/hfsplus/SuperBlock.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/SuperBlock.java @@ -26,8 +26,8 @@ import java.util.Calendar; import java.util.Date; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FileSystemException; import org.jnode.fs.hfsplus.catalog.CatalogNodeId; import org.jnode.fs.hfsplus.extent.ExtentDescriptor; @@ -41,6 +41,8 @@ */ public class SuperBlock extends HfsPlusObject { + private static final Logger log = System.getLogger(SuperBlock.class.getName()); + public static final int HFSPLUS_SUPER_MAGIC = 0x482b; // H+ public static final int HFSX_SUPER_MAGIC = 0x4858; // HX @@ -56,8 +58,6 @@ public class SuperBlock extends HfsPlusObject { public static final int HFSPLUS_VOL_JOURNALED_BIT = 13; public static final int HFSPLUS_VOL_SOFTLOCK_BIT = 15; - private final Logger log = LogManager.getLogger(getClass()); - /** * Volume header data length */ @@ -80,7 +80,7 @@ public SuperBlock(final HfsPlusFileSystem fs, boolean create) throws FileSystemE data = new byte[SUPERBLOCK_LENGTH]; try { if (!create) { - log.debug("load HFS+ volume header."); + log.log(Level.DEBUG, "load HFS+ volume header."); // skip the first 1024 bytes (boot sector) and read the volume // header. ByteBuffer b = ByteBuffer.allocate(SUPERBLOCK_LENGTH); @@ -105,7 +105,7 @@ public SuperBlock(final HfsPlusFileSystem fs, boolean create) throws FileSystemE * @throws IOException */ public void create(HFSPlusParams params) throws IOException { - log.debug("Create new HFS+ volume header (" + params.getVolumeName() + + log.log(Level.DEBUG, "Create new HFS+ volume header (" + params.getVolumeName() + ") with block size of " + params.getBlockSize() + " bytes."); int burnedBlocksBeforeVH = 0; int burnedBlocksAfterAltVH = 0; @@ -140,7 +140,7 @@ public void create(HFSPlusParams params) throws IOException { this.setDataClumpSize(params.getDataClumpSize()); this.setNextCatalogId(CatalogNodeId.HFSPLUS_FIRSTUSER_CNID.getId()); // Allocation file creation - log.debug("Init allocation file."); + log.log(Level.DEBUG, "Init allocation file."); long allocationClumpSize = getClumpSize(params.getBlockCount()); long bitmapBlocks = allocationClumpSize / blockSize; long blockUsed = 2 + burnedBlocksBeforeVH + burnedBlocksAfterAltVH + bitmapBlocks; @@ -165,7 +165,7 @@ public void create(HFSPlusParams params) throws IOException { nextBlock = desc.getNext(); } // Extent B-Tree initialization - log.debug("Init extent file."); + log.log(Level.DEBUG, "Init extent file."); forkdata = new HfsPlusForkData(CatalogNodeId.HFSPLUS_EXT_CNID, params.getExtentClumpSize(), params.getExtentClumpSize(), (params.getExtentClumpSize() / blockSize)); @@ -175,7 +175,7 @@ public void create(HFSPlusParams params) throws IOException { blockUsed += forkdata.getTotalBlocks(); nextBlock = desc.getNext(); // Catalog B-Tree initialization - log.debug("Init catalog file."); + log.log(Level.DEBUG, "Init catalog file."); int totalBlocks = params.getCatalogClumpSize() / blockSize; forkdata = new HfsPlusForkData(CatalogNodeId.HFSPLUS_CAT_CNID, params.getCatalogClumpSize(), diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/attributes/Attributes.java b/fs/src/main/java/org/jnode/fs/hfsplus/attributes/Attributes.java index 8a3d73c081..2c717d0354 100644 --- a/fs/src/main/java/org/jnode/fs/hfsplus/attributes/Attributes.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/attributes/Attributes.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.nio.ByteBuffer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.hfsplus.HfsPlusFileSystem; import org.jnode.fs.hfsplus.HfsPlusForkData; import org.jnode.fs.hfsplus.SuperBlock; @@ -45,7 +45,7 @@ public class Attributes { /** * The logger. */ - private static final Logger log = LogManager.getLogger(Attributes.class); + private static final Logger log = System.getLogger(Attributes.class.getName()); /** * B-Tree Header record @@ -69,7 +69,7 @@ public class Attributes { * @throws IOException if an error occurs. */ public Attributes(HfsPlusFileSystem fs) throws IOException { - log.debug("Loading the attributes file B-Tree"); + log.log(Level.DEBUG, "Loading the attributes file B-Tree"); this.fs = fs; SuperBlock sb = fs.getVolumeHeader(); attributesFile = sb.getAttributesFile(); @@ -80,13 +80,13 @@ public Attributes(HfsPlusFileSystem fs) throws IOException { attributesFile.read(fs, 0, buffer); buffer.rewind(); byte[] data = ByteBufferUtils.toArray(buffer); - log.debug("Load attributes node descriptor."); + log.log(Level.DEBUG, "Load attributes node descriptor."); NodeDescriptor btnd = new NodeDescriptor(data, 0); - log.debug(btnd.toString()); - log.debug("Load attributes header record."); + log.log(Level.DEBUG, btnd.toString()); + log.log(Level.DEBUG, "Load attributes header record."); bthr = new BTHeaderRecord(data, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); - log.debug(bthr.toString()); + log.log(Level.DEBUG, bthr.toString()); } } @@ -158,7 +158,7 @@ public AttributeData getAttribute(CatalogNodeId fileId, String attributeName, lo } else if (type == AttributeData.ATTRIBUTE_EXTENTS) { throw new UnsupportedOperationException(); } else { - log.warn(String.format("Invalid attribute record type: %d for leaf: %s", type, leafRecord)); + log.log(Level.WARNING, String.format("Invalid attribute record type: %d for leaf: %s", type, leafRecord)); return null; } } diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/catalog/Catalog.java b/fs/src/main/java/org/jnode/fs/hfsplus/catalog/Catalog.java index 4beea82810..f440ddfb54 100755 --- a/fs/src/main/java/org/jnode/fs/hfsplus/catalog/Catalog.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/catalog/Catalog.java @@ -26,8 +26,8 @@ import java.util.LinkedList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.hfsplus.HFSPlusParams; import org.jnode.fs.hfsplus.HfsPlusFileSystem; import org.jnode.fs.hfsplus.HfsPlusForkData; @@ -42,8 +42,9 @@ public class Catalog { - private final Logger log = LogManager.getLogger(getClass()); - private HfsPlusFileSystem fs; + private static final Logger log = System.getLogger(Catalog.class.getName()); + + private final HfsPlusFileSystem fs; /** * B-Tree node descriptor @@ -66,7 +67,7 @@ public class Catalog { * @throws IOException */ public Catalog(final HfsPlusFileSystem fs) throws IOException { - log.debug("Load B-Tree catalog file."); + log.log(Level.DEBUG, "Load B-Tree catalog file."); this.fs = fs; SuperBlock sb = fs.getVolumeHeader(); catalogFile = sb.getCatalogFile(); @@ -77,12 +78,12 @@ public Catalog(final HfsPlusFileSystem fs) throws IOException { catalogFile.read(fs, 0, buffer); buffer.rewind(); byte[] data = ByteBufferUtils.toArray(buffer); - log.debug("Load catalog node descriptor."); + log.log(Level.DEBUG, "Load catalog node descriptor."); btnd = new NodeDescriptor(data, 0); - log.debug(btnd.toString()); - log.debug("Load catalog header record."); + log.log(Level.DEBUG, btnd.toString()); + log.log(Level.DEBUG, "Load catalog header record."); bthr = new BTHeaderRecord(data, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); - log.debug(bthr.toString()); + log.log(Level.DEBUG, bthr.toString()); } } @@ -93,18 +94,18 @@ public Catalog(final HfsPlusFileSystem fs) throws IOException { * @param params */ public Catalog(HFSPlusParams params, HfsPlusFileSystem fs) { - log.debug("Create B-Tree catalog file."); + log.log(Level.DEBUG, "Create B-Tree catalog file."); this.fs = fs; int nodeSize = params.getCatalogNodeSize(); int bufferLength = 0; - log.debug("Create catalog node descriptor."); + log.log(Level.DEBUG, "Create catalog node descriptor."); btnd = new NodeDescriptor(0, 0, NodeDescriptor.BT_HEADER_NODE, 0, 3); - log.debug(btnd.toString()); + log.log(Level.DEBUG, btnd.toString()); bufferLength += NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH; // int totalNodes = params.getCatalogClumpSize() / params.getCatalogNodeSize(); int freeNodes = totalNodes - 2; - log.debug("Create catalog header record."); + log.log(Level.DEBUG, "Create catalog header record."); bthr = new BTHeaderRecord(1, 1, params.getInitializeNumRecords(), 1, 1, nodeSize, CatalogKey.MAXIMUM_KEY_LENGTH, totalNodes, freeNodes, @@ -112,9 +113,9 @@ public Catalog(HFSPlusParams params, HfsPlusFileSystem fs) { BTHeaderRecord.KEY_COMPARE_TYPE_CASE_FOLDING, BTHeaderRecord.BT_VARIABLE_INDEX_KEYS_MASK + BTHeaderRecord.BT_BIG_KEYS_MASK); - log.debug(bthr.toString()); + log.log(Level.DEBUG, bthr.toString()); bufferLength += BTHeaderRecord.BT_HEADER_RECORD_LENGTH; - log.debug("Create root node."); + log.log(Level.DEBUG, "Create root node."); long rootNodePosition = bthr.getRootNode() * nodeSize; bufferLength += (int) (rootNodePosition - bufferLength); CatalogLeafNode rootNode = createRootNode(params); @@ -157,7 +158,7 @@ private CatalogLeafNode createRootNode(HFSPlusParams params) { CatalogNodeId.HFSPLUS_ROOT_CNID, new HfsUnicodeString("")); record = new LeafRecord(tck, ct.getBytes()); rootNode.addNodeRecord(record); - log.debug(rootNode.toString()); + log.log(Level.DEBUG, rootNode.toString()); return rootNode; } @@ -283,7 +284,7 @@ public final LeafRecord[] getRecords(final CatalogNodeId parentID, final long no CatalogLeafNode node = new CatalogLeafNode(nodeData.array(), nodeSize); return node.findAll(new CatalogKey(parentID)); } else { - log.info(String.format("Node %d wasn't a leaf or index: %s\n%s", nodeNumber, nd, NumberUtils.hex(datas))); + log.log(Level.INFO, String.format("Node %d wasn't a leaf or index: %s\n%s", nodeNumber, nd, NumberUtils.hex(datas))); return new LeafRecord[0]; } diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/catalog/CatalogIndexNode.java b/fs/src/main/java/org/jnode/fs/hfsplus/catalog/CatalogIndexNode.java index 1bf5ad3af2..4bb6734205 100644 --- a/fs/src/main/java/org/jnode/fs/hfsplus/catalog/CatalogIndexNode.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/catalog/CatalogIndexNode.java @@ -20,13 +20,14 @@ package org.jnode.fs.hfsplus.catalog; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.hfsplus.tree.AbstractIndexNode; import org.jnode.fs.hfsplus.tree.NodeDescriptor; public class CatalogIndexNode extends AbstractIndexNode { - private final Logger log = LogManager.getLogger(getClass()); + + private static final Logger log = System.getLogger(CatalogIndexNode.class.getName()); /** * Create a new node. @@ -46,8 +47,7 @@ public CatalogIndexNode(NodeDescriptor descriptor, final int nodeSize) { */ public CatalogIndexNode(final byte[] nodeData, final int nodeSize) { super(nodeData, nodeSize); - - } + } @Override protected CatalogKey createKey(byte[] nodeData, int offset) { diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java b/fs/src/main/java/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java index 7a93e31161..2e82daadb0 100644 --- a/fs/src/main/java/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java @@ -20,15 +20,15 @@ package org.jnode.fs.hfsplus.catalog; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.hfsplus.tree.AbstractLeafNode; import org.jnode.fs.hfsplus.tree.Key; import org.jnode.fs.hfsplus.tree.LeafRecord; import org.jnode.fs.hfsplus.tree.NodeDescriptor; public class CatalogLeafNode extends AbstractLeafNode { - private static final Logger log = LogManager.getLogger(CatalogLeafNode.class); + private static final Logger log = System.getLogger(CatalogLeafNode.class.getName()); /** * Create a new node. diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/compression/LzvnForkCompression.java b/fs/src/main/java/org/jnode/fs/hfsplus/compression/LzvnForkCompression.java index a4c56588b1..be4701cff4 100644 --- a/fs/src/main/java/org/jnode/fs/hfsplus/compression/LzvnForkCompression.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/compression/LzvnForkCompression.java @@ -3,8 +3,8 @@ import java.io.IOException; import java.nio.ByteBuffer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.hfsplus.HfsPlusFile; import org.jnode.fs.hfsplus.HfsPlusFileSystem; import org.jnode.fs.hfsplus.attributes.AttributeData; @@ -24,7 +24,7 @@ public class LzvnForkCompression implements HfsPlusCompression { /** * The logger for this class. */ - private static final Logger log = LogManager.getLogger(LzvnForkCompression.class); + private static final Logger log = System.getLogger(LzvnForkCompression.class.getName()); /** * The LZVN fork compression chunk size. @@ -155,7 +155,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr do { switch (jmpTo) { case LZVN_CASE_TABLE: - log.debug(String + log.log(Level.DEBUG, String .format("caseTable[%d]", LzvnForkCompression.CASE_TABLE[FSUtils.checkedCast(caseTableIndex)])); switch (LzvnForkCompression.CASE_TABLE[FSUtils.checkedCast(caseTableIndex)]) { @@ -276,7 +276,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr break; case LZVN_0: - log.debug("jmpTable(0)"); + log.log(Level.DEBUG, "jmpTable(0)"); currentLength = destOffset + sourceValue; sourceValue = -sourceValue; @@ -287,7 +287,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr } case LZVN_1: - log.debug("jmpTable(1)"); + log.log(Level.DEBUG, "jmpTable(1)"); do { address = sourceOffset + sourceValue; @@ -308,12 +308,12 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr break; case LZVN_2: - log.debug("jmpTable(2)"); + log.log(Level.DEBUG, "jmpTable(2)"); currentLength = (decompressedSize + 8); case LZVN_3: - log.debug("jmpTable(3)"); + log.log(Level.DEBUG, "jmpTable(3)"); do { address = sourceOffset + sourceValue; @@ -337,14 +337,14 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr break; case LZVN_4: - log.debug("jmpTable(4)"); + log.log(Level.DEBUG, "jmpTable(4)"); currentLength = (decompressedSize + 8); jmpTo = LZVN_9; break; case LZVN_5: - log.debug("jmpTable(5)"); + log.log(Level.DEBUG, "jmpTable(5)"); do { address = sourceValue; @@ -365,7 +365,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr break; case LZVN_6: - log.debug("jmpTable(6)"); + log.log(Level.DEBUG, "jmpTable(6)"); do { uncompressedBuffer[FSUtils.checkedCast(destOffset)] = (byte) (sourceValue & 0xff); @@ -381,7 +381,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr } while (caseTableIndex != 1); case LZVN_7: - log.debug("jmpTable(7)"); + log.log(Level.DEBUG, "jmpTable(7)"); sourceValue = destOffset; sourceValue -= negativeOffset; @@ -394,7 +394,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr break; case LZVN_8: - log.debug("jmpTable(8)"); + log.log(Level.DEBUG, "jmpTable(8)"); if (caseTableIndex == 0) { jmpTo = LZVN_7; @@ -406,7 +406,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr break; case LZVN_9: - log.debug("jmpTable(9)"); + log.log(Level.DEBUG, "jmpTable(9)"); do { address = sourceValue; @@ -431,7 +431,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr break; case LZVN_10: - log.debug("jmpTable(10)"); + log.log(Level.DEBUG, "jmpTable(10)"); currentLength = (destOffset + caseTableIndex); currentLength += byteCount; @@ -460,7 +460,7 @@ public static int lzvnDecode(ByteBuffer compressedByteBuffer, ByteBuffer decompr break; case LZVN_11: - log.debug("jmpTable(11)"); + log.log(Level.DEBUG, "jmpTable(11)"); sourceValue = destOffset; sourceValue -= negativeOffset; diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/extent/Extent.java b/fs/src/main/java/org/jnode/fs/hfsplus/extent/Extent.java index 1912e7c7bc..faf3e9bd66 100644 --- a/fs/src/main/java/org/jnode/fs/hfsplus/extent/Extent.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/extent/Extent.java @@ -26,8 +26,8 @@ import java.util.LinkedList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.hfsplus.HFSPlusParams; import org.jnode.fs.hfsplus.HfsPlusFileSystem; import org.jnode.fs.hfsplus.HfsPlusForkData; @@ -39,7 +39,8 @@ import org.jnode.util.NumberUtils; public class Extent { - private final Logger log = LogManager.getLogger(getClass()); + + private static final Logger log = System.getLogger(Extent.class.getName()); /** * B-Tree node descriptor @@ -64,7 +65,7 @@ public class Extent { private ByteBuffer buffer; public Extent(HFSPlusParams params) { - log.debug("Create B-Tree extent file."); + log.log(Level.DEBUG, "Create B-Tree extent file."); btnd = new NodeDescriptor(0, 0, NodeDescriptor.BT_HEADER_NODE, 0, 3); // int totalNodes = params.getExtentClumpSize() / params.getExtentNodeSize(); @@ -77,7 +78,7 @@ public Extent(HFSPlusParams params) { } public Extent(HfsPlusFileSystem fs) throws IOException { - log.debug("Load B-Tree extent overflow file."); + log.log(Level.DEBUG, "Load B-Tree extent overflow file."); this.fs = fs; SuperBlock sb = fs.getVolumeHeader(); extentFile = sb.getExtentsFile(); @@ -88,12 +89,12 @@ public Extent(HfsPlusFileSystem fs) throws IOException { extentFile.read(fs, 0, buffer); buffer.rewind(); byte[] data = ByteBufferUtils.toArray(buffer); - log.debug("Load extent node descriptor."); + log.log(Level.DEBUG, "Load extent node descriptor."); btnd = new NodeDescriptor(data, 0); - log.debug(btnd.toString()); - log.debug("Load extent header record."); + log.log(Level.DEBUG, btnd.toString()); + log.log(Level.DEBUG, "Load extent header record."); bthr = new BTHeaderRecord(data, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); - log.debug(bthr.toString()); + log.log(Level.DEBUG, bthr.toString()); } } @@ -141,7 +142,7 @@ public final ExtentDescriptor[] getOverflowExtents(final ExtentKey key, long nod return node.getOverflowExtents(key); } else { - log.info(String.format("Node %d wasn't a leaf or index: %s\n%s", nodeNumber, nd, NumberUtils.hex(data))); + log.log(Level.INFO, String.format("Node %d wasn't a leaf or index: %s\n%s", nodeNumber, nd, NumberUtils.hex(data))); return new ExtentDescriptor[0]; } diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/tree/AbstractLeafNode.java b/fs/src/main/java/org/jnode/fs/hfsplus/tree/AbstractLeafNode.java index 44d7075e58..da725dadeb 100644 --- a/fs/src/main/java/org/jnode/fs/hfsplus/tree/AbstractLeafNode.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/tree/AbstractLeafNode.java @@ -23,12 +23,12 @@ import java.util.LinkedList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; public abstract class AbstractLeafNode extends AbstractNode { - private static final Logger log = LogManager.getLogger(AbstractLeafNode.class); + private static final Logger log = System.getLogger(AbstractLeafNode.class.getName()); /** * Create a new node. @@ -58,7 +58,7 @@ protected LeafRecord createRecord(Key key, byte[] nodeData, int offset, int reco public final LeafRecord[] findAll(K key) { List list = new LinkedList<>(); for (LeafRecord record : records) { - log.debug("Record: " + record.toString() + " Key: " + key); + log.log(Level.DEBUG, "Record: " + record.toString() + " Key: " + key); @SuppressWarnings("unchecked") K recordKey = (K) record.getKey(); if (recordKey != null && recordKey.equals(key)) { diff --git a/fs/src/main/java/org/jnode/fs/hfsplus/tree/AbstractNode.java b/fs/src/main/java/org/jnode/fs/hfsplus/tree/AbstractNode.java index 377010b16a..424771ad07 100644 --- a/fs/src/main/java/org/jnode/fs/hfsplus/tree/AbstractNode.java +++ b/fs/src/main/java/org/jnode/fs/hfsplus/tree/AbstractNode.java @@ -23,12 +23,14 @@ import java.util.ArrayList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.BigEndian; public abstract class AbstractNode implements Node { - private final Logger log = LogManager.getLogger(getClass()); + + private static final Logger log = System.getLogger(AbstractNode.class.getName()); + protected NodeDescriptor descriptor; protected List records; protected List offsets; @@ -53,9 +55,7 @@ public AbstractNode(final byte[] nodeData, final int nodeSize) { offsets.add(offset); } - if (log.isDebugEnabled()) { - log.debug("Creating node for: " + descriptor.toString() + " offsets: " + offsets); - } + log.log(Level.DEBUG, "Creating node for: " + descriptor.toString() + " offsets: " + offsets); loadRecords(nodeData); } @@ -73,9 +73,7 @@ private void loadRecords(final byte[] nodeData) { int recordSize = offsets.get(i + 1) - offset; records.add(createRecord(key, nodeData, offset, recordSize)); - if (log.isDebugEnabled()) { - log.debug("Loading record: " + key); - } + log.log(Level.DEBUG, "Loading record: " + key); } } @@ -122,7 +120,7 @@ public T getNodeRecord(int index) { */ public final T find(K key) { for (T record : records) { - log.debug("Record: " + record.toString() + " Key: " + key); + log.log(Level.DEBUG, "Record: " + record.toString() + " Key: " + key); @SuppressWarnings("unchecked") K recordKey = (K) record.getKey(); if (recordKey != null && recordKey.equals(key)) { diff --git a/fs/src/main/java/org/jnode/fs/iso9660/ISO9660Directory.java b/fs/src/main/java/org/jnode/fs/iso9660/ISO9660Directory.java index c771e93619..ec14ab29e5 100644 --- a/fs/src/main/java/org/jnode/fs/iso9660/ISO9660Directory.java +++ b/fs/src/main/java/org/jnode/fs/iso9660/ISO9660Directory.java @@ -47,7 +47,7 @@ public ISO9660Directory(ISO9660Entry entry) { * @see org.jnode.fs.FSDirectory#iterator() */ public Iterator iterator() throws IOException { - return new Iterator() { + return new Iterator<>() { int offset = 0; @@ -62,7 +62,7 @@ public boolean hasNext() { public FSEntry next() { final ISO9660Volume volume = parent.getVolume(); final EntryRecord fEntry = - new EntryRecord(volume, buffer, offset + 1, parent.getEncoding()); + new EntryRecord(volume, buffer, offset + 1, parent.getEncoding()); offset += fEntry.getLengthOfDirectoryEntry(); return new ISO9660Entry((ISO9660FileSystem) entry.getFileSystem(), fEntry); } diff --git a/fs/src/main/java/org/jnode/fs/iso9660/ISO9660Volume.java b/fs/src/main/java/org/jnode/fs/iso9660/ISO9660Volume.java index 0a6b58a768..296d78e0cc 100644 --- a/fs/src/main/java/org/jnode/fs/iso9660/ISO9660Volume.java +++ b/fs/src/main/java/org/jnode/fs/iso9660/ISO9660Volume.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.nio.ByteBuffer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.block.BlockDeviceAPI; import org.jnode.driver.block.FSBlockDeviceAPI; @@ -34,7 +34,7 @@ */ public class ISO9660Volume implements ISO9660Constants { - private static final Logger bootlog = LogManager.getLogger("bootlog"); + private static final Logger bootlog = System.getLogger("bootlog"); private final BlockDeviceAPI api; @@ -68,15 +68,15 @@ public ISO9660Volume(FSBlockDeviceAPI api) throws IOException { done = true; break; case VolumeDescriptorType.BOOTRECORD: - bootlog.debug("Found boot record"); + bootlog.log(Level.DEBUG, "Found boot record"); break; case VolumeDescriptorType.PRIMARY_DESCRIPTOR: - bootlog.debug("Found primary descriptor"); + bootlog.log(Level.DEBUG, "Found primary descriptor"); pVD = new PrimaryVolumeDescriptor(this, buffer); // pVD.dump(System.out); break; case VolumeDescriptorType.SUPPLEMENTARY_DESCRIPTOR: - bootlog.debug("Found supplementatory descriptor"); + bootlog.log(Level.DEBUG, "Found supplementatory descriptor"); final SupplementaryVolumeDescriptor d = new SupplementaryVolumeDescriptor(this, buffer); if (d.isEncodingKnown()) { @@ -84,10 +84,10 @@ public ISO9660Volume(FSBlockDeviceAPI api) throws IOException { } break; case VolumeDescriptorType.PARTITION_DESCRIPTOR: - bootlog.debug("Found partition descriptor"); + bootlog.log(Level.DEBUG, "Found partition descriptor"); break; default: - bootlog.debug("Found unknown descriptor with type " + type); + bootlog.log(Level.DEBUG, "Found unknown descriptor with type " + type); } } if (pVD == null) { diff --git a/fs/src/main/java/org/jnode/fs/iso9660/SupplementaryVolumeDescriptor.java b/fs/src/main/java/org/jnode/fs/iso9660/SupplementaryVolumeDescriptor.java index c00e5ba458..056ff9c2d6 100644 --- a/fs/src/main/java/org/jnode/fs/iso9660/SupplementaryVolumeDescriptor.java +++ b/fs/src/main/java/org/jnode/fs/iso9660/SupplementaryVolumeDescriptor.java @@ -23,15 +23,15 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; /** * @author Ewout Prangsma (epr@users.sourceforge.net) */ public class SupplementaryVolumeDescriptor extends VolumeDescriptor { - private static final Logger bootlog = LogManager.getLogger("bootlog"); + private static final Logger bootlog = System.getLogger("bootlog"); private final int flags; private final String encoding; @@ -61,7 +61,7 @@ public SupplementaryVolumeDescriptor(ISO9660Volume volume, byte[] buffer) } catch (UnsupportedEncodingException ex) { encoding = DEFAULT_ENCODING; encodingKnown = false; - bootlog.warn("Unsupported encoding, escapeSequences: '" + escapeSequences + "'"); + bootlog.log(Level.WARNING, "Unsupported encoding, escapeSequences: '" + escapeSequences + "'"); } this.encoding = encoding; this.encodingKnown = encodingKnown; diff --git a/fs/src/main/java/org/jnode/fs/jfat/ATBootSector.java b/fs/src/main/java/org/jnode/fs/jfat/ATBootSector.java index a6ffb64990..4de227beb6 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/ATBootSector.java +++ b/fs/src/main/java/org/jnode/fs/jfat/ATBootSector.java @@ -22,10 +22,9 @@ import java.io.IOException; import java.nio.ByteBuffer; -import java.util.logging.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.block.BlockDeviceAPI; import org.jnode.partitions.ibm.IBMPartitionTable; import org.jnode.util.LittleEndian; @@ -40,7 +39,7 @@ */ public class ATBootSector implements BootSector { @SuppressWarnings("unused") - private static final Logger log = LogManager.getLogger(ATBootSector.class); + private static final Logger log = System.getLogger(ATBootSector.class.getName()); private static final int IFAT12 = 12; private static final int IFAT16 = 16; @@ -128,8 +127,9 @@ public boolean isaValidBootSector() { @Override public synchronized void read(BlockDeviceAPI device) throws IOException { device.read(0, ByteBuffer.wrap(sector)); -Debug.println(Level.FINE, "bpb:\n" + StringUtil.getDump(sector, 256)); +log.log(Level.DEBUG, "bpb:\n" + StringUtil.getDump(sector, 256)); decode(); +log.log(Level.DEBUG, "bpb:\n" + this); dirty = false; } @@ -166,7 +166,7 @@ else if (CountOfClusters < SZFAT16) else type = IFAT32; -Debug.println(Level.INFO, "type: " + type); +log.log(Level.INFO, "type: " + type); if (isFat32()) { FirstDataSector = BPB_RsvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors; } else { @@ -324,16 +324,12 @@ protected void setBytes(int offset, int len, byte[] value) { @Override public String fatType() { - switch (type) { - case IFAT12: - return SFAT12; - case IFAT16: - return SFAT16; - case IFAT32: - return SFAT32; - default: - return ""; - } + return switch (type) { + case IFAT12 -> SFAT12; + case IFAT16 -> SFAT16; + case IFAT32 -> SFAT32; + default -> ""; + }; } @Override @@ -398,7 +394,7 @@ public int getNrFats() { @Override public long getRootDirectoryStartCluster() { -Debug.println(Level.INFO, "BPB_RootClus: " + BPB_RootClus); +log.log(Level.INFO, "BPB_RootClus: " + BPB_RootClus); return BPB_RootClus; } diff --git a/fs/src/main/java/org/jnode/fs/jfat/Fat.java b/fs/src/main/java/org/jnode/fs/jfat/Fat.java index 4339bf207f..0206bc11d4 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/Fat.java +++ b/fs/src/main/java/org/jnode/fs/jfat/Fat.java @@ -122,7 +122,7 @@ public final long getFirst(int fatnum) { } public final long getLast(int fatnum) { - return getLast(fatnum) + offset(size() - 1); + return getLastSector(fatnum) + offset(size() - 1); } protected final long position(int fatnum, int index) throws IOException { @@ -136,7 +136,7 @@ public void readCluster(int cluster, int offset, ByteBuffer dst) throws IOExcept if (offset < 0) { throw new IllegalArgumentException("offset<0"); } -Debug.println(Level.FINE, "cluster: " + cluster); +Debug.println(Level.FINER, "cluster: " + cluster); if ((offset + dst.remaining()) > getClusterSize()) { throw new IllegalArgumentException("length[" + (offset + dst.remaining()) + "] " + "exceed clusterSize[" + getClusterSize() + "]"); diff --git a/fs/src/main/java/org/jnode/fs/jfat/Fat16.java b/fs/src/main/java/org/jnode/fs/jfat/Fat16.java index 9c50f239b0..bc48ac1d4a 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/Fat16.java +++ b/fs/src/main/java/org/jnode/fs/jfat/Fat16.java @@ -57,7 +57,7 @@ public long getClusterPosition(int index) { BootSector bootSector = getBootSector(); long rootDirectoryOffset = bootSector.getFirstDataSector() * bootSector.getBytesPerSector(); -Debug.printf(Level.FINE, "fat[" + index + "]: offset: %08x%n", rootDirectoryOffset); +Debug.printf(Level.FINER, "fat[" + index + "]: offset: %08x%n", rootDirectoryOffset); if (index == 0) { return rootDirectoryOffset; } diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatCase.java b/fs/src/main/java/org/jnode/fs/jfat/FatCase.java index 8b966b7170..34ee334cf8 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatCase.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatCase.java @@ -42,13 +42,13 @@ public FatCase(int ncase) { } public FatCase(String baseName, String extName) { - if (baseName.length() == 0) + if (baseName.isEmpty()) throw new UnsupportedOperationException("empty baseName"); final boolean baseIsUpper = FatUtils.isUpperCase(baseName); final boolean baseIsLower = FatUtils.isLowerCase(baseName); - if (extName.length() == 0) { + if (extName.isEmpty()) { if (baseIsLower) ncase = LOWER_UPPER; else diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatChain.java b/fs/src/main/java/org/jnode/fs/jfat/FatChain.java index a0f9af4644..ce371223cc 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatChain.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatChain.java @@ -26,8 +26,8 @@ import java.nio.ByteBuffer; import java.util.NoSuchElementException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FileSystemFullException; /** @@ -35,7 +35,7 @@ * */ public class FatChain { - private static final Logger log = LogManager.getLogger(FatChain.class); + private static final Logger log = System.getLogger(FatChain.class.getName()); private final FatFileSystem fs; private final Fat fat; @@ -61,7 +61,7 @@ public FatChain(FatFileSystem fs, int startEntry) { } private void mylog(String msg) { - log.debug(msg); + log.log(Level.DEBUG, msg); } public FatFileSystem getFatFileSystem() { @@ -514,7 +514,7 @@ public String toString() { out.print(">]"); } catch (IOException ex) { - log.debug("error in chain"); + log.log(Level.DEBUG, "error in chain"); out.print("error in chain"); } diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatEntriesFactory.java b/fs/src/main/java/org/jnode/fs/jfat/FatEntriesFactory.java index b4fbc4c457..21848ebf82 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatEntriesFactory.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatEntriesFactory.java @@ -3,12 +3,12 @@ import java.io.IOException; import java.util.NoSuchElementException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; public class FatEntriesFactory { - private static final Logger log = LogManager.getLogger(FatEntriesFactory.class); + private static final Logger log = System.getLogger(FatEntriesFactory.class.getName()); private boolean label; private int index; @@ -32,7 +32,7 @@ protected boolean hasNextEntry() { FatRecord v = new FatRecord(); if (index > FatDirectory.MAXENTRIES) - log.debug("Full Directory: invalid index " + index); + log.log(Level.DEBUG, "Full Directory: invalid index " + index); for (i = index;; ) { /* @@ -45,7 +45,7 @@ protected boolean hasNextEntry() { entry = null; return false; } catch (IOException ex) { - log.debug("cannot read entry " + i); + log.log(Level.DEBUG, "cannot read entry " + i); i++; continue; } @@ -60,7 +60,7 @@ protected boolean hasNextEntry() { } else if (e.isLongDirEntry()) { FatLongDirEntry l = (FatLongDirEntry) e; if (l.isDamaged()) { - log.debug("Damaged entry at " + (i - 1)); + log.log(Level.DEBUG, "Damaged entry at " + (i - 1)); v.clear(); } else { v.add(l); @@ -71,13 +71,13 @@ protected boolean hasNextEntry() { if (directory.isRoot()) { FatRootDirectory r = (FatRootDirectory) directory; if (label) { - log.debug("Duplicated label in root directory"); + log.log(Level.DEBUG, "Duplicated label in root directory"); } else { r.setEntry(s); label = true; } } else { - log.debug("Volume label in non root directory"); + log.log(Level.DEBUG, "Volume label in non root directory"); } } else { break; diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatEntry.java b/fs/src/main/java/org/jnode/fs/jfat/FatEntry.java index 79818e606d..842f2444a5 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatEntry.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatEntry.java @@ -25,8 +25,8 @@ import java.util.Arrays; import java.util.Vector; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSAccessRights; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; @@ -36,7 +36,8 @@ import org.jnode.util.NumberUtils; public class FatEntry extends FatObject implements FSEntry, FSEntryCreated, FSEntryLastAccessed { - private static final Logger log = LogManager.getLogger(FatEntry.class); + + private static final Logger log = System.getLogger(FatEntry.class.getName()); private String name; private FatRecord record; @@ -223,7 +224,7 @@ public String getPath() { StringBuilder path = new StringBuilder(1024); FatDirectory parent = getParent(); - if (getName().length() != 0) + if (!getName().isEmpty()) path.append(getName()); else path.append("\\"); @@ -258,7 +259,7 @@ public String toStringValue() { out.println("Chain\t\t" + getChain()); out.print("---------------------------------------"); } catch (IOException ex) { - log.debug("entry error"); + log.log(Level.DEBUG, "entry error"); out.print("entry error"); } diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatFile.java b/fs/src/main/java/org/jnode/fs/jfat/FatFile.java index c8afbc909a..82bcf16026 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatFile.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatFile.java @@ -24,13 +24,13 @@ import java.nio.ByteBuffer; import java.util.NoSuchElementException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSFile; import org.jnode.fs.FSFileSlackSpace; public class FatFile extends FatEntry implements FSFile, FSFileSlackSpace { - private static final Logger log = LogManager.getLogger(FatFile.class); + private static final Logger log = System.getLogger(FatFile.class.getName()); public FatFile(FatFileSystem fs, FatDirectory parent, FatRecord record) { super(fs, parent, record); @@ -89,7 +89,7 @@ public void read(long offset, ByteBuffer dst) throws IOException { getChain().read(offset, dst); } catch (NoSuchElementException ex) { - log.debug("End Of Chain reached: shouldn't happen"); + log.log(Level.DEBUG, "End Of Chain reached: shouldn't happen"); } finally { dst.limit(limit); } diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatFileSystem.java b/fs/src/main/java/org/jnode/fs/jfat/FatFileSystem.java index b35a03af56..26d68caa64 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatFileSystem.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatFileSystem.java @@ -22,8 +22,8 @@ import java.io.IOException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; @@ -35,9 +35,10 @@ * @author gvt */ public class FatFileSystem extends AbstractFileSystem { - private static final Logger log = LogManager.getLogger(FatFileSystem.class); - private Fat fat; + private static final Logger log = System.getLogger(FatFileSystem.class.getName()); + + private final Fat fat; private final CodePage cp; public FatFileSystem(Device device, BootSector bs, String codePageName, boolean readOnly) @@ -88,7 +89,7 @@ protected FatRootDirectory createRootEntry() throws IOException { public void flush() throws IOException { super.flush(); fat.flush(); - log.debug(getFat().getCacheStat()); + log.log(Level.DEBUG, getFat().getCacheStat()); } @Override diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatFileSystemFormatter.java b/fs/src/main/java/org/jnode/fs/jfat/FatFileSystemFormatter.java index f3cb65529e..20200d2779 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatFileSystemFormatter.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatFileSystemFormatter.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.util.NoSuchElementException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.ApiNotFoundException; import org.jnode.driver.Device; import org.jnode.driver.block.BlockDeviceAPI; @@ -40,7 +40,7 @@ * @author Tango */ public class FatFileSystemFormatter extends Formatter { - private static final Logger log = LogManager.getLogger(FatFileSystemFormatter.class); + private static final Logger log = System.getLogger(FatFileSystemFormatter.class.getName()); public static final int SECTOR_SIZE = 512; @@ -61,7 +61,7 @@ public FatFileSystem format(Device device) throws FileSystemException { int sectorSize = api.getSectorSize(); if (sectorSize != SECTOR_SIZE) { - log.error("This mkjfat1.0 support only the Hard Disk.Sector Size must " + + log.log(Level.ERROR, "This mkjfat1.0 support only the Hard Disk.Sector Size must " + SECTOR_SIZE + " bytes.\n"); } @@ -83,7 +83,7 @@ public FatFileSystem format(Device device) throws FileSystemException { * just fine, but the spec says that we shouldn't do this, so we won't. */ if (numberOfSectors < 65536) { - log.error("This drive is too small for FAT32 - there must be at least 64K clusters\n"); + log.log(Level.ERROR, "This drive is too small for FAT32 - there must be at least 64K clusters\n"); } /* @@ -96,7 +96,7 @@ public FatFileSystem format(Device device) throws FileSystemException { * Perhaps a future version of FAT32 and FASTFAT will handle this. */ if (numberOfSectors >= (Math.pow(2, 32) - 1)) { - log.error("This drive is too big for FAT32 - max 2TB supported :" + numberOfSectors); + log.log(Level.ERROR, "This drive is too big for FAT32 - max 2TB supported :" + numberOfSectors); } // The FAT32 Formatter class constructor diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatFormatter.java b/fs/src/main/java/org/jnode/fs/jfat/FatFormatter.java index c3b78e709f..2ba642e7cd 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatFormatter.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatFormatter.java @@ -44,10 +44,11 @@ import java.nio.ByteBuffer; import java.util.Date; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.block.BlockDeviceAPI; import org.jnode.util.LittleEndian; +import vavi.emu.disk.FAT; import static java.lang.Integer.toHexString; @@ -72,7 +73,7 @@ * */ public class FatFormatter { - private static final Logger log = LogManager.getLogger(FatFormatter.class); + private static final Logger log = System.getLogger(FatFormatter.class.getName()); /** The Device Identifier for Floppy Device */ public static final int FLOPPY_DESC = 0xf0; @@ -183,10 +184,8 @@ public FatFormatter(int mediumDescriptor, int sectorSize, int nbTotalSectors, api.flush(); int DiskSize = getDiskSize(nbTotalSectors, sectorSize); int SectorPerCluster = get_spc(ClusterSize, sectorSize); - int UserAreaSize = - getUserAreaSize(nbTotalSectors, ReservedSectorCount, NumOfFATs, ClusterSize); - this.FatSize = - getFATSizeSectors(nbTotalSectors, ReservedSectorCount, SectorPerCluster, NumOfFATs, + int UserAreaSize = getUserAreaSize(nbTotalSectors, ReservedSectorCount, NumOfFATs, ClusterSize); + this.FatSize = getFATSizeSectors(nbTotalSectors, ReservedSectorCount, SectorPerCluster, NumOfFATs, sectorSize); // fill out the boot sector and fs info @@ -233,57 +232,47 @@ public FatFormatter(int mediumDescriptor, int sectorSize, int nbTotalSectors, fsInfo.setReserve2(); fsInfo.setFsInfo_TrailSig(FSI_TrailSig); - /** - * TODO:This portion need modofication for the Disk Size Handlings Not - * So mandatory now .WIll look into it. Work out the Cluster Count - */ + // TODO:This portion need modofication for the Disk Size Handlings Not + // So mandatory now .WIll look into it. Work out the Cluster Count long FatNeeded = UserAreaSize / SectorPerCluster; - /** - * check for a cluster count of >2^28, since the upper 4 bits of the - * cluster values in the FAT are reserved - */ + // check for a cluster count of >2^28, since the upper 4 bits of the + // cluster values in the FAT are reserved if (FatNeeded > Math.pow(2, 28)) { - log - .error("This drive has more than 2^28 clusters, try to specify a larger cluster size\n"); + log.log(Level.ERROR, "This drive has more than 2^28 clusters, try to specify a larger cluster size\n"); } - /** - * Once zero_sectors has run, any data on the drive is basically - * lost.... First zero out ReservedSect + FatSize * NumFats + - * SectorsPerCluster - * - */ + // Once zero_sectors has run, any data on the drive is basically + // lost.... First zero out ReservedSect + FatSize * NumFats + + // SectorsPerCluster int SystemAreaSize = (ReservedSectorCount + (NumOfFATs * FatSize) + SectorPerCluster); - log.info("Clearing out " + SystemAreaSize + + log.log(Level.INFO, "Clearing out " + SystemAreaSize + " sectors for Reserved sectors, fats and root cluster...\n"); - /** Disk Freeing */ + // Disk Freeing try { setQuickSectorFree(SystemAreaSize, api); } catch (IOException e1) { - log.info("Error ocured during Disk Free."); + log.log(Level.INFO, "Error ocured during Disk Free."); } - /** calling the Format method */ + // calling the Format method try { - log.info("Initialising reserved sectors and FATs...."); + log.log(Level.INFO, "Initialising reserved sectors and FATs...."); format(api, bs, fsInfo, SectorPerCluster, nbTotalSectors); } catch (IOException e) { - log.error("Problems in Disk Formatting."); + log.log(Level.ERROR, "Problems in Disk Formatting."); } - /** - * The mkjfat informations group - */ + // The mkjfat informations group int DiskSizeGB = DiskSize / (1000 * 1000 * 1000); - log.info("Size(Bytes): " + DiskSize + "\tSize(GB): " + DiskSizeGB + "\tSectors :" + + log.log(Level.INFO, "Size(Bytes): " + DiskSize + "\tSize(GB): " + DiskSizeGB + "\tSectors :" + nbTotalSectors); - log.info("Volume ID is :" + toHexString(VolumeID >> 16) + ":" + + log.log(Level.INFO, "Volume ID is :" + toHexString(VolumeID >> 16) + ":" + toHexString(VolumeID & 0xffff)); - log.info(sectorSize + " Bytes Per Sector , Cluster Size " + ClusterSize + " bytes."); - log.info(ReservedSectorCount + " Reserved Sectors ," + (FatSize) + " Sectors Per FAT ," + + log.log(Level.INFO, sectorSize + " Bytes Per Sector , Cluster Size " + ClusterSize + " bytes."); + log.log(Level.INFO, ReservedSectorCount + " Reserved Sectors ," + (FatSize) + " Sectors Per FAT ," + NumOfFATs + " FATs."); - log.info("Total Clusters :" + (UserAreaSize / SectorPerCluster)); - log.info("Free Clusters: " + FSI_FreeCount); + log.log(Level.INFO, "Total Clusters :" + (UserAreaSize / SectorPerCluster)); + log.log(Level.INFO, "Free Clusters: " + FSI_FreeCount); // Flushing the DeviceAPI api.flush(); @@ -297,17 +286,15 @@ public FatFormatter(int mediumDescriptor, int sectorSize, int nbTotalSectors, */ public void format(BlockDeviceAPI api, BootSector bs, FatFsInfo fsInfo, int sectorPerCluster, int nbTotalSectors) throws IOException { - log.info("The Formatting...\n"); - /** - * Now we should write the boot sector and fsinfo twice, once at 0 and - * once at the backup boot sect position - */ + log.log(Level.INFO, "The Formatting...\n"); + // Now we should write the boot sector and fsinfo twice, once at 0 and + // once at the backup boot sect position for (int i = 0; i < 2; i++) { int SectorStart = (i == 0) ? 0 : (BackupBootSector * 512); bs.write(api, SectorStart); // Write the BootSector fsInfo.write(api, (long) SectorStart + 512); } - /** Write the first fat sector in the right places */ + // Write the first fat sector in the right places for (int i = 0; i < NumOfFATs; i++) { int SectorStart = (ReservedSectorCount + (i * FatSize)) * 512; this.reservedSector = new byte[12]; @@ -315,9 +302,7 @@ public void format(BlockDeviceAPI api, BootSector bs, FatFsInfo fsInfo, int sect LittleEndian.setInt32(this.reservedSector, 4, ReservedSector_1); LittleEndian.setInt32(this.reservedSector, 8, ReservedSector_2); api.write(SectorStart, ByteBuffer.wrap(this.reservedSector)); - } - } /** @@ -405,8 +390,7 @@ public int getFATSizeSectors(int TotalSectorNumber, int ReservedSecCnt, int SecP * @param FATSize * @return */ - private int getUserAreaSize(int TotalSectors, int ReservedSectorCount, int NumFATs, - ClusterSize FATSize) { + private int getUserAreaSize(int TotalSectors, int ReservedSectorCount, int NumFATs, ClusterSize FATSize) { int UserAreaSize = TotalSectors - ReservedSectorCount - (NumFATs * FATSize.getSize()); return (UserAreaSize); } @@ -420,5 +404,4 @@ private int getUserAreaSize(int TotalSectors, int ReservedSectorCount, int NumFA private int getDiskSize(int TotalSectors, int sectorSize) { return (TotalSectors * sectorSize); } - } diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatName.java b/fs/src/main/java/org/jnode/fs/jfat/FatName.java index 8de61ebe39..97d6e5eb71 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatName.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatName.java @@ -124,7 +124,7 @@ public class FatName { shortCase = new FatCase(shortBase, shortExt); } - if (shortExt.length() > 0) + if (!shortExt.isEmpty()) shortName = shortBase + "." + shortExt; else shortName = shortBase; diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatRecord.java b/fs/src/main/java/org/jnode/fs/jfat/FatRecord.java index a5d4c8c673..94ffe43eed 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatRecord.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatRecord.java @@ -23,12 +23,13 @@ import java.io.IOException; import java.util.Vector; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.NumberUtils; public class FatRecord { - private static final Logger log = LogManager.getLogger(FatRecord.class); + + private static final Logger log = System.getLogger(FatRecord.class.getName()); private static final int MAXLONGENTRIES = 20; @@ -145,13 +146,13 @@ public void close(FatShortDirEntry entry) { int ordinal = last - i + 1; if (l.getOrdinal() != ordinal && !l.isFreeDirEntry()) { - log.debug("ordinal orphaned vector discarded for " + getShortName()); + log.log(Level.DEBUG, "ordinal orphaned vector discarded for " + getShortName()); clearLongEntries(); return; } if (l.getChkSum() != chkSum && !l.isFreeDirEntry()) { - log.debug("chksum orphaned vector discarded for " + getShortName()); + log.log(Level.DEBUG, "chksum orphaned vector discarded for " + getShortName()); clearLongEntries(); return; } diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatShortDirEntry.java b/fs/src/main/java/org/jnode/fs/jfat/FatShortDirEntry.java index 32f97f6d0a..eda86d41e3 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatShortDirEntry.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatShortDirEntry.java @@ -24,15 +24,16 @@ import java.nio.charset.CharacterCodingException; import java.util.Arrays; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.NumberUtils; /** * @author gvt */ public class FatShortDirEntry extends FatDirEntry { - private static final Logger log = LogManager.getLogger(FatShortDirEntry.class); + + private static final Logger log = System.getLogger(FatShortDirEntry.class.getName()); /* * encoded side @@ -127,8 +128,8 @@ protected void decodeBase() { try { baseName = getFatFileSystem().getCodePage().newDecoder().decode(basebuf); } catch (CharacterCodingException ex) { - log.debug("CharacterCodingException: CodePage error"); - log.debug("go on with standard decoding"); + log.log(Level.DEBUG, "CharacterCodingException: CodePage error"); + log.log(Level.DEBUG, "go on with standard decoding"); baseName = base; } @@ -147,8 +148,8 @@ protected void decodeExt() { try { extName = getFatFileSystem().getCodePage().newDecoder().decode(extbuf); } catch (CharacterCodingException ex) { - log.debug("CharacterCodingException: CodePage error"); - log.debug("go on with standard decoding"); + log.log(Level.DEBUG, "CharacterCodingException: CodePage error"); + log.log(Level.DEBUG, "go on with standard decoding"); extName = ext; } @@ -419,8 +420,8 @@ public String getLabel() { try { label = getFatFileSystem().getCodePage().newDecoder().decode(lName); } catch (CharacterCodingException ex) { - log.debug("CharacterCodingException: CodePage error"); - log.debug("go on with standard decoding"); + log.log(Level.DEBUG, "CharacterCodingException: CodePage error"); + log.log(Level.DEBUG, "go on with standard decoding"); label = new String(lName); } @@ -431,7 +432,7 @@ public String getShortName() { String base = getBase(); String ext = getExt(); - if (ext.length() > 0) + if (!ext.isEmpty()) return base + "." + ext; else return base; diff --git a/fs/src/main/java/org/jnode/fs/jfat/FatUtils.java b/fs/src/main/java/org/jnode/fs/jfat/FatUtils.java index 11a55d5e4e..5745024a45 100644 --- a/fs/src/main/java/org/jnode/fs/jfat/FatUtils.java +++ b/fs/src/main/java/org/jnode/fs/jfat/FatUtils.java @@ -128,7 +128,7 @@ public static String toUpperCase(String s) { } public static boolean isLowerCase(String s) { - if (s.length() == 0) + if (s.isEmpty()) return false; char[] ca = s.toCharArray(); @@ -141,7 +141,7 @@ public static boolean isLowerCase(String s) { } public static boolean isUpperCase(String s) { - if (s.length() == 0) + if (s.isEmpty()) return false; char[] ca = s.toCharArray(); diff --git a/fs/src/main/java/org/jnode/fs/nfs/nfs2/NFS2Directory.java b/fs/src/main/java/org/jnode/fs/nfs/nfs2/NFS2Directory.java index abb53fd10d..63dc901a7f 100644 --- a/fs/src/main/java/org/jnode/fs/nfs/nfs2/NFS2Directory.java +++ b/fs/src/main/java/org/jnode/fs/nfs/nfs2/NFS2Directory.java @@ -45,7 +45,7 @@ */ public class NFS2Directory extends NFS2Object implements FSDirectory { - private static final Iterator EMPTY_NFSENTRY_ITERATOR = new Iterator() { + private static final Iterator EMPTY_NFSENTRY_ITERATOR = new Iterator<>() { public boolean hasNext() { return false; @@ -155,7 +155,7 @@ else if (x instanceof IOException) { // fetch the entries Set nfsEntrySet = getNFS2EntrySet(); - if (nfsEntrySet.size() == 0) { + if (nfsEntrySet.isEmpty()) { return EMPTY_NFSENTRY_ITERATOR; } @@ -188,7 +188,7 @@ private Set getNFS2EntrySet() throws IOException { } } - if (entrySet.size() == 0) { + if (entrySet.isEmpty()) { return new HashSet<>(); } diff --git a/fs/src/main/java/org/jnode/fs/nfs/nfs2/TableEntry.java b/fs/src/main/java/org/jnode/fs/nfs/nfs2/TableEntry.java index d18e3165bd..6f9a82a7de 100644 --- a/fs/src/main/java/org/jnode/fs/nfs/nfs2/TableEntry.java +++ b/fs/src/main/java/org/jnode/fs/nfs/nfs2/TableEntry.java @@ -53,7 +53,7 @@ public synchronized void removeEntry(String name) { } public synchronized Set getEntrySet() { - if (entryMap.size() == 0) { + if (entryMap.isEmpty()) { return new HashSet<>(); } diff --git a/fs/src/main/java/org/jnode/fs/ntfs/BootRecord.java b/fs/src/main/java/org/jnode/fs/ntfs/BootRecord.java index 2a993ca9ff..ca0939a0bd 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/BootRecord.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/BootRecord.java @@ -20,6 +20,9 @@ package org.jnode.fs.ntfs; +import java.lang.System.Logger.Level; + + /** * @author Chira * @author Ewout Prangsma (epr@users.sourceforge.net) @@ -82,9 +85,9 @@ public BootRecord(byte[] buffer) { this.fileRecordSize = calcByteSize(clustersPerMFTRecord); this.indexRecordSize = calcByteSize(clustersPerIndexRecord); - log.debug("FileRecordSize = " + fileRecordSize); - log.debug("IndexRecordSize = " + indexRecordSize); - log.debug("TotalSectors = " + totalSectors); + log.log(Level.DEBUG, "FileRecordSize = " + fileRecordSize); + log.log(Level.DEBUG, "IndexRecordSize = " + indexRecordSize); + log.log(Level.DEBUG, "TotalSectors = " + totalSectors); } /** diff --git a/fs/src/main/java/org/jnode/fs/ntfs/CompressedDataRun.java b/fs/src/main/java/org/jnode/fs/ntfs/CompressedDataRun.java index 28c73e90f2..68c059f002 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/CompressedDataRun.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/CompressedDataRun.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.util.Arrays; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.LittleEndian; /** @@ -40,7 +40,7 @@ public final class CompressedDataRun implements DataRunInterface { /** * Logger. */ - private static final Logger log = LogManager.getLogger(CompressedDataRun.class); + private static final Logger log = System.getLogger(CompressedDataRun.class.getName()); /** * The underlying data run containing the compressed data. @@ -93,7 +93,7 @@ public int readClusters(long vcn, byte[] dst, int dstOffset, int nrClusters, int final long myFirstVcn = compressedRun.getFirstVcn(); final long myLastVcn = getLastVcn(); final long reqLastVcn = vcn + nrClusters - 1; - log.debug("me:" + myFirstVcn + "-" + myLastVcn + ", req:" + vcn + "-" + reqLastVcn); + log.log(Level.DEBUG, "me:" + myFirstVcn + "-" + myLastVcn + ", req:" + vcn + "-" + reqLastVcn); if ((vcn > myLastVcn) || (myFirstVcn > reqLastVcn)) { // Not my region return 0; @@ -195,7 +195,7 @@ private static int uncompressBlock(final OffsetByteArray compressed, final int rawLen = compressed.getShort(cpos); cpos += 2; final int len = rawLen & 0xFFF; - log.debug("ntfs_uncompblock: block length: " + len + " + 3, 0x" + + log.log(Level.DEBUG, "ntfs_uncompblock: block length: " + len + " + 3, 0x" + Integer.toHexString(len) + ",0x" + Integer.toHexString(rawLen)); if (rawLen == 0) { @@ -207,7 +207,7 @@ private static int uncompressBlock(final OffsetByteArray compressed, if ((rawLen & 0x8000) == 0) { // Uncompressed chunks store length as 0xFFF always. if ((len + 1) != BLOCK_SIZE) { - log.debug("ntfs_uncompblock: len: " + len + " instead of 0xfff"); + log.log(Level.DEBUG, "ntfs_uncompblock: len: " + len + " instead of 0xfff"); } // Copies the entire compression block as-is, need to skip the compression flag, diff --git a/fs/src/main/java/org/jnode/fs/ntfs/DataRun.java b/fs/src/main/java/org/jnode/fs/ntfs/DataRun.java index 2a7df3b61e..104be8e2b4 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/DataRun.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/DataRun.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.util.Arrays; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.ntfs.attribute.NTFSNonResidentAttribute; /** @@ -35,7 +35,7 @@ public final class DataRun implements DataRunInterface { /** * logger */ - private static final Logger log = LogManager.getLogger(DataRun.class); + private static final Logger log = System.getLogger(DataRun.class.getName()); /** * Cluster number of first cluster of this run. If this is zero, the run @@ -219,9 +219,7 @@ public int readClusters(long vcn, byte[] dst, int dstOffset, int nrClusters, int final long reqLastVcn = vcn + nrClusters - 1; - if (log.isDebugEnabled()) { - log.debug("me:" + myFirstVcn + "-" + myLastVcn + ", req:" + vcn + "-" + reqLastVcn); - } + log.log(Level.DEBUG, "me:" + myFirstVcn + "-" + myLastVcn + ", req:" + vcn + "-" + reqLastVcn); if ((vcn > myLastVcn) || (myFirstVcn > reqLastVcn)) { // Not my region @@ -244,9 +242,9 @@ public int readClusters(long vcn, byte[] dst, int dstOffset, int nrClusters, int actCluster = getCluster() + vcnDelta; } - if (log.isDebugEnabled()) { - log.debug("cluster=" + cluster + ", length=" + length + ", dstOffset=" + dstOffset); - log.debug("cnt=" + count + ", actclu=" + actCluster + ", actdstoff=" + actDstOffset); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "cluster=" + cluster + ", length=" + length + ", dstOffset=" + dstOffset); + log.log(Level.DEBUG, "cnt=" + count + ", actclu=" + actCluster + ", actdstoff=" + actDstOffset); } // Zero the area diff --git a/fs/src/main/java/org/jnode/fs/ntfs/FileRecord.java b/fs/src/main/java/org/jnode/fs/ntfs/FileRecord.java index d22c4f7375..f9c6c4ee74 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/FileRecord.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/FileRecord.java @@ -21,6 +21,7 @@ package org.jnode.fs.ntfs; import java.io.IOException; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -133,7 +134,7 @@ public FileRecord(NTFSVolume volume, int bytesPerSector, int clusterSize, boolea public void checkIfValid() throws IOException { // check for the magic number to see if we have a filerecord if (getMagic() != Magic.FILE) { - log.debug("Invalid magic number found for FILE record: " + getMagic() + " -- dumping buffer"); + log.log(Level.DEBUG, "Invalid magic number found for FILE record: " + getMagic() + " -- dumping buffer"); for (int off = 0; off < getBuffer().length; off += 32) { StringBuilder builder = new StringBuilder(); for (int i = off; i < off + 32 && i < getBuffer().length; i++) { @@ -144,7 +145,7 @@ public void checkIfValid() throws IOException { builder.append(' ').append(hex); } - log.debug(builder.toString()); + log.log(Level.DEBUG, builder.toString()); } throw new IOException("Invalid magic found: " + getMagic()); @@ -407,14 +408,14 @@ public synchronized List getAllAttributes() { try { if (attributeListAttribute == null) { - log.debug("All attributes stored"); + log.log(Level.DEBUG, "All attributes stored"); attributeList = new ArrayList<>(getAllStoredAttributes()); } else { - log.debug("Attributes in attribute list"); + log.log(Level.DEBUG, "Attributes in attribute list"); readAttributeListAttributes(); } } catch (Exception e) { - log.error("Error getting attributes for entry: " + this, e); + log.log(Level.ERROR, "Error getting attributes for entry: " + this, e); } } @@ -428,16 +429,16 @@ public synchronized List getAllAttributes() { * @return the attribute. */ public NTFSAttribute findAttributeByType(int attrTypeID) { - log.debug("findAttributeByType(0x" + NumberUtils.hex(attrTypeID, 4) + ")"); + log.log(Level.DEBUG, "findAttributeByType(0x" + NumberUtils.hex(attrTypeID, 4) + ")"); for (NTFSAttribute attr : getAllAttributes()) { if (attr.getAttributeType() == attrTypeID) { - log.debug("findAttributeByType(0x" + NumberUtils.hex(attrTypeID, 4) + ") found"); + log.log(Level.DEBUG, "findAttributeByType(0x" + NumberUtils.hex(attrTypeID, 4) + ") found"); return attr; } } - log.debug("findAttributeByType(0x" + NumberUtils.hex(attrTypeID, 4) + ") not found"); + log.log(Level.DEBUG, "findAttributeByType(0x" + NumberUtils.hex(attrTypeID, 4) + ") not found"); return null; } @@ -448,7 +449,7 @@ public NTFSAttribute findAttributeByType(int attrTypeID) { * @return an iterator for the matching the attributes. */ public Iterator findAttributesByType(final int attrTypeID) { - log.debug("findAttributesByType(0x" + NumberUtils.hex(attrTypeID, 4) + ")"); + log.log(Level.DEBUG, "findAttributesByType(0x" + NumberUtils.hex(attrTypeID, 4) + ")"); return new FilteredAttributeIterator(getAllAttributes().iterator()) { @Override @@ -466,14 +467,14 @@ protected boolean matches(NTFSAttribute attr) { * @return an iterator for the matching the attributes. */ public Iterator findAttributesByTypeAndName(final int attrTypeID, final String name) { - log.debug("findAttributesByTypeAndName(0x" + NumberUtils.hex(attrTypeID, 4) + "," + name + ")"); + log.log(Level.DEBUG, "findAttributesByTypeAndName(0x" + NumberUtils.hex(attrTypeID, 4) + "," + name + ")"); return new FilteredAttributeIterator(getAllAttributes().iterator()) { @Override protected boolean matches(NTFSAttribute attr) { if (attr.getAttributeType() == attrTypeID) { String attrName = attr.getAttributeName(); if (Objects.equals(name, attrName)) { - log.debug("findAttributesByTypeAndName(0x" + NumberUtils.hex(attrTypeID, 4) + "," + name + log.log(Level.DEBUG, "findAttributesByTypeAndName(0x" + NumberUtils.hex(attrTypeID, 4) + "," + name + ") found"); return true; } @@ -546,10 +547,8 @@ public void readData(int attributeType, String streamName, long fileOffset, byte boolean limitToInitialised) throws IOException { - if (log.isDebugEnabled()) { - log.debug("readData: offset " + fileOffset + " attr:" + attributeType + " stream: " + streamName + + log.log(Level.DEBUG, "readData: offset " + fileOffset + " attr:" + attributeType + " stream: " + streamName + " length " + len + ", file record = " + this); - } if (len == 0) { return; @@ -574,9 +573,7 @@ public void readData(int attributeType, String streamName, long fileOffset, byte } resData.getData(resData.getAttributeOffset() + (int) fileOffset, dest, off, len); - if (log.isDebugEnabled()) { - log.debug("readData: read from resident data"); - } + log.log(Level.DEBUG, "readData: read from resident data"); return; } @@ -641,9 +638,7 @@ public void readData(int attributeType, String streamName, long fileOffset, byte } } - if (log.isDebugEnabled()) { - log.debug("readData: read " + readClusters + " from non-resident attributes"); - } + log.log(Level.DEBUG, "readData: read " + readClusters + " from non-resident attributes"); if (readClusters != nrClusters) { throw new IOException("Requested " + nrClusters + " clusters but only read " + readClusters + @@ -688,7 +683,7 @@ private synchronized void readAttributeListAttributes() { if (entry.getFileReferenceNumber() == referenceNumber) { attribute = findStoredAttributeByID(entry.getAttributeID()); } else { - log.debug("Looking up MFT entry for: " + entry.getFileReferenceNumber()); + log.log(Level.DEBUG, "Looking up MFT entry for: " + entry.getFileReferenceNumber()); // When reading the MFT itself don't attempt to check the index is in range (we won't know the total // MFT length yet) @@ -700,7 +695,7 @@ private synchronized void readAttributeListAttributes() { attribute = holdingRecord.findStoredAttributeByID(entry.getAttributeID()); if (attribute == null) { - log.error(String.format("Failed to find an attribute matching entry '%s' in the holding record", entry)); + log.log(Level.ERROR, String.format("Failed to find an attribute matching entry '%s' in the holding record", entry)); continue; } else if (!attribute.isResident() && attribute.isCompressedAttribute() && compressedByType.containsKey(attribute.getAttributeType())) { @@ -722,9 +717,7 @@ private synchronized void readAttributeListAttributes() { compressedByType.put(attribute.getAttributeType(), (NTFSNonResidentAttribute) attribute); } - if (log.isDebugEnabled()) { - log.debug("Attribute: " + attribute); - } + log.log(Level.DEBUG, "Attribute: " + attribute); attributeList.add(attribute); } catch (Exception e) { @@ -752,13 +745,11 @@ private List readStoredAttributes() { } else { NTFSAttribute attribute = NTFSAttribute.getAttribute(FileRecord.this, offset); - if (log.isDebugEnabled()) { - log.debug("Attribute: " + attribute.toDebugString()); - } + log.log(Level.DEBUG, "Attribute: " + attribute.toDebugString()); int offsetToNextOffset = getUInt32AsInt(offset + 0x04); if (offsetToNextOffset <= 0) { - log.debug("Non-positive offset, preventing infinite loop. Data on disk may be corrupt. " + log.log(Level.DEBUG, "Non-positive offset, preventing infinite loop. Data on disk may be corrupt. " + "referenceNumber = " + referenceNumber); break; } else { diff --git a/fs/src/main/java/org/jnode/fs/ntfs/MasterFileTable.java b/fs/src/main/java/org/jnode/fs/ntfs/MasterFileTable.java index 68c8d4bca3..47e8483b75 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/MasterFileTable.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/MasterFileTable.java @@ -21,6 +21,7 @@ package org.jnode.fs.ntfs; import java.io.IOException; +import java.lang.System.Logger.Level; import org.jnode.fs.ntfs.attribute.NTFSAttribute; import org.jnode.fs.ntfs.index.IndexEntry; @@ -193,7 +194,7 @@ public byte[] readRecord(long index) throws IOException { * @return the file record. */ public FileRecord getRecordUnchecked(long index) throws IOException { - log.debug("getRecord(" + index + ")"); + log.log(Level.DEBUG, "getRecord(" + index + ")"); final NTFSVolume volume = getVolume(); diff --git a/fs/src/main/java/org/jnode/fs/ntfs/NTFSDirectory.java b/fs/src/main/java/org/jnode/fs/ntfs/NTFSDirectory.java index f2e89f4af6..34b691944e 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/NTFSDirectory.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/NTFSDirectory.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.util.Iterator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSDirectoryId; import org.jnode.fs.FSEntry; @@ -41,7 +41,7 @@ */ public class NTFSDirectory implements FSDirectory, FSDirectoryId { - private static final Logger log = LogManager.getLogger(NTFSDirectory.class); + private static final Logger log = System.getLogger(NTFSDirectory.class.getName()); /** * The file record for the directory. @@ -91,7 +91,7 @@ public Iterator iterator() { * Gets an entry with a given name. */ public FSEntry getEntry(String name) { - log.debug("getEntry(" + name + ")"); + log.log(Level.DEBUG, "getEntry(" + name + ")"); for (Iterator it = this.iterator(); it.hasNext(); ) { final NTFSEntry entry = (NTFSEntry) it.next(); if (entry.getName().equals(name)) { diff --git a/fs/src/main/java/org/jnode/fs/ntfs/NTFSRecord.java b/fs/src/main/java/org/jnode/fs/ntfs/NTFSRecord.java index 86cac0867a..9268d572ce 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/NTFSRecord.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/NTFSRecord.java @@ -21,6 +21,8 @@ package org.jnode.fs.ntfs; import java.io.IOException; +import java.lang.System.Logger.Level; + /** * @author Ewout Prangsma (epr@users.sourceforge.net) @@ -150,7 +152,7 @@ private void fixUp(boolean strictFixUp) throws IOException { if (strictFixUp) { throw new IOException("Fix-up error", e); } else { - log.debug("Fix-up error", e); + log.log(Level.DEBUG, "Fix-up error", e); } } } diff --git a/fs/src/main/java/org/jnode/fs/ntfs/NTFSStructure.java b/fs/src/main/java/org/jnode/fs/ntfs/NTFSStructure.java index 82b3a7e643..4d396de705 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/NTFSStructure.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/NTFSStructure.java @@ -22,8 +22,8 @@ import java.nio.charset.StandardCharsets; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.LittleEndian; /** @@ -34,7 +34,7 @@ public class NTFSStructure { /** * My logger */ - protected static final Logger log = LogManager.getLogger(NTFSStructure.class); + protected static final Logger log = System.getLogger(NTFSStructure.class.getName()); private byte[] buffer; private int offset; diff --git a/fs/src/main/java/org/jnode/fs/ntfs/NTFSVolume.java b/fs/src/main/java/org/jnode/fs/ntfs/NTFSVolume.java index 0d9f44be60..e46d4646a4 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/NTFSVolume.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/NTFSVolume.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.nio.ByteBuffer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.block.BlockDeviceAPI; /** @@ -32,7 +32,7 @@ */ public class NTFSVolume { - private static final Logger log = LogManager.getLogger(NTFSVolume.class); + private static final Logger log = System.getLogger(NTFSVolume.class.getName()); public static final byte LONG_FILE_NAMES = 0x01; @@ -80,7 +80,7 @@ public final BootRecord getBootRecord() { public void readCluster(long cluster, byte[] dst, int dstOffset) throws IOException { final int clusterSize = getClusterSize(); final long clusterOffset = cluster * clusterSize; - log.debug("readCluster(" + cluster + ") " + (readClusterCount++)); + log.log(Level.DEBUG, "readCluster(" + cluster + ") " + (readClusterCount++)); api.read(clusterOffset, ByteBuffer.wrap(dst, dstOffset, clusterSize)); } @@ -97,7 +97,7 @@ public void readCluster(long cluster, byte[] dst, int dstOffset) throws IOExcept * @throws IOException */ public void readClusters(long firstCluster, byte[] dst, int dstOffset, int nrClusters) throws IOException { - log.debug("readClusters(" + firstCluster + ", " + nrClusters + ") " + (readClustersCount++)); + log.log(Level.DEBUG, "readClusters(" + firstCluster + ", " + nrClusters + ") " + (readClustersCount++)); final int clusterSize = getClusterSize(); final long clusterOffset = firstCluster * clusterSize; api.read(clusterOffset, ByteBuffer.wrap(dst, dstOffset, nrClusters * clusterSize)); @@ -149,7 +149,7 @@ public FileRecord getRootDirectory() throws IOException { // Read the root directory final MasterFileTable mft = getMFT(); rootDirectory = mft.getRecord(MasterFileTable.SystemFiles.ROOT); - log.info("getRootDirectory: " + rootDirectory.getFileName()); + log.log(Level.INFO, "getRootDirectory: " + rootDirectory.getFileName()); } return rootDirectory; } diff --git a/fs/src/main/java/org/jnode/fs/ntfs/attribute/AttributeListAttributeNonRes.java b/fs/src/main/java/org/jnode/fs/ntfs/attribute/AttributeListAttributeNonRes.java index 81b25c3862..dce240f2df 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/attribute/AttributeListAttributeNonRes.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/attribute/AttributeListAttributeNonRes.java @@ -21,6 +21,7 @@ package org.jnode.fs.ntfs.attribute; import java.io.IOException; +import java.lang.System.Logger.Level; import java.util.Iterator; import org.jnode.fs.ntfs.FileRecord; @@ -58,7 +59,7 @@ public Iterator getAllEntries() throws IOException { // TODO: Consider handling multiple data runs separately instead // of "glueing" them all together like this. final int nrClusters = getNumberOfVCNs(); - log.debug(String.format("Allocating %d clusters for non-resident attribute", nrClusters)); + log.log(Level.DEBUG, String.format("Allocating %d clusters for non-resident attribute", nrClusters)); final byte[] data = new byte[nrClusters * getFileRecord().getClusterSize()]; readVCN(getStartVCN(), data, 0, nrClusters); AttributeListBlock listBlock = new AttributeListBlock(data, 0, getAttributeActualSize()); diff --git a/fs/src/main/java/org/jnode/fs/ntfs/attribute/AttributeListBlock.java b/fs/src/main/java/org/jnode/fs/ntfs/attribute/AttributeListBlock.java index 37b9c0bdff..3e6f650293 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/attribute/AttributeListBlock.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/attribute/AttributeListBlock.java @@ -20,6 +20,7 @@ package org.jnode.fs.ntfs.attribute; +import java.lang.System.Logger.Level; import java.util.Iterator; import java.util.NoSuchElementException; @@ -89,12 +90,12 @@ public boolean hasNext() { int length = getUInt16(offset + 0x04); if (length <= 0) { - log.error("Invalid attribute length, preventing infinite loop. Data on disk may be corrupt."); + log.log(Level.ERROR, "Invalid attribute length, preventing infinite loop. Data on disk may be corrupt."); return false; } nextElement = new AttributeListEntry(AttributeListBlock.this, offset); - log.debug(nextElement); + log.log(Level.DEBUG, nextElement); offset += length; return true; } diff --git a/fs/src/main/java/org/jnode/fs/ntfs/attribute/NTFSNonResidentAttribute.java b/fs/src/main/java/org/jnode/fs/ntfs/attribute/NTFSNonResidentAttribute.java index bbc78b5c79..93e598163f 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/attribute/NTFSNonResidentAttribute.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/attribute/NTFSNonResidentAttribute.java @@ -21,6 +21,7 @@ package org.jnode.fs.ntfs.attribute; import java.io.IOException; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; @@ -160,9 +161,7 @@ private void readDataRuns(int parentoffset, int fallbackCompressionUnit) { while (getUInt8(offset) != 0x0) { final DataRun dataRun = new DataRun(this, offset, vcn, previousLCN); - if (log.isDebugEnabled()) { - log.debug("Data run at offset: " + offset + " " + dataRun); - } + log.log(Level.DEBUG, "Data run at offset: " + offset + " " + dataRun); if (compressed) { if (dataRun.isSparse() && (expectingSparseRunNext || firstDataRun)) { @@ -246,7 +245,7 @@ private void readDataRuns(int parentoffset, int fallbackCompressionUnit) { final long allocatedVCNs = (getAttributeAllocatedSize() - 1) / clusterSize + 1; if (this.numberOfVCNs != allocatedVCNs) { // Probably not a problem, often multiple attributes make up one allocation. - log.debug("VCN mismatch between data runs and allocated size, possibly a composite attribute. " + + log.log(Level.DEBUG, "VCN mismatch between data runs and allocated size, possibly a composite attribute. " + "data run VCNs = " + this.numberOfVCNs + ", allocated size = " + allocatedVCNs + ", data run count = " + dataRuns.size()); } @@ -274,10 +273,8 @@ public int readVCN(long vcn, byte[] dst, int dstOffset, int nrClusters) throws I throw new IOException("Reading encrypted files is not supported"); } - if (log.isDebugEnabled()) { - log.debug("readVCN: wants start " + vcn + " length " + nrClusters + + log.log(Level.DEBUG, "readVCN: wants start " + vcn + " length " + nrClusters + ", we have start " + getStartVCN() + " length " + getNumberOfVCNs()); - } final NTFSVolume volume = getFileRecord().getVolume(); final int clusterSize = volume.getClusterSize(); @@ -289,9 +286,7 @@ public int readVCN(long vcn, byte[] dst, int dstOffset, int nrClusters) throws I } } - if (log.isDebugEnabled()) { - log.debug("readVCN: read " + readClusters); - } + log.log(Level.DEBUG, "readVCN: read " + readClusters); return readClusters; } diff --git a/fs/src/main/java/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java b/fs/src/main/java/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java index d3f499d91c..316fed19d2 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java @@ -21,6 +21,7 @@ package org.jnode.fs.ntfs.index; import java.io.IOException; +import java.lang.System.Logger.Level; import org.jnode.fs.ntfs.FileRecord; import org.jnode.fs.ntfs.attribute.NTFSNonResidentAttribute; @@ -60,7 +61,7 @@ public int getMagic() { * @throws IOException */ public IndexBlock getIndexBlock(IndexRoot indexRoot, long vcn) throws IOException { - log.debug("getIndexBlock(..," + vcn + ")"); + log.log(Level.DEBUG, "getIndexBlock(..," + vcn + ")"); final FileRecord fileRecord = getFileRecord(); // VCN passed in is relative to the size of index clusters, not filesystem clusters. diff --git a/fs/src/main/java/org/jnode/fs/ntfs/index/NTFSIndex.java b/fs/src/main/java/org/jnode/fs/ntfs/index/NTFSIndex.java index dd3d060841..d67724cf1f 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/index/NTFSIndex.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/index/NTFSIndex.java @@ -24,8 +24,8 @@ import java.util.Iterator; import java.util.NoSuchElementException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.ntfs.FileRecord; import org.jnode.fs.ntfs.attribute.NTFSAttribute; import org.jnode.util.Queue; @@ -47,7 +47,7 @@ public final class NTFSIndex { private IndexAllocationAttribute indexAllocationAttribute; - static final Logger log = LogManager.getLogger(NTFSIndex.class); + static final Logger log = System.getLogger(NTFSIndex.class.getName()); /** * Initialize this instance. @@ -69,7 +69,7 @@ public IndexRootAttribute getIndexRootAttribute() { if (indexRootAttribute == null) { indexRootAttribute = (IndexRootAttribute) fileRecord.findAttributesByTypeAndName(NTFSAttribute.Types.INDEX_ROOT, attributeName).next(); - log.debug("getIndexRootAttribute: " + indexRootAttribute); + log.log(Level.DEBUG, "getIndexRootAttribute: " + indexRootAttribute); } return indexRootAttribute; } @@ -163,7 +163,7 @@ public IndexEntry searchSubTree(IndexEntry topEntry, IndexSearchCallback callbac } public Iterator iterator() { - log.debug("iterator"); + log.log(Level.DEBUG, "iterator"); return new FullIndexEntryIterator(); } @@ -184,9 +184,9 @@ class FullIndexEntryIterator implements Iterator { * Initialize this instance. */ public FullIndexEntryIterator() { - log.debug("FullIndexEntryIterator"); + log.log(Level.DEBUG, "FullIndexEntryIterator"); currentIterator = getIndexRootAttribute().iterator(); - log.debug("currentIterator=" + currentIterator); + log.log(Level.DEBUG, "currentIterator=" + currentIterator); readNextEntry(); } @@ -222,7 +222,7 @@ private void readNextEntry() { // Read it nextEntry = currentIterator.next(); if (nextEntry.hasSubNodes()) { - log.debug("next has subnode"); + log.log(Level.DEBUG, "next has subnode"); subNodeEntries.add(nextEntry); } if (!nextEntry.isLastIndexEntryInSubnode()) { @@ -234,11 +234,11 @@ private void readNextEntry() { // Do we have subnodes to iterate over? if (subNodeEntries.isEmpty()) { // No, we're done - log.debug("end of list"); + log.log(Level.DEBUG, "end of list"); return; } - log.debug("hasNext: read next indexblock"); + log.log(Level.DEBUG, "hasNext: read next indexblock"); final IndexEntry entry = subNodeEntries.get(); final IndexRoot indexRoot = getIndexRootAttribute().getRoot(); final IndexBlock indexBlock; diff --git a/fs/src/main/java/org/jnode/fs/ntfs/logfile/LogFile.java b/fs/src/main/java/org/jnode/fs/ntfs/logfile/LogFile.java index 6fcb69ca7a..a2e29ebb5c 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/logfile/LogFile.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/logfile/LogFile.java @@ -10,8 +10,8 @@ import java.util.Map; import java.util.TreeMap; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.ntfs.FileRecord; import org.jnode.fs.ntfs.NTFSVolume; import org.jnode.fs.ntfs.attribute.NTFSAttribute; @@ -28,7 +28,7 @@ public class LogFile { /** * My logger */ - protected static final Logger log = LogManager.getLogger(LogFile.class); + protected static final Logger log = System.getLogger(LogFile.class.getName()); /** * The start of the normal area (in pages). @@ -104,17 +104,17 @@ public LogFile(FileRecord fileRecord) throws IOException { restartArea = new RestartArea(logFileBuffer, restartAreaOffset); if ((restartArea.getFlags() & RestartArea.VOLUME_CLEANLY_UNMOUNTED) != RestartArea.VOLUME_CLEANLY_UNMOUNTED) { - log.info("Volume not cleanly unmounted"); + log.log(Level.INFO, "Volume not cleanly unmounted"); cleanlyShutdown = false; } else { - log.info("Volume marked as cleanly unmounted"); + log.log(Level.INFO, "Volume marked as cleanly unmounted"); } // Read in any open log client records int logClientCount = restartArea.getLogClients(); if (logClientCount != RestartArea.LOGFILE_NO_CLIENT) { - log.info(String.format("Found %d open log clients", logClientCount)); + log.log(Level.INFO, String.format("Found %d open log clients", logClientCount)); int logClientOffset = restartAreaOffset + restartArea.getClientArrayOffset(); LogClientRecord logClientRecord = new LogClientRecord(logFileBuffer, logClientOffset); @@ -178,7 +178,7 @@ private void parseRecords() { if (pageHeader.getLastLsnOrFileOffset() < lastLsn || pageHeader.getLastLsnOrFileOffset() - lastLsn > 0x8000) { // This page doesn't seem to continue on from the last page, so reset the offsets - log.info(String.format("$LogFile discontinuous at 0x%x [%d -> %d]", offset, lastLsn, + log.log(Level.INFO, String.format("$LogFile discontinuous at 0x%x [%d -> %d]", offset, lastLsn, pageHeader.getLastLsnOrFileOffset())); recordOffset = 0; lastRecordLength = 0; @@ -227,7 +227,7 @@ private void parseRecords() { lastRecordLength -= logPageSize - start; } else { if (lsn <= 0 || lsn > pageHeader.getLastLsnOrFileOffset()) { - log.warn("Log record seems to be invalid: " + logRecord.toDebugString()); + log.log(Level.WARNING, "Log record seems to be invalid: " + logRecord.toDebugString()); } // Seems to be the end of valid records for this page lastRecordLength = 0; @@ -316,14 +316,14 @@ private RestartPageHeader getNewestRestartPageHeader(NTFSVolume volume, byte[] b if (!restartPageHeader1.isValid()) { throw new IllegalStateException("Restart header has invalid magic: " + restartPageHeader1.getMagic()); } else if (restartPageHeader1.getMagic() == RestartPageHeader.Magic.CHKD) { - log.warn("First $LogFile restart header has check disk magic"); + log.log(Level.WARNING, "First $LogFile restart header has check disk magic"); } RestartPageHeader restartPageHeader2 = new RestartPageHeader(volume, buffer, restartPageHeader1.getLogPageSize()); if (!restartPageHeader2.isValid()) { throw new IllegalStateException("Second restart header has invalid magic: " + restartPageHeader2.getMagic()); } else if (restartPageHeader2.getMagic() == RestartPageHeader.Magic.CHKD) { - log.warn("Second $LogFile restart header has check disk magic"); + log.log(Level.WARNING, "Second $LogFile restart header has check disk magic"); } int restartAreaOffset1 = restartPageHeader1.getRestartOffset(); diff --git a/fs/src/main/java/org/jnode/fs/ntfs/security/WellKnownSids.java b/fs/src/main/java/org/jnode/fs/ntfs/security/WellKnownSids.java index 2633fb2bcb..ff6d35ef3b 100644 --- a/fs/src/main/java/org/jnode/fs/ntfs/security/WellKnownSids.java +++ b/fs/src/main/java/org/jnode/fs/ntfs/security/WellKnownSids.java @@ -161,7 +161,7 @@ public class WellKnownSids { /** * Well known SIDs for the sub-region beginning with 1-5-21 then a set of values and ending in the following. */ - private static final Map WELL_KNOWN_1_5_21_MAP = new LinkedHashMap() {{ + private static final Map WELL_KNOWN_1_5_21_MAP = new LinkedHashMap<>() {{ put("500", "Administrator"); put("501", "Guest"); put("502", "KRBTGT"); diff --git a/fs/src/main/java/org/jnode/fs/smbfs/Format.java b/fs/src/main/java/org/jnode/fs/smbfs/Format.java index 3798e27d87..ecb18258e0 100644 --- a/fs/src/main/java/org/jnode/fs/smbfs/Format.java +++ b/fs/src/main/java/org/jnode/fs/smbfs/Format.java @@ -466,7 +466,7 @@ else if (s > 0) { if (show_plus) p = "+"; else if (show_space) p = " "; } else { - if (fmt == 'o' && alternate && r.length() > 0 && r.charAt(0) != '0') p = "0"; + if (fmt == 'o' && alternate && !r.isEmpty() && r.charAt(0) != '0') p = "0"; else if (fmt == 'x' && alternate) p = "0x"; else if (fmt == 'X' && alternate) p = "0X"; } diff --git a/fs/src/main/java/org/jnode/fs/spi/AbstractFSDirectory.java b/fs/src/main/java/org/jnode/fs/spi/AbstractFSDirectory.java index a5479b4efe..c1ae33ca2a 100644 --- a/fs/src/main/java/org/jnode/fs/spi/AbstractFSDirectory.java +++ b/fs/src/main/java/org/jnode/fs/spi/AbstractFSDirectory.java @@ -25,8 +25,8 @@ import java.io.PrintWriter; import java.util.Iterator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; import org.jnode.fs.ReadOnlyFileSystemException; @@ -38,7 +38,7 @@ * @author Fabien DUMINY */ public abstract class AbstractFSDirectory extends AbstractFSObject implements FSDirectory { - private static final Logger log = LogManager.getLogger(AbstractFSDirectory.class); + private static final Logger log = System.getLogger(AbstractFSDirectory.class.getName()); /* Table of entries */ private FSEntryTable entries = FSEntryTable.EMPTY_TABLE; @@ -124,7 +124,7 @@ public final FSEntry getEntry(String name) throws IOException { * @throws IOException */ public final synchronized FSEntry addDirectory(String name) throws IOException { - log.debug("<<< BEGIN addDirectory " + name + " >>>"); + log.log(Level.DEBUG, "<<< BEGIN addDirectory " + name + " >>>"); if (!canWrite()) throw new ReadOnlyFileSystemException("Filesystem or directory is mounted read-only!"); @@ -133,7 +133,7 @@ public final synchronized FSEntry addDirectory(String name) throws IOException { } FSEntry newEntry = createDirectoryEntry(name); setFreeEntry(newEntry); - log.debug("<<< END addDirectory " + name + " >>>"); + log.log(Level.DEBUG, "<<< END addDirectory " + name + " >>>"); return newEntry; } @@ -207,9 +207,9 @@ public final boolean isDirty() throws IOException { * yet initialized (constructed). */ protected final void checkEntriesLoaded() { - log.debug("<<< BEGIN checkEntriesLoaded >>>"); + log.log(Level.DEBUG, "<<< BEGIN checkEntriesLoaded >>>"); if (!isEntriesLoaded()) { - log.debug("checkEntriesLoaded : loading"); + log.log(Level.DEBUG, "checkEntriesLoaded : loading"); try { if (canRead()) { entries = readEntries(); @@ -217,17 +217,17 @@ protected final void checkEntriesLoaded() { // the next time, we will call checkEntriesLoaded() // we will retry to load entries entries = FSEntryTable.EMPTY_TABLE; - log.debug("checkEntriesLoaded : can't read, using EMPTY_TABLE"); + log.log(Level.DEBUG, "checkEntriesLoaded : can't read, using EMPTY_TABLE"); } resetDirty(); } catch (IOException e) { - log.fatal("unable to read directory entries", e); + log.log(Level.ERROR, "unable to read directory entries", e); // the next time, we will call checkEntriesLoaded() // we will retry to load entries entries = FSEntryTable.EMPTY_TABLE; } } - log.debug("<<< END checkEntriesLoaded >>>"); + log.log(Level.DEBUG, "<<< END checkEntriesLoaded >>>"); } /** @@ -247,7 +247,7 @@ private boolean isEntriesLoaded() { * @return the added file entry */ public final synchronized FSEntry addFile(String name) throws IOException { - log.debug("<<< BEGIN addFile " + name + " >>>"); + log.log(Level.DEBUG, "<<< BEGIN addFile " + name + " >>>"); if (!canWrite()) throw new ReadOnlyFileSystemException("Filesystem or directory is mounted read-only!"); @@ -257,7 +257,7 @@ public final synchronized FSEntry addFile(String name) throws IOException { FSEntry newEntry = createFileEntry(name); setFreeEntry(newEntry); - log.debug("<<< END addFile " + name + " >>>"); + log.log(Level.DEBUG, "<<< END addFile " + name + " >>>"); return newEntry; } @@ -286,7 +286,7 @@ public final synchronized FSEntry addFile(String name) throws IOException { private void setFreeEntry(FSEntry newEntry) throws IOException { checkEntriesLoaded(); if (entries.setFreeEntry(newEntry) >= 0) { - log.debug("setFreeEntry: free entry found !"); + log.log(Level.DEBUG, "setFreeEntry: free entry found !"); // a free entry has been found setDirty(); flush(); diff --git a/fs/src/main/java/org/jnode/fs/spi/AbstractFSEntry.java b/fs/src/main/java/org/jnode/fs/spi/AbstractFSEntry.java index 46ffcc426e..259861139c 100644 --- a/fs/src/main/java/org/jnode/fs/spi/AbstractFSEntry.java +++ b/fs/src/main/java/org/jnode/fs/spi/AbstractFSEntry.java @@ -22,8 +22,8 @@ import java.io.IOException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSAccessRights; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; @@ -37,7 +37,8 @@ * @author Fabien DUMINY */ public abstract class AbstractFSEntry extends AbstractFSObject implements FSEntry { - private static final Logger log = LogManager.getLogger(AbstractFSEntry.class); + + private static final Logger log = System.getLogger(AbstractFSEntry.class.getName()); // common types of entries found in most FileSystems: /** Fake entry: lower bound */ @@ -175,21 +176,21 @@ public final boolean isRoot() { * @throws IOException */ public final void setName(String newName) throws IOException { - log.debug("<<< BEGIN setName newName=" + newName + " >>>"); + log.log(Level.DEBUG, "<<< BEGIN setName newName=" + newName + " >>>"); // NB: table is null for a root if (isRoot()) { - log.debug("<<< END setName newName=" + newName + " ERROR: root >>>"); + log.log(Level.DEBUG, "<<< END setName newName=" + newName + " ERROR: root >>>"); throw new IOException("Cannot change name of root directory"); } // It's not a root --> table != null if (table.rename(name, newName) < 0) { - log.debug("<<< END setName newName=" + newName + " ERROR: table can't rename >>>"); + log.log(Level.DEBUG, "<<< END setName newName=" + newName + " ERROR: table can't rename >>>"); throw new IOException("Cannot change name"); } this.name = newName; - log.debug("<<< END setName newName=" + newName + " >>>"); + log.log(Level.DEBUG, "<<< END setName newName=" + newName + " >>>"); } public void setLastModified(long lastModified) throws IOException { diff --git a/fs/src/main/java/org/jnode/fs/spi/AbstractFileSystem.java b/fs/src/main/java/org/jnode/fs/spi/AbstractFileSystem.java index b9ea57ef3d..ee88af4af2 100644 --- a/fs/src/main/java/org/jnode/fs/spi/AbstractFileSystem.java +++ b/fs/src/main/java/org/jnode/fs/spi/AbstractFileSystem.java @@ -23,8 +23,8 @@ import java.io.IOException; import java.util.HashMap; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.ApiNotFoundException; import org.jnode.driver.Device; import org.jnode.driver.block.BlockDeviceAPI; @@ -41,8 +41,10 @@ * @author Fabien DUMINY */ public abstract class AbstractFileSystem implements FileSystem { + /** My logger */ - private static final Logger log = LogManager.getLogger(AbstractFileSystem.class); + private static final Logger log = System.getLogger(AbstractFileSystem.class.getName()); + /** The device that contains the file system */ private final Device device; /** API of the block device */ @@ -206,11 +208,9 @@ public final synchronized FSFile getFile(FSEntry entry) throws IOException { * @throws IOException if error occurs during write of datas on the device. */ private void flushFiles() throws IOException { - log.info("flushing files ..."); + log.log(Level.INFO, "flushing files ..."); for (FSFile f : files.values()) { - if (log.isDebugEnabled()) { - log.debug("flush: flushing file " + f); - } + log.log(Level.DEBUG, "flush: flushing file " + f); f.flush(); } } @@ -250,11 +250,9 @@ public final synchronized FSDirectory getDirectory(FSEntry entry) throws IOExcep * Save all unsaved files from entry cache. */ private void flushDirectories() { - log.info("flushing directories ..."); + log.log(Level.INFO, "flushing directories ..."); for (FSDirectory d : directories.values()) { - if (log.isDebugEnabled()) { - log.debug("flush: flushing directory " + d); - } + log.log(Level.DEBUG, "flush: flushing directory " + d); //TODO: uncomment this line //d.flush(); } diff --git a/fs/src/main/java/org/jnode/fs/spi/FSEntryTable.java b/fs/src/main/java/org/jnode/fs/spi/FSEntryTable.java index 1590d37afc..5eb01548ee 100644 --- a/fs/src/main/java/org/jnode/fs/spi/FSEntryTable.java +++ b/fs/src/main/java/org/jnode/fs/spi/FSEntryTable.java @@ -28,8 +28,8 @@ import java.util.List; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSEntry; /** @@ -42,7 +42,7 @@ */ public class FSEntryTable extends AbstractFSObject { - private static final Logger log = LogManager.getLogger(FSEntryTable.class); + private static final Logger log = System.getLogger(FSEntryTable.class.getName()); /** * An empty table that's used as a default table (that can't be modified) @@ -56,18 +56,18 @@ public class FSEntryTable extends AbstractFSObject { * Map of entries (key=name, value=entry). As a value may be null (a free * entry) we must use Hashtable and not Hashtable */ - private Map entries; // must be a HashMap + private final Map entries; // must be a HashMap /** * Map of entries (key=id, value=entry). As a value may be null (a free * entry) we must use Hashtable and not Hashtable */ - private Map entriesById; // must be a HashMap + private final Map entriesById; // must be a HashMap /** * Names of the entries (list of String or null) */ - private List entryNames; + private final List entryNames; /** * Private constructor for EMPTY_TABLE @@ -98,11 +98,11 @@ public FSEntryTable(AbstractFileSystem fs, List entryList) { entryNames.add(null); } else { final String name = normalizeName(entry.getName()); - log.debug("FSEntryTable: adding entry " + name + " (length=+" + name.length() + ")"); + log.log(Level.DEBUG, "FSEntryTable: adding entry " + name + " (length=+" + name.length() + ")"); entries.put(name, entry); FSEntry existingEntry = entriesById.put(entry.getId(), entry); if (existingEntry != null) { - log.error(String.format("Duplicate entries for ID: '%s' old:%s new:%s", entry.getId(), + log.log(Level.ERROR, String.format("Duplicate entries for ID: '%s' old:%s new:%s", entry.getId(), existingEntry, entry)); } entryNames.add(name); @@ -166,7 +166,7 @@ public FSEntry get(String name) { return null; name = normalizeName(name); - log.debug("get(" + name + ")"); + log.log(Level.DEBUG, "get(" + name + ")"); return entries.get(name); } @@ -249,7 +249,7 @@ public final boolean isDirty() throws IOException { * @return an Iterator with all used entries */ public final Iterator iterator() { - return new Iterator() { + return new Iterator<>() { private int index = 0; private List usedEntries = getUsedEntries(); @@ -317,13 +317,13 @@ public int remove(String name) { * @return the index of renamed file */ public int rename(String oldName, String newName) { - log.debug("<<< BEGIN rename oldName=" + oldName + " newName=" + newName + " >>>"); - log.debug("rename: table=" + this); + log.log(Level.DEBUG, "<<< BEGIN rename oldName=" + oldName + " newName=" + newName + " >>>"); + log.log(Level.DEBUG, "rename: table=" + this); oldName = normalizeName(oldName); newName = normalizeName(newName); - log.debug("rename oldName=" + oldName + " newName=" + newName); + log.log(Level.DEBUG, "rename oldName=" + oldName + " newName=" + newName); if (!entryNames.contains(oldName)) { - log.debug("<<< END rename return false (oldName not found) >>>"); + log.log(Level.DEBUG, "<<< END rename return false (oldName not found) >>>"); return -1; } @@ -336,7 +336,7 @@ public int rename(String oldName, String newName) { FSEntry entry = entries.remove(oldName); entries.put(newName, entry); - log.debug("<<< END rename return true >>>"); + log.log(Level.DEBUG, "<<< END rename return true >>>"); return index; } @@ -353,7 +353,7 @@ public int setFreeEntry(FSEntry newEntry) throws IOException { String name = normalizeName(newEntry.getName()); int index = findFreeEntry(newEntry); if (index < 0) { - log.debug("setFreeEntry: ERROR: entry table is full"); + log.log(Level.DEBUG, "setFreeEntry: ERROR: entry table is full"); throw new IOException("Directory is full"); } diff --git a/fs/src/main/java/org/jnode/fs/spi/UnixFSAccessRights.java b/fs/src/main/java/org/jnode/fs/spi/UnixFSAccessRights.java index c6d628b151..7cd535bb65 100644 --- a/fs/src/main/java/org/jnode/fs/spi/UnixFSAccessRights.java +++ b/fs/src/main/java/org/jnode/fs/spi/UnixFSAccessRights.java @@ -20,15 +20,14 @@ package org.jnode.fs.spi; +import java.nio.file.attribute.UserPrincipal; import java.security.Principal; -import java.security.acl.Group; +import java.util.Set; +import javax.security.auth.Subject; import org.jnode.fs.FSAccessRights; import org.jnode.fs.FileSystem; -import com.sun.security.auth.UserPrincipal; // TODO uses an internal class - -import sun.security.acl.GroupImpl; // TODO uses an internal class /** * @@ -38,8 +37,10 @@ public class UnixFSAccessRights implements FSAccessRights { private final FileSystem filesystem; - private Principal owner; - private Group group; + private Subject subject = new Subject(); + + private UserPrincipal owner; + private Set admins; private final Rights ownerRights = new Rights(true, true, true); private final Rights groupRights = new Rights(); @@ -52,9 +53,9 @@ public UnixFSAccessRights(FileSystem filesystem) { this.filesystem = filesystem; // TODO manages users & groups in JNode - owner = new UserPrincipal("root"); - group = new GroupImpl("admins"); - group.addMember(owner); + owner = () -> "root"; + admins = subject.getPrincipals(); + admins.add(owner); } private Principal getUser() { @@ -69,7 +70,7 @@ private Rights getUserRights() { Rights rights = worldRights; if (owner.equals(user)) { rights = ownerRights; - } else if (group.isMember(user)) { + } else if (admins.contains(user)) { rights = groupRights; } diff --git a/fs/src/main/java/org/jnode/fs/util/FSUtils.java b/fs/src/main/java/org/jnode/fs/util/FSUtils.java index 088c2e1958..9532377e83 100644 --- a/fs/src/main/java/org/jnode/fs/util/FSUtils.java +++ b/fs/src/main/java/org/jnode/fs/util/FSUtils.java @@ -25,8 +25,8 @@ import java.text.SimpleDateFormat; import java.util.Date; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; import org.jnode.fs.FSFile; @@ -37,7 +37,7 @@ */ public class FSUtils { - private static final Logger log = LogManager.getLogger(FSUtils.class); + private static final Logger log = System.getLogger(FSUtils.class.getName()); protected static DateFormat dateFormat = new SimpleDateFormat(); @@ -85,13 +85,13 @@ public static String toString(FSEntry entry, boolean deep) { sb.append(toStringDate(" lastModified=", entry.getLastModified())); } catch (IOException e) { sb.append(" lastModified=###").append(e.getMessage()).append("###"); - log.error("error in lastModified", e); + log.log(Level.ERROR, "error in lastModified", e); } try { sb.append(" isDirty=").append(entry.isDirty()); } catch (IOException e1) { sb.append(" isDirty=###").append(e1.getMessage()).append("###"); - log.error("error in isDirty", e1); + log.log(Level.ERROR, "error in isDirty", e1); } sb.append(" isValid=").append(entry.isValid()); @@ -101,7 +101,7 @@ public static String toString(FSEntry entry, boolean deep) { sb.append(toString(entry.getFile())); } catch (IOException e2) { sb.append(" getFile=###").append(e2.getMessage()).append("###"); - log.error("error in getFile", e2); + log.log(Level.ERROR, "error in getFile", e2); } } @@ -111,7 +111,7 @@ public static String toString(FSEntry entry, boolean deep) { sb.append(toString(entry.getDirectory())); } catch (IOException e3) { sb.append(" getDirectory=###").append(e3.getMessage()).append("###"); - log.error("error in getDirectory", e3); + log.log(Level.ERROR, "error in getDirectory", e3); } sb.append(""); diff --git a/fs/src/main/java/org/jnode/partitions/apm/ApmPartitionTable.java b/fs/src/main/java/org/jnode/partitions/apm/ApmPartitionTable.java index e68be04bff..239404d6e3 100644 --- a/fs/src/main/java/org/jnode/partitions/apm/ApmPartitionTable.java +++ b/fs/src/main/java/org/jnode/partitions/apm/ApmPartitionTable.java @@ -25,8 +25,8 @@ import java.util.Iterator; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.partitions.PartitionTable; import org.jnode.util.BigEndian; @@ -42,7 +42,7 @@ public class ApmPartitionTable implements PartitionTable private final List partitions = new ArrayList<>(); /** My logger */ - private static final Logger log = LogManager.getLogger(ApmPartitionTable.class); + private static final Logger log = System.getLogger(ApmPartitionTable.class.getName()); /** * Create a new instance @@ -56,7 +56,7 @@ public ApmPartitionTable(byte[] first16KiB, Device device) { long entries = BigEndian.getUInt32(first16KiB, 0x204); for (int partitionNumber = 0; partitionNumber < entries; partitionNumber++) { - log.debug("try part " + partitionNumber); + log.log(Level.DEBUG, "try part " + partitionNumber); int offset = 0x200 + (partitionNumber * 0x200); diff --git a/fs/src/main/java/org/jnode/partitions/gpt/GptPartitionTable.java b/fs/src/main/java/org/jnode/partitions/gpt/GptPartitionTable.java index b72ff30be5..70bcdc245c 100644 --- a/fs/src/main/java/org/jnode/partitions/gpt/GptPartitionTable.java +++ b/fs/src/main/java/org/jnode/partitions/gpt/GptPartitionTable.java @@ -26,8 +26,8 @@ import java.util.Iterator; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.partitions.PartitionTable; import org.jnode.partitions.ibm.IBMPartitionTable; @@ -49,7 +49,7 @@ public class GptPartitionTable implements PartitionTable private final List partitions = new ArrayList<>(); /** My logger */ - private static final Logger log = LogManager.getLogger(GptPartitionTable.class); + private static final Logger log = System.getLogger(GptPartitionTable.class.getName()); /** * Create a new instance @@ -66,12 +66,12 @@ public GptPartitionTable(byte[] first16KiB, Device device) { int entrySize = (int) LittleEndian.getUInt32(first16KiB, blockSize + 0x54); for (int partitionNumber = 0; partitionNumber < entries; partitionNumber++) { - log.debug("try part " + partitionNumber); + log.log(Level.DEBUG, "try part " + partitionNumber); int offset = blockSize * 2 + (partitionNumber * entrySize); GptPartitionTableEntry entry = new GptPartitionTableEntry(this, first16KiB, offset, blockSize); - log.debug(entry); + log.log(Level.DEBUG, entry); if (entry.isValid()) { partitions.add(entry); @@ -126,7 +126,7 @@ public static boolean containsPartitionTable(byte[] first16KiB, boolean requireP } if (entries.isEmpty() || entries.get(0).getSystemIndicator() != IBMPartitionTypes.PARTTYPE_EFI_GPT) { - log.debug("No protective MBR found: " + entries); + log.log(Level.DEBUG, "No protective MBR found: " + entries); return false; } } diff --git a/fs/src/main/java/org/jnode/partitions/gpt/GptPartitionTypes.java b/fs/src/main/java/org/jnode/partitions/gpt/GptPartitionTypes.java index 878a625622..3c135d7b3b 100644 --- a/fs/src/main/java/org/jnode/partitions/gpt/GptPartitionTypes.java +++ b/fs/src/main/java/org/jnode/partitions/gpt/GptPartitionTypes.java @@ -22,8 +22,8 @@ import java.util.UUID; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.util.NumberUtils; /** @@ -130,7 +130,7 @@ public enum GptPartitionTypes { /** * Logger */ - private static final Logger log = LogManager.getLogger(GptPartitionTypes.class); + private static final Logger log = System.getLogger(GptPartitionTypes.class.getName()); private UUID uuid; private final String name; @@ -188,7 +188,7 @@ public static GptPartitionTypes lookUp(byte[] partitionTypeGuid) { } } } catch (Exception e) { - log.warn("Exception checking uuid: " + uuidBuilder); + log.log(Level.WARNING, "Exception checking uuid: " + uuidBuilder); } return UNKNOWN; diff --git a/fs/src/main/java/org/jnode/partitions/ibm/IBMPartitionTable.java b/fs/src/main/java/org/jnode/partitions/ibm/IBMPartitionTable.java index e06f2e328e..28b36394dd 100644 --- a/fs/src/main/java/org/jnode/partitions/ibm/IBMPartitionTable.java +++ b/fs/src/main/java/org/jnode/partitions/ibm/IBMPartitionTable.java @@ -29,8 +29,8 @@ import java.util.List; import java.util.Set; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.ApiNotFoundException; import org.jnode.driver.Device; import org.jnode.driver.block.BlockDeviceAPI; @@ -83,7 +83,7 @@ public class IBMPartitionTable implements PartitionTable /** * My logger */ - private static final Logger log = LogManager.getLogger(IBMPartitionTable.class); + private static final Logger log = System.getLogger(IBMPartitionTable.class.getName()); /** * The position of the extendedPartition in the table @@ -101,11 +101,11 @@ public IBMPartitionTable(byte[] bootSector, Device device) { if (containsPartitionTable(bootSector)) { this.partitions = new IBMPartitionTableEntry[TABLE_SIZE]; for (int partNr = 0; partNr < partitions.length; partNr++) { - log.debug("try part " + partNr); + log.log(Level.DEBUG, "try part " + partNr); partitions[partNr] = new IBMPartitionTableEntry(this, bootSector, partNr); if (partitions[partNr].isExtended()) { extendedPartitionEntry = partNr; - log.debug("Found Extended partitions"); + log.log(Level.DEBUG, "Found Extended partitions"); handleExtended(partitions[partNr]); } } @@ -122,15 +122,15 @@ private void handleExtended(IBMPartitionTableEntry current) { final long startLBA = current.getStartLba(); final ByteBuffer sector = ByteBuffer.allocate(SECTOR_SIZE); try { - log.debug("Try to read the Extended Partition Table"); + log.log(Level.DEBUG, "Try to read the Extended Partition Table"); BlockDeviceAPI api = driveDevice.getAPI(BlockDeviceAPI.class); api.read(startLBA * SECTOR_SIZE, sector); } catch (ApiNotFoundException e) { // I think we can't get it - log.error("API Not Found Exception"); + log.log(Level.ERROR, "API Not Found Exception"); } catch (IOException e) { // I think we can't get it - log.error("IOException"); + log.log(Level.ERROR, "IOException"); } IBMPartitionTableEntry entry; @@ -167,37 +167,37 @@ public static boolean containsPartitionTable(byte[] bootSector) { } if (LittleEndian.getUInt16(bootSector, 510) != 0xaa55) { - log.debug("No aa55 magic"); + log.log(Level.DEBUG, "No aa55 magic"); return false; } if (LittleEndian.getUInt16(bootSector, 428) == 0x5678) { // Matches the AAP MBR extra signature, probably an valid partition table - log.debug("Has AAP MBR extra signature"); + log.log(Level.DEBUG, "Has AAP MBR extra signature"); return true; } if (LittleEndian.getUInt16(bootSector, 380) == 0xa55a) { // Matches the AST/NEC MBR extra signature, probably an valid partition table - log.debug("Has AST/NEC MBR extra signature"); + log.log(Level.DEBUG, "Has AST/NEC MBR extra signature"); return true; } if (LittleEndian.getUInt16(bootSector, 252) == 0x55aa) { // Matches the Disk Manager MBR extra signature, probably an valid partition table - log.debug("Has Disk Manager MBR extra signature"); + log.log(Level.DEBUG, "Has Disk Manager MBR extra signature"); return true; } if (LittleEndian.getUInt32(bootSector, 2) == 0x4c57454e) { // Matches the NEWLDR MBR extra signature, probably an valid partition table - log.debug("Has NEWLDR MBR extra signature"); + log.log(Level.DEBUG, "Has NEWLDR MBR extra signature"); return true; } if (LittleEndian.getUInt32(bootSector, 6) == 0x4f4c494c) { // Matches the LILO signature, probably an valid partition table - log.debug("Has LILO signature"); + log.log(Level.DEBUG, "Has LILO signature"); return true; } @@ -206,7 +206,7 @@ public static boolean containsPartitionTable(byte[] bootSector) { // "\r\nMissing operating system\r\n\u0000\r\nMaster Boot Record Error\r\n\u0000\r\nPress a key.\r\n\u0000" // "\r\nManglende operativ system\r\n\u0000\r\nFeil i hovedoppstartsposten\r\n\u0000\r\nTrykk en tast" - log.debug("Has HP boot code signature"); + log.log(Level.DEBUG, "Has HP boot code signature"); return true; } @@ -216,7 +216,7 @@ public static boolean containsPartitionTable(byte[] bootSector) { // Matches DOS 2.0 partition boot code error message signature // see: // http://thestarman.narod.ru/asm/mbr/200MBR.htm - log.debug("Has DOS 2.0 code error string signature"); + log.log(Level.DEBUG, "Has DOS 2.0 code error string signature"); return true; } @@ -227,7 +227,7 @@ public static boolean containsPartitionTable(byte[] bootSector) { // http://thestarman.narod.ru/asm/mbr/Win2kmbr.htm // http://thestarman.narod.ru/asm/mbr/95BMEMBR.htm // http://thestarman.narod.ru/asm/mbr/STDMBR.htm - log.debug("Has Microsoft code error string signature"); + log.log(Level.DEBUG, "Has Microsoft code error string signature"); return true; } @@ -237,37 +237,37 @@ public static boolean containsPartitionTable(byte[] bootSector) { // // see: // http://thestarman.narod.ru/asm/mbr/Win2kmbr.htm - log.debug("Has w2k boot code signature"); + log.log(Level.DEBUG, "Has w2k boot code signature"); return true; } if (bootSectorAsString.contains("Read\u0000Boot\u0000 error\r\n\u0000")) { // Matches BSD partition boot code error message signature - log.debug("Has BSD code error string signature"); + log.log(Level.DEBUG, "Has BSD code error string signature"); return true; } if (bootSectorAsString.contains("GRUB \u0000Geom\u0000Hard Disk\u0000Read\u0000 Error")) { // Matches GRUB string signature - log.debug("Has GRUB string signature"); + log.log(Level.DEBUG, "Has GRUB string signature"); return true; } if (bootSectorAsString.contains("\u0000Multiple active partitions.\r\n")) { // Matches SYSLINUX string signature - log.debug("Has SYSLINUX string signature"); + log.log(Level.DEBUG, "Has SYSLINUX string signature"); return true; } if (bootSectorAsString.contains("MAKEBOOT")) { // Matches MAKEBOOT string extra signature - log.debug("Has MAKEBOOT string signature"); + log.log(Level.DEBUG, "Has MAKEBOOT string signature"); return true; } if (bootSectorAsString.contains("MBR \u0010\u0000")) { // Matches MBR string extra signature - log.debug("Has MBR string signature"); + log.log(Level.DEBUG, "Has MBR string signature"); return true; } @@ -276,7 +276,7 @@ public static boolean containsPartitionTable(byte[] bootSector) { // * 0xF1 - Windows Vista // * 0x18E - Windows PE // see http://thestarman.pcministry.com/asm/mbr/VistaMBR.htm - log.debug("Has TCPA extra signature"); + log.log(Level.DEBUG, "Has TCPA extra signature"); return true; } @@ -284,7 +284,7 @@ public static boolean containsPartitionTable(byte[] bootSector) { if (bsdNameTabString.contains("Linu\ufffd") || bsdNameTabString.contains("FreeBS\ufffd")) { // Matches BSD nametab entries signature - log.debug("Has BSD nametab entries"); + log.log(Level.DEBUG, "Has BSD nametab entries"); return true; } @@ -294,7 +294,7 @@ public static boolean containsPartitionTable(byte[] bootSector) { if ("HdrS".equals(linuxKernelHeaderString)) { // Matches Linux kernel header signature - log.debug("Has Linux kernel header signature"); + log.log(Level.DEBUG, "Has Linux kernel header signature"); return false; } } @@ -302,18 +302,18 @@ public static boolean containsPartitionTable(byte[] bootSector) { // Check if this looks like a filesystem instead of a partition table String oemName = new String(bootSector, 3, 8, StandardCharsets.US_ASCII); if (FILESYSTEM_OEM_NAMES.contains(oemName)) { - log.debug("Looks like a file system instead of a partition table."); + log.log(Level.DEBUG, "Looks like a file system instead of a partition table."); return false; } if (LittleEndian.getUInt32(bootSector, 0xc) == 0x504E0000) { // Matches the 'NP' signature - log.debug("Matches the 'NP' signature"); + log.log(Level.DEBUG, "Matches the 'NP' signature"); return true; } // Nothing matched, fall back to validating any specified partition entries - log.debug("Checking partitions"); + log.log(Level.DEBUG, "Checking partitions"); List entries = new ArrayList<>(); for (int partitionNumber = 0; partitionNumber < TABLE_SIZE; partitionNumber++) { IBMPartitionTableEntry partition = new IBMPartitionTableEntry(null, bootSector, partitionNumber); @@ -333,7 +333,7 @@ public static boolean containsPartitionTable(byte[] bootSector) { if (partition.getStartLba() <= otherPartition.getStartLba() + otherPartition.getNrSectors() - 1 && otherPartition.getStartLba() <= partition.getStartLba() + partition.getNrSectors() - 1) { - log.error("Parition table entries overlap: " + partition + " " + otherPartition); + log.log(Level.ERROR, "Parition table entries overlap: " + partition + " " + otherPartition); return false; } } @@ -345,7 +345,7 @@ public static boolean containsPartitionTable(byte[] bootSector) { } public Iterator iterator() { - return new Iterator() { + return new Iterator<>() { private int index = 0; private final int last = (partitions == null) ? 0 : partitions.length; diff --git a/fs/src/main/java/org/jnode/partitions/ibm/IBMPartitionTableEntry.java b/fs/src/main/java/org/jnode/partitions/ibm/IBMPartitionTableEntry.java index ba58a7cf3c..a3c0141c42 100644 --- a/fs/src/main/java/org/jnode/partitions/ibm/IBMPartitionTableEntry.java +++ b/fs/src/main/java/org/jnode/partitions/ibm/IBMPartitionTableEntry.java @@ -20,10 +20,8 @@ package org.jnode.partitions.ibm; -import java.util.logging.Level; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.block.CHS; import org.jnode.partitions.PartitionTableEntry; import org.jnode.util.LittleEndian; @@ -37,7 +35,7 @@ public class IBMPartitionTableEntry implements PartitionTableEntry { private static final int BOOTABLE = 0x80; - private final Logger log = LogManager.getLogger(getClass()); + private static final Logger log = System.getLogger(IBMPartitionTableEntry.class.getName()); private final byte[] bs; private final int ofs; @@ -55,7 +53,7 @@ public IBMPartitionTableEntry(IBMPartitionTable parent, byte[] bs, int partNr) { @Override public boolean isValid() { int bootIndicatorValue = getBootIndicatorValue(); -Debug.println(Level.FINE, "bootIndicatorValue:" + bootIndicatorValue + ", empty: " + isEmpty() + ", nrSectors: " + getNrSectors()); +log.log(Level.DEBUG, "bootIndicatorValue:" + bootIndicatorValue + ", empty: " + isEmpty() + ", nrSectors: " + getNrSectors()); return !isEmpty() && (bootIndicatorValue == 0 || bootIndicatorValue == BOOTABLE) && @@ -93,7 +91,7 @@ public boolean getBootIndicator() { } public int getBootIndicatorValue() { -Debug.println(Level.FINE, "getBootIndicatorValue: ofs: " + (ofs + 0) + ", value: " + LittleEndian.getUInt8(bs, ofs + 0)); +log.log(Level.DEBUG, "getBootIndicatorValue: ofs: " + (ofs + 0) + ", value: " + LittleEndian.getUInt8(bs, ofs + 0)); return LittleEndian.getUInt8(bs, ofs + 0); } @@ -127,7 +125,7 @@ public IBMPartitionTypes getSystemIndicator() { try { return IBMPartitionTypes.valueOf(code); } catch (IllegalArgumentException e) { - log.debug("Unknown or invalid system indicator code: 0x" + Integer.toHexString(code)); + log.log(Level.DEBUG, "Unknown or invalid system indicator code: 0x" + Integer.toHexString(code)); return IBMPartitionTypes.PARTTYPE_UNKNOWN; } } diff --git a/fs/src/main/java/vavi/nio/file/jnode/JNodeFileSystemDriver.java b/fs/src/main/java/vavi/nio/file/jnode/JNodeFileSystemDriver.java index c474a7ed02..65433df1e4 100644 --- a/fs/src/main/java/vavi/nio/file/jnode/JNodeFileSystemDriver.java +++ b/fs/src/main/java/vavi/nio/file/jnode/JNodeFileSystemDriver.java @@ -158,7 +158,7 @@ protected T createDirectoryEntry(T parentEntry, Path dir) throws IOException { @Override protected boolean hasChildren(T dirEntry, Path dir) throws IOException { - return getDirectoryEntries(dirEntry, dir).size() > 0; + return !getDirectoryEntries(dirEntry, dir).isEmpty(); } @Override diff --git a/fs/src/test/java/vavi/nio/file/jnode/JNodeTest.java b/fs/src/test/java/vavi/nio/file/jnode/JNodeTest.java index f41894706b..eca5cf795b 100644 --- a/fs/src/test/java/vavi/nio/file/jnode/JNodeTest.java +++ b/fs/src/test/java/vavi/nio/file/jnode/JNodeTest.java @@ -6,7 +6,6 @@ package vavi.nio.file.jnode; -import java.io.BufferedInputStream; import java.io.IOException; import java.net.URI; import java.nio.file.FileSystem; @@ -16,13 +15,10 @@ import java.util.Collections; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIf; - import vavi.util.Debug; -import vavi.util.StringUtil; import vavi.util.properties.annotation.Property; import vavi.util.properties.annotation.PropsEntity; @@ -41,6 +37,8 @@ static boolean localPropertiesExists() { return Files.exists(Paths.get("local.properties")); } + @Property + String avdsdcard; @Property String exfat; @Property @@ -59,7 +57,7 @@ void before() throws IOException { @DisplayName("by scheme, raw disk") void test() throws Exception { Path exfatPath = Paths.get(exfat); -Debug.println("disc: " + exfat + ", " + Files.exists(exfatPath)); +Debug.println("disc: " + exfatPath + ", " + Files.exists(exfatPath)); URI uri = URI.create("jnode:exfat:" + exfatPath.toUri()); FileSystem fs = new JNodeFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); // Files.list(fs.getRootDirectories().iterator().next()).forEach(System.err::println); @@ -76,7 +74,7 @@ void test() throws Exception { @DisplayName("by partition, parted disk") void test2() throws Exception { Path dmgPath = Paths.get(dmg); -Debug.println("disc: " + dmg + ", " + Files.exists(dmgPath)); +Debug.println("disc: " + dmgPath + ", " + Files.exists(dmgPath)); URI uri = URI.create("jnode:" + dmgPath.toUri()); FileSystem fs = new JNodeFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); Files.walk(fs.getRootDirectories().iterator().next()).forEach(p -> { @@ -92,7 +90,7 @@ void test2() throws Exception { @DisplayName("by partition, raw disk") void test3() throws Exception { Path exfatPath = Paths.get(exfat); -Debug.println("disc: " + exfat + ", " + Files.exists(exfatPath)); +Debug.println("disc: " + exfatPath + ", " + Files.exists(exfatPath)); URI uri = URI.create("jnode:" + exfatPath.toUri()); FileSystem fs = new JNodeFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); Files.walk(fs.getRootDirectories().iterator().next()).forEach(p -> { @@ -108,7 +106,7 @@ void test3() throws Exception { @DisplayName("dmg jfat:fat16") void test4() throws Exception { Path dmgPath = Paths.get(dmg); -Debug.println("disc: " + dmg + ", " + Files.exists(dmgPath)); +Debug.println("disc: " + dmgPath + ", " + Files.exists(dmgPath)); URI uri = URI.create("jnode:" + dmgPath.toUri()); FileSystem fs = new JNodeFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); Files.walk(fs.getRootDirectories().iterator().next()).forEach(p -> { @@ -125,7 +123,7 @@ void test4() throws Exception { // @Disabled("wip d88") void test5() throws Exception { Path d88Path = Paths.get(d88); -Debug.println("disc: " + d88 + ", " + Files.exists(d88Path)); +Debug.println("disc: " + d88Path + ", " + Files.exists(d88Path)); URI uri = URI.create("jnode:" + d88Path.toUri()); FileSystem fs = new JNodeFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); Files.walk(fs.getRootDirectories().iterator().next()).forEach(p -> { @@ -141,7 +139,7 @@ void test5() throws Exception { @DisplayName("fdi fat12") void test6() throws Exception { Path fidPath = Paths.get(fdi); -Debug.println("disc: " + fdi + ", " + Files.exists(fidPath)); +Debug.println("disc: " + fidPath + ", " + Files.exists(fidPath)); URI uri = URI.create("jnode:" + fidPath.toUri()); FileSystem fs = new JNodeFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); Files.walk(fs.getRootDirectories().iterator().next()).forEach(p -> { @@ -153,6 +151,23 @@ void test6() throws Exception { e.printStackTrace(); } }); - }} + } + + @Test + @DisplayName("by partition, raw disk") + void test7() throws Exception { + Path exfatPath = Paths.get(avdsdcard); +Debug.println("disc: " + exfatPath + ", " + Files.exists(exfatPath)); + URI uri = URI.create("jnode:" + exfatPath.toUri()); + FileSystem fs = new JNodeFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); + Files.walk(fs.getRootDirectories().iterator().next()).forEach(p -> { + try { + System.err.println(p + ", " + Files.getLastModifiedTime(p)); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } +} /* */ diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000000..efde7bf258 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk17 diff --git a/net/.checkstyle b/net/.checkstyle deleted file mode 100644 index b889bd04b2..0000000000 --- a/net/.checkstyle +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/net/pom.xml b/net/pom.xml index 9b073733b4..2e151ad440 100644 --- a/net/pom.xml +++ b/net/pom.xml @@ -4,27 +4,16 @@ vavi vavi-nio-file-jnode - 0.2.11v + 0.2.12 jnode-net - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - 1.8 - 1.8 - UTF-8 - - org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M7 -Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties @@ -46,13 +35,13 @@ vavi jnode-core - 0.2.11v + 0.2.12 commons-net commons-net - 3.9.0 + 3.10.0 com.github.dnsjava @@ -62,12 +51,7 @@ org.acplt.remotetea remotetea-oncrpc - 1.1.4 - - - - org.apache.logging.log4j - log4j-api + 1.1.5 @@ -92,16 +76,5 @@ 0.1.55 test - - - org.apache.logging.log4j - log4j-core - test - - - org.apache.logging.log4j - log4j-jul - test - diff --git a/net/src/main/java/org/jnode/net/SocketBuffer.java b/net/src/main/java/org/jnode/net/SocketBuffer.java index 426e7624c2..649df0bde8 100644 --- a/net/src/main/java/org/jnode/net/SocketBuffer.java +++ b/net/src/main/java/org/jnode/net/SocketBuffer.java @@ -20,8 +20,8 @@ package org.jnode.net; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; /** @@ -43,7 +43,7 @@ public class SocketBuffer { private static final int INITIAL_SIZE = 256; /** My logger */ - private static final Logger log = LogManager.getLogger(SocketBuffer.class); + private static final Logger log = System.getLogger(SocketBuffer.class.getName()); /** Actual data */ private byte[] data; /** Size of the buffer that is in use */ @@ -540,7 +540,7 @@ public void get(byte[] dst, int dstOffset, int index, int length) { } } } catch (IndexOutOfBoundsException ex) { - log.debug("get(dst, " + dstOffset + ", " + index + ", " + length + ") start=" + start + + log.log(Level.DEBUG, "get(dst, " + dstOffset + ", " + index + ", " + length + ") start=" + start + ", size=" + size); throw new IndexOutOfBoundsException(ex.getMessage()); } diff --git a/net/src/main/java/org/jnode/net/arp/ARPCache.java b/net/src/main/java/org/jnode/net/arp/ARPCache.java index bb6b4bda77..d25625fb70 100644 --- a/net/src/main/java/org/jnode/net/arp/ARPCache.java +++ b/net/src/main/java/org/jnode/net/arp/ARPCache.java @@ -25,8 +25,8 @@ import java.util.HashMap; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.HardwareAddress; import org.jnode.net.ProtocolAddress; @@ -37,7 +37,7 @@ */ public class ARPCache { - private static final Logger log = LogManager.getLogger(ARPCache.class); + private static final Logger log = System.getLogger(ARPCache.class.getName()); private final Map networkToProtocolAddresses = new HashMap<>(); @@ -79,7 +79,7 @@ public synchronized HardwareAddress get(ProtocolAddress protocolAddress) { return null; } if (entry.isExpired()) { - log.debug("Removing expired ARP entry " + entry); + log.log(Level.DEBUG, "Removing expired ARP entry " + entry); protocolToNetworkAddresses.remove(protocolAddress); if (networkToProtocolAddresses.get(entry.getHwAddress()) == entry) { networkToProtocolAddresses.remove(entry.getHwAddress()); diff --git a/net/src/main/java/org/jnode/net/arp/ARPNetworkLayer.java b/net/src/main/java/org/jnode/net/arp/ARPNetworkLayer.java index d0aff14d42..18141f12d5 100644 --- a/net/src/main/java/org/jnode/net/arp/ARPNetworkLayer.java +++ b/net/src/main/java/org/jnode/net/arp/ARPNetworkLayer.java @@ -24,8 +24,8 @@ import java.util.ArrayList; import java.util.Collection; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.ApiNotFoundException; import org.jnode.driver.Device; import org.jnode.driver.net.NetDeviceAPI; @@ -58,7 +58,7 @@ public class ARPNetworkLayer implements NetworkLayer { /** * My logger */ - private static final Logger log = LogManager.getLogger(ARPNetworkLayer.class); + private static final Logger log = System.getLogger(ARPNetworkLayer.class.getName()); private static final boolean DEBUG = false; @@ -134,7 +134,7 @@ public void receive(SocketBuffer skbuf, NetDeviceAPI deviceAPI) throws SocketExc processRARPReply(skbuf, hdr, deviceAPI); break; default: { - log.debug("Unknown ARP operation " + hdr.getOperation()); + log.log(Level.DEBUG, "Unknown ARP operation " + hdr.getOperation()); } } } @@ -152,7 +152,7 @@ private void processARPRequest(SocketBuffer skbuf, ARPHeader hdr, NetDeviceAPI d final ProtocolAddressInfo addrInfo = deviceAPI.getProtocolAddressInfo(hdr.getPType()); if ((addrInfo != null) && (addrInfo.contains(hdr.getTargetPAddress()))) { - // log.debug("Sending ARP reply"); + // log.log(Level.DEBUG, "Sending ARP reply"); stat.arpreply.inc(); stat.opackets.inc(); hdr.swapAddresses(); @@ -163,7 +163,7 @@ private void processARPRequest(SocketBuffer skbuf, ARPHeader hdr, NetDeviceAPI d hdr.prefixTo(skbuf); deviceAPI.transmit(skbuf, hdr.getTargetHWAddress()); } else { - // log.debug("ARP request, not my IP-address"); + // log.log(Level.DEBUG, "ARP request, not my IP-address"); } } @@ -191,7 +191,7 @@ private void processARPReply(SocketBuffer skbuf, ARPHeader hdr, NetDeviceAPI dev private void processRARPRequest(SocketBuffer skbuf, ARPHeader hdr, NetDeviceAPI deviceAPI) throws SocketException { stat.rarpreq.inc(); - log.debug("GOT RARP Request"); + log.log(Level.DEBUG, "GOT RARP Request"); } /** @@ -204,7 +204,7 @@ private void processRARPRequest(SocketBuffer skbuf, ARPHeader hdr, NetDeviceAPI */ private void processRARPReply(SocketBuffer skbuf, ARPHeader hdr, NetDeviceAPI deviceAPI) throws SocketException { - log.debug("GOT RARP Reply"); + log.log(Level.DEBUG, "GOT RARP Reply"); } /** @@ -268,10 +268,8 @@ public HardwareAddress getHardwareAddress(ProtocolAddress address, ProtocolAddre long lastReq = 0; if (DEBUG) { - if (log.isDebugEnabled()) { - log.debug("getHardwareAddress(" + address + ", " + myAddress + ", " + device.getId() + + log.log(Level.DEBUG, "getHardwareAddress(" + address + ", " + myAddress + ", " + device.getId() + ", " + timeout + ')'); - } } if (address.equals(myAddress)) { diff --git a/net/src/main/java/org/jnode/net/ipv4/IPv4FragmentList.java b/net/src/main/java/org/jnode/net/ipv4/IPv4FragmentList.java index c91a256383..2d741af7fa 100644 --- a/net/src/main/java/org/jnode/net/ipv4/IPv4FragmentList.java +++ b/net/src/main/java/org/jnode/net/ipv4/IPv4FragmentList.java @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.Iterator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.SocketBuffer; /** @@ -35,7 +35,7 @@ public class IPv4FragmentList implements IPv4Constants { /** My logger */ - private static final Logger log = LogManager.getLogger(IPv4FragmentList.class); + private static final Logger log = System.getLogger(IPv4FragmentList.class.getName()); /** When was this object created */ private final long creationTime; /** List of fragments */ @@ -108,7 +108,7 @@ public void add(SocketBuffer skbuf) { return; } else if (myFrOfs < (fOfs + fSize)) { // Fragment offset in the middle of an existing fragment: this is an error! - log.debug("Fragment offset(" + myFrOfs + mySize + ',' + + log.log(Level.DEBUG, "Fragment offset(" + myFrOfs + mySize + ',' + ") falls in another fragment (" + fOfs + ',' + fSize + ")."); return; } diff --git a/net/src/main/java/org/jnode/net/ipv4/bootp/AbstractBOOTPClient.java b/net/src/main/java/org/jnode/net/ipv4/bootp/AbstractBOOTPClient.java index 5fef30576a..5b30c13931 100644 --- a/net/src/main/java/org/jnode/net/ipv4/bootp/AbstractBOOTPClient.java +++ b/net/src/main/java/org/jnode/net/ipv4/bootp/AbstractBOOTPClient.java @@ -26,8 +26,8 @@ import java.net.MulticastSocket; import java.net.NetworkInterface; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.HardwareAddress; import org.jnode.net.ipv4.IPv4Address; @@ -42,7 +42,7 @@ public class AbstractBOOTPClient { /** * My logger */ - private static final Logger log = LogManager.getLogger(AbstractBOOTPClient.class); + private static final Logger log = System.getLogger(AbstractBOOTPClient.class.getName()); private static final int RECEIVE_TIMEOUT = 10 * 1000; // 10 seconds public static final int SERVER_PORT = 67; @@ -67,7 +67,7 @@ protected final void configureDevice(final String deviceName, final HardwareAddr // Create the BOOTP header final Inet4Address myIP = null; // any address - final int transactionID = (int) (System.currentTimeMillis() & 0xFFFFFFFF); + final int transactionID = (int) (System.currentTimeMillis() & 0xFFFF_FFFFL); BOOTPHeader hdr = new BOOTPHeader(BOOTPHeader.BOOTREQUEST, transactionID, 0, myIP, hwAddress); @@ -126,9 +126,9 @@ protected boolean processResponse(int transactionID, DatagramPacket packet) thro * settings in a BOOTP header. */ protected void doConfigure(BOOTPHeader hdr) throws IOException { - log.info("Got Client IP address : " + hdr.getClientIPAddress()); - log.info("Got Your IP address : " + hdr.getYourIPAddress()); - log.info("Got Server IP address : " + hdr.getServerIPAddress()); - log.info("Got Gateway IP address : " + hdr.getGatewayIPAddress()); + log.log(Level.INFO, "Got Client IP address : " + hdr.getClientIPAddress()); + log.log(Level.INFO, "Got Your IP address : " + hdr.getYourIPAddress()); + log.log(Level.INFO, "Got Server IP address : " + hdr.getServerIPAddress()); + log.log(Level.INFO, "Got Gateway IP address : " + hdr.getGatewayIPAddress()); } } diff --git a/net/src/main/java/org/jnode/net/ipv4/bootp/BOOTPServer.java b/net/src/main/java/org/jnode/net/ipv4/bootp/BOOTPServer.java index cf2f4e236a..978c5c04e9 100644 --- a/net/src/main/java/org/jnode/net/ipv4/bootp/BOOTPServer.java +++ b/net/src/main/java/org/jnode/net/ipv4/bootp/BOOTPServer.java @@ -32,8 +32,8 @@ import java.util.List; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.nanoxml.XMLElement; import org.jnode.net.ipv4.IPv4Address; @@ -42,7 +42,7 @@ */ public class BOOTPServer { - private static final Logger log = LogManager.getLogger(BOOTPServer.class); + private static final Logger log = System.getLogger(BOOTPServer.class.getName()); public static final int SERVER_PORT = 67; public static final int CLIENT_PORT = 68; @@ -59,7 +59,7 @@ public static void main(String[] args) { server.loadTable(filename); server.run(); } catch (IOException ex) { - LogManager.getLogger(BOOTPServer.class).debug("I/O exception", ex); + log.log(Level.DEBUG, "I/O exception", ex); } } @@ -88,7 +88,7 @@ private void loadTable(String filename) throws IOException { table.put(child.getStringAttribute("ethernetAddress").toUpperCase(), new TableEntry(child)); } catch (IllegalArgumentException ex) { - log.debug("Invalid IP address", ex); + log.log(Level.DEBUG, "Invalid IP address", ex); } } } @@ -109,7 +109,7 @@ private void run() throws SocketException { socket.receive(packet); processRequest(packet); } catch (IOException ex) { - log.debug("I/O exception", ex); + log.log(Level.DEBUG, "I/O exception", ex); } } } finally { @@ -118,7 +118,7 @@ private void run() throws SocketException { } private void processRequest(DatagramPacket packet) throws IOException { - log.debug("Received packet: " + packet.getAddress() + ':' + packet.getPort() + ' ' + + log.log(Level.DEBUG, "Received packet: " + packet.getAddress() + ':' + packet.getPort() + ' ' + new String(packet.getData(), packet.getOffset(), packet.getLength())); BOOTPHeader hdr = new BOOTPHeader(packet); if (hdr.getOpcode() != BOOTPHeader.BOOTREQUEST) { @@ -126,17 +126,17 @@ private void processRequest(DatagramPacket packet) throws IOException { return; } - log.debug("Got Client IP address : " + hdr.getClientIPAddress()); - log.debug("Got Your IP address : " + hdr.getYourIPAddress()); - log.debug("Got Server IP address : " + hdr.getServerIPAddress()); - log.debug("Got Gateway IP address : " + hdr.getGatewayIPAddress()); - log.debug("Got Hardware address : " + hdr.getClientHwAddress()); + log.log(Level.DEBUG, "Got Client IP address : " + hdr.getClientIPAddress()); + log.log(Level.DEBUG, "Got Your IP address : " + hdr.getYourIPAddress()); + log.log(Level.DEBUG, "Got Server IP address : " + hdr.getServerIPAddress()); + log.log(Level.DEBUG, "Got Gateway IP address : " + hdr.getGatewayIPAddress()); + log.log(Level.DEBUG, "Got Hardware address : " + hdr.getClientHwAddress()); TableEntry entry = table.get(hdr.getClientHwAddress().toString().toUpperCase()); if (entry == null) { // no entry in table - log.debug("No match for hardware address found in table"); + log.log(Level.DEBUG, "No match for hardware address found in table"); return; } Inet4Address yourIP = entry.address; diff --git a/net/src/main/java/org/jnode/net/ipv4/config/impl/ConfigurationProcessor.java b/net/src/main/java/org/jnode/net/ipv4/config/impl/ConfigurationProcessor.java index 3dd2cd1729..6257d2a80d 100644 --- a/net/src/main/java/org/jnode/net/ipv4/config/impl/ConfigurationProcessor.java +++ b/net/src/main/java/org/jnode/net/ipv4/config/impl/ConfigurationProcessor.java @@ -20,8 +20,8 @@ package org.jnode.net.ipv4.config.impl; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.util.Queue; import org.jnode.util.QueueProcessor; @@ -34,7 +34,7 @@ public class ConfigurationProcessor implements QueueProcessor queue = new Queue<>(); - static final Logger log = LogManager.getLogger(ConfigurationProcessor.class); + static final Logger log = System.getLogger(ConfigurationProcessor.class.getName()); private QueueProcessorThread thread; diff --git a/net/src/main/java/org/jnode/net/ipv4/config/impl/ConfigurationQueueEntry.java b/net/src/main/java/org/jnode/net/ipv4/config/impl/ConfigurationQueueEntry.java index c6bfa4ade7..2a030524a5 100644 --- a/net/src/main/java/org/jnode/net/ipv4/config/impl/ConfigurationQueueEntry.java +++ b/net/src/main/java/org/jnode/net/ipv4/config/impl/ConfigurationQueueEntry.java @@ -20,10 +20,13 @@ package org.jnode.net.ipv4.config.impl; +import java.lang.System.Logger.Level; + import org.jnode.driver.Device; import org.jnode.driver.net.NetworkException; final class ConfigurationQueueEntry { + private final Device device; private final NetDeviceConfig config; @@ -45,7 +48,7 @@ public synchronized void apply() { try { config.apply(device); } catch (NetworkException ex) { - ConfigurationProcessor.log.error("Cannot configure device " + device.getId(), ex); + ConfigurationProcessor.log.log(Level.ERROR, "Cannot configure device " + device.getId(), ex); } finally { ready = true; this.notifyAll(); diff --git a/net/src/main/java/org/jnode/net/ipv4/config/impl/NetConfigurationData.java b/net/src/main/java/org/jnode/net/ipv4/config/impl/NetConfigurationData.java index 7040af96be..28383a260b 100644 --- a/net/src/main/java/org/jnode/net/ipv4/config/impl/NetConfigurationData.java +++ b/net/src/main/java/org/jnode/net/ipv4/config/impl/NetConfigurationData.java @@ -20,13 +20,11 @@ package org.jnode.net.ipv4.config.impl; -import java.security.AccessController; -import java.security.PrivilegedAction; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jnode.driver.Device; /** @@ -35,7 +33,7 @@ final class NetConfigurationData { /** My logger */ - static final Logger log = LogManager.getLogger(NetConfigurationData.class); + static final Logger log = System.getLogger(NetConfigurationData.class.getName()); /** The preferences that contain my data */ private final Preferences prefs; @@ -79,27 +77,23 @@ public NetDeviceConfig getConfiguration(Device device) { final Preferences devPrefs = devConfigsPrefs.node(device.getId()); final String clsName = devPrefs.get(CONFIG_CLASS_NAME_KEY, null); if (clsName != null) { - final PrivilegedAction action = () -> { - try { - final Class cls = - Thread.currentThread().getContextClassLoader().loadClass(clsName); - return cls.newInstance(); - } catch (ClassNotFoundException ex) { - log.warn("NetDeviceConfig class not found", ex); - return null; - } catch (InstantiationException ex) { - log.warn("Cannot instantiate NetDeviceConfig class", ex); - return null; - } catch (IllegalAccessException ex) { - log.warn("Cannot access NetDeviceConfig class", ex); - return null; - } - }; - cfg = (NetDeviceConfig) AccessController.doPrivileged(action); + try { + final Class cls = Thread.currentThread().getContextClassLoader().loadClass(clsName); + return (NetDeviceConfig) cls.newInstance(); + } catch (ClassNotFoundException ex) { + log.log(Level.WARNING, "NetDeviceConfig class not found", ex); + return null; + } catch (InstantiationException ex) { + log.log(Level.WARNING, "Cannot instantiate NetDeviceConfig class", ex); + return null; + } catch (IllegalAccessException ex) { + log.log(Level.WARNING, "Cannot access NetDeviceConfig class", ex); + return null; + } } } } catch (BackingStoreException ex) { - log.warn("BackingStore error while loading NetDeviceConfig preferences", ex); + log.log(Level.WARNING, "BackingStore error while loading NetDeviceConfig preferences", ex); // Ignore } diff --git a/net/src/main/java/org/jnode/net/ipv4/config/impl/NetDeviceMonitor.java b/net/src/main/java/org/jnode/net/ipv4/config/impl/NetDeviceMonitor.java index d23a889e0b..fb3d3d8357 100644 --- a/net/src/main/java/org/jnode/net/ipv4/config/impl/NetDeviceMonitor.java +++ b/net/src/main/java/org/jnode/net/ipv4/config/impl/NetDeviceMonitor.java @@ -20,8 +20,8 @@ package org.jnode.net.ipv4.config.impl; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.driver.net.NetDeviceAPI; @@ -33,7 +33,7 @@ final class NetDeviceMonitor { /** My logger */ - private static final Logger log = LogManager.getLogger(NetDeviceMonitor.class); + private static final Logger log = System.getLogger(NetDeviceMonitor.class.getName()); private final ConfigurationProcessor processor; private final NetConfigurationData config; @@ -63,7 +63,7 @@ public void deviceStop(Device device) { } private void configureDevice(Device dev) { - log.info("Configuring " + dev.getId()); + log.log(Level.INFO, "Configuring " + dev.getId()); final NetDeviceConfig cfg = config.getConfiguration(dev); if (cfg != null) { processor.apply(dev, cfg, false); diff --git a/net/src/main/java/org/jnode/net/ipv4/dhcp/AbstractDHCPClient.java b/net/src/main/java/org/jnode/net/ipv4/dhcp/AbstractDHCPClient.java index 071510e629..aae9e944df 100644 --- a/net/src/main/java/org/jnode/net/ipv4/dhcp/AbstractDHCPClient.java +++ b/net/src/main/java/org/jnode/net/ipv4/dhcp/AbstractDHCPClient.java @@ -24,8 +24,8 @@ import java.net.DatagramPacket; import java.net.InetAddress; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.ipv4.IPv4Address; import org.jnode.net.ipv4.bootp.AbstractBOOTPClient; import org.jnode.net.ipv4.bootp.BOOTPHeader; @@ -38,7 +38,7 @@ */ public class AbstractDHCPClient extends AbstractBOOTPClient { - private static final Logger log = LogManager.getLogger(AbstractDHCPClient.class); + private static final Logger log = System.getLogger(AbstractDHCPClient.class.getName()); /** * Create a DHCP discovery packet @@ -61,23 +61,23 @@ protected boolean processResponse(int transactionID, DatagramPacket packet) thro } // debug the DHCP message - if (log.isDebugEnabled()) { - log.debug("Got Client IP address : " + hdr.getClientIPAddress()); - log.debug("Got Your IP address : " + hdr.getYourIPAddress()); - log.debug("Got Server IP address : " + hdr.getServerIPAddress()); - log.debug("Got Gateway IP address : " + hdr.getGatewayIPAddress()); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "Got Client IP address : " + hdr.getClientIPAddress()); + log.log(Level.DEBUG, "Got Your IP address : " + hdr.getYourIPAddress()); + log.log(Level.DEBUG, "Got Server IP address : " + hdr.getServerIPAddress()); + log.log(Level.DEBUG, "Got Gateway IP address : " + hdr.getGatewayIPAddress()); for (int n = 1; n < 255; n++) { byte[] value = msg.getOption(n); if (value != null) { if (value.length == 1) { - log.debug("Option " + n + " : " + (int) (value[0])); + log.log(Level.DEBUG, "Option " + n + " : " + (int) (value[0])); } else if (value.length == 2) { - log.debug("Option " + n + " : " + ((value[0] << 8) | value[1])); + log.log(Level.DEBUG, "Option " + n + " : " + ((value[0] << 8) | value[1])); } else if (value.length == 4) { - log.debug("Option " + n + " : " + + log.log(Level.DEBUG, "Option " + n + " : " + InetAddress.getByAddress(value)); } else { - log.debug("Option " + n + " : " + new String(value)); + log.log(Level.DEBUG, "Option " + n + " : " + new String(value)); } } } diff --git a/net/src/main/java/org/jnode/net/ipv4/dhcp/DHCPClient.java b/net/src/main/java/org/jnode/net/ipv4/dhcp/DHCPClient.java index 67d9cd5858..d73e069a5d 100644 --- a/net/src/main/java/org/jnode/net/ipv4/dhcp/DHCPClient.java +++ b/net/src/main/java/org/jnode/net/ipv4/dhcp/DHCPClient.java @@ -29,8 +29,8 @@ import java.util.NoSuchElementException; import java.util.ServiceLoader; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.ApiNotFoundException; import org.jnode.driver.Device; import org.jnode.driver.net.NetDeviceAPI; @@ -49,7 +49,7 @@ */ public class DHCPClient extends AbstractDHCPClient { - private static final Logger log = LogManager.getLogger(DHCPClient.class); + private static final Logger log = System.getLogger(DHCPClient.class.getName()); private Device device; private NetDeviceAPI api; @@ -62,28 +62,13 @@ public class DHCPClient extends AbstractDHCPClient { public final void configureDevice(final Device device) throws IOException { this.device = device; - final SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new NetPermission("dhcpClient")); - } - + // Get the API. try { - AccessController.doPrivileged((PrivilegedExceptionAction) () -> { - // Get the API. - try { - api = device.getAPI(NetDeviceAPI.class); - } catch (ApiNotFoundException ex) { - throw new NetworkException("Device is not a network device", ex); - } - configureDevice(device.getId(), api.getAddress()); - return null; - }); - } catch (PrivilegedActionException ex) { - throw (IOException) ex.getException(); + api = device.getAPI(NetDeviceAPI.class); + } catch (ApiNotFoundException ex) { + throw new NetworkException("Device is not a network device", ex); } - - this.api = null; - this.device = null; + configureDevice(device.getId(), api.getAddress()); } /** @@ -117,7 +102,7 @@ protected void doConfigure(DHCPMessage msg) throws IOException { byte[] routerValue = msg.getOption(DHCPMessage.ROUTER_OPTION); if (routerValue != null && routerValue.length >= 4) { IPv4Address routerIP = new IPv4Address(routerValue, 0); - log.info("Got Router IP address : " + routerIP); + log.log(Level.INFO, "Got Router IP address : " + routerIP); cfg.addRoute(IPv4Address.ANY, routerIP, device, false); } @@ -127,12 +112,12 @@ protected void doConfigure(DHCPMessage msg) throws IOException { for (int i = 0; i < dnsValue.length; i += 4) { final IPv4Address dnsIP = new IPv4Address(dnsValue, i); - log.info("Got Dns IP address : " + dnsIP); + log.log(Level.INFO, "Got Dns IP address : " + dnsIP); try { ResolverImpl.addDnsServer(dnsIP); } catch (Throwable ex) { - log.error("Failed to configure DNS server"); - log.debug("Failed to configure DNS server", ex); + log.log(Level.ERROR, "Failed to configure DNS server"); + log.log(Level.DEBUG, "Failed to configure DNS server", ex); } } } @@ -141,16 +126,13 @@ protected void doConfigure(DHCPMessage msg) throws IOException { final byte[] pluginLoaderValue = msg.getOption(DHCPMessage.PLUGIN_LOADER_OPTION); if (pluginLoaderValue != null) { final String pluginLoaderURL = new String(pluginLoaderValue, StandardCharsets.UTF_8); - log.info("Got plugin loader url : " + pluginLoaderURL); - AccessController.doPrivileged((PrivilegedAction) () -> { - try { - // TODO - } catch (Throwable ex) { - log.error("Failed to configure plugin loader"); - log.debug("Failed to configure plugin loader", ex); - } - return null; - }); + log.log(Level.INFO, "Got plugin loader url : " + pluginLoaderURL); + try { + // TODO + } catch (Throwable ex) { + log.log(Level.ERROR, "Failed to configure plugin loader"); + log.log(Level.DEBUG, "Failed to configure plugin loader", ex); + } } } } diff --git a/net/src/main/java/org/jnode/net/ipv4/icmp/ICMPProtocol.java b/net/src/main/java/org/jnode/net/ipv4/icmp/ICMPProtocol.java index 8a97abf70b..183b54a29f 100644 --- a/net/src/main/java/org/jnode/net/ipv4/icmp/ICMPProtocol.java +++ b/net/src/main/java/org/jnode/net/ipv4/icmp/ICMPProtocol.java @@ -25,8 +25,8 @@ import java.net.SocketImplFactory; import java.util.Vector; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.SocketBuffer; import org.jnode.net.ipv4.IPv4Constants; import org.jnode.net.ipv4.IPv4Header; @@ -50,7 +50,7 @@ public class ICMPProtocol implements IPv4Protocol, IPv4Constants, ICMPConstants, /** * My logger */ - private Logger log = LogManager.getLogger(getClass()); + private static final Logger log = System.getLogger(ICMPProtocol.class.getName()); /** * The IP service we're a part of @@ -128,7 +128,7 @@ public void receive(SocketBuffer skbuf) throws SocketException { notifyListeners(skbuf); break; default: - log.debug("GOT ICMP type " + hdr.getType() + ", code " + hdr.getCode()); + log.log(Level.DEBUG, "GOT ICMP type " + hdr.getType() + ", code " + hdr.getCode()); } } catch (SocketException ex) { // TODO fix me @@ -222,7 +222,7 @@ private void processReplyRequest(SocketBuffer skbuf) { sendEchoReply((ICMPEchoHeader) hdr, skbuf); } } catch (SocketException ex) { - log.error("Error in ICMP reply", ex); + log.log(Level.ERROR, "Error in ICMP reply", ex); } } diff --git a/net/src/main/java/org/jnode/net/ipv4/layer/IPv4NetworkLayer.java b/net/src/main/java/org/jnode/net/ipv4/layer/IPv4NetworkLayer.java index 299b806eb1..5465118cd8 100644 --- a/net/src/main/java/org/jnode/net/ipv4/layer/IPv4NetworkLayer.java +++ b/net/src/main/java/org/jnode/net/ipv4/layer/IPv4NetworkLayer.java @@ -27,8 +27,8 @@ import java.util.Collection; import java.util.HashMap; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.driver.net.NetDeviceAPI; import org.jnode.driver.net.NetworkException; @@ -67,7 +67,7 @@ public class IPv4NetworkLayer implements NetworkLayer, IPv4Constants, IPv4Servic /** * My logger */ - private static final Logger log = LogManager.getLogger(IPv4NetworkLayer.class); + private static final Logger log = System.getLogger(IPv4NetworkLayer.class.getName()); private final HashMap protocols = new HashMap<>(); @@ -189,7 +189,7 @@ public void receive(SocketBuffer skbuf, NetDeviceAPI deviceAPI) throws SocketExc shouldProcess = !skbuf.getLinkLayerHeader().getDestinationAddress().isBroadcast(); } if (!shouldProcess) { - // log.debug("IPPacket not for me, ignoring (dst=" + dstAddr + ")"); + // log.log(Level.DEBUG, "IPPacket not for me, ignoring (dst=" + dstAddr + ")"); return; } @@ -230,7 +230,7 @@ private void deliver(IPv4Header hdr, SocketBuffer skbuf) throws SocketException protocol = getProtocol(hdr.getProtocol()); protocol.receive(skbuf); } catch (NoSuchProtocolException ex) { - log.debug("Found unknown IP src=" + hdr.getSource() + ", dst=" + hdr.getDestination() + + log.log(Level.DEBUG, "Found unknown IP src=" + hdr.getSource() + ", dst=" + hdr.getDestination() + ", prot=0x" + NumberUtils.hex(hdr.getProtocol(), 2)); } } @@ -284,7 +284,7 @@ private void removeDeadFragments() { fragments.remove(key); } // We're done - log.debug("Removed " + deadFragmentKeys.size() + " dead fragments"); + log.log(Level.DEBUG, "Removed " + deadFragmentKeys.size() + " dead fragments"); } // Update our last invocation timestamp lastFragmentCleanup = System.currentTimeMillis(); @@ -401,9 +401,9 @@ private void updateARPCache(HardwareAddress hwAddr, ProtocolAddress pAddr) { try { arp = (ARPNetworkLayer) NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_ARP); } catch (NoSuchProtocolException ex) { - log.error("Cannot find ARP layer", ex); + log.log(Level.ERROR, "Cannot find ARP layer", ex); } catch (IOException ex) { - log.error("Cannot network layer manager", ex); + log.log(Level.ERROR, "Cannot network layer manager", ex); } } if (arp != null) { diff --git a/net/src/main/java/org/jnode/net/ipv4/raw/RAWProtocol.java b/net/src/main/java/org/jnode/net/ipv4/raw/RAWProtocol.java index 29ed20338f..84a23fe24a 100644 --- a/net/src/main/java/org/jnode/net/ipv4/raw/RAWProtocol.java +++ b/net/src/main/java/org/jnode/net/ipv4/raw/RAWProtocol.java @@ -24,8 +24,8 @@ import java.net.SocketException; import java.net.SocketImplFactory; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.SocketBuffer; import org.jnode.net.ipv4.IPv4Constants; import org.jnode.net.ipv4.IPv4Protocol; @@ -36,11 +36,12 @@ * @author epr */ public class RAWProtocol implements IPv4Protocol, IPv4Constants { + /** My logger */ - private static final Logger log = LogManager.getLogger(RAWProtocol.class); + private static final Logger log = System.getLogger(RAWProtocol.class.getName()); - /** The service i'm a part of */ - // private final IPv4Service ipService; +// /** The service i'm a part of */ +// private final IPv4Service ipService; /** My statistics */ private final RAWStatistics stat = new RAWStatistics(); @@ -72,9 +73,8 @@ public int getProtocolID() { * @see org.jnode.net.ipv4.IPv4Protocol#receive(org.jnode.net.SocketBuffer) */ public void receive(SocketBuffer skbuf) throws SocketException { - log.debug("Received RAW IP packet"); + log.log(Level.DEBUG, "Received RAW IP packet"); // TODO Implement RAW protocol reception - } /** @@ -114,5 +114,4 @@ public DatagramSocketImplFactory getDatagramSocketImplFactory() throws SocketExc public Statistics getStatistics() { return stat; } - } diff --git a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPControlBlock.java b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPControlBlock.java index 4c198d7510..8059d3038b 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPControlBlock.java +++ b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPControlBlock.java @@ -24,8 +24,8 @@ import java.net.SocketException; import java.util.LinkedList; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.SocketBuffer; import org.jnode.net.ipv4.IPv4Address; import org.jnode.net.ipv4.IPv4Constants; @@ -42,7 +42,7 @@ public class TCPControlBlock extends IPv4ControlBlock implements TCPConstants { /** * My logger */ - private static final Logger log = LogManager.getLogger(TCPControlBlock.class); + private static final Logger log = System.getLogger(TCPControlBlock.class.getName()); /** * The outgoing channel @@ -113,9 +113,9 @@ public TCPControlBlock(TCPControlBlockList list, TCPControlBlock parent, TCPProt this.refused = false; } - // ------------------------------------------ + // // Receive (input) methods - // ------------------------------------------ + // /** * Handle a received segment for this connection @@ -125,9 +125,7 @@ public TCPControlBlock(TCPControlBlockList list, TCPControlBlock parent, TCPProt */ public synchronized void receive(TCPHeader hdr, SocketBuffer skbuf) throws SocketException { if (DEBUG) { - if (log.isDebugEnabled()) { - log.debug("receive: me=[" + this + "], hdr=[" + hdr + ']'); - } + log.log(Level.DEBUG, "receive: me=[" + this + "], hdr=[" + hdr + ']'); } final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader(); @@ -173,7 +171,7 @@ public synchronized void receive(TCPHeader hdr, SocketBuffer skbuf) throws Socke break; default: if (DEBUG) { - log.debug("Unhandled state in receive (" + getStateName() + ')'); + log.log(Level.DEBUG, "Unhandled state in receive (" + getStateName() + ')'); } break; } @@ -237,7 +235,7 @@ private void receiveProcessReset(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer s private void receiveListen(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf) throws SocketException { if (DEBUG) { - log.debug("receiveListen"); + log.log(Level.DEBUG, "receiveListen"); } final boolean ack = hdr.isFlagAcknowledgeSet(); @@ -276,7 +274,7 @@ private void receiveListen(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf) private void listenSynReceivedOnCopy(TCPHeader hdr, SocketBuffer skbuf) throws SocketException { if (DEBUG) { - log.debug("listenSynReceivedOnCopy"); + log.log(Level.DEBUG, "listenSynReceivedOnCopy"); } // Save the foreign seq nr @@ -463,7 +461,7 @@ public void timeout() { try { outChannel.timeout(); } catch (SocketException ex) { - log.error("Error in timeout of " + this, ex); + log.log(Level.ERROR, "Error in timeout of " + this, ex); } } @@ -476,7 +474,7 @@ public void timeout() { */ private void drop(IPv4Header ipHdr, TCPHeader hdr, String reason) { if (DEBUG) { - log.debug("Dropping segment due to: " + reason); + log.log(Level.DEBUG, "Dropping segment due to: " + reason); } } @@ -485,7 +483,7 @@ private void drop(IPv4Header ipHdr, TCPHeader hdr, String reason) { */ protected final void sendACK(int extraFlags, int ackNr) throws SocketException { if (DEBUG) { - log.debug("sendACK(0x" + NumberUtils.hex(extraFlags, 4) + ", " + (ackNr & 0xFFFFFFFFL) + ')'); + log.log(Level.DEBUG, "sendACK(0x" + NumberUtils.hex(extraFlags, 4) + ", " + (ackNr & 0xFFFFFFFFL) + ')'); } // Create the FIN TCP reply @@ -504,7 +502,7 @@ protected final void sendACK(int extraFlags, int ackNr) throws SocketException { */ private void sendFIN() throws SocketException { if (DEBUG) { - log.debug("sendFIN"); + log.log(Level.DEBUG, "sendFIN"); } // Create the FIN TCP reply @@ -523,7 +521,7 @@ private void sendFIN() throws SocketException { */ private void sendRST() throws SocketException { if (DEBUG) { - log.debug("sendRST"); + log.log(Level.DEBUG, "sendRST"); } // Create the RST TCP reply @@ -542,7 +540,7 @@ private void sendRST() throws SocketException { */ private void sendSYN() throws SocketException { if (DEBUG) { - log.debug("sendSYN"); + log.log(Level.DEBUG, "sendSYN"); } // Create the SYN TCP @@ -692,7 +690,7 @@ public synchronized void appConnect(IPv4Address fAddr, int fPort) throws SocketE throw new ConnectException("Connection refused"); } if (DEBUG) { - log.debug("Connected to " + fAddr + ':' + fPort); + log.log(Level.DEBUG, "Connected to " + fAddr + ':' + fPort); } return; } catch (TimeoutException ex) { @@ -729,9 +727,7 @@ public synchronized TCPControlBlock appAccept() { */ public/* synchronized */void appClose() throws SocketException { if (DEBUG) { - if (log.isDebugEnabled()) { - log.debug("active close state=" + getStateName()); - } + log.log(Level.DEBUG, "active close state=" + getStateName()); } try { @@ -781,7 +777,7 @@ public synchronized TCPControlBlock appAccept() { */ public void appSendData(byte[] data, int offset, int length) throws SocketException { if (DEBUG) { - log.debug("appSendData(data, " + offset + ", " + length + ')'); + log.log(Level.DEBUG, "appSendData(data, " + offset + ", " + length + ')'); } if (!isState(TCPS_ESTABLISHED) && !isState(TCPS_CLOSE_WAIT)) { throw new SocketException("Illegal state to send data: " + getStateName()); diff --git a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPHeader.java b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPHeader.java index 401c891f64..8d720859ef 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPHeader.java +++ b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPHeader.java @@ -20,8 +20,8 @@ package org.jnode.net.ipv4.tcp; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.SocketBuffer; import org.jnode.net.TransportLayerHeader; import org.jnode.net.ipv4.IPv4Header; @@ -33,7 +33,7 @@ */ public class TCPHeader implements TransportLayerHeader, TCPConstants { - private static final Logger log = LogManager.getLogger(TCPHeader.class); + private static final Logger log = System.getLogger(TCPHeader.class.getName()); private final int srcPort; private final int dstPort; private int sequenceNr; @@ -85,7 +85,7 @@ public TCPHeader(SocketBuffer skbuf) { this.headerLength = (optionHdrLength & 0xf000) >> 10; this.flags = optionHdrLength & 0x0FFF; - // Syslog.debug("optionHdrLength 0x" + NumberUtils.hex(optionHdrLength, + // Syslog.log(Level.DEBUG, "optionHdrLength 0x" + NumberUtils.hex(optionHdrLength, // 4)); this.windowSize = skbuf.get16(14); @@ -97,7 +97,7 @@ public TCPHeader(SocketBuffer skbuf) { this.tcpLength = ipHdr.getDataLength() - headerLength; if (checksum == 0) { - log.debug("No checksum set"); + log.log(Level.DEBUG, "No checksum set"); this.checksumOk = true; } else { // Create the pseudo header for checksum calculation @@ -113,7 +113,7 @@ public TCPHeader(SocketBuffer skbuf) { final int ccs2 = IPv4Utils.calcChecksum(phdr, 0, headerLength + tcpLength + 12); this.checksumOk = (ccs2 == 0); if (!checksumOk) { - log.debug("Found invalid TCP checksum 0x" + NumberUtils.hex(ccs2, 4) + + log.log(Level.DEBUG, "Found invalid TCP checksum 0x" + NumberUtils.hex(ccs2, 4) + ", tcpLength 0x" + NumberUtils.hex(tcpLength, 4) + ", ipDataLength 0x" + NumberUtils.hex(ipHdr.getDataLength(), 4) + ", tcpHdrLen 0x" + NumberUtils.hex(headerLength, 4)); @@ -253,7 +253,7 @@ public String getFlagsAsString() { if (isFlagUrgentSet()) { b.append('P'); } - if (b.length() == 0) { + if (b.isEmpty()) { return "."; } else { return b.toString(); diff --git a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPInChannel.java b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPInChannel.java index 3f210aeaf2..9eed032305 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPInChannel.java +++ b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPInChannel.java @@ -23,8 +23,8 @@ import java.net.SocketException; import java.util.LinkedList; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.SocketBuffer; import org.jnode.net.ipv4.IPv4Header; @@ -36,7 +36,7 @@ public class TCPInChannel { /** * My logger */ - private static final Logger log = LogManager.getLogger(TCPInChannel.class); + private static final Logger log = System.getLogger(TCPInChannel.class.getName()); /** * Segments that have been received, but are out of order @@ -93,7 +93,7 @@ public void processData(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf) thr // Check the seq-nr if (TCPUtils.SEQ_LT(seqNr, rcv_next)) { // Ignore segment, we've already got it - log.debug("Ignoring segment because we already got it"); + log.log(Level.DEBUG, "Ignoring segment because we already got it"); return; } @@ -140,7 +140,7 @@ private synchronized boolean processNextSegment(TCPHeader hdr, SocketBuffer skbu final int dataLength = hdr.getDataLength(); if (dataLength > dataBuffer.getFreeSize()) { // Not enough free space, ignore this segment, it will be retransmitted. - log.debug("nextSegment dropped due to lack of space"); + log.log(Level.DEBUG, "nextSegment dropped due to lack of space"); return false; } else { // Enough space, save diff --git a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPOutChannel.java b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPOutChannel.java index 96621b2d8c..5b21899a10 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPOutChannel.java +++ b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPOutChannel.java @@ -24,8 +24,8 @@ import java.util.Iterator; import java.util.LinkedList; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.ipv4.IPv4Header; /** @@ -37,7 +37,7 @@ public class TCPOutChannel { /** * My logger */ - private static final Logger log = LogManager.getLogger(TCPOutChannel.class); + private static final Logger log = System.getLogger(TCPOutChannel.class.getName()); /** * The protocol @@ -111,12 +111,12 @@ public synchronized void processAck(int ackNr) { return; } else if (!TCPUtils.SEQ_LT(snd_unack, ackNr)) { // snd_unack < ackNr violated - log.debug("snd_unack < ackNr violated"); + log.log(Level.DEBUG, "snd_unack < ackNr violated"); return; } if (!TCPUtils.SEQ_LE(ackNr, snd_max)) { // ackNr <= snd_max violated - log.debug("ackNr <= snd_max violated"); + log.log(Level.DEBUG, "ackNr <= snd_max violated"); return; } @@ -183,7 +183,7 @@ public void send(IPv4Header ipHdr, TCPHeader hdr) throws SocketException { public synchronized void send(IPv4Header ipHdr, TCPHeader hdr, byte[] data, int offset, int length) throws SocketException { if (DEBUG) { - log.debug("outChannel.send(ipHdr,hdr,data," + offset + ", " + length + ')'); + log.log(Level.DEBUG, "outChannel.send(ipHdr,hdr,data," + offset + ", " + length + ')'); } // Check for maximum datalength if (length > mss) { @@ -232,7 +232,7 @@ private void sendHelper(IPv4Header ipHdr, TCPHeader hdr, int dataOffset) seg.send(tcp); if (!seg.isAckOnly() && !hdr.isFlagSynchronizeSet()) { if (DEBUG) { - log.debug("Adding segment " + seg.getSeqNr() + " to unacklist"); + log.log(Level.DEBUG, "Adding segment " + seg.getSeqNr() + " to unacklist"); } unackedSegments.add(seg); } diff --git a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPOutSegment.java b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPOutSegment.java index c7041ed14f..3f8903510a 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPOutSegment.java +++ b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPOutSegment.java @@ -22,8 +22,8 @@ import java.net.SocketException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.SocketBuffer; import org.jnode.net.ipv4.IPv4Header; @@ -36,7 +36,7 @@ public class TCPOutSegment extends TCPSegment { /** * My logger */ - private static final Logger log = LogManager.getLogger(TCPOutSegment.class); + private static final Logger log = System.getLogger(TCPOutSegment.class.getName()); private final TCPDataBuffer buffer; private int dataOffset; @@ -56,8 +56,7 @@ public class TCPOutSegment extends TCPSegment { * @param hdr * @param dataOffset */ - public TCPOutSegment(IPv4Header ipHdr, TCPHeader hdr, TCPDataBuffer buffer, int dataOffset, - int timeout) { + public TCPOutSegment(IPv4Header ipHdr, TCPHeader hdr, TCPDataBuffer buffer, int dataOffset, int timeout) { super(ipHdr, hdr); this.buffer = buffer; this.dataOffset = dataOffset; @@ -72,7 +71,7 @@ public void timeout(TCPProtocol tcp) throws SocketException { timeout--; if (timeout == 0) { if (DEBUG) { - log.debug("Resend segment " + getSeqNr()); + log.log(Level.DEBUG, "Resend segment " + getSeqNr()); } send(tcp); timeoutTicks = timeoutTicks * 2; diff --git a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPProtocol.java b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPProtocol.java index 7049e7e866..4d5af66a27 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPProtocol.java +++ b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPProtocol.java @@ -21,18 +21,15 @@ package org.jnode.net.ipv4.tcp; import java.io.IOException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.net.BindException; import java.net.DatagramSocketImplFactory; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; import java.net.SocketImplFactory; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jnode.driver.net.NetworkException; import org.jnode.net.SocketBuffer; import org.jnode.net.ipv4.IPv4Address; @@ -79,7 +76,7 @@ public class TCPProtocol implements IPv4Protocol, IPv4Constants, TCPConstants { /** * My logger */ - private static final Logger log = LogManager.getLogger(TCPProtocol.class); + private static final Logger log = System.getLogger(TCPProtocol.class.getName()); /** * Initialize a new instance @@ -94,15 +91,11 @@ public TCPProtocol(IPv4Service ipService) throws NetworkException { try { socketImplFactory = new TCPSocketImplFactory(this); try { - AccessController.doPrivileged((PrivilegedExceptionAction) () -> { - Socket.setSocketImplFactory(socketImplFactory); - ServerSocket.setSocketFactory(socketImplFactory); - return null; - }); + Socket.setSocketImplFactory(socketImplFactory); + ServerSocket.setSocketFactory(socketImplFactory); + return; } catch (SecurityException ex) { - log.error("No permission for set socket factory.", ex); - } catch (PrivilegedActionException ex) { - throw new NetworkException(ex.getException()); + log.log(Level.ERROR, "No permission for set socket factory.", ex); } } catch (IOException ex) { throw new NetworkException(ex); @@ -168,16 +161,12 @@ public void receive(SocketBuffer skbuf) throws SocketException { if (!hdr.isChecksumOk()) { if (DEBUG) { - if (log.isDebugEnabled()) { - log.debug("Receive: badsum: " + hdr); - } + log.log(Level.DEBUG, "Receive: badsum: " + hdr); } stat.badsum.inc(); } else { if (DEBUG) { - if (log.isDebugEnabled()) { - log.debug("Receive: " + hdr); - } + log.log(Level.DEBUG, "Receive: " + hdr); } // Find the corresponding control block @@ -193,7 +182,7 @@ public void receive(SocketBuffer skbuf) throws SocketException { // Port unreachable if (ack && rst) { // the source is also unreachable - log.debug("Dropping segment due to: connection refused as the source is also unreachable"); + log.log(Level.DEBUG, "Dropping segment due to: connection refused as the source is also unreachable"); } else { processPortUnreachable(ipHdr, hdr); } @@ -245,9 +234,7 @@ public TCPControlBlock bind(IPv4Address lAddr, int lPort) throws BindException { protected void send(IPv4Header ipHdr, TCPHeader tcpHdr, SocketBuffer skbuf) throws SocketException { if (DEBUG) { - if (log.isDebugEnabled()) { - log.debug("send(ipHdr, " + tcpHdr + ')'); - } + log.log(Level.DEBUG, "send(ipHdr, " + tcpHdr + ')'); } skbuf.setTransportLayerHeader(tcpHdr); tcpHdr.prefixTo(skbuf); diff --git a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPSocketImpl.java b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPSocketImpl.java index 49bc2bbf65..d20f38e821 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPSocketImpl.java +++ b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPSocketImpl.java @@ -31,8 +31,8 @@ import java.net.SocketOptions; import java.nio.channels.UnresolvedAddressException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.ipv4.IPv4Address; /** @@ -64,7 +64,7 @@ public class TCPSocketImpl extends SocketImpl { /** * My logger */ - private static final Logger log = LogManager.getLogger(TCPSocketImpl.class); + private static final Logger log = System.getLogger(TCPSocketImpl.class.getName()); /** * Initialize a new instance @@ -83,24 +83,24 @@ public TCPSocketImpl(TCPProtocol protocol) { */ protected void accept(SocketImpl s) throws IOException { if (DEBUG) { - log.debug("accept " + s); + log.log(Level.DEBUG, "accept " + s); } if (controlBlock == null) { throw new IOException("Not listening"); } final TCPSocketImpl impl = (TCPSocketImpl) s; if (DEBUG) { - log.debug("accept: blocking"); + log.log(Level.DEBUG, "accept: blocking"); } impl.controlBlock = controlBlock.appAccept(); if (DEBUG) { - log.debug("accept: got one"); + log.log(Level.DEBUG, "accept: got one"); } } protected int getLocalPort() { if (DEBUG) { - log.debug("getLocalPort: controlBlock.getLocalPort()"); + log.log(Level.DEBUG, "getLocalPort: controlBlock.getLocalPort()"); } return controlBlock.getLocalPort(); } diff --git a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPTimer.java b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPTimer.java index 598afb08d9..bb379ad5ae 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tcp/TCPTimer.java +++ b/net/src/main/java/org/jnode/net/ipv4/tcp/TCPTimer.java @@ -20,15 +20,15 @@ package org.jnode.net.ipv4.tcp; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; /** * @author Ewout Prangsma (epr@users.sourceforge.net) */ public class TCPTimer extends Thread { - private static final Logger log = LogManager.getLogger(TCPTimer.class); + private static final Logger log = System.getLogger(TCPTimer.class.getName()); private final TCPControlBlockList cbList; private boolean stop = false; private long counter; @@ -55,7 +55,7 @@ public void run() { cbList.timeout(); counter += TCPConstants.TCP_TIMER_PERIOD; } catch (Throwable ex) { - log.error("Error in TCP timer", ex); + log.log(Level.ERROR, "Error in TCP timer", ex); } try { Thread.sleep(TCPConstants.TCP_TIMER_PERIOD); diff --git a/net/src/main/java/org/jnode/net/ipv4/tftp/TFTPServer.java b/net/src/main/java/org/jnode/net/ipv4/tftp/TFTPServer.java index beddff68da..93dc42c9a3 100644 --- a/net/src/main/java/org/jnode/net/ipv4/tftp/TFTPServer.java +++ b/net/src/main/java/org/jnode/net/ipv4/tftp/TFTPServer.java @@ -36,8 +36,8 @@ import org.apache.commons.net.tftp.TFTPPacketException; import org.apache.commons.net.tftp.TFTPReadRequestPacket; import org.apache.commons.net.tftp.TFTPWriteRequestPacket; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; /** * TFTP server. Currently only supports one client at a time. @@ -46,7 +46,7 @@ */ public class TFTPServer extends TFTP { - private static final Logger log = LogManager.getLogger(TFTPServer.class); + private static final Logger log = System.getLogger(TFTPServer.class.getName()); /** current client address */ private InetAddress clientAddress; @@ -63,11 +63,10 @@ public class TFTPServer extends TFTP { private int blockNumber; public static void main(String[] args) { - TFTPServer server = new TFTPServer(); - try { + try (TFTPServer server = new TFTPServer()) { server.run(); } catch (SocketException ex) { - LogManager.getLogger(TFTPServer.class).fatal("Socket exception", ex); + log.log(Level.ERROR, "Socket exception", ex); } } @@ -83,9 +82,9 @@ private void run() throws SocketException { TFTPPacket packet = bufferedReceive(); processRequest(packet); } catch (TFTPPacketException ex) { - log.debug("Error in TFTP packet", ex); + log.log(Level.DEBUG, "Error in TFTP packet", ex); } catch (IOException ex) { - log.debug("I/O exception", ex); + log.log(Level.DEBUG, "I/O exception", ex); } } } finally { @@ -95,15 +94,14 @@ private void run() throws SocketException { } private void processRequest(TFTPPacket packet) throws IOException { - if (log.isDebugEnabled()) - log.debug("Received packet: " + packet.getAddress() + ':' + packet.getPort()); + log.log(Level.DEBUG, "Received packet: " + packet.getAddress() + ':' + packet.getPort()); final int type = packet.getType(); switch (type) { case TFTPPacket.WRITE_REQUEST: if (clientAddress == null) { TFTPWriteRequestPacket wreqPacket = (TFTPWriteRequestPacket) packet; File file = new File(".", wreqPacket.getFilename()); - log.info("Request to write file " + wreqPacket.getFilename() + " (" + + log.log(Level.INFO, "Request to write file " + wreqPacket.getFilename() + " (" + file.getAbsolutePath() + ") received from " + packet.getAddress() + ':' + packet.getPort()); fileOut = new FileOutputStream(file); @@ -138,7 +136,7 @@ private void processRequest(TFTPPacket packet) throws IOException { TFTPReadRequestPacket rreqPacket = (TFTPReadRequestPacket) packet; try { File file = new File(".", rreqPacket.getFilename()); - log.info("Request to read file " + rreqPacket.getFilename() + " (" + + log.log(Level.INFO, "Request to read file " + rreqPacket.getFilename() + " (" + file.getAbsolutePath() + ") received from " + packet.getAddress() + ':' + packet.getPort()); fileIn = new FileInputStream(file); diff --git a/net/src/main/java/org/jnode/net/ipv4/udp/UDPHeader.java b/net/src/main/java/org/jnode/net/ipv4/udp/UDPHeader.java index f66bf26e3e..a3c1e883a8 100644 --- a/net/src/main/java/org/jnode/net/ipv4/udp/UDPHeader.java +++ b/net/src/main/java/org/jnode/net/ipv4/udp/UDPHeader.java @@ -20,8 +20,8 @@ package org.jnode.net.ipv4.udp; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.SocketBuffer; import org.jnode.net.TransportLayerHeader; import org.jnode.net.ipv4.IPv4Header; @@ -36,7 +36,7 @@ public class UDPHeader implements TransportLayerHeader, UDPConstants { /** My logger */ - private static final Logger log = LogManager.getLogger(UDPHeader.class); + private static final Logger log = System.getLogger(UDPHeader.class.getName()); /** The port of the sending process or 0 if not used. */ private final int srcPort; /** The destination port within the context of a particular internet address */ @@ -71,7 +71,7 @@ public UDPHeader(SocketBuffer skbuf) { this.udpLength = skbuf.get16(4); final int checksum = skbuf.get16(6); if (checksum == 0) { - log.debug("No checksum set"); + log.log(Level.DEBUG, "No checksum set"); this.checksumOk = true; } else { // Create the pseudo header for checksum calculation @@ -87,7 +87,7 @@ public UDPHeader(SocketBuffer skbuf) { final int ccs2 = IPv4Utils.calcChecksum(phdr, 0, udpLength + 12); this.checksumOk = (ccs2 == 0); if (!checksumOk) { - log.debug("Found invalid UDP checksum 0x" + NumberUtils.hex(ccs2, 4)); + log.log(Level.DEBUG, "Found invalid UDP checksum 0x" + NumberUtils.hex(ccs2, 4)); } } } diff --git a/net/src/main/java/org/jnode/net/ipv4/udp/UDPProtocol.java b/net/src/main/java/org/jnode/net/ipv4/udp/UDPProtocol.java index fd84835899..f8122c4761 100644 --- a/net/src/main/java/org/jnode/net/ipv4/udp/UDPProtocol.java +++ b/net/src/main/java/org/jnode/net/ipv4/udp/UDPProtocol.java @@ -32,8 +32,8 @@ import java.util.HashMap; import java.util.Random; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.net.NetworkException; import org.jnode.net.SocketBuffer; import org.jnode.net.ipv4.IPv4Constants; @@ -52,7 +52,7 @@ public class UDPProtocol implements IPv4Protocol, IPv4Constants { /** * My logger */ - private static final Logger log = LogManager.getLogger(UDPProtocol.class); + private static final Logger log = System.getLogger(UDPProtocol.class.getName()); /** * The underlying IP service @@ -105,7 +105,7 @@ public UDPProtocol(IPv4Service ipService) throws NetworkException { return null; }); } catch (SecurityException ex) { - log.error("No permission to set DatagramSocketImplFactory", ex); + log.log(Level.ERROR, "No permission to set DatagramSocketImplFactory", ex); } catch (PrivilegedActionException ex) { throw new NetworkException(ex.getException()); } @@ -154,7 +154,7 @@ public void receive(SocketBuffer skbuf) throws SocketException { return; } - // Syslog.debug("Found UDP: " + hdr); + // Syslog.log(Level.DEBUG, "Found UDP: " + hdr); deliver(hdr, skbuf); } diff --git a/net/src/main/java/org/jnode/net/nfs/nfs2/NFS2Client.java b/net/src/main/java/org/jnode/net/nfs/nfs2/NFS2Client.java index 4805a1978c..cc551ef07b 100644 --- a/net/src/main/java/org/jnode/net/nfs/nfs2/NFS2Client.java +++ b/net/src/main/java/org/jnode/net/nfs/nfs2/NFS2Client.java @@ -37,8 +37,8 @@ import org.acplt.oncrpc.XdrDecodingStream; import org.acplt.oncrpc.XdrEncodingStream; import org.acplt.oncrpc.XdrVoid; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.nfs.Protocol; /** @@ -106,7 +106,7 @@ public class NFS2Client { private static final int PROCEDURE_GET_FILE_SYSTEM_ATTRIBUTE = 17; - private static final Logger LOGGER = LogManager.getLogger(NFS2Client.class); + private static final Logger LOGGER = System.getLogger(NFS2Client.class.getName()); private List rpcClientPool; @@ -169,7 +169,7 @@ private synchronized OncRpcClient getRpcClient() throws OncRpcException, IOExcep if (closed) { throw new IOException("The nfs client it is closed"); } - if (rpcClientPool.size() == 0) { + if (rpcClientPool.isEmpty()) { // TODO Improve this lock return createRpcClient(); } else { @@ -220,7 +220,7 @@ private void call(final int functionId, final XdrAble parameter, final XdrAble r if (countCall > 5) { throw new NFS2Exception(e.getMessage(), e); } else { - LOGGER.warn("An error occurs when nfs file system try to call the rpc method. Reason: " + + LOGGER.log(Level.WARNING, "An error occurs when nfs file system try to call the rpc method. Reason: " + e.getMessage() + " . It will try again"); } } else { @@ -249,7 +249,7 @@ public synchronized void close() throws IOException { exceptionList.add(e); } } - if (exceptionList.size() != 0) { + if (!exceptionList.isEmpty()) { StringBuilder builder = new StringBuilder(); builder.append("An error occurs when the mount client close connections. Reason:"); for (OncRpcException anExceptionList : exceptionList) { diff --git a/net/src/main/java/org/jnode/net/nfs/nfs2/mount/Mount1Client.java b/net/src/main/java/org/jnode/net/nfs/nfs2/mount/Mount1Client.java index cf7aed1326..e9c9ff30df 100644 --- a/net/src/main/java/org/jnode/net/nfs/nfs2/mount/Mount1Client.java +++ b/net/src/main/java/org/jnode/net/nfs/nfs2/mount/Mount1Client.java @@ -34,8 +34,8 @@ import org.acplt.oncrpc.XdrDecodingStream; import org.acplt.oncrpc.XdrEncodingStream; import org.acplt.oncrpc.XdrVoid; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.net.nfs.Protocol; /** @@ -44,7 +44,7 @@ */ public class Mount1Client { - private static final Logger LOGGER = LogManager.getLogger(Mount1Client.class); + private static final Logger log = System.getLogger(Mount1Client.class.getName()); private static final int MOUNT_CODE = 100005; private static final int MOUNT_VERSION = 1; @@ -104,7 +104,7 @@ private synchronized OncRpcClient getRpcClient() throws OncRpcException, IOExcep throw new IOException("The mount client it is closed"); } - if (rpcClientPool.size() == 0) { + if (rpcClientPool.isEmpty()) { return createRpcClient(); } else { return rpcClientPool.remove(0); @@ -151,8 +151,7 @@ private void call(final int functionId, final XdrAble parameter, final XdrAble r if (countCall > 5) { throw new MountException(e.getMessage(), e); } else { - LOGGER - .warn("An error occurs when nfs file system try to call the rpc method. Reason : " + + log.log(Level.WARNING, "An error occurs when nfs file system try to call the rpc method. Reason : " + e.getMessage() + ". It will try again"); } @@ -334,7 +333,7 @@ public synchronized void close() throws IOException { } } - if (exceptionList.size() != 0) { + if (!exceptionList.isEmpty()) { StringBuilder builder = new StringBuilder(); builder.append("An error occurs when the mount client close connections. Reason:"); for (OncRpcException anExceptionList : exceptionList) { diff --git a/net/src/main/java/org/jnode/net/util/AbstractDatagramSocketImpl.java b/net/src/main/java/org/jnode/net/util/AbstractDatagramSocketImpl.java index 823b6c2639..e60c586910 100644 --- a/net/src/main/java/org/jnode/net/util/AbstractDatagramSocketImpl.java +++ b/net/src/main/java/org/jnode/net/util/AbstractDatagramSocketImpl.java @@ -29,8 +29,8 @@ import java.net.SocketException; import java.net.SocketTimeoutException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.lang.System.Logger.Level; +import java.lang.System.Logger; import org.jnode.driver.Device; import org.jnode.net.SocketBuffer; import org.jnode.net.ethernet.EthernetConstants; @@ -41,7 +41,7 @@ */ public abstract class AbstractDatagramSocketImpl extends DatagramSocketImpl { - private static final Logger bootlog = LogManager.getLogger("bootlog"); + private static final Logger bootlog = System.getLogger("bootlog"); /** The receive queue of SocketBuffer instances */ private final Queue receiveQueue = new Queue<>(); @@ -170,7 +170,7 @@ public final synchronized void setOption(int option_id, Object val) throws Socke } protected void doSetOption(int option_id, Object val) throws SocketException { - bootlog.error("Unknown option " + option_id); + bootlog.log(Level.ERROR, "Unknown option " + option_id); } /** diff --git a/net/src/test/java/org/jnode/test/net/TCPTest.java b/net/src/test/java/org/jnode/test/net/TCPTest.java index ea1b6dba41..39f0f47370 100644 --- a/net/src/test/java/org/jnode/test/net/TCPTest.java +++ b/net/src/test/java/org/jnode/test/net/TCPTest.java @@ -47,7 +47,7 @@ public static void main(String[] args) throws Exception { String line; while ((line = in.readLine()) != null) { System.out.println(line); - if (line.length() == 0) { + if (line.isEmpty()) { break; } } diff --git a/pom.xml b/pom.xml index b211fb2fdf..f262f2d2a2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ vavi vavi-nio-file-jnode - 0.2.11v + 0.2.12 pom JNode Parent Module @@ -22,31 +22,32 @@ + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 17 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 + + + + + - - org.apache.logging.log4j - log4j-api - 2.19.0 - - - - org.apache.logging.log4j - log4j-core - 2.19.0 - test - - - org.apache.logging.log4j - log4j-jul - 2.19.0 - test - - org.junit junit-bom - 5.9.1 + 5.10.2 pom import