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: - * - * - * @param value - * the {@code String} containing the ByteOrder representation to be parsed - * @return the ByteOrder represented by the string argument - * @throws IllegalArgumentException - * if the {@code String} containing the ByteOrder representation to be parsed is unknown. - */ - public static ByteOrder parseByteOrder(final String value) { - if (ByteOrder.BIG_ENDIAN.toString().equals(value)) { - return ByteOrder.BIG_ENDIAN; - } - if (ByteOrder.LITTLE_ENDIAN.toString().equals(value)) { - return ByteOrder.LITTLE_ENDIAN; - } - throw new IllegalArgumentException("Unsupported byte order setting: " + value + ", expeced one of " + ByteOrder.LITTLE_ENDIAN + - ", " + ByteOrder.BIG_ENDIAN); - } - -} diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/Charsets.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/Charsets.java index f9f427a70..2fcd52576 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/Charsets.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/Charsets.java @@ -1,192 +1,192 @@ -/* - * 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.nio.charset.StandardCharsets; -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. - *

- * - * - * - * @see Standard charsets - * @since 2.3 - * @version $Id$ - */ -public class Charsets { - // - // This class should only contain Charset instances for required encodings. This guarantees that it will load - // correctly and without delay on all Java platforms. - // - - /** - * Constructs a sorted map from canonical charset names to charset objects required of every implementation of the - * Java platform. - *

- * 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 requiredCharsets() { - // maybe cache? - final TreeMap m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - m.put(StandardCharsets.ISO_8859_1.name(), StandardCharsets.ISO_8859_1); - m.put(StandardCharsets.US_ASCII.name(), StandardCharsets.US_ASCII); - m.put(StandardCharsets.UTF_16.name(), StandardCharsets.UTF_16); - m.put(StandardCharsets.UTF_16BE.name(), StandardCharsets.UTF_16BE); - m.put(StandardCharsets.UTF_16LE.name(), StandardCharsets.UTF_16LE); - m.put(StandardCharsets.UTF_8.name(), StandardCharsets.UTF_8); - return Collections.unmodifiableSortedMap(m); - } - - /** - * Returns the given Charset or the default Charset if the given Charset is null. - * - * @param charset - * A charset or null. - * @return the given Charset or the default Charset if the given Charset is null - */ - public static Charset toCharset(final Charset charset) { - return charset == null ? Charset.defaultCharset() : charset; - } - - /** - * Returns a Charset for the named charset. If the name is null, return the default Charset. - * - * @param charset - * The name of the requested charset, may be null. - * @return a Charset for the named charset - * @throws java.nio.charset.UnsupportedCharsetException - * If the named charset is unavailable - */ - public static Charset toCharset(final String charset) { - return charset == null ? Charset.defaultCharset() : Charset.forName(charset); - } - - /** - * CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1. - *

- * 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. + *

+ * + * + * + * @see Standard charsets + * @since 2.3 + * @version $Id: Charsets.java 1686747 2015-06-21 18:44:49Z krosenvold $ + */ +public class Charsets { + // + // This class should only contain Charset instances for required encodings. This guarantees that it will load + // correctly and without delay on all Java platforms. + // + + /** + * Constructs a sorted map from canonical charset names to charset objects required of every implementation of the + * Java platform. + *

+ * 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 requiredCharsets() { + // maybe cache? + // TODO Re-implement on Java 7 to use java.nio.charset.StandardCharsets + final TreeMap m = new TreeMap(String.CASE_INSENSITIVE_ORDER); + m.put(ISO_8859_1.name(), ISO_8859_1); + m.put(US_ASCII.name(), US_ASCII); + m.put(UTF_16.name(), UTF_16); + m.put(UTF_16BE.name(), UTF_16BE); + m.put(UTF_16LE.name(), UTF_16LE); + m.put(UTF_8.name(), UTF_8); + return Collections.unmodifiableSortedMap(m); + } + + /** + * Returns the given Charset or the default Charset if the given Charset is null. + * + * @param charset + * A charset or null. + * @return the given Charset or the default Charset if the given Charset is null + */ + public static Charset toCharset(final Charset charset) { + return charset == null ? Charset.defaultCharset() : charset; + } + + /** + * Returns a Charset for the named charset. If the name is null, return the default Charset. + * + * @param charset + * The name of the requested charset, may be null. + * @return a Charset for the named charset + * @throws java.nio.charset.UnsupportedCharsetException + * If the named charset is unavailable + */ + public static Charset toCharset(final String charset) { + return charset == null ? Charset.defaultCharset() : Charset.forName(charset); + } + + /** + * CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1. + *

+ * 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: *

    - *
  • 3.1 External / Multi-threaded - cancellation being + *
  • 3.1 External / Mult-threaded - cancellation being * decided/initiated by an external process.
  • *
  • 3.2 Internal - cancellation being decided/initiated * from within a DirectoryWalker implementation.
  • @@ -246,7 +246,7 @@ import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter; * * * @since 1.3 - * @version $Id$ + * @version $Id: DirectoryWalker.java 1723627 2016-01-07 21:15:47Z niallp $ */ public abstract class DirectoryWalker { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/EndianUtils.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/EndianUtils.java index b415bc74c..b12ab0139 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/EndianUtils.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/EndianUtils.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. @@ -16,7 +16,7 @@ */ package com.fr.third.org.apache.commons.io; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; +import com.fr.third.org.apache.commons.io.input.SwappedDataInputStream; import java.io.EOFException; import java.io.IOException; @@ -35,7 +35,8 @@ import java.io.OutputStream; *

    * 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 q = new ReferenceQueue<>(); + ReferenceQueue q = new ReferenceQueue(); /** * Collection of Tracker instances in existence. */ @@ -82,7 +83,7 @@ public class FileCleaningTracker { /** * 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 @@ -112,7 +113,7 @@ public class FileCleaningTracker { /** * 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 @@ -175,7 +176,7 @@ public class FileCleaningTracker { * 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 diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileDeleteStrategy.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileDeleteStrategy.java index 312a5ee6d..995336aff 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileDeleteStrategy.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileDeleteStrategy.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. @@ -28,6 +28,7 @@ import java.io.IOException; *

    * This class captures the strategy to use and is designed for user subclassing. * + * @version $Id: FileDeleteStrategy.java 1563227 2014-01-31 19:45:30Z ggregory $ * @since 1.3 */ public class FileDeleteStrategy { @@ -106,7 +107,7 @@ public class FileDeleteStrategy { * This implementation uses {@link File#delete()}. * * @param fileToDelete the file to delete, exists, not null - * @return true if the file was deleted + * @return true if the file was deleteds * @throws NullPointerException if the file is null * @throws IOException if an error occurs during file deletion */ diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileExistsException.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileExistsException.java index b89275a8a..e2f3ab1b5 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileExistsException.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileExistsException.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; /** * Indicates that a file already exists. - * + * + * @version $Id: FileExistsException.java 1415850 2012-11-30 20:51:39Z ggregory $ * @since 2.0 */ public class FileExistsException extends IOException { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileSystemUtils.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileSystemUtils.java index 12f36b541..ad82d95eb 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileSystemUtils.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/FileSystemUtils.java @@ -40,13 +40,9 @@ import java.util.StringTokenizer; *

  • Get the free space on a drive * * + * @version $Id: FileSystemUtils.java 1686747 2015-06-21 18:44:49Z krosenvold $ * @since 1.1 - * @deprecated As of 2.6 deprecated without replacement. Use equivalent - * methods in {@link java.nio.file.FileStore} instead, e.g. - * 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.
          * 
          * 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.
          * 

    * 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.
          * 

    * 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 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 Collection listFiles( 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 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 Stack backtrack = 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 cause is not used in this instance's * message. *

    - * + * * @param message * the message (see {@link #getMessage()}) * @param cause @@ -55,7 +56,7 @@ public class IOExceptionWithCause extends IOException { * The message is set to cause==null ? null : cause.toString(), which by default contains the class * and message of cause. This constructor is useful for call sites that just wrap another throwable. *

    - * + * * @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; *

    * 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 { *

  • * * @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 { *
    * * @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 { *
    * * @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 { *
    * * @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. - * - *

    - * It is expected the given name to be absolute. The - * behavior is not well-defined otherwise. - *

    - * - * @param name name of the desired resource - * @param encoding the encoding to use, null means platform default - * @return the requested String - * @throws IOException if an I/O error occurs - * - * @since 2.6 - */ - public static String resourceToString(final String name, final Charset encoding) throws IOException { - return resourceToString(name, encoding, null); - } - - /** - * Gets the contents of a classpath resource as a String using the - * specified character encoding. - * - *

    - * It is expected the given name to be absolute. The - * behavior is not well-defined otherwise. - *

    - * - * @param name name of the desired resource - * @param encoding the encoding to use, null means platform default - * @param classLoader the class loader that the resolution of the resource is delegated to - * @return the requested String - * @throws IOException if an I/O error occurs - * - * @since 2.6 - */ - public static String resourceToString(final String name, final Charset encoding, final ClassLoader classLoader) throws IOException { - return toString(resourceToURL(name, classLoader), encoding); - } - - /** - * Gets the contents of a classpath resource as a byte array. - * - *

    - * It is expected the given name to be absolute. The - * behavior is not well-defined otherwise. - *

    - * - * @param name name of the desired resource - * @return the requested byte array - * @throws IOException if an I/O error occurs - * - * @since 2.6 - */ - public static byte[] resourceToByteArray(final String name) throws IOException { - return resourceToByteArray(name, null); - } - - /** - * Gets the contents of a classpath resource as a byte array. - * - *

    - * It is expected the given name to be absolute. The - * behavior is not well-defined otherwise. - *

    - * - * @param name name of the desired resource - * @param classLoader the class loader that the resolution of the resource is delegated to - * @return the requested byte array - * @throws IOException if an I/O error occurs - * - * @since 2.6 - */ - public static byte[] resourceToByteArray(final String name, final ClassLoader classLoader) throws IOException { - return toByteArray(resourceToURL(name, classLoader)); - } - - /** - * Gets a URL pointing to the given classpath resource. - * - *

    - * It is expected the given name to be absolute. The - * behavior is not well-defined otherwise. - *

    - * - * @param name name of the desired resource - * @return the requested URL - * @throws IOException if an I/O error occurs - * - * @since 2.6 - */ - public static URL resourceToURL(final String name) throws IOException { - return resourceToURL(name, null); - } - - /** - * Gets a URL pointing to the given classpath resource. - * - *

    - * It is expected the given name to be absolute. The - * behavior is not well-defined otherwise. - *

    - * - * @param name name of the desired resource - * @param classLoader the class loader that the resolution of the resource is delegated to - * @return the requested URL - * @throws IOException if an I/O error occurs - * - * @since 2.6 - */ - public static URL resourceToURL(final String name, final ClassLoader classLoader) throws IOException { - // What about the thread context class loader? - // What about the system class loader? - final URL resource = classLoader == null ? IOUtils.class.getResource(name) : classLoader.getResource(name); - - if (resource == null) { - throw new IOException("Resource not found: " + name); - } - - return resource; - } - // readLines //----------------------------------------------------------------------- @@ -1455,7 +1287,7 @@ public class IOUtils { */ public static List readLines(final Reader input) throws IOException { final BufferedReader reader = toBufferedReader(input); - final List list = new ArrayList<>(); + final List list = new ArrayList(); String line = reader.readLine(); while (line != null) { list.add(line); @@ -1706,7 +1538,7 @@ public class IOUtils { int bytes = data.length; int offset = 0; while (bytes > 0) { - final int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE); + int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE); output.write(data, offset, chunk); bytes -= chunk; offset += chunk; @@ -1813,7 +1645,7 @@ public class IOUtils { int bytes = data.length; int offset = 0; while (bytes > 0) { - final int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE); + int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE); output.write(data, offset, chunk); bytes -= chunk; offset += chunk; diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/Java7Support.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/Java7Support.java new file mode 100644 index 000000000..12a290ec7 --- /dev/null +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/Java7Support.java @@ -0,0 +1,190 @@ +package com.fr.third.org.apache.commons.io; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * Java7 feature detection and reflection based feature access. + *

    + * Taken from maven-shared-utils, only for private usage until we go full java7 + */ +class Java7Support { + + private static final boolean IS_JAVA7; + + private static Method isSymbolicLink; + + private static Method delete; + + private static Method toPath; + + private static Method exists; + + private static Method toFile; + + private static Method readSymlink; + + private static Method createSymlink; + + private static Object emptyLinkOpts; + + private static Object emptyFileAttributes; + + static { + boolean isJava7x = true; + try { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Class files = cl.loadClass("java.nio.file.Files"); + Class path = cl.loadClass("java.nio.file.Path"); + Class fa = cl.loadClass("java.nio.file.attribute.FileAttribute"); + Class linkOption = cl.loadClass("java.nio.file.LinkOption"); + isSymbolicLink = files.getMethod("isSymbolicLink", path); + delete = files.getMethod("delete", path); + readSymlink = files.getMethod("readSymbolicLink", path); + + emptyFileAttributes = Array.newInstance(fa, 0); + createSymlink = files.getMethod("createSymbolicLink", path, path, emptyFileAttributes.getClass()); + emptyLinkOpts = Array.newInstance(linkOption, 0); + exists = files.getMethod("exists", path, emptyLinkOpts.getClass()); + toPath = File.class.getMethod("toPath"); + toFile = path.getMethod("toFile"); + } catch (ClassNotFoundException e) { + isJava7x = false; + } catch (NoSuchMethodException e) { + isJava7x = false; + } + IS_JAVA7 = isJava7x; + } + + /** + * Invokes java7 isSymbolicLink + * @param file The file to check + * @return true if the file is a symbolic link + */ + public static boolean isSymLink(File file) { + try { + Object path = toPath.invoke(file); + Boolean result = (Boolean) isSymbolicLink.invoke(null, path); + return result.booleanValue(); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + /** + * Reads the target of a symbolic link + * @param symlink The symlink to read + * @return The location the symlink is pointing to + * @throws IOException Upon failure + */ + + public static File readSymbolicLink(File symlink) + throws IOException { + try { + Object path = toPath.invoke(symlink); + Object resultPath = readSymlink.invoke(null, path); + return (File) toFile.invoke(resultPath); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + + /** + * Indicates if a symlunk target exists + * @param file The symlink file + * @return true if the target exists + * @throws IOException upon error + */ + private static boolean exists(File file) + throws IOException { + try { + Object path = toPath.invoke(file); + final Boolean result = (Boolean) exists.invoke(null, path, emptyLinkOpts); + return result.booleanValue(); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw (RuntimeException) e.getTargetException(); + } + + } + + /** + * Creates a symbolic link + * @param symlink The symlink to create + * @param target Where it should point + * @return The newly created symlink + * @throws IOException upon error + */ + public static File createSymbolicLink(File symlink, File target) + throws IOException { + try { + if (!exists(symlink)) { + Object link = toPath.invoke(symlink); + Object path = createSymlink.invoke(null, link, toPath.invoke(target), emptyFileAttributes); + return (File) toFile.invoke(path); + } + return symlink; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + final Throwable targetException = e.getTargetException(); + throw (IOException) targetException; + } + + } + + /** + * Performs a nio delete + * + * @param file the file to delete + * @throws IOException Upon error + */ + public static void delete(File file) + throws IOException { + try { + Object path = toPath.invoke(file); + delete.invoke(null, path); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw (IOException) e.getTargetException(); + } + } + + /** + * Indicates if the current vm has java7 lubrary support + * @return true if java7 library support + */ + public static boolean isAtLeastJava7() { + return IS_JAVA7; + } + +} diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/LineIterator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/LineIterator.java index 0162ee76d..53eda99a6 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/LineIterator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/LineIterator.java @@ -17,7 +17,6 @@ package com.fr.third.org.apache.commons.io; import java.io.BufferedReader; -import java.io.Closeable; import java.io.IOException; import java.io.Reader; import java.util.Iterator; @@ -45,9 +44,10 @@ import java.util.NoSuchElementException; * } * * + * @version $Id: LineIterator.java 1471767 2013-04-24 23:24:19Z sebb $ * @since 1.2 */ -public class LineIterator implements Iterator, Closeable { +public class LineIterator implements Iterator { // N.B. This class deliberately does not implement Iterable, see https://issues.apache.org/jira/browse/IO-181 @@ -84,7 +84,6 @@ public class LineIterator implements Iterator, Closeable { * @return {@code true} if the Reader has more lines * @throws IllegalStateException if an IO exception occurs */ - @Override public boolean hasNext() { if (cachedLine != null) { return true; @@ -103,11 +102,7 @@ public class LineIterator implements Iterator, Closeable { } } } catch(final IOException ioe) { - try { - close(); - } catch (final IOException e) { - ioe.addSuppressed(e); - } + close(); throw new IllegalStateException(ioe); } } @@ -129,7 +124,6 @@ public class LineIterator implements Iterator, Closeable { * @return the next line from the input * @throws NoSuchElementException if there is no line to return */ - @Override public String next() { return nextLine(); } @@ -150,21 +144,16 @@ public class LineIterator implements Iterator, Closeable { } /** - * Closes the underlying {@code Reader}. + * Closes the underlying 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 Iterator, Closeable { * * @throws UnsupportedOperationException always */ - @Override public void remove() { throw new UnsupportedOperationException("Remove unsupported on LineIterator"); } //----------------------------------------------------------------------- /** - * Closes a {@code LineIterator} quietly. + * Closes the iterator, handling null and ignoring exceptions. * - * @param iterator The iterator to close, or {@code null}. - * @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) + * @param iterator the iterator to close */ - @Deprecated public static void closeQuietly(final LineIterator iterator) { - try { - if (iterator != null) { - iterator.close(); - } - } catch(final IOException e) { - // Suppressed. + if (iterator != null) { + iterator.close(); } } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/TaggedIOException.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/TaggedIOException.java index 0ebe7a24c..67ada99aa 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/TaggedIOException.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/TaggedIOException.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. @@ -26,7 +26,7 @@ import java.io.Serializable; * * @since 2.0 */ -@SuppressWarnings("deprecation") // needs to extend deprecated IOExceptionWithCause to preserve binary compatibility +@SuppressWarnings("deprecation") // needs to extend deprecated IOExceptionWithCause to preserve binary compatibility public class TaggedIOException extends IOExceptionWithCause { /** diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/ThreadMonitor.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/ThreadMonitor.java index d6c59085a..e9a9d7e1c 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/ThreadMonitor.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/ThreadMonitor.java @@ -24,7 +24,7 @@ package com.fr.third.org.apache.commons.io; * completes its work before being interrupted, it should interrupt() * 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 { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/CompositeFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/CompositeFileComparator.java index e4195de7d..5dbf54339 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/CompositeFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/CompositeFileComparator.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; * comparator.sort(list); * * + * @version $Id: CompositeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 2.0 */ public class CompositeFileComparator extends AbstractFileComparator implements Serializable { @@ -72,7 +73,7 @@ public class CompositeFileComparator extends AbstractFileComparator implements S if (delegates == null) { this.delegates = (Comparator[]) NO_COMPARATORS; //1 } else { - final List> list = new ArrayList<>(); + final List> list = new ArrayList>(); for (final Comparator comparator : delegates) { list.add(comparator); } @@ -82,13 +83,12 @@ public class CompositeFileComparator extends AbstractFileComparator implements S /** * Compare the two files using delegate comparators. - * + * * @param file1 The first file to compare * @param file2 The second file to compare * @return the first non-zero result returned from * the delegate comparators or zero. */ - @Override public int compare(final File file1, final File file2) { int result = 0; for (final Comparator delegate : delegates) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DefaultFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DefaultFileComparator.java index 2162e98da..6c42294f8 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DefaultFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DefaultFileComparator.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. @@ -41,6 +41,7 @@ import java.util.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 delegate; /** - * Construct an instance with the specified delegate {@link Comparator}. + * Construct an instance with the sepecified delegate {@link Comparator}. * * @param delegate The comparator to delegate to */ @@ -45,13 +46,12 @@ class ReverseComparator extends AbstractFileComparator implements Serializable { /** * Compare using the delegate Comparator, but reversing the result. - * + * * @param file1 The first file to compare * @param file2 The second file to compare * @return the result from the delegate {@link Comparator#compare(Object, Object)} * reversing the value (i.e. positive becomes negative and vice versa) */ - @Override public int compare(final File file1, final File file2) { return delegate.compare(file2, file1); // parameters switched round } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/SizeFileComparator.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/SizeFileComparator.java index ee76007fa..ee8f9931d 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/SizeFileComparator.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/SizeFileComparator.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.FileUtils; import com.fr.third.org.apache.commons.io.FileUtils; /** @@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.FileUtils; * N.B. Directories are treated as zero size unless * 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.

    ...alternatively you can do this in one line:

    -
    -      File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
    -
    +

    +

    +        File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
    +  
    +

    Composite Comparator

    @@ -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);
    +  
    +

    Singleton Instances (thread-safe)

    The {@link java.util.Comparator} implementations have some convenience singleton(thread-safe) instances ready to use: +

    - diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AbstractFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AbstractFileFilter.java index 381dd1a9a..8ff11a265 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AbstractFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AbstractFileFilter.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. @@ -19,44 +19,42 @@ package com.fr.third.org.apache.commons.io.filefilter; import java.io.File; /** - * An abstract class which implements the Java FileFilter and FilenameFilter + * An abstract class which implements the Java FileFilter and FilenameFilter * interfaces via the IOFileFilter interface. *

    * Note that a subclass must override one of the accept methods, * otherwise your class will infinitely loop. * * @since 1.0 - * @version $Id$ + * @version $Id: AbstractFileFilter.java 1415850 2012-11-30 20:51:39Z ggregory $ */ public abstract class AbstractFileFilter implements IOFileFilter { /** * Checks to see if the File should be accepted by this filter. - * + * * @param file the File to check * @return true if this file matches the test */ - @Override public boolean accept(final File file) { return accept(file.getParentFile(), file.getName()); } /** * Checks to see if the File should be accepted by this filter. - * + * * @param dir the directory File to check * @param name the filename within the directory to check * @return true if this file matches the test */ - @Override public boolean accept(final File dir, final String name) { return accept(new File(dir, name)); } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AgeFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AgeFileFilter.java index b3043c73d..3793f0ba8 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AgeFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AgeFileFilter.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.Date; -import com.fr.third.org.apache.commons.io.FileUtils; import com.fr.third.org.apache.commons.io.FileUtils; /** @@ -40,6 +39,7 @@ import com.fr.third.org.apache.commons.io.FileUtils; * } * * + * @version $Id: AgeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @see FileFilterUtils#ageFileFilter(Date) * @see FileFilterUtils#ageFileFilter(File) * @see FileFilterUtils#ageFileFilter(long) @@ -107,7 +107,7 @@ public class AgeFileFilter extends AbstractFileFilter implements Serializable { * a certain File (whose last modification time will be used as reference). * * @param cutoffReference the file whose last modification - * time is used as the threshold age of the files + * time is usesd as the threshold age of the files */ public AgeFileFilter(final File cutoffReference) { this(cutoffReference, true); @@ -119,7 +119,7 @@ public class AgeFileFilter extends AbstractFileFilter implements Serializable { * reference). * * @param cutoffReference the file whose last modification - * time is used as the threshold age of the files + * time is usesd as the threshold age of the files * @param acceptOlder if true, older files (at or before the cutoff) * are accepted, else newer ones (after the cutoff). */ @@ -147,9 +147,9 @@ public class AgeFileFilter extends AbstractFileFilter implements Serializable { } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AndFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AndFileFilter.java index 5c70d0860..376d8818e 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AndFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AndFileFilter.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. @@ -30,7 +30,7 @@ import java.util.List; * {@code false}. * * @since 1.0 - * @version $Id$ + * @version $Id: AndFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * * @see FileFilterUtils#and(IOFileFilter...) */ @@ -49,7 +49,7 @@ public class AndFileFilter * @since 1.1 */ public AndFileFilter() { - this.fileFilters = new ArrayList<>(); + this.fileFilters = new ArrayList(); } /** @@ -61,9 +61,9 @@ public class AndFileFilter */ public AndFileFilter(final List fileFilters) { if (fileFilters == null) { - this.fileFilters = new ArrayList<>(); + this.fileFilters = new ArrayList(); } else { - this.fileFilters = new ArrayList<>(fileFilters); + this.fileFilters = new ArrayList(fileFilters); } } @@ -78,7 +78,7 @@ public class AndFileFilter if (filter1 == null || filter2 == null) { throw new IllegalArgumentException("The filters must not be null"); } - this.fileFilters = new ArrayList<>(2); + this.fileFilters = new ArrayList(2); addFileFilter(filter1); addFileFilter(filter2); } @@ -86,7 +86,6 @@ public class AndFileFilter /** * {@inheritDoc} */ - @Override public void addFileFilter(final IOFileFilter ioFileFilter) { this.fileFilters.add(ioFileFilter); } @@ -94,7 +93,6 @@ public class AndFileFilter /** * {@inheritDoc} */ - @Override public List getFileFilters() { return Collections.unmodifiableList(this.fileFilters); } @@ -102,7 +100,6 @@ public class AndFileFilter /** * {@inheritDoc} */ - @Override public boolean removeFileFilter(final IOFileFilter ioFileFilter) { return this.fileFilters.remove(ioFileFilter); } @@ -110,7 +107,6 @@ public class AndFileFilter /** * {@inheritDoc} */ - @Override public void setFileFilters(final List fileFilters) { this.fileFilters.clear(); this.fileFilters.addAll(fileFilters); @@ -149,9 +145,9 @@ public class AndFileFilter } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanReadFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanReadFileFilter.java index 38e63431b..417db0c2a 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanReadFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanReadFileFilter.java @@ -58,7 +58,7 @@ import java.io.Serializable; * * * @since 1.3 - * @version $Id$ + * @version $Id: CanReadFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ */ public class CanReadFileFilter extends AbstractFileFilter implements Serializable { @@ -75,7 +75,7 @@ public class CanReadFileFilter extends AbstractFileFilter implements Serializabl CanWriteFileFilter.CANNOT_WRITE); /** - * Restrictive constructor. + * Restrictive consructor. */ protected CanReadFileFilter() { } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanWriteFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanWriteFileFilter.java index 8985ff247..092f7a4ca 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanWriteFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanWriteFileFilter.java @@ -50,7 +50,7 @@ import java.io.Serializable; * CanReadFileFilter.READ_ONLY. * * @since 1.3 - * @version $Id$ + * @version $Id: CanWriteFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ */ public class CanWriteFileFilter extends AbstractFileFilter implements Serializable { @@ -63,7 +63,7 @@ public class CanWriteFileFilter extends AbstractFileFilter implements Serializab public static final IOFileFilter CANNOT_WRITE = new NotFileFilter(CAN_WRITE); /** - * Restrictive constructor. + * Restrictive consructor. */ protected CanWriteFileFilter() { } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/ConditionalFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/ConditionalFileFilter.java index 5cd3c2f29..e549c63b5 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/ConditionalFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/ConditionalFileFilter.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. @@ -22,7 +22,7 @@ import java.util.List; * Defines operations for conditional file filters. * * @since 1.1 - * @version $Id$ + * @version $Id: ConditionalFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $ */ public interface ConditionalFileFilter { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DelegateFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DelegateFileFilter.java index ed18fba73..a7284db78 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DelegateFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DelegateFileFilter.java @@ -25,7 +25,7 @@ import java.io.Serializable; * This class turns a Java FileFilter or FilenameFilter into an IO FileFilter. * * @since 1.0 - * @version $Id$ + * @version $Id: DelegateFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * * @see FileFilterUtils#asFileFilter(FileFilter) * @see FileFilterUtils#asFileFilter(FilenameFilter) @@ -96,9 +96,9 @@ public class DelegateFileFilter extends AbstractFileFilter implements Serializab } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DirectoryFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DirectoryFileFilter.java index caf59c742..a051764db 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DirectoryFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DirectoryFileFilter.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. @@ -22,7 +22,7 @@ import java.io.Serializable; /** * This filter accepts Files that are directories. *

    - * For example, here is how to print out a list of the + * For example, here is how to print out a list of the * current directory's subdirectories: * *

    @@ -34,7 +34,7 @@ import java.io.Serializable;
      * 
    * * @since 1.0 - * @version $Id$ + * @version $Id: DirectoryFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * * @see FileFilterUtils#directoryFileFilter() */ @@ -55,7 +55,7 @@ public class DirectoryFileFilter extends AbstractFileFilter implements Serializa public static final IOFileFilter INSTANCE = DIRECTORY; /** - * Restrictive constructor. + * Restrictive consructor. */ protected DirectoryFileFilter() { } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/EmptyFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/EmptyFileFilter.java index 5af014e2d..ff677bd7d 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/EmptyFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/EmptyFileFilter.java @@ -49,7 +49,7 @@ import java.io.Serializable; * * * @since 1.3 - * @version $Id$ + * @version $Id: EmptyFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ */ public class EmptyFileFilter extends AbstractFileFilter implements Serializable { @@ -62,7 +62,7 @@ public class EmptyFileFilter extends AbstractFileFilter implements Serializable public static final IOFileFilter NOT_EMPTY = new NotFileFilter(EMPTY); /** - * Restrictive constructor. + * Restrictive consructor. */ protected EmptyFileFilter() { } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FalseFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FalseFileFilter.java index a6ea20ed9..1cecceb33 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FalseFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FalseFileFilter.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. @@ -23,7 +23,7 @@ import java.io.Serializable; * A file filter that always returns false. * * @since 1.0 - * @version $Id$ + * @version $Id: FalseFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * * @see FileFilterUtils#falseFileFilter() */ @@ -44,7 +44,7 @@ public class FalseFileFilter implements IOFileFilter, Serializable { public static final IOFileFilter INSTANCE = FALSE; /** - * Restrictive constructor. + * Restrictive consructor. */ protected FalseFileFilter() { } @@ -55,7 +55,6 @@ public class FalseFileFilter implements IOFileFilter, Serializable { * @param file the file to check (ignored) * @return false */ - @Override public boolean accept(final File file) { return false; } @@ -67,7 +66,6 @@ public class FalseFileFilter implements IOFileFilter, Serializable { * @param name the filename (ignored) * @return false */ - @Override public boolean accept(final File dir, final String name) { return false; } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFileFilter.java index 37fac1690..19e0b2ce8 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFileFilter.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. @@ -34,7 +34,7 @@ import java.io.Serializable; * * * @since 1.3 - * @version $Id$ + * @version $Id: FileFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @see FileFilterUtils#fileFileFilter() */ public class FileFileFilter extends AbstractFileFilter implements Serializable { @@ -44,7 +44,7 @@ public class FileFileFilter extends AbstractFileFilter implements Serializable { public static final IOFileFilter FILE = new FileFileFilter(); /** - * Restrictive constructor. + * Restrictive consructor. */ protected FileFileFilter() { } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFilterUtils.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFilterUtils.java index 432c95440..47b0af1d9 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFilterUtils.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFilterUtils.java @@ -27,7 +27,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase; /** @@ -36,7 +35,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * every class you use. * * @since 1.0 - * @version $Id$ + * @version $Id: FileFilterUtils.java 1471767 2013-04-24 23:24:19Z sebb $ */ public class FileFilterUtils { @@ -81,7 +80,7 @@ public class FileFilterUtils { if (files == null) { return new File[0]; } - final List acceptedFiles = new ArrayList<>(); + final List acceptedFiles = new ArrayList(); for (final File file : files) { if (file == null) { throw new IllegalArgumentException("file array contains null"); @@ -211,7 +210,7 @@ public class FileFilterUtils { */ public static Set filterSet(final IOFileFilter filter, final File... files) { final File[] acceptedFiles = filter(filter, files); - return new HashSet<>(Arrays.asList(acceptedFiles)); + return new HashSet(Arrays.asList(acceptedFiles)); } /** @@ -450,7 +449,7 @@ public class FileFilterUtils { if (filters == null) { throw new IllegalArgumentException("The filters must not be null"); } - final List list = new ArrayList<>(filters.length); + final List list = new ArrayList(filters.length); for (int i = 0; i < filters.length; i++) { if (filters[i] == null) { throw new IllegalArgumentException("The filter[" + i + "] is null"); @@ -519,8 +518,8 @@ public class FileFilterUtils { //----------------------------------------------------------------------- /** - * Returns a filter that returns true if the file was last modified before - * or at the specified cutoff time. + * Returns a filter that returns true if the file was last modified after + * the specified cutoff time. * * @param cutoff the time threshold * @return an appropriately configured age file filter @@ -545,8 +544,8 @@ public class FileFilterUtils { } /** - * Returns a filter that returns true if the file was last modified before - * or at the specified cutoff date. + * Returns a filter that returns true if the file was last modified after + * the specified cutoff date. * * @param cutoffDate the time threshold * @return an appropriately configured age file filter @@ -571,11 +570,11 @@ public class FileFilterUtils { } /** - * Returns a filter that returns true if the file was last modified before - * or at the same time as the specified reference file. + * Returns a filter that returns true if the file was last modified after + * the specified reference file. * * @param cutoffReference the file whose last modification - * time is used as the threshold age of the files + * time is usesd as the threshold age of the files * @return an appropriately configured age file filter * @see AgeFileFilter * @since 1.2 @@ -588,7 +587,7 @@ public class FileFilterUtils { * Returns a filter that filters files based on a cutoff reference file. * * @param cutoffReference the file whose last modification - * time is used as the threshold age of the files + * time is usesd as the threshold age of the files * @param acceptOlder if true, older files get accepted, if false, newer * @return an appropriately configured age file filter * @see AgeFileFilter diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/HiddenFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/HiddenFileFilter.java index 1d73af3d4..17e6fe76f 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/HiddenFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/HiddenFileFilter.java @@ -46,7 +46,7 @@ import java.io.Serializable; * * * @since 1.3 - * @version $Id$ + * @version $Id: HiddenFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ */ public class HiddenFileFilter extends AbstractFileFilter implements Serializable { @@ -59,7 +59,7 @@ public class HiddenFileFilter extends AbstractFileFilter implements Serializable public static final IOFileFilter VISIBLE = new NotFileFilter(HIDDEN); /** - * Restrictive constructor. + * Restrictive consructor. */ protected HiddenFileFilter() { } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/IOFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/IOFileFilter.java index 96a5090a1..523a89b70 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/IOFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/IOFileFilter.java @@ -25,7 +25,7 @@ import java.io.FilenameFilter; * interfaces together. * * @since 1.0 - * @version $Id$ + * @version $Id: IOFileFilter.java 1471767 2013-04-24 23:24:19Z sebb $ */ public interface IOFileFilter extends FileFilter, FilenameFilter { @@ -37,7 +37,6 @@ public interface IOFileFilter extends FileFilter, FilenameFilter { * @param file the File to check * @return true if this file matches the test */ - @Override boolean accept(File file); /** @@ -49,7 +48,6 @@ public interface IOFileFilter extends FileFilter, FilenameFilter { * @param name the filename within the directory to check * @return true if this file matches the test */ - @Override boolean accept(File dir, String name); } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/MagicNumberFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/MagicNumberFileFilter.java index 540a4da19..2124e2690 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/MagicNumberFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/MagicNumberFileFilter.java @@ -23,6 +23,8 @@ import java.io.Serializable; import java.nio.charset.Charset; import java.util.Arrays; +import com.fr.third.org.apache.commons.io.IOUtils; + /** *

    * File filter for matching files containing a "magic number". A magic number @@ -232,19 +234,20 @@ public class MagicNumberFileFilter extends AbstractFileFilter implements @Override public boolean accept(final File file) { if (file != null && file.isFile() && file.canRead()) { + RandomAccessFile randomAccessFile = null; try { - try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r")) { - final byte[] fileBytes = new byte[this.magicNumbers.length]; - randomAccessFile.seek(byteOffset); - final int read = randomAccessFile.read(fileBytes); - if (read != magicNumbers.length) { - return false; - } - return Arrays.equals(this.magicNumbers, fileBytes); + final byte[] fileBytes = new byte[this.magicNumbers.length]; + randomAccessFile = new RandomAccessFile(file, "r"); + randomAccessFile.seek(byteOffset); + final int read = randomAccessFile.read(fileBytes); + if (read != magicNumbers.length) { + return false; } - } - catch (final IOException ioe) { + return Arrays.equals(this.magicNumbers, fileBytes); + } catch (final IOException ioe) { // Do nothing, fall through and do not accept file + } finally { + IOUtils.closeQuietly(randomAccessFile); } } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NameFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NameFileFilter.java index b5eec57b6..5f327cc86 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NameFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NameFileFilter.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.Serializable; import java.util.List; -import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase; /** @@ -38,7 +37,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * * * @since 1.0 - * @version $Id$ + * @version $Id: NameFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @see FileFilterUtils#nameFileFilter(String) * @see FileFilterUtils#nameFileFilter(String, IOCase) */ @@ -167,9 +166,9 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable { } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NotFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NotFileFilter.java index b1023f5e0..578cb0ffd 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NotFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NotFileFilter.java @@ -23,7 +23,7 @@ import java.io.Serializable; * This filter produces a logical NOT of the filters specified. * * @since 1.0 - * @version $Id$ + * @version $Id: NotFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @see FileFilterUtils#notFileFilter(IOFileFilter) */ public class NotFileFilter extends AbstractFileFilter implements Serializable { @@ -69,9 +69,9 @@ public class NotFileFilter extends AbstractFileFilter implements Serializable { } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/OrFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/OrFileFilter.java index f71a76615..1b2e7efb0 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/OrFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/OrFileFilter.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. @@ -30,7 +30,7 @@ import java.util.List; * {@code true}. * * @since 1.0 - * @version $Id$ + * @version $Id: OrFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @see FileFilterUtils#or(IOFileFilter...) */ public class OrFileFilter @@ -47,7 +47,7 @@ public class OrFileFilter * @since 1.1 */ public OrFileFilter() { - this.fileFilters = new ArrayList<>(); + this.fileFilters = new ArrayList(); } /** @@ -59,15 +59,15 @@ public class OrFileFilter */ public OrFileFilter(final List fileFilters) { if (fileFilters == null) { - this.fileFilters = new ArrayList<>(); + this.fileFilters = new ArrayList(); } else { - this.fileFilters = new ArrayList<>(fileFilters); + this.fileFilters = new ArrayList(fileFilters); } } /** * Constructs a new file filter that ORs the result of two other filters. - * + * * @param filter1 the first filter, must not be null * @param filter2 the second filter, must not be null * @throws IllegalArgumentException if either filter is null @@ -76,7 +76,7 @@ public class OrFileFilter if (filter1 == null || filter2 == null) { throw new IllegalArgumentException("The filters must not be null"); } - this.fileFilters = new ArrayList<>(2); + this.fileFilters = new ArrayList(2); addFileFilter(filter1); addFileFilter(filter2); } @@ -84,7 +84,6 @@ public class OrFileFilter /** * {@inheritDoc} */ - @Override public void addFileFilter(final IOFileFilter ioFileFilter) { this.fileFilters.add(ioFileFilter); } @@ -92,7 +91,6 @@ public class OrFileFilter /** * {@inheritDoc} */ - @Override public List getFileFilters() { return Collections.unmodifiableList(this.fileFilters); } @@ -100,7 +98,6 @@ public class OrFileFilter /** * {@inheritDoc} */ - @Override public boolean removeFileFilter(final IOFileFilter ioFileFilter) { return this.fileFilters.remove(ioFileFilter); } @@ -108,7 +105,6 @@ public class OrFileFilter /** * {@inheritDoc} */ - @Override public void setFileFilters(final List fileFilters) { this.fileFilters.clear(); this.fileFilters.addAll(fileFilters); @@ -141,9 +137,9 @@ public class OrFileFilter } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/PrefixFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/PrefixFileFilter.java index e13635d60..da99dfd0a 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/PrefixFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/PrefixFileFilter.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.Serializable; import java.util.List; -import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase; /** @@ -38,7 +37,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * * * @since 1.0 - * @version $Id$ + * @version $Id: PrefixFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @see FileFilterUtils#prefixFileFilter(String) * @see FileFilterUtils#prefixFileFilter(String, IOCase) */ @@ -174,9 +173,9 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/RegexFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/RegexFileFilter.java index 41cfb976e..e07caec47 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/RegexFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/RegexFileFilter.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.regex.Pattern; -import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase; /** @@ -40,6 +39,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * } * * + * @version $Id: RegexFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.4 */ public class RegexFileFilter extends AbstractFileFilter implements Serializable { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SizeFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SizeFileFilter.java index dd35d0aab..f7324de20 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SizeFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SizeFileFilter.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. @@ -34,6 +34,7 @@ import java.io.Serializable; * } * * + * @version $Id: SizeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.2 * @see FileFilterUtils#sizeFileFilter(long) * @see FileFilterUtils#sizeFileFilter(long, boolean) @@ -48,7 +49,7 @@ public class SizeFileFilter extends AbstractFileFilter implements Serializable { private final boolean acceptLarger; /** - * Constructs a new size file filter for files equal to or + * Constructs a new size file filter for files equal to or * larger than a certain size. * * @param size the threshold size of the files @@ -94,9 +95,9 @@ public class SizeFileFilter extends AbstractFileFilter implements Serializable { } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SuffixFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SuffixFileFilter.java index 7f9167792..c8edc137c 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SuffixFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SuffixFileFilter.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.Serializable; import java.util.List; -import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase; /** @@ -39,7 +38,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * * * @since 1.0 - * @version $Id$ + * @version $Id: SuffixFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @see FileFilterUtils#suffixFileFilter(String) * @see FileFilterUtils#suffixFileFilter(String, IOCase) */ @@ -81,7 +80,7 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable } /** - * Constructs a new Suffix file filter for an array of suffixes. + * Constructs a new Suffix file filter for an array of suffixs. *

    * The array is not cloned, so could be changed after constructing the * instance. This would be inadvisable however. @@ -94,7 +93,7 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable } /** - * Constructs a new Suffix file filter for an array of suffixes + * Constructs a new Suffix file filter for an array of suffixs * specifying case-sensitivity. * * @param suffixes the suffixes to allow, must not be null @@ -175,9 +174,9 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable } /** - * Provide a String representation of this file filter. + * Provide a String representaion of this file filter. * - * @return a String representation + * @return a String representaion */ @Override public String toString() { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/TrueFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/TrueFileFilter.java index 2a3c314bc..b48f4ccf9 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/TrueFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/TrueFileFilter.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. @@ -23,7 +23,7 @@ import java.io.Serializable; * A file filter that always returns true. * * @since 1.0 - * @version $Id$ + * @version $Id: TrueFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @see FileFilterUtils#trueFileFilter() */ public class TrueFileFilter implements IOFileFilter, Serializable { @@ -54,7 +54,6 @@ public class TrueFileFilter implements IOFileFilter, Serializable { * @param file the file to check (ignored) * @return true */ - @Override public boolean accept(final File file) { return true; } @@ -66,7 +65,6 @@ public class TrueFileFilter implements IOFileFilter, Serializable { * @param name the filename (ignored) * @return true */ - @Override public boolean accept(final File dir, final String name) { return true; } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFileFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFileFilter.java index 49232f057..d104b589b 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFileFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFileFilter.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.List; -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; @@ -47,6 +45,7 @@ import com.fr.third.org.apache.commons.io.IOCase; * } * * + * @version $Id: WildcardFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.3 */ public class WildcardFileFilter extends AbstractFileFilter implements Serializable { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFilter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFilter.java index cdc57e98d..618e3d3a5 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFilter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFilter.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.Serializable; import java.util.List; -import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.third.org.apache.commons.io.FilenameUtils; /** @@ -45,9 +44,10 @@ import com.fr.third.org.apache.commons.io.FilenameUtils; * } * * + * @version $Id: WildcardFilter.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.1 - * @deprecated Use WildcardFileFilter. Deprecated as this class performs directory - * filtering which it shouldn't do, but that can't be removed due to compatibility. + * @deprecated Use WilcardFileFilter. Deprecated as this class performs directory + * filtering which it shouldn't do, but that can't be removed due to compatability. */ @Deprecated public class WildcardFilter extends AbstractFileFilter implements Serializable { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/package.html b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/package.html index e32a192f8..e495e9521 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/package.html +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/package.html @@ -24,8 +24,10 @@ IOFileFilter interface including implementation that allow you to combine other such filters.

    These filter can be used to list files or in {@link java.awt.FileDialog}, for example.

    + +

    There are a number of 'primitive' filters:

    + - @@ -57,8 +59,10 @@ for example.

    There are a number of 'primitive' filters:
    DirectoryFilter
    + +

    And there are five 'boolean' filters:

    + - diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/AutoCloseInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/AutoCloseInputStream.java index 00c27541f..8094ad6d2 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/AutoCloseInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/AutoCloseInputStream.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. @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.IOException; import java.io.InputStream; @@ -35,6 +33,7 @@ import java.io.InputStream; * closing the stream when no longer needed) or the underlying stream (by not * releasing resources once the last byte has been read) do not do that. * + * @version $Id: AutoCloseInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $ * @since 1.4 */ public class AutoCloseInputStream extends ProxyInputStream { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BOMInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BOMInputStream.java index 990185a7c..982bbb155 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BOMInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BOMInputStream.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. @@ -16,25 +16,21 @@ */ package com.fr.third.org.apache.commons.io.input; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.IOException; import java.io.InputStream; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.List; import com.fr.third.org.apache.commons.io.ByteOrderMark; import com.fr.third.org.apache.commons.io.IOUtils; -import com.fr.third.org.apache.commons.io.ByteOrderMark; /** * This class is used to wrap a stream that includes an encoded {@link ByteOrderMark} as its first bytes. - * + * * This class detects these bytes and, if required, can automatically skip them and return the subsequent byte as the * first byte in the stream. - * + * * The {@link ByteOrderMark} implementation has the following pre-defined BOMs: *
      *
    • UTF-8 - {@link ByteOrderMark#UTF_8}
    • @@ -43,19 +39,19 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark; *
    • UTF-32BE - {@link ByteOrderMark#UTF_32LE}
    • *
    • UTF-32LE - {@link ByteOrderMark#UTF_32BE}
    • *
    - * - * + * + * *

    Example 1 - Detect and exclude a UTF-8 BOM

    - * + * *
      * BOMInputStream bomIn = new BOMInputStream(in);
      * if (bomIn.hasBOM()) {
      *     // has a UTF-8 BOM
      * }
      * 
    - * + * *

    Example 2 - Detect a UTF-8 BOM (but don't exclude it)

    - * + * *
      * boolean include = true;
      * BOMInputStream bomIn = new BOMInputStream(in, include);
    @@ -63,11 +59,11 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark;
      *     // has a UTF-8 BOM
      * }
      * 
    - * + * *

    Example 3 - Detect Multiple BOMs

    - * + * *
    - * BOMInputStream bomIn = new BOMInputStream(in,
    + * BOMInputStream bomIn = new BOMInputStream(in, 
      *   ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE,
      *   ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE
      *   );
    @@ -83,10 +79,10 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark;
      *     // has a UTF-32BE BOM
      * }
      * 
    - * + * * @see ByteOrderMark * @see Wikipedia - Byte Order Mark - * @version $Id$ + * @version $Id: BOMInputStream.java 1686527 2015-06-20 06:31:39Z krosenvold $ * @since 2.0 */ public class BOMInputStream extends ProxyInputStream { @@ -104,7 +100,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Constructs a new BOM InputStream that excludes a {@link ByteOrderMark#UTF_8} BOM. - * + * * @param delegate * the InputStream to delegate to */ @@ -114,7 +110,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Constructs a new BOM InputStream that detects a a {@link ByteOrderMark#UTF_8} and optionally includes it. - * + * * @param delegate * the InputStream to delegate to * @param include @@ -126,7 +122,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Constructs a new BOM InputStream that excludes the specified BOMs. - * + * * @param delegate * the InputStream to delegate to * @param boms @@ -141,7 +137,6 @@ public class BOMInputStream extends ProxyInputStream { */ private static final Comparator ByteOrderMarkLengthComparator = new Comparator() { - @Override public int compare(final ByteOrderMark bom1, final ByteOrderMark bom2) { final int len1 = bom1.length(); final int len2 = bom2.length(); @@ -157,7 +152,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them. - * + * * @param delegate * the InputStream to delegate to * @param include @@ -171,16 +166,15 @@ public class BOMInputStream extends ProxyInputStream { throw new IllegalArgumentException("No BOMs specified"); } this.include = include; - final List list = Arrays.asList(boms); // Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes. - Collections.sort(list, ByteOrderMarkLengthComparator); - this.boms = list; + Arrays.sort(boms, ByteOrderMarkLengthComparator); + this.boms = Arrays.asList(boms); } /** * Indicates whether the stream contains one of the specified BOMs. - * + * * @return true if the stream has one of the specified BOMs, otherwise false if it does not * @throws IOException * if an error reading the first bytes of the stream occurs @@ -191,7 +185,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Indicates whether the stream contains the specified BOM. - * + * * @param bom * The BOM to check for * @return true if the stream has the specified BOM, otherwise false if it does not @@ -204,13 +198,12 @@ public class BOMInputStream extends ProxyInputStream { if (!boms.contains(bom)) { throw new IllegalArgumentException("Stream not configure to detect " + bom); } - getBOM(); - return byteOrderMark != null && byteOrderMark.equals(bom); + return byteOrderMark != null && getBOM().equals(bom); } /** * Return the BOM (Byte Order Mark). - * + * * @return The BOM or null if none * @throws IOException * if an error reading the first bytes of the stream occurs @@ -246,11 +239,11 @@ public class BOMInputStream extends ProxyInputStream { /** * Return the BOM charset Name - {@link ByteOrderMark#getCharsetName()}. - * + * * @return The BOM charset Name or null if no BOM found * @throws IOException * if an error reading the first bytes of the stream occurs - * + * */ public String getBOMCharsetName() throws IOException { getBOM(); @@ -261,7 +254,7 @@ public class BOMInputStream extends ProxyInputStream { * This method reads and either preserves or skips the first bytes in the stream. It behaves like the single-byte * read() method, either returning a valid byte or -1 to indicate that the initial bytes have been * processed already. - * + * * @return the byte read (excluding BOM) or -1 if the end of stream * @throws IOException * if an I/O error occurs @@ -273,7 +266,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Find a BOM with the specified bytes. - * + * * @return The matched BOM or null if none matched */ private ByteOrderMark find() { @@ -287,7 +280,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Check if the bytes match a BOM. - * + * * @param bom * The BOM * @return true if the bytes match the bom, otherwise false @@ -311,7 +304,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Invokes the delegate's read() method, detecting and optionally skipping BOM. - * + * * @return the byte read (excluding BOM) or -1 if the end of stream * @throws IOException * if an I/O error occurs @@ -324,7 +317,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Invokes the delegate's read(byte[], int, int) method, detecting and optionally skipping BOM. - * + * * @param buf * the buffer to read the bytes into * @param off @@ -353,7 +346,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Invokes the delegate's read(byte[]) method, detecting and optionally skipping BOM. - * + * * @param buf * the buffer to read the bytes into * @return the number of bytes read (excluding BOM) or -1 if the end of stream @@ -367,7 +360,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Invokes the delegate's mark(int) method. - * + * * @param readlimit * read ahead limit */ @@ -380,7 +373,7 @@ public class BOMInputStream extends ProxyInputStream { /** * Invokes the delegate's reset() method. - * + * * @throws IOException * if an I/O error occurs */ @@ -395,8 +388,8 @@ public class BOMInputStream extends ProxyInputStream { } /** - * Invokes the delegate's skip(long) method, detecting and optionally skipping BOM. - * + * Invokes the delegate's skip(long) method, detecting and optionallyskipping BOM. + * * @param n * the number of bytes to skip * @return the number of bytes to skipped or -1 if the end of stream @@ -404,7 +397,7 @@ public class BOMInputStream extends ProxyInputStream { * if an I/O error occurs */ @Override - public long skip(final long n) throws IOException { + public long skip(long n) throws IOException { int skipped = 0; while ((n > skipped) && (readFirstBytes() >= 0)) { skipped++; diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedInputStream.java index 74505646e..8280d5775 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedInputStream.java @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.IOException; import java.io.InputStream; @@ -34,6 +32,7 @@ import java.io.InputStream; * ServletInputStream's header, will stop it blocking, providing it's been sent * with a correct content length. * + * @version $Id: BoundedInputStream.java 1586342 2014-04-10 15:36:29Z ggregory $ * @since 2.0 */ public class BoundedInputStream extends InputStream { @@ -50,7 +49,7 @@ public class BoundedInputStream extends InputStream { /** the marked position */ private long mark = IOUtils.EOF; - /** flag if close should be propagated */ + /** flag if close shoud be propagated */ private boolean propagateClose = true; /** diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedReader.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedReader.java index eeb90c2ae..6f0f39bb4 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedReader.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedReader.java @@ -57,7 +57,7 @@ public class BoundedReader * @param maxCharsFromTargetReader The maximum number of characters that can be read from target * @throws IOException if mark fails */ - public BoundedReader( final Reader target, final int maxCharsFromTargetReader ) throws IOException { + public BoundedReader( Reader target, int maxCharsFromTargetReader ) throws IOException { this.target = target; this.maxCharsFromTargetReader = maxCharsFromTargetReader; } @@ -73,10 +73,9 @@ public class BoundedReader } /** - * Resets the target to the latest mark, + * Resets the target to the latest mark, @see java.io.Reader#reset() * * @throws IOException If an I/O error occurs while calling the underlying reader's reset method - * @see java.io.Reader#reset() */ @Override public void reset() throws IOException { @@ -85,7 +84,7 @@ public class BoundedReader } /** - * marks the target stream + * marks the target stream, @see java.io.Reader#mark(int). * * @param readAheadLimit The number of characters that can be read while * still retaining the ability to do #reset(). @@ -95,10 +94,9 @@ public class BoundedReader * greater. * * @throws IOException If an I/O error occurs while calling the underlying reader's mark method - * @see java.io.Reader#mark(int) */ @Override - public void mark( final int readAheadLimit ) throws IOException { + public void mark( int readAheadLimit ) throws IOException { this.readAheadLimit = readAheadLimit - charsRead; markedAt = charsRead; @@ -107,11 +105,10 @@ public class BoundedReader } /** - * Reads a single character + * Reads a single character, @see java.io.Reader#read() * * @return -1 on eof or the character read * @throws IOException If an I/O error occurs while calling the underlying reader's read method - * @see java.io.Reader#read() */ @Override public int read() throws IOException { @@ -128,22 +125,21 @@ public class BoundedReader } /** - * Reads into an array + * Reads into an array, @see java.io.Reader#read(char[], int, int) * * @param cbuf The buffer to fill * @param off The offset * @param len The number of chars to read * @return the number of chars read * @throws IOException If an I/O error occurs while calling the underlying reader's read method - * @see java.io.Reader#read(char[], int, int) */ @Override - public int read( final char[] cbuf, final int off, final int len ) throws IOException { + public int read( char[] cbuf, int off, int len ) throws IOException { int c; for ( int i = 0; i < len; i++ ) { c = read(); if ( c == -1 ) { - return i == 0 ? -1 : i; + return i; } cbuf[off + i] = (char) c; } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BrokenInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BrokenInputStream.java index 990d8df36..691981415 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BrokenInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BrokenInputStream.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. diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceInputStream.java index 5205e8591..797543225 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceInputStream.java @@ -19,8 +19,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceReader.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceReader.java index abe7265ef..81aba57c7 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceReader.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceReader.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. @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.Reader; import java.io.Serializable; @@ -29,6 +27,7 @@ import java.io.Serializable; *

    * Note: Supports {@link #mark(int)} and {@link #reset()}. * + * @version $Id: CharSequenceReader.java 1642757 2014-12-01 21:09:30Z sebb $ * @since 1.4 */ public class CharSequenceReader extends Reader implements Serializable { @@ -92,7 +91,7 @@ public class CharSequenceReader extends Reader implements Serializable { } /** - * Read the specified number of characters into the array. + * Read the sepcified number of characters into the array. * * @param array The array to store the characters in * @param offset The starting position in the array to store diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClassLoaderObjectInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClassLoaderObjectInputStream.java index 51dcdd685..bdc914908 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClassLoaderObjectInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClassLoaderObjectInputStream.java @@ -29,6 +29,7 @@ import java.lang.reflect.Proxy; *

    * This is useful in dynamic container environments. * + * @version $Id: ClassLoaderObjectInputStream.java 1471767 2013-04-24 23:24:19Z sebb $ * @since 1.1 */ public class ClassLoaderObjectInputStream extends ObjectInputStream { @@ -66,7 +67,7 @@ public class ClassLoaderObjectInputStream extends ObjectInputStream { try { return Class.forName(objectStreamClass.getName(), false, classLoader); - } catch (final ClassNotFoundException cnfe) { + } catch (ClassNotFoundException cnfe) { // delegate to super class loader which can resolve primitives return super.resolveClass(objectStreamClass); } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CloseShieldInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CloseShieldInputStream.java index b9b2fca2c..2f2daa1af 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CloseShieldInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CloseShieldInputStream.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.io.InputStream; * passed to a component that wants to explicitly close the stream even if * more input would still be available to other components. * + * @version $Id: CloseShieldInputStream.java 1415850 2012-11-30 20:51:39Z ggregory $ * @since 1.4 */ public class CloseShieldInputStream extends ProxyInputStream { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClosedInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClosedInputStream.java index b6836db28..300659c74 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClosedInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClosedInputStream.java @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.InputStream; /** @@ -30,6 +28,7 @@ import java.io.InputStream; * that accept input streams and acting as a sentinel value instead of a * {@code null} input stream. * + * @version $Id: ClosedInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $ * @since 1.4 */ public class ClosedInputStream extends InputStream { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CountingInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CountingInputStream.java index 0249a9ef3..a394b3610 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CountingInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CountingInputStream.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. @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.IOException; import java.io.InputStream; @@ -30,6 +28,7 @@ import java.io.InputStream; * A typical use case would be during debugging, to ensure that data is being * read as expected. * + * @version $Id: CountingInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $ */ public class CountingInputStream extends ProxyInputStream { @@ -95,8 +94,8 @@ public class CountingInputStream extends ProxyInputStream { return (int) result; } - /** - * Set the byte count back to 0. + /** + * Set the byte count back to 0. *

    * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an int. @@ -127,8 +126,8 @@ public class CountingInputStream extends ProxyInputStream { return this.count; } - /** - * Set the byte count back to 0. + /** + * Set the byte count back to 0. *

    * NOTE: This method is an alternative for resetCount() * and was added because that method returns an integer which will diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/DemuxInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/DemuxInputStream.java index a747d1b5e..6ef5f1347 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/DemuxInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/DemuxInputStream.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. @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.IOException; import java.io.InputStream; @@ -27,11 +25,12 @@ import java.io.InputStream; * Data written to this stream is forwarded to a stream that has been associated * with this thread. * + * @version $Id: DemuxInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $ */ public class DemuxInputStream extends InputStream { - private final InheritableThreadLocal m_streams = new InheritableThreadLocal<>(); + private final InheritableThreadLocal m_streams = new InheritableThreadLocal(); /** * Bind the specified stream to the current thread. diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/InfiniteCircularInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/InfiniteCircularInputStream.java deleted file mode 100644 index 70a2b8f56..000000000 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/InfiniteCircularInputStream.java +++ /dev/null @@ -1,52 +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.input; - -import java.io.InputStream; - -/** - * - * An {@link InputStream} that infinitely repeats provided bytes. - *

    - * Closing a InfiniteCircularInputStream has no effect. The methods in - * this class can be called after the stream has been closed without generating - * an IOException. - * - */ -public class InfiniteCircularInputStream extends InputStream { - - final private byte[] repeatedContent; - private int position = -1; - - /** - * Creates a InfiniteCircularStream from the specified array of chars. - * - * @param repeatedContent - * Input buffer to be repeated (not copied) - */ - public InfiniteCircularInputStream(final byte[] repeatedContent) { - this.repeatedContent = repeatedContent; - } - - @Override - public int read() { - position = (position + 1) % repeatedContent.length; - return repeatedContent[position] & 0xff; // copied from - // java.io.ByteArrayInputStream.read() - } - -} diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java deleted file mode 100644 index 323050e96..000000000 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java +++ /dev/null @@ -1,102 +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.input; - -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - - -/** - * This class is an example for using an {@link ObservableInputStream}. It - * creates its own {@link Observer}, - * which calculates a checksum using a MessageDigest, for example an MD5 sum. - * Note: Neither {@link ObservableInputStream}, nor {@link MessageDigest}, - * are thread safe. So is {@link MessageDigestCalculatingInputStream}. - */ -public class MessageDigestCalculatingInputStream extends ObservableInputStream { - - /** - * Maintains the message digest. - */ - public static class MessageDigestMaintainingObserver extends Observer { - private final MessageDigest md; - - /** - * Creates an MessageDigestMaintainingObserver for the given MessageDigest. - * @param pMd the message digest to use - */ - public MessageDigestMaintainingObserver(final MessageDigest pMd) { - md = pMd; - } - - @Override - void data(final int pByte) throws IOException { - md.update((byte) pByte); - } - - @Override - void data(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { - md.update(pBuffer, pOffset, pLength); - } - } - - private final MessageDigest messageDigest; - - /** Creates a new instance, which calculates a signature on the given stream, - * using the given {@link MessageDigest}. - * @param pStream the stream to calculate the message digest for - * @param pDigest the message digest to use - */ - public MessageDigestCalculatingInputStream(final InputStream pStream, final MessageDigest pDigest) { - super(pStream); - messageDigest = pDigest; - add(new MessageDigestMaintainingObserver(pDigest)); - } - - /** Creates a new instance, which calculates a signature on the given stream, - * using a {@link MessageDigest} with the given algorithm. - * @param pStream the stream to calculate the message digest for - * @param pAlgorithm the name of the algorithm to use - * @throws NoSuchAlgorithmException if no Provider supports a MessageDigestSpi implementation for the specified algorithm. - */ - public MessageDigestCalculatingInputStream(final InputStream pStream, final String pAlgorithm) throws NoSuchAlgorithmException { - this(pStream, MessageDigest.getInstance(pAlgorithm)); - } - - /** Creates a new instance, which calculates a signature on the given stream, - * using a {@link MessageDigest} with the "MD5" algorithm. - * @param pStream the stream to calculate the message digest for - * @throws NoSuchAlgorithmException if no Provider supports a MessageDigestSpi implementation for the specified algorithm. - */ - public MessageDigestCalculatingInputStream(final InputStream pStream) throws NoSuchAlgorithmException { - this(pStream, MessageDigest.getInstance("MD5")); - } - - /** Returns the {@link MessageDigest}, which is being used for generating the - * checksum. - * Note: The checksum will only reflect the data, which has been read so far. - * This is probably not, what you expect. Make sure, that the complete data has been - * read, if that is what you want. The easiest way to do so is by invoking - * {@link #consume()}. - * @return the message digest used - */ - public MessageDigest getMessageDigest() { - return messageDigest; - } -} diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullInputStream.java index 7cd64ebb7..7d31d8a8d 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullInputStream.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. @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -62,7 +60,7 @@ import java.io.InputStream; * * * @since 1.3 - * @version $Id$ + * @version $Id: NullInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $ */ public class NullInputStream extends InputStream { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullReader.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullReader.java index f75439428..ddcb4fe30 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullReader.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullReader.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. @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.EOFException; import java.io.IOException; import java.io.Reader; @@ -62,7 +60,7 @@ import java.io.Reader; * * * @since 1.3 - * @version $Id$ + * @version $Id: NullReader.java 1586350 2014-04-10 15:57:20Z ggregory $ */ public class NullReader extends Reader { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ObservableInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ObservableInputStream.java deleted file mode 100644 index 076e19b6e..000000000 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ObservableInputStream.java +++ /dev/null @@ -1,266 +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.input; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - - -/** - * The {@link ObservableInputStream} allows, that an InputStream may be consumed - * by other receivers, apart from the thread, which is reading it. - * The other consumers are implemented as instances of {@link Observer}. A - * typical application may be the generation of a {@link java.security.MessageDigest} on the - * fly. - * {@code Note}: The {@link ObservableInputStream} is not thread safe, - * as instances of InputStream usually aren't. - * If you must access the stream from multiple threads, then synchronization, locking, - * or a similar means must be used. - * @see MessageDigestCalculatingInputStream - */ -public class ObservableInputStream extends ProxyInputStream { - - public static abstract class Observer { - - /** Called to indicate, that {@link InputStream#read()} has been invoked - * on the {@link ObservableInputStream}, and will return a value. - * @param pByte The value, which is being returned. This will never be -1 (EOF), - * because, in that case, {@link #finished()} will be invoked instead. - * @throws IOException if an i/o-error occurs - */ - void data(final int pByte) throws IOException {} - - /** Called to indicate, that {@link InputStream#read(byte[])}, or - * {@link InputStream#read(byte[], int, int)} have been called, and are about to - * invoke data. - * @param pBuffer The byte array, which has been passed to the read call, and where - * data has been stored. - * @param pOffset The offset within the byte array, where data has been stored. - * @param pLength The number of bytes, which have been stored in the byte array. - * @throws IOException if an i/o-error occurs - */ - void data(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException {} - - /** Called to indicate, that EOF has been seen on the underlying stream. - * This method may be called multiple times, if the reader keeps invoking - * either of the read methods, and they will consequently keep returning - * EOF. - * @throws IOException if an i/o-error occurs - */ - void finished() throws IOException {} - - /** Called to indicate, that the {@link ObservableInputStream} has been closed. - * @throws IOException if an i/o-error occurs - */ - void closed() throws IOException {} - - /** - * Called to indicate, that an error occurred on the underlying stream. - * @throws IOException if an i/o-error occurs - */ - void error(final IOException pException) throws IOException { throw pException; } - } - - private final List observers = new ArrayList<>(); - - /** - * Creates a new ObservableInputStream for the given InputStream. - * @param pProxy the input stream to proxy - */ - public ObservableInputStream(final InputStream pProxy) { - super(pProxy); - } - - /** - * Adds an Observer. - * @param pObserver the observer to add - */ - public void add(final Observer pObserver) { - observers.add(pObserver); - } - - /** - * Removes an Observer. - * @param pObserver the observer to remove - */ - public void remove(final Observer pObserver) { - observers.remove(pObserver); - } - - /** - * Removes all Observers. - */ - public void removeAllObservers() { - observers.clear(); - } - - @Override - public int read() throws IOException { - int result = 0; - IOException ioe = null; - try { - result = super.read(); - } catch (final IOException pException) { - ioe = pException; - } - if (ioe != null) { - noteError(ioe); - } else if (result == -1) { - noteFinished(); - } else { - noteDataByte(result); - } - return result; - } - - @Override - public int read(final byte[] pBuffer) throws IOException { - int result = 0; - IOException ioe = null; - try { - result = super.read(pBuffer); - } catch (final IOException pException) { - ioe = pException; - } - if (ioe != null) { - noteError(ioe); - } else if (result == -1) { - noteFinished(); - } else if (result > 0) { - noteDataBytes(pBuffer, 0, result); - } - return result; - } - - @Override - public int read(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { - int result = 0; - IOException ioe = null; - try { - result = super.read(pBuffer, pOffset, pLength); - } catch (final IOException pException) { - ioe = pException; - } - if (ioe != null) { - noteError(ioe); - } else if (result == -1) { - noteFinished(); - } else if (result > 0) { - noteDataBytes(pBuffer, pOffset, result); - } - return result; - } - - /** Notifies the observers by invoking {@link Observer#data(byte[],int,int)} - * with the given arguments. - * @param pBuffer Passed to the observers. - * @param pOffset Passed to the observers. - * @param pLength Passed to the observers. - * @throws IOException Some observer has thrown an exception, which is being - * passed down. - */ - protected void noteDataBytes(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { - for (final Observer observer : getObservers()) { - observer.data(pBuffer, pOffset, pLength); - } - } - - /** Notifies the observers by invoking {@link Observer#finished()}. - * @throws IOException Some observer has thrown an exception, which is being - * passed down. - */ - protected void noteFinished() throws IOException { - for (final Observer observer : getObservers()) { - observer.finished(); - } - } - - /** Notifies the observers by invoking {@link Observer#data(int)} - * with the given arguments. - * @param pDataByte Passed to the observers. - * @throws IOException Some observer has thrown an exception, which is being - * passed down. - */ - protected void noteDataByte(final int pDataByte) throws IOException { - for (final Observer observer : getObservers()) { - observer.data(pDataByte); - } - } - - /** Notifies the observers by invoking {@link Observer#error(IOException)} - * with the given argument. - * @param pException Passed to the observers. - * @throws IOException Some observer has thrown an exception, which is being - * passed down. This may be the same exception, which has been passed as an - * argument. - */ - protected void noteError(final IOException pException) throws IOException { - for (final Observer observer : getObservers()) { - observer.error(pException); - } - } - - /** Notifies the observers by invoking {@link Observer#finished()}. - * @throws IOException Some observer has thrown an exception, which is being - * passed down. - */ - protected void noteClosed() throws IOException { - for (final Observer observer : getObservers()) { - observer.closed(); - } - } - - /** Gets all currently registered observers. - * @return a list of the currently registered observers - */ - protected List getObservers() { - return observers; - } - - @Override - public void close() throws IOException { - IOException ioe = null; - try { - super.close(); - } catch (final IOException e) { - ioe = e; - } - if (ioe == null) { - noteClosed(); - } else { - noteError(ioe); - } - } - - /** Reads all data from the underlying {@link InputStream}, while notifying the - * observers. - * @throws IOException The underlying {@link InputStream}, or either of the - * observers has thrown an exception. - */ - public void consume() throws IOException { - final byte[] buffer = new byte[8192]; - for (;;) { - final int res = read(buffer); - if (res == -1) { - return; - } - } - } - -} diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyInputStream.java index 0d2ce68d9..dbb9cfcee 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyInputStream.java @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; @@ -36,6 +34,7 @@ import java.io.InputStream; * See the protected methods for ways in which a subclass can easily decorate * a stream with custom pre-, post- or error processing functionality. * + * @version $Id: ProxyInputStream.java 1603493 2014-06-18 15:46:07Z ggregory $ */ public abstract class ProxyInputStream extends FilterInputStream { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyReader.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyReader.java index b199cf9c2..858510542 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyReader.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyReader.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. @@ -18,28 +18,27 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.FilterReader; import java.io.IOException; import java.io.Reader; import java.nio.CharBuffer; /** - * A Proxy stream which acts as expected, that is it passes the method - * calls on to the proxied stream and doesn't change which methods are - * being called. + * A Proxy stream which acts as expected, that is it passes the method + * calls on to the proxied stream and doesn't change which methods are + * being called. *

    * It is an alternative base class to FilterReader - * to increase reusability, because FilterReader changes the + * to increase reusability, because FilterReader changes the * methods being called, such as read(char[]) to read(char[], int, int). - * + * + * @version $Id: ProxyReader.java 1586350 2014-04-10 15:57:20Z ggregory $ */ public abstract class ProxyReader extends FilterReader { /** * Constructs a new ProxyReader. - * + * * @param proxy the Reader to delegate to */ public ProxyReader(final Reader proxy) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReaderInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReaderInputStream.java index 03e5b8470..64d5ee51c 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReaderInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReaderInputStream.java @@ -17,8 +17,7 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; - -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; +import com.fr.third.org.apache.commons.io.output.WriterOutputStream; import java.io.IOException; import java.io.InputStream; @@ -64,7 +63,7 @@ import java.nio.charset.CodingErrorAction; * in the design of the code. This class is typically used in situations where an existing * API only accepts an {@link InputStream}, but where the most natural way to produce the data * is as a character stream, i.e. by providing a {@link Reader} instance. An example of a situation - * where this problem may appear is when implementing the {@code javax.activation.DataSource} + * where this problem may appear is when implementing the {@link javax.activation.DataSource} * interface from the Java Activation Framework. *

    * Given the fact that the {@link Reader} class doesn't provide any way to predict whether the next @@ -74,7 +73,7 @@ import java.nio.charset.CodingErrorAction; *

    * Instances of {@link ReaderInputStream} are not thread safe. * - * @see com.fr.third.org.apache.commons.io.output.WriterOutputStream + * @see WriterOutputStream * * @since 2.0 */ diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReversedLinesFileReader.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReversedLinesFileReader.java index 70959e68a..d7163d86d 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReversedLinesFileReader.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReversedLinesFileReader.java @@ -23,9 +23,7 @@ import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; -import java.nio.charset.StandardCharsets; -import com.fr.third.org.apache.commons.io.Charsets; import com.fr.third.org.apache.commons.io.Charsets; /** @@ -93,6 +91,7 @@ public class ReversedLinesFileReader implements Closeable { * @throws IOException if an I/O error occurs * @since 2.3 */ + @SuppressWarnings("deprecation") // unavoidable until Java 7 public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException { this.blockSize = blockSize; this.encoding = encoding; @@ -104,7 +103,7 @@ public class ReversedLinesFileReader implements Closeable { if (maxBytesPerChar == 1f) { // all one byte encodings are no problem byteDecrement = 1; - } else if (charset == StandardCharsets.UTF_8) { + } else if (charset == Charsets.UTF_8) { // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte // http://en.wikipedia.org/wiki/UTF-8 byteDecrement = 1; @@ -115,11 +114,11 @@ public class ReversedLinesFileReader implements Closeable { charset == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese) charset == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese) byteDecrement = 1; - } else if (charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) { + } else if (charset == Charsets.UTF_16BE || charset == Charsets.UTF_16LE) { // UTF-16 new line sequences are not allowed as second tuple of four byte sequences, // however byte order has to be specified byteDecrement = 2; - } else if (charset == StandardCharsets.UTF_16) { + } else if (charset == Charsets.UTF_16) { throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte order (use UTF-16BE or " + "UTF-16LE)"); } else { @@ -199,7 +198,6 @@ public class ReversedLinesFileReader implements Closeable { * * @throws IOException if an I/O error occurs */ - @Override public void close() throws IOException { randomAccessFile.close(); } @@ -244,7 +242,7 @@ public class ReversedLinesFileReader implements Closeable { /** * Handles block rollover - * + * * @return the new FilePart or null * @throws IOException if there was a problem reading the file */ @@ -269,7 +267,7 @@ public class ReversedLinesFileReader implements Closeable { /** * Reads a line. - * + * * @return the line or null * @throws IOException if there is an error reading from the file */ @@ -344,7 +342,7 @@ public class ReversedLinesFileReader implements Closeable { /** * Finds the new-line sequence and return its length. - * + * * @param data buffer to scan * @param i start offset in buffer * @return length of newline sequence or 0 if none found diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/SwappedDataInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/SwappedDataInputStream.java index edc978b09..6662ed17a 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/SwappedDataInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/SwappedDataInputStream.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. @@ -16,8 +16,6 @@ */ package com.fr.third.org.apache.commons.io.input; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.DataInput; import java.io.EOFException; import java.io.IOException; @@ -25,15 +23,15 @@ import java.io.InputStream; import com.fr.third.org.apache.commons.io.EndianUtils; import com.fr.third.org.apache.commons.io.IOUtils; -import com.fr.third.org.apache.commons.io.EndianUtils; /** * DataInput for systems relying on little endian data formats. - * When read, values will be changed from little endian to big - * endian formats for internal usage. + * When read, values will be changed from little endian to big + * endian formats for internal usage. *

    * Origin of code: Avalon Excalibur (IO) * + * @version CVS $Revision: 1302050 $ */ public class SwappedDataInputStream extends ProxyInputStream implements DataInput @@ -55,7 +53,6 @@ public class SwappedDataInputStream extends ProxyInputStream * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ - @Override public boolean readBoolean() throws IOException, EOFException { @@ -68,7 +65,6 @@ public class SwappedDataInputStream extends ProxyInputStream * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ - @Override public byte readByte() throws IOException, EOFException { @@ -81,7 +77,6 @@ public class SwappedDataInputStream extends ProxyInputStream * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ - @Override public char readChar() throws IOException, EOFException { @@ -94,7 +89,6 @@ public class SwappedDataInputStream extends ProxyInputStream * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ - @Override public double readDouble() throws IOException, EOFException { @@ -102,12 +96,11 @@ public class SwappedDataInputStream extends ProxyInputStream } /** - * Delegates to {@link EndianUtils#readSwappedFloat(InputStream)}. + * Delegates to {@link EndianUtils#readSwappedFloat(InputStream)}. * @return the read long * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ - @Override public float readFloat() throws IOException, EOFException { @@ -116,12 +109,11 @@ public class SwappedDataInputStream extends ProxyInputStream /** * Invokes the delegate's read(byte[] data, int, int) method. - * + * * @param data the buffer to read the bytes into * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public void readFully( final byte[] data ) throws IOException, EOFException { @@ -131,14 +123,13 @@ public class SwappedDataInputStream extends ProxyInputStream /** * Invokes the delegate's read(byte[] data, int, int) method. - * + * * @param data the buffer to read the bytes into * @param offset The start offset * @param length The number of bytes to read * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public void readFully( final byte[] data, final int offset, final int length ) throws IOException, EOFException { @@ -159,12 +150,11 @@ public class SwappedDataInputStream extends ProxyInputStream } /** - * Delegates to {@link EndianUtils#readSwappedInteger(InputStream)}. + * Delegates to {@link EndianUtils#readSwappedInteger(InputStream)}. * @return the read long * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public int readInt() throws IOException, EOFException { @@ -177,21 +167,19 @@ public class SwappedDataInputStream extends ProxyInputStream * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public String readLine() throws IOException, EOFException { - throw new UnsupportedOperationException( + throw new UnsupportedOperationException( "Operation not supported: readLine()" ); } /** - * Delegates to {@link EndianUtils#readSwappedLong(InputStream)}. + * Delegates to {@link EndianUtils#readSwappedLong(InputStream)}. * @return the read long * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public long readLong() throws IOException, EOFException { @@ -199,12 +187,11 @@ public class SwappedDataInputStream extends ProxyInputStream } /** - * Delegates to {@link EndianUtils#readSwappedShort(InputStream)}. + * Delegates to {@link EndianUtils#readSwappedShort(InputStream)}. * @return the read long * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public short readShort() throws IOException, EOFException { @@ -217,7 +204,6 @@ public class SwappedDataInputStream extends ProxyInputStream * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public int readUnsignedByte() throws IOException, EOFException { @@ -225,12 +211,11 @@ public class SwappedDataInputStream extends ProxyInputStream } /** - * Delegates to {@link EndianUtils#readSwappedUnsignedShort(InputStream)}. + * Delegates to {@link EndianUtils#readSwappedUnsignedShort(InputStream)}. * @return the read long * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public int readUnsignedShort() throws IOException, EOFException { @@ -243,11 +228,10 @@ public class SwappedDataInputStream extends ProxyInputStream * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public String readUTF() throws IOException, EOFException { - throw new UnsupportedOperationException( + throw new UnsupportedOperationException( "Operation not supported: readUTF()" ); } @@ -258,7 +242,6 @@ public class SwappedDataInputStream extends ProxyInputStream * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ - @Override public int skipBytes( final int count ) throws IOException, EOFException { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TaggedInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TaggedInputStream.java index ce0823037..2b5cd0a06 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TaggedInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TaggedInputStream.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,6 @@ import java.io.InputStream; import java.io.Serializable; import java.util.UUID; -import com.fr.third.org.apache.commons.io.TaggedIOException; import com.fr.third.org.apache.commons.io.TaggedIOException; /** @@ -105,7 +104,7 @@ public class TaggedInputStream extends ProxyInputStream { /** * Tags any IOExceptions thrown, wrapping and re-throwing. - * + * * @param e The IOException thrown * @throws IOException if an I/O error occurs */ diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/Tailer.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/Tailer.java index 4c420c7fa..51e8c3a93 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/Tailer.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/Tailer.java @@ -16,8 +16,6 @@ */ package com.fr.third.org.apache.commons.io.input; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -27,11 +25,10 @@ import java.nio.charset.Charset; import com.fr.third.org.apache.commons.io.FileUtils; import com.fr.third.org.apache.commons.io.IOUtils; -import com.fr.third.org.apache.commons.io.FileUtils; /** * Simple implementation of the unix "tail -f" functionality. - * + * *

    1. Create a TailerListener implementation

    *

    * First you need to create a {@link TailerListener} implementation @@ -112,10 +109,10 @@ import com.fr.third.org.apache.commons.io.FileUtils; * *

    If you interrupt a tailer, the tailer listener is called with the {@link InterruptedException}.

    * - *

    The file is read using the default charset; this can be overridden if necessary

    + *

    The file is read using the default charset; this can be overriden if necessary

    * @see TailerListener * @see TailerListenerAdapter - * @version $Id$ + * @version $Id: Tailer.java 1714076 2015-11-12 16:06:41Z krosenvold $ * @since 2.0 * @since 2.5 Updated behavior and documentation for {@link Thread#interrupt()} */ @@ -263,7 +260,7 @@ public class Tailer implements Runnable { this.listener = listener; listener.init(this); this.reOpen = reOpen; - this.cset = cset; + this.cset = cset; } /** @@ -404,7 +401,6 @@ public class Tailer implements Runnable { /** * Follows changes in the file, calling the TailerListener's handle method for each new line. */ - @Override public void run() { RandomAccessFile reader = null; try { @@ -433,22 +429,24 @@ public class Tailer implements Runnable { if (length < position) { // File was rotated listener.fileRotated(); - // Reopen the reader after rotation ensuring that the old file is closed iff we re-open it - // successfully - try (RandomAccessFile save = reader) { + // Reopen the reader after rotation + try { + // Ensure that the old file is closed iff we re-open it successfully + final RandomAccessFile save = reader; reader = new RandomAccessFile(file, RAF_MODE); // At this point, we're sure that the old file is rotated // Finish scanning the old file and then we'll start with the new one try { readLines(save); - } catch (final IOException ioe) { + } catch (IOException ioe) { listener.handle(ioe); } position = 0; + // close old file explicitly rather than relying on GC picking up previous RAF + IOUtils.closeQuietly(save); } catch (final FileNotFoundException e) { // in this case we continue to use the previous reader and position values listener.fileNotFound(); - Thread.sleep(delayMillis); } continue; } else { @@ -471,8 +469,8 @@ public class Tailer implements Runnable { last = file.lastModified(); } } - if (reOpen && reader != null) { - reader.close(); + if (reOpen) { + IOUtils.closeQuietly(reader); } Thread.sleep(delayMillis); if (getRun() && reOpen) { @@ -482,22 +480,23 @@ public class Tailer implements Runnable { } } catch (final InterruptedException e) { Thread.currentThread().interrupt(); - listener.handle(e); + stop(e); } catch (final Exception e) { - listener.handle(e); + stop(e); } finally { - try { - if (reader != null) { - reader.close(); - } - } - catch (final IOException e) { - listener.handle(e); - } - stop(); + IOUtils.closeQuietly(reader); } } + /** + * Stops the tailer with an exception + * @param e The exception to send to listener + */ + private void stop(final Exception e) { + listener.handle(e); + stop(); + } + /** * Allows the tailer to complete its current loop and return. */ @@ -513,47 +512,47 @@ public class Tailer implements Runnable { * @throws java.io.IOException if an I/O error occurs. */ private long readLines(final RandomAccessFile reader) throws IOException { - try (ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64)) { - long pos = reader.getFilePointer(); - long rePos = pos; // position to re-read - int num; - boolean seenCR = false; - while (getRun() && ((num = reader.read(inbuf)) != IOUtils.EOF)) { - for (int i = 0; i < num; i++) { - final byte ch = inbuf[i]; - switch ( ch ) { - case '\n': - seenCR = false; // swallow CR before LF - listener.handle(new String(lineBuf.toByteArray(), cset)); - lineBuf.reset(); - rePos = pos + i + 1; - break; - case '\r': - if (seenCR) { - lineBuf.write('\r'); - } - seenCR = true; - break; - default: - if (seenCR) { - seenCR = false; // swallow final CR - listener.handle(new String(lineBuf.toByteArray(), cset)); - lineBuf.reset(); - rePos = pos + i + 1; - } - lineBuf.write(ch); + ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64); + long pos = reader.getFilePointer(); + long rePos = pos; // position to re-read + int num; + boolean seenCR = false; + while (getRun() && ((num = reader.read(inbuf)) != IOUtils.EOF)) { + for (int i = 0; i < num; i++) { + final byte ch = inbuf[i]; + switch (ch) { + case '\n': + seenCR = false; // swallow CR before LF + listener.handle(new String(lineBuf.toByteArray(), cset)); + lineBuf.reset(); + rePos = pos + i + 1; + break; + case '\r': + if (seenCR) { + lineBuf.write('\r'); + } + seenCR = true; + break; + default: + if (seenCR) { + seenCR = false; // swallow final CR + listener.handle(new String(lineBuf.toByteArray(), cset)); + lineBuf.reset(); + rePos = pos + i + 1; } + lineBuf.write(ch); } - pos = reader.getFilePointer(); - } - - reader.seek(rePos); // Ensure we can re-read if necessary - - if (listener instanceof TailerListenerAdapter) { - ((TailerListenerAdapter) listener).endOfFileReached(); } + pos = reader.getFilePointer(); + } + IOUtils.closeQuietly(lineBuf); // not strictly necessary + reader.seek(rePos); // Ensure we can re-read if necessary - return rePos; + if (listener instanceof TailerListenerAdapter) { + ((TailerListenerAdapter) listener).endOfFileReached(); } + + return rePos; } + } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListener.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListener.java index bdcfd6f21..c4bc564c7 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListener.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListener.java @@ -19,6 +19,7 @@ package com.fr.third.org.apache.commons.io.input; /** * Listener for events from a {@link Tailer}. * + * @version $Id: TailerListener.java 1714076 2015-11-12 16:06:41Z krosenvold $ * @since 2.0 */ public interface TailerListener { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListenerAdapter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListenerAdapter.java index 1d2b2b54b..44bc8ca33 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListenerAdapter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListenerAdapter.java @@ -19,6 +19,7 @@ package com.fr.third.org.apache.commons.io.input; /** * {@link TailerListener} Adapter. * + * @version $Id: TailerListenerAdapter.java 1714076 2015-11-12 16:06:41Z krosenvold $ * @since 2.0 */ public class TailerListenerAdapter implements TailerListener { @@ -28,14 +29,12 @@ public class TailerListenerAdapter implements TailerListener { * giving the listener a method of stopping the tailer. * @param tailer the tailer. */ - @Override public void init(final Tailer tailer) { } /** * This method is called if the tailed file is not found. */ - @Override public void fileNotFound() { } @@ -45,7 +44,6 @@ public class TailerListenerAdapter implements TailerListener { * This method is called before the file is reopened, and fileNotFound may * be called if the new file has not yet been created. */ - @Override public void fileRotated() { } @@ -53,7 +51,6 @@ public class TailerListenerAdapter implements TailerListener { * Handles a line from a Tailer. * @param line the line. */ - @Override public void handle(final String line) { } @@ -61,7 +58,6 @@ public class TailerListenerAdapter implements TailerListener { * Handles an Exception . * @param ex the exception. */ - @Override public void handle(final Exception ex) { } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TeeInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TeeInputStream.java index fd4b534f9..744b86c88 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TeeInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TeeInputStream.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. @@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input; import com.fr.third.org.apache.commons.io.IOUtils; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -35,8 +33,8 @@ import java.io.OutputStream; * called on this proxy. It is configurable whether the associated output * stream will also closed. * + * @version $Id: TeeInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $ * @since 1.4 - * @see ObservableInputStream */ public class TeeInputStream extends ProxyInputStream { @@ -105,7 +103,7 @@ public class TeeInputStream extends ProxyInputStream { * the associated output stream. * * @return next byte from the stream, or -1 if the stream has ended - * @throws IOException if the stream could not be read (or written) + * @throws IOException if the stream could not be read (or written) */ @Override public int read() throws IOException { @@ -124,7 +122,7 @@ public class TeeInputStream extends ProxyInputStream { * @param st start offset within the buffer * @param end maximum number of bytes to read * @return number of bytes read, or -1 if the stream has ended - * @throws IOException if the stream could not be read (or written) + * @throws IOException if the stream could not be read (or written) */ @Override public int read(final byte[] bts, final int st, final int end) throws IOException { @@ -141,7 +139,7 @@ public class TeeInputStream extends ProxyInputStream { * * @param bts byte buffer * @return number of bytes read, or -1 if the stream has ended - * @throws IOException if the stream could not be read (or written) + * @throws IOException if the stream could not be read (or written) */ @Override public int read(final byte[] bts) throws IOException { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/UnixLineEndingInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/UnixLineEndingInputStream.java index aae4fce81..5372f68ef 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/UnixLineEndingInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/UnixLineEndingInputStream.java @@ -43,7 +43,7 @@ public class UnixLineEndingInputStream extends InputStream { * @param in The input stream to wrap * @param ensureLineFeedAtEndOfFile true to ensure that the file ends with LF */ - public UnixLineEndingInputStream( final InputStream in, final boolean ensureLineFeedAtEndOfFile ) { + public UnixLineEndingInputStream( InputStream in, boolean ensureLineFeedAtEndOfFile ) { this.target = in; this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile; } @@ -69,12 +69,12 @@ public class UnixLineEndingInputStream extends InputStream { */ @Override public int read() throws IOException { - final boolean previousWasSlashR = slashRSeen; + boolean previousWasSlashR = slashRSeen; if ( eofSeen ) { return eofGame(previousWasSlashR); } else { - final int target = readWithUpdate(); + int target = readWithUpdate(); if ( eofSeen ) { return eofGame(previousWasSlashR); } @@ -96,7 +96,7 @@ public class UnixLineEndingInputStream extends InputStream { * @param previousWasSlashR Indicates if the last seen was a \r * @return The next char to output to the stream */ - private int eofGame(final boolean previousWasSlashR) { + private int eofGame(boolean previousWasSlashR) { if ( previousWasSlashR || !ensureLineFeedAtEndOfFile ) { return -1; } @@ -122,7 +122,7 @@ public class UnixLineEndingInputStream extends InputStream { * {@inheritDoc} */ @Override - public synchronized void mark( final int readlimit ) { + public synchronized void mark( int readlimit ) { throw new UnsupportedOperationException( "Mark notsupported" ); } } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/WindowsLineEndingInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/WindowsLineEndingInputStream.java index 3a0772ce1..8ff763db4 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/WindowsLineEndingInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/WindowsLineEndingInputStream.java @@ -44,7 +44,7 @@ public class WindowsLineEndingInputStream extends InputStream { * @param in The input stream to wrap * @param ensureLineFeedAtEndOfFile true to ensure that the file ends with CRLF */ - public WindowsLineEndingInputStream( final InputStream in, final boolean ensureLineFeedAtEndOfFile ) { + public WindowsLineEndingInputStream( InputStream in, boolean ensureLineFeedAtEndOfFile ) { this.target = in; this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile; } @@ -76,8 +76,8 @@ public class WindowsLineEndingInputStream extends InputStream { injectSlashN = false; return '\n'; } else { - final boolean prevWasSlashR = slashRSeen; - final int target = readWithUpdate(); + boolean prevWasSlashR = slashRSeen; + int target = readWithUpdate(); if ( eofSeen ) { return eofGame(); } @@ -128,7 +128,7 @@ public class WindowsLineEndingInputStream extends InputStream { * {@inheritDoc} */ @Override - public synchronized void mark( final int readlimit ) { + public synchronized void mark( int readlimit ) { throw new UnsupportedOperationException( "Mark not supported" ); } } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReader.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReader.java index e2274cf63..e1faf635d 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReader.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReader.java @@ -34,10 +34,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.fr.third.org.apache.commons.io.ByteOrderMark; -import com.fr.third.org.apache.commons.io.ByteOrderMark; +import com.fr.third.org.apache.commons.io.output.XmlStreamWriter; /** - * Character stream that handles all the necessary Voodoo to figure out the + * Character stream that handles all the necessary Voodo to figure out the * charset encoding of the XML document within the stream. *

    * IMPORTANT: This class is not related in any way to the org.xml.sax.XMLReader. @@ -52,7 +52,7 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark; * Files, raw streams and HTTP streams by offering a wide set of constructors. *

    * By default the charset encoding detection is lenient, the constructor with - * the lenient flag can be used for a script (following HTTP MIME and XML + * the lenient flag can be used for an script (following HTTP MIME and XML * specifications). All this is nicely explained by Mark Pilgrim in his blog, * Determining the character encoding of a feed. @@ -60,7 +60,8 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark; * Originally developed for ROME under * Apache License 2.0. * - * @see com.fr.third.org.apache.commons.io.output.XmlStreamWriter + * @version $Id: XmlStreamReader.java 1686747 2015-06-21 18:44:49Z krosenvold $ + * @see XmlStreamWriter * @since 2.0 */ public class XmlStreamReader extends Reader { @@ -277,7 +278,7 @@ public class XmlStreamReader extends Reader { } /** - * Creates a Reader using an InputStream and the associated content-type + * Creates a Reader using an InputStream an the associated content-type * header. *

    * First it checks if the stream has BOM. If there is not BOM checks the @@ -299,7 +300,7 @@ public class XmlStreamReader extends Reader { } /** - * Creates a Reader using an InputStream and the associated content-type + * Creates a Reader using an InputStream an the associated content-type * header. This constructor is lenient regarding the encoding detection. *

    * First it checks if the stream has BOM. If there is not BOM checks the @@ -342,7 +343,7 @@ public class XmlStreamReader extends Reader { } /** - * Creates a Reader using an InputStream and the associated content-type + * Creates a Reader using an InputStream an the associated content-type * header. This constructor is lenient regarding the encoding detection. *

    * First it checks if the stream has BOM. If there is not BOM checks the diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReaderException.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReaderException.java index db2351453..d2caff8d4 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReaderException.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReaderException.java @@ -28,6 +28,7 @@ import java.io.IOException; * InputStream given to the XmlStreamReader cannot be used as that one has been * already read. * + * @version $Id: XmlStreamReaderException.java 1415850 2012-11-30 20:51:39Z ggregory $ * @since 2.0 */ public class XmlStreamReaderException extends IOException { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListener.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListener.java index 6dee82cd4..ac7b303b5 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListener.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListener.java @@ -21,9 +21,9 @@ import java.io.File; * A listener that receives events of file system modifications. *

    * Register {@link FileAlterationListener}s with a {@link FileAlterationObserver}. - * + * * @see FileAlterationObserver - * @version $Id$ + * @version $Id: FileAlterationListener.java 1304052 2012-03-22 20:55:29Z ggregory $ * @since 2.0 */ public interface FileAlterationListener { @@ -37,42 +37,42 @@ public interface FileAlterationListener { /** * Directory created Event. - * + * * @param directory The directory created */ void onDirectoryCreate(final File directory); /** * Directory changed Event. - * + * * @param directory The directory changed */ void onDirectoryChange(final File directory); /** * Directory deleted Event. - * + * * @param directory The directory deleted */ void onDirectoryDelete(final File directory); /** * File created Event. - * + * * @param file The file created */ void onFileCreate(final File file); /** * File changed Event. - * + * * @param file The file changed */ void onFileChange(final File file); /** * File deleted Event. - * + * * @param file The file deleted */ void onFileDelete(final File file); diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java index b3b186e56..8336035e1 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java @@ -20,9 +20,9 @@ import java.io.File; /** * Convenience {@link FileAlterationListener} implementation that does nothing. - * + * * @see FileAlterationObserver - * @version $Id$ + * @version $Id: FileAlterationListenerAdaptor.java 1304062 2012-03-22 21:10:46Z sebb $ * @since 2.0 */ public class FileAlterationListenerAdaptor implements FileAlterationListener { @@ -32,61 +32,54 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener { * * @param observer The file system observer (ignored) */ - @Override public void onStart(final FileAlterationObserver observer) { } /** * Directory created Event. - * + * * @param directory The directory created (ignored) */ - @Override public void onDirectoryCreate(final File directory) { } /** * Directory changed Event. - * + * * @param directory The directory changed (ignored) */ - @Override public void onDirectoryChange(final File directory) { } /** * Directory deleted Event. - * + * * @param directory The directory deleted (ignored) */ - @Override public void onDirectoryDelete(final File directory) { } /** * File created Event. - * + * * @param file The file created (ignored) */ - @Override public void onFileCreate(final File file) { } /** * File changed Event. - * + * * @param file The file changed (ignored) */ - @Override public void onFileChange(final File file) { } /** * File deleted Event. - * + * * @param file The file deleted (ignored) */ - @Override public void onFileDelete(final File file) { } @@ -95,7 +88,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener { * * @param observer The file system observer (ignored) */ - @Override public void onStop(final FileAlterationObserver observer) { } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationMonitor.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationMonitor.java index 7e56caf4a..e1292b6fc 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationMonitor.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationMonitor.java @@ -23,15 +23,15 @@ import java.util.concurrent.ThreadFactory; /** * A runnable that spawns a monitoring thread triggering any * registered {@link FileAlterationObserver} at a specified interval. - * + * * @see FileAlterationObserver - * @version $Id$ + * @version $Id: FileAlterationMonitor.java 1415850 2012-11-30 20:51:39Z ggregory $ * @since 2.0 */ public final class FileAlterationMonitor implements Runnable { private final long interval; - private final List observers = new CopyOnWriteArrayList<>(); + private final List observers = new CopyOnWriteArrayList(); private Thread thread = null; private ThreadFactory threadFactory; private volatile boolean running = false; @@ -46,7 +46,7 @@ public final class FileAlterationMonitor implements Runnable { /** * Construct a monitor with the specified interval. * - * @param interval The amount of time in milliseconds to wait between + * @param interval The amount of time in miliseconds to wait between * checks of the file system */ public FileAlterationMonitor(final long interval) { @@ -56,7 +56,7 @@ public final class FileAlterationMonitor implements Runnable { /** * Construct a monitor with the specified interval and set of observers. * - * @param interval The amount of time in milliseconds to wait between + * @param interval The amount of time in miliseconds to wait between * checks of the file system * @param observers The set of observers to add to the monitor. */ @@ -112,7 +112,7 @@ public final class FileAlterationMonitor implements Runnable { /** * Returns the set of {@link FileAlterationObserver} registered with - * this monitor. + * this monitor. * * @return The set of {@link FileAlterationObserver} */ @@ -176,7 +176,6 @@ public final class FileAlterationMonitor implements Runnable { /** * Run. */ - @Override public void run() { while (running) { for (final FileAlterationObserver observer : observers) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationObserver.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationObserver.java index 4d8437583..555b3b569 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationObserver.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationObserver.java @@ -24,9 +24,6 @@ import java.util.Comparator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import com.fr.third.org.apache.commons.io.FileUtils; -import com.fr.third.org.apache.commons.io.IOCase; -import com.fr.third.org.apache.commons.io.comparator.NameFileComparator; import com.fr.third.org.apache.commons.io.FileUtils; import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.comparator.NameFileComparator; @@ -57,7 +54,7 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator; * To manually observe a directory, initialize the observer and invoked the * {@link #checkAndNotify()} method as required: *

    - *      // initialize
    + *      // intialize
      *      observer.init();
      *      ...
      *      // invoke as required
    @@ -68,7 +65,7 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
      *      // finished
      *      observer.finish();
      * 
    - * Alternatively, register the observer(s) with a {@link FileAlterationMonitor}, + * Alternatively, register the oberver(s) with a {@link FileAlterationMonitor}, * which creates a new thread, invoking the observer at the specified interval: *
      *      long interval = ...
    @@ -86,7 +83,7 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
      * noise from unwanted file system events.
      * 

    * Commons IO has a good range of - * useful, ready made + * useful, ready made * File Filter * implementations for this purpose. *

    @@ -119,13 +116,13 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator; * * @see FileAlterationListener * @see FileAlterationMonitor - * @version $Id$ + * @version $Id: FileAlterationObserver.java 1686747 2015-06-21 18:44:49Z krosenvold $ * @since 2.0 */ public class FileAlterationObserver implements Serializable { private static final long serialVersionUID = 1185122225658782848L; - private final List listeners = new CopyOnWriteArrayList<>(); + private final List listeners = new CopyOnWriteArrayList(); private final FileEntry rootEntry; private final FileFilter fileFilter; private final Comparator comparator; @@ -291,7 +288,7 @@ public class FileAlterationObserver implements Serializable { } /** - * Check whether the file and its children have been created, modified or deleted. + * Check whether the file and its chlidren have been created, modified or deleted. */ public void checkAndNotify() { @@ -370,7 +367,7 @@ public class FileAlterationObserver implements Serializable { * @param entry the parent entry * @return The child files */ - private FileEntry[] doListFiles(final File file, final FileEntry entry) { + private FileEntry[] doListFiles(File file, FileEntry entry) { final File[] files = listFiles(file); final FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES; for (int i = 0; i < files.length; i++) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileEntry.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileEntry.java index d3f6489a8..5f6a8e087 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileEntry.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileEntry.java @@ -29,7 +29,7 @@ import java.io.Serializable; *

  • Length (see {@link File#length()}) - directories treated as zero
  • *
  • Children - contents of a directory (see {@link File#listFiles(java.io.FileFilter)})
  • * - * + * *

    Custom Implementations

    *

    * If the state of additional {@link File} attributes is required then create a custom diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/AppendableOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/AppendableOutputStream.java index c3cadefa5..43cb04747 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/AppendableOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/AppendableOutputStream.java @@ -28,7 +28,7 @@ import java.io.OutputStream; * * @since 2.5 * @see java.lang.Appendable - * @version $Id$ + * @version $Id: AppendableOutputStream.java 1687815 2015-06-26 17:18:56Z krosenvold $ */ public class AppendableOutputStream extends OutputStream { @@ -39,7 +39,7 @@ public class AppendableOutputStream extends OutputStream * * @param appendable the appendable to write to */ - public AppendableOutputStream(final T appendable) { + public AppendableOutputStream(T appendable) { this.appendable = appendable; } @@ -50,7 +50,7 @@ public class AppendableOutputStream extends OutputStream * @throws IOException upon error */ @Override - public void write(final int b) throws IOException { + public void write(int b) throws IOException { appendable.append((char)b); } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/BrokenOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/BrokenOutputStream.java index 47a491e8a..44886d569 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/BrokenOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/BrokenOutputStream.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. diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ByteArrayOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ByteArrayOutputStream.java index dba1b6576..2c02f4e93 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ByteArrayOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ByteArrayOutputStream.java @@ -16,8 +16,6 @@ */ package com.fr.third.org.apache.commons.io.output; -import static com.fr.third.org.apache.commons.io.IOUtils.EOF; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -31,7 +29,6 @@ import java.util.List; import com.fr.third.org.apache.commons.io.IOUtils; import com.fr.third.org.apache.commons.io.input.ClosedInputStream; -import com.fr.third.org.apache.commons.io.input.ClosedInputStream; /** * This class implements an output stream in which the data is @@ -54,16 +51,15 @@ import com.fr.third.org.apache.commons.io.input.ClosedInputStream; * designed to behave exactly like the original. The only exception is the * deprecated toString(int) method that has been ignored. * + * @version $Id: ByteArrayOutputStream.java 1612034 2014-07-20 06:35:19Z ggregory $ */ public class ByteArrayOutputStream extends OutputStream { - static final int DEFAULT_SIZE = 1024; - /** A singleton empty byte array. */ private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; /** The list of buffers, which grows and never reduces. */ - private final List buffers = new ArrayList<>(); + private final List buffers = new ArrayList(); /** The index of the current buffer. */ private int currentBufferIndex; /** The total count of bytes in all the filled buffers. */ @@ -80,7 +76,7 @@ public class ByteArrayOutputStream extends OutputStream { * initially 1024 bytes, though its size increases if necessary. */ public ByteArrayOutputStream() { - this(DEFAULT_SIZE); + this(1024); } /** @@ -242,7 +238,7 @@ public class ByteArrayOutputStream extends OutputStream { } else { //Throw away old buffers currentBuffer = null; - final int size = buffers.get(0).length; + int size = buffers.get(0).length; buffers.clear(); needNewBuffer(size); reuseBuffers = true; @@ -317,7 +313,7 @@ public class ByteArrayOutputStream extends OutputStream { * @throws IOException if an I/O error occurs * @since 2.5 */ - public static InputStream toBufferedInputStream(final InputStream input, final int size) + public static InputStream toBufferedInputStream(final InputStream input, int size) throws IOException { // It does not matter if a ByteArrayOutputStream is not closed as close() is a no-op @SuppressWarnings("resource") @@ -341,7 +337,7 @@ public class ByteArrayOutputStream extends OutputStream { if (remaining == 0) { return new ClosedInputStream(); } - final List list = new ArrayList<>(buffers.size()); + final List list = new ArrayList(buffers.size()); for (final byte[] buf : buffers) { final int c = Math.min(buf.length, remaining); list.add(new ByteArrayInputStream(buf, 0, c)); @@ -355,7 +351,7 @@ public class ByteArrayOutputStream extends OutputStream { } /** - * Gets the current contents of this byte stream as a byte array. + * Gets the curent contents of this byte stream as a byte array. * The result is independent of this stream. * * @return the current contents of this output stream, as a byte array @@ -381,7 +377,7 @@ public class ByteArrayOutputStream extends OutputStream { } /** - * Gets the current contents of this byte stream as a string + * Gets the curent contents of this byte stream as a string * using the platform default charset. * @return the contents of the byte array as a String * @see java.io.ByteArrayOutputStream#toString() @@ -395,7 +391,7 @@ public class ByteArrayOutputStream extends OutputStream { } /** - * Gets the current contents of this byte stream as a string + * Gets the curent contents of this byte stream as a string * using the specified encoding. * * @param enc the name of the character encoding @@ -408,7 +404,7 @@ public class ByteArrayOutputStream extends OutputStream { } /** - * Gets the current contents of this byte stream as a string + * Gets the curent contents of this byte stream as a string * using the specified encoding. * * @param charset the character encoding diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedOutputStream.java index 216bdb747..d8ef6c3b4 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedOutputStream.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. @@ -46,7 +46,7 @@ public class ChunkedOutputStream extends FilterOutputStream { * @param chunkSize the chunk size to use; must be a positive number. * @throws IllegalArgumentException if the chunk size is <= 0 */ - public ChunkedOutputStream(final OutputStream stream, final int chunkSize) { + public ChunkedOutputStream(final OutputStream stream, int chunkSize) { super(stream); if (chunkSize <= 0) { throw new IllegalArgumentException(); @@ -56,7 +56,7 @@ public class ChunkedOutputStream extends FilterOutputStream { /** * Creates a new stream that uses a chunk size of {@link #DEFAULT_CHUNK_SIZE}. - * + * * @param stream the stream to wrap */ public ChunkedOutputStream(final OutputStream stream) { @@ -73,11 +73,11 @@ public class ChunkedOutputStream extends FilterOutputStream { * @throws IOException if an I/O error occurs. */ @Override - public void write(final byte[] data, final int srcOffset, final int length) throws IOException { + public void write(byte[] data, int srcOffset, int length) throws IOException { int bytes = length; int dstOffset = srcOffset; while(bytes > 0) { - final int chunk = Math.min(bytes, chunkSize); + int chunk = Math.min(bytes, chunkSize); out.write(data, dstOffset, chunk); bytes -= chunk; dstOffset += chunk; diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedWriter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedWriter.java index 0bc8eece5..08b31589a 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedWriter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedWriter.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. @@ -46,7 +46,7 @@ public class ChunkedWriter extends FilterWriter { * @param chunkSize the chunk size to use; must be a positive number. * @throws IllegalArgumentException if the chunk size is <= 0 */ - public ChunkedWriter(final Writer writer, final int chunkSize) { + public ChunkedWriter(final Writer writer, int chunkSize) { super(writer); if (chunkSize <= 0) { throw new IllegalArgumentException(); @@ -71,11 +71,11 @@ public class ChunkedWriter extends FilterWriter { * @throws IOException upon error */ @Override - public void write(final char[] data, final int srcOffset, final int length) throws IOException { + public void write(char[] data, int srcOffset, int length) throws IOException { int bytes = length; int dstOffset = srcOffset; while(bytes > 0) { - final int chunk = Math.min(bytes, chunkSize); + int chunk = Math.min(bytes, chunkSize); out.write(data, dstOffset, chunk); bytes -= chunk; dstOffset += chunk; diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CloseShieldOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CloseShieldOutputStream.java index 50d19bd8d..b2b14ba2f 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CloseShieldOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CloseShieldOutputStream.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,7 +25,7 @@ import java.io.OutputStream; * passed to a component that wants to explicitly close the stream even if * other components would still use the stream for output. *

    - * @version $Id$ + * @version $Id: CloseShieldOutputStream.java 1674710 2015-04-20 00:25:55Z ggregory $ * @since 1.4 */ public class CloseShieldOutputStream extends ProxyOutputStream { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ClosedOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ClosedOutputStream.java index 90773eb08..ca22c63ec 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ClosedOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ClosedOutputStream.java @@ -27,6 +27,7 @@ import java.io.OutputStream; * that accept an output stream and acting as a sentinel value instead of * a {@code null} output stream. * + * @version $Id: ClosedOutputStream.java 1471767 2013-04-24 23:24:19Z sebb $ * @since 1.4 */ public class ClosedOutputStream extends OutputStream { @@ -47,13 +48,4 @@ public class ClosedOutputStream extends OutputStream { throw new IOException("write(" + b + ") failed: stream is closed"); } - /** - * Throws an {@link IOException} to indicate that the stream is closed. - * - * @throws IOException always thrown - */ - @Override - public void flush() throws IOException { - throw new IOException("flush() failed: stream is closed"); - } } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CountingOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CountingOutputStream.java index 50b4e3afe..45140a8e0 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CountingOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CountingOutputStream.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.io.OutputStream; * A typical use case would be during debugging, to ensure that data is being * written as expected. * + * @version $Id: CountingOutputStream.java 1415850 2012-11-30 20:51:39Z ggregory $ */ public class CountingOutputStream extends ProxyOutputStream { @@ -33,7 +34,7 @@ public class CountingOutputStream extends ProxyOutputStream { /** * Constructs a new CountingOutputStream. - * + * * @param out the OutputStream to write to */ public CountingOutputStream( final OutputStream out ) { @@ -72,8 +73,8 @@ public class CountingOutputStream extends ProxyOutputStream { return (int) result; } - /** - * Set the byte count back to 0. + /** + * Set the byte count back to 0. *

    * NOTE: From v1.3 this method throws an ArithmeticException if the * count is greater than can be expressed by an int. @@ -104,8 +105,8 @@ public class CountingOutputStream extends ProxyOutputStream { return this.count; } - /** - * Set the byte count back to 0. + /** + * Set the byte count back to 0. *

    * NOTE: This method is an alternative for resetCount(). * It was added because that method returns an integer which will diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DeferredFileOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DeferredFileOutputStream.java index b0415d3f1..a413b0c88 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DeferredFileOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DeferredFileOutputStream.java @@ -22,9 +22,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import com.fr.third.org.apache.commons.io.FileUtils; -import com.fr.third.org.apache.commons.io.IOUtils; -import com.fr.third.org.apache.commons.io.FileUtils; import com.fr.third.org.apache.commons.io.IOUtils; @@ -39,15 +36,17 @@ import com.fr.third.org.apache.commons.io.IOUtils; * you want to store it in memory (for speed), but if the file is large you want * to store it to file (to avoid memory issues). * + * @version $Id: DeferredFileOutputStream.java 1686747 2015-06-21 18:44:49Z krosenvold $ */ public class DeferredFileOutputStream extends ThresholdingOutputStream { + // ----------------------------------------------------------- Data members /** - * The output stream to which data will be written prior to the threshold + * The output stream to which data will be written prior to the theshold * being reached. */ private ByteArrayOutputStream memoryOutputStream; @@ -93,38 +92,19 @@ public class DeferredFileOutputStream /** * Constructs an instance of this class which will trigger an event at the * specified threshold, and save data to a file beyond that point. - * The initial buffer size will default to 1024 bytes which is ByteArrayOutputStream's default buffer size. * * @param threshold The number of bytes at which to trigger an event. * @param outputFile The file to which data is saved beyond the threshold. */ public DeferredFileOutputStream(final int threshold, final File outputFile) { - this(threshold, outputFile, null, null, null, ByteArrayOutputStream.DEFAULT_SIZE); + this(threshold, outputFile, null, null, null); } - /** - * Constructs an instance of this class which will trigger an event at the - * specified threshold, and save data to a file beyond that point. - * - * @param threshold The number of bytes at which to trigger an event. - * @param initialBufferSize The initial size of the in memory buffer. - * @param outputFile The file to which data is saved beyond the threshold. - * - * @since 2.5 - */ - public DeferredFileOutputStream(final int threshold, final int initialBufferSize, final File outputFile) - { - this(threshold, outputFile, null, null, null, initialBufferSize); - if (initialBufferSize < 0) { - throw new IllegalArgumentException("Initial buffer size must be atleast 0."); - } - } /** * Constructs an instance of this class which will trigger an event at the * specified threshold, and save data to a temporary file beyond that point. - * The initial buffer size will default to 32 bytes which is ByteArrayOutputStream's default buffer size. * * @param threshold The number of bytes at which to trigger an event. * @param prefix Prefix to use for the temporary file. @@ -135,34 +115,10 @@ public class DeferredFileOutputStream */ public DeferredFileOutputStream(final int threshold, final String prefix, final String suffix, final File directory) { - this(threshold, null, prefix, suffix, directory, ByteArrayOutputStream.DEFAULT_SIZE); - if (prefix == null) { - throw new IllegalArgumentException("Temporary file prefix is missing"); - } - } - - /** - * Constructs an instance of this class which will trigger an event at the - * specified threshold, and save data to a temporary file beyond that point. - * - * @param threshold The number of bytes at which to trigger an event. - * @param initialBufferSize The initial size of the in memory buffer. - * @param prefix Prefix to use for the temporary file. - * @param suffix Suffix to use for the temporary file. - * @param directory Temporary file directory. - * - * @since 2.5 - */ - public DeferredFileOutputStream(final int threshold, final int initialBufferSize, final String prefix, - final String suffix, final File directory) - { - this(threshold, null, prefix, suffix, directory, initialBufferSize); + this(threshold, null, prefix, suffix, directory); if (prefix == null) { throw new IllegalArgumentException("Temporary file prefix is missing"); } - if (initialBufferSize < 0) { - throw new IllegalArgumentException("Initial buffer size must be atleast 0."); - } } /** @@ -174,18 +130,17 @@ public class DeferredFileOutputStream * @param prefix Prefix to use for the temporary file. * @param suffix Suffix to use for the temporary file. * @param directory Temporary file directory. - * @param initialBufferSize The initial size of the in memory buffer. */ private DeferredFileOutputStream(final int threshold, final File outputFile, final String prefix, - final String suffix, final File directory, final int initialBufferSize) { + final String suffix, final File directory) { super(threshold); this.outputFile = outputFile; + + memoryOutputStream = new ByteArrayOutputStream(); + currentOutputStream = memoryOutputStream; this.prefix = prefix; this.suffix = suffix; this.directory = directory; - - memoryOutputStream = new ByteArrayOutputStream(initialBufferSize); - currentOutputStream = memoryOutputStream; } @@ -198,7 +153,7 @@ public class DeferredFileOutputStream * * @return The underlying output stream. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ @Override protected OutputStream getStream() throws IOException @@ -213,7 +168,7 @@ public class DeferredFileOutputStream * much data is being written to keep in memory, so we elect to switch to * disk-based storage. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ @Override protected void thresholdReached() throws IOException @@ -221,11 +176,10 @@ public class DeferredFileOutputStream if (prefix != null) { outputFile = File.createTempFile(prefix, suffix, directory); } - FileUtils.forceMkdirParent(outputFile); final FileOutputStream fos = new FileOutputStream(outputFile); try { memoryOutputStream.writeTo(fos); - } catch (final IOException e){ + } catch (IOException e){ fos.close(); throw e; } @@ -291,7 +245,7 @@ public class DeferredFileOutputStream /** * Closes underlying output stream, and mark this as closed * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ @Override public void close() throws IOException @@ -306,22 +260,29 @@ public class DeferredFileOutputStream * after it has been closed. * * @param out output stream to write to. - * @throws IOException if this stream is not yet closed or an error occurs. + * @exception IOException if this stream is not yet closed or an error occurs. */ public void writeTo(final OutputStream out) throws IOException { // we may only need to check if this is closed if we are working with a file // but we should force the habit of closing wether we are working with // a file or memory. - if (!closed) { + if (!closed) + { throw new IOException("Stream not closed"); } - if (isInMemory()) { + if(isInMemory()) + { memoryOutputStream.writeTo(out); - } else { - try (FileInputStream fis = new FileInputStream(outputFile)) { + } + else + { + final FileInputStream fis = new FileInputStream(outputFile); + try { IOUtils.copy(fis, out); + } finally { + IOUtils.closeQuietly(fis); } } } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DemuxOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DemuxOutputStream.java index 9c0075e12..40efdf229 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DemuxOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DemuxOutputStream.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. @@ -22,9 +22,10 @@ import java.io.OutputStream; /** * Forwards data to a stream that has been associated with this thread. * + * @version $Id: DemuxOutputStream.java 1737901 2016-04-06 00:23:36Z ggregory $ */ public class DemuxOutputStream extends OutputStream { - private final InheritableThreadLocal outputStreamThreadLocal = new InheritableThreadLocal<>(); + private final InheritableThreadLocal outputStreamThreadLocal = new InheritableThreadLocal(); /** * Binds the specified stream to the current thread. diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/FileWriterWithEncoding.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/FileWriterWithEncoding.java index e7c83c3d1..31a605962 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/FileWriterWithEncoding.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/FileWriterWithEncoding.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. @@ -26,7 +26,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import com.fr.third.org.apache.commons.io.FileUtils; -import com.fr.third.org.apache.commons.io.FileUtils; +import com.fr.third.org.apache.commons.io.IOUtils; /** * Writer of files that allows the encoding to be set. @@ -42,10 +42,10 @@ import com.fr.third.org.apache.commons.io.FileUtils; * is required then use the {@link java.io.FileWriter} directly, rather than * this implementation. *

    - * + * * * @since 1.4 - * @version $Id$ + * @version $Id: FileWriterWithEncoding.java 1686747 2015-06-21 18:44:49Z krosenvold $ */ public class FileWriterWithEncoding extends Writer { // Cannot extend ProxyWriter, as requires writer to be @@ -230,30 +230,34 @@ public class FileWriterWithEncoding extends Writer { if (encoding == null) { throw new NullPointerException("Encoding is missing"); } - OutputStream stream = null; final boolean fileExistedAlready = file.exists(); + OutputStream stream = null; + Writer writer = null; try { stream = new FileOutputStream(file, append); if (encoding instanceof Charset) { - return new OutputStreamWriter(stream, (Charset)encoding); + writer = new OutputStreamWriter(stream, (Charset)encoding); } else if (encoding instanceof CharsetEncoder) { - return new OutputStreamWriter(stream, (CharsetEncoder)encoding); + writer = new OutputStreamWriter(stream, (CharsetEncoder)encoding); } else { - return new OutputStreamWriter(stream, (String)encoding); + writer = new OutputStreamWriter(stream, (String)encoding); } - } catch (final IOException | RuntimeException ex) { - try { - if (stream != null) { - stream.close(); - } - } catch (final IOException e) { - ex.addSuppressed(e); + } catch (final IOException ex) { + IOUtils.closeQuietly(writer); + IOUtils.closeQuietly(stream); + if (fileExistedAlready == false) { + FileUtils.deleteQuietly(file); } + throw ex; + } catch (final RuntimeException ex) { + IOUtils.closeQuietly(writer); + IOUtils.closeQuietly(stream); if (fileExistedAlready == false) { FileUtils.deleteQuietly(file); } throw ex; } + return writer; } //----------------------------------------------------------------------- diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/LockableFileWriter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/LockableFileWriter.java index 48db4f422..166448024 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/LockableFileWriter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/LockableFileWriter.java @@ -19,14 +19,14 @@ package com.fr.third.org.apache.commons.io.output; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.Charset; import com.fr.third.org.apache.commons.io.Charsets; import com.fr.third.org.apache.commons.io.FileUtils; -import com.fr.third.org.apache.commons.io.Charsets; -import com.fr.third.org.apache.commons.io.FileUtils; +import com.fr.third.org.apache.commons.io.IOUtils; /** * FileWriter that will create and honor lock files to allow simple @@ -46,6 +46,7 @@ import com.fr.third.org.apache.commons.io.FileUtils; * java.io.tmpdir. * The encoding may also be specified, and defaults to the platform default. * + * @version $Id: LockableFileWriter.java 1686747 2015-06-21 18:44:49Z krosenvold $ */ public class LockableFileWriter extends Writer { // Cannot extend ProxyWriter, as requires writer to be @@ -266,17 +267,29 @@ public class LockableFileWriter extends Writer { */ private Writer initWriter(final File file, final Charset encoding, final boolean append) throws IOException { final boolean fileExistedAlready = file.exists(); + OutputStream stream = null; + Writer writer = null; try { - return new OutputStreamWriter(new FileOutputStream(file.getAbsolutePath(), append), - Charsets.toCharset(encoding)); - - } catch (final IOException | RuntimeException ex) { + stream = new FileOutputStream(file.getAbsolutePath(), append); + writer = new OutputStreamWriter(stream, Charsets.toCharset(encoding)); + } catch (final IOException ex) { + IOUtils.closeQuietly(writer); + IOUtils.closeQuietly(stream); + FileUtils.deleteQuietly(lockFile); + if (fileExistedAlready == false) { + FileUtils.deleteQuietly(file); + } + throw ex; + } catch (final RuntimeException ex) { + IOUtils.closeQuietly(writer); + IOUtils.closeQuietly(stream); FileUtils.deleteQuietly(lockFile); if (fileExistedAlready == false) { FileUtils.deleteQuietly(file); } throw ex; } + return writer; } //----------------------------------------------------------------------- diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/NullOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/NullOutputStream.java index 86b721c0a..0aced044d 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/NullOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/NullOutputStream.java @@ -25,7 +25,7 @@ import java.io.OutputStream; * This output stream has no destination (file/socket etc.) and all * bytes written to it are ignored and lost. *

    - * @version $Id$ + * @version $Id: NullOutputStream.java 1674708 2015-04-20 00:02:45Z ggregory $ */ public class NullOutputStream extends OutputStream { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/NullWriter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/NullWriter.java index 8840bb715..7201bfacd 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/NullWriter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/NullWriter.java @@ -24,6 +24,7 @@ import java.io.Writer; * This Writer has no destination (file/socket etc.) and all * characters written to it are ignored and lost. * + * @version $Id: NullWriter.java 1471767 2013-04-24 23:24:19Z sebb $ */ public class NullWriter extends Writer { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ProxyOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ProxyOutputStream.java index ddcd52dfd..2652942ea 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ProxyOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ProxyOutputStream.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,20 +21,21 @@ import java.io.IOException; import java.io.OutputStream; /** - * A Proxy stream which acts as expected, that is it passes the method - * calls on to the proxied stream and doesn't change which methods are + * A Proxy stream which acts as expected, that is it passes the method + * calls on to the proxied stream and doesn't change which methods are * being called. It is an alternative base class to FilterOutputStream * to increase reusability. *

    * See the protected methods for ways in which a subclass can easily decorate * a stream with custom pre-, post- or error processing functionality. - * + * + * @version $Id: ProxyOutputStream.java 1415850 2012-11-30 20:51:39Z ggregory $ */ public class ProxyOutputStream extends FilterOutputStream { /** * Constructs a new ProxyOutputStream. - * + * * @param proxy the OutputStream to delegate to */ public ProxyOutputStream(final OutputStream proxy) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ProxyWriter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ProxyWriter.java index 5cc11f13f..1db106b81 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ProxyWriter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ProxyWriter.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,19 +21,20 @@ import java.io.IOException; import java.io.Writer; /** - * A Proxy stream which acts as expected, that is it passes the method - * calls on to the proxied stream and doesn't change which methods are + * A Proxy stream which acts as expected, that is it passes the method + * calls on to the proxied stream and doesn't change which methods are * being called. It is an alternative base class to FilterWriter - * to increase reusability, because FilterWriter changes the + * to increase reusability, because FilterWriter changes the * methods being called, such as write(char[]) to write(char[], int, int) * and write(String) to write(String, int, int). - * + * + * @version $Id: ProxyWriter.java 1415850 2012-11-30 20:51:39Z ggregory $ */ public class ProxyWriter extends FilterWriter { /** * Constructs a new ProxyWriter. - * + * * @param proxy the Writer to delegate to */ public ProxyWriter(final Writer proxy) { diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/StringBuilderWriter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/StringBuilderWriter.java index a6e805ee6..56c647d9c 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/StringBuilderWriter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/StringBuilderWriter.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. @@ -28,6 +28,7 @@ import java.io.Writer; * For safe usage with multiple {@link Thread}s then * java.io.StringWriter should be used. * + * @version $Id: StringBuilderWriter.java 1722253 2015-12-30 00:36:12Z ggregory $ * @since 2.0 */ public class StringBuilderWriter extends Writer implements Serializable { @@ -53,7 +54,7 @@ public class StringBuilderWriter extends Writer implements Serializable { /** * Constructs a new instance with the specified {@link StringBuilder}. - * + * *

    If {@code builder} is null a new instance with default capacity will be created.

    * * @param builder The String builder. May be null. @@ -101,7 +102,7 @@ public class StringBuilderWriter extends Writer implements Serializable { } /** - * Closing this writer has no effect. + * Closing this writer has no effect. */ @Override public void close() { @@ -109,7 +110,7 @@ public class StringBuilderWriter extends Writer implements Serializable { } /** - * Flushing this writer has no effect. + * Flushing this writer has no effect. */ @Override public void flush() { @@ -119,7 +120,7 @@ public class StringBuilderWriter extends Writer implements Serializable { /** * Writes a String to the {@link StringBuilder}. - * + * * @param value The value to write */ @Override diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/TaggedOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/TaggedOutputStream.java index 6bfaa9fe2..e7f97250b 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/TaggedOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/TaggedOutputStream.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,6 @@ import java.io.OutputStream; import java.io.Serializable; import java.util.UUID; -import com.fr.third.org.apache.commons.io.TaggedIOException; import com.fr.third.org.apache.commons.io.TaggedIOException; /** diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/TeeOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/TeeOutputStream.java index 3efe38fa1..e9bab97eb 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/TeeOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/TeeOutputStream.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,10 +20,11 @@ import java.io.IOException; import java.io.OutputStream; /** - * Classic splitter of OutputStream. Named after the unix 'tee' - * command. It allows a stream to be branched off so there + * Classic splitter of OutputStream. Named after the unix 'tee' + * command. It allows a stream to be branched off so there * are now two streams. * + * @version $Id: TeeOutputStream.java 1686503 2015-06-19 21:32:13Z sebb $ */ public class TeeOutputStream extends ProxyOutputStream { @@ -87,12 +88,12 @@ public class TeeOutputStream extends ProxyOutputStream { /** * Closes both output streams. - * + * * If closing the main output stream throws an exception, attempt to close the branch output stream. - * + * * If closing the main and branch output streams both throw exceptions, which exceptions is thrown by this method is * currently unspecified and subject to change. - * + * * @throws IOException * if an I/O error occurs */ diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ThresholdingOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ThresholdingOutputStream.java index 30b5de1e1..56e77b61b 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ThresholdingOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ThresholdingOutputStream.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. @@ -34,6 +34,7 @@ import java.io.OutputStream; * is actually reached, since it triggers when a pending write operation would * cause the threshold to be exceeded. * + * @version $Id: ThresholdingOutputStream.java 1687815 2015-06-26 17:18:56Z krosenvold $ */ public abstract class ThresholdingOutputStream extends OutputStream @@ -83,7 +84,7 @@ public abstract class ThresholdingOutputStream * * @param b The byte to be written. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ @Override public void write(final int b) throws IOException @@ -100,7 +101,7 @@ public abstract class ThresholdingOutputStream * * @param b The array of bytes to be written. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ @Override public void write(final byte b[]) throws IOException @@ -119,7 +120,7 @@ public abstract class ThresholdingOutputStream * @param off The start offset in the byte array. * @param len The number of bytes to write. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ @Override public void write(final byte b[], final int off, final int len) throws IOException @@ -134,7 +135,7 @@ public abstract class ThresholdingOutputStream * Flushes this output stream and forces any buffered output bytes to be * written out. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ @Override public void flush() throws IOException @@ -147,7 +148,7 @@ public abstract class ThresholdingOutputStream * Closes this output stream and releases any system resources associated * with this stream. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ @Override public void close() throws IOException @@ -213,7 +214,7 @@ public abstract class ThresholdingOutputStream * @param count The number of bytes about to be written to the underlying * output stream. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ protected void checkThreshold(final int count) throws IOException { @@ -225,18 +226,18 @@ public abstract class ThresholdingOutputStream } /** - * Resets the byteCount to zero. You can call this from - * {@link #thresholdReached()} if you want the event to be triggered again. + * Resets the byteCount to zero. You can call this from + * {@link #thresholdReached()} if you want the event to be triggered again. */ - protected void resetByteCount() + protected void resetByteCount() { this.thresholdExceeded = false; this.written = 0; } /** - * Sets the byteCount to count. Useful for re-opening an output stream - * that has previously been written to. + * Sets the byteCount to count. Usefull for re-opening an output stream + * that been previously written to. * * @param count The number of bytes that have already been written to the * output stream @@ -257,7 +258,7 @@ public abstract class ThresholdingOutputStream * * @return The underlying output stream. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ protected abstract OutputStream getStream() throws IOException; @@ -267,7 +268,7 @@ public abstract class ThresholdingOutputStream * subclass should take whatever action necessary on this event. This may * include changing the underlying output stream. * - * @throws IOException if an error occurs. + * @exception IOException if an error occurs. */ protected abstract void thresholdReached() throws IOException; } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/WriterOutputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/WriterOutputStream.java index b97596604..1eb6f82ef 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/WriterOutputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/WriterOutputStream.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. @@ -67,9 +67,9 @@ import java.nio.charset.CodingErrorAction; * character data that must be decoded for further use. *

    * Instances of {@link WriterOutputStream} are not thread safe. - * + * * @see ReaderInputStream - * + * * @since 2.0 */ public class WriterOutputStream extends OutputStream { @@ -97,7 +97,7 @@ public class WriterOutputStream extends OutputStream { * Constructs a new {@link WriterOutputStream} with a default output buffer size of * 1024 characters. The output buffer will only be flushed when it overflows or when * {@link #flush()} or {@link #close()} is called. - * + * * @param writer the target {@link Writer} * @param decoder the charset decoder * @since 2.1 @@ -108,7 +108,7 @@ public class WriterOutputStream extends OutputStream { /** * Constructs a new {@link WriterOutputStream}. - * + * * @param writer the target {@link Writer} * @param decoder the charset decoder * @param bufferSize the size of the output buffer in number of characters @@ -130,7 +130,7 @@ public class WriterOutputStream extends OutputStream { /** * Constructs a new {@link WriterOutputStream}. - * + * * @param writer the target {@link Writer} * @param charset the charset encoding * @param bufferSize the size of the output buffer in number of characters @@ -155,7 +155,7 @@ public class WriterOutputStream extends OutputStream { * Constructs a new {@link WriterOutputStream} with a default output buffer size of * 1024 characters. The output buffer will only be flushed when it overflows or when * {@link #flush()} or {@link #close()} is called. - * + * * @param writer the target {@link Writer} * @param charset the charset encoding */ @@ -165,7 +165,7 @@ public class WriterOutputStream extends OutputStream { /** * Constructs a new {@link WriterOutputStream}. - * + * * @param writer the target {@link Writer} * @param charsetName the name of the charset encoding * @param bufferSize the size of the output buffer in number of characters @@ -184,7 +184,7 @@ public class WriterOutputStream extends OutputStream { * Constructs a new {@link WriterOutputStream} with a default output buffer size of * 1024 characters. The output buffer will only be flushed when it overflows or when * {@link #flush()} or {@link #close()} is called. - * + * * @param writer the target {@link Writer} * @param charsetName the name of the charset encoding */ @@ -196,7 +196,7 @@ public class WriterOutputStream extends OutputStream { * Constructs a new {@link WriterOutputStream} that uses the default character encoding * and with a default output buffer size of 1024 characters. The output buffer will only * be flushed when it overflows or when {@link #flush()} or {@link #close()} is called. - * + * * @param writer the target {@link Writer} * @deprecated 2.5 use {@link #WriterOutputStream(Writer, Charset)} instead */ @@ -207,7 +207,7 @@ public class WriterOutputStream extends OutputStream { /** * Write bytes from the specified byte array to the stream. - * + * * @param b the byte array containing the bytes to write * @param off the start offset in the byte array * @param len the number of bytes to write @@ -229,7 +229,7 @@ public class WriterOutputStream extends OutputStream { /** * Write bytes from the specified byte array to the stream. - * + * * @param b the byte array containing the bytes to write * @throws IOException if an I/O error occurs */ @@ -240,7 +240,7 @@ public class WriterOutputStream extends OutputStream { /** * Write a single byte to the stream. - * + * * @param b the byte to write * @throws IOException if an I/O error occurs */ @@ -252,7 +252,7 @@ public class WriterOutputStream extends OutputStream { /** * Flush the stream. Any remaining content accumulated in the output buffer * will be written to the underlying {@link Writer}. After that - * {@link Writer#flush()} will be called. + * {@link Writer#flush()} will be called. * @throws IOException if an I/O error occurs */ @Override @@ -264,7 +264,7 @@ public class WriterOutputStream extends OutputStream { /** * Close the stream. Any remaining content accumulated in the output buffer * will be written to the underlying {@link Writer}. After that - * {@link Writer#close()} will be called. + * {@link Writer#close()} will be called. * @throws IOException if an I/O error occurs */ @Override @@ -276,7 +276,7 @@ public class WriterOutputStream extends OutputStream { /** * Decode the contents of the input ByteBuffer into a CharBuffer. - * + * * @param endOfInput indicates end of input * @throws IOException if an I/O error occurs */ @@ -302,7 +302,7 @@ public class WriterOutputStream extends OutputStream { /** * Flush the output. - * + * * @throws IOException if an I/O error occurs */ private void flushOutput() throws IOException { @@ -312,28 +312,21 @@ public class WriterOutputStream extends OutputStream { } } - /** - * Check if the JDK in use properly supports the given charset. - * - * @param charset the charset to check the support for - */ - private static void checkIbmJdkWithBrokenUTF16(final Charset charset){ - if (!"UTF-16".equals(charset.name())) { - return; - } + private static void checkIbmJdkWithBrokenUTF16(Charset charset){ + if (!"UTF-16".equals(charset.name())) return; final String TEST_STRING_2 = "v\u00e9s"; - final byte[] bytes = TEST_STRING_2.getBytes(charset); + byte[] bytes = TEST_STRING_2.getBytes(charset); final CharsetDecoder charsetDecoder2 = charset.newDecoder(); - final ByteBuffer bb2 = ByteBuffer.allocate(16); - final CharBuffer cb2 = CharBuffer.allocate(TEST_STRING_2.length()); + ByteBuffer bb2 = ByteBuffer.allocate(16); + CharBuffer cb2 = CharBuffer.allocate(TEST_STRING_2.length()); final int len = bytes.length; for (int i = 0; i < len; i++) { bb2.put(bytes[i]); bb2.flip(); try { charsetDecoder2.decode(bb2, cb2, i == (len - 1)); - } catch ( final IllegalArgumentException e){ + } catch ( IllegalArgumentException e){ throw new UnsupportedOperationException("UTF-16 requested when runninng on an IBM JDK with broken UTF-16 support. " + "Please find a JDK that supports UTF-16 if you intend to use UF-16 with WriterOutputStream"); } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/XmlStreamWriter.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/XmlStreamWriter.java index edc0af181..3f4c25e4a 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/XmlStreamWriter.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/output/XmlStreamWriter.java @@ -27,13 +27,13 @@ import java.io.Writer; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.fr.third.org.apache.commons.io.input.XmlStreamReader; import com.fr.third.org.apache.commons.io.input.XmlStreamReader; /** - * Character stream that handles all the necessary Voodoo to figure out the + * Character stream that handles all the necessary Voodo to figure out the * charset encoding of the XML document written to the stream. * + * @version $Id: XmlStreamWriter.java 1415850 2012-11-30 20:51:39Z ggregory $ * @see XmlStreamReader * @since 2.0 */ @@ -51,7 +51,7 @@ public class XmlStreamWriter extends Writer { private String encoding; /** - * Constructs a new XML stream writer for the specified output stream + * Construct an new XML stream writer for the specified output stream * with a default encoding of UTF-8. * * @param out The output stream @@ -61,7 +61,7 @@ public class XmlStreamWriter extends Writer { } /** - * Constructs a new XML stream writer for the specified output stream + * Construct an new XML stream writer for the specified output stream * with the specified default encoding. * * @param out The output stream @@ -73,9 +73,9 @@ public class XmlStreamWriter extends Writer { } /** - * Constructs a new XML stream writer for the specified file + * Construct an new XML stream writer for the specified file * with a default encoding of UTF-8. - * + * * @param file The file to write to * @throws FileNotFoundException if there is an error creating or * opening the file @@ -85,9 +85,9 @@ public class XmlStreamWriter extends Writer { } /** - * Constructs a new XML stream writer for the specified file + * Construct an new XML stream writer for the specified file * with the specified default encoding. - * + * * @param file The file to write to * @param defaultEncoding The default encoding if not encoding could be detected * @throws FileNotFoundException if there is an error creating or @@ -98,7 +98,7 @@ public class XmlStreamWriter extends Writer { } /** - * Returns the detected encoding. + * Return the detected encoding. * * @return the detected encoding */ @@ -107,7 +107,7 @@ public class XmlStreamWriter extends Writer { } /** - * Returns the default encoding. + * Return the default encoding. * * @return the default encoding */ @@ -116,7 +116,7 @@ public class XmlStreamWriter extends Writer { } /** - * Closes the underlying writer. + * Close the underlying writer. * * @throws IOException if an error occurs closing the underlying writer */ @@ -131,7 +131,7 @@ public class XmlStreamWriter extends Writer { } /** - * Flushes the underlying writer. + * Flush the underlying writer. * * @throws IOException if an error occurs flushing the underlying writer */ @@ -143,7 +143,7 @@ public class XmlStreamWriter extends Writer { } /** - * Detects the encoding. + * Detect the encoding. * * @param cbuf the buffer to write the characters from * @param off The start offset @@ -200,8 +200,8 @@ public class XmlStreamWriter extends Writer { } /** - * Writes the characters to the underlying writer, detecting encoding. - * + * Write the characters to the underlying writer, detecing encoding. + * * @param cbuf the buffer to write the characters from * @param off The start offset * @param len The number of characters to write diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/ClassNameMatcher.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/ClassNameMatcher.java index 8b9360a97..e051bdb06 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/ClassNameMatcher.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/ClassNameMatcher.java @@ -24,8 +24,8 @@ package com.fr.third.org.apache.commons.io.serialization; public interface ClassNameMatcher { /** - * Returns true if the supplied class name matches this object's condition. - * + * Returns true if the supplied class name matches this object's condition. + * * @param className fully qualified class name * @return true if the class name matches this object's condition */ diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/FullClassNameMatcher.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/FullClassNameMatcher.java index 45b5c9f6f..bd927013b 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/FullClassNameMatcher.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/FullClassNameMatcher.java @@ -35,15 +35,15 @@ final class FullClassNameMatcher implements ClassNameMatcher { /** * Constructs an object based on the specified class names. - * + * * @param classes a list of class names */ - public FullClassNameMatcher(final String... classes) { - classesSet = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(classes))); + public FullClassNameMatcher(String... classes) { + classesSet = Collections.unmodifiableSet(new HashSet(Arrays.asList(classes))); } @Override - public boolean matches(final String className) { + public boolean matches(String className) { return classesSet.contains(className); } } \ No newline at end of file diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/RegexpClassNameMatcher.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/RegexpClassNameMatcher.java index bb8995f5d..a9436ecdf 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/RegexpClassNameMatcher.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/RegexpClassNameMatcher.java @@ -32,20 +32,20 @@ final class RegexpClassNameMatcher implements ClassNameMatcher { /** * Constructs an object based on the specified regular expression. - * + * * @param regex a regular expression for evaluating acceptable class names */ - public RegexpClassNameMatcher(final String regex) { + public RegexpClassNameMatcher(String regex) { this(Pattern.compile(regex)); } /** * Constructs an object based on the specified pattern. - * + * * @param pattern a pattern for evaluating acceptable class names * @throws IllegalArgumentException if pattern is null */ - public RegexpClassNameMatcher(final Pattern pattern) { + public RegexpClassNameMatcher(Pattern pattern) { if (pattern == null) { throw new IllegalArgumentException("Null pattern"); } @@ -53,7 +53,7 @@ final class RegexpClassNameMatcher implements ClassNameMatcher { } @Override - public boolean matches(final String className) { + public boolean matches(String className) { return pattern.matcher(className).matches(); } } \ No newline at end of file diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/ValidatingObjectInputStream.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/ValidatingObjectInputStream.java index 780425e3b..19e1810e5 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/ValidatingObjectInputStream.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/ValidatingObjectInputStream.java @@ -37,7 +37,7 @@ import java.util.regex.Pattern; * Various accept/reject methods allow for specifying which classes * can be deserialized. *

    - * + * *

    * Design inspired by IBM @@ -45,19 +45,19 @@ import java.util.regex.Pattern; *

    */ public class ValidatingObjectInputStream extends ObjectInputStream { - private final List acceptMatchers = new ArrayList<>(); - private final List rejectMatchers = new ArrayList<>(); + private final List acceptMatchers = new ArrayList(); + private final List rejectMatchers = new ArrayList(); /** * Constructs an object to deserialize the specified input stream. * At least one accept method needs to be called to specify which - * classes can be deserialized, as by default no classes are - * accepted. - * + * classes can be deserialized, as by default no classes are + * accepted. + * * @param input an input stream * @throws IOException if an I/O error occurs while reading stream header */ - public ValidatingObjectInputStream(final InputStream input) throws IOException { + public ValidatingObjectInputStream(InputStream input) throws IOException { super(input); } @@ -65,16 +65,16 @@ public class ValidatingObjectInputStream extends ObjectInputStream { * @param name The class name * @throws InvalidClassException when a non-accepted class is encountered */ - private void validateClassName(final String name) throws InvalidClassException { + private void validateClassName(String name) throws InvalidClassException { // Reject has precedence over accept - for (final ClassNameMatcher m : rejectMatchers) { + for (ClassNameMatcher m : rejectMatchers) { if (m.matches(name)) { invalidClassNameFound(name); } } boolean ok = false; - for (final ClassNameMatcher m : acceptMatchers) { + for (ClassNameMatcher m : acceptMatchers) { if (m.matches(name)) { ok = true; break; @@ -89,43 +89,43 @@ public class ValidatingObjectInputStream extends ObjectInputStream { * Called to throw InvalidClassException if an invalid * class name is found during deserialization. Can be overridden, for example * to log those class names. - * - * @param className name of the invalid class + * + * @param className name of the invalid class * @throws InvalidClassException if the specified class is not allowed */ - protected void invalidClassNameFound(final String className) throws InvalidClassException { + protected void invalidClassNameFound(String className) throws InvalidClassException { throw new InvalidClassException("Class name not accepted: " + className); } @Override - protected Class resolveClass(final ObjectStreamClass osc) throws IOException, ClassNotFoundException { + protected Class resolveClass(ObjectStreamClass osc) throws IOException, ClassNotFoundException { validateClassName(osc.getName()); return super.resolveClass(osc); } /** - * Accept the specified classes for deserialization, unless they + * Accept the specified classes for deserialization, unless they * are otherwise rejected. - * + * * @param classes Classes to accept * @return this object */ - public ValidatingObjectInputStream accept(final Class... classes) { - for (final Class c : classes) { + public ValidatingObjectInputStream accept(Class... classes) { + for (Class c : classes) { acceptMatchers.add(new FullClassNameMatcher(c.getName())); } return this; } /** - * Reject the specified classes for deserialization, even if they + * Reject the specified classes for deserialization, even if they * are otherwise accepted. - * + * * @param classes Classes to reject * @return this object */ - public ValidatingObjectInputStream reject(final Class... classes) { - for (final Class c : classes) { + public ValidatingObjectInputStream reject(Class... classes) { + for (Class c : classes) { rejectMatchers.add(new FullClassNameMatcher(c.getName())); } return this; @@ -139,36 +139,36 @@ public class ValidatingObjectInputStream extends ObjectInputStream { * {@link FilenameUtils#wildcardMatch(String, String) FilenameUtils.wildcardMatch} * @return this object */ - public ValidatingObjectInputStream accept(final String... patterns) { - for (final String pattern : patterns) { + public ValidatingObjectInputStream accept(String... patterns) { + for (String pattern : patterns) { acceptMatchers.add(new WildcardClassNameMatcher(pattern)); } return this; } /** - * Reject the wildcard specified classes for deserialization, + * Reject the wildcard specified classes for deserialization, * even if they are otherwise accepted. - * + * * @param patterns Wildcard filename patterns as defined by * {@link FilenameUtils#wildcardMatch(String, String) FilenameUtils.wildcardMatch} * @return this object */ - public ValidatingObjectInputStream reject(final String... patterns) { - for (final String pattern : patterns) { + public ValidatingObjectInputStream reject(String... patterns) { + for (String pattern : patterns) { rejectMatchers.add(new WildcardClassNameMatcher(pattern)); } return this; } - /** + /** * Accept class names that match the supplied pattern for * deserialization, unless they are otherwise rejected. - * + * * @param pattern standard Java regexp * @return this object */ - public ValidatingObjectInputStream accept(final Pattern pattern) { + public ValidatingObjectInputStream accept(Pattern pattern) { acceptMatchers.add(new RegexpClassNameMatcher(pattern)); return this; } @@ -176,11 +176,11 @@ public class ValidatingObjectInputStream extends ObjectInputStream { /** * Reject class names that match the supplied pattern for * deserialization, even if they are otherwise accepted. - * + * * @param pattern standard Java regexp * @return this object */ - public ValidatingObjectInputStream reject(final Pattern pattern) { + public ValidatingObjectInputStream reject(Pattern pattern) { rejectMatchers.add(new RegexpClassNameMatcher(pattern)); return this; } @@ -188,11 +188,11 @@ public class ValidatingObjectInputStream extends ObjectInputStream { /** * Accept class names where the supplied ClassNameMatcher matches for * deserialization, unless they are otherwise rejected. - * + * * @param m the matcher to use * @return this object */ - public ValidatingObjectInputStream accept(final ClassNameMatcher m) { + public ValidatingObjectInputStream accept(ClassNameMatcher m) { acceptMatchers.add(m); return this; } @@ -200,11 +200,11 @@ public class ValidatingObjectInputStream extends ObjectInputStream { /** * Reject class names where the supplied ClassNameMatcher matches for * deserialization, even if they are otherwise accepted. - * + * * @param m the matcher to use * @return this object */ - public ValidatingObjectInputStream reject(final ClassNameMatcher m) { + public ValidatingObjectInputStream reject(ClassNameMatcher m) { rejectMatchers.add(m); return this; } diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/WildcardClassNameMatcher.java b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/WildcardClassNameMatcher.java index 7b676e3ae..36be9f207 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/WildcardClassNameMatcher.java +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/WildcardClassNameMatcher.java @@ -22,26 +22,26 @@ import com.fr.third.org.apache.commons.io.FilenameUtils; /** * A {@link ClassNameMatcher} that uses simplified regular expressions - * provided by {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String) FilenameUtils.wildcardMatch} + * provided by {@link FilenameUtils#wildcardMatch(String, String) FilenameUtils.wildcardMatch} *

    * This object is immutable and thread-safe. *

    - */ + */ final class WildcardClassNameMatcher implements ClassNameMatcher { private final String pattern; /** * Constructs an object based on the specified simplified regular expression. - * + * * @param pattern a {@link FilenameUtils#wildcardMatch} pattern. */ - public WildcardClassNameMatcher(final String pattern) { + public WildcardClassNameMatcher(String pattern) { this.pattern = pattern; } - + @Override - public boolean matches(final String className) { + public boolean matches(String className) { return FilenameUtils.wildcardMatch(className, pattern); } } \ No newline at end of file diff --git a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/package.html b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/package.html index 89f3b4010..271802e4d 100644 --- a/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/package.html +++ b/fine-commons-io/src/com/fr/third/org/apache/commons/io/serialization/package.html @@ -1,24 +1,24 @@ - - - - -

    -This package provides a framework for controlling the deserialization of classes. -

    - - + + + + +

    +This package provides a framework for controlling the deserialization of classes. +

    + +
    And there are five 'boolean' filters:
    TrueFileFilter