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. 22
      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. 19
      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. 49
      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;
import com.fr.third.org.apache.commons.io.input.BOMInputStream;
import java.io.Serializable;
/**
* Byte Order Mark (BOM) representation - see {@link org.apache.commons.io.input.BOMInputStream}.
* Byte Order Mark (BOM) representation - see {@link BOMInputStream}.
*
* @see com.fr.third.org.apache.commons.io.input.BOMInputStream
* @see BOMInputStream
* @see <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
* (Non-Normative)</a>
* @version $Id$
* @version $Id: ByteOrderMark.java 1586504 2014-04-10 23:34:37Z ggregory $
* @since 2.0
*/
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;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;
@ -25,7 +24,7 @@ import java.util.TreeMap;
/**
* 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>:
* <p>
* <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>
* </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
* @version $Id$
* @version $Id: Charsets.java 1686747 2015-06-21 18:44:49Z krosenvold $
*/
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
* Java platform.
* <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>:
* </p>
*
@ -73,13 +72,14 @@ public class Charsets {
*/
public static SortedMap<String, Charset> requiredCharsets() {
// maybe cache?
final TreeMap<String, Charset> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
m.put(StandardCharsets.ISO_8859_1.name(), StandardCharsets.ISO_8859_1);
m.put(StandardCharsets.US_ASCII.name(), StandardCharsets.US_ASCII);
m.put(StandardCharsets.UTF_16.name(), StandardCharsets.UTF_16);
m.put(StandardCharsets.UTF_16BE.name(), StandardCharsets.UTF_16BE);
m.put(StandardCharsets.UTF_16LE.name(), StandardCharsets.UTF_16LE);
m.put(StandardCharsets.UTF_8.name(), StandardCharsets.UTF_8);
// TODO Re-implement on Java 7 to use java.nio.charset.StandardCharsets
final TreeMap<String, Charset> m = new TreeMap<String, Charset>(String.CASE_INSENSITIVE_ORDER);
m.put(ISO_8859_1.name(), ISO_8859_1);
m.put(US_ASCII.name(), US_ASCII);
m.put(UTF_16.name(), UTF_16);
m.put(UTF_16BE.name(), UTF_16BE);
m.put(UTF_16LE.name(), UTF_16LE);
m.put(UTF_8.name(), UTF_8);
return Collections.unmodifiableSortedMap(m);
}
@ -113,11 +113,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding.
* </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
public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
/**
* <p>
@ -127,11 +127,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding.
* </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
public static final Charset US_ASCII = StandardCharsets.US_ASCII;
public static final Charset US_ASCII = Charset.forName("US-ASCII");
/**
* <p>
@ -142,11 +142,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding.
* </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
public static final Charset UTF_16 = StandardCharsets.UTF_16;
public static final Charset UTF_16 = Charset.forName("UTF-16");
/**
* <p>
@ -156,11 +156,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding.
* </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
public static final Charset UTF_16BE = StandardCharsets.UTF_16BE;
public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
/**
* <p>
@ -170,11 +170,11 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding.
* </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
public static final Charset UTF_16LE = StandardCharsets.UTF_16LE;
public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
/**
* <p>
@ -184,9 +184,9 @@ public class Charsets {
* Every implementation of the Java platform is required to support this character encoding.
* </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
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>
* Origin of code: Excalibur.
*
* @version $Id: CopyUtils.java 1680650 2015-05-20 18:36:40Z britter $
* @deprecated Use IOUtils. Will be removed in 2.0.
* Methods renamed to IOUtils.write() or IOUtils.copy().
* Null handling behaviour changed in IOUtils (null data does not

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.
* <p>
* 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
* <a href="filefilter/package-summary.html"> filefilter</a> package.
* <p>
@ -172,7 +172,7 @@ import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter;
* <p>
* Two possible scenarios are envisaged for cancellation:
* <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>
* <li><a href="#internal">3.2 Internal</a> - cancellation being decided/initiated
* from within a DirectoryWalker implementation.</li>
@ -246,7 +246,7 @@ import com.fr.third.org.apache.commons.io.filefilter.TrueFileFilter;
* </pre>
*
* @since 1.3
* @version $Id$
* @version $Id: DirectoryWalker.java 1723627 2016-01-07 21:15:47Z niallp $
*/
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;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import com.fr.third.org.apache.commons.io.input.SwappedDataInputStream;
import java.io.EOFException;
import java.io.IOException;
@ -35,7 +35,8 @@ import java.io.OutputStream;
* <p>
* 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 {

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
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar.
*
* @version $Id: FileCleaner.java 1680650 2015-05-20 18:36:40Z britter $
* @deprecated Use {@link FileCleaningTracker}
*/
@Deprecated
@ -60,7 +61,7 @@ public class FileCleaner {
/**
* Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected.
* The specified deletion strategy is used.
* The speified deletion strategy is used.
*
* @param file the file to be tracked, not null
* @param marker the marker object used to track the file, not null
@ -91,7 +92,7 @@ public class FileCleaner {
/**
* Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected.
* The specified deletion strategy is used.
* The speified deletion strategy is used.
*
* @param path the full path to the file to be tracked, not null
* @param marker the marker object used to track the file, not null
@ -125,7 +126,7 @@ public class FileCleaner {
* thread will simply exit when the JVM exits. In a more complex environment,
* with multiple class loaders (such as an application server), you should be
* aware that the file cleaner thread will continue running even if the class
* loader it was started from terminates. This can constitute a memory leak.
* loader it was started from terminates. This can consitute a memory leak.
* <p>
* 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

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
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar.
*
* @version $Id: FileCleaningTracker.java 1686747 2015-06-21 18:44:49Z krosenvold $
*/
public class FileCleaningTracker {
@ -47,7 +48,7 @@ public class FileCleaningTracker {
/**
* Queue of <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.
*/
@ -82,7 +83,7 @@ public class FileCleaningTracker {
/**
* Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected.
* The specified deletion strategy is used.
* The speified deletion strategy is used.
*
* @param file the file to be tracked, not null
* @param marker the marker object used to track the file, not null
@ -112,7 +113,7 @@ public class FileCleaningTracker {
/**
* Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected.
* The specified deletion strategy is used.
* The speified deletion strategy is used.
*
* @param path the full path to the file to be tracked, not null
* @param marker the marker object used to track the file, not null
@ -175,7 +176,7 @@ public class FileCleaningTracker {
* thread will simply exit when the JVM exits. In a more complex environment,
* with multiple class loaders (such as an application server), you should be
* aware that the file cleaner thread will continue running even if the class
* loader it was started from terminates. This can constitute a memory leak.
* loader it was started from terminates. This can consitute a memory leak.
* <p>
* 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

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

@ -28,6 +28,7 @@ import java.io.IOException;
* <p>
* This class captures the strategy to use and is designed for user subclassing.
*
* @version $Id: FileDeleteStrategy.java 1563227 2014-01-31 19:45:30Z ggregory $
* @since 1.3
*/
public class FileDeleteStrategy {
@ -106,7 +107,7 @@ public class FileDeleteStrategy {
* This implementation uses {@link File#delete()}.
*
* @param fileToDelete the file to delete, exists, not null
* @return true if the file was deleted
* @return true if the file was deleteds
* @throws NullPointerException if the file is null
* @throws IOException if an error occurs during file deletion
*/

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

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

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

@ -77,6 +77,7 @@ import java.util.Stack;
* <p>
* Origin of code: Excalibur, Alexandria, Tomcat, Commons-Utils.
*
* @version $Id: FilenameUtils.java 1702170 2015-09-10 06:35:02Z krosenvold $
* @since 1.1
*/
public class FilenameUtils {
@ -328,7 +329,7 @@ public class FilenameUtils {
*
* @param filename the filename to normalize, null returns null
* @param unixSeparator {@code true} if a unix separator should
* be used or {@code false} if a windows separator should be used.
* be used or {@code false} if a windows separtor should be used.
* @return the normalized filename, or null if invalid. Null bytes inside string will be removed
* @since 2.0
*/
@ -666,8 +667,6 @@ public class FilenameUtils {
return 2;
}
return 3;
} else if (ch0 == UNIX_SEPARATOR) {
return 1;
}
return NOT_FOUND;
@ -772,7 +771,7 @@ public class FilenameUtils {
failIfNullBytePresent(filename + UNIX_SEPARATOR);
return filename + UNIX_SEPARATOR;
}
final String path = filename.substring(0, len);
String path = filename.substring(0, len);
failIfNullBytePresent(path);
return path;
}
@ -852,7 +851,7 @@ public class FilenameUtils {
if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
return "";
}
final String path = filename.substring(prefix, endIndex);
String path = filename.substring(prefix, endIndex);
failIfNullBytePresent(path);
return path;
}
@ -982,8 +981,8 @@ public class FilenameUtils {
* This may be used for poison byte attacks.
* @param path the path to check
*/
private static void failIfNullBytePresent(final String path) {
final int len = path.length();
private static void failIfNullBytePresent(String path) {
int len = path.length();
for (int i = 0; i < len; i++) {
if (path.charAt(i) == 0) {
throw new IllegalArgumentException("Null byte present in file/path name. There are no " +
@ -1278,7 +1277,7 @@ public class FilenameUtils {
*
* @param filename the filename to match on
* @param wildcardMatcher the wildcard string to match against
* @return true if the filename matches the wildcard string
* @return true if the filename matches the wilcard string
* @see IOCase#SENSITIVE
*/
public static boolean wildcardMatch(final String filename, final String wildcardMatcher) {
@ -1304,7 +1303,7 @@ public class FilenameUtils {
*
* @param filename the filename to match on
* @param wildcardMatcher the wildcard string to match against
* @return true if the filename matches the wildcard string
* @return true if the filename matches the wilcard string
* @see IOCase#SYSTEM
*/
public static boolean wildcardMatchOnSystem(final String filename, final String wildcardMatcher) {
@ -1322,7 +1321,7 @@ public class FilenameUtils {
* @param filename the filename to match on
* @param wildcardMatcher the wildcard string to match against
* @param caseSensitivity what case sensitivity rule to use, null means case-sensitive
* @return true if the filename matches the wildcard string
* @return true if the filename matches the wilcard string
* @since 1.3
*/
public static boolean wildcardMatch(final String filename, final String wildcardMatcher, IOCase caseSensitivity) {
@ -1339,7 +1338,7 @@ public class FilenameUtils {
boolean anyChars = false;
int textIdx = 0;
int wcsIdx = 0;
final Stack<int[]> backtrack = new Stack<>();
final Stack<int[]> backtrack = new Stack<int[]>();
// loop around a backtrack stack, to handle complex * matching
do {
@ -1424,7 +1423,7 @@ public class FilenameUtils {
}
final char[] array = text.toCharArray();
final ArrayList<String> list = new ArrayList<>();
final ArrayList<String> list = new ArrayList<String>();
final StringBuilder buffer = new StringBuilder();
char prevChar = 0;
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>
* Origin of code: POI.
*
* @version $Id: HexDump.java 1471767 2013-04-24 23:24:19Z sebb $
*/
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
* class to compare filenames.
*
* @version $Id: IOCase.java 1483915 2013-05-17 17:02:35Z sebb $
* @since 1.3
*/
public enum IOCase implements Serializable {
@ -54,7 +55,7 @@ public enum IOCase implements Serializable {
* Unix file separator and case-insensitive if they use the Windows file separator
* (see {@link java.io.File#separatorChar}).
* <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.
*/
SYSTEM ("System", !FilenameUtils.isSystemWindows());
@ -77,7 +78,7 @@ public enum IOCase implements Serializable {
* @throws IllegalArgumentException if the name is invalid
*/
public static IOCase forName(final String name) {
for (final IOCase ioCase : IOCase.values())
for (IOCase ioCase : IOCase.values())
{
if (ioCase.getName().equals(name))
{

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.
*
* @version $Id: IOExceptionWithCause.java 1643107 2014-12-03 13:05:23Z sebb $
* @since 1.4
* @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>
* This class provides static utility methods for input/output operations.
* <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>write - these methods write data to a stream
* <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>
* Origin of code: Excalibur.
*
* @version $Id: IOUtils.java 1722156 2015-12-29 15:40:07Z ggregory $
*/
public class IOUtils {
// NOTE: This class is focused on InputStream, OutputStream, Reader and
@ -134,11 +135,11 @@ public class IOUtils {
static {
// avoid security issues
try (final StringBuilderWriter buf = new StringBuilderWriter(4);
final PrintWriter out = new PrintWriter(buf)) {
final StringBuilderWriter buf = new StringBuilderWriter(4);
final PrintWriter out = new PrintWriter(buf);
out.println();
LINE_SEPARATOR = buf.toString();
}
out.close();
}
/**
@ -211,12 +212,7 @@ public class IOUtils {
* </pre>
*
* @param input the Reader to close, may be null or already closed
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final Reader input) {
closeQuietly((Closeable) input);
}
@ -242,12 +238,7 @@ public class IOUtils {
* </pre>
*
* @param output the Writer to close, may be null or already closed
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final Writer output) {
closeQuietly((Closeable) output);
}
@ -274,12 +265,7 @@ public class IOUtils {
* </pre>
*
* @param input the InputStream to close, may be null or already closed
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final InputStream input) {
closeQuietly((Closeable) input);
}
@ -307,12 +293,7 @@ public class IOUtils {
* </pre>
*
* @param output the OutputStream to close, may be null or already closed
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final OutputStream output) {
closeQuietly((Closeable) output);
}
@ -351,12 +332,7 @@ public class IOUtils {
*
* @param closeable the objects to close, may be null or already closed
* @since 2.0
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final Closeable closeable) {
try {
if (closeable != null) {
@ -409,12 +385,7 @@ public class IOUtils {
* @param closeables the objects to close, may be null or already closed
* @see #closeQuietly(Closeable)
* @since 2.5
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final Closeable... closeables) {
if (closeables == null) {
return;
@ -446,12 +417,7 @@ public class IOUtils {
*
* @param sock the Socket to close, may be null or already closed
* @since 2.0
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final Socket sock) {
if (sock != null) {
try {
@ -484,12 +450,7 @@ public class IOUtils {
*
* @param selector the Selector to close, may be null or already closed
* @since 2.2
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final Selector selector) {
if (selector != null) {
try {
@ -522,12 +483,7 @@ public class IOUtils {
*
* @param sock the ServerSocket to close, may be null or already closed
* @since 2.2
*
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
@Deprecated
public static void closeQuietly(final ServerSocket sock) {
if (sock != null) {
try {
@ -585,7 +541,7 @@ public class IOUtils {
* @throws IOException if an I/O error occurs
* @since 2.5
*/
public static InputStream toBufferedInputStream(final InputStream input, final int size) throws IOException {
public static InputStream toBufferedInputStream(final InputStream input, int size) throws IOException {
return ByteArrayOutputStream.toBufferedInputStream(input, size);
}
@ -614,7 +570,7 @@ public class IOUtils {
* @see #buffer(Reader)
* @since 2.5
*/
public static BufferedReader toBufferedReader(final Reader reader, final int size) {
public static BufferedReader toBufferedReader(final Reader reader, int size) {
return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, size);
}
@ -641,7 +597,7 @@ public class IOUtils {
* @throws NullPointerException if the input parameter is null
* @since 2.5
*/
public static BufferedReader buffer(final Reader reader, final int size) {
public static BufferedReader buffer(final Reader reader, int size) {
return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, size);
}
@ -668,7 +624,7 @@ public class IOUtils {
* @throws NullPointerException if the input parameter is null
* @since 2.5
*/
public static BufferedWriter buffer(final Writer writer, final int size) {
public static BufferedWriter buffer(final Writer writer, int size) {
return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer, size);
}
@ -700,7 +656,7 @@ public class IOUtils {
* @throws NullPointerException if the input parameter is null
* @since 2.5
*/
public static BufferedOutputStream buffer(final OutputStream outputStream, final int size) {
public static BufferedOutputStream buffer(final OutputStream outputStream, int size) {
// reject null early on rather than waiting for IO operation to fail
if (outputStream == null) { // not checked by BufferedOutputStream
throw new NullPointerException();
@ -737,7 +693,7 @@ public class IOUtils {
* @throws NullPointerException if the input parameter is null
* @since 2.5
*/
public static BufferedInputStream buffer(final InputStream inputStream, final int size) {
public static BufferedInputStream buffer(final InputStream inputStream, int size) {
// reject null early on rather than waiting for IO operation to fail
if (inputStream == null) { // not checked by BufferedInputStream
throw new NullPointerException();
@ -761,11 +717,10 @@ public class IOUtils {
* @throws IOException if an I/O error occurs
*/
public static byte[] toByteArray(final InputStream input) throws IOException {
try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) {
final ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output);
return output.toByteArray();
}
}
/**
* 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];
int offset = 0;
int read;
int readed;
while (offset < size && (read = input.read(data, offset, size - offset)) != EOF) {
offset += read;
while (offset < size && (readed = input.read(data, offset, size - offset)) != EOF) {
offset += readed;
}
if (offset != size) {
throw new IOException("Unexpected read size. current: " + offset + ", expected: " + size);
throw new IOException("Unexpected readed size. current: " + offset + ", excepted: " + size);
}
return data;
@ -864,11 +819,10 @@ public class IOUtils {
* @since 2.3
*/
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);
return output.toByteArray();
}
}
/**
* Gets the contents of a <code>Reader</code> as a <code>byte[]</code>
@ -953,8 +907,11 @@ public class IOUtils {
* @since 2.4
*/
public static byte[] toByteArray(final URLConnection urlConn) throws IOException {
try (InputStream inputStream = urlConn.getInputStream()) {
final InputStream inputStream = urlConn.getInputStream();
try {
return IOUtils.toByteArray(inputStream);
} finally {
inputStream.close();
}
}
@ -1080,11 +1037,10 @@ public class IOUtils {
* @since 2.3
*/
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);
return sw.toString();
}
}
/**
* 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
*/
public static String toString(final Reader input) throws IOException {
try (final StringBuilderWriter sw = new StringBuilderWriter()) {
final StringBuilderWriter sw = new StringBuilderWriter();
copy(input, sw);
return sw.toString();
}
}
/**
* Gets the contents at the given URI.
@ -1195,8 +1150,11 @@ public class IOUtils {
* @since 2.3
*/
public static String toString(final URL url, final Charset encoding) throws IOException {
try (InputStream inputStream = url.openStream()) {
final InputStream inputStream = url.openStream();
try {
return toString(inputStream, encoding);
} finally {
inputStream.close();
}
}
@ -1249,132 +1207,6 @@ public class IOUtils {
return new String(input, Charsets.toCharset(encoding));
}
// resources
//-----------------------------------------------------------------------
/**
* Gets the contents of a classpath resource as a String using the
* specified character encoding.
*
* <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
//-----------------------------------------------------------------------
@ -1455,7 +1287,7 @@ public class IOUtils {
*/
public static List<String> readLines(final Reader input) throws IOException {
final BufferedReader reader = toBufferedReader(input);
final List<String> list = new ArrayList<>();
final List<String> list = new ArrayList<String>();
String line = reader.readLine();
while (line != null) {
list.add(line);
@ -1706,7 +1538,7 @@ public class IOUtils {
int bytes = data.length;
int offset = 0;
while (bytes > 0) {
final int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
output.write(data, offset, chunk);
bytes -= chunk;
offset += chunk;
@ -1813,7 +1645,7 @@ public class IOUtils {
int bytes = data.length;
int offset = 0;
while (bytes > 0) {
final int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
output.write(data, offset, chunk);
bytes -= chunk;
offset += chunk;

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;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.Reader;
import java.util.Iterator;
@ -45,9 +44,10 @@ import java.util.NoSuchElementException;
* }
* </pre>
*
* @version $Id: LineIterator.java 1471767 2013-04-24 23:24:19Z sebb $
* @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
@ -84,7 +84,6 @@ public class LineIterator implements Iterator<String>, Closeable {
* @return {@code true} if the Reader has more lines
* @throws IllegalStateException if an IO exception occurs
*/
@Override
public boolean hasNext() {
if (cachedLine != null) {
return true;
@ -103,11 +102,7 @@ public class LineIterator implements Iterator<String>, Closeable {
}
}
} catch(final IOException ioe) {
try {
close();
} catch (final IOException e) {
ioe.addSuppressed(e);
}
throw new IllegalStateException(ioe);
}
}
@ -129,7 +124,6 @@ public class LineIterator implements Iterator<String>, Closeable {
* @return the next line from the input
* @throws NoSuchElementException if there is no line to return
*/
@Override
public String next() {
return nextLine();
}
@ -150,21 +144,16 @@ public class LineIterator implements Iterator<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
* 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.
*
* @throws IOException if closing the underlying {@code Reader} fails.
*/
@Override
public void close() throws IOException {
public void close() {
finished = true;
IOUtils.closeQuietly(bufferedReader);
cachedLine = null;
if (this.bufferedReader != null) {
this.bufferedReader.close();
}
}
/**
@ -172,29 +161,20 @@ public class LineIterator implements Iterator<String>, Closeable {
*
* @throws UnsupportedOperationException always
*/
@Override
public void remove() {
throw new UnsupportedOperationException("Remove unsupported on LineIterator");
}
//-----------------------------------------------------------------------
/**
* Closes a {@code LineIterator} quietly.
* Closes the iterator, handling null and ignoring exceptions.
*
* @param iterator The iterator to close, or {@code null}.
* @deprecated As of 2.6 removed without replacement. Please use the try-with-resources statement or handle
* suppressed exceptions manually.
* @see Throwable#addSuppressed(java.lang.Throwable)
* @param iterator the iterator to close
*/
@Deprecated
public static void closeQuietly(final LineIterator iterator) {
try {
if (iterator != null) {
iterator.close();
}
} catch(final IOException e) {
// Suppressed.
}
}
}

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>
*
* @version $Id: ThreadMonitor.java 1718945 2015-12-09 19:51:14Z krosenvold $
*/
class ThreadMonitor implements Runnable {
@ -102,7 +103,6 @@ class ThreadMonitor implements Runnable {
*
* @see Runnable#run()
*/
@Override
public void run() {
try {
sleep(timeout);
@ -117,12 +117,12 @@ class ThreadMonitor implements Runnable {
*
* This method exists because Thread.sleep(100) can sleep for 0, 70, 100 or 200ms or anything else
* it deems appropriate. Read the docs on Thread.sleep for further interesting details.
*
* @
* @param ms the number of milliseconds to sleep for
* @throws InterruptedException if interrupted
*/
private static void sleep(final long ms) throws InterruptedException {
final long finishAt = System.currentTimeMillis() + ms;
private static void sleep(long ms) throws InterruptedException {
long finishAt = System.currentTimeMillis() + ms;
long remaining = ms;
do {
Thread.sleep(remaining);

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.
*
* @version $Id: AbstractFileComparator.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0
*/
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);
* </pre>
*
* @version $Id: CompositeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 2.0
*/
public class CompositeFileComparator extends AbstractFileComparator implements Serializable {
@ -72,7 +73,7 @@ public class CompositeFileComparator extends AbstractFileComparator implements S
if (delegates == null) {
this.delegates = (Comparator<File>[]) NO_COMPARATORS; //1
} else {
final List<Comparator<File>> list = new ArrayList<>();
final List<Comparator<File>> list = new ArrayList<Comparator<File>>();
for (final Comparator<File> comparator : delegates) {
list.add(comparator);
}
@ -88,7 +89,6 @@ public class CompositeFileComparator extends AbstractFileComparator implements S
* @return the first non-zero result returned from
* the delegate comparators or zero.
*/
@Override
public int compare(final File file1, final File file2) {
int result = 0;
for (final Comparator<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>
* <p>
*
* @version $Id: DefaultFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
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
* {@link File#compareTo(File)} with file2 as the parameter.
*/
@Override
public int compare(final File file1, final File 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>
* <p>
*
* @version $Id: DirectoryFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 2.0
*/
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
* {@link File#compareTo(File)} with file2 as the parameter.
*/
@Override
public int compare(final File file1, final File 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.util.Comparator;
import com.fr.third.org.apache.commons.io.FilenameUtils;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.FilenameUtils;
import com.fr.third.org.apache.commons.io.IOCase;
@ -50,6 +48,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
* <p>
*
* @version $Id: ExtensionFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class ExtensionFileComparator extends AbstractFileComparator implements Serializable {
@ -106,7 +105,6 @@ public class ExtensionFileComparator extends AbstractFileComparator implements S
* is greater than the second file.
*
*/
@Override
public int compare(final File file1, final File file2) {
final String suffix1 = FilenameUtils.getExtension(file1.getName());
final String suffix2 = FilenameUtils.getExtension(file2.getName());

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

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

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.util.Comparator;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
* <p>
*
* @version $Id: NameFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
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
* is greater than the second file.
*/
@Override
public int compare(final File file1, final File file2) {
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.util.Comparator;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
* <p>
*
* @version $Id: PathFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class PathFileComparator extends AbstractFileComparator implements Serializable {
@ -101,7 +101,6 @@ public class PathFileComparator extends AbstractFileComparator implements Serial
* is greater than the second file.
*
*/
@Override
public int compare(final File file1, final File file2) {
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
* the delegate {@link Comparator}.
*
* @version $Id: ReverseComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
class ReverseComparator extends AbstractFileComparator implements Serializable {
@ -32,7 +33,7 @@ class ReverseComparator extends AbstractFileComparator implements Serializable {
private final Comparator<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
*/
@ -51,7 +52,6 @@ class ReverseComparator extends AbstractFileComparator implements Serializable {
* @return the result from the delegate {@link Comparator#compare(Object, Object)}
* reversing the value (i.e. positive becomes negative and vice versa)
*/
@Override
public int compare(final File file1, final File file2) {
return delegate.compare(file2, file1); // parameters switched round
}

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

22
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>
...alternatively you can do this in one line:
</p>
<pre>
<p>
<pre>
File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
</pre>
</pre>
</p>
<h3>Composite Comparator</h3>
<p>
@ -48,21 +50,22 @@ for {@link java.io.File}s.
For example, to sort an array of files by type (i.e. directory or file)
and then by name:
</p>
<pre>
<p>
<pre>
CompositeFileComparator comparator =
new CompositeFileComparator(
DirectoryFileComparator.DIRECTORY_COMPARATOR,
NameFileComparator.NAME_COMPARATOR);
File[] files = dir.listFiles();
comparator.sort(files);
</pre>
</pre>
</p>
<h3>Singleton Instances (thread-safe)</h3>
<p>
The {@link java.util.Comparator} implementations have some <i>convenience</i>
singleton(<i>thread-safe</i>) instances ready to use:
</p>
<ul>
<ul>
<li><a href="DefaultFileComparator.html">DefaultFileComparator</a> - default file compare:
<ul>
<li><a href="DefaultFileComparator.html#DEFAULT_COMPARATOR">DEFAULT_COMPARATOR</a>
@ -76,10 +79,10 @@ for {@link java.io.File}s.
<li><a href="DirectoryFileComparator.html">DirectoryFileComparator</a> - compare by type (directory or file):
<ul>
<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><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>
</ul>
</li>
@ -178,7 +181,8 @@ for {@link java.io.File}s.
</li>
</ul>
</li>
</ul>
</ul>
</p>
</body>
</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.
*
* @since 1.0
* @version $Id$
* @version $Id: AbstractFileFilter.java 1415850 2012-11-30 20:51:39Z ggregory $
*/
public abstract class AbstractFileFilter implements IOFileFilter {
@ -36,7 +36,6 @@ public abstract class AbstractFileFilter implements IOFileFilter {
* @param file the File to check
* @return true if this file matches the test
*/
@Override
public boolean accept(final File file) {
return accept(file.getParentFile(), file.getName());
}
@ -48,15 +47,14 @@ public abstract class AbstractFileFilter implements IOFileFilter {
* @param name the filename within the directory to check
* @return true if this file matches the test
*/
@Override
public boolean accept(final File dir, final String name) {
return accept(new File(dir, name));
}
/**
* Provide a String representation of this file filter.
* Provide a String representaion of this file filter.
*
* @return a String representation
* @return a String representaion
*/
@Override
public String toString() {

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

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

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

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

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

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.
*
* @since 1.1
* @version $Id$
* @version $Id: ConditionalFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
*/
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.
*
* @since 1.0
* @version $Id$
* @version $Id: DelegateFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
*
* @see FileFilterUtils#asFileFilter(FileFilter)
* @see FileFilterUtils#asFileFilter(FilenameFilter)
@ -96,9 +96,9 @@ public class DelegateFileFilter extends AbstractFileFilter implements Serializab
}
/**
* Provide a String representation of this file filter.
* Provide a String representaion of this file filter.
*
* @return a String representation
* @return a String representaion
*/
@Override
public String toString() {

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

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

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

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

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

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

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

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

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

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

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

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.util.Arrays;
import com.fr.third.org.apache.commons.io.IOUtils;
/**
* <p>
* File filter for matching files containing a "magic number". A magic number
@ -232,19 +234,20 @@ public class MagicNumberFileFilter extends AbstractFileFilter implements
@Override
public boolean accept(final File file) {
if (file != null && file.isFile() && file.canRead()) {
RandomAccessFile randomAccessFile = null;
try {
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r")) {
final byte[] fileBytes = new byte[this.magicNumbers.length];
randomAccessFile = new RandomAccessFile(file, "r");
randomAccessFile.seek(byteOffset);
final int read = randomAccessFile.read(fileBytes);
if (read != magicNumbers.length) {
return false;
}
return Arrays.equals(this.magicNumbers, fileBytes);
}
}
catch (final IOException ioe) {
} catch (final IOException ioe) {
// 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.util.List;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -38,7 +37,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
*
* @since 1.0
* @version $Id$
* @version $Id: NameFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#nameFileFilter(String)
* @see FileFilterUtils#nameFileFilter(String, IOCase)
*/
@ -167,9 +166,9 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable {
}
/**
* Provide a String representation of this file filter.
* Provide a String representaion of this file filter.
*
* @return a String representation
* @return a String representaion
*/
@Override
public String toString() {

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.
*
* @since 1.0
* @version $Id$
* @version $Id: NotFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#notFileFilter(IOFileFilter)
*/
public class NotFileFilter extends AbstractFileFilter implements Serializable {
@ -69,9 +69,9 @@ public class NotFileFilter extends AbstractFileFilter implements Serializable {
}
/**
* Provide a String representation of this file filter.
* Provide a String representaion of this file filter.
*
* @return a String representation
* @return a String representaion
*/
@Override
public String toString() {

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

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.util.List;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -38,7 +37,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
*
* @since 1.0
* @version $Id$
* @version $Id: PrefixFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#prefixFileFilter(String)
* @see FileFilterUtils#prefixFileFilter(String, IOCase)
*/
@ -174,9 +173,9 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
}
/**
* Provide a String representation of this file filter.
* Provide a String representaion of this file filter.
*
* @return a String representation
* @return a String representaion
*/
@Override
public String toString() {

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.util.regex.Pattern;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -40,6 +39,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* }
* </pre>
*
* @version $Id: RegexFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
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>
*
* @version $Id: SizeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.2
* @see FileFilterUtils#sizeFileFilter(long)
* @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
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.util.List;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -39,7 +38,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
*
* @since 1.0
* @version $Id$
* @version $Id: SuffixFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#suffixFileFilter(String)
* @see FileFilterUtils#suffixFileFilter(String, IOCase)
*/
@ -81,7 +80,7 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
}
/**
* Constructs a new Suffix file filter for an array of suffixes.
* Constructs a new Suffix file filter for an array of suffixs.
* <p>
* The array is not cloned, so could be changed after constructing the
* instance. This would be inadvisable however.
@ -94,7 +93,7 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
}
/**
* Constructs a new Suffix file filter for an array of suffixes
* Constructs a new Suffix file filter for an array of suffixs
* specifying case-sensitivity.
*
* @param suffixes the suffixes to allow, must not be null
@ -175,9 +174,9 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
}
/**
* Provide a String representation of this file filter.
* Provide a String representaion of this file filter.
*
* @return a String representation
* @return a String representaion
*/
@Override
public String toString() {

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

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

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>
<p>These filter can be used to list files or in {@link java.awt.FileDialog},
for example.</p>
<p>There are a number of 'primitive' filters:</p>
<table>
<caption>There are a number of 'primitive' filters:</caption>
<tbody>
<tr>
<td><a href="DirectoryFileFilter.html">DirectoryFilter</a></td>
@ -57,8 +59,10 @@ for example.</p>
</tr>
</tbody>
</table>
<p>And there are five 'boolean' filters:</p>
<table>
<caption>And there are five 'boolean' filters:</caption>
<tbody>
<tr>
<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 static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
@ -35,6 +33,7 @@ import java.io.InputStream;
* closing the stream when no longer needed) or the underlying stream (by not
* releasing resources once the last byte has been read) do not do that.
*
* @version $Id: AutoCloseInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
* @since 1.4
*/
public class AutoCloseInputStream extends ProxyInputStream {

19
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;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.fr.third.org.apache.commons.io.ByteOrderMark;
import com.fr.third.org.apache.commons.io.IOUtils;
import com.fr.third.org.apache.commons.io.ByteOrderMark;
/**
* This class is used to wrap a stream that includes an encoded {@link ByteOrderMark} as its first bytes.
@ -86,7 +82,7 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark;
*
* @see ByteOrderMark
* @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
*/
public class BOMInputStream extends ProxyInputStream {
@ -141,7 +137,6 @@ public class BOMInputStream extends ProxyInputStream {
*/
private static final Comparator<ByteOrderMark> ByteOrderMarkLengthComparator = new Comparator<ByteOrderMark>() {
@Override
public int compare(final ByteOrderMark bom1, final ByteOrderMark bom2) {
final int len1 = bom1.length();
final int len2 = bom2.length();
@ -171,10 +166,9 @@ public class BOMInputStream extends ProxyInputStream {
throw new IllegalArgumentException("No BOMs specified");
}
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.
Collections.sort(list, ByteOrderMarkLengthComparator);
this.boms = list;
Arrays.sort(boms, ByteOrderMarkLengthComparator);
this.boms = Arrays.asList(boms);
}
@ -204,8 +198,7 @@ public class BOMInputStream extends ProxyInputStream {
if (!boms.contains(bom)) {
throw new IllegalArgumentException("Stream not configure to detect " + bom);
}
getBOM();
return byteOrderMark != null && byteOrderMark.equals(bom);
return byteOrderMark != null && getBOM().equals(bom);
}
/**
@ -395,7 +388,7 @@ public class BOMInputStream extends ProxyInputStream {
}
/**
* Invokes the delegate's <code>skip(long)</code> method, detecting and optionally skipping BOM.
* Invokes the delegate's <code>skip(long)</code> method, detecting and optionallyskipping BOM.
*
* @param n
* the number of bytes to skip
@ -404,7 +397,7 @@ public class BOMInputStream extends ProxyInputStream {
* if an I/O error occurs
*/
@Override
public long skip(final long n) throws IOException {
public long skip(long n) throws IOException {
int skipped = 0;
while ((n > skipped) && (readFirstBytes() >= 0)) {
skipped++;

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

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

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 static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
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 static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.Reader;
import java.io.Serializable;
@ -29,6 +27,7 @@ import java.io.Serializable;
* <p>
* <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
*/
public class CharSequenceReader extends Reader implements Serializable {
@ -92,7 +91,7 @@ public class CharSequenceReader extends Reader implements Serializable {
}
/**
* Read the specified number of characters into the array.
* Read the sepcified number of characters into the array.
*
* @param array The array to store the characters in
* @param offset The starting position in the array to store

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

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
* more input would still be available to other components.
*
* @version $Id: CloseShieldInputStream.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 1.4
*/
public class CloseShieldInputStream extends ProxyInputStream {

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

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

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 static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
@ -27,11 +25,12 @@ import java.io.InputStream;
* Data written to this stream is forwarded to a stream that has been associated
* with this thread.
*
* @version $Id: DemuxInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
*/
public class DemuxInputStream
extends InputStream
{
private final InheritableThreadLocal<InputStream> m_streams = new InheritableThreadLocal<>();
private final InheritableThreadLocal<InputStream> m_streams = new InheritableThreadLocal<InputStream>();
/**
* 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 static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@ -62,7 +60,7 @@ import java.io.InputStream;
* </pre>
*
* @since 1.3
* @version $Id$
* @version $Id: NullInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
*/
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 static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.EOFException;
import java.io.IOException;
import java.io.Reader;
@ -62,7 +60,7 @@ import java.io.Reader;
* </pre>
*
* @since 1.3
* @version $Id$
* @version $Id: NullReader.java 1586350 2014-04-10 15:57:20Z ggregory $
*/
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 static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -36,6 +34,7 @@ import java.io.InputStream;
* See the protected methods for ways in which a subclass can easily decorate
* a stream with custom pre-, post- or error processing functionality.
*
* @version $Id: ProxyInputStream.java 1603493 2014-06-18 15:46:07Z ggregory $
*/
public abstract class ProxyInputStream extends FilterInputStream {

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 static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.FilterReader;
import java.io.IOException;
import java.io.Reader;
@ -34,6 +32,7 @@ import java.nio.CharBuffer;
* to increase reusability, because FilterReader changes the
* methods being called, such as read(char[]) to read(char[], int, int).
*
* @version $Id: ProxyReader.java 1586350 2014-04-10 15:57:20Z ggregory $
*/
public abstract class ProxyReader extends FilterReader {

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;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import com.fr.third.org.apache.commons.io.output.WriterOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -64,7 +63,7 @@ import java.nio.charset.CodingErrorAction;
* in the design of the code. This class is typically used in situations where an existing
* API only accepts an {@link InputStream}, but where the most natural way to produce the data
* is as a character stream, i.e. by providing a {@link Reader} instance. An example of a situation
* where this problem may appear is when implementing the {@code javax.activation.DataSource}
* where this problem may appear is when implementing the {@link javax.activation.DataSource}
* interface from the Java Activation Framework.
* <p>
* 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>
* Instances of {@link ReaderInputStream} are not thread safe.
*
* @see com.fr.third.org.apache.commons.io.output.WriterOutputStream
* @see WriterOutputStream
*
* @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.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import com.fr.third.org.apache.commons.io.Charsets;
import com.fr.third.org.apache.commons.io.Charsets;
/**
@ -93,6 +91,7 @@ public class ReversedLinesFileReader implements Closeable {
* @throws IOException if an I/O error occurs
* @since 2.3
*/
@SuppressWarnings("deprecation") // unavoidable until Java 7
public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException {
this.blockSize = blockSize;
this.encoding = encoding;
@ -104,7 +103,7 @@ public class ReversedLinesFileReader implements Closeable {
if (maxBytesPerChar == 1f) {
// all one byte encodings are no problem
byteDecrement = 1;
} else if (charset == StandardCharsets.UTF_8) {
} else if (charset == Charsets.UTF_8) {
// UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte
// http://en.wikipedia.org/wiki/UTF-8
byteDecrement = 1;
@ -115,11 +114,11 @@ public class ReversedLinesFileReader implements Closeable {
charset == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese)
charset == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese)
byteDecrement = 1;
} else if (charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) {
} else if (charset == Charsets.UTF_16BE || charset == Charsets.UTF_16LE) {
// UTF-16 new line sequences are not allowed as second tuple of four byte sequences,
// however byte order has to be specified
byteDecrement = 2;
} else if (charset == StandardCharsets.UTF_16) {
} else if (charset == Charsets.UTF_16) {
throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte order (use UTF-16BE or " +
"UTF-16LE)");
} else {
@ -199,7 +198,6 @@ public class ReversedLinesFileReader implements Closeable {
*
* @throws IOException if an I/O error occurs
*/
@Override
public void close() throws IOException {
randomAccessFile.close();
}

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

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.util.UUID;
import com.fr.third.org.apache.commons.io.TaggedIOException;
import com.fr.third.org.apache.commons.io.TaggedIOException;
/**

49
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/Tailer.java

@ -16,8 +16,6 @@
*/
package com.fr.third.org.apache.commons.io.input;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
@ -27,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.IOUtils;
import com.fr.third.org.apache.commons.io.FileUtils;
/**
* Simple implementation of the unix "tail -f" functionality.
@ -112,10 +109,10 @@ import com.fr.third.org.apache.commons.io.FileUtils;
* </pre>
* <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 TailerListenerAdapter
* @version $Id$
* @version $Id: Tailer.java 1714076 2015-11-12 16:06:41Z krosenvold $
* @since 2.0
* @since 2.5 Updated behavior and documentation for {@link Thread#interrupt()}
*/
@ -404,7 +401,6 @@ public class Tailer implements Runnable {
/**
* Follows changes in the file, calling the TailerListener's handle method for each new line.
*/
@Override
public void run() {
RandomAccessFile reader = null;
try {
@ -433,22 +429,24 @@ public class Tailer implements Runnable {
if (length < position) {
// File was rotated
listener.fileRotated();
// Reopen the reader after rotation ensuring that the old file is closed iff we re-open it
// successfully
try (RandomAccessFile save = reader) {
// Reopen the reader after rotation
try {
// Ensure that the old file is closed iff we re-open it successfully
final RandomAccessFile save = reader;
reader = new RandomAccessFile(file, RAF_MODE);
// At this point, we're sure that the old file is rotated
// Finish scanning the old file and then we'll start with the new one
try {
readLines(save);
} catch (final IOException ioe) {
} catch (IOException ioe) {
listener.handle(ioe);
}
position = 0;
// close old file explicitly rather than relying on GC picking up previous RAF
IOUtils.closeQuietly(save);
} catch (final FileNotFoundException e) {
// in this case we continue to use the previous reader and position values
listener.fileNotFound();
Thread.sleep(delayMillis);
}
continue;
} else {
@ -471,8 +469,8 @@ public class Tailer implements Runnable {
last = file.lastModified();
}
}
if (reOpen && reader != null) {
reader.close();
if (reOpen) {
IOUtils.closeQuietly(reader);
}
Thread.sleep(delayMillis);
if (getRun() && reOpen) {
@ -482,21 +480,22 @@ public class Tailer implements Runnable {
}
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
listener.handle(e);
stop(e);
} catch (final Exception e) {
listener.handle(e);
stop(e);
} finally {
try {
if (reader != null) {
reader.close();
IOUtils.closeQuietly(reader);
}
}
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);
}
stop();
}
}
/**
* 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.
*/
private long readLines(final RandomAccessFile reader) throws IOException {
try (ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64)) {
ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64);
long pos = reader.getFilePointer();
long rePos = pos; // position to re-read
int num;
@ -521,7 +520,7 @@ public class Tailer implements Runnable {
while (getRun() && ((num = reader.read(inbuf)) != IOUtils.EOF)) {
for (int i = 0; i < num; i++) {
final byte ch = inbuf[i];
switch ( ch ) {
switch (ch) {
case '\n':
seenCR = false; // swallow CR before LF
listener.handle(new String(lineBuf.toByteArray(), cset));
@ -546,7 +545,7 @@ public class Tailer implements Runnable {
}
pos = reader.getFilePointer();
}
IOUtils.closeQuietly(lineBuf); // not strictly necessary
reader.seek(rePos); // Ensure we can re-read if necessary
if (listener instanceof TailerListenerAdapter) {
@ -555,5 +554,5 @@ public class Tailer implements Runnable {
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}.
*
* @version $Id: TailerListener.java 1714076 2015-11-12 16:06:41Z krosenvold $
* @since 2.0
*/
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.
*
* @version $Id: TailerListenerAdapter.java 1714076 2015-11-12 16:06:41Z krosenvold $
* @since 2.0
*/
public class TailerListenerAdapter implements TailerListener {
@ -28,14 +29,12 @@ public class TailerListenerAdapter implements TailerListener {
* giving the listener a method of stopping the tailer.
* @param tailer the tailer.
*/
@Override
public void init(final Tailer tailer) {
}
/**
* This method is called if the tailed file is not found.
*/
@Override
public void fileNotFound() {
}
@ -45,7 +44,6 @@ public class TailerListenerAdapter implements TailerListener {
* This method is called before the file is reopened, and fileNotFound may
* be called if the new file has not yet been created.
*/
@Override
public void fileRotated() {
}
@ -53,7 +51,6 @@ public class TailerListenerAdapter implements TailerListener {
* Handles a line from a Tailer.
* @param line the line.
*/
@Override
public void handle(final String line) {
}
@ -61,7 +58,6 @@ public class TailerListenerAdapter implements TailerListener {
* Handles an Exception .
* @param ex the exception.
*/
@Override
public void handle(final Exception ex) {
}

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

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

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

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 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.
* <p>
* 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.
* <p>
* 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
* href="http://diveintomark.org/archives/2004/02/13/xml-media-types">
* 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
* Apache License 2.0.
*
* @see com.fr.third.org.apache.commons.io.output.XmlStreamWriter
* @version $Id: XmlStreamReader.java 1686747 2015-06-21 18:44:49Z krosenvold $
* @see XmlStreamWriter
* @since 2.0
*/
public class XmlStreamReader extends Reader {
@ -277,7 +278,7 @@ public class XmlStreamReader extends Reader {
}
/**
* Creates a Reader using an InputStream and the associated content-type
* Creates a Reader using an InputStream an the associated content-type
* header.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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
* already read.
*
* @version $Id: XmlStreamReaderException.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0
*/
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}.
*
* @see FileAlterationObserver
* @version $Id$
* @version $Id: FileAlterationListener.java 1304052 2012-03-22 20:55:29Z ggregory $
* @since 2.0
*/
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.
*
* @see FileAlterationObserver
* @version $Id$
* @version $Id: FileAlterationListenerAdaptor.java 1304062 2012-03-22 21:10:46Z sebb $
* @since 2.0
*/
public class FileAlterationListenerAdaptor implements FileAlterationListener {
@ -32,7 +32,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param observer The file system observer (ignored)
*/
@Override
public void onStart(final FileAlterationObserver observer) {
}
@ -41,7 +40,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param directory The directory created (ignored)
*/
@Override
public void onDirectoryCreate(final File directory) {
}
@ -50,7 +48,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param directory The directory changed (ignored)
*/
@Override
public void onDirectoryChange(final File directory) {
}
@ -59,7 +56,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param directory The directory deleted (ignored)
*/
@Override
public void onDirectoryDelete(final File directory) {
}
@ -68,7 +64,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param file The file created (ignored)
*/
@Override
public void onFileCreate(final File file) {
}
@ -77,7 +72,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param file The file changed (ignored)
*/
@Override
public void onFileChange(final File file) {
}
@ -86,7 +80,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param file The file deleted (ignored)
*/
@Override
public void onFileDelete(final File file) {
}
@ -95,7 +88,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param observer The file system observer (ignored)
*/
@Override
public void onStop(final FileAlterationObserver observer) {
}

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.
*
* @see FileAlterationObserver
* @version $Id$
* @version $Id: FileAlterationMonitor.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0
*/
public final class FileAlterationMonitor implements Runnable {
private final long interval;
private final List<FileAlterationObserver> observers = new CopyOnWriteArrayList<>();
private final List<FileAlterationObserver> observers = new CopyOnWriteArrayList<FileAlterationObserver>();
private Thread thread = null;
private ThreadFactory threadFactory;
private volatile boolean running = false;
@ -46,7 +46,7 @@ public final class FileAlterationMonitor implements Runnable {
/**
* Construct a monitor with the specified interval.
*
* @param interval The amount of time in milliseconds to wait between
* @param interval The amount of time in miliseconds to wait between
* checks of the file system
*/
public FileAlterationMonitor(final long interval) {
@ -56,7 +56,7 @@ public final class FileAlterationMonitor implements Runnable {
/**
* Construct a monitor with the specified interval and set of observers.
*
* @param interval The amount of time in milliseconds to wait between
* @param interval The amount of time in miliseconds to wait between
* checks of the file system
* @param observers The set of observers to add to the monitor.
*/
@ -176,7 +176,6 @@ public final class FileAlterationMonitor implements Runnable {
/**
* Run.
*/
@Override
public void run() {
while (running) {
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.concurrent.CopyOnWriteArrayList;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
@ -57,7 +54,7 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
* To manually observe a directory, initialize the observer and invoked the
* {@link #checkAndNotify()} method as required:
* <pre>
* // initialize
* // intialize
* observer.init();
* ...
* // invoke as required
@ -68,7 +65,7 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
* // finished
* observer.finish();
* </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:
* <pre>
* long interval = ...
@ -119,13 +116,13 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
*
* @see FileAlterationListener
* @see FileAlterationMonitor
* @version $Id$
* @version $Id: FileAlterationObserver.java 1686747 2015-06-21 18:44:49Z krosenvold $
* @since 2.0
*/
public class FileAlterationObserver implements Serializable {
private static final long serialVersionUID = 1185122225658782848L;
private final List<FileAlterationListener> listeners = new CopyOnWriteArrayList<>();
private final List<FileAlterationListener> listeners = new CopyOnWriteArrayList<FileAlterationListener>();
private final FileEntry rootEntry;
private final FileFilter fileFilter;
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() {
@ -370,7 +367,7 @@ public class FileAlterationObserver implements Serializable {
* @param entry the parent entry
* @return The child files
*/
private FileEntry[] doListFiles(final File file, final FileEntry entry) {
private FileEntry[] doListFiles(File file, FileEntry entry) {
final File[] files = listFiles(file);
final FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES;
for (int i = 0; i < files.length; i++) {

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
* @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 {
@ -39,7 +39,7 @@ public class AppendableOutputStream <T extends Appendable> extends OutputStream
*
* @param appendable the appendable to write to
*/
public AppendableOutputStream(final T appendable) {
public AppendableOutputStream(T appendable) {
this.appendable = appendable;
}
@ -50,7 +50,7 @@ public class AppendableOutputStream <T extends Appendable> extends OutputStream
* @throws IOException upon error
*/
@Override
public void write(final int b) throws IOException {
public void write(int b) throws IOException {
appendable.append((char)b);
}

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

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.
* @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);
if (chunkSize <= 0) {
throw new IllegalArgumentException();
@ -73,11 +73,11 @@ public class ChunkedOutputStream extends FilterOutputStream {
* @throws IOException if an I/O error occurs.
*/
@Override
public void write(final byte[] data, final int srcOffset, final int length) throws IOException {
public void write(byte[] data, int srcOffset, int length) throws IOException {
int bytes = length;
int dstOffset = srcOffset;
while(bytes > 0) {
final int chunk = Math.min(bytes, chunkSize);
int chunk = Math.min(bytes, chunkSize);
out.write(data, dstOffset, chunk);
bytes -= chunk;
dstOffset += chunk;

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.
* @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);
if (chunkSize <= 0) {
throw new IllegalArgumentException();
@ -71,11 +71,11 @@ public class ChunkedWriter extends FilterWriter {
* @throws IOException upon error
*/
@Override
public void write(final char[] data, final int srcOffset, final int length) throws IOException {
public void write(char[] data, int srcOffset, int length) throws IOException {
int bytes = length;
int dstOffset = srcOffset;
while(bytes > 0) {
final int chunk = Math.min(bytes, chunkSize);
int chunk = Math.min(bytes, chunkSize);
out.write(data, dstOffset, chunk);
bytes -= chunk;
dstOffset += chunk;

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
* other components would still use the stream for output.
* </p>
* @version $Id$
* @version $Id: CloseShieldOutputStream.java 1674710 2015-04-20 00:25:55Z ggregory $
* @since 1.4
*/
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
* a {@code null} output stream.
*
* @version $Id: ClosedOutputStream.java 1471767 2013-04-24 23:24:19Z sebb $
* @since 1.4
*/
public class ClosedOutputStream extends OutputStream {
@ -47,13 +48,4 @@ public class ClosedOutputStream extends OutputStream {
throw new IOException("write(" + b + ") failed: stream is closed");
}
/**
* Throws an {@link IOException} to indicate that the stream is closed.
*
* @throws IOException always thrown
*/
@Override
public void flush() throws IOException {
throw new IOException("flush() failed: stream is closed");
}
}

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

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.
*
* @version $Id: DemuxOutputStream.java 1737901 2016-04-06 00:23:36Z ggregory $
*/
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.

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

Loading…
Cancel
Save