Browse Source

jdk1.6

10.0
richie 7 years ago
parent
commit
6d24a198e1
  1. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderMark.java
  2. 66
      fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderParser.java
  3. 48
      fine-commons-io/src/com/fr/third/org/apache/commons/io/Charsets.java
  4. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/CopyUtils.java
  5. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/DirectoryWalker.java
  6. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/EndianUtils.java
  7. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaner.java
  8. 9
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaningTracker.java
  9. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileDeleteStrategy.java
  10. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileExistsException.java
  11. 65
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileSystemUtils.java
  12. 336
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileUtils.java
  13. 23
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FilenameUtils.java
  14. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/HexDump.java
  15. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/IOCase.java
  16. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/IOExceptionWithCause.java
  17. 228
      fine-commons-io/src/com/fr/third/org/apache/commons/io/IOUtils.java
  18. 190
      fine-commons-io/src/com/fr/third/org/apache/commons/io/Java7Support.java
  19. 36
      fine-commons-io/src/com/fr/third/org/apache/commons/io/LineIterator.java
  20. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/ThreadMonitor.java
  21. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/AbstractFileComparator.java
  22. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/CompositeFileComparator.java
  23. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DefaultFileComparator.java
  24. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DirectoryFileComparator.java
  25. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ExtensionFileComparator.java
  26. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/LastModifiedFileComparator.java
  27. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/NameFileComparator.java
  28. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/PathFileComparator.java
  29. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ReverseComparator.java
  30. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/SizeFileComparator.java
  31. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/package.html
  32. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AbstractFileFilter.java
  33. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AgeFileFilter.java
  34. 18
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AndFileFilter.java
  35. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanReadFileFilter.java
  36. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanWriteFileFilter.java
  37. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/ConditionalFileFilter.java
  38. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DelegateFileFilter.java
  39. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DirectoryFileFilter.java
  40. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/EmptyFileFilter.java
  41. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FalseFileFilter.java
  42. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFileFilter.java
  43. 25
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFilterUtils.java
  44. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/HiddenFileFilter.java
  45. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/IOFileFilter.java
  46. 11
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/MagicNumberFileFilter.java
  47. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NameFileFilter.java
  48. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NotFileFilter.java
  49. 18
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/OrFileFilter.java
  50. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/PrefixFileFilter.java
  51. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/RegexFileFilter.java
  52. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SizeFileFilter.java
  53. 11
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SuffixFileFilter.java
  54. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/TrueFileFilter.java
  55. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFileFilter.java
  56. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFilter.java
  57. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/package.html
  58. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/AutoCloseInputStream.java
  59. 17
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BOMInputStream.java
  60. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedInputStream.java
  61. 20
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedReader.java
  62. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceInputStream.java
  63. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceReader.java
  64. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
  65. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CloseShieldInputStream.java
  66. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClosedInputStream.java
  67. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CountingInputStream.java
  68. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/DemuxInputStream.java
  69. 52
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/InfiniteCircularInputStream.java
  70. 102
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java
  71. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullInputStream.java
  72. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullReader.java
  73. 266
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ObservableInputStream.java
  74. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyInputStream.java
  75. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyReader.java
  76. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReaderInputStream.java
  77. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReversedLinesFileReader.java
  78. 19
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/SwappedDataInputStream.java
  79. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TaggedInputStream.java
  80. 47
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/Tailer.java
  81. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListener.java
  82. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListenerAdapter.java
  83. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TeeInputStream.java
  84. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/UnixLineEndingInputStream.java
  85. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/WindowsLineEndingInputStream.java
  86. 15
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReader.java
  87. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReaderException.java
  88. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListener.java
  89. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java
  90. 9
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationMonitor.java
  91. 15
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationObserver.java
  92. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/AppendableOutputStream.java
  93. 24
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ByteArrayOutputStream.java
  94. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedOutputStream.java
  95. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedWriter.java
  96. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CloseShieldOutputStream.java
  97. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ClosedOutputStream.java
  98. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CountingOutputStream.java
  99. 89
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DeferredFileOutputStream.java
  100. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DemuxOutputStream.java
  101. Some files were not shown because too many files have changed in this diff Show More

8
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; package com.fr.third.org.apache.commons.io;
import com.fr.third.org.apache.commons.io.input.BOMInputStream;
import java.io.Serializable; 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 <a href="http://en.wikipedia.org/wiki/Byte_order_mark">Wikipedia: Byte Order Mark</a> * @see <a href="http://en.wikipedia.org/wiki/Byte_order_mark">Wikipedia: Byte Order Mark</a>
* @see <a href="http://www.w3.org/TR/2006/REC-xml-20060816/#sec-guessing">W3C: Autodetection of Character Encodings * @see <a href="http://www.w3.org/TR/2006/REC-xml-20060816/#sec-guessing">W3C: Autodetection of Character Encodings
* (Non-Normative)</a> * (Non-Normative)</a>
* @version $Id$ * @version $Id: ByteOrderMark.java 1586504 2014-04-10 23:34:37Z ggregory $
* @since 2.0 * @since 2.0
*/ */
public class ByteOrderMark implements Serializable { public class ByteOrderMark implements Serializable {

66
fine-commons-io/src/com/fr/third/org/apache/commons/io/ByteOrderParser.java

@ -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}.
* <p>
* Returns {@code ByteOrder.LITTLE_ENDIAN} if the given value is {@code "LITTLE_ENDIAN"}.
* </p>
* <p>
* Returns {@code ByteOrder.BIG_ENDIAN} if the given value is {@code "BIG_ENDIAN"}.
* </p>
* Examples:
* <ul>
* <li>{@code ByteOrderParser.parseByteOrder("LITTLE_ENDIAN")} returns {@code ByteOrder.LITTLE_ENDIAN}</li>
* <li>{@code ByteOrderParser.parseByteOrder("BIG_ENDIAN")} returns {@code ByteOrder.BIG_ENDIAN}</li>
* </ul>
*
* @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);
}
}

48
fine-commons-io/src/com/fr/third/org/apache/commons/io/Charsets.java

@ -17,7 +17,6 @@
package com.fr.third.org.apache.commons.io; package com.fr.third.org.apache.commons.io;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
@ -25,7 +24,7 @@ import java.util.TreeMap;
/** /**
* Charsets required of every implementation of the Java platform. * Charsets required of every implementation of the Java platform.
* *
* From the Java documentation <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html"> * From the Java documentation <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">
* Standard charsets</a>: * Standard charsets</a>:
* <p> * <p>
* <cite>Every implementation of the Java platform is required to support the following character encodings. Consult * <cite>Every implementation of the Java platform is required to support the following character encodings. Consult
@ -49,9 +48,9 @@ import java.util.TreeMap;
* accepted on input, big-endian used on output.)</li> * accepted on input, big-endian used on output.)</li>
* </ul> * </ul>
* *
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
* @since 2.3 * @since 2.3
* @version $Id$ * @version $Id: Charsets.java 1686747 2015-06-21 18:44:49Z krosenvold $
*/ */
public class Charsets { public class Charsets {
// //
@ -63,7 +62,7 @@ public class Charsets {
* Constructs a sorted map from canonical charset names to charset objects required of every implementation of the * Constructs a sorted map from canonical charset names to charset objects required of every implementation of the
* Java platform. * Java platform.
* <p> * <p>
* From the Java documentation <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html"> * From the Java documentation <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">
* Standard charsets</a>: * Standard charsets</a>:
* </p> * </p>
* *
@ -73,13 +72,14 @@ public class Charsets {
*/ */
public static SortedMap<String, Charset> requiredCharsets() { public static SortedMap<String, Charset> requiredCharsets() {
// maybe cache? // maybe cache?
final TreeMap<String, Charset> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); // TODO Re-implement on Java 7 to use java.nio.charset.StandardCharsets
m.put(StandardCharsets.ISO_8859_1.name(), StandardCharsets.ISO_8859_1); final TreeMap<String, Charset> m = new TreeMap<String, Charset>(String.CASE_INSENSITIVE_ORDER);
m.put(StandardCharsets.US_ASCII.name(), StandardCharsets.US_ASCII); m.put(ISO_8859_1.name(), ISO_8859_1);
m.put(StandardCharsets.UTF_16.name(), StandardCharsets.UTF_16); m.put(US_ASCII.name(), US_ASCII);
m.put(StandardCharsets.UTF_16BE.name(), StandardCharsets.UTF_16BE); m.put(UTF_16.name(), UTF_16);
m.put(StandardCharsets.UTF_16LE.name(), StandardCharsets.UTF_16LE); m.put(UTF_16BE.name(), UTF_16BE);
m.put(StandardCharsets.UTF_8.name(), StandardCharsets.UTF_8); m.put(UTF_16LE.name(), UTF_16LE);
m.put(UTF_8.name(), UTF_8);
return Collections.unmodifiableSortedMap(m); return Collections.unmodifiableSortedMap(m);
} }
@ -113,11 +113,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding. * Every implementation of the Java platform is required to support this character encoding.
* </p> * </p>
* *
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/ */
@Deprecated @Deprecated
public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1; public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
/** /**
* <p> * <p>
@ -127,11 +127,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding. * Every implementation of the Java platform is required to support this character encoding.
* </p> * </p>
* *
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/ */
@Deprecated @Deprecated
public static final Charset US_ASCII = StandardCharsets.US_ASCII; public static final Charset US_ASCII = Charset.forName("US-ASCII");
/** /**
* <p> * <p>
@ -142,11 +142,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding. * Every implementation of the Java platform is required to support this character encoding.
* </p> * </p>
* *
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/ */
@Deprecated @Deprecated
public static final Charset UTF_16 = StandardCharsets.UTF_16; public static final Charset UTF_16 = Charset.forName("UTF-16");
/** /**
* <p> * <p>
@ -156,11 +156,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding. * Every implementation of the Java platform is required to support this character encoding.
* </p> * </p>
* *
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/ */
@Deprecated @Deprecated
public static final Charset UTF_16BE = StandardCharsets.UTF_16BE; public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
/** /**
* <p> * <p>
@ -170,11 +170,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding. * Every implementation of the Java platform is required to support this character encoding.
* </p> * </p>
* *
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/ */
@Deprecated @Deprecated
public static final Charset UTF_16LE = StandardCharsets.UTF_16LE; public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
/** /**
* <p> * <p>
@ -184,9 +184,9 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding. * Every implementation of the Java platform is required to support this character encoding.
* </p> * </p>
* *
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets} * @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/ */
@Deprecated @Deprecated
public static final Charset UTF_8 = StandardCharsets.UTF_8; public static final Charset UTF_8 = Charset.forName("UTF-8");
} }

1
fine-commons-io/src/com/fr/third/org/apache/commons/io/CopyUtils.java

@ -103,6 +103,7 @@ import java.nio.charset.Charset;
* <p> * <p>
* Origin of code: Excalibur. * 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. * @deprecated Use IOUtils. Will be removed in 2.0.
* Methods renamed to IOUtils.write() or IOUtils.copy(). * Methods renamed to IOUtils.write() or IOUtils.copy().
* Null handling behaviour changed in IOUtils (null data does not * Null handling behaviour changed in IOUtils (null data does not

6
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. * subclasses with convenient hooks to add specific behaviour.
* <p> * <p>
* This class operates with a {@link FileFilter} and maximum depth to * 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 * Commons IO supplies many common filter implementations in the
* <a href="filefilter/package-summary.html"> filefilter</a> package. * <a href="filefilter/package-summary.html"> filefilter</a> package.
* <p> * <p>
@ -172,7 +172,7 @@ import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter;
* <p> * <p>
* Two possible scenarios are envisaged for cancellation: * Two possible scenarios are envisaged for cancellation:
* <ul> * <ul>
* <li><a href="#external">3.1 External / Multi-threaded</a> - cancellation being * <li><a href="#external">3.1 External / Mult-threaded</a> - cancellation being
* decided/initiated by an external process.</li> * decided/initiated by an external process.</li>
* <li><a href="#internal">3.2 Internal</a> - cancellation being decided/initiated * <li><a href="#internal">3.2 Internal</a> - cancellation being decided/initiated
* from within a DirectoryWalker implementation.</li> * from within a DirectoryWalker implementation.</li>
@ -246,7 +246,7 @@ import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter;
* </pre> * </pre>
* *
* @since 1.3 * @since 1.3
* @version $Id$ * @version $Id: DirectoryWalker.java 1723627 2016-01-07 21:15:47Z niallp $
*/ */
public abstract class DirectoryWalker<T> { public abstract class DirectoryWalker<T> {

5
fine-commons-io/src/com/fr/third/org/apache/commons/io/EndianUtils.java

@ -16,7 +16,7 @@
*/ */
package com.fr.third.org.apache.commons.io; 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.EOFException;
import java.io.IOException; import java.io.IOException;
@ -35,7 +35,8 @@ import java.io.OutputStream;
* <p> * <p>
* Origin of code: Excalibur * 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 { public class EndianUtils {

7
fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaner.java

@ -32,6 +32,7 @@ import java.io.File;
* {@link #exitWhenFinished}, typically in * {@link #exitWhenFinished}, typically in
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar. * {@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 Use {@link FileCleaningTracker}
*/ */
@Deprecated @Deprecated
@ -60,7 +61,7 @@ public class FileCleaner {
/** /**
* Track the specified file, using the provided marker, deleting the file * Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected. * 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 file the file to be tracked, not null
* @param marker the marker object used to track the file, 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 * Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected. * 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 path the full path to the file to be tracked, not null
* @param marker the marker object used to track the file, 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, * 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 * 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 * 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.
* <p> * <p>
* For example, suppose that you have developed a web application, which * 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 * contains the commons-io jar file in your WEB-INF/lib directory. In other

9
fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaningTracker.java

@ -39,6 +39,7 @@ import java.util.List;
* {@link #exitWhenFinished}, typically in * {@link #exitWhenFinished}, typically in
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar. * {@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 { public class FileCleaningTracker {
@ -47,7 +48,7 @@ public class FileCleaningTracker {
/** /**
* Queue of <code>Tracker</code> instances being watched. * Queue of <code>Tracker</code> instances being watched.
*/ */
ReferenceQueue<Object> q = new ReferenceQueue<>(); ReferenceQueue<Object> q = new ReferenceQueue<Object>();
/** /**
* Collection of <code>Tracker</code> instances in existence. * Collection of <code>Tracker</code> instances in existence.
*/ */
@ -82,7 +83,7 @@ public class FileCleaningTracker {
/** /**
* Track the specified file, using the provided marker, deleting the file * Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected. * 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 file the file to be tracked, not null
* @param marker the marker object used to track the file, 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 * Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected. * 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 path the full path to the file to be tracked, not null
* @param marker the marker object used to track the file, 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, * 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 * 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 * 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.
* <p> * <p>
* For example, suppose that you have developed a web application, which * 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 * contains the commons-io jar file in your WEB-INF/lib directory. In other

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/FileDeleteStrategy.java

@ -28,6 +28,7 @@ import java.io.IOException;
* <p> * <p>
* This class captures the strategy to use and is designed for user subclassing. * 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 * @since 1.3
*/ */
public class FileDeleteStrategy { public class FileDeleteStrategy {
@ -106,7 +107,7 @@ public class FileDeleteStrategy {
* This implementation uses {@link File#delete()}. * This implementation uses {@link File#delete()}.
* *
* @param fileToDelete the file to delete, exists, not null * @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 NullPointerException if the file is null
* @throws IOException if an error occurs during file deletion * @throws IOException if an error occurs during file deletion
*/ */

1
fine-commons-io/src/com/fr/third/org/apache/commons/io/FileExistsException.java

@ -22,6 +22,7 @@ import java.io.IOException;
/** /**
* Indicates that a file already exists. * Indicates that a file already exists.
* *
* @version $Id: FileExistsException.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0 * @since 2.0
*/ */
public class FileExistsException extends IOException { public class FileExistsException extends IOException {

65
fine-commons-io/src/com/fr/third/org/apache/commons/io/FileSystemUtils.java

@ -40,13 +40,9 @@ import java.util.StringTokenizer;
* <li>Get the free space on a drive * <li>Get the free space on a drive
* </ul> * </ul>
* *
* @version $Id: FileSystemUtils.java 1686747 2015-06-21 18:44:49Z krosenvold $
* @since 1.1 * @since 1.1
* @deprecated As of 2.6 deprecated without replacement. Use equivalent
* methods in {@link java.nio.file.FileStore} instead, e.g.
* <code>Files.getFileStore(Paths.get("/home")).getUsableSpace()</code>
* or iterate over <code>FileSystems.getDefault().getFileStores()</code>
*/ */
@Deprecated
public class FileSystemUtils { public class FileSystemUtils {
/** Singleton instance, used mainly for testing. */ /** Singleton instance, used mainly for testing. */
@ -84,7 +80,6 @@ public class FileSystemUtils {
} else if (osName.contains("linux") || } else if (osName.contains("linux") ||
osName.contains("mpe/ix") || osName.contains("mpe/ix") ||
osName.contains("freebsd") || osName.contains("freebsd") ||
osName.contains("openbsd") ||
osName.contains("irix") || osName.contains("irix") ||
osName.contains("digital unix") || osName.contains("digital unix") ||
osName.contains("unix") || osName.contains("unix") ||
@ -150,8 +145,8 @@ public class FileSystemUtils {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Returns the free space on a drive or volume in kibibytes (1024 bytes) * Returns the free space on a drive or volume in kilobytes by invoking
* by invoking the command line. * the command line.
* <pre> * <pre>
* FileSystemUtils.freeSpaceKb("C:"); // Windows * FileSystemUtils.freeSpaceKb("C:"); // Windows
* FileSystemUtils.freeSpaceKb("/volume"); // *nix * FileSystemUtils.freeSpaceKb("/volume"); // *nix
@ -172,15 +167,13 @@ public class FileSystemUtils {
* @throws IllegalStateException if an error occurred in initialisation * @throws IllegalStateException if an error occurred in initialisation
* @throws IOException if an error occurs when finding the free space * @throws IOException if an error occurs when finding the free space
* @since 1.2, enhanced OS support in 1.3 * @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 { public static long freeSpaceKb(final String path) throws IOException {
return freeSpaceKb(path, -1); return freeSpaceKb(path, -1);
} }
/** /**
* Returns the free space on a drive or volume in kibibytes (1024 bytes) * Returns the free space on a drive or volume in kilobytes by invoking
* by invoking the command line. * the command line.
* <pre> * <pre>
* FileSystemUtils.freeSpaceKb("C:"); // Windows * FileSystemUtils.freeSpaceKb("C:"); // Windows
* FileSystemUtils.freeSpaceKb("/volume"); // *nix * FileSystemUtils.freeSpaceKb("/volume"); // *nix
@ -203,16 +196,13 @@ public class FileSystemUtils {
* @throws IllegalStateException if an error occurred in initialisation * @throws IllegalStateException if an error occurred in initialisation
* @throws IOException if an error occurs when finding the free space * @throws IOException if an error occurs when finding the free space
* @since 2.0 * @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 { public static long freeSpaceKb(final String path, final long timeout) throws IOException {
return INSTANCE.freeSpaceOS(path, OS, true, timeout); return INSTANCE.freeSpaceOS(path, OS, true, timeout);
} }
/** /**
* Returns the free space for the working directory * Returns the disk size of the volume which holds the working directory.
* in kibibytes (1024 bytes) by invoking the command line.
* <p> * <p>
* Identical to: * Identical to:
* <pre> * <pre>
@ -222,16 +212,13 @@ public class FileSystemUtils {
* @throws IllegalStateException if an error occurred in initialisation * @throws IllegalStateException if an error occurred in initialisation
* @throws IOException if an error occurs when finding the free space * @throws IOException if an error occurs when finding the free space
* @since 2.0 * @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 { public static long freeSpaceKb() throws IOException {
return freeSpaceKb(-1); return freeSpaceKb(-1);
} }
/** /**
* Returns the free space for the working directory * Returns the disk size of the volume which holds the working directory.
* in kibibytes (1024 bytes) by invoking the command line.
* <p> * <p>
* Identical to: * Identical to:
* <pre> * <pre>
@ -243,9 +230,7 @@ public class FileSystemUtils {
* @throws IllegalStateException if an error occurred in initialisation * @throws IllegalStateException if an error occurred in initialisation
* @throws IOException if an error occurs when finding the free space * @throws IOException if an error occurs when finding the free space
* @since 2.0 * @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 { public static long freeSpaceKb(final long timeout) throws IOException {
return freeSpaceKb(new File(".").getAbsolutePath(), timeout); return freeSpaceKb(new File(".").getAbsolutePath(), timeout);
} }
@ -300,17 +285,14 @@ public class FileSystemUtils {
* @return the amount of free drive space on the drive * @return the amount of free drive space on the drive
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
long freeSpaceWindows(final String path, final long timeout) throws IOException { long freeSpaceWindows(String path, final long timeout) throws IOException {
String normPath = FilenameUtils.normalize(path, false); path = FilenameUtils.normalize(path, false);
if (normPath == null) { if (path.length() > 0 && path.charAt(0) != '"') {
throw new IllegalArgumentException(path); path = "\"" + path + "\"";
}
if (normPath.length() > 0 && normPath.charAt(0) != '"') {
normPath = "\"" + normPath + "\"";
} }
// build and run the 'dir' command // 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 // read in the output of the command to an ArrayList
final List<String> lines = performCommand(cmdAttribs, Integer.MAX_VALUE, timeout); final List<String> lines = performCommand(cmdAttribs, Integer.MAX_VALUE, timeout);
@ -322,13 +304,13 @@ public class FileSystemUtils {
for (int i = lines.size() - 1; i >= 0; i--) { for (int i = lines.size() - 1; i >= 0; i--) {
final String line = lines.get(i); final String line = lines.get(i);
if (line.length() > 0) { if (line.length() > 0) {
return parseDir(line, normPath); return parseDir(line, path);
} }
} }
// all lines are blank // all lines are blank
throw new IOException( throw new IOException(
"Command line 'dir /-c' did not return any info " + "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 // 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) // (see commons-exec or Ant for a better multi-threaded multi-os solution)
final List<String> lines = new ArrayList<>(20); final List<String> lines = new ArrayList<String>(20);
Process proc = null; Process proc = null;
InputStream in = null; InputStream in = null;
OutputStream out = null; OutputStream out = null;
@ -528,23 +510,6 @@ public class FileSystemUtils {
"Command line did not return any info " + "Command line did not return any info " +
"for command " + Arrays.asList(cmdAttribs)); "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; return lines;
} catch (final InterruptedException ex) { } catch (final InterruptedException ex) {

336
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.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date; 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.FalseFileFilter;
import com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils; 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.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.SuffixFileFilter;
import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter; import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter;
import com.fr.third.org.apache.commons.io.output.NullOutputStream; import com.fr.third.org.apache.commons.io.output.NullOutputStream;
@ -69,12 +68,9 @@ import com.fr.third.org.apache.commons.io.output.NullOutputStream;
* <li>calculating a checksum * <li>calculating a checksum
* </ul> * </ul>
* <p> * <p>
* 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.
* <p>
* Origin of code: Excalibur, Alexandria, Commons-Utils * Origin of code: Excalibur, Alexandria, Commons-Utils
* *
* @version $Id: FileUtils.java 1722481 2016-01-01 01:42:04Z dbrosius $
*/ */
public class FileUtils { public class FileUtils {
@ -437,7 +433,8 @@ public class FileUtils {
*/ */
public static void touch(final File file) throws IOException { public static void touch(final File file) throws IOException {
if (!file.exists()) { if (!file.exists()) {
openOutputStream(file).close(); final OutputStream out = openOutputStream(file);
IOUtils.closeQuietly(out);
} }
final boolean success = file.setLastModified(System.currentTimeMillis()); final boolean success = file.setLastModified(System.currentTimeMillis());
if (!success) { if (!success) {
@ -503,14 +500,13 @@ public class FileUtils {
* in <code>FileFilterUtils.makeCVSAware(null)</code>. * in <code>FileFilterUtils.makeCVSAware(null)</code>.
* *
* @param directory the directory to search in * @param directory the directory to search in
* @param fileFilter filter to apply when finding files. Must not be {@code null}, * @param fileFilter filter to apply when finding files.
* use {@link TrueFileFilter#INSTANCE} to match all files in selected directories.
* @param dirFilter optional filter to apply when finding subdirectories. * @param dirFilter optional filter to apply when finding subdirectories.
* If this parameter is {@code null}, subdirectories will not be included in the * If this parameter is {@code null}, subdirectories will not be included in the
* search. Use {@link TrueFileFilter#INSTANCE} to match all directories. * search. Use TrueFileFilter.INSTANCE to match all directories.
* @return a collection of java.io.File with the matching files * @return an collection of java.io.File with the matching files
* @see com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils * @see FileFilterUtils
* @see com.fr.third.org.apache.commons.io.filefilter.NameFileFilter * @see NameFileFilter
*/ */
public static Collection<File> listFiles( public static Collection<File> listFiles(
final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) { final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) {
@ -520,7 +516,7 @@ public class FileUtils {
final IOFileFilter effDirFilter = setUpEffectiveDirFilter(dirFilter); final IOFileFilter effDirFilter = setUpEffectiveDirFilter(dirFilter);
//Find files //Find files
final Collection<File> files = new java.util.LinkedList<>(); final Collection<File> files = new java.util.LinkedList<File>();
innerListFiles(files, directory, innerListFiles(files, directory,
FileFilterUtils.or(effFileFilter, effDirFilter), false); FileFilterUtils.or(effFileFilter, effDirFilter), false);
return files; return files;
@ -579,10 +575,10 @@ public class FileUtils {
* @param dirFilter optional filter to apply when finding subdirectories. * @param dirFilter optional filter to apply when finding subdirectories.
* If this parameter is {@code null}, subdirectories will not be included in the * If this parameter is {@code null}, subdirectories will not be included in the
* search. Use TrueFileFilter.INSTANCE to match all directories. * search. Use TrueFileFilter.INSTANCE to match all directories.
* @return a collection of java.io.File with the matching files * @return an collection of java.io.File with the matching files
* @see com.fr.third.org.apache.commons.io.FileUtils#listFiles * @see FileUtils#listFiles
* @see com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils * @see FileFilterUtils
* @see com.fr.third.org.apache.commons.io.filefilter.NameFileFilter * @see NameFileFilter
* @since 2.2 * @since 2.2
*/ */
public static Collection<File> listFilesAndDirs( public static Collection<File> listFilesAndDirs(
@ -593,7 +589,7 @@ public class FileUtils {
final IOFileFilter effDirFilter = setUpEffectiveDirFilter(dirFilter); final IOFileFilter effDirFilter = setUpEffectiveDirFilter(dirFilter);
//Find files //Find files
final Collection<File> files = new java.util.LinkedList<>(); final Collection<File> files = new java.util.LinkedList<File>();
if (directory.isDirectory()) { if (directory.isDirectory()) {
files.add(directory); files.add(directory);
} }
@ -616,8 +612,8 @@ public class FileUtils {
* If this parameter is {@code null}, subdirectories will not be included in the * If this parameter is {@code null}, subdirectories will not be included in the
* search. Use TrueFileFilter.INSTANCE to match all directories. * search. Use TrueFileFilter.INSTANCE to match all directories.
* @return an iterator of java.io.File for the matching files * @return an iterator of java.io.File for the matching files
* @see com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils * @see FileFilterUtils
* @see com.fr.third.org.apache.commons.io.filefilter.NameFileFilter * @see NameFileFilter
* @since 1.2 * @since 1.2
*/ */
public static Iterator<File> iterateFiles( public static Iterator<File> iterateFiles(
@ -641,8 +637,8 @@ public class FileUtils {
* If this parameter is {@code null}, subdirectories will not be included in the * If this parameter is {@code null}, subdirectories will not be included in the
* search. Use TrueFileFilter.INSTANCE to match all directories. * search. Use TrueFileFilter.INSTANCE to match all directories.
* @return an iterator of java.io.File for the matching files * @return an iterator of java.io.File for the matching files
* @see com.fr.third.org.apache.commons.io.filefilter.FileFilterUtils * @see FileFilterUtils
* @see com.fr.third.org.apache.commons.io.filefilter.NameFileFilter * @see NameFileFilter
* @since 2.2 * @since 2.2
*/ */
public static Iterator<File> iterateFilesAndDirs(final File directory, final IOFileFilter fileFilter, public static Iterator<File> 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 * @param extensions an array of extensions, ex. {"java","xml"}. If this
* parameter is {@code null}, all files are returned. * parameter is {@code null}, all files are returned.
* @param recursive if true all subdirectories are searched as well * @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<File> listFiles( public static Collection<File> listFiles(
final File directory, final String[] extensions, final boolean recursive) { final File directory, final String[] extensions, final boolean recursive) {
@ -750,9 +746,16 @@ public class FileUtils {
return true; return true;
} }
try (InputStream input1 = new FileInputStream(file1); InputStream input1 = null;
InputStream input2 = new FileInputStream(file2)) { InputStream input2 = null;
try {
input1 = new FileInputStream(file1);
input2 = new FileInputStream(file2);
return IOUtils.contentEquals(input1, input2); return IOUtils.contentEquals(input1, input2);
} finally {
IOUtils.closeQuietly(input1);
IOUtils.closeQuietly(input2);
} }
} }
@ -796,13 +799,22 @@ public class FileUtils {
return true; return true;
} }
try (Reader input1 = charsetName == null Reader input1 = null;
? new InputStreamReader(new FileInputStream(file1), Charset.defaultCharset()) Reader input2 = null;
: new InputStreamReader(new FileInputStream(file1), charsetName); try {
Reader input2 = charsetName == null if (charsetName == null) {
? new InputStreamReader(new FileInputStream(file2), Charset.defaultCharset()) // N.B. make explicit the use of the default charset
: new InputStreamReader(new FileInputStream(file2), charsetName)) { 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); 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 * @return The decoded URL or {@code null} if the input was
* {@code null}. * {@code null}.
*/ */
@SuppressWarnings("deprecation") // unavoidable until Java 7
static String decodeUrl(final String url) { static String decodeUrl(final String url) {
String decoded = url; String decoded = url;
if (url != null && url.indexOf('%') >= 0) { if (url != null && url.indexOf('%') >= 0) {
@ -866,7 +879,7 @@ public class FileUtils {
} finally { } finally {
if (bytes.position() > 0) { if (bytes.position() > 0) {
bytes.flip(); bytes.flip();
buffer.append(StandardCharsets.UTF_8.decode(bytes).toString()); buffer.append(Charsets.UTF_8.decode(bytes).toString());
bytes.clear(); bytes.clear();
} }
} }
@ -1090,8 +1103,11 @@ public class FileUtils {
* @since 2.1 * @since 2.1
*/ */
public static long copyFile(final File input, final OutputStream output) throws IOException { 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); 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"); throw new IOException("Destination '" + destFile + "' exists but is a directory");
} }
try (FileInputStream fis = new FileInputStream(srcFile); FileInputStream fis = null;
FileChannel input = fis.getChannel(); FileOutputStream fos = null;
FileOutputStream fos = new FileOutputStream(destFile); FileChannel input = null;
FileChannel output = fos.getChannel()) { 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 final long size = input.size(); // TODO See IO-386
long pos = 0; long pos = 0;
long count = 0; long count = 0;
@ -1134,6 +1155,8 @@ public class FileUtils {
} }
pos += bytesCopied; pos += bytesCopied;
} }
} finally {
IOUtils.closeQuietly(output, fos, input, fis);
} }
final long srcLen = srcFile.length(); // TODO See IO-386 final long srcLen = srcFile.length(); // TODO See IO-386
@ -1356,7 +1379,7 @@ public class FileUtils {
if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) { if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
final File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter); final File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
if (srcFiles != null && srcFiles.length > 0) { if (srcFiles != null && srcFiles.length > 0) {
exclusionList = new ArrayList<>(srcFiles.length); exclusionList = new ArrayList<String>(srcFiles.length);
for (final File srcFile : srcFiles) { for (final File srcFile : srcFiles) {
final File copiedFile = new File(destDir, srcFile.getName()); final File copiedFile = new File(destDir, srcFile.getName());
exclusionList.add(copiedFile.getCanonicalPath()); exclusionList.add(copiedFile.getCanonicalPath());
@ -1372,7 +1395,7 @@ public class FileUtils {
* @param dest the destination * @param dest the destination
* @throws FileNotFoundException if the destination does not exist * @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) { if (src == null) {
throw new NullPointerException("Source must not be null"); throw new NullPointerException("Source must not be null");
} }
@ -1502,8 +1525,10 @@ public class FileUtils {
* @since 2.0 * @since 2.0
*/ */
public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException { public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException {
try (InputStream in = source) { try {
copyToFile(in, destination); copyToFile(source, destination);
} finally {
IOUtils.closeQuietly(source);
} }
} }
@ -1525,78 +1550,12 @@ public class FileUtils {
* @since 2.5 * @since 2.5
*/ */
public static void copyToFile(final InputStream source, final File destination) throws IOException { public static void copyToFile(final InputStream source, final File destination) throws IOException {
try (InputStream in = source; final FileOutputStream output = openOutputStream(destination);
OutputStream out = openOutputStream(destination)) { try {
IOUtils.copy(in, out); IOUtils.copy(source, output);
} output.close(); // don't swallow close Exception if copy completes normally
} } finally {
IOUtils.closeQuietly(output);
/**
* Copies a file or directory to within another directory preserving the file dates.
* <p>
* This method copies the source file or directory, along all its contents, to a
* directory of the same name in the specified destination directory.
* <p>
* 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.
* <p>
* <strong>Note:</strong> 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.
* <p>
* 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.
* <p>
* <strong>Note:</strong> 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<File> 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);
} }
} }
@ -1735,7 +1694,7 @@ public class FileUtils {
* @return The files in the directory, never null. * @return The files in the directory, never null.
* @throws IOException if an I/O error occurs * @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()) { if (!directory.exists()) {
final String message = directory + " does not exist"; final String message = directory + " does not exist";
throw new IllegalArgumentException(message); throw new IllegalArgumentException(message);
@ -1766,11 +1725,11 @@ public class FileUtils {
* @throws NullPointerException if the file is {@code null} * @throws NullPointerException if the file is {@code null}
*/ */
public static boolean waitFor(final File file, final int seconds) { 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; boolean wasInterrupted = false;
try { try {
while (!file.exists()) { while (!file.exists()) {
final long remaining = finishAt - System.currentTimeMillis(); long remaining = finishAt - System.currentTimeMillis();
if (remaining < 0){ if (remaining < 0){
return false; return false;
} }
@ -1802,8 +1761,12 @@ public class FileUtils {
* @since 2.3 * @since 2.3
*/ */
public static String readFileToString(final File file, final Charset encoding) throws IOException { 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)); 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} * @return the file contents, never {@code null}
* @throws IOException in case of an I/O error * @throws IOException in case of an I/O error
* @since 1.3.1 * @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 @Deprecated
public static String readFileToString(final File file) throws IOException { public static String readFileToString(final File file) throws IOException {
@ -1848,10 +1811,12 @@ public class FileUtils {
* @since 1.1 * @since 1.1
*/ */
public static byte[] readFileToByteArray(final File file) throws IOException { public static byte[] readFileToByteArray(final File file) throws IOException {
try (InputStream in = openInputStream(file)) { InputStream in = null;
final long fileLength = file.length(); try {
// file.length() may return 0 for system-dependent entities, treat 0 as unknown length - see IO-453 in = openInputStream(file);
return fileLength > 0 ? IOUtils.toByteArray(in, fileLength) : IOUtils.toByteArray(in); 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 * @since 2.3
*/ */
public static List<String> readLines(final File file, final Charset encoding) throws IOException { public static List<String> 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)); 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} * @return the list of Strings representing each line in the file, never {@code null}
* @throws IOException in case of an I/O error * @throws IOException in case of an I/O error
* @since 1.3 * @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 @Deprecated
public static List<String> readLines(final File file) throws IOException { public static List<String> readLines(final File file) throws IOException {
@ -1937,15 +1906,11 @@ public class FileUtils {
try { try {
in = openInputStream(file); in = openInputStream(file);
return IOUtils.lineIterator(in, encoding); return IOUtils.lineIterator(in, encoding);
} catch (final IOException | RuntimeException ex) { } catch (final IOException ex) {
try { IOUtils.closeQuietly(in);
if (in != null) { throw ex;
in.close(); } catch (final RuntimeException ex) {
} IOUtils.closeQuietly(in);
}
catch (final IOException e) {
ex.addSuppressed(e);
}
throw ex; throw ex;
} }
} }
@ -2010,10 +1975,15 @@ public class FileUtils {
* @throws IOException in case of an I/O error * @throws IOException in case of an I/O error
* @since 2.3 * @since 2.3
*/ */
public static void writeStringToFile(final File file, final String data, final Charset encoding, public static void writeStringToFile(final File file, final String data, final Charset encoding, final boolean
final boolean append) throws IOException { append) throws IOException {
try (OutputStream out = openOutputStream(file, append)) { OutputStream out = null;
try {
out = openOutputStream(file, append);
IOUtils.write(data, out, encoding); 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 file the file to write
* @param data the content to write to the file * @param data the content to write to the file
* @throws IOException in case of an I/O error * @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 @Deprecated
public static void writeStringToFile(final File file, final String data) throws IOException { 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 * end of the file rather than overwriting
* @throws IOException in case of an I/O error * @throws IOException in case of an I/O error
* @since 2.1 * @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 @Deprecated
public static void writeStringToFile(final File file, final String data, final boolean append) throws IOException { 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 * @param data the content to write to the file
* @throws IOException in case of an I/O error * @throws IOException in case of an I/O error
* @since 2.0 * @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 @Deprecated
public static void write(final File file, final CharSequence data) throws IOException { 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 * end of the file rather than overwriting
* @throws IOException in case of an I/O error * @throws IOException in case of an I/O error
* @since 2.1 * @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 @Deprecated
public static void write(final File file, final CharSequence data, final boolean append) throws IOException { 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, public static void writeByteArrayToFile(final File file, final byte[] data, final int off, final int len,
final boolean append) throws IOException { 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.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, public static void writeLines(final File file, final String encoding, final Collection<?> lines,
final String lineEnding, final boolean append) throws IOException { final String lineEnding, final boolean append) throws IOException {
try (OutputStream out = new BufferedOutputStream(openOutputStream(file, append))) { FileOutputStream out = null;
IOUtils.writeLines(lines, lineEnding, out, encoding); 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 * the size of a file
* @param file the file to check * @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()) { if (file.isDirectory()) {
return sizeOfDirectory0(file); return sizeOfDirectory0(file);
} else { } else {
@ -2688,7 +2670,7 @@ public class FileUtils {
// internal method; if file does not exist will return 0 // 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 * @param fileOrDir The file
* @return the size * @return the size
*/ */
@ -2887,8 +2869,12 @@ public class FileUtils {
if (file.isDirectory()) { if (file.isDirectory()) {
throw new IllegalArgumentException("Checksums can't be computed on directories"); 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()); IOUtils.copy(in, new NullOutputStream());
} finally {
IOUtils.closeQuietly(in);
} }
return checksum; return checksum;
} }
@ -3101,9 +3087,61 @@ public class FileUtils {
* @since 2.0 * @since 2.0
*/ */
public static boolean isSymlink(final File file) throws IOException { public static boolean isSymlink(final File file) throws IOException {
if ( Java7Support.isAtLeastJava7() )
{
return Java7Support.isSymLink( file );
}
if (file == null) { if (file == null) {
throw new NullPointerException("File must not be 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;
} }
} }

23
fine-commons-io/src/com/fr/third/org/apache/commons/io/FilenameUtils.java

@ -77,6 +77,7 @@ import java.util.Stack;
* <p> * <p>
* Origin of code: Excalibur, Alexandria, Tomcat, Commons-Utils. * Origin of code: Excalibur, Alexandria, Tomcat, Commons-Utils.
* *
* @version $Id: FilenameUtils.java 1702170 2015-09-10 06:35:02Z krosenvold $
* @since 1.1 * @since 1.1
*/ */
public class FilenameUtils { public class FilenameUtils {
@ -328,7 +329,7 @@ public class FilenameUtils {
* *
* @param filename the filename to normalize, null returns null * @param filename the filename to normalize, null returns null
* @param unixSeparator {@code true} if a unix separator should * @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 * @return the normalized filename, or null if invalid. Null bytes inside string will be removed
* @since 2.0 * @since 2.0
*/ */
@ -666,8 +667,6 @@ public class FilenameUtils {
return 2; return 2;
} }
return 3; return 3;
} else if (ch0 == UNIX_SEPARATOR) {
return 1;
} }
return NOT_FOUND; return NOT_FOUND;
@ -772,7 +771,7 @@ public class FilenameUtils {
failIfNullBytePresent(filename + UNIX_SEPARATOR); failIfNullBytePresent(filename + UNIX_SEPARATOR);
return filename + UNIX_SEPARATOR; return filename + UNIX_SEPARATOR;
} }
final String path = filename.substring(0, len); String path = filename.substring(0, len);
failIfNullBytePresent(path); failIfNullBytePresent(path);
return path; return path;
} }
@ -852,7 +851,7 @@ public class FilenameUtils {
if (prefix >= filename.length() || index < 0 || prefix >= endIndex) { if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
return ""; return "";
} }
final String path = filename.substring(prefix, endIndex); String path = filename.substring(prefix, endIndex);
failIfNullBytePresent(path); failIfNullBytePresent(path);
return path; return path;
} }
@ -982,8 +981,8 @@ public class FilenameUtils {
* This may be used for poison byte attacks. * This may be used for poison byte attacks.
* @param path the path to check * @param path the path to check
*/ */
private static void failIfNullBytePresent(final String path) { private static void failIfNullBytePresent(String path) {
final int len = path.length(); int len = path.length();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
if (path.charAt(i) == 0) { if (path.charAt(i) == 0) {
throw new IllegalArgumentException("Null byte present in file/path name. There are no " + 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 filename the filename to match on
* @param wildcardMatcher the wildcard string to match against * @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 * @see IOCase#SENSITIVE
*/ */
public static boolean wildcardMatch(final String filename, final String wildcardMatcher) { 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 filename the filename to match on
* @param wildcardMatcher the wildcard string to match against * @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 * @see IOCase#SYSTEM
*/ */
public static boolean wildcardMatchOnSystem(final String filename, final String wildcardMatcher) { 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 filename the filename to match on
* @param wildcardMatcher the wildcard string to match against * @param wildcardMatcher the wildcard string to match against
* @param caseSensitivity what case sensitivity rule to use, null means case-sensitive * @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 * @since 1.3
*/ */
public static boolean wildcardMatch(final String filename, final String wildcardMatcher, IOCase caseSensitivity) { public static boolean wildcardMatch(final String filename, final String wildcardMatcher, IOCase caseSensitivity) {
@ -1339,7 +1338,7 @@ public class FilenameUtils {
boolean anyChars = false; boolean anyChars = false;
int textIdx = 0; int textIdx = 0;
int wcsIdx = 0; int wcsIdx = 0;
final Stack<int[]> backtrack = new Stack<>(); final Stack<int[]> backtrack = new Stack<int[]>();
// loop around a backtrack stack, to handle complex * matching // loop around a backtrack stack, to handle complex * matching
do { do {
@ -1424,7 +1423,7 @@ public class FilenameUtils {
} }
final char[] array = text.toCharArray(); final char[] array = text.toCharArray();
final ArrayList<String> list = new ArrayList<>(); final ArrayList<String> list = new ArrayList<String>();
final StringBuilder buffer = new StringBuilder(); final StringBuilder buffer = new StringBuilder();
char prevChar = 0; char prevChar = 0;
for (final char ch : array) { for (final char ch : array) {

1
fine-commons-io/src/com/fr/third/org/apache/commons/io/HexDump.java

@ -28,6 +28,7 @@ import java.nio.charset.Charset;
* <p> * <p>
* Origin of code: POI. * Origin of code: POI.
* *
* @version $Id: HexDump.java 1471767 2013-04-24 23:24:19Z sebb $
*/ */
public class HexDump { public class HexDump {

5
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 <code>check</code> methods in this * Wherever possible, you should use the <code>check</code> methods in this
* class to compare filenames. * class to compare filenames.
* *
* @version $Id: IOCase.java 1483915 2013-05-17 17:02:35Z sebb $
* @since 1.3 * @since 1.3
*/ */
public enum IOCase implements Serializable { 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 * Unix file separator and case-insensitive if they use the Windows file separator
* (see {@link java.io.File#separatorChar}). * (see {@link java.io.File#separatorChar}).
* <p> * <p>
* 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. * versa, then the value of the case-sensitivity flag will change.
*/ */
SYSTEM ("System", !FilenameUtils.isSystemWindows()); SYSTEM ("System", !FilenameUtils.isSystemWindows());
@ -77,7 +78,7 @@ public enum IOCase implements Serializable {
* @throws IllegalArgumentException if the name is invalid * @throws IllegalArgumentException if the name is invalid
*/ */
public static IOCase forName(final String name) { public static IOCase forName(final String name) {
for (final IOCase ioCase : IOCase.values()) for (IOCase ioCase : IOCase.values())
{ {
if (ioCase.getName().equals(name)) if (ioCase.getName().equals(name))
{ {

1
fine-commons-io/src/com/fr/third/org/apache/commons/io/IOExceptionWithCause.java

@ -22,6 +22,7 @@ import java.io.IOException;
/** /**
* Subclasses IOException with the {@link Throwable} constructors missing before Java 6. * 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 * @since 1.4
* @deprecated (since 2.5) use {@link IOException} instead * @deprecated (since 2.5) use {@link IOException} instead
*/ */

228
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;
* <p> * <p>
* This class provides static utility methods for input/output operations. * This class provides static utility methods for input/output operations.
* <ul> * <ul>
* <li><b>[Deprecated]</b> closeQuietly - these methods close a stream ignoring nulls and exceptions * <li>closeQuietly - these methods close a stream ignoring nulls and exceptions
* <li>toXxx/read - these methods read data from a stream * <li>toXxx/read - these methods read data from a stream
* <li>write - these methods write data to a stream * <li>write - these methods write data to a stream
* <li>copy - these methods copy all the data from one stream to another * <li>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;
* <p> * <p>
* Origin of code: Excalibur. * Origin of code: Excalibur.
* *
* @version $Id: IOUtils.java 1722156 2015-12-29 15:40:07Z ggregory $
*/ */
public class IOUtils { public class IOUtils {
// NOTE: This class is focused on InputStream, OutputStream, Reader and // NOTE: This class is focused on InputStream, OutputStream, Reader and
@ -134,11 +135,11 @@ public class IOUtils {
static { static {
// avoid security issues // avoid security issues
try (final StringBuilderWriter buf = new StringBuilderWriter(4); final StringBuilderWriter buf = new StringBuilderWriter(4);
final PrintWriter out = new PrintWriter(buf)) { final PrintWriter out = new PrintWriter(buf);
out.println(); out.println();
LINE_SEPARATOR = buf.toString(); LINE_SEPARATOR = buf.toString();
} out.close();
} }
/** /**
@ -211,12 +212,7 @@ public class IOUtils {
* </pre> * </pre>
* *
* @param input the Reader to close, may be null or already closed * @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) { public static void closeQuietly(final Reader input) {
closeQuietly((Closeable) input); closeQuietly((Closeable) input);
} }
@ -242,12 +238,7 @@ public class IOUtils {
* </pre> * </pre>
* *
* @param output the Writer to close, may be null or already closed * @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) { public static void closeQuietly(final Writer output) {
closeQuietly((Closeable) output); closeQuietly((Closeable) output);
} }
@ -274,12 +265,7 @@ public class IOUtils {
* </pre> * </pre>
* *
* @param input the InputStream to close, may be null or already closed * @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) { public static void closeQuietly(final InputStream input) {
closeQuietly((Closeable) input); closeQuietly((Closeable) input);
} }
@ -307,12 +293,7 @@ public class IOUtils {
* </pre> * </pre>
* *
* @param output the OutputStream to close, may be null or already closed * @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) { public static void closeQuietly(final OutputStream output) {
closeQuietly((Closeable) output); closeQuietly((Closeable) output);
} }
@ -351,12 +332,7 @@ public class IOUtils {
* *
* @param closeable the objects to close, may be null or already closed * @param closeable the objects to close, may be null or already closed
* @since 2.0 * @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) { public static void closeQuietly(final Closeable closeable) {
try { try {
if (closeable != null) { if (closeable != null) {
@ -409,12 +385,7 @@ public class IOUtils {
* @param closeables the objects to close, may be null or already closed * @param closeables the objects to close, may be null or already closed
* @see #closeQuietly(Closeable) * @see #closeQuietly(Closeable)
* @since 2.5 * @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) { public static void closeQuietly(final Closeable... closeables) {
if (closeables == null) { if (closeables == null) {
return; return;
@ -446,12 +417,7 @@ public class IOUtils {
* *
* @param sock the Socket to close, may be null or already closed * @param sock the Socket to close, may be null or already closed
* @since 2.0 * @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) { public static void closeQuietly(final Socket sock) {
if (sock != null) { if (sock != null) {
try { try {
@ -484,12 +450,7 @@ public class IOUtils {
* *
* @param selector the Selector to close, may be null or already closed * @param selector the Selector to close, may be null or already closed
* @since 2.2 * @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) { public static void closeQuietly(final Selector selector) {
if (selector != null) { if (selector != null) {
try { try {
@ -522,12 +483,7 @@ public class IOUtils {
* *
* @param sock the ServerSocket to close, may be null or already closed * @param sock the ServerSocket to close, may be null or already closed
* @since 2.2 * @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) { public static void closeQuietly(final ServerSocket sock) {
if (sock != null) { if (sock != null) {
try { try {
@ -585,7 +541,7 @@ public class IOUtils {
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
* @since 2.5 * @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); return ByteArrayOutputStream.toBufferedInputStream(input, size);
} }
@ -614,7 +570,7 @@ public class IOUtils {
* @see #buffer(Reader) * @see #buffer(Reader)
* @since 2.5 * @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); 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 * @throws NullPointerException if the input parameter is null
* @since 2.5 * @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); 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 * @throws NullPointerException if the input parameter is null
* @since 2.5 * @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); 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 * @throws NullPointerException if the input parameter is null
* @since 2.5 * @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 // reject null early on rather than waiting for IO operation to fail
if (outputStream == null) { // not checked by BufferedOutputStream if (outputStream == null) { // not checked by BufferedOutputStream
throw new NullPointerException(); throw new NullPointerException();
@ -737,7 +693,7 @@ public class IOUtils {
* @throws NullPointerException if the input parameter is null * @throws NullPointerException if the input parameter is null
* @since 2.5 * @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 // reject null early on rather than waiting for IO operation to fail
if (inputStream == null) { // not checked by BufferedInputStream if (inputStream == null) { // not checked by BufferedInputStream
throw new NullPointerException(); throw new NullPointerException();
@ -761,11 +717,10 @@ public class IOUtils {
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
public static byte[] toByteArray(final InputStream input) throws IOException { public static byte[] toByteArray(final InputStream input) throws IOException {
try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { final ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output); copy(input, output);
return output.toByteArray(); return output.toByteArray();
} }
}
/** /**
* Gets contents of an <code>InputStream</code> as a <code>byte[]</code>. * Gets contents of an <code>InputStream</code> as a <code>byte[]</code>.
@ -818,14 +773,14 @@ public class IOUtils {
final byte[] data = new byte[size]; final byte[] data = new byte[size];
int offset = 0; int offset = 0;
int read; int readed;
while (offset < size && (read = input.read(data, offset, size - offset)) != EOF) { while (offset < size && (readed = input.read(data, offset, size - offset)) != EOF) {
offset += read; offset += readed;
} }
if (offset != size) { 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; return data;
@ -864,11 +819,10 @@ public class IOUtils {
* @since 2.3 * @since 2.3
*/ */
public static byte[] toByteArray(final Reader input, final Charset encoding) throws IOException { public static byte[] toByteArray(final Reader input, final Charset encoding) throws IOException {
try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { final ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output, encoding); copy(input, output, encoding);
return output.toByteArray(); return output.toByteArray();
} }
}
/** /**
* Gets the contents of a <code>Reader</code> as a <code>byte[]</code> * Gets the contents of a <code>Reader</code> as a <code>byte[]</code>
@ -953,8 +907,11 @@ public class IOUtils {
* @since 2.4 * @since 2.4
*/ */
public static byte[] toByteArray(final URLConnection urlConn) throws IOException { public static byte[] toByteArray(final URLConnection urlConn) throws IOException {
try (InputStream inputStream = urlConn.getInputStream()) { final InputStream inputStream = urlConn.getInputStream();
try {
return IOUtils.toByteArray(inputStream); return IOUtils.toByteArray(inputStream);
} finally {
inputStream.close();
} }
} }
@ -1080,11 +1037,10 @@ public class IOUtils {
* @since 2.3 * @since 2.3
*/ */
public static String toString(final InputStream input, final Charset encoding) throws IOException { public static String toString(final InputStream input, final Charset encoding) throws IOException {
try (final StringBuilderWriter sw = new StringBuilderWriter()) { final StringBuilderWriter sw = new StringBuilderWriter();
copy(input, sw, encoding); copy(input, sw, encoding);
return sw.toString(); return sw.toString();
} }
}
/** /**
* Gets the contents of an <code>InputStream</code> as a String * Gets the contents of an <code>InputStream</code> as a String
@ -1122,11 +1078,10 @@ public class IOUtils {
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
public static String toString(final Reader input) throws IOException { public static String toString(final Reader input) throws IOException {
try (final StringBuilderWriter sw = new StringBuilderWriter()) { final StringBuilderWriter sw = new StringBuilderWriter();
copy(input, sw); copy(input, sw);
return sw.toString(); return sw.toString();
} }
}
/** /**
* Gets the contents at the given URI. * Gets the contents at the given URI.
@ -1195,8 +1150,11 @@ public class IOUtils {
* @since 2.3 * @since 2.3
*/ */
public static String toString(final URL url, final Charset encoding) throws IOException { 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); return toString(inputStream, encoding);
} finally {
inputStream.close();
} }
} }
@ -1249,132 +1207,6 @@ public class IOUtils {
return new String(input, Charsets.toCharset(encoding)); return new String(input, Charsets.toCharset(encoding));
} }
// resources
//-----------------------------------------------------------------------
/**
* Gets the contents of a classpath resource as a String using the
* specified character encoding.
*
* <p>
* It is expected the given <code>name</code> to be absolute. The
* behavior is not well-defined otherwise.
* </p>
*
* @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.
*
* <p>
* It is expected the given <code>name</code> to be absolute. The
* behavior is not well-defined otherwise.
* </p>
*
* @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.
*
* <p>
* It is expected the given <code>name</code> to be absolute. The
* behavior is not well-defined otherwise.
* </p>
*
* @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.
*
* <p>
* It is expected the given <code>name</code> to be absolute. The
* behavior is not well-defined otherwise.
* </p>
*
* @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.
*
* <p>
* It is expected the given <code>name</code> to be absolute. The
* behavior is not well-defined otherwise.
* </p>
*
* @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.
*
* <p>
* It is expected the given <code>name</code> to be absolute. The
* behavior is not well-defined otherwise.
* </p>
*
* @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 // readLines
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -1455,7 +1287,7 @@ public class IOUtils {
*/ */
public static List<String> readLines(final Reader input) throws IOException { public static List<String> readLines(final Reader input) throws IOException {
final BufferedReader reader = toBufferedReader(input); final BufferedReader reader = toBufferedReader(input);
final List<String> list = new ArrayList<>(); final List<String> list = new ArrayList<String>();
String line = reader.readLine(); String line = reader.readLine();
while (line != null) { while (line != null) {
list.add(line); list.add(line);
@ -1706,7 +1538,7 @@ public class IOUtils {
int bytes = data.length; int bytes = data.length;
int offset = 0; int offset = 0;
while (bytes > 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); output.write(data, offset, chunk);
bytes -= chunk; bytes -= chunk;
offset += chunk; offset += chunk;
@ -1813,7 +1645,7 @@ public class IOUtils {
int bytes = data.length; int bytes = data.length;
int offset = 0; int offset = 0;
while (bytes > 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); output.write(data, offset, chunk);
bytes -= chunk; bytes -= chunk;
offset += chunk; offset += chunk;

190
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.
* <p/>
* 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;
}
}

36
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; package com.fr.third.org.apache.commons.io;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.util.Iterator; import java.util.Iterator;
@ -45,9 +44,10 @@ import java.util.NoSuchElementException;
* } * }
* </pre> * </pre>
* *
* @version $Id: LineIterator.java 1471767 2013-04-24 23:24:19Z sebb $
* @since 1.2 * @since 1.2
*/ */
public class LineIterator implements Iterator<String>, Closeable { public class LineIterator implements Iterator<String> {
// N.B. This class deliberately does not implement Iterable, see https://issues.apache.org/jira/browse/IO-181 // 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<String>, Closeable {
* @return {@code true} if the Reader has more lines * @return {@code true} if the Reader has more lines
* @throws IllegalStateException if an IO exception occurs * @throws IllegalStateException if an IO exception occurs
*/ */
@Override
public boolean hasNext() { public boolean hasNext() {
if (cachedLine != null) { if (cachedLine != null) {
return true; return true;
@ -103,11 +102,7 @@ public class LineIterator implements Iterator<String>, Closeable {
} }
} }
} catch(final IOException ioe) { } catch(final IOException ioe) {
try {
close(); close();
} catch (final IOException e) {
ioe.addSuppressed(e);
}
throw new IllegalStateException(ioe); throw new IllegalStateException(ioe);
} }
} }
@ -129,7 +124,6 @@ public class LineIterator implements Iterator<String>, Closeable {
* @return the next line from the input * @return the next line from the input
* @throws NoSuchElementException if there is no line to return * @throws NoSuchElementException if there is no line to return
*/ */
@Override
public String next() { public String next() {
return nextLine(); return nextLine();
} }
@ -150,21 +144,16 @@ public class LineIterator implements Iterator<String>, Closeable {
} }
/** /**
* Closes the underlying {@code Reader}. * Closes the underlying <code>Reader</code> quietly.
* This method is useful if you only want to process the first few * 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 * lines of a larger file. If you do not close the iterator
* then the {@code Reader} remains open. * then the <code>Reader</code> remains open.
* This method can safely be called multiple times. * This method can safely be called multiple times.
*
* @throws IOException if closing the underlying {@code Reader} fails.
*/ */
@Override public void close() {
public void close() throws IOException {
finished = true; finished = true;
IOUtils.closeQuietly(bufferedReader);
cachedLine = null; cachedLine = null;
if (this.bufferedReader != null) {
this.bufferedReader.close();
}
} }
/** /**
@ -172,29 +161,20 @@ public class LineIterator implements Iterator<String>, Closeable {
* *
* @throws UnsupportedOperationException always * @throws UnsupportedOperationException always
*/ */
@Override
public void remove() { public void remove() {
throw new UnsupportedOperationException("Remove unsupported on LineIterator"); 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}. * @param iterator the iterator to close
* @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 LineIterator iterator) { public static void closeQuietly(final LineIterator iterator) {
try {
if (iterator != null) { if (iterator != null) {
iterator.close(); iterator.close();
} }
} catch(final IOException e) {
// Suppressed.
}
} }
} }

8
fine-commons-io/src/com/fr/third/org/apache/commons/io/ThreadMonitor.java

@ -36,6 +36,7 @@ package com.fr.third.org.apache.commons.io;
* } * }
* </pre> * </pre>
* *
* @version $Id: ThreadMonitor.java 1718945 2015-12-09 19:51:14Z krosenvold $
*/ */
class ThreadMonitor implements Runnable { class ThreadMonitor implements Runnable {
@ -102,7 +103,6 @@ class ThreadMonitor implements Runnable {
* *
* @see Runnable#run() * @see Runnable#run()
*/ */
@Override
public void run() { public void run() {
try { try {
sleep(timeout); 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 * 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. * it deems appropriate. Read the docs on Thread.sleep for further interesting details.
* * @
* @param ms the number of milliseconds to sleep for * @param ms the number of milliseconds to sleep for
* @throws InterruptedException if interrupted * @throws InterruptedException if interrupted
*/ */
private static void sleep(final long ms) throws InterruptedException { private static void sleep(long ms) throws InterruptedException {
final long finishAt = System.currentTimeMillis() + ms; long finishAt = System.currentTimeMillis() + ms;
long remaining = ms; long remaining = ms;
do { do {
Thread.sleep(remaining); Thread.sleep(remaining);

1
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/AbstractFileComparator.java

@ -25,6 +25,7 @@ import java.util.List;
/** /**
* Abstract file {@link Comparator} which provides sorting for file arrays and lists. * 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 * @since 2.0
*/ */
abstract class AbstractFileComparator implements Comparator<File> { abstract class AbstractFileComparator implements Comparator<File> {

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/CompositeFileComparator.java

@ -39,6 +39,7 @@ import java.util.List;
* comparator.sort(list); * comparator.sort(list);
* </pre> * </pre>
* *
* @version $Id: CompositeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 2.0 * @since 2.0
*/ */
public class CompositeFileComparator extends AbstractFileComparator implements Serializable { public class CompositeFileComparator extends AbstractFileComparator implements Serializable {
@ -72,7 +73,7 @@ public class CompositeFileComparator extends AbstractFileComparator implements S
if (delegates == null) { if (delegates == null) {
this.delegates = (Comparator<File>[]) NO_COMPARATORS; //1 this.delegates = (Comparator<File>[]) NO_COMPARATORS; //1
} else { } else {
final List<Comparator<File>> list = new ArrayList<>(); final List<Comparator<File>> list = new ArrayList<Comparator<File>>();
for (final Comparator<File> comparator : delegates) { for (final Comparator<File> comparator : delegates) {
list.add(comparator); list.add(comparator);
} }
@ -88,7 +89,6 @@ public class CompositeFileComparator extends AbstractFileComparator implements S
* @return the first non-zero result returned from * @return the first non-zero result returned from
* the delegate comparators or zero. * the delegate comparators or zero.
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
int result = 0; int result = 0;
for (final Comparator<File> delegate : delegates) { for (final Comparator<File> delegate : delegates) {

2
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DefaultFileComparator.java

@ -41,6 +41,7 @@ import java.util.Comparator;
* </pre> * </pre>
* <p> * <p>
* *
* @version $Id: DefaultFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class DefaultFileComparator extends AbstractFileComparator implements Serializable { public class DefaultFileComparator extends AbstractFileComparator implements Serializable {
@ -61,7 +62,6 @@ public class DefaultFileComparator extends AbstractFileComparator implements Ser
* @return the result of calling file1's * @return the result of calling file1's
* {@link File#compareTo(File)} with file2 as the parameter. * {@link File#compareTo(File)} with file2 as the parameter.
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
return file1.compareTo(file2); return file1.compareTo(file2);
} }

2
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DirectoryFileComparator.java

@ -40,6 +40,7 @@ import java.util.Comparator;
* </pre> * </pre>
* <p> * <p>
* *
* @version $Id: DirectoryFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 2.0 * @since 2.0
*/ */
public class DirectoryFileComparator extends AbstractFileComparator implements Serializable { public class DirectoryFileComparator extends AbstractFileComparator implements Serializable {
@ -60,7 +61,6 @@ public class DirectoryFileComparator extends AbstractFileComparator implements S
* @return the result of calling file1's * @return the result of calling file1's
* {@link File#compareTo(File)} with file2 as the parameter. * {@link File#compareTo(File)} with file2 as the parameter.
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
return getType(file1) - getType(file2); return getType(file1) - getType(file2);
} }

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ExtensionFileComparator.java

@ -20,8 +20,6 @@ import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; 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.FilenameUtils;
import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase;
@ -50,6 +48,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre> * </pre>
* <p> * <p>
* *
* @version $Id: ExtensionFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class ExtensionFileComparator extends AbstractFileComparator implements Serializable { public class ExtensionFileComparator extends AbstractFileComparator implements Serializable {
@ -106,7 +105,6 @@ public class ExtensionFileComparator extends AbstractFileComparator implements S
* is greater than the second file. * is greater than the second file.
* *
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
final String suffix1 = FilenameUtils.getExtension(file1.getName()); final String suffix1 = FilenameUtils.getExtension(file1.getName());
final String suffix2 = FilenameUtils.getExtension(file2.getName()); final String suffix2 = FilenameUtils.getExtension(file2.getName());

2
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/LastModifiedFileComparator.java

@ -42,6 +42,7 @@ import java.util.Comparator;
* </pre> * </pre>
* <p> * <p>
* *
* @version $Id: LastModifiedFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class LastModifiedFileComparator extends AbstractFileComparator implements Serializable { public class LastModifiedFileComparator extends AbstractFileComparator implements Serializable {
@ -65,7 +66,6 @@ public class LastModifiedFileComparator extends AbstractFileComparator implement
* is greater than the second file. * is greater than the second file.
* *
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
final long result = file1.lastModified() - file2.lastModified(); final long result = file1.lastModified() - file2.lastModified();
if (result < 0) { if (result < 0) {

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/NameFileComparator.java

@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import com.fr.third.org.apache.commons.io.IOCase;
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;
* </pre> * </pre>
* <p> * <p>
* *
* @version $Id: NameFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class NameFileComparator extends AbstractFileComparator implements Serializable { public class NameFileComparator extends AbstractFileComparator implements Serializable {
@ -100,7 +100,6 @@ public class NameFileComparator extends AbstractFileComparator implements Serial
* same and a positive value if the first files name * same and a positive value if the first files name
* is greater than the second file. * is greater than the second file.
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
return caseSensitivity.checkCompareTo(file1.getName(), file2.getName()); return caseSensitivity.checkCompareTo(file1.getName(), file2.getName());
} }

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/PathFileComparator.java

@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import com.fr.third.org.apache.commons.io.IOCase;
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;
* </pre> * </pre>
* <p> * <p>
* *
* @version $Id: PathFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class PathFileComparator extends AbstractFileComparator implements Serializable { public class PathFileComparator extends AbstractFileComparator implements Serializable {
@ -101,7 +101,6 @@ public class PathFileComparator extends AbstractFileComparator implements Serial
* is greater than the second file. * is greater than the second file.
* *
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath()); return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath());
} }

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ReverseComparator.java

@ -24,6 +24,7 @@ import java.util.Comparator;
* Reverses the result of comparing two objects using * Reverses the result of comparing two objects using
* the delegate {@link Comparator}. * the delegate {@link Comparator}.
* *
* @version $Id: ReverseComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
class ReverseComparator extends AbstractFileComparator implements Serializable { class ReverseComparator extends AbstractFileComparator implements Serializable {
@ -32,7 +33,7 @@ class ReverseComparator extends AbstractFileComparator implements Serializable {
private final Comparator<File> delegate; private final Comparator<File> 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 * @param delegate The comparator to delegate to
*/ */
@ -51,7 +52,6 @@ class ReverseComparator extends AbstractFileComparator implements Serializable {
* @return the result from the delegate {@link Comparator#compare(Object, Object)} * @return the result from the delegate {@link Comparator#compare(Object, Object)}
* reversing the value (i.e. positive becomes negative and vice versa) * reversing the value (i.e. positive becomes negative and vice versa)
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
return delegate.compare(file2, file1); // parameters switched round return delegate.compare(file2, file1); // parameters switched round
} }

5
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/SizeFileComparator.java

@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
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.FileUtils;
/** /**
@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.FileUtils;
* <strong>N.B.</strong> Directories are treated as <b>zero size</b> unless * <strong>N.B.</strong> Directories are treated as <b>zero size</b> unless
* <code>sumDirectoryContents</code> is {@code true}. * <code>sumDirectoryContents</code> is {@code true}.
* *
* @version $Id: SizeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class SizeFileComparator extends AbstractFileComparator implements Serializable { public class SizeFileComparator extends AbstractFileComparator implements Serializable {
@ -88,7 +88,7 @@ public class SizeFileComparator extends AbstractFileComparator implements Serial
* If the <code>sumDirectoryContents</code> is {@code true} The size of * If the <code>sumDirectoryContents</code> is {@code true} The size of
* directories is calculated using {@link FileUtils#sizeOfDirectory(File)}. * 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 * should be calculated, otherwise {@code false} if directories should be treated
* as size zero (see {@link FileUtils#sizeOfDirectory(File)}). * as size zero (see {@link FileUtils#sizeOfDirectory(File)}).
*/ */
@ -107,7 +107,6 @@ public class SizeFileComparator extends AbstractFileComparator implements Serial
* is greater than the second file. * is greater than the second file.
* *
*/ */
@Override
public int compare(final File file1, final File file2) { public int compare(final File file1, final File file2) {
long size1 = 0; long size1 = 0;
if (file1.isDirectory()) { if (file1.isDirectory()) {

10
fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/package.html

@ -35,9 +35,11 @@ for {@link java.io.File}s.
<p> <p>
...alternatively you can do this in one line: ...alternatively you can do this in one line:
</p> </p>
<p>
<pre> <pre>
File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles()); File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
</pre> </pre>
</p>
<h3>Composite Comparator</h3> <h3>Composite Comparator</h3>
<p> <p>
@ -48,6 +50,7 @@ for {@link java.io.File}s.
For example, to sort an array of files by type (i.e. directory or file) For example, to sort an array of files by type (i.e. directory or file)
and then by name: and then by name:
</p> </p>
<p>
<pre> <pre>
CompositeFileComparator comparator = CompositeFileComparator comparator =
new CompositeFileComparator( new CompositeFileComparator(
@ -56,12 +59,12 @@ for {@link java.io.File}s.
File[] files = dir.listFiles(); File[] files = dir.listFiles();
comparator.sort(files); comparator.sort(files);
</pre> </pre>
</p>
<h3>Singleton Instances (thread-safe)</h3> <h3>Singleton Instances (thread-safe)</h3>
<p> <p>
The {@link java.util.Comparator} implementations have some <i>convenience</i> The {@link java.util.Comparator} implementations have some <i>convenience</i>
singleton(<i>thread-safe</i>) instances ready to use: singleton(<i>thread-safe</i>) instances ready to use:
</p>
<ul> <ul>
<li><a href="DefaultFileComparator.html">DefaultFileComparator</a> - default file compare: <li><a href="DefaultFileComparator.html">DefaultFileComparator</a> - default file compare:
<ul> <ul>
@ -76,10 +79,10 @@ for {@link java.io.File}s.
<li><a href="DirectoryFileComparator.html">DirectoryFileComparator</a> - compare by type (directory or file): <li><a href="DirectoryFileComparator.html">DirectoryFileComparator</a> - compare by type (directory or file):
<ul> <ul>
<li><a href="DirectoryFileComparator.html#DIRECTORY_COMPARATOR">DIRECTORY_COMPARATOR</a> <li><a href="DirectoryFileComparator.html#DIRECTORY_COMPARATOR">DIRECTORY_COMPARATOR</a>
- Compare using <code>File.isDirectory()</code> method (directories &lt; files). - Compare using <code>File.isDirectory()</code> method (directories < files).
</li> </li>
<li><a href="DirectoryFileComparator.html#DIRECTORY_REVERSE">DIRECTORY_REVERSE</a> <li><a href="DirectoryFileComparator.html#DIRECTORY_REVERSE">DIRECTORY_REVERSE</a>
- Reverse compare of <code>File.isDirectory()</code> method (directories &gt;files). - Reverse compare of <code>File.isDirectory()</code> method (directories > files).
</li> </li>
</ul> </ul>
</li> </li>
@ -179,6 +182,7 @@ for {@link java.io.File}s.
</ul> </ul>
</li> </li>
</ul> </ul>
</p>
</body> </body>
</html> </html>

8
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AbstractFileFilter.java

@ -26,7 +26,7 @@ import java.io.File;
* otherwise your class will infinitely loop. * otherwise your class will infinitely loop.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: AbstractFileFilter.java 1415850 2012-11-30 20:51:39Z ggregory $
*/ */
public abstract class AbstractFileFilter implements IOFileFilter { public abstract class AbstractFileFilter implements IOFileFilter {
@ -36,7 +36,6 @@ public abstract class AbstractFileFilter implements IOFileFilter {
* @param file the File to check * @param file the File to check
* @return true if this file matches the test * @return true if this file matches the test
*/ */
@Override
public boolean accept(final File file) { public boolean accept(final File file) {
return accept(file.getParentFile(), file.getName()); return accept(file.getParentFile(), file.getName());
} }
@ -48,15 +47,14 @@ public abstract class AbstractFileFilter implements IOFileFilter {
* @param name the filename within the directory to check * @param name the filename within the directory to check
* @return true if this file matches the test * @return true if this file matches the test
*/ */
@Override
public boolean accept(final File dir, final String name) { public boolean accept(final File dir, final String name) {
return accept(new File(dir, 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 @Override
public String toString() { public String toString() {

10
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AgeFileFilter.java

@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
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.FileUtils;
/** /**
@ -40,6 +39,7 @@ import com.fr.third.org.apache.commons.io.FileUtils;
* } * }
* </pre> * </pre>
* *
* @version $Id: AgeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#ageFileFilter(Date) * @see FileFilterUtils#ageFileFilter(Date)
* @see FileFilterUtils#ageFileFilter(File) * @see FileFilterUtils#ageFileFilter(File)
* @see FileFilterUtils#ageFileFilter(long) * @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). * a certain File (whose last modification time will be used as reference).
* *
* @param cutoffReference the file whose last modification * @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) { public AgeFileFilter(final File cutoffReference) {
this(cutoffReference, true); this(cutoffReference, true);
@ -119,7 +119,7 @@ public class AgeFileFilter extends AbstractFileFilter implements Serializable {
* reference). * reference).
* *
* @param cutoffReference the file whose last modification * @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) * @param acceptOlder if true, older files (at or before the cutoff)
* are accepted, else newer ones (after 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 @Override
public String toString() { public String toString() {

18
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AndFileFilter.java

@ -30,7 +30,7 @@ import java.util.List;
* {@code false}. * {@code false}.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: AndFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* *
* @see FileFilterUtils#and(IOFileFilter...) * @see FileFilterUtils#and(IOFileFilter...)
*/ */
@ -49,7 +49,7 @@ public class AndFileFilter
* @since 1.1 * @since 1.1
*/ */
public AndFileFilter() { public AndFileFilter() {
this.fileFilters = new ArrayList<>(); this.fileFilters = new ArrayList<IOFileFilter>();
} }
/** /**
@ -61,9 +61,9 @@ public class AndFileFilter
*/ */
public AndFileFilter(final List<IOFileFilter> fileFilters) { public AndFileFilter(final List<IOFileFilter> fileFilters) {
if (fileFilters == null) { if (fileFilters == null) {
this.fileFilters = new ArrayList<>(); this.fileFilters = new ArrayList<IOFileFilter>();
} else { } else {
this.fileFilters = new ArrayList<>(fileFilters); this.fileFilters = new ArrayList<IOFileFilter>(fileFilters);
} }
} }
@ -78,7 +78,7 @@ public class AndFileFilter
if (filter1 == null || filter2 == null) { if (filter1 == null || filter2 == null) {
throw new IllegalArgumentException("The filters must not be null"); throw new IllegalArgumentException("The filters must not be null");
} }
this.fileFilters = new ArrayList<>(2); this.fileFilters = new ArrayList<IOFileFilter>(2);
addFileFilter(filter1); addFileFilter(filter1);
addFileFilter(filter2); addFileFilter(filter2);
} }
@ -86,7 +86,6 @@ public class AndFileFilter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void addFileFilter(final IOFileFilter ioFileFilter) { public void addFileFilter(final IOFileFilter ioFileFilter) {
this.fileFilters.add(ioFileFilter); this.fileFilters.add(ioFileFilter);
} }
@ -94,7 +93,6 @@ public class AndFileFilter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public List<IOFileFilter> getFileFilters() { public List<IOFileFilter> getFileFilters() {
return Collections.unmodifiableList(this.fileFilters); return Collections.unmodifiableList(this.fileFilters);
} }
@ -102,7 +100,6 @@ public class AndFileFilter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public boolean removeFileFilter(final IOFileFilter ioFileFilter) { public boolean removeFileFilter(final IOFileFilter ioFileFilter) {
return this.fileFilters.remove(ioFileFilter); return this.fileFilters.remove(ioFileFilter);
} }
@ -110,7 +107,6 @@ public class AndFileFilter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void setFileFilters(final List<IOFileFilter> fileFilters) { public void setFileFilters(final List<IOFileFilter> fileFilters) {
this.fileFilters.clear(); this.fileFilters.clear();
this.fileFilters.addAll(fileFilters); 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 @Override
public String toString() { public String toString() {

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanReadFileFilter.java

@ -58,7 +58,7 @@ import java.io.Serializable;
* </pre> * </pre>
* *
* @since 1.3 * @since 1.3
* @version $Id$ * @version $Id: CanReadFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
*/ */
public class CanReadFileFilter extends AbstractFileFilter implements Serializable { public class CanReadFileFilter extends AbstractFileFilter implements Serializable {
@ -75,7 +75,7 @@ public class CanReadFileFilter extends AbstractFileFilter implements Serializabl
CanWriteFileFilter.CANNOT_WRITE); CanWriteFileFilter.CANNOT_WRITE);
/** /**
* Restrictive constructor. * Restrictive consructor.
*/ */
protected CanReadFileFilter() { protected CanReadFileFilter() {
} }

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanWriteFileFilter.java

@ -50,7 +50,7 @@ import java.io.Serializable;
* <code>CanReadFileFilter.READ_ONLY</code>. * <code>CanReadFileFilter.READ_ONLY</code>.
* *
* @since 1.3 * @since 1.3
* @version $Id$ * @version $Id: CanWriteFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
*/ */
public class CanWriteFileFilter extends AbstractFileFilter implements Serializable { 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); public static final IOFileFilter CANNOT_WRITE = new NotFileFilter(CAN_WRITE);
/** /**
* Restrictive constructor. * Restrictive consructor.
*/ */
protected CanWriteFileFilter() { protected CanWriteFileFilter() {
} }

2
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/ConditionalFileFilter.java

@ -22,7 +22,7 @@ import java.util.List;
* Defines operations for conditional file filters. * Defines operations for conditional file filters.
* *
* @since 1.1 * @since 1.1
* @version $Id$ * @version $Id: ConditionalFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
*/ */
public interface ConditionalFileFilter { public interface ConditionalFileFilter {

6
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. * This class turns a Java FileFilter or FilenameFilter into an IO FileFilter.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: DelegateFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* *
* @see FileFilterUtils#asFileFilter(FileFilter) * @see FileFilterUtils#asFileFilter(FileFilter)
* @see FileFilterUtils#asFileFilter(FilenameFilter) * @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 @Override
public String toString() { public String toString() {

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DirectoryFileFilter.java

@ -34,7 +34,7 @@ import java.io.Serializable;
* </pre> * </pre>
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: DirectoryFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* *
* @see FileFilterUtils#directoryFileFilter() * @see FileFilterUtils#directoryFileFilter()
*/ */
@ -55,7 +55,7 @@ public class DirectoryFileFilter extends AbstractFileFilter implements Serializa
public static final IOFileFilter INSTANCE = DIRECTORY; public static final IOFileFilter INSTANCE = DIRECTORY;
/** /**
* Restrictive constructor. * Restrictive consructor.
*/ */
protected DirectoryFileFilter() { protected DirectoryFileFilter() {
} }

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/EmptyFileFilter.java

@ -49,7 +49,7 @@ import java.io.Serializable;
* </pre> * </pre>
* *
* @since 1.3 * @since 1.3
* @version $Id$ * @version $Id: EmptyFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
*/ */
public class EmptyFileFilter extends AbstractFileFilter implements Serializable { 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); public static final IOFileFilter NOT_EMPTY = new NotFileFilter(EMPTY);
/** /**
* Restrictive constructor. * Restrictive consructor.
*/ */
protected EmptyFileFilter() { protected EmptyFileFilter() {
} }

6
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FalseFileFilter.java

@ -23,7 +23,7 @@ import java.io.Serializable;
* A file filter that always returns false. * A file filter that always returns false.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: FalseFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* *
* @see FileFilterUtils#falseFileFilter() * @see FileFilterUtils#falseFileFilter()
*/ */
@ -44,7 +44,7 @@ public class FalseFileFilter implements IOFileFilter, Serializable {
public static final IOFileFilter INSTANCE = FALSE; public static final IOFileFilter INSTANCE = FALSE;
/** /**
* Restrictive constructor. * Restrictive consructor.
*/ */
protected FalseFileFilter() { protected FalseFileFilter() {
} }
@ -55,7 +55,6 @@ public class FalseFileFilter implements IOFileFilter, Serializable {
* @param file the file to check (ignored) * @param file the file to check (ignored)
* @return false * @return false
*/ */
@Override
public boolean accept(final File file) { public boolean accept(final File file) {
return false; return false;
} }
@ -67,7 +66,6 @@ public class FalseFileFilter implements IOFileFilter, Serializable {
* @param name the filename (ignored) * @param name the filename (ignored)
* @return false * @return false
*/ */
@Override
public boolean accept(final File dir, final String name) { public boolean accept(final File dir, final String name) {
return false; return false;
} }

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFileFilter.java

@ -34,7 +34,7 @@ import java.io.Serializable;
* </pre> * </pre>
* *
* @since 1.3 * @since 1.3
* @version $Id$ * @version $Id: FileFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#fileFileFilter() * @see FileFilterUtils#fileFileFilter()
*/ */
public class FileFileFilter extends AbstractFileFilter implements Serializable { 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(); public static final IOFileFilter FILE = new FileFileFilter();
/** /**
* Restrictive constructor. * Restrictive consructor.
*/ */
protected FileFileFilter() { protected FileFileFilter() {
} }

25
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.List;
import java.util.Set; import java.util.Set;
import com.fr.third.org.apache.commons.io.IOCase;
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. * every class you use.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: FileFilterUtils.java 1471767 2013-04-24 23:24:19Z sebb $
*/ */
public class FileFilterUtils { public class FileFilterUtils {
@ -81,7 +80,7 @@ public class FileFilterUtils {
if (files == null) { if (files == null) {
return new File[0]; return new File[0];
} }
final List<File> acceptedFiles = new ArrayList<>(); final List<File> acceptedFiles = new ArrayList<File>();
for (final File file : files) { for (final File file : files) {
if (file == null) { if (file == null) {
throw new IllegalArgumentException("file array contains null"); throw new IllegalArgumentException("file array contains null");
@ -211,7 +210,7 @@ public class FileFilterUtils {
*/ */
public static Set<File> filterSet(final IOFileFilter filter, final File... files) { public static Set<File> filterSet(final IOFileFilter filter, final File... files) {
final File[] acceptedFiles = filter(filter, files); final File[] acceptedFiles = filter(filter, files);
return new HashSet<>(Arrays.asList(acceptedFiles)); return new HashSet<File>(Arrays.asList(acceptedFiles));
} }
/** /**
@ -450,7 +449,7 @@ public class FileFilterUtils {
if (filters == null) { if (filters == null) {
throw new IllegalArgumentException("The filters must not be null"); throw new IllegalArgumentException("The filters must not be null");
} }
final List<IOFileFilter> list = new ArrayList<>(filters.length); final List<IOFileFilter> list = new ArrayList<IOFileFilter>(filters.length);
for (int i = 0; i < filters.length; i++) { for (int i = 0; i < filters.length; i++) {
if (filters[i] == null) { if (filters[i] == null) {
throw new IllegalArgumentException("The filter[" + i + "] is 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 * Returns a filter that returns true if the file was last modified after
* or at the specified cutoff time. * the specified cutoff time.
* *
* @param cutoff the time threshold * @param cutoff the time threshold
* @return an appropriately configured age file filter * @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 * Returns a filter that returns true if the file was last modified after
* or at the specified cutoff date. * the specified cutoff date.
* *
* @param cutoffDate the time threshold * @param cutoffDate the time threshold
* @return an appropriately configured age file filter * @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 * Returns a filter that returns true if the file was last modified after
* or at the same time as the specified reference file. * the specified reference file.
* *
* @param cutoffReference the file whose last modification * @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 * @return an appropriately configured age file filter
* @see AgeFileFilter * @see AgeFileFilter
* @since 1.2 * @since 1.2
@ -588,7 +587,7 @@ public class FileFilterUtils {
* Returns a filter that filters files based on a cutoff reference file. * Returns a filter that filters files based on a cutoff reference file.
* *
* @param cutoffReference the file whose last modification * @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 * @param acceptOlder if true, older files get accepted, if false, newer
* @return an appropriately configured age file filter * @return an appropriately configured age file filter
* @see AgeFileFilter * @see AgeFileFilter

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/HiddenFileFilter.java

@ -46,7 +46,7 @@ import java.io.Serializable;
* </pre> * </pre>
* *
* @since 1.3 * @since 1.3
* @version $Id$ * @version $Id: HiddenFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
*/ */
public class HiddenFileFilter extends AbstractFileFilter implements Serializable { 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); public static final IOFileFilter VISIBLE = new NotFileFilter(HIDDEN);
/** /**
* Restrictive constructor. * Restrictive consructor.
*/ */
protected HiddenFileFilter() { protected HiddenFileFilter() {
} }

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/IOFileFilter.java

@ -25,7 +25,7 @@ import java.io.FilenameFilter;
* interfaces together. * interfaces together.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: IOFileFilter.java 1471767 2013-04-24 23:24:19Z sebb $
*/ */
public interface IOFileFilter extends FileFilter, FilenameFilter { public interface IOFileFilter extends FileFilter, FilenameFilter {
@ -37,7 +37,6 @@ public interface IOFileFilter extends FileFilter, FilenameFilter {
* @param file the File to check * @param file the File to check
* @return true if this file matches the test * @return true if this file matches the test
*/ */
@Override
boolean accept(File file); boolean accept(File file);
/** /**
@ -49,7 +48,6 @@ public interface IOFileFilter extends FileFilter, FilenameFilter {
* @param name the filename within the directory to check * @param name the filename within the directory to check
* @return true if this file matches the test * @return true if this file matches the test
*/ */
@Override
boolean accept(File dir, String name); boolean accept(File dir, String name);
} }

11
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.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import com.fr.third.org.apache.commons.io.IOUtils;
/** /**
* <p> * <p>
* File filter for matching files containing a "magic number". A magic number * File filter for matching files containing a "magic number". A magic number
@ -232,19 +234,20 @@ public class MagicNumberFileFilter extends AbstractFileFilter implements
@Override @Override
public boolean accept(final File file) { public boolean accept(final File file) {
if (file != null && file.isFile() && file.canRead()) { if (file != null && file.isFile() && file.canRead()) {
RandomAccessFile randomAccessFile = null;
try { try {
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r")) {
final byte[] fileBytes = new byte[this.magicNumbers.length]; final byte[] fileBytes = new byte[this.magicNumbers.length];
randomAccessFile = new RandomAccessFile(file, "r");
randomAccessFile.seek(byteOffset); randomAccessFile.seek(byteOffset);
final int read = randomAccessFile.read(fileBytes); final int read = randomAccessFile.read(fileBytes);
if (read != magicNumbers.length) { if (read != magicNumbers.length) {
return false; return false;
} }
return Arrays.equals(this.magicNumbers, fileBytes); return Arrays.equals(this.magicNumbers, fileBytes);
} } catch (final IOException ioe) {
}
catch (final IOException ioe) {
// Do nothing, fall through and do not accept file // Do nothing, fall through and do not accept file
} finally {
IOUtils.closeQuietly(randomAccessFile);
} }
} }

7
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.io.Serializable;
import java.util.List; import java.util.List;
import com.fr.third.org.apache.commons.io.IOCase;
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;
* </pre> * </pre>
* *
* @since 1.0 * @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)
* @see FileFilterUtils#nameFileFilter(String, IOCase) * @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 @Override
public String toString() { public String toString() {

6
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. * This filter produces a logical NOT of the filters specified.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: NotFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#notFileFilter(IOFileFilter) * @see FileFilterUtils#notFileFilter(IOFileFilter)
*/ */
public class NotFileFilter extends AbstractFileFilter implements Serializable { 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 @Override
public String toString() { public String toString() {

18
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/OrFileFilter.java

@ -30,7 +30,7 @@ import java.util.List;
* {@code true}. * {@code true}.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: OrFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#or(IOFileFilter...) * @see FileFilterUtils#or(IOFileFilter...)
*/ */
public class OrFileFilter public class OrFileFilter
@ -47,7 +47,7 @@ public class OrFileFilter
* @since 1.1 * @since 1.1
*/ */
public OrFileFilter() { public OrFileFilter() {
this.fileFilters = new ArrayList<>(); this.fileFilters = new ArrayList<IOFileFilter>();
} }
/** /**
@ -59,9 +59,9 @@ public class OrFileFilter
*/ */
public OrFileFilter(final List<IOFileFilter> fileFilters) { public OrFileFilter(final List<IOFileFilter> fileFilters) {
if (fileFilters == null) { if (fileFilters == null) {
this.fileFilters = new ArrayList<>(); this.fileFilters = new ArrayList<IOFileFilter>();
} else { } else {
this.fileFilters = new ArrayList<>(fileFilters); this.fileFilters = new ArrayList<IOFileFilter>(fileFilters);
} }
} }
@ -76,7 +76,7 @@ public class OrFileFilter
if (filter1 == null || filter2 == null) { if (filter1 == null || filter2 == null) {
throw new IllegalArgumentException("The filters must not be null"); throw new IllegalArgumentException("The filters must not be null");
} }
this.fileFilters = new ArrayList<>(2); this.fileFilters = new ArrayList<IOFileFilter>(2);
addFileFilter(filter1); addFileFilter(filter1);
addFileFilter(filter2); addFileFilter(filter2);
} }
@ -84,7 +84,6 @@ public class OrFileFilter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void addFileFilter(final IOFileFilter ioFileFilter) { public void addFileFilter(final IOFileFilter ioFileFilter) {
this.fileFilters.add(ioFileFilter); this.fileFilters.add(ioFileFilter);
} }
@ -92,7 +91,6 @@ public class OrFileFilter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public List<IOFileFilter> getFileFilters() { public List<IOFileFilter> getFileFilters() {
return Collections.unmodifiableList(this.fileFilters); return Collections.unmodifiableList(this.fileFilters);
} }
@ -100,7 +98,6 @@ public class OrFileFilter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public boolean removeFileFilter(final IOFileFilter ioFileFilter) { public boolean removeFileFilter(final IOFileFilter ioFileFilter) {
return this.fileFilters.remove(ioFileFilter); return this.fileFilters.remove(ioFileFilter);
} }
@ -108,7 +105,6 @@ public class OrFileFilter
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void setFileFilters(final List<IOFileFilter> fileFilters) { public void setFileFilters(final List<IOFileFilter> fileFilters) {
this.fileFilters.clear(); this.fileFilters.clear();
this.fileFilters.addAll(fileFilters); 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 @Override
public String toString() { public String toString() {

7
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.io.Serializable;
import java.util.List; import java.util.List;
import com.fr.third.org.apache.commons.io.IOCase;
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;
* </pre> * </pre>
* *
* @since 1.0 * @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)
* @see FileFilterUtils#prefixFileFilter(String, IOCase) * @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 @Override
public String toString() { public String toString() {

2
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/RegexFileFilter.java

@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.fr.third.org.apache.commons.io.IOCase;
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;
* } * }
* </pre> * </pre>
* *
* @version $Id: RegexFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class RegexFileFilter extends AbstractFileFilter implements Serializable { public class RegexFileFilter extends AbstractFileFilter implements Serializable {

5
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SizeFileFilter.java

@ -34,6 +34,7 @@ import java.io.Serializable;
* } * }
* </pre> * </pre>
* *
* @version $Id: SizeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.2 * @since 1.2
* @see FileFilterUtils#sizeFileFilter(long) * @see FileFilterUtils#sizeFileFilter(long)
* @see FileFilterUtils#sizeFileFilter(long, boolean) * @see FileFilterUtils#sizeFileFilter(long, boolean)
@ -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 @Override
public String toString() { public String toString() {

11
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.io.Serializable;
import java.util.List; import java.util.List;
import com.fr.third.org.apache.commons.io.IOCase;
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;
* </pre> * </pre>
* *
* @since 1.0 * @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)
* @see FileFilterUtils#suffixFileFilter(String, IOCase) * @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.
* <p> * <p>
* The array is not cloned, so could be changed after constructing the * The array is not cloned, so could be changed after constructing the
* instance. This would be inadvisable however. * 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. * specifying case-sensitivity.
* *
* @param suffixes the suffixes to allow, must not be null * @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 @Override
public String toString() { public String toString() {

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/TrueFileFilter.java

@ -23,7 +23,7 @@ import java.io.Serializable;
* A file filter that always returns true. * A file filter that always returns true.
* *
* @since 1.0 * @since 1.0
* @version $Id$ * @version $Id: TrueFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#trueFileFilter() * @see FileFilterUtils#trueFileFilter()
*/ */
public class TrueFileFilter implements IOFileFilter, Serializable { public class TrueFileFilter implements IOFileFilter, Serializable {
@ -54,7 +54,6 @@ public class TrueFileFilter implements IOFileFilter, Serializable {
* @param file the file to check (ignored) * @param file the file to check (ignored)
* @return true * @return true
*/ */
@Override
public boolean accept(final File file) { public boolean accept(final File file) {
return true; return true;
} }
@ -66,7 +65,6 @@ public class TrueFileFilter implements IOFileFilter, Serializable {
* @param name the filename (ignored) * @param name the filename (ignored)
* @return true * @return true
*/ */
@Override
public boolean accept(final File dir, final String name) { public boolean accept(final File dir, final String name) {
return true; return true;
} }

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFileFilter.java

@ -20,8 +20,6 @@ import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; 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.FilenameUtils;
import com.fr.third.org.apache.commons.io.IOCase; import com.fr.third.org.apache.commons.io.IOCase;
@ -47,6 +45,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* } * }
* </pre> * </pre>
* *
* @version $Id: WildcardFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.3 * @since 1.3
*/ */
public class WildcardFileFilter extends AbstractFileFilter implements Serializable { public class WildcardFileFilter extends AbstractFileFilter implements Serializable {

6
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.io.Serializable;
import java.util.List; import java.util.List;
import com.fr.third.org.apache.commons.io.FilenameUtils;
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;
* } * }
* </pre> * </pre>
* *
* @version $Id: WildcardFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.1 * @since 1.1
* @deprecated Use WildcardFileFilter. Deprecated as this class performs directory * @deprecated Use WilcardFileFilter. Deprecated as this class performs directory
* filtering which it shouldn't do, but that can't be removed due to compatibility. * filtering which it shouldn't do, but that can't be removed due to compatability.
*/ */
@Deprecated @Deprecated
public class WildcardFilter extends AbstractFileFilter implements Serializable { public class WildcardFilter extends AbstractFileFilter implements Serializable {

8
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.</p> other such filters.</p>
<p>These filter can be used to list files or in {@link java.awt.FileDialog}, <p>These filter can be used to list files or in {@link java.awt.FileDialog},
for example.</p> for example.</p>
<p>There are a number of 'primitive' filters:</p>
<table> <table>
<caption>There are a number of 'primitive' filters:</caption>
<tbody> <tbody>
<tr> <tr>
<td><a href="DirectoryFileFilter.html">DirectoryFilter</a></td> <td><a href="DirectoryFileFilter.html">DirectoryFilter</a></td>
@ -57,8 +59,10 @@ for example.</p>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<p>And there are five 'boolean' filters:</p>
<table> <table>
<caption>And there are five 'boolean' filters:</caption>
<tbody> <tbody>
<tr> <tr>
<td><a href="TrueFileFilter.html">TrueFileFilter</a></td> <td><a href="TrueFileFilter.html">TrueFileFilter</a></td>

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/AutoCloseInputStream.java

@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; 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.IOException;
import java.io.InputStream; 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 * 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. * 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 * @since 1.4
*/ */
public class AutoCloseInputStream extends ProxyInputStream { public class AutoCloseInputStream extends ProxyInputStream {

17
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BOMInputStream.java

@ -16,18 +16,14 @@
*/ */
package com.fr.third.org.apache.commons.io.input; 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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
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.IOUtils; 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 is used to wrap a stream that includes an encoded {@link ByteOrderMark} as its first bytes.
@ -86,7 +82,7 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark;
* *
* @see ByteOrderMark * @see ByteOrderMark
* @see <a href="http://en.wikipedia.org/wiki/Byte_order_mark">Wikipedia - Byte Order Mark</a> * @see <a href="http://en.wikipedia.org/wiki/Byte_order_mark">Wikipedia - Byte Order Mark</a>
* @version $Id$ * @version $Id: BOMInputStream.java 1686527 2015-06-20 06:31:39Z krosenvold $
* @since 2.0 * @since 2.0
*/ */
public class BOMInputStream extends ProxyInputStream { public class BOMInputStream extends ProxyInputStream {
@ -141,7 +137,6 @@ public class BOMInputStream extends ProxyInputStream {
*/ */
private static final Comparator<ByteOrderMark> ByteOrderMarkLengthComparator = new Comparator<ByteOrderMark>() { private static final Comparator<ByteOrderMark> ByteOrderMarkLengthComparator = new Comparator<ByteOrderMark>() {
@Override
public int compare(final ByteOrderMark bom1, final ByteOrderMark bom2) { public int compare(final ByteOrderMark bom1, final ByteOrderMark bom2) {
final int len1 = bom1.length(); final int len1 = bom1.length();
final int len2 = bom2.length(); final int len2 = bom2.length();
@ -171,10 +166,9 @@ public class BOMInputStream extends ProxyInputStream {
throw new IllegalArgumentException("No BOMs specified"); throw new IllegalArgumentException("No BOMs specified");
} }
this.include = include; this.include = include;
final List<ByteOrderMark> list = Arrays.asList(boms);
// Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes. // Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes.
Collections.sort(list, ByteOrderMarkLengthComparator); Arrays.sort(boms, ByteOrderMarkLengthComparator);
this.boms = list; this.boms = Arrays.asList(boms);
} }
@ -204,8 +198,7 @@ public class BOMInputStream extends ProxyInputStream {
if (!boms.contains(bom)) { if (!boms.contains(bom)) {
throw new IllegalArgumentException("Stream not configure to detect " + bom); throw new IllegalArgumentException("Stream not configure to detect " + bom);
} }
getBOM(); return byteOrderMark != null && getBOM().equals(bom);
return byteOrderMark != null && byteOrderMark.equals(bom);
} }
/** /**
@ -404,7 +397,7 @@ public class BOMInputStream extends ProxyInputStream {
* if an I/O error occurs * if an I/O error occurs
*/ */
@Override @Override
public long skip(final long n) throws IOException { public long skip(long n) throws IOException {
int skipped = 0; int skipped = 0;
while ((n > skipped) && (readFirstBytes() >= 0)) { while ((n > skipped) && (readFirstBytes() >= 0)) {
skipped++; skipped++;

5
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 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.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -34,6 +32,7 @@ import java.io.InputStream;
* ServletInputStream's header, will stop it blocking, providing it's been sent * ServletInputStream's header, will stop it blocking, providing it's been sent
* with a correct content length. * with a correct content length.
* *
* @version $Id: BoundedInputStream.java 1586342 2014-04-10 15:36:29Z ggregory $
* @since 2.0 * @since 2.0
*/ */
public class BoundedInputStream extends InputStream { public class BoundedInputStream extends InputStream {
@ -50,7 +49,7 @@ public class BoundedInputStream extends InputStream {
/** the marked position */ /** the marked position */
private long mark = IOUtils.EOF; private long mark = IOUtils.EOF;
/** flag if close should be propagated */ /** flag if close shoud be propagated */
private boolean propagateClose = true; private boolean propagateClose = true;
/** /**

20
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 * @param maxCharsFromTargetReader The maximum number of characters that can be read from target
* @throws IOException if mark fails * @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.target = target;
this.maxCharsFromTargetReader = maxCharsFromTargetReader; 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 * @throws IOException If an I/O error occurs while calling the underlying reader's reset method
* @see java.io.Reader#reset()
*/ */
@Override @Override
public void reset() throws IOException { 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 * @param readAheadLimit The number of characters that can be read while
* still retaining the ability to do #reset(). * still retaining the ability to do #reset().
@ -95,10 +94,9 @@ public class BoundedReader
* greater. * greater.
* *
* @throws IOException If an I/O error occurs while calling the underlying reader's mark method * @throws IOException If an I/O error occurs while calling the underlying reader's mark method
* @see java.io.Reader#mark(int)
*/ */
@Override @Override
public void mark( final int readAheadLimit ) throws IOException { public void mark( int readAheadLimit ) throws IOException {
this.readAheadLimit = readAheadLimit - charsRead; this.readAheadLimit = readAheadLimit - charsRead;
markedAt = 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 * @return -1 on eof or the character read
* @throws IOException If an I/O error occurs while calling the underlying reader's read method * @throws IOException If an I/O error occurs while calling the underlying reader's read method
* @see java.io.Reader#read()
*/ */
@Override @Override
public int read() throws IOException { 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 cbuf The buffer to fill
* @param off The offset * @param off The offset
* @param len The number of chars to read * @param len The number of chars to read
* @return the number of chars read * @return the number of chars read
* @throws IOException If an I/O error occurs while calling the underlying reader's read method * @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 @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; int c;
for ( int i = 0; i < len; i++ ) { for ( int i = 0; i < len; i++ ) {
c = read(); c = read();
if ( c == -1 ) { if ( c == -1 ) {
return i == 0 ? -1 : i; return i;
} }
cbuf[off + i] = (char) c; cbuf[off + i] = (char) c;
} }

2
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 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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

5
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceReader.java

@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; 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.Reader;
import java.io.Serializable; import java.io.Serializable;
@ -29,6 +27,7 @@ import java.io.Serializable;
* <p> * <p>
* <strong>Note:</strong> Supports {@link #mark(int)} and {@link #reset()}. * <strong>Note:</strong> Supports {@link #mark(int)} and {@link #reset()}.
* *
* @version $Id: CharSequenceReader.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class CharSequenceReader extends Reader implements Serializable { 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 array The array to store the characters in
* @param offset The starting position in the array to store * @param offset The starting position in the array to store

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClassLoaderObjectInputStream.java

@ -29,6 +29,7 @@ import java.lang.reflect.Proxy;
* <p> * <p>
* This is useful in dynamic container environments. * This is useful in dynamic container environments.
* *
* @version $Id: ClassLoaderObjectInputStream.java 1471767 2013-04-24 23:24:19Z sebb $
* @since 1.1 * @since 1.1
*/ */
public class ClassLoaderObjectInputStream extends ObjectInputStream { public class ClassLoaderObjectInputStream extends ObjectInputStream {
@ -66,7 +67,7 @@ public class ClassLoaderObjectInputStream extends ObjectInputStream {
try { try {
return Class.forName(objectStreamClass.getName(), false, classLoader); return Class.forName(objectStreamClass.getName(), false, classLoader);
} catch (final ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
// delegate to super class loader which can resolve primitives // delegate to super class loader which can resolve primitives
return super.resolveClass(objectStreamClass); return super.resolveClass(objectStreamClass);
} }

1
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CloseShieldInputStream.java

@ -25,6 +25,7 @@ import java.io.InputStream;
* passed to a component that wants to explicitly close the stream even if * passed to a component that wants to explicitly close the stream even if
* more input would still be available to other components. * more input would still be available to other components.
* *
* @version $Id: CloseShieldInputStream.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 1.4 * @since 1.4
*/ */
public class CloseShieldInputStream extends ProxyInputStream { public class CloseShieldInputStream extends ProxyInputStream {

3
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 com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.InputStream; 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 * that accept input streams and acting as a sentinel value instead of a
* {@code null} input stream. * {@code null} input stream.
* *
* @version $Id: ClosedInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
* @since 1.4 * @since 1.4
*/ */
public class ClosedInputStream extends InputStream { public class ClosedInputStream extends InputStream {

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CountingInputStream.java

@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; 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.IOException;
import java.io.InputStream; 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 * A typical use case would be during debugging, to ensure that data is being
* read as expected. * read as expected.
* *
* @version $Id: CountingInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
*/ */
public class CountingInputStream extends ProxyInputStream { public class CountingInputStream extends ProxyInputStream {

5
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/DemuxInputStream.java

@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; 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.IOException;
import java.io.InputStream; 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 * Data written to this stream is forwarded to a stream that has been associated
* with this thread. * with this thread.
* *
* @version $Id: DemuxInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
*/ */
public class DemuxInputStream public class DemuxInputStream
extends InputStream extends InputStream
{ {
private final InheritableThreadLocal<InputStream> m_streams = new InheritableThreadLocal<>(); private final InheritableThreadLocal<InputStream> m_streams = new InheritableThreadLocal<InputStream>();
/** /**
* Bind the specified stream to the current thread. * Bind the specified stream to the current thread.

52
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/InfiniteCircularInputStream.java

@ -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.
* <p>
* Closing a <tt>InfiniteCircularInputStream</tt> has no effect. The methods in
* this class can be called after the stream has been closed without generating
* an <tt>IOException</tt>.
*
*/
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()
}
}

102
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java

@ -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.
* <em>Note</em>: 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.
* <em>Note</em>: 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;
}
}

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullInputStream.java

@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; 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.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -62,7 +60,7 @@ import java.io.InputStream;
* </pre> * </pre>
* *
* @since 1.3 * @since 1.3
* @version $Id$ * @version $Id: NullInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
*/ */
public class NullInputStream extends InputStream { public class NullInputStream extends InputStream {

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullReader.java

@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; 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.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
@ -62,7 +60,7 @@ import java.io.Reader;
* </pre> * </pre>
* *
* @since 1.3 * @since 1.3
* @version $Id$ * @version $Id: NullReader.java 1586350 2014-04-10 15:57:20Z ggregory $
*/ */
public class NullReader extends Reader { public class NullReader extends Reader {

266
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ObservableInputStream.java

@ -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 <em>not</em> 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<Observer> 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<Observer> 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;
}
}
}
}

3
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 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.FilterInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; 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 * See the protected methods for ways in which a subclass can easily decorate
* a stream with custom pre-, post- or error processing functionality. * 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 { public abstract class ProxyInputStream extends FilterInputStream {

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyReader.java

@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; 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.FilterReader;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
@ -34,6 +32,7 @@ import java.nio.CharBuffer;
* 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). * 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 { public abstract class ProxyReader extends FilterReader {

7
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; package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; import com.fr.third.org.apache.commons.io.IOUtils;
import com.fr.third.org.apache.commons.io.output.WriterOutputStream;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; 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 * 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 * 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 * 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. * interface from the Java Activation Framework.
* <p> * <p>
* Given the fact that the {@link Reader} class doesn't provide any way to predict whether the next * 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;
* <p> * <p>
* Instances of {@link ReaderInputStream} are not thread safe. * Instances of {@link ReaderInputStream} are not thread safe.
* *
* @see com.fr.third.org.apache.commons.io.output.WriterOutputStream * @see WriterOutputStream
* *
* @since 2.0 * @since 2.0
*/ */

10
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.io.UnsupportedEncodingException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder; 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; 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 * @throws IOException if an I/O error occurs
* @since 2.3 * @since 2.3
*/ */
@SuppressWarnings("deprecation") // unavoidable until Java 7
public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException { public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException {
this.blockSize = blockSize; this.blockSize = blockSize;
this.encoding = encoding; this.encoding = encoding;
@ -104,7 +103,7 @@ public class ReversedLinesFileReader implements Closeable {
if (maxBytesPerChar == 1f) { if (maxBytesPerChar == 1f) {
// all one byte encodings are no problem // all one byte encodings are no problem
byteDecrement = 1; 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 // 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 // http://en.wikipedia.org/wiki/UTF-8
byteDecrement = 1; byteDecrement = 1;
@ -115,11 +114,11 @@ public class ReversedLinesFileReader implements Closeable {
charset == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese) charset == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese)
charset == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese) charset == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese)
byteDecrement = 1; 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, // UTF-16 new line sequences are not allowed as second tuple of four byte sequences,
// however byte order has to be specified // however byte order has to be specified
byteDecrement = 2; 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 " + throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte order (use UTF-16BE or " +
"UTF-16LE)"); "UTF-16LE)");
} else { } else {
@ -199,7 +198,6 @@ public class ReversedLinesFileReader implements Closeable {
* *
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public void close() throws IOException { public void close() throws IOException {
randomAccessFile.close(); randomAccessFile.close();
} }

19
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/SwappedDataInputStream.java

@ -16,8 +16,6 @@
*/ */
package com.fr.third.org.apache.commons.io.input; 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.DataInput;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
@ -25,7 +23,6 @@ import java.io.InputStream;
import com.fr.third.org.apache.commons.io.EndianUtils; 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.IOUtils;
import com.fr.third.org.apache.commons.io.EndianUtils;
/** /**
* DataInput for systems relying on little endian data formats. * DataInput for systems relying on little endian data formats.
@ -34,6 +31,7 @@ import com.fr.third.org.apache.commons.io.EndianUtils;
* <p> * <p>
* <b>Origin of code: </b>Avalon Excalibur (IO) * <b>Origin of code: </b>Avalon Excalibur (IO)
* *
* @version CVS $Revision: 1302050 $
*/ */
public class SwappedDataInputStream extends ProxyInputStream public class SwappedDataInputStream extends ProxyInputStream
implements DataInput implements DataInput
@ -55,7 +53,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
*/ */
@Override
public boolean readBoolean() public boolean readBoolean()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -68,7 +65,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
*/ */
@Override
public byte readByte() public byte readByte()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -81,7 +77,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
*/ */
@Override
public char readChar() public char readChar()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -94,7 +89,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
*/ */
@Override
public double readDouble() public double readDouble()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -107,7 +101,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
*/ */
@Override
public float readFloat() public float readFloat()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -121,7 +114,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public void readFully( final byte[] data ) public void readFully( final byte[] data )
throws IOException, EOFException throws IOException, EOFException
{ {
@ -138,7 +130,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public void readFully( final byte[] data, final int offset, final int length ) public void readFully( final byte[] data, final int offset, final int length )
throws IOException, EOFException throws IOException, EOFException
{ {
@ -164,7 +155,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public int readInt() public int readInt()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -177,7 +167,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public String readLine() public String readLine()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -191,7 +180,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public long readLong() public long readLong()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -204,7 +192,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public short readShort() public short readShort()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -217,7 +204,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public int readUnsignedByte() public int readUnsignedByte()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -230,7 +216,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public int readUnsignedShort() public int readUnsignedShort()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -243,7 +228,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public String readUTF() public String readUTF()
throws IOException, EOFException throws IOException, EOFException
{ {
@ -258,7 +242,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly * @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
@Override
public int skipBytes( final int count ) public int skipBytes( final int count )
throws IOException, EOFException throws IOException, EOFException
{ {

1
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TaggedInputStream.java

@ -21,7 +21,6 @@ import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.UUID; import java.util.UUID;
import com.fr.third.org.apache.commons.io.TaggedIOException;
import com.fr.third.org.apache.commons.io.TaggedIOException; import com.fr.third.org.apache.commons.io.TaggedIOException;
/** /**

47
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; 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.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -27,7 +25,6 @@ import java.nio.charset.Charset;
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; 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. * Simple implementation of the unix "tail -f" functionality.
@ -112,10 +109,10 @@ import com.fr.third.org.apache.commons.io.FileUtils;
* </pre> * </pre>
* <p>If you interrupt a tailer, the tailer listener is called with the {@link InterruptedException}.</p> * <p>If you interrupt a tailer, the tailer listener is called with the {@link InterruptedException}.</p>
* *
* <p>The file is read using the default charset; this can be overridden if necessary</p> * <p>The file is read using the default charset; this can be overriden if necessary</p>
* @see TailerListener * @see TailerListener
* @see TailerListenerAdapter * @see TailerListenerAdapter
* @version $Id$ * @version $Id: Tailer.java 1714076 2015-11-12 16:06:41Z krosenvold $
* @since 2.0 * @since 2.0
* @since 2.5 Updated behavior and documentation for {@link Thread#interrupt()} * @since 2.5 Updated behavior and documentation for {@link Thread#interrupt()}
*/ */
@ -404,7 +401,6 @@ public class Tailer implements Runnable {
/** /**
* Follows changes in the file, calling the TailerListener's handle method for each new line. * Follows changes in the file, calling the TailerListener's handle method for each new line.
*/ */
@Override
public void run() { public void run() {
RandomAccessFile reader = null; RandomAccessFile reader = null;
try { try {
@ -433,22 +429,24 @@ public class Tailer implements Runnable {
if (length < position) { if (length < position) {
// File was rotated // File was rotated
listener.fileRotated(); listener.fileRotated();
// Reopen the reader after rotation ensuring that the old file is closed iff we re-open it // Reopen the reader after rotation
// successfully try {
try (RandomAccessFile save = reader) { // Ensure that the old file is closed iff we re-open it successfully
final RandomAccessFile save = reader;
reader = new RandomAccessFile(file, RAF_MODE); reader = new RandomAccessFile(file, RAF_MODE);
// At this point, we're sure that the old file is rotated // 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 // Finish scanning the old file and then we'll start with the new one
try { try {
readLines(save); readLines(save);
} catch (final IOException ioe) { } catch (IOException ioe) {
listener.handle(ioe); listener.handle(ioe);
} }
position = 0; position = 0;
// close old file explicitly rather than relying on GC picking up previous RAF
IOUtils.closeQuietly(save);
} catch (final FileNotFoundException e) { } catch (final FileNotFoundException e) {
// in this case we continue to use the previous reader and position values // in this case we continue to use the previous reader and position values
listener.fileNotFound(); listener.fileNotFound();
Thread.sleep(delayMillis);
} }
continue; continue;
} else { } else {
@ -471,8 +469,8 @@ public class Tailer implements Runnable {
last = file.lastModified(); last = file.lastModified();
} }
} }
if (reOpen && reader != null) { if (reOpen) {
reader.close(); IOUtils.closeQuietly(reader);
} }
Thread.sleep(delayMillis); Thread.sleep(delayMillis);
if (getRun() && reOpen) { if (getRun() && reOpen) {
@ -482,21 +480,22 @@ public class Tailer implements Runnable {
} }
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
listener.handle(e); stop(e);
} catch (final Exception e) { } catch (final Exception e) {
listener.handle(e); stop(e);
} finally { } finally {
try { IOUtils.closeQuietly(reader);
if (reader != null) {
reader.close();
} }
} }
catch (final IOException e) {
/**
* Stops the tailer with an exception
* @param e The exception to send to listener
*/
private void stop(final Exception e) {
listener.handle(e); listener.handle(e);
}
stop(); stop();
} }
}
/** /**
* Allows the tailer to complete its current loop and return. * Allows the tailer to complete its current loop and return.
@ -513,7 +512,7 @@ public class Tailer implements Runnable {
* @throws java.io.IOException if an I/O error occurs. * @throws java.io.IOException if an I/O error occurs.
*/ */
private long readLines(final RandomAccessFile reader) throws IOException { private long readLines(final RandomAccessFile reader) throws IOException {
try (ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64)) { ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64);
long pos = reader.getFilePointer(); long pos = reader.getFilePointer();
long rePos = pos; // position to re-read long rePos = pos; // position to re-read
int num; int num;
@ -546,7 +545,7 @@ public class Tailer implements Runnable {
} }
pos = reader.getFilePointer(); pos = reader.getFilePointer();
} }
IOUtils.closeQuietly(lineBuf); // not strictly necessary
reader.seek(rePos); // Ensure we can re-read if necessary reader.seek(rePos); // Ensure we can re-read if necessary
if (listener instanceof TailerListenerAdapter) { if (listener instanceof TailerListenerAdapter) {
@ -555,5 +554,5 @@ public class Tailer implements Runnable {
return rePos; return rePos;
} }
}
} }

1
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}. * Listener for events from a {@link Tailer}.
* *
* @version $Id: TailerListener.java 1714076 2015-11-12 16:06:41Z krosenvold $
* @since 2.0 * @since 2.0
*/ */
public interface TailerListener { public interface TailerListener {

6
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. * {@link TailerListener} Adapter.
* *
* @version $Id: TailerListenerAdapter.java 1714076 2015-11-12 16:06:41Z krosenvold $
* @since 2.0 * @since 2.0
*/ */
public class TailerListenerAdapter implements TailerListener { public class TailerListenerAdapter implements TailerListener {
@ -28,14 +29,12 @@ public class TailerListenerAdapter implements TailerListener {
* giving the listener a method of stopping the tailer. * giving the listener a method of stopping the tailer.
* @param tailer the tailer. * @param tailer the tailer.
*/ */
@Override
public void init(final Tailer tailer) { public void init(final Tailer tailer) {
} }
/** /**
* This method is called if the tailed file is not found. * This method is called if the tailed file is not found.
*/ */
@Override
public void fileNotFound() { public void fileNotFound() {
} }
@ -45,7 +44,6 @@ public class TailerListenerAdapter implements TailerListener {
* This method is called before the file is reopened, and fileNotFound may * This method is called before the file is reopened, and fileNotFound may
* be called if the new file has not yet been created. * be called if the new file has not yet been created.
*/ */
@Override
public void fileRotated() { public void fileRotated() {
} }
@ -53,7 +51,6 @@ public class TailerListenerAdapter implements TailerListener {
* Handles a line from a Tailer. * Handles a line from a Tailer.
* @param line the line. * @param line the line.
*/ */
@Override
public void handle(final String line) { public void handle(final String line) {
} }
@ -61,7 +58,6 @@ public class TailerListenerAdapter implements TailerListener {
* Handles an Exception . * Handles an Exception .
* @param ex the exception. * @param ex the exception.
*/ */
@Override
public void handle(final Exception ex) { public void handle(final Exception ex) {
} }

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TeeInputStream.java

@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils; 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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -35,8 +33,8 @@ import java.io.OutputStream;
* called on this proxy. It is configurable whether the associated output * called on this proxy. It is configurable whether the associated output
* stream will also closed. * stream will also closed.
* *
* @version $Id: TeeInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
* @since 1.4 * @since 1.4
* @see ObservableInputStream
*/ */
public class TeeInputStream extends ProxyInputStream { public class TeeInputStream extends ProxyInputStream {

10
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 in The input stream to wrap
* @param ensureLineFeedAtEndOfFile true to ensure that the file ends with LF * @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.target = in;
this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile; this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
} }
@ -69,12 +69,12 @@ public class UnixLineEndingInputStream extends InputStream {
*/ */
@Override @Override
public int read() throws IOException { public int read() throws IOException {
final boolean previousWasSlashR = slashRSeen; boolean previousWasSlashR = slashRSeen;
if ( eofSeen ) { if ( eofSeen ) {
return eofGame(previousWasSlashR); return eofGame(previousWasSlashR);
} }
else { else {
final int target = readWithUpdate(); int target = readWithUpdate();
if ( eofSeen ) { if ( eofSeen ) {
return eofGame(previousWasSlashR); return eofGame(previousWasSlashR);
} }
@ -96,7 +96,7 @@ public class UnixLineEndingInputStream extends InputStream {
* @param previousWasSlashR Indicates if the last seen was a \r * @param previousWasSlashR Indicates if the last seen was a \r
* @return The next char to output to the stream * @return The next char to output to the stream
*/ */
private int eofGame(final boolean previousWasSlashR) { private int eofGame(boolean previousWasSlashR) {
if ( previousWasSlashR || !ensureLineFeedAtEndOfFile ) { if ( previousWasSlashR || !ensureLineFeedAtEndOfFile ) {
return -1; return -1;
} }
@ -122,7 +122,7 @@ public class UnixLineEndingInputStream extends InputStream {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public synchronized void mark( final int readlimit ) { public synchronized void mark( int readlimit ) {
throw new UnsupportedOperationException( "Mark notsupported" ); throw new UnsupportedOperationException( "Mark notsupported" );
} }
} }

8
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 in The input stream to wrap
* @param ensureLineFeedAtEndOfFile true to ensure that the file ends with CRLF * @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.target = in;
this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile; this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
} }
@ -76,8 +76,8 @@ public class WindowsLineEndingInputStream extends InputStream {
injectSlashN = false; injectSlashN = false;
return '\n'; return '\n';
} else { } else {
final boolean prevWasSlashR = slashRSeen; boolean prevWasSlashR = slashRSeen;
final int target = readWithUpdate(); int target = readWithUpdate();
if ( eofSeen ) { if ( eofSeen ) {
return eofGame(); return eofGame();
} }
@ -128,7 +128,7 @@ public class WindowsLineEndingInputStream extends InputStream {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public synchronized void mark( final int readlimit ) { public synchronized void mark( int readlimit ) {
throw new UnsupportedOperationException( "Mark not supported" ); throw new UnsupportedOperationException( "Mark not supported" );
} }
} }

15
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 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.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. * charset encoding of the XML document within the stream.
* <p> * <p>
* IMPORTANT: This class is not related in any way to the org.xml.sax.XMLReader. * 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. * Files, raw streams and HTTP streams by offering a wide set of constructors.
* <p> * <p>
* By default the charset encoding detection is lenient, the constructor with * 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, <a * specifications). All this is nicely explained by Mark Pilgrim in his blog, <a
* href="http://diveintomark.org/archives/2004/02/13/xml-media-types"> * href="http://diveintomark.org/archives/2004/02/13/xml-media-types">
* Determining the character encoding of a feed</a>. * Determining the character encoding of a feed</a>.
@ -60,7 +60,8 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark;
* Originally developed for <a href="http://rome.dev.java.net">ROME</a> under * Originally developed for <a href="http://rome.dev.java.net">ROME</a> under
* Apache License 2.0. * 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 * @since 2.0
*/ */
public class XmlStreamReader extends Reader { 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. * header.
* <p> * <p>
* First it checks if the stream has BOM. If there is not BOM checks the * 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. * header. This constructor is lenient regarding the encoding detection.
* <p> * <p>
* First it checks if the stream has BOM. If there is not BOM checks the * 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. * header. This constructor is lenient regarding the encoding detection.
* <p> * <p>
* First it checks if the stream has BOM. If there is not BOM checks the * First it checks if the stream has BOM. If there is not BOM checks the

1
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 * InputStream given to the XmlStreamReader cannot be used as that one has been
* already read. * already read.
* *
* @version $Id: XmlStreamReaderException.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0 * @since 2.0
*/ */
public class XmlStreamReaderException extends IOException { public class XmlStreamReaderException extends IOException {

2
fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListener.java

@ -23,7 +23,7 @@ import java.io.File;
* Register {@link FileAlterationListener}s with a {@link FileAlterationObserver}. * Register {@link FileAlterationListener}s with a {@link FileAlterationObserver}.
* *
* @see FileAlterationObserver * @see FileAlterationObserver
* @version $Id$ * @version $Id: FileAlterationListener.java 1304052 2012-03-22 20:55:29Z ggregory $
* @since 2.0 * @since 2.0
*/ */
public interface FileAlterationListener { public interface FileAlterationListener {

10
fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java

@ -22,7 +22,7 @@ import java.io.File;
* Convenience {@link FileAlterationListener} implementation that does nothing. * Convenience {@link FileAlterationListener} implementation that does nothing.
* *
* @see FileAlterationObserver * @see FileAlterationObserver
* @version $Id$ * @version $Id: FileAlterationListenerAdaptor.java 1304062 2012-03-22 21:10:46Z sebb $
* @since 2.0 * @since 2.0
*/ */
public class FileAlterationListenerAdaptor implements FileAlterationListener { public class FileAlterationListenerAdaptor implements FileAlterationListener {
@ -32,7 +32,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
* *
* @param observer The file system observer (ignored) * @param observer The file system observer (ignored)
*/ */
@Override
public void onStart(final FileAlterationObserver observer) { public void onStart(final FileAlterationObserver observer) {
} }
@ -41,7 +40,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
* *
* @param directory The directory created (ignored) * @param directory The directory created (ignored)
*/ */
@Override
public void onDirectoryCreate(final File directory) { public void onDirectoryCreate(final File directory) {
} }
@ -50,7 +48,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
* *
* @param directory The directory changed (ignored) * @param directory The directory changed (ignored)
*/ */
@Override
public void onDirectoryChange(final File directory) { public void onDirectoryChange(final File directory) {
} }
@ -59,7 +56,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
* *
* @param directory The directory deleted (ignored) * @param directory The directory deleted (ignored)
*/ */
@Override
public void onDirectoryDelete(final File directory) { public void onDirectoryDelete(final File directory) {
} }
@ -68,7 +64,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
* *
* @param file The file created (ignored) * @param file The file created (ignored)
*/ */
@Override
public void onFileCreate(final File file) { public void onFileCreate(final File file) {
} }
@ -77,7 +72,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
* *
* @param file The file changed (ignored) * @param file The file changed (ignored)
*/ */
@Override
public void onFileChange(final File file) { public void onFileChange(final File file) {
} }
@ -86,7 +80,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
* *
* @param file The file deleted (ignored) * @param file The file deleted (ignored)
*/ */
@Override
public void onFileDelete(final File file) { public void onFileDelete(final File file) {
} }
@ -95,7 +88,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
* *
* @param observer The file system observer (ignored) * @param observer The file system observer (ignored)
*/ */
@Override
public void onStop(final FileAlterationObserver observer) { public void onStop(final FileAlterationObserver observer) {
} }

9
fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationMonitor.java

@ -25,13 +25,13 @@ import java.util.concurrent.ThreadFactory;
* registered {@link FileAlterationObserver} at a specified interval. * registered {@link FileAlterationObserver} at a specified interval.
* *
* @see FileAlterationObserver * @see FileAlterationObserver
* @version $Id$ * @version $Id: FileAlterationMonitor.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0 * @since 2.0
*/ */
public final class FileAlterationMonitor implements Runnable { public final class FileAlterationMonitor implements Runnable {
private final long interval; private final long interval;
private final List<FileAlterationObserver> observers = new CopyOnWriteArrayList<>(); private final List<FileAlterationObserver> observers = new CopyOnWriteArrayList<FileAlterationObserver>();
private Thread thread = null; private Thread thread = null;
private ThreadFactory threadFactory; private ThreadFactory threadFactory;
private volatile boolean running = false; private volatile boolean running = false;
@ -46,7 +46,7 @@ public final class FileAlterationMonitor implements Runnable {
/** /**
* Construct a monitor with the specified interval. * 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 * checks of the file system
*/ */
public FileAlterationMonitor(final long interval) { 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. * 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 * checks of the file system
* @param observers The set of observers to add to the monitor. * @param observers The set of observers to add to the monitor.
*/ */
@ -176,7 +176,6 @@ public final class FileAlterationMonitor implements Runnable {
/** /**
* Run. * Run.
*/ */
@Override
public void run() { public void run() {
while (running) { while (running) {
for (final FileAlterationObserver observer : observers) { for (final FileAlterationObserver observer : observers) {

15
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.List;
import java.util.concurrent.CopyOnWriteArrayList; 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.FileUtils;
import com.fr.third.org.apache.commons.io.IOCase; 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.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 * To manually observe a directory, initialize the observer and invoked the
* {@link #checkAndNotify()} method as required: * {@link #checkAndNotify()} method as required:
* <pre> * <pre>
* // initialize * // intialize
* observer.init(); * observer.init();
* ... * ...
* // invoke as required * // invoke as required
@ -68,7 +65,7 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
* // finished * // finished
* observer.finish(); * observer.finish();
* </pre> * </pre>
* 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: * which creates a new thread, invoking the observer at the specified interval:
* <pre> * <pre>
* long interval = ... * long interval = ...
@ -119,13 +116,13 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
* *
* @see FileAlterationListener * @see FileAlterationListener
* @see FileAlterationMonitor * @see FileAlterationMonitor
* @version $Id$ * @version $Id: FileAlterationObserver.java 1686747 2015-06-21 18:44:49Z krosenvold $
* @since 2.0 * @since 2.0
*/ */
public class FileAlterationObserver implements Serializable { public class FileAlterationObserver implements Serializable {
private static final long serialVersionUID = 1185122225658782848L; private static final long serialVersionUID = 1185122225658782848L;
private final List<FileAlterationListener> listeners = new CopyOnWriteArrayList<>(); private final List<FileAlterationListener> listeners = new CopyOnWriteArrayList<FileAlterationListener>();
private final FileEntry rootEntry; private final FileEntry rootEntry;
private final FileFilter fileFilter; private final FileFilter fileFilter;
private final Comparator<File> comparator; private final Comparator<File> 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() { public void checkAndNotify() {
@ -370,7 +367,7 @@ public class FileAlterationObserver implements Serializable {
* @param entry the parent entry * @param entry the parent entry
* @return The child files * @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 File[] files = listFiles(file);
final FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES; final FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES;
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {

6
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 * @since 2.5
* @see java.lang.Appendable * @see java.lang.Appendable
* @version $Id$ * @version $Id: AppendableOutputStream.java 1687815 2015-06-26 17:18:56Z krosenvold $
*/ */
public class AppendableOutputStream <T extends Appendable> extends OutputStream { public class AppendableOutputStream <T extends Appendable> extends OutputStream {
@ -39,7 +39,7 @@ public class AppendableOutputStream <T extends Appendable> extends OutputStream
* *
* @param appendable the appendable to write to * @param appendable the appendable to write to
*/ */
public AppendableOutputStream(final T appendable) { public AppendableOutputStream(T appendable) {
this.appendable = appendable; this.appendable = appendable;
} }
@ -50,7 +50,7 @@ public class AppendableOutputStream <T extends Appendable> extends OutputStream
* @throws IOException upon error * @throws IOException upon error
*/ */
@Override @Override
public void write(final int b) throws IOException { public void write(int b) throws IOException {
appendable.append((char)b); appendable.append((char)b);
} }

24
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; 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.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; 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.IOUtils;
import com.fr.third.org.apache.commons.io.input.ClosedInputStream; 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 * 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 * designed to behave exactly like the original. The only exception is the
* deprecated toString(int) method that has been ignored. * 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 { public class ByteArrayOutputStream extends OutputStream {
static final int DEFAULT_SIZE = 1024;
/** A singleton empty byte array. */ /** A singleton empty byte array. */
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
/** The list of buffers, which grows and never reduces. */ /** The list of buffers, which grows and never reduces. */
private final List<byte[]> buffers = new ArrayList<>(); private final List<byte[]> buffers = new ArrayList<byte[]>();
/** The index of the current buffer. */ /** The index of the current buffer. */
private int currentBufferIndex; private int currentBufferIndex;
/** The total count of bytes in all the filled buffers. */ /** 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. * initially 1024 bytes, though its size increases if necessary.
*/ */
public ByteArrayOutputStream() { public ByteArrayOutputStream() {
this(DEFAULT_SIZE); this(1024);
} }
/** /**
@ -242,7 +238,7 @@ public class ByteArrayOutputStream extends OutputStream {
} else { } else {
//Throw away old buffers //Throw away old buffers
currentBuffer = null; currentBuffer = null;
final int size = buffers.get(0).length; int size = buffers.get(0).length;
buffers.clear(); buffers.clear();
needNewBuffer(size); needNewBuffer(size);
reuseBuffers = true; reuseBuffers = true;
@ -317,7 +313,7 @@ public class ByteArrayOutputStream extends OutputStream {
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
* @since 2.5 * @since 2.5
*/ */
public static InputStream toBufferedInputStream(final InputStream input, final int size) public static InputStream toBufferedInputStream(final InputStream input, int size)
throws IOException { throws IOException {
// It does not matter if a ByteArrayOutputStream is not closed as close() is a no-op // It does not matter if a ByteArrayOutputStream is not closed as close() is a no-op
@SuppressWarnings("resource") @SuppressWarnings("resource")
@ -341,7 +337,7 @@ public class ByteArrayOutputStream extends OutputStream {
if (remaining == 0) { if (remaining == 0) {
return new ClosedInputStream(); return new ClosedInputStream();
} }
final List<ByteArrayInputStream> list = new ArrayList<>(buffers.size()); final List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
for (final byte[] buf : buffers) { for (final byte[] buf : buffers) {
final int c = Math.min(buf.length, remaining); final int c = Math.min(buf.length, remaining);
list.add(new ByteArrayInputStream(buf, 0, c)); 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. * The result is independent of this stream.
* *
* @return the current contents of this output stream, as a byte array * @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. * using the platform default charset.
* @return the contents of the byte array as a String * @return the contents of the byte array as a String
* @see java.io.ByteArrayOutputStream#toString() * @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. * using the specified encoding.
* *
* @param enc the name of the character 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. * using the specified encoding.
* *
* @param charset the character encoding * @param charset the character encoding

6
fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedOutputStream.java

@ -46,7 +46,7 @@ public class ChunkedOutputStream extends FilterOutputStream {
* @param chunkSize the chunk size to use; must be a positive number. * @param chunkSize the chunk size to use; must be a positive number.
* @throws IllegalArgumentException if the chunk size is &lt;= 0 * @throws IllegalArgumentException if the chunk size is &lt;= 0
*/ */
public ChunkedOutputStream(final OutputStream stream, final int chunkSize) { public ChunkedOutputStream(final OutputStream stream, int chunkSize) {
super(stream); super(stream);
if (chunkSize <= 0) { if (chunkSize <= 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@ -73,11 +73,11 @@ public class ChunkedOutputStream extends FilterOutputStream {
* @throws IOException if an I/O error occurs. * @throws IOException if an I/O error occurs.
*/ */
@Override @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 bytes = length;
int dstOffset = srcOffset; int dstOffset = srcOffset;
while(bytes > 0) { while(bytes > 0) {
final int chunk = Math.min(bytes, chunkSize); int chunk = Math.min(bytes, chunkSize);
out.write(data, dstOffset, chunk); out.write(data, dstOffset, chunk);
bytes -= chunk; bytes -= chunk;
dstOffset += chunk; dstOffset += chunk;

6
fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedWriter.java

@ -46,7 +46,7 @@ public class ChunkedWriter extends FilterWriter {
* @param chunkSize the chunk size to use; must be a positive number. * @param chunkSize the chunk size to use; must be a positive number.
* @throws IllegalArgumentException if the chunk size is &lt;= 0 * @throws IllegalArgumentException if the chunk size is &lt;= 0
*/ */
public ChunkedWriter(final Writer writer, final int chunkSize) { public ChunkedWriter(final Writer writer, int chunkSize) {
super(writer); super(writer);
if (chunkSize <= 0) { if (chunkSize <= 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@ -71,11 +71,11 @@ public class ChunkedWriter extends FilterWriter {
* @throws IOException upon error * @throws IOException upon error
*/ */
@Override @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 bytes = length;
int dstOffset = srcOffset; int dstOffset = srcOffset;
while(bytes > 0) { while(bytes > 0) {
final int chunk = Math.min(bytes, chunkSize); int chunk = Math.min(bytes, chunkSize);
out.write(data, dstOffset, chunk); out.write(data, dstOffset, chunk);
bytes -= chunk; bytes -= chunk;
dstOffset += chunk; dstOffset += chunk;

2
fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CloseShieldOutputStream.java

@ -25,7 +25,7 @@ import java.io.OutputStream;
* passed to a component that wants to explicitly close the stream even if * passed to a component that wants to explicitly close the stream even if
* other components would still use the stream for output. * other components would still use the stream for output.
* </p> * </p>
* @version $Id$ * @version $Id: CloseShieldOutputStream.java 1674710 2015-04-20 00:25:55Z ggregory $
* @since 1.4 * @since 1.4
*/ */
public class CloseShieldOutputStream extends ProxyOutputStream { public class CloseShieldOutputStream extends ProxyOutputStream {

10
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 * that accept an output stream and acting as a sentinel value instead of
* a {@code null} output stream. * a {@code null} output stream.
* *
* @version $Id: ClosedOutputStream.java 1471767 2013-04-24 23:24:19Z sebb $
* @since 1.4 * @since 1.4
*/ */
public class ClosedOutputStream extends OutputStream { public class ClosedOutputStream extends OutputStream {
@ -47,13 +48,4 @@ public class ClosedOutputStream extends OutputStream {
throw new IOException("write(" + b + ") failed: stream is closed"); 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");
}
} }

1
fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CountingOutputStream.java

@ -25,6 +25,7 @@ import java.io.OutputStream;
* A typical use case would be during debugging, to ensure that data is being * A typical use case would be during debugging, to ensure that data is being
* written as expected. * written as expected.
* *
* @version $Id: CountingOutputStream.java 1415850 2012-11-30 20:51:39Z ggregory $
*/ */
public class CountingOutputStream extends ProxyOutputStream { public class CountingOutputStream extends ProxyOutputStream {

89
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.IOException;
import java.io.OutputStream; 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; 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 * 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). * to store it to file (to avoid memory issues).
* *
* @version $Id: DeferredFileOutputStream.java 1686747 2015-06-21 18:44:49Z krosenvold $
*/ */
public class DeferredFileOutputStream public class DeferredFileOutputStream
extends ThresholdingOutputStream extends ThresholdingOutputStream
{ {
// ----------------------------------------------------------- Data members // ----------------------------------------------------------- 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. * being reached.
*/ */
private ByteArrayOutputStream memoryOutputStream; private ByteArrayOutputStream memoryOutputStream;
@ -93,38 +92,19 @@ public class DeferredFileOutputStream
/** /**
* Constructs an instance of this class which will trigger an event at the * Constructs an instance of this class which will trigger an event at the
* specified threshold, and save data to a file beyond that point. * 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 threshold The number of bytes at which to trigger an event.
* @param outputFile The file to which data is saved beyond the threshold. * @param outputFile The file to which data is saved beyond the threshold.
*/ */
public DeferredFileOutputStream(final int threshold, final File outputFile) 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 * 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. * 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 threshold The number of bytes at which to trigger an event.
* @param prefix Prefix to use for the temporary file. * @param prefix Prefix to use for the temporary file.
@ -135,36 +115,12 @@ public class DeferredFileOutputStream
*/ */
public DeferredFileOutputStream(final int threshold, final String prefix, final String suffix, final File directory) public DeferredFileOutputStream(final int threshold, final String prefix, final String suffix, final File directory)
{ {
this(threshold, null, prefix, suffix, directory, ByteArrayOutputStream.DEFAULT_SIZE); this(threshold, null, prefix, suffix, directory);
if (prefix == null) { if (prefix == null) {
throw new IllegalArgumentException("Temporary file prefix is missing"); 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);
if (prefix == null) {
throw new IllegalArgumentException("Temporary file prefix is missing");
}
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 * Constructs an instance of this class which will trigger an event at the
* specified threshold, and save data either to a file beyond that point. * specified threshold, and save data either to a file beyond that point.
@ -174,18 +130,17 @@ public class DeferredFileOutputStream
* @param prefix Prefix to use for the temporary file. * @param prefix Prefix to use for the temporary file.
* @param suffix Suffix to use for the temporary file. * @param suffix Suffix to use for the temporary file.
* @param directory Temporary file directory. * @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, 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); super(threshold);
this.outputFile = outputFile; this.outputFile = outputFile;
memoryOutputStream = new ByteArrayOutputStream();
currentOutputStream = memoryOutputStream;
this.prefix = prefix; this.prefix = prefix;
this.suffix = suffix; this.suffix = suffix;
this.directory = directory; this.directory = directory;
memoryOutputStream = new ByteArrayOutputStream(initialBufferSize);
currentOutputStream = memoryOutputStream;
} }
@ -198,7 +153,7 @@ public class DeferredFileOutputStream
* *
* @return The underlying output stream. * @return The underlying output stream.
* *
* @throws IOException if an error occurs. * @exception IOException if an error occurs.
*/ */
@Override @Override
protected OutputStream getStream() throws IOException 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 * much data is being written to keep in memory, so we elect to switch to
* disk-based storage. * disk-based storage.
* *
* @throws IOException if an error occurs. * @exception IOException if an error occurs.
*/ */
@Override @Override
protected void thresholdReached() throws IOException protected void thresholdReached() throws IOException
@ -221,11 +176,10 @@ public class DeferredFileOutputStream
if (prefix != null) { if (prefix != null) {
outputFile = File.createTempFile(prefix, suffix, directory); outputFile = File.createTempFile(prefix, suffix, directory);
} }
FileUtils.forceMkdirParent(outputFile);
final FileOutputStream fos = new FileOutputStream(outputFile); final FileOutputStream fos = new FileOutputStream(outputFile);
try { try {
memoryOutputStream.writeTo(fos); memoryOutputStream.writeTo(fos);
} catch (final IOException e){ } catch (IOException e){
fos.close(); fos.close();
throw e; throw e;
} }
@ -291,7 +245,7 @@ public class DeferredFileOutputStream
/** /**
* Closes underlying output stream, and mark this as closed * Closes underlying output stream, and mark this as closed
* *
* @throws IOException if an error occurs. * @exception IOException if an error occurs.
*/ */
@Override @Override
public void close() throws IOException public void close() throws IOException
@ -306,22 +260,29 @@ public class DeferredFileOutputStream
* after it has been closed. * after it has been closed.
* *
* @param out output stream to write to. * @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 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 // 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 // but we should force the habit of closing wether we are working with
// a file or memory. // a file or memory.
if (!closed) { if (!closed)
{
throw new IOException("Stream not closed"); throw new IOException("Stream not closed");
} }
if (isInMemory()) { if(isInMemory())
{
memoryOutputStream.writeTo(out); memoryOutputStream.writeTo(out);
} else { }
try (FileInputStream fis = new FileInputStream(outputFile)) { else
{
final FileInputStream fis = new FileInputStream(outputFile);
try {
IOUtils.copy(fis, out); IOUtils.copy(fis, out);
} finally {
IOUtils.closeQuietly(fis);
} }
} }
} }

3
fine-commons-io/src/com/fr/third/org/apache/commons/io/output/DemuxOutputStream.java

@ -22,9 +22,10 @@ import java.io.OutputStream;
/** /**
* Forwards data to a stream that has been associated with this thread. * 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 { public class DemuxOutputStream extends OutputStream {
private final InheritableThreadLocal<OutputStream> outputStreamThreadLocal = new InheritableThreadLocal<>(); private final InheritableThreadLocal<OutputStream> outputStreamThreadLocal = new InheritableThreadLocal<OutputStream>();
/** /**
* Binds the specified stream to the current thread. * Binds the specified stream to the current thread.

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save