This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 9a70427dea06b0cf09cf8665ebb816f803e4757c Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Apr 13 11:10:41 2023 -0400 Add FileSystem.getBlockSize() --- src/changes/changes.xml | 3 ++ .../java/org/apache/commons/io/FileSystem.java | 37 +++++++++++++++------- .../java/org/apache/commons/io/FileSystemTest.java | 8 +++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 687777f1..7cbdb7dc 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -465,6 +465,9 @@ The <action> type attribute can be add,update,fix,remove. <action issue="IO-786" dev="ggregory" type="add" due-to="Gary Gregory, Benoit Tellier"> Add UnsynchronizedBufferedInputStream. </action> + <action dev="ggregory" type="add" due-to="Gary Gregory"> + Add FileSystem.getBlockSize(). + </action> <!-- UPDATE --> <action dev="kinow" type="update" due-to="Dependabot, Gary Gregory"> Bump actions/cache from 2.1.6 to 3.0.10 #307, #337, #393. diff --git a/src/main/java/org/apache/commons/io/FileSystem.java b/src/main/java/org/apache/commons/io/FileSystem.java index 42f51672..d71bd373 100644 --- a/src/main/java/org/apache/commons/io/FileSystem.java +++ b/src/main/java/org/apache/commons/io/FileSystem.java @@ -36,12 +36,12 @@ public enum FileSystem { /** * Generic file system. */ - GENERIC(false, false, Integer.MAX_VALUE, Integer.MAX_VALUE, new int[] { 0 }, new String[] {}, false, false, '/'), + GENERIC(4096, false, false, Integer.MAX_VALUE, Integer.MAX_VALUE, new int[] { 0 }, new String[] {}, false, false, '/'), /** * Linux file system. */ - LINUX(true, true, 255, 4096, new int[] { + LINUX(8192, true, true, 255, 4096, new int[] { // KEEP THIS ARRAY SORTED! // @formatter:off // ASCII NUL @@ -53,7 +53,7 @@ public enum FileSystem { /** * MacOS file system. */ - MAC_OSX(true, true, 255, 1024, new int[] { + MAC_OSX(4096, true, true, 255, 1024, new int[] { // KEEP THIS ARRAY SORTED! // @formatter:off // ASCII NUL @@ -76,8 +76,9 @@ public enum FileSystem { * @see <a href="https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#consoles"> * CreateFileA function - Consoles (microsoft.com)</a> */ - WINDOWS(false, true, 255, - 32000, new int[] { + WINDOWS(4096, false, true, + 255, 32000, // KEEP THIS ARRAY SORTED! + new int[] { // KEEP THIS ARRAY SORTED! // @formatter:off // ASCII NUL @@ -87,9 +88,8 @@ public enum FileSystem { 29, 30, 31, '"', '*', '/', ':', '<', '>', '?', '\\', '|' // @formatter:on - }, // KEEP THIS ARRAY SORTED! - new String[] { "AUX", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "CON", "CONIN$", "CONOUT$", - "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "NUL", "PRN" }, true, true, '\\'); + }, new String[] { "AUX", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "CON", "CONIN$", "CONOUT$", + "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "NUL", "PRN" }, true, true, '\\'); /** * <p> @@ -296,6 +296,8 @@ public enum FileSystem { private static String replace(final String path, final char oldChar, final char newChar) { return path == null ? null : path.replace(oldChar, newChar); } + + private final int blockSize; private final boolean casePreserving; private final boolean caseSensitive; private final int[] illegalFileNameChars; @@ -305,12 +307,12 @@ public enum FileSystem { private final boolean reservedFileNamesExtensions; private final boolean supportsDriveLetter; private final char nameSeparator; - private final char nameSeparatorOther; /** * Constructs a new instance. * + * @param blockSize file allocation block size in bytes. * @param caseSensitive Whether this file system is case-sensitive. * @param casePreserving Whether this file system is case-preserving. * @param maxFileLength The maximum length for file names. The file name does not include folders. @@ -321,9 +323,10 @@ public enum FileSystem { * @param supportsDriveLetter Whether this file system support driver letters. * @param nameSeparator The name separator, '\\' on Windows, '/' on Linux. */ - FileSystem(final boolean caseSensitive, final boolean casePreserving, final int maxFileLength, - final int maxPathLength, final int[] illegalFileNameChars, final String[] reservedFileNames, - final boolean reservedFileNamesExtensions, final boolean supportsDriveLetter, final char nameSeparator) { + FileSystem(final int blockSize, final boolean caseSensitive, final boolean casePreserving, + final int maxFileLength, final int maxPathLength, final int[] illegalFileNameChars, + final String[] reservedFileNames, final boolean reservedFileNamesExtensions, final boolean supportsDriveLetter, final char nameSeparator) { + this.blockSize = blockSize; this.maxFileNameLength = maxFileLength; this.maxPathLength = maxPathLength; this.illegalFileNameChars = Objects.requireNonNull(illegalFileNameChars, "illegalFileNameChars"); @@ -336,6 +339,16 @@ public enum FileSystem { this.nameSeparatorOther = FilenameUtils.flipSeparator(nameSeparator); } + /** + * Gets the file allocation block size in bytes. + * @return the file allocation block size in bytes. + * + * @since 2.12.0 + */ + public int getBlockSize() { + return blockSize; + } + /** * Gets a cloned copy of the illegal characters for this file system. * diff --git a/src/test/java/org/apache/commons/io/FileSystemTest.java b/src/test/java/org/apache/commons/io/FileSystemTest.java index a1e24331..8e7a8c5d 100644 --- a/src/test/java/org/apache/commons/io/FileSystemTest.java +++ b/src/test/java/org/apache/commons/io/FileSystemTest.java @@ -21,8 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.IOException; - import org.apache.commons.lang3.SystemUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnOs; @@ -33,6 +31,10 @@ import org.junit.jupiter.api.condition.OS; */ public class FileSystemTest { + @Test + public void testGetBlockSize() { + assertTrue(FileSystem.getCurrent().getBlockSize() >= 0); + } @Test public void testGetCurrent() { @@ -72,7 +74,7 @@ public class FileSystemTest { @Test @EnabledOnOs(OS.WINDOWS) - public void testIsReservedFileNameOnWindows() throws IOException { + public void testIsReservedFileNameOnWindows() { final FileSystem fs = FileSystem.WINDOWS; for (final String candidate : fs.getReservedFileNames()) { // System.out.printf("Reserved %s exists: %s%n", candidate, Files.exists(Paths.get(candidate)));