diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderMark.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderMark.java index ee3ded442..0364a8464 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderMark.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderMark.java @@ -16,16 +16,18 @@ */ package com.fr.third.org.apache.commons.io; +import com.fr.third.org.apache.commons.io.input.BOMInputStream; + import java.io.Serializable; /** - * Byte Order Mark (BOM) representation - see {@link org.apache.commons.io.input.BOMInputStream}. + * Byte Order Mark (BOM) representation - see {@link BOMInputStream}. * - * @see com.fr.third.org.apache.commons.io.input.BOMInputStream + * @see BOMInputStream * @see Wikipedia: Byte Order Mark * @see W3C: Autodetection of Character Encodings * (Non-Normative) - * @version $Id$ + * @version $Id: ByteOrderMark.java 1586504 2014-04-10 23:34:37Z ggregory $ * @since 2.0 */ public class ByteOrderMark implements Serializable { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderParser.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderParser.java deleted file mode 100644 index a1ba7547a..000000000 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderParser.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.fr.third.org.apache.commons.io; - -import java.nio.ByteOrder; - -/** - * Converts Strings to {@link ByteOrder} instances. - * - * @since 2.6 - */ -public final class ByteOrderParser { - - /** - * ByteOrderUtils is a static utility class, so prevent construction with a private constructor. - */ - private ByteOrderParser() { - } - - /** - * Parses the String argument as a {@link ByteOrder}. - *
- * Returns {@code ByteOrder.LITTLE_ENDIAN} if the given value is {@code "LITTLE_ENDIAN"}. - *
- *- * Returns {@code ByteOrder.BIG_ENDIAN} if the given value is {@code "BIG_ENDIAN"}. - *
- * Examples: - *- * Every implementation of the Java platform is required to support the following character encodings. Consult - * the release documentation for your implementation to see if any other encodings are supported. Consult the release - * documentation for your implementation to see if any other encodings are supported. - *
- * - *US-ASCII
ISO-8859-1
UTF-8
UTF-16BE
UTF-16LE
UTF-16
- * From the Java documentation - * Standard charsets: - *
- * - * @return An immutable, case-insensitive map from canonical charset names to charset objects. - * @see Charset#availableCharsets() - * @since 2.5 - */ - public static SortedMap- * Every implementation of the Java platform is required to support this character encoding. - *
- * - * @see Standard charsets - * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} - */ - @Deprecated - public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1; - - /** - *- * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set. - *
- *- * Every implementation of the Java platform is required to support this character encoding. - *
- * - * @see Standard charsets - * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} - */ - @Deprecated - public static final Charset US_ASCII = StandardCharsets.US_ASCII; - - /** - *- * Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark - * (either order accepted on input, big-endian used on output) - *
- *- * Every implementation of the Java platform is required to support this character encoding. - *
- * - * @see Standard charsets - * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} - */ - @Deprecated - public static final Charset UTF_16 = StandardCharsets.UTF_16; - - /** - *- * Sixteen-bit Unicode Transformation Format, big-endian byte order. - *
- *- * Every implementation of the Java platform is required to support this character encoding. - *
- * - * @see Standard charsets - * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} - */ - @Deprecated - public static final Charset UTF_16BE = StandardCharsets.UTF_16BE; - - /** - *- * Sixteen-bit Unicode Transformation Format, little-endian byte order. - *
- *- * Every implementation of the Java platform is required to support this character encoding. - *
- * - * @see Standard charsets - * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} - */ - @Deprecated - public static final Charset UTF_16LE = StandardCharsets.UTF_16LE; - - /** - *- * Eight-bit Unicode Transformation Format. - *
- *- * Every implementation of the Java platform is required to support this character encoding. - *
- * - * @see Standard charsets - * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} - */ - @Deprecated - public static final Charset UTF_8 = StandardCharsets.UTF_8; -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.fr.third.org.apache.commons.io; + +import java.nio.charset.Charset; +import java.util.Collections; +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * Charsets required of every implementation of the Java platform. + * + * From the Java documentation + * Standard charsets: + *+ * Every implementation of the Java platform is required to support the following character encodings. Consult + * the release documentation for your implementation to see if any other encodings are supported. Consult the release + * documentation for your implementation to see if any other encodings are supported. + *
+ * + *US-ASCII
ISO-8859-1
UTF-8
UTF-16BE
UTF-16LE
UTF-16
+ * From the Java documentation + * Standard charsets: + *
+ * + * @return An immutable, case-insensitive map from canonical charset names to charset objects. + * @see Charset#availableCharsets() + * @since 2.5 + */ + public static SortedMap+ * Every implementation of the Java platform is required to support this character encoding. + *
+ * + * @see Standard charsets + * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} + */ + @Deprecated + public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); + + /** + *+ * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set. + *
+ *+ * Every implementation of the Java platform is required to support this character encoding. + *
+ * + * @see Standard charsets + * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} + */ + @Deprecated + public static final Charset US_ASCII = Charset.forName("US-ASCII"); + + /** + *+ * Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark + * (either order accepted on input, big-endian used on output) + *
+ *+ * Every implementation of the Java platform is required to support this character encoding. + *
+ * + * @see Standard charsets + * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} + */ + @Deprecated + public static final Charset UTF_16 = Charset.forName("UTF-16"); + + /** + *+ * Sixteen-bit Unicode Transformation Format, big-endian byte order. + *
+ *+ * Every implementation of the Java platform is required to support this character encoding. + *
+ * + * @see Standard charsets + * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} + */ + @Deprecated + public static final Charset UTF_16BE = Charset.forName("UTF-16BE"); + + /** + *+ * Sixteen-bit Unicode Transformation Format, little-endian byte order. + *
+ *+ * Every implementation of the Java platform is required to support this character encoding. + *
+ * + * @see Standard charsets + * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} + */ + @Deprecated + public static final Charset UTF_16LE = Charset.forName("UTF-16LE"); + + /** + *+ * Eight-bit Unicode Transformation Format. + *
+ *+ * Every implementation of the Java platform is required to support this character encoding. + *
+ * + * @see Standard charsets + * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} + */ + @Deprecated + public static final Charset UTF_8 = Charset.forName("UTF-8"); +} diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/CopyUtils.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/CopyUtils.java index 5a498facd..49d8762b5 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/CopyUtils.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/CopyUtils.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -103,6 +103,7 @@ import java.nio.charset.Charset; ** Origin of code: Excalibur. * + * @version $Id: CopyUtils.java 1680650 2015-05-20 18:36:40Z britter $ * @deprecated Use IOUtils. Will be removed in 2.0. * Methods renamed to IOUtils.write() or IOUtils.copy(). * Null handling behaviour changed in IOUtils (null data does not diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/DirectoryWalker.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/DirectoryWalker.java index ba778c54f..d4f41c307 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/DirectoryWalker.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/DirectoryWalker.java @@ -30,7 +30,7 @@ import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter; * subclasses with convenient hooks to add specific behaviour. *
* This class operates with a {@link FileFilter} and maximum depth to - * limit the files and directories visited. + * limit the files and direcories visited. * Commons IO supplies many common filter implementations in the * filefilter package. *
@@ -172,7 +172,7 @@ import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter; *
* Two possible scenarios are envisaged for cancellation: *
* Origin of code: Excalibur * - * @see com.fr.third.org.apache.commons.io.input.SwappedDataInputStream + * @version $Id: EndianUtils.java 1686450 2015-06-19 16:43:48Z krosenvold $ + * @see SwappedDataInputStream */ public class EndianUtils { @@ -188,7 +189,7 @@ public class EndianUtils { final long high = data[ offset + 3 ] & 0xff; - return (high << 24) + (0xffffffffL & low); + return (high << 24) + (0xffffffffL & low); } /** @@ -369,7 +370,7 @@ public class EndianUtils { final long high = value4 & 0xff; - return (high << 24) + (0xffffffffL & low); + return (high << 24) + (0xffffffffL & low); } /** diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaner.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaner.java index a94103d0b..c1bd9c07d 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaner.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaner.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,6 +32,7 @@ import java.io.File; * {@link #exitWhenFinished}, typically in * {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar. * + * @version $Id: FileCleaner.java 1680650 2015-05-20 18:36:40Z britter $ * @deprecated Use {@link FileCleaningTracker} */ @Deprecated @@ -60,7 +61,7 @@ public class FileCleaner { /** * Track the specified file, using the provided marker, deleting the file * when the marker instance is garbage collected. - * The specified deletion strategy is used. + * The speified deletion strategy is used. * * @param file the file to be tracked, not null * @param marker the marker object used to track the file, not null @@ -91,7 +92,7 @@ public class FileCleaner { /** * Track the specified file, using the provided marker, deleting the file * when the marker instance is garbage collected. - * The specified deletion strategy is used. + * The speified deletion strategy is used. * * @param path the full path to the file to be tracked, not null * @param marker the marker object used to track the file, not null @@ -125,7 +126,7 @@ public class FileCleaner { * thread will simply exit when the JVM exits. In a more complex environment, * with multiple class loaders (such as an application server), you should be * aware that the file cleaner thread will continue running even if the class - * loader it was started from terminates. This can constitute a memory leak. + * loader it was started from terminates. This can consitute a memory leak. *
* For example, suppose that you have developed a web application, which * contains the commons-io jar file in your WEB-INF/lib directory. In other @@ -135,7 +136,7 @@ public class FileCleaner { * posing a memory leak. *
* This method allows the thread to be terminated. Simply call this method
- * in the resource cleanup code, such as
+ * in the resource cleanup code, such as
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)}.
* One called, no new objects can be tracked by the file cleaner.
* @deprecated Use {@link FileCleaningTracker#exitWhenFinished()}.
@@ -150,7 +151,7 @@ public class FileCleaner {
* This is mainly useful for code, which wants to support the new
* {@link FileCleaningTracker} class while maintain compatibility with the
* deprecated {@link FileCleaner}.
- *
+ *
* @return the singleton instance
*/
public static FileCleaningTracker getInstance() {
diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaningTracker.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaningTracker.java
index d6364694e..f0a31d7c4 100644
--- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaningTracker.java
+++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaningTracker.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -39,6 +39,7 @@ import java.util.List;
* {@link #exitWhenFinished}, typically in
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar.
*
+ * @version $Id: FileCleaningTracker.java 1686747 2015-06-21 18:44:49Z krosenvold $
*/
public class FileCleaningTracker {
@@ -47,7 +48,7 @@ public class FileCleaningTracker {
/**
* Queue of Tracker
instances being watched.
*/
- ReferenceQueue
Files.getFileStore(Paths.get("/home")).getUsableSpace()
- * or iterate over FileSystems.getDefault().getFileStores()
*/
-@Deprecated
public class FileSystemUtils {
/** Singleton instance, used mainly for testing. */
@@ -84,7 +80,6 @@ public class FileSystemUtils {
} else if (osName.contains("linux") ||
osName.contains("mpe/ix") ||
osName.contains("freebsd") ||
- osName.contains("openbsd") ||
osName.contains("irix") ||
osName.contains("digital unix") ||
osName.contains("unix") ||
@@ -150,8 +145,8 @@ public class FileSystemUtils {
//-----------------------------------------------------------------------
/**
- * Returns the free space on a drive or volume in kibibytes (1024 bytes)
- * by invoking the command line.
+ * Returns the free space on a drive or volume in kilobytes by invoking
+ * the command line.
* * FileSystemUtils.freeSpaceKb("C:"); // Windows * FileSystemUtils.freeSpaceKb("/volume"); // *nix @@ -172,15 +167,13 @@ public class FileSystemUtils { * @throws IllegalStateException if an error occurred in initialisation * @throws IOException if an error occurs when finding the free space * @since 1.2, enhanced OS support in 1.3 - * @deprecated As of 2.6 deprecated without replacement. Please use {@link java.nio.file.FileStore#getUsableSpace()}. */ - @Deprecated public static long freeSpaceKb(final String path) throws IOException { return freeSpaceKb(path, -1); } /** - * Returns the free space on a drive or volume in kibibytes (1024 bytes) - * by invoking the command line. + * Returns the free space on a drive or volume in kilobytes by invoking + * the command line. ** * @param output the OutputStream to close, may be null or already closed - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final OutputStream output) { closeQuietly((Closeable) output); } @@ -351,12 +332,7 @@ public class IOUtils { * * @param closeable the objects to close, may be null or already closed * @since 2.0 - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final Closeable closeable) { try { if (closeable != null) { @@ -409,12 +385,7 @@ public class IOUtils { * @param closeables the objects to close, may be null or already closed * @see #closeQuietly(Closeable) * @since 2.5 - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final Closeable... closeables) { if (closeables == null) { return; @@ -446,12 +417,7 @@ public class IOUtils { * * @param sock the Socket to close, may be null or already closed * @since 2.0 - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final Socket sock) { if (sock != null) { try { @@ -484,12 +450,7 @@ public class IOUtils { * * @param selector the Selector to close, may be null or already closed * @since 2.2 - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final Selector selector) { if (selector != null) { try { @@ -522,12 +483,7 @@ public class IOUtils { * * @param sock the ServerSocket to close, may be null or already closed * @since 2.2 - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final ServerSocket sock) { if (sock != null) { try { @@ -585,7 +541,7 @@ public class IOUtils { * @throws IOException if an I/O error occurs * @since 2.5 */ - public static InputStream toBufferedInputStream(final InputStream input, final int size) throws IOException { + public static InputStream toBufferedInputStream(final InputStream input, int size) throws IOException { return ByteArrayOutputStream.toBufferedInputStream(input, size); } @@ -614,7 +570,7 @@ public class IOUtils { * @see #buffer(Reader) * @since 2.5 */ - public static BufferedReader toBufferedReader(final Reader reader, final int size) { + public static BufferedReader toBufferedReader(final Reader reader, int size) { return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, size); } @@ -641,7 +597,7 @@ public class IOUtils { * @throws NullPointerException if the input parameter is null * @since 2.5 */ - public static BufferedReader buffer(final Reader reader, final int size) { + public static BufferedReader buffer(final Reader reader, int size) { return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, size); } @@ -668,7 +624,7 @@ public class IOUtils { * @throws NullPointerException if the input parameter is null * @since 2.5 */ - public static BufferedWriter buffer(final Writer writer, final int size) { + public static BufferedWriter buffer(final Writer writer, int size) { return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer, size); } @@ -700,7 +656,7 @@ public class IOUtils { * @throws NullPointerException if the input parameter is null * @since 2.5 */ - public static BufferedOutputStream buffer(final OutputStream outputStream, final int size) { + public static BufferedOutputStream buffer(final OutputStream outputStream, int size) { // reject null early on rather than waiting for IO operation to fail if (outputStream == null) { // not checked by BufferedOutputStream throw new NullPointerException(); @@ -737,7 +693,7 @@ public class IOUtils { * @throws NullPointerException if the input parameter is null * @since 2.5 */ - public static BufferedInputStream buffer(final InputStream inputStream, final int size) { + public static BufferedInputStream buffer(final InputStream inputStream, int size) { // reject null early on rather than waiting for IO operation to fail if (inputStream == null) { // not checked by BufferedInputStream throw new NullPointerException(); @@ -761,10 +717,9 @@ public class IOUtils { * @throws IOException if an I/O error occurs */ public static byte[] toByteArray(final InputStream input) throws IOException { - try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { - copy(input, output); - return output.toByteArray(); - } + final ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy(input, output); + return output.toByteArray(); } /** @@ -818,14 +773,14 @@ public class IOUtils { final byte[] data = new byte[size]; int offset = 0; - int read; + int readed; - while (offset < size && (read = input.read(data, offset, size - offset)) != EOF) { - offset += read; + while (offset < size && (readed = input.read(data, offset, size - offset)) != EOF) { + offset += readed; } if (offset != size) { - throw new IOException("Unexpected read size. current: " + offset + ", expected: " + size); + throw new IOException("Unexpected readed size. current: " + offset + ", excepted: " + size); } return data; @@ -864,10 +819,9 @@ public class IOUtils { * @since 2.3 */ public static byte[] toByteArray(final Reader input, final Charset encoding) throws IOException { - try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { - copy(input, output, encoding); - return output.toByteArray(); - } + final ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy(input, output, encoding); + return output.toByteArray(); } /** @@ -953,8 +907,11 @@ public class IOUtils { * @since 2.4 */ public static byte[] toByteArray(final URLConnection urlConn) throws IOException { - try (InputStream inputStream = urlConn.getInputStream()) { + final InputStream inputStream = urlConn.getInputStream(); + try { return IOUtils.toByteArray(inputStream); + } finally { + inputStream.close(); } } @@ -1080,10 +1037,9 @@ public class IOUtils { * @since 2.3 */ public static String toString(final InputStream input, final Charset encoding) throws IOException { - try (final StringBuilderWriter sw = new StringBuilderWriter()) { - copy(input, sw, encoding); - return sw.toString(); - } + final StringBuilderWriter sw = new StringBuilderWriter(); + copy(input, sw, encoding); + return sw.toString(); } /** @@ -1122,10 +1078,9 @@ public class IOUtils { * @throws IOException if an I/O error occurs */ public static String toString(final Reader input) throws IOException { - try (final StringBuilderWriter sw = new StringBuilderWriter()) { - copy(input, sw); - return sw.toString(); - } + final StringBuilderWriter sw = new StringBuilderWriter(); + copy(input, sw); + return sw.toString(); } /** @@ -1195,8 +1150,11 @@ public class IOUtils { * @since 2.3 */ public static String toString(final URL url, final Charset encoding) throws IOException { - try (InputStream inputStream = url.openStream()) { + final InputStream inputStream = url.openStream(); + try { return toString(inputStream, encoding); + } finally { + inputStream.close(); } } @@ -1249,132 +1207,6 @@ public class IOUtils { return new String(input, Charsets.toCharset(encoding)); } - // resources - //----------------------------------------------------------------------- - - /** - * Gets the contents of a classpath resource as a String using the - * specified character encoding. - * - ** FileSystemUtils.freeSpaceKb("C:"); // Windows * FileSystemUtils.freeSpaceKb("/volume"); // *nix @@ -203,16 +196,13 @@ public class FileSystemUtils { * @throws IllegalStateException if an error occurred in initialisation * @throws IOException if an error occurs when finding the free space * @since 2.0 - * @deprecated As of 2.6 deprecated without replacement. Please use {@link java.nio.file.FileStore#getUsableSpace()}. */ - @Deprecated public static long freeSpaceKb(final String path, final long timeout) throws IOException { return INSTANCE.freeSpaceOS(path, OS, true, timeout); } /** - * Returns the free space for the working directory - * in kibibytes (1024 bytes) by invoking the command line. + * Returns the disk size of the volume which holds the working directory. ** * @param input the InputStream to close, may be null or already closed - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final InputStream input) { closeQuietly((Closeable) input); } @@ -307,12 +293,7 @@ public class IOUtils { ** Identical to: *
@@ -222,16 +212,13 @@ public class FileSystemUtils { * @throws IllegalStateException if an error occurred in initialisation * @throws IOException if an error occurs when finding the free space * @since 2.0 - * @deprecated As of 2.6 deprecated without replacement. Please use {@link java.nio.file.FileStore#getUsableSpace()}. */ - @Deprecated public static long freeSpaceKb() throws IOException { return freeSpaceKb(-1); } /** - * Returns the free space for the working directory - * in kibibytes (1024 bytes) by invoking the command line. + * Returns the disk size of the volume which holds the working directory. ** * @param output the Writer to close, may be null or already closed - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final Writer output) { closeQuietly((Closeable) output); } @@ -274,12 +265,7 @@ public class IOUtils { ** Identical to: *
@@ -243,9 +230,7 @@ public class FileSystemUtils { * @throws IllegalStateException if an error occurred in initialisation * @throws IOException if an error occurs when finding the free space * @since 2.0 - * @deprecated As of 2.6 deprecated without replacement. Please use {@link java.nio.file.FileStore#getUsableSpace()}. */ - @Deprecated public static long freeSpaceKb(final long timeout) throws IOException { return freeSpaceKb(new File(".").getAbsolutePath(), timeout); } @@ -300,17 +285,14 @@ public class FileSystemUtils { * @return the amount of free drive space on the drive * @throws IOException if an error occurs */ - long freeSpaceWindows(final String path, final long timeout) throws IOException { - String normPath = FilenameUtils.normalize(path, false); - if (normPath == null) { - throw new IllegalArgumentException(path); - } - if (normPath.length() > 0 && normPath.charAt(0) != '"') { - normPath = "\"" + normPath + "\""; + long freeSpaceWindows(String path, final long timeout) throws IOException { + path = FilenameUtils.normalize(path, false); + if (path.length() > 0 && path.charAt(0) != '"') { + path = "\"" + path + "\""; } // build and run the 'dir' command - final String[] cmdAttribs = new String[] {"cmd.exe", "/C", "dir /a /-c " + normPath}; + final String[] cmdAttribs = new String[] {"cmd.exe", "/C", "dir /a /-c " + path}; // read in the output of the command to an ArrayList final List* * @param input the Reader to close, may be null or already closed - * - * @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle - * suppressed exceptions manually. - * @see Throwable#addSuppressed(java.lang.Throwable) */ - @Deprecated public static void closeQuietly(final Reader input) { closeQuietly((Closeable) input); } @@ -242,12 +238,7 @@ public class IOUtils { *lines = performCommand(cmdAttribs, Integer.MAX_VALUE, timeout); @@ -322,13 +304,13 @@ public class FileSystemUtils { for (int i = lines.size() - 1; i >= 0; i--) { final String line = lines.get(i); if (line.length() > 0) { - return parseDir(line, normPath); + return parseDir(line, path); } } // all lines are blank throw new IOException( "Command line 'dir /-c' did not return any info " + - "for path '" + normPath + "'"); + "for path '" + path + "'"); } /** @@ -489,7 +471,7 @@ public class FileSystemUtils { // however, its still not perfect as the JDK support is so poor // (see commons-exec or Ant for a better multi-threaded multi-os solution) - final List lines = new ArrayList<>(20); + final List lines = new ArrayList (20); Process proc = null; InputStream in = null; OutputStream out = null; @@ -528,23 +510,6 @@ public class FileSystemUtils { "Command line did not return any info " + "for command " + Arrays.asList(cmdAttribs)); } - - inr.close(); - inr = null; - - in.close(); - in = null; - - if (out != null) { - out.close(); - out = null; - } - - if (err != null) { - err.close(); - err = null; - } - return lines; } catch (final InterruptedException ex) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileUtils.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileUtils.java index 2e872c1e4..b8e5797f9 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileUtils.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileUtils.java @@ -33,8 +33,6 @@ import java.net.URLConnection; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -48,6 +46,7 @@ import com.fr.third.org.apache.commons.io.filefilter.DirectoryFileFilter; import com.fr.third.org.apache.commons.io.filefilter.FalseFileFilter; import com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils; import com.fr.third.org.apache.commons.io.filefilter.IOFileFilter; +import com.fr.third.org.apache.commons.io.filefilter.NameFileFilter; import com.fr.third.org.apache.commons.io.filefilter.SuffixFileFilter; import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter; import com.fr.third.org.apache.commons.io.output.NullOutputStream; @@ -69,12 +68,9 @@ import com.fr.third.org.apache.commons.io.output.NullOutputStream; * calculating a checksum * * - * Note that a specific charset should be specified whenever possible. - * Relying on the platform default means that the code is Locale-dependent. - * Only use the default if the files are known to always use the platform default. - *
* Origin of code: Excalibur, Alexandria, Commons-Utils * + * @version $Id: FileUtils.java 1722481 2016-01-01 01:42:04Z dbrosius $ */ public class FileUtils { @@ -437,7 +433,8 @@ public class FileUtils { */ public static void touch(final File file) throws IOException { if (!file.exists()) { - openOutputStream(file).close(); + final OutputStream out = openOutputStream(file); + IOUtils.closeQuietly(out); } final boolean success = file.setLastModified(System.currentTimeMillis()); if (!success) { @@ -503,14 +500,13 @@ public class FileUtils { * in
FileFilterUtils.makeCVSAware(null)
. * * @param directory the directory to search in - * @param fileFilter filter to apply when finding files. Must not be {@code null}, - * use {@link TrueFileFilter#INSTANCE} to match all files in selected directories. + * @param fileFilter filter to apply when finding files. * @param dirFilter optional filter to apply when finding subdirectories. * If this parameter is {@code null}, subdirectories will not be included in the - * search. Use {@link TrueFileFilter#INSTANCE} to match all directories. - * @return a collection of java.io.File with the matching files - * @see com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils - * @see com.fr.third.org.apache.commons.io.filefilter.NameFileFilter + * search. Use TrueFileFilter.INSTANCE to match all directories. + * @return an collection of java.io.File with the matching files + * @see FileFilterUtils + * @see NameFileFilter */ public static CollectionlistFiles( final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) { @@ -520,7 +516,7 @@ public class FileUtils { final IOFileFilter effDirFilter = setUpEffectiveDirFilter(dirFilter); //Find files - final Collection files = new java.util.LinkedList<>(); + final Collection files = new java.util.LinkedList (); innerListFiles(files, directory, FileFilterUtils.or(effFileFilter, effDirFilter), false); return files; @@ -579,10 +575,10 @@ public class FileUtils { * @param dirFilter optional filter to apply when finding subdirectories. * If this parameter is {@code null}, subdirectories will not be included in the * search. Use TrueFileFilter.INSTANCE to match all directories. - * @return a collection of java.io.File with the matching files - * @see com.fr.third.org.apache.commons.io.FileUtils#listFiles - * @see com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils - * @see com.fr.third.org.apache.commons.io.filefilter.NameFileFilter + * @return an collection of java.io.File with the matching files + * @see FileUtils#listFiles + * @see FileFilterUtils + * @see NameFileFilter * @since 2.2 */ public static Collection listFilesAndDirs( @@ -593,7 +589,7 @@ public class FileUtils { final IOFileFilter effDirFilter = setUpEffectiveDirFilter(dirFilter); //Find files - final Collection files = new java.util.LinkedList<>(); + final Collection files = new java.util.LinkedList (); if (directory.isDirectory()) { files.add(directory); } @@ -616,8 +612,8 @@ public class FileUtils { * If this parameter is {@code null}, subdirectories will not be included in the * search. Use TrueFileFilter.INSTANCE to match all directories. * @return an iterator of java.io.File for the matching files - * @see com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils - * @see com.fr.third.org.apache.commons.io.filefilter.NameFileFilter + * @see FileFilterUtils + * @see NameFileFilter * @since 1.2 */ public static Iterator iterateFiles( @@ -641,8 +637,8 @@ public class FileUtils { * If this parameter is {@code null}, subdirectories will not be included in the * search. Use TrueFileFilter.INSTANCE to match all directories. * @return an iterator of java.io.File for the matching files - * @see com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils - * @see com.fr.third.org.apache.commons.io.filefilter.NameFileFilter + * @see FileFilterUtils + * @see NameFileFilter * @since 2.2 */ public static Iterator iterateFilesAndDirs(final File directory, final IOFileFilter fileFilter, @@ -675,7 +671,7 @@ public class FileUtils { * @param extensions an array of extensions, ex. {"java","xml"}. If this * parameter is {@code null}, all files are returned. * @param recursive if true all subdirectories are searched as well - * @return a collection of java.io.File with the matching files + * @return an collection of java.io.File with the matching files */ public static Collection listFiles( final File directory, final String[] extensions, final boolean recursive) { @@ -750,9 +746,16 @@ public class FileUtils { return true; } - try (InputStream input1 = new FileInputStream(file1); - InputStream input2 = new FileInputStream(file2)) { + InputStream input1 = null; + InputStream input2 = null; + try { + input1 = new FileInputStream(file1); + input2 = new FileInputStream(file2); return IOUtils.contentEquals(input1, input2); + + } finally { + IOUtils.closeQuietly(input1); + IOUtils.closeQuietly(input2); } } @@ -796,13 +799,22 @@ public class FileUtils { return true; } - try (Reader input1 = charsetName == null - ? new InputStreamReader(new FileInputStream(file1), Charset.defaultCharset()) - : new InputStreamReader(new FileInputStream(file1), charsetName); - Reader input2 = charsetName == null - ? new InputStreamReader(new FileInputStream(file2), Charset.defaultCharset()) - : new InputStreamReader(new FileInputStream(file2), charsetName)) { + Reader input1 = null; + Reader input2 = null; + try { + if (charsetName == null) { + // N.B. make explicit the use of the default charset + input1 = new InputStreamReader(new FileInputStream(file1), Charset.defaultCharset()); + input2 = new InputStreamReader(new FileInputStream(file2), Charset.defaultCharset()); + } else { + input1 = new InputStreamReader(new FileInputStream(file1), charsetName); + input2 = new InputStreamReader(new FileInputStream(file2), charsetName); + } return IOUtils.contentEqualsIgnoreEOL(input1, input2); + + } finally { + IOUtils.closeQuietly(input1); + IOUtils.closeQuietly(input2); } } @@ -845,6 +857,7 @@ public class FileUtils { * @return The decoded URL or {@code null} if the input was * {@code null}. */ + @SuppressWarnings("deprecation") // unavoidable until Java 7 static String decodeUrl(final String url) { String decoded = url; if (url != null && url.indexOf('%') >= 0) { @@ -866,7 +879,7 @@ public class FileUtils { } finally { if (bytes.position() > 0) { bytes.flip(); - buffer.append(StandardCharsets.UTF_8.decode(bytes).toString()); + buffer.append(Charsets.UTF_8.decode(bytes).toString()); bytes.clear(); } } @@ -1090,8 +1103,11 @@ public class FileUtils { * @since 2.1 */ public static long copyFile(final File input, final OutputStream output) throws IOException { - try (FileInputStream fis = new FileInputStream(input)) { + final FileInputStream fis = new FileInputStream(input); + try { return IOUtils.copyLarge(fis, output); + } finally { + fis.close(); } } @@ -1118,10 +1134,15 @@ public class FileUtils { throw new IOException("Destination '" + destFile + "' exists but is a directory"); } - try (FileInputStream fis = new FileInputStream(srcFile); - FileChannel input = fis.getChannel(); - FileOutputStream fos = new FileOutputStream(destFile); - FileChannel output = fos.getChannel()) { + FileInputStream fis = null; + FileOutputStream fos = null; + FileChannel input = null; + FileChannel output = null; + try { + fis = new FileInputStream(srcFile); + fos = new FileOutputStream(destFile); + input = fis.getChannel(); + output = fos.getChannel(); final long size = input.size(); // TODO See IO-386 long pos = 0; long count = 0; @@ -1134,6 +1155,8 @@ public class FileUtils { } pos += bytesCopied; } + } finally { + IOUtils.closeQuietly(output, fos, input, fis); } final long srcLen = srcFile.length(); // TODO See IO-386 @@ -1356,7 +1379,7 @@ public class FileUtils { if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) { final File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter); if (srcFiles != null && srcFiles.length > 0) { - exclusionList = new ArrayList<>(srcFiles.length); + exclusionList = new ArrayList (srcFiles.length); for (final File srcFile : srcFiles) { final File copiedFile = new File(destDir, srcFile.getName()); exclusionList.add(copiedFile.getCanonicalPath()); @@ -1372,7 +1395,7 @@ public class FileUtils { * @param dest the destination * @throws FileNotFoundException if the destination does not exist */ - private static void checkFileRequirements(final File src, final File dest) throws FileNotFoundException { + private static void checkFileRequirements(File src, File dest) throws FileNotFoundException { if (src == null) { throw new NullPointerException("Source must not be null"); } @@ -1502,8 +1525,10 @@ public class FileUtils { * @since 2.0 */ public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException { - try (InputStream in = source) { - copyToFile(in, destination); + try { + copyToFile(source, destination); + } finally { + IOUtils.closeQuietly(source); } } @@ -1525,78 +1550,12 @@ public class FileUtils { * @since 2.5 */ public static void copyToFile(final InputStream source, final File destination) throws IOException { - try (InputStream in = source; - OutputStream out = openOutputStream(destination)) { - IOUtils.copy(in, out); - } - } - - /** - * Copies a file or directory to within another directory preserving the file dates. - * - * This method copies the source file or directory, along all its contents, to a - * directory of the same name in the specified destination directory. - *
- * The destination directory is created if it does not exist. - * If the destination directory did exist, then this method merges - * the source with the destination, with the source taking precedence. - *
- * Note: This method tries to preserve the files' last - * modified date/times using {@link File#setLastModified(long)}, however - * it is not guaranteed that those operations will succeed. - * If the modification operation fails, no indication is provided. - * - * @param src an existing file or directory to copy, must not be {@code null} - * @param destDir the directory to place the copy in, must not be {@code null} - * - * @throws NullPointerException if source or destination is {@code null} - * @throws IOException if source or destination is invalid - * @throws IOException if an IO error occurs during copying - * @see #copyDirectoryToDirectory(File, File) - * @see #copyFileToDirectory(File, File) - * @since 2.6 - */ - public static void copyToDirectory(final File src, final File destDir) throws IOException { - if (src == null) { - throw new NullPointerException("Source must not be null"); - } - if (src.isFile()) { - copyFileToDirectory(src, destDir); - } else if (src.isDirectory()) { - copyDirectoryToDirectory(src, destDir); - } else { - throw new IOException("The source " + src + " does not exist"); - } - } - - /** - * Copies a files to a directory preserving each file's date. - *
- * This method copies the contents of the specified source files - * to a file of the same name in the specified destination directory. - * The destination directory is created if it does not exist. - * If the destination file exists, then this method will overwrite it. - *
- * Note: This method tries to preserve the file's last - * modified date/times using {@link File#setLastModified(long)}, however - * it is not guaranteed that the operation will succeed. - * If the modification operation fails, no indication is provided. - * - * @param srcs a existing files to copy, must not be {@code null} - * @param destDir the directory to place the copy in, must not be {@code null} - * - * @throws NullPointerException if source or destination is null - * @throws IOException if source or destination is invalid - * @throws IOException if an IO error occurs during copying - * @see #copyFileToDirectory(File, File) - * @since 2.6 - */ - public static void copyToDirectory(final Iterable
- * + * * @param cause * the cause (see {@link #getCause()}). A {@code null} value is allowed. */ diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOUtils.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOUtils.java index 96049af9b..837ed278b 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOUtils.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOUtils.java @@ -55,7 +55,7 @@ import com.fr.third.org.apache.commons.io.output.StringBuilderWriter; *srcs, final File destDir) throws IOException { - if (srcs == null) { - throw new NullPointerException("Sources must not be null"); - } - for (final File src : srcs) { - copyFileToDirectory(src, destDir); + final FileOutputStream output = openOutputStream(destination); + try { + IOUtils.copy(source, output); + output.close(); // don't swallow close Exception if copy completes normally + } finally { + IOUtils.closeQuietly(output); } } @@ -1735,7 +1694,7 @@ public class FileUtils { * @return The files in the directory, never null. * @throws IOException if an I/O error occurs */ - private static File[] verifiedListFiles(final File directory) throws IOException { + private static File[] verifiedListFiles(File directory) throws IOException { if (!directory.exists()) { final String message = directory + " does not exist"; throw new IllegalArgumentException(message); @@ -1766,11 +1725,11 @@ public class FileUtils { * @throws NullPointerException if the file is {@code null} */ public static boolean waitFor(final File file, final int seconds) { - final long finishAt = System.currentTimeMillis() + (seconds * 1000L); + long finishAt = System.currentTimeMillis() + (seconds * 1000L); boolean wasInterrupted = false; try { while (!file.exists()) { - final long remaining = finishAt - System.currentTimeMillis(); + long remaining = finishAt - System.currentTimeMillis(); if (remaining < 0){ return false; } @@ -1802,8 +1761,12 @@ public class FileUtils { * @since 2.3 */ public static String readFileToString(final File file, final Charset encoding) throws IOException { - try (InputStream in = openInputStream(file)) { + InputStream in = null; + try { + in = openInputStream(file); return IOUtils.toString(in, Charsets.toCharset(encoding)); + } finally { + IOUtils.closeQuietly(in); } } @@ -1831,7 +1794,7 @@ public class FileUtils { * @return the file contents, never {@code null} * @throws IOException in case of an I/O error * @since 1.3.1 - * @deprecated 2.5 use {@link #readFileToString(File, Charset)} instead (and specify the appropriate encoding) + * @deprecated 2.5 use {@link #readFileToString(File, Charset)} instead */ @Deprecated public static String readFileToString(final File file) throws IOException { @@ -1848,10 +1811,12 @@ public class FileUtils { * @since 1.1 */ public static byte[] readFileToByteArray(final File file) throws IOException { - try (InputStream in = openInputStream(file)) { - final long fileLength = file.length(); - // file.length() may return 0 for system-dependent entities, treat 0 as unknown length - see IO-453 - return fileLength > 0 ? IOUtils.toByteArray(in, fileLength) : IOUtils.toByteArray(in); + InputStream in = null; + try { + in = openInputStream(file); + return IOUtils.toByteArray(in); // Do NOT use file.length() - see IO-453 + } finally { + IOUtils.closeQuietly(in); } } @@ -1866,8 +1831,12 @@ public class FileUtils { * @since 2.3 */ public static List readLines(final File file, final Charset encoding) throws IOException { - try (InputStream in = openInputStream(file)) { + InputStream in = null; + try { + in = openInputStream(file); return IOUtils.readLines(in, Charsets.toCharset(encoding)); + } finally { + IOUtils.closeQuietly(in); } } @@ -1894,7 +1863,7 @@ public class FileUtils { * @return the list of Strings representing each line in the file, never {@code null} * @throws IOException in case of an I/O error * @since 1.3 - * @deprecated 2.5 use {@link #readLines(File, Charset)} instead (and specify the appropriate encoding) + * @deprecated 2.5 use {@link #readLines(File, Charset)} instead */ @Deprecated public static List readLines(final File file) throws IOException { @@ -1937,15 +1906,11 @@ public class FileUtils { try { in = openInputStream(file); return IOUtils.lineIterator(in, encoding); - } catch (final IOException | RuntimeException ex) { - try { - if (in != null) { - in.close(); - } - } - catch (final IOException e) { - ex.addSuppressed(e); - } + } catch (final IOException ex) { + IOUtils.closeQuietly(in); + throw ex; + } catch (final RuntimeException ex) { + IOUtils.closeQuietly(in); throw ex; } } @@ -2010,10 +1975,15 @@ public class FileUtils { * @throws IOException in case of an I/O error * @since 2.3 */ - public static void writeStringToFile(final File file, final String data, final Charset encoding, - final boolean append) throws IOException { - try (OutputStream out = openOutputStream(file, append)) { + public static void writeStringToFile(final File file, final String data, final Charset encoding, final boolean + append) throws IOException { + OutputStream out = null; + try { + out = openOutputStream(file, append); IOUtils.write(data, out, encoding); + out.close(); // don't swallow close Exception if copy completes normally + } finally { + IOUtils.closeQuietly(out); } } @@ -2041,7 +2011,7 @@ public class FileUtils { * @param file the file to write * @param data the content to write to the file * @throws IOException in case of an I/O error - * @deprecated 2.5 use {@link #writeStringToFile(File, String, Charset)} instead (and specify the appropriate encoding) + * @deprecated 2.5 use {@link #writeStringToFile(File, String, Charset)} instead */ @Deprecated public static void writeStringToFile(final File file, final String data) throws IOException { @@ -2057,7 +2027,7 @@ public class FileUtils { * end of the file rather than overwriting * @throws IOException in case of an I/O error * @since 2.1 - * @deprecated 2.5 use {@link #writeStringToFile(File, String, Charset, boolean)} instead (and specify the appropriate encoding) + * @deprecated 2.5 use {@link #writeStringToFile(File, String, Charset, boolean)} instead */ @Deprecated public static void writeStringToFile(final File file, final String data, final boolean append) throws IOException { @@ -2071,7 +2041,7 @@ public class FileUtils { * @param data the content to write to the file * @throws IOException in case of an I/O error * @since 2.0 - * @deprecated 2.5 use {@link #write(File, CharSequence, Charset)} instead (and specify the appropriate encoding) + * @deprecated 2.5 use {@link #write(File, CharSequence, Charset)} instead */ @Deprecated public static void write(final File file, final CharSequence data) throws IOException { @@ -2087,7 +2057,7 @@ public class FileUtils { * end of the file rather than overwriting * @throws IOException in case of an I/O error * @since 2.1 - * @deprecated 2.5 use {@link #write(File, CharSequence, Charset, boolean)} instead (and specify the appropriate encoding) + * @deprecated 2.5 use {@link #write(File, CharSequence, Charset, boolean)} instead */ @Deprecated public static void write(final File file, final CharSequence data, final boolean append) throws IOException { @@ -2219,8 +2189,13 @@ public class FileUtils { */ public static void writeByteArrayToFile(final File file, final byte[] data, final int off, final int len, final boolean append) throws IOException { - try (OutputStream out = openOutputStream(file, append)) { + OutputStream out = null; + try { + out = openOutputStream(file, append); out.write(data, off, len); + out.close(); // don't swallow close Exception if copy completes normally + } finally { + IOUtils.closeQuietly(out); } } @@ -2331,8 +2306,15 @@ public class FileUtils { */ public static void writeLines(final File file, final String encoding, final Collection> lines, final String lineEnding, final boolean append) throws IOException { - try (OutputStream out = new BufferedOutputStream(openOutputStream(file, append))) { - IOUtils.writeLines(lines, lineEnding, out, encoding); + FileOutputStream out = null; + try { + out = openOutputStream(file, append); + final BufferedOutputStream buffer = new BufferedOutputStream(out); + IOUtils.writeLines(lines, lineEnding, buffer, encoding); + buffer.flush(); + out.close(); // don't swallow close Exception if copy completes normally + } finally { + IOUtils.closeQuietly(out); } } @@ -2634,9 +2616,9 @@ public class FileUtils { /** * the size of a file * @param file the file to check - * @return the size of the file + * @return the size of the fil */ - private static long sizeOf0(final File file) { + private static long sizeOf0(File file) { if (file.isDirectory()) { return sizeOfDirectory0(file); } else { @@ -2688,7 +2670,7 @@ public class FileUtils { // internal method; if file does not exist will return 0 /** - * Returns the size of a file + * Returns the sid of a file * @param fileOrDir The file * @return the size */ @@ -2887,8 +2869,12 @@ public class FileUtils { if (file.isDirectory()) { throw new IllegalArgumentException("Checksums can't be computed on directories"); } - try (InputStream in = new CheckedInputStream(new FileInputStream(file), checksum)) { + InputStream in = null; + try { + in = new CheckedInputStream(new FileInputStream(file), checksum); IOUtils.copy(in, new NullOutputStream()); + } finally { + IOUtils.closeQuietly(in); } return checksum; } @@ -3101,9 +3087,61 @@ public class FileUtils { * @since 2.0 */ public static boolean isSymlink(final File file) throws IOException { + if ( Java7Support.isAtLeastJava7() ) + { + return Java7Support.isSymLink( file ); + } + if (file == null) { throw new NullPointerException("File must not be null"); } - return Files.isSymbolicLink(file.toPath()); + if (FilenameUtils.isSystemWindows()) { + return false; + } + File fileInCanonicalDir = null; + if (file.getParent() == null) { + fileInCanonicalDir = file; + } else { + final File canonicalDir = file.getParentFile().getCanonicalFile(); + fileInCanonicalDir = new File(canonicalDir, file.getName()); + } + + if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())) { + return isBrokenSymlink(file); + } else { + return true; + } + } + + /** + * Determines if the specified file is possibly a broken symbolic link. + * + * @param file the file to check + + * @return true if the file is a Symbolic Link + * @throws IOException if an IO error occurs while checking the file + */ + private static boolean isBrokenSymlink(final File file) throws IOException { + // if file exists then if it is a symlink it's not broken + if (file.exists()) { + return false; + } + // a broken symlink will show up in the list of files of its parent directory + final File canon = file.getCanonicalFile(); + File parentDir = canon.getParentFile(); + if (parentDir == null || !parentDir.exists()) { + return false; + } + + // is it worthwhile to create a FileFilterUtil method for this? + // is it worthwhile to create an "identity" IOFileFilter for this? + File[] fileInDir = parentDir.listFiles( + new FileFilter() { + public boolean accept(File aFile) { + return aFile.equals(canon); + } + } + ); + return fileInDir != null && fileInDir.length > 0; } } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FilenameUtils.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FilenameUtils.java index 20abdcac1..73848113a 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FilenameUtils.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FilenameUtils.java @@ -77,6 +77,7 @@ import java.util.Stack; * * Origin of code: Excalibur, Alexandria, Tomcat, Commons-Utils. * + * @version $Id: FilenameUtils.java 1702170 2015-09-10 06:35:02Z krosenvold $ * @since 1.1 */ public class FilenameUtils { @@ -328,7 +329,7 @@ public class FilenameUtils { * * @param filename the filename to normalize, null returns null * @param unixSeparator {@code true} if a unix separator should - * be used or {@code false} if a windows separator should be used. + * be used or {@code false} if a windows separtor should be used. * @return the normalized filename, or null if invalid. Null bytes inside string will be removed * @since 2.0 */ @@ -666,8 +667,6 @@ public class FilenameUtils { return 2; } return 3; - } else if (ch0 == UNIX_SEPARATOR) { - return 1; } return NOT_FOUND; @@ -716,7 +715,7 @@ public class FilenameUtils { *
* The output will be the same irrespective of the machine that the code is running on. *
- * + * * @param filename * the filename to find the last extension separator in, null returns -1 * @return the index of the last extension separator character, or -1 if there is no such character @@ -772,7 +771,7 @@ public class FilenameUtils { failIfNullBytePresent(filename + UNIX_SEPARATOR); return filename + UNIX_SEPARATOR; } - final String path = filename.substring(0, len); + String path = filename.substring(0, len); failIfNullBytePresent(path); return path; } @@ -852,7 +851,7 @@ public class FilenameUtils { if (prefix >= filename.length() || index < 0 || prefix >= endIndex) { return ""; } - final String path = filename.substring(prefix, endIndex); + String path = filename.substring(prefix, endIndex); failIfNullBytePresent(path); return path; } @@ -982,8 +981,8 @@ public class FilenameUtils { * This may be used for poison byte attacks. * @param path the path to check */ - private static void failIfNullBytePresent(final String path) { - final int len = path.length(); + private static void failIfNullBytePresent(String path) { + int len = path.length(); for (int i = 0; i < len; i++) { if (path.charAt(i) == 0) { throw new IllegalArgumentException("Null byte present in file/path name. There are no " + @@ -1278,7 +1277,7 @@ public class FilenameUtils { * * @param filename the filename to match on * @param wildcardMatcher the wildcard string to match against - * @return true if the filename matches the wildcard string + * @return true if the filename matches the wilcard string * @see IOCase#SENSITIVE */ public static boolean wildcardMatch(final String filename, final String wildcardMatcher) { @@ -1304,7 +1303,7 @@ public class FilenameUtils { * * @param filename the filename to match on * @param wildcardMatcher the wildcard string to match against - * @return true if the filename matches the wildcard string + * @return true if the filename matches the wilcard string * @see IOCase#SYSTEM */ public static boolean wildcardMatchOnSystem(final String filename, final String wildcardMatcher) { @@ -1322,7 +1321,7 @@ public class FilenameUtils { * @param filename the filename to match on * @param wildcardMatcher the wildcard string to match against * @param caseSensitivity what case sensitivity rule to use, null means case-sensitive - * @return true if the filename matches the wildcard string + * @return true if the filename matches the wilcard string * @since 1.3 */ public static boolean wildcardMatch(final String filename, final String wildcardMatcher, IOCase caseSensitivity) { @@ -1339,7 +1338,7 @@ public class FilenameUtils { boolean anyChars = false; int textIdx = 0; int wcsIdx = 0; - final Stackbacktrack = new Stack<>(); + final Stack backtrack = new Stack (); // loop around a backtrack stack, to handle complex * matching do { @@ -1424,7 +1423,7 @@ public class FilenameUtils { } final char[] array = text.toCharArray(); - final ArrayList list = new ArrayList<>(); + final ArrayList list = new ArrayList (); final StringBuilder buffer = new StringBuilder(); char prevChar = 0; for (final char ch : array) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/HexDump.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/HexDump.java index 10b91a492..a83ed7d84 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/HexDump.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/HexDump.java @@ -28,6 +28,7 @@ import java.nio.charset.Charset; * * Origin of code: POI. * + * @version $Id: HexDump.java 1471767 2013-04-24 23:24:19Z sebb $ */ public class HexDump { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOCase.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOCase.java index e89f02c4c..1290a5e9a 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOCase.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOCase.java @@ -31,6 +31,7 @@ import java.io.Serializable; * Wherever possible, you should use the
check
methods in this * class to compare filenames. * + * @version $Id: IOCase.java 1483915 2013-05-17 17:02:35Z sebb $ * @since 1.3 */ public enum IOCase implements Serializable { @@ -54,7 +55,7 @@ public enum IOCase implements Serializable { * Unix file separator and case-insensitive if they use the Windows file separator * (see {@link java.io.File#separatorChar}). *- * If you serialize this constant on Windows, and deserialize on Unix, or vice + * If you derialize this constant of Windows, and deserialize on Unix, or vice * versa, then the value of the case-sensitivity flag will change. */ SYSTEM ("System", !FilenameUtils.isSystemWindows()); @@ -77,7 +78,7 @@ public enum IOCase implements Serializable { * @throws IllegalArgumentException if the name is invalid */ public static IOCase forName(final String name) { - for (final IOCase ioCase : IOCase.values()) + for (IOCase ioCase : IOCase.values()) { if (ioCase.getName().equals(name)) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOExceptionWithCause.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOExceptionWithCause.java index a6341bdd3..19e04c627 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOExceptionWithCause.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/IOExceptionWithCause.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,7 +21,8 @@ import java.io.IOException; /** * Subclasses IOException with the {@link Throwable} constructors missing before Java 6. - * + * + * @version $Id: IOExceptionWithCause.java 1643107 2014-12-03 13:05:23Z sebb $ * @since 1.4 * @deprecated (since 2.5) use {@link IOException} instead */ @@ -39,7 +40,7 @@ public class IOExceptionWithCause extends IOException { * As specified in {@link Throwable}, the message in the given
- * + * * @param message * the message (see {@link #getMessage()}) * @param cause @@ -55,7 +56,7 @@ public class IOExceptionWithCause extends IOException { * The message is set tocause
is not used in this instance's * message. *cause==null ? null : cause.toString()
, which by default contains the class * and message ofcause
. This constructor is useful for call sites that just wrap another throwable. ** This class provides static utility methods for input/output operations. *
- *
- [Deprecated] closeQuietly - these methods close a stream ignoring nulls and exceptions + *
- closeQuietly - these methods close a stream ignoring nulls and exceptions *
- toXxx/read - these methods read data from a stream *
- write - these methods write data to a stream *
- copy - these methods copy all the data from one stream to another @@ -95,6 +95,7 @@ import com.fr.third.org.apache.commons.io.output.StringBuilderWriter; *
* Origin of code: Excalibur. * + * @version $Id: IOUtils.java 1722156 2015-12-29 15:40:07Z ggregory $ */ public class IOUtils { // NOTE: This class is focused on InputStream, OutputStream, Reader and @@ -134,11 +135,11 @@ public class IOUtils { static { // avoid security issues - try (final StringBuilderWriter buf = new StringBuilderWriter(4); - final PrintWriter out = new PrintWriter(buf)) { - out.println(); - LINE_SEPARATOR = buf.toString(); - } + final StringBuilderWriter buf = new StringBuilderWriter(4); + final PrintWriter out = new PrintWriter(buf); + out.println(); + LINE_SEPARATOR = buf.toString(); + out.close(); } /** @@ -211,12 +212,7 @@ public class IOUtils { *
- * It is expected the given name
to be absolute. The
- * behavior is not well-defined otherwise.
- *
- * It is expected the given name
to be absolute. The
- * behavior is not well-defined otherwise.
- *
- * It is expected the given name
to be absolute. The
- * behavior is not well-defined otherwise.
- *
- * It is expected the given name
to be absolute. The
- * behavior is not well-defined otherwise.
- *
- * It is expected the given name
to be absolute. The
- * behavior is not well-defined otherwise.
- *
- * It is expected the given name
to be absolute. The
- * behavior is not well-defined otherwise.
- *
Reader
quietly.
* This method is useful if you only want to process the first few
* lines of a larger file. If you do not close the iterator
- * then the {@code Reader} remains open.
+ * then the Reader
remains open.
* This method can safely be called multiple times.
- *
- * @throws IOException if closing the underlying {@code Reader} fails.
*/
- @Override
- public void close() throws IOException {
+ public void close() {
finished = true;
+ IOUtils.closeQuietly(bufferedReader);
cachedLine = null;
- if (this.bufferedReader != null) {
- this.bufferedReader.close();
- }
}
/**
@@ -172,28 +161,19 @@ public class LineIterator implements Iteratorinterrupt()
* the monitor thread.
*
- *
+ *
* * long timeoutInMillis = 1000; * try { @@ -36,6 +36,7 @@ package com.fr.third.org.apache.commons.io; * } ** + * @version $Id: ThreadMonitor.java 1718945 2015-12-09 19:51:14Z krosenvold $ */ class ThreadMonitor implements Runnable { @@ -102,7 +103,6 @@ class ThreadMonitor implements Runnable { * * @see Runnable#run() */ - @Override public void run() { try { sleep(timeout); @@ -117,12 +117,12 @@ class ThreadMonitor implements Runnable { * * This method exists because Thread.sleep(100) can sleep for 0, 70, 100 or 200ms or anything else * it deems appropriate. Read the docs on Thread.sleep for further interesting details. - * + * @ * @param ms the number of milliseconds to sleep for * @throws InterruptedException if interrupted */ - private static void sleep(final long ms) throws InterruptedException { - final long finishAt = System.currentTimeMillis() + ms; + private static void sleep(long ms) throws InterruptedException { + long finishAt = System.currentTimeMillis() + ms; long remaining = ms; do { Thread.sleep(remaining); diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/AbstractFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/AbstractFileComparator.java index ee5e03def..d7dbbf02e 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/AbstractFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/AbstractFileComparator.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,6 +25,7 @@ import java.util.List; /** * Abstract file {@link Comparator} which provides sorting for file arrays and lists. * + * @version $Id: AbstractFileComparator.java 1415850 2012-11-30 20:51:39Z ggregory $ * @since 2.0 */ abstract class AbstractFileComparator implements Comparator
* + * @version $Id: DefaultFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.4 */ public class DefaultFileComparator extends AbstractFileComparator implements Serializable { @@ -55,13 +56,12 @@ public class DefaultFileComparator extends AbstractFileComparator implements Ser /** * Compare the two files using the {@link File#compareTo(File)} method. - * + * * @param file1 The first file to compare * @param file2 The second file to compare * @return the result of calling file1's * {@link File#compareTo(File)} with file2 as the parameter. */ - @Override public int compare(final File file1, final File file2) { return file1.compareTo(file2); } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DirectoryFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DirectoryFileComparator.java index 2ba75bfe5..4ceaa8698 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DirectoryFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DirectoryFileComparator.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -40,6 +40,7 @@ import java.util.Comparator; * *
* + * @version $Id: DirectoryFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 2.0 */ public class DirectoryFileComparator extends AbstractFileComparator implements Serializable { @@ -54,13 +55,12 @@ public class DirectoryFileComparator extends AbstractFileComparator implements S /** * Compare the two files using the {@link File#isDirectory()} method. - * + * * @param file1 The first file to compare * @param file2 The second file to compare * @return the result of calling file1's * {@link File#compareTo(File)} with file2 as the parameter. */ - @Override public int compare(final File file1, final File file2) { return getType(file1) - getType(file2); } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ExtensionFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ExtensionFileComparator.java index 8c9301f0a..e8cec236c 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ExtensionFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ExtensionFileComparator.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,8 +20,6 @@ import java.io.File; import java.io.Serializable; import java.util.Comparator; -import com.fr.third.org.apache.commons.io.FilenameUtils; -import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.third.org.apache.commons.io.IOCase; @@ -50,6 +48,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * *
* + * @version $Id: ExtensionFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.4 */ public class ExtensionFileComparator extends AbstractFileComparator implements Serializable { @@ -97,16 +96,15 @@ public class ExtensionFileComparator extends AbstractFileComparator implements S /** * Compare the extensions of two files the specified case sensitivity. - * + * * @param file1 The first file to compare * @param file2 The second file to compare * @return a negative value if the first file's extension * is less than the second, zero if the extensions are the * same and a positive value if the first files extension * is greater than the second file. - * + * */ - @Override public int compare(final File file1, final File file2) { final String suffix1 = FilenameUtils.getExtension(file1.getName()); final String suffix2 = FilenameUtils.getExtension(file2.getName()); diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/LastModifiedFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/LastModifiedFileComparator.java index e21cf790f..fb9185727 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/LastModifiedFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/LastModifiedFileComparator.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,7 +21,7 @@ import java.io.Serializable; import java.util.Comparator; /** - * Compare the last modified date/time of two files for order + * Compare the last modified date/time of two files for order * (see {@link File#lastModified()}). *
* This comparator can be used to sort lists or arrays of files @@ -42,6 +42,7 @@ import java.util.Comparator; * *
* + * @version $Id: LastModifiedFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.4 */ public class LastModifiedFileComparator extends AbstractFileComparator implements Serializable { @@ -56,16 +57,15 @@ public class LastModifiedFileComparator extends AbstractFileComparator implement /** * Compare the last the last modified date/time of two files. - * + * * @param file1 The first file to compare * @param file2 The second file to compare * @return a negative value if the first file's lastmodified date/time * is less than the second, zero if the lastmodified date/time are the * same and a positive value if the first files lastmodified date/time * is greater than the second file. - * + * */ - @Override public int compare(final File file1, final File file2) { final long result = file1.lastModified() - file2.lastModified(); if (result < 0) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/NameFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/NameFileComparator.java index 3c764808a..76cfff0b5 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/NameFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/NameFileComparator.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +20,6 @@ import java.io.File; import java.io.Serializable; import java.util.Comparator; -import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase; /** @@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * *
* + * @version $Id: NameFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.4 */ public class NameFileComparator extends AbstractFileComparator implements Serializable { @@ -92,7 +92,7 @@ public class NameFileComparator extends AbstractFileComparator implements Serial /** * Compare the names of two files with the specified case sensitivity. - * + * * @param file1 The first file to compare * @param file2 The second file to compare * @return a negative value if the first file's name @@ -100,7 +100,6 @@ public class NameFileComparator extends AbstractFileComparator implements Serial * same and a positive value if the first files name * is greater than the second file. */ - @Override public int compare(final File file1, final File file2) { return caseSensitivity.checkCompareTo(file1.getName(), file2.getName()); } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/PathFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/PathFileComparator.java index 21a571178..cf0aa0063 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/PathFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/PathFileComparator.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +20,6 @@ import java.io.File; import java.io.Serializable; import java.util.Comparator; -import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase; /** @@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * *
*
+ * @version $Id: PathFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class PathFileComparator extends AbstractFileComparator implements Serializable {
@@ -92,16 +92,15 @@ public class PathFileComparator extends AbstractFileComparator implements Serial
/**
* Compare the paths of two files the specified case sensitivity.
- *
+ *
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return a negative value if the first file's path
* is less than the second, zero if the paths are the
* same and a positive value if the first files path
* is greater than the second file.
- *
+ *
*/
- @Override
public int compare(final File file1, final File file2) {
return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath());
}
diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ReverseComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ReverseComparator.java
index 0703199e9..b41e7a124 100644
--- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ReverseComparator.java
+++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ReverseComparator.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,6 +24,7 @@ import java.util.Comparator;
* Reverses the result of comparing two objects using
* the delegate {@link Comparator}.
*
+ * @version $Id: ReverseComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
class ReverseComparator extends AbstractFileComparator implements Serializable {
@@ -32,7 +33,7 @@ class ReverseComparator extends AbstractFileComparator implements Serializable {
private final Comparator
...alternatively you can do this in one line:
+ sumDirectoryContents
is {@code true}.
*
+ * @version $Id: SizeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class SizeFileComparator extends AbstractFileComparator implements Serializable {
@@ -88,7 +88,7 @@ public class SizeFileComparator extends AbstractFileComparator implements Serial
* If the sumDirectoryContents
is {@code true} The size of
* directories is calculated using {@link FileUtils#sizeOfDirectory(File)}.
*
- * @param sumDirectoryContents {@code true} if the sum of the directories' contents
+ * @param sumDirectoryContents {@code true} if the sum of the directoryies contents
* should be calculated, otherwise {@code false} if directories should be treated
* as size zero (see {@link FileUtils#sizeOfDirectory(File)}).
*/
@@ -98,16 +98,15 @@ public class SizeFileComparator extends AbstractFileComparator implements Serial
/**
* Compare the length of two files.
- *
+ *
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return a negative value if the first file's length
* is less than the second, zero if the lengths are the
* same and a positive value if the first files length
* is greater than the second file.
- *
+ *
*/
- @Override
public int compare(final File file1, final File file2) {
long size1 = 0;
if (file1.isDirectory()) {
diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/package.html b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/package.html
index fa66bb0f3..d0071583e 100644
--- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/package.html
+++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/package.html
@@ -35,9 +35,11 @@ for {@link java.io.File}s.
- File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
-
+
+ File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
+
+
@@ -48,137 +50,139 @@ for {@link java.io.File}s. For example, to sort an array of files by type (i.e. directory or file) and then by name:
-- CompositeFileComparator comparator = - new CompositeFileComparator( - DirectoryFileComparator.DIRECTORY_COMPARATOR, - NameFileComparator.NAME_COMPARATOR); - File[] files = dir.listFiles(); - comparator.sort(files); -+
+
+ CompositeFileComparator comparator = + new CompositeFileComparator( + DirectoryFileComparator.DIRECTORY_COMPARATOR, + NameFileComparator.NAME_COMPARATOR); + File[] files = dir.listFiles(); + comparator.sort(files); ++
The {@link java.util.Comparator} implementations have some convenience singleton(thread-safe) instances ready to use: +
File.compareTo(File)
method.
+ File.compareTo(File)
method.
+ File.isDirectory()
method (directories < files).
+ File.isDirectory()
method (directories > files).
+ FilenameUtils.getExtension(String)
method.
+ FilenameUtils.getExtension(String)
method.
+ FilenameUtils.getExtension(String)
method.
+ FilenameUtils.getExtension(String)
method.
+ FilenameUtils.getExtension(String)
method.
+ FilenameUtils.getExtension(String)
method.
+ File.lastModified()
method.
+ File.lastModified()
method.
+ File.getName()
method.
+ File.getName()
method.
+ File.getName()
method.
+ File.getName()
method.
+ File.getName()
method.
+ File.getName()
method.
+ File.getPath()
method.
+ File.getPath()
method.
+ File.getPath()
method.
+ File.getPath()
method.
+ File.getPath()
method.
+ File.getPath()
method.
+ File.length()
method (directories treated as zero length).
+ File.length()
method (directories treated as zero length).
+ FileUtils.sizeOfDirectory(File)
method
+ (sums the size of a directory's contents).
+ FileUtils.sizeOfDirectory(File)
method
+ (sums the size of a directory's contents).
+ File.compareTo(File)
method.
- File.compareTo(File)
method.
- File.isDirectory()
method (directories < files).
- File.isDirectory()
method (directories >files).
- FilenameUtils.getExtension(String)
method.
- FilenameUtils.getExtension(String)
method.
- FilenameUtils.getExtension(String)
method.
- FilenameUtils.getExtension(String)
method.
- FilenameUtils.getExtension(String)
method.
- FilenameUtils.getExtension(String)
method.
- File.lastModified()
method.
- File.lastModified()
method.
- File.getName()
method.
- File.getName()
method.
- File.getName()
method.
- File.getName()
method.
- File.getName()
method.
- File.getName()
method.
- File.getPath()
method.
- File.getPath()
method.
- File.getPath()
method.
- File.getPath()
method.
- File.getPath()
method.
- File.getPath()
method.
- File.length()
method (directories treated as zero length).
- File.length()
method (directories treated as zero length).
- FileUtils.sizeOfDirectory(File)
method
- (sums the size of a directory's contents).
- FileUtils.sizeOfDirectory(File)
method
- (sums the size of a directory's contents).
-