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 2eda2a41464ef8c4155c80ab68d6e4f51792ba67 Author: Gary Gregory <[email protected]> AuthorDate: Fri Sep 3 17:49:22 2021 -0400 Add FileSystem.getNameSeparator(). --- src/changes/changes.xml | 3 +++ .../java/org/apache/commons/io/FileSystem.java | 23 +++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index eab7c72..c260a9c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -138,6 +138,9 @@ The <action> type attribute can be add,update,fix,remove. <action dev="ggregory" type="add" due-to="Gary Gregory"> Add PathUtils.getTempDirectory(). </action> + <action dev="ggregory" type="add" due-to="Gary Gregory"> + Add FileSystem.getNameSeparator(). + </action> <!-- UPDATE --> <action dev="ggregory" type="update" due-to="Dependabot"> Bump Maven Javadoc plugin from 3.2.0 to 3.3.0. diff --git a/src/main/java/org/apache/commons/io/FileSystem.java b/src/main/java/org/apache/commons/io/FileSystem.java index a983db1..e53e9bc 100644 --- a/src/main/java/org/apache/commons/io/FileSystem.java +++ b/src/main/java/org/apache/commons/io/FileSystem.java @@ -36,7 +36,7 @@ public enum FileSystem { /** * Generic file system. */ - GENERIC(false, false, Integer.MAX_VALUE, Integer.MAX_VALUE, new char[] { 0 }, new String[] {}, false), + GENERIC(false, false, Integer.MAX_VALUE, Integer.MAX_VALUE, new char[] { 0 }, new String[] {}, false, '/'), /** * Linux file system. @@ -48,7 +48,7 @@ public enum FileSystem { 0, '/' // @formatter:on - }, new String[] {}, false), + }, new String[] {}, false, '/'), /** * MacOS file system. @@ -61,7 +61,7 @@ public enum FileSystem { '/', ':' // @formatter:on - }, new String[] {}, false), + }, new String[] {}, false, '/'), /** * Windows file system. @@ -87,7 +87,7 @@ public enum FileSystem { // @formatter:on }, // KEEP THIS ARRAY SORTED! new String[] { "AUX", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "CON", "LPT1", - "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "NUL", "PRN" }, true); + "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "NUL", "PRN" }, true, '\\'); /** * <p> @@ -217,6 +217,7 @@ public enum FileSystem { private final int maxPathLength; private final String[] reservedFileNames; private final boolean supportsDriveLetter; + private final char nameSeparator; /** * Constructs a new instance. @@ -228,10 +229,11 @@ public enum FileSystem { * @param illegalFileNameChars Illegal characters for this file system. * @param reservedFileNames The reserved file names. * @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 char[] illegalFileNameChars, final String[] reservedFileNames, - final boolean supportsDriveLetter) { + final boolean supportsDriveLetter, char nameSeparator) { this.maxFileNameLength = maxFileLength; this.maxPathLength = maxPathLength; this.illegalFileNameChars = Objects.requireNonNull(illegalFileNameChars, "illegalFileNameChars"); @@ -239,6 +241,7 @@ public enum FileSystem { this.caseSensitive = caseSensitive; this.casePreserving = casePreserving; this.supportsDriveLetter = supportsDriveLetter; + this.nameSeparator = nameSeparator; } /** @@ -269,6 +272,16 @@ public enum FileSystem { } /** + * Gets the name separator, '\\' on Windows, '/' on Linux. + * @return '\\' on Windows, '/' on Linux. + * + * @since 2.12.0 + */ + public char getNameSeparator() { + return nameSeparator; + } + + /** * Gets a cloned copy of the reserved file names. * * @return the reserved file names.
