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. 384
      fine-commons-io/src/com/fr/third/org/apache/commons/io/Charsets.java
  4. 5
      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. 13
      fine-commons-io/src/com/fr/third/org/apache/commons/io/EndianUtils.java
  7. 15
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaner.java
  8. 13
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileCleaningTracker.java
  9. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/FileDeleteStrategy.java
  10. 7
      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. 25
      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. 11
      fine-commons-io/src/com/fr/third/org/apache/commons/io/IOExceptionWithCause.java
  17. 248
      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. 42
      fine-commons-io/src/com/fr/third/org/apache/commons/io/LineIterator.java
  20. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/TaggedIOException.java
  21. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/ThreadMonitor.java
  22. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/AbstractFileComparator.java
  23. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/CompositeFileComparator.java
  24. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DefaultFileComparator.java
  25. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/DirectoryFileComparator.java
  26. 12
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ExtensionFileComparator.java
  27. 12
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/LastModifiedFileComparator.java
  28. 9
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/NameFileComparator.java
  29. 11
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/PathFileComparator.java
  30. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/ReverseComparator.java
  31. 13
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/SizeFileComparator.java
  32. 260
      fine-commons-io/src/com/fr/third/org/apache/commons/io/comparator/package.html
  33. 18
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AbstractFileFilter.java
  34. 14
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AgeFileFilter.java
  35. 22
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/AndFileFilter.java
  36. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanReadFileFilter.java
  37. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/CanWriteFileFilter.java
  38. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/ConditionalFileFilter.java
  39. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DelegateFileFilter.java
  40. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/DirectoryFileFilter.java
  41. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/EmptyFileFilter.java
  42. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FalseFileFilter.java
  43. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFileFilter.java
  44. 25
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/FileFilterUtils.java
  45. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/HiddenFileFilter.java
  46. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/IOFileFilter.java
  47. 23
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/MagicNumberFileFilter.java
  48. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NameFileFilter.java
  49. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/NotFileFilter.java
  50. 24
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/OrFileFilter.java
  51. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/PrefixFileFilter.java
  52. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/RegexFileFilter.java
  53. 11
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SizeFileFilter.java
  54. 11
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/SuffixFileFilter.java
  55. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/TrueFileFilter.java
  56. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFileFilter.java
  57. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/WildcardFilter.java
  58. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/filefilter/package.html
  59. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/AutoCloseInputStream.java
  60. 81
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BOMInputStream.java
  61. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedInputStream.java
  62. 20
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BoundedReader.java
  63. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/BrokenInputStream.java
  64. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceInputStream.java
  65. 9
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CharSequenceReader.java
  66. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
  67. 5
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CloseShieldInputStream.java
  68. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ClosedInputStream.java
  69. 15
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/CountingInputStream.java
  70. 9
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/DemuxInputStream.java
  71. 52
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/InfiniteCircularInputStream.java
  72. 102
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java
  73. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullInputStream.java
  74. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/NullReader.java
  75. 266
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ObservableInputStream.java
  76. 3
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyInputStream.java
  77. 19
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ProxyReader.java
  78. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReaderInputStream.java
  79. 16
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReversedLinesFileReader.java
  80. 45
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/SwappedDataInputStream.java
  81. 7
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TaggedInputStream.java
  82. 125
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/Tailer.java
  83. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListener.java
  84. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TailerListenerAdapter.java
  85. 14
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/TeeInputStream.java
  86. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/UnixLineEndingInputStream.java
  87. 8
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/WindowsLineEndingInputStream.java
  88. 15
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReader.java
  89. 1
      fine-commons-io/src/com/fr/third/org/apache/commons/io/input/XmlStreamReaderException.java
  90. 16
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListener.java
  91. 24
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java
  92. 13
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationMonitor.java
  93. 17
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileAlterationObserver.java
  94. 2
      fine-commons-io/src/com/fr/third/org/apache/commons/io/monitor/FileEntry.java
  95. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/AppendableOutputStream.java
  96. 4
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/BrokenOutputStream.java
  97. 24
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ByteArrayOutputStream.java
  98. 12
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedOutputStream.java
  99. 10
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/ChunkedWriter.java
  100. 6
      fine-commons-io/src/com/fr/third/org/apache/commons/io/output/CloseShieldOutputStream.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);
}
}

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

@ -1,192 +1,192 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fr.third.org.apache.commons.io;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;
/**
* Charsets required of every implementation of the Java platform.
*
* From the Java documentation <a href="https://docs.oracle.com/javase/7/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
* the release documentation for your implementation to see if any other encodings are supported. Consult the release
* documentation for your implementation to see if any other encodings are supported. </cite>
* </p>
*
* <ul>
* <li><code>US-ASCII</code><br>
* Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.</li>
* <li><code>ISO-8859-1</code><br>
* ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.</li>
* <li><code>UTF-8</code><br>
* Eight-bit Unicode Transformation Format.</li>
* <li><code>UTF-16BE</code><br>
* Sixteen-bit Unicode Transformation Format, big-endian byte order.</li>
* <li><code>UTF-16LE</code><br>
* Sixteen-bit Unicode Transformation Format, little-endian byte order.</li>
* <li><code>UTF-16</code><br>
* Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
* 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>
* @since 2.3
* @version $Id$
*/
public class Charsets {
//
// This class should only contain Charset instances for required encodings. This guarantees that it will load
// correctly and without delay on all Java platforms.
//
/**
* Constructs a sorted map from canonical charset names to charset objects required of every implementation of the
* Java platform.
* <p>
* From the Java documentation <a href="https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">
* Standard charsets</a>:
* </p>
*
* @return An immutable, case-insensitive map from canonical charset names to charset objects.
* @see Charset#availableCharsets()
* @since 2.5
*/
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);
return Collections.unmodifiableSortedMap(m);
}
/**
* Returns the given Charset or the default Charset if the given Charset is null.
*
* @param charset
* A charset or null.
* @return the given Charset or the default Charset if the given Charset is null
*/
public static Charset toCharset(final Charset charset) {
return charset == null ? Charset.defaultCharset() : charset;
}
/**
* Returns a Charset for the named charset. If the name is null, return the default Charset.
*
* @param charset
* The name of the requested charset, may be null.
* @return a Charset for the named charset
* @throws java.nio.charset.UnsupportedCharsetException
* If the named charset is unavailable
*/
public static Charset toCharset(final String charset) {
return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
}
/**
* CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
* <p>
* 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>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/
@Deprecated
public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
/**
* <p>
* Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
* </p>
* <p>
* 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>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/
@Deprecated
public static final Charset US_ASCII = StandardCharsets.US_ASCII;
/**
* <p>
* Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
* (either order accepted on input, big-endian used on output)
* </p>
* <p>
* 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>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/
@Deprecated
public static final Charset UTF_16 = StandardCharsets.UTF_16;
/**
* <p>
* Sixteen-bit Unicode Transformation Format, big-endian byte order.
* </p>
* <p>
* 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>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/
@Deprecated
public static final Charset UTF_16BE = StandardCharsets.UTF_16BE;
/**
* <p>
* Sixteen-bit Unicode Transformation Format, little-endian byte order.
* </p>
* <p>
* 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>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/
@Deprecated
public static final Charset UTF_16LE = StandardCharsets.UTF_16LE;
/**
* <p>
* Eight-bit Unicode Transformation Format.
* </p>
* <p>
* 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>
* @deprecated Use Java 7's {@link java.nio.charset.StandardCharsets}
*/
@Deprecated
public static final Charset UTF_8 = StandardCharsets.UTF_8;
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fr.third.org.apache.commons.io;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;
/**
* Charsets required of every implementation of the Java platform.
*
* From the Java documentation <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
* the release documentation for your implementation to see if any other encodings are supported. Consult the release
* documentation for your implementation to see if any other encodings are supported. </cite>
* </p>
*
* <ul>
* <li><code>US-ASCII</code><br>
* Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.</li>
* <li><code>ISO-8859-1</code><br>
* ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.</li>
* <li><code>UTF-8</code><br>
* Eight-bit Unicode Transformation Format.</li>
* <li><code>UTF-16BE</code><br>
* Sixteen-bit Unicode Transformation Format, big-endian byte order.</li>
* <li><code>UTF-16LE</code><br>
* Sixteen-bit Unicode Transformation Format, little-endian byte order.</li>
* <li><code>UTF-16</code><br>
* Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
* accepted on input, big-endian used on output.)</li>
* </ul>
*
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
* @since 2.3
* @version $Id: Charsets.java 1686747 2015-06-21 18:44:49Z krosenvold $
*/
public class Charsets {
//
// This class should only contain Charset instances for required encodings. This guarantees that it will load
// correctly and without delay on all Java platforms.
//
/**
* Constructs a sorted map from canonical charset names to charset objects required of every implementation of the
* Java platform.
* <p>
* From the Java documentation <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">
* Standard charsets</a>:
* </p>
*
* @return An immutable, case-insensitive map from canonical charset names to charset objects.
* @see Charset#availableCharsets()
* @since 2.5
*/
public static SortedMap<String, Charset> requiredCharsets() {
// maybe cache?
// 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);
}
/**
* Returns the given Charset or the default Charset if the given Charset is null.
*
* @param charset
* A charset or null.
* @return the given Charset or the default Charset if the given Charset is null
*/
public static Charset toCharset(final Charset charset) {
return charset == null ? Charset.defaultCharset() : charset;
}
/**
* Returns a Charset for the named charset. If the name is null, return the default Charset.
*
* @param charset
* The name of the requested charset, may be null.
* @return a Charset for the named charset
* @throws java.nio.charset.UnsupportedCharsetException
* If the named charset is unavailable
*/
public static Charset toCharset(final String charset) {
return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
}
/**
* CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
* <p>
* Every implementation of the Java platform is required to support this character encoding.
* </p>
*
* @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 = Charset.forName("ISO-8859-1");
/**
* <p>
* Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
* </p>
* <p>
* Every implementation of the Java platform is required to support this character encoding.
* </p>
*
* @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 = Charset.forName("US-ASCII");
/**
* <p>
* Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
* (either order accepted on input, big-endian used on output)
* </p>
* <p>
* Every implementation of the Java platform is required to support this character encoding.
* </p>
*
* @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 = Charset.forName("UTF-16");
/**
* <p>
* Sixteen-bit Unicode Transformation Format, big-endian byte order.
* </p>
* <p>
* Every implementation of the Java platform is required to support this character encoding.
* </p>
*
* @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 = Charset.forName("UTF-16BE");
/**
* <p>
* Sixteen-bit Unicode Transformation Format, little-endian byte order.
* </p>
* <p>
* Every implementation of the Java platform is required to support this character encoding.
* </p>
*
* @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 = Charset.forName("UTF-16LE");
/**
* <p>
* Eight-bit Unicode Transformation Format.
* </p>
* <p>
* Every implementation of the Java platform is required to support this character encoding.
* </p>
*
* @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 = Charset.forName("UTF-8");
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -103,6 +103,7 @@ import java.nio.charset.Charset;
* <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> {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,7 +16,7 @@
*/
package com.fr.third.org.apache.commons.io;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import com.fr.third.org.apache.commons.io.input.SwappedDataInputStream;
import java.io.EOFException;
import java.io.IOException;
@ -35,7 +35,8 @@ import java.io.OutputStream;
* <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 {
@ -188,7 +189,7 @@ public class EndianUtils {
final long high = data[ offset + 3 ] & 0xff;
return (high << 24) + (0xffffffffL & low);
return (high << 24) + (0xffffffffL & low);
}
/**
@ -369,7 +370,7 @@ public class EndianUtils {
final long high = value4 & 0xff;
return (high << 24) + (0xffffffffL & low);
return (high << 24) + (0xffffffffL & low);
}
/**

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -32,6 +32,7 @@ import java.io.File;
* {@link #exitWhenFinished}, typically in
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar.
*
* @version $Id: FileCleaner.java 1680650 2015-05-20 18:36:40Z britter $
* @deprecated Use {@link FileCleaningTracker}
*/
@Deprecated
@ -60,7 +61,7 @@ public class FileCleaner {
/**
* Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected.
* The specified deletion strategy is used.
* The speified deletion strategy is used.
*
* @param file the file to be tracked, not null
* @param marker the marker object used to track the file, not null
@ -91,7 +92,7 @@ public class FileCleaner {
/**
* Track the specified file, using the provided marker, deleting the file
* when the marker instance is garbage collected.
* The specified deletion strategy is used.
* The speified deletion strategy is used.
*
* @param path the full path to the file to be tracked, not null
* @param marker the marker object used to track the file, not null
@ -125,7 +126,7 @@ public class FileCleaner {
* thread will simply exit when the JVM exits. In a more complex environment,
* with multiple class loaders (such as an application server), you should be
* aware that the file cleaner thread will continue running even if the class
* loader it was started from terminates. This can constitute a memory leak.
* loader it was started from terminates. This can consitute a memory leak.
* <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
@ -135,7 +136,7 @@ public class FileCleaner {
* posing a memory leak.
* <p>
* This method allows the thread to be terminated. Simply call this method
* in the resource cleanup code, such as
* in the resource cleanup code, such as
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)}.
* One called, no new objects can be tracked by the file cleaner.
* @deprecated Use {@link FileCleaningTracker#exitWhenFinished()}.
@ -150,7 +151,7 @@ public class FileCleaner {
* This is mainly useful for code, which wants to support the new
* {@link FileCleaningTracker} class while maintain compatibility with the
* deprecated {@link FileCleaner}.
*
*
* @return the singleton instance
*/
public static FileCleaningTracker getInstance() {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -39,6 +39,7 @@ import java.util.List;
* {@link #exitWhenFinished}, typically in
* {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)} or similar.
*
* @version $Id: FileCleaningTracker.java 1686747 2015-06-21 18:44:49Z krosenvold $
*/
public class FileCleaningTracker {
@ -47,7 +48,7 @@ public class FileCleaningTracker {
/**
* Queue of <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

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -28,6 +28,7 @@ import java.io.IOException;
* <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
*/

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -21,7 +21,8 @@ import java.io.IOException;
/**
* Indicates that a file already exists.
*
*
* @version $Id: FileExistsException.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0
*/
public class FileExistsException extends IOException {

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;
}
}

25
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;
@ -716,7 +715,7 @@ public class FilenameUtils {
* <p>
* The output will be the same irrespective of the machine that the code is running on.
* </p>
*
*
* @param filename
* the filename to find the last extension separator in, null returns -1
* @return the index of the last extension separator character, or -1 if there is no such character
@ -772,7 +771,7 @@ public class FilenameUtils {
failIfNullBytePresent(filename + UNIX_SEPARATOR);
return filename + UNIX_SEPARATOR;
}
final String path = filename.substring(0, len);
String path = filename.substring(0, len);
failIfNullBytePresent(path);
return path;
}
@ -852,7 +851,7 @@ public class FilenameUtils {
if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
return "";
}
final String path = filename.substring(prefix, endIndex);
String path = filename.substring(prefix, endIndex);
failIfNullBytePresent(path);
return path;
}
@ -982,8 +981,8 @@ public class FilenameUtils {
* This may be used for poison byte attacks.
* @param path the path to check
*/
private static void failIfNullBytePresent(final String path) {
final int len = path.length();
private static void failIfNullBytePresent(String path) {
int len = path.length();
for (int i = 0; i < len; i++) {
if (path.charAt(i) == 0) {
throw new IllegalArgumentException("Null byte present in file/path name. There are no " +
@ -1278,7 +1277,7 @@ public class FilenameUtils {
*
* @param filename the filename to match on
* @param wildcardMatcher the wildcard string to match against
* @return true if the filename matches the wildcard string
* @return true if the filename matches the wilcard string
* @see IOCase#SENSITIVE
*/
public static boolean wildcardMatch(final String filename, final String wildcardMatcher) {
@ -1304,7 +1303,7 @@ public class FilenameUtils {
*
* @param filename the filename to match on
* @param wildcardMatcher the wildcard string to match against
* @return true if the filename matches the wildcard string
* @return true if the filename matches the wilcard string
* @see IOCase#SYSTEM
*/
public static boolean wildcardMatchOnSystem(final String filename, final String wildcardMatcher) {
@ -1322,7 +1321,7 @@ public class FilenameUtils {
* @param filename the filename to match on
* @param wildcardMatcher the wildcard string to match against
* @param caseSensitivity what case sensitivity rule to use, null means case-sensitive
* @return true if the filename matches the wildcard string
* @return true if the filename matches the wilcard string
* @since 1.3
*/
public static boolean wildcardMatch(final String filename, final String wildcardMatcher, IOCase caseSensitivity) {
@ -1339,7 +1338,7 @@ public class FilenameUtils {
boolean anyChars = false;
int textIdx = 0;
int wcsIdx = 0;
final Stack<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))
{

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -21,7 +21,8 @@ import java.io.IOException;
/**
* Subclasses IOException with the {@link Throwable} constructors missing before Java 6.
*
*
* @version $Id: IOExceptionWithCause.java 1643107 2014-12-03 13:05:23Z sebb $
* @since 1.4
* @deprecated (since 2.5) use {@link IOException} instead
*/
@ -39,7 +40,7 @@ public class IOExceptionWithCause extends IOException {
* As specified in {@link Throwable}, the message in the given <code>cause</code> is not used in this instance's
* message.
* </p>
*
*
* @param message
* the message (see {@link #getMessage()})
* @param cause
@ -55,7 +56,7 @@ public class IOExceptionWithCause extends IOException {
* The message is set to <code>cause==null ? null : cause.toString()</code>, which by default contains the class
* and message of <code>cause</code>. This constructor is useful for call sites that just wrap another throwable.
* </p>
*
*
* @param cause
* the cause (see {@link #getCause()}). A {@code null} value is allowed.
*/

248
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)) {
out.println();
LINE_SEPARATOR = buf.toString();
}
final StringBuilderWriter buf = new StringBuilderWriter(4);
final PrintWriter out = new PrintWriter(buf);
out.println();
LINE_SEPARATOR = buf.toString();
out.close();
}
/**
@ -211,12 +212,7 @@ public class IOUtils {
* </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,10 +717,9 @@ public class IOUtils {
* @throws IOException if an I/O error occurs
*/
public static byte[] toByteArray(final InputStream input) throws IOException {
try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) {
copy(input, output);
return output.toByteArray();
}
final ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output);
return output.toByteArray();
}
/**
@ -818,14 +773,14 @@ public class IOUtils {
final byte[] data = new byte[size];
int offset = 0;
int read;
int readed;
while (offset < size && (read = input.read(data, offset, size - offset)) != EOF) {
offset += read;
while (offset < size && (readed = input.read(data, offset, size - offset)) != EOF) {
offset += readed;
}
if (offset != size) {
throw new IOException("Unexpected read size. current: " + offset + ", expected: " + size);
throw new IOException("Unexpected readed size. current: " + offset + ", excepted: " + size);
}
return data;
@ -864,10 +819,9 @@ public class IOUtils {
* @since 2.3
*/
public static byte[] toByteArray(final Reader input, final Charset encoding) throws IOException {
try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) {
copy(input, output, encoding);
return output.toByteArray();
}
final ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output, encoding);
return output.toByteArray();
}
/**
@ -953,8 +907,11 @@ public class IOUtils {
* @since 2.4
*/
public static byte[] toByteArray(final URLConnection urlConn) throws IOException {
try (InputStream inputStream = urlConn.getInputStream()) {
final InputStream inputStream = urlConn.getInputStream();
try {
return IOUtils.toByteArray(inputStream);
} finally {
inputStream.close();
}
}
@ -1080,10 +1037,9 @@ public class IOUtils {
* @since 2.3
*/
public static String toString(final InputStream input, final Charset encoding) throws IOException {
try (final StringBuilderWriter sw = new StringBuilderWriter()) {
copy(input, sw, encoding);
return sw.toString();
}
final StringBuilderWriter sw = new StringBuilderWriter();
copy(input, sw, encoding);
return sw.toString();
}
/**
@ -1122,10 +1078,9 @@ public class IOUtils {
* @throws IOException if an I/O error occurs
*/
public static String toString(final Reader input) throws IOException {
try (final StringBuilderWriter sw = new StringBuilderWriter()) {
copy(input, sw);
return sw.toString();
}
final StringBuilderWriter sw = new StringBuilderWriter();
copy(input, sw);
return sw.toString();
}
/**
@ -1195,8 +1150,11 @@ public class IOUtils {
* @since 2.3
*/
public static String toString(final URL url, final Charset encoding) throws IOException {
try (InputStream inputStream = url.openStream()) {
final InputStream inputStream = url.openStream();
try {
return toString(inputStream, encoding);
} finally {
inputStream.close();
}
}
@ -1249,132 +1207,6 @@ public class IOUtils {
return new String(input, Charsets.toCharset(encoding));
}
// resources
//-----------------------------------------------------------------------
/**
* Gets the contents of a classpath resource as a String using the
* specified character encoding.
*
* <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;
}
}

42
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);
}
close();
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,28 +161,19 @@ 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.
if (iterator != null) {
iterator.close();
}
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -26,7 +26,7 @@ import java.io.Serializable;
*
* @since 2.0
*/
@SuppressWarnings("deprecation") // needs to extend deprecated IOExceptionWithCause to preserve binary compatibility
@SuppressWarnings("deprecation") // needs to extend deprecated IOExceptionWithCause to preserve binary compatibility
public class TaggedIOException extends IOExceptionWithCause {
/**

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

@ -24,7 +24,7 @@ package com.fr.third.org.apache.commons.io;
* completes its work before being interrupted, it should <code>interrupt()</code>
* the <i>monitor</i> thread.
* </p>
*
*
* <pre>
* long timeoutInMillis = 1000;
* try {
@ -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);

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -25,6 +25,7 @@ import java.util.List;
/**
* Abstract file {@link Comparator} which provides sorting for file arrays and lists.
*
* @version $Id: AbstractFileComparator.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0
*/
abstract class AbstractFileComparator implements Comparator<File> {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -39,6 +39,7 @@ import java.util.List;
* comparator.sort(list);
* </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);
}
@ -82,13 +83,12 @@ public class CompositeFileComparator extends AbstractFileComparator implements S
/**
* Compare the two files using delegate comparators.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return the first non-zero result returned from
* the delegate comparators or zero.
*/
@Override
public int compare(final File file1, final File file2) {
int result = 0;
for (final Comparator<File> delegate : delegates) {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -41,6 +41,7 @@ import java.util.Comparator;
* </pre>
* <p>
*
* @version $Id: DefaultFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class DefaultFileComparator extends AbstractFileComparator implements Serializable {
@ -55,13 +56,12 @@ public class DefaultFileComparator extends AbstractFileComparator implements Ser
/**
* Compare the two files using the {@link File#compareTo(File)} method.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return the result of calling file1's
* {@link File#compareTo(File)} with file2 as the parameter.
*/
@Override
public int compare(final File file1, final File file2) {
return file1.compareTo(file2);
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -40,6 +40,7 @@ import java.util.Comparator;
* </pre>
* <p>
*
* @version $Id: DirectoryFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 2.0
*/
public class DirectoryFileComparator extends AbstractFileComparator implements Serializable {
@ -54,13 +55,12 @@ public class DirectoryFileComparator extends AbstractFileComparator implements S
/**
* Compare the two files using the {@link File#isDirectory()} method.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return the result of calling file1's
* {@link File#compareTo(File)} with file2 as the parameter.
*/
@Override
public int compare(final File file1, final File file2) {
return getType(file1) - getType(file2);
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -20,8 +20,6 @@ import java.io.File;
import java.io.Serializable;
import java.util.Comparator;
import com.fr.third.org.apache.commons.io.FilenameUtils;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.FilenameUtils;
import com.fr.third.org.apache.commons.io.IOCase;
@ -50,6 +48,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
* <p>
*
* @version $Id: ExtensionFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class ExtensionFileComparator extends AbstractFileComparator implements Serializable {
@ -97,16 +96,15 @@ public class ExtensionFileComparator extends AbstractFileComparator implements S
/**
* Compare the extensions of two files the specified case sensitivity.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return a negative value if the first file's extension
* is less than the second, zero if the extensions are the
* same and a positive value if the first files extension
* is greater than the second file.
*
*
*/
@Override
public int compare(final File file1, final File file2) {
final String suffix1 = FilenameUtils.getExtension(file1.getName());
final String suffix2 = FilenameUtils.getExtension(file2.getName());

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -21,7 +21,7 @@ import java.io.Serializable;
import java.util.Comparator;
/**
* Compare the <b>last modified date/time</b> of two files for order
* Compare the <b>last modified date/time</b> of two files for order
* (see {@link File#lastModified()}).
* <p>
* This comparator can be used to sort lists or arrays of files
@ -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 {
@ -56,16 +57,15 @@ public class LastModifiedFileComparator extends AbstractFileComparator implement
/**
* Compare the last the last modified date/time of two files.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return a negative value if the first file's lastmodified date/time
* is less than the second, zero if the lastmodified date/time are the
* same and a positive value if the first files lastmodified date/time
* is greater than the second file.
*
*
*/
@Override
public int compare(final File file1, final File file2) {
final long result = file1.lastModified() - file2.lastModified();
if (result < 0) {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable;
import java.util.Comparator;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
* <p>
*
* @version $Id: NameFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class NameFileComparator extends AbstractFileComparator implements Serializable {
@ -92,7 +92,7 @@ public class NameFileComparator extends AbstractFileComparator implements Serial
/**
* Compare the names of two files with the specified case sensitivity.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return a negative value if the first file's name
@ -100,7 +100,6 @@ public class NameFileComparator extends AbstractFileComparator implements Serial
* same and a positive value if the first files name
* is greater than the second file.
*/
@Override
public int compare(final File file1, final File file2) {
return caseSensitivity.checkCompareTo(file1.getName(), file2.getName());
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable;
import java.util.Comparator;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* </pre>
* <p>
*
* @version $Id: PathFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class PathFileComparator extends AbstractFileComparator implements Serializable {
@ -92,16 +92,15 @@ public class PathFileComparator extends AbstractFileComparator implements Serial
/**
* Compare the paths of two files the specified case sensitivity.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return a negative value if the first file's path
* is less than the second, zero if the paths are the
* same and a positive value if the first files path
* is greater than the second file.
*
*
*/
@Override
public int compare(final File file1, final File file2) {
return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath());
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -24,6 +24,7 @@ import java.util.Comparator;
* Reverses the result of comparing two objects using
* the delegate {@link Comparator}.
*
* @version $Id: ReverseComparator.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
class ReverseComparator extends AbstractFileComparator implements Serializable {
@ -32,7 +33,7 @@ class ReverseComparator extends AbstractFileComparator implements Serializable {
private final Comparator<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
*/
@ -45,13 +46,12 @@ class ReverseComparator extends AbstractFileComparator implements Serializable {
/**
* Compare using the delegate Comparator, but reversing the result.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return the result from the delegate {@link Comparator#compare(Object, Object)}
* reversing the value (i.e. positive becomes negative and vice versa)
*/
@Override
public int compare(final File file1, final File file2) {
return delegate.compare(file2, file1); // parameters switched round
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable;
import java.util.Comparator;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.third.org.apache.commons.io.FileUtils;
/**
@ -47,6 +46,7 @@ import com.fr.third.org.apache.commons.io.FileUtils;
* <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)}).
*/
@ -98,16 +98,15 @@ public class SizeFileComparator extends AbstractFileComparator implements Serial
/**
* Compare the length of two files.
*
*
* @param file1 The first file to compare
* @param file2 The second file to compare
* @return a negative value if the first file's length
* is less than the second, zero if the lengths are the
* same and a positive value if the first files length
* is greater than the second file.
*
*
*/
@Override
public int compare(final File file1, final File file2) {
long size1 = 0;
if (file1.isDirectory()) {

260
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>
File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
</pre>
<p>
<pre>
File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
</pre>
</p>
<h3>Composite Comparator</h3>
<p>
@ -48,137 +50,139 @@ for {@link java.io.File}s.
For example, to sort an array of files by type (i.e. directory or file)
and then by name:
</p>
<pre>
CompositeFileComparator comparator =
new CompositeFileComparator(
DirectoryFileComparator.DIRECTORY_COMPARATOR,
NameFileComparator.NAME_COMPARATOR);
File[] files = dir.listFiles();
comparator.sort(files);
</pre>
<p>
<pre>
CompositeFileComparator comparator =
new CompositeFileComparator(
DirectoryFileComparator.DIRECTORY_COMPARATOR,
NameFileComparator.NAME_COMPARATOR);
File[] files = dir.listFiles();
comparator.sort(files);
</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:
<ul>
<li><a href="DefaultFileComparator.html">DefaultFileComparator</a> - default file compare:
<ul>
<li><a href="DefaultFileComparator.html#DEFAULT_COMPARATOR">DEFAULT_COMPARATOR</a>
- Compare using <code>File.compareTo(File)</code> method.
</li>
<li><a href="DefaultFileComparator.html#DEFAULT_REVERSE">DEFAULT_REVERSE</a>
- Reverse compare of <code>File.compareTo(File)</code> method.
</li>
</ul>
</li>
<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 < files).
</li>
<li><a href="DirectoryFileComparator.html#DIRECTORY_REVERSE">DIRECTORY_REVERSE</a>
- Reverse compare of <code>File.isDirectory()</code> method (directories > files).
</li>
</ul>
</li>
<li><a href="ExtensionFileComparator.html">ExtensionFileComparator</a> - compare file extenstions:
<ul>
<li><a href="ExtensionFileComparator.html#EXTENSION_COMPARATOR">EXTENSION_COMPARATOR</a>
- Compare using <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_REVERSE">EXTENSION_REVERSE</a>
- Reverse compare of <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_INSENSITIVE_COMPARATOR">EXTENSION_INSENSITIVE_COMPARATOR</a>
- Case-insensitive compare using <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_INSENSITIVE_REVERSE">EXTENSION_INSENSITIVE_REVERSE</a>
- Reverse case-insensitive compare of <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_SYSTEM_COMPARATOR">EXTENSION_SYSTEM_COMPARATOR</a>
- System sensitive compare using <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_SYSTEM_REVERSE">EXTENSION_SYSTEM_REVERSE</a>
- Reverse system sensitive compare of <code>FilenameUtils.getExtension(String)</code> method.
</li>
</ul>
</li>
<li><a href="LastModifiedFileComparator.html">LastModifiedFileComparator</a>
- compare the file's last modified date/time:
<ul>
<li><a href="LastModifiedFileComparator.html#LASTMODIFIED_COMPARATOR">LASTMODIFIED_COMPARATOR</a>
- Compare using <code>File.lastModified()</code> method.
</li>
<li><a href="LastModifiedFileComparator.html#LASTMODIFIED_REVERSE">LASTMODIFIED_REVERSE</a>
- Reverse compare of <code>File.lastModified()</code> method.
</li>
</ul>
</li>
<li><a href="NameFileComparator.html">NameFileComparator</a> - compare file names:
<ul>
<li><a href="NameFileComparator.html#NAME_COMPARATOR">NAME_COMPARATOR</a>
- Compare using <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_REVERSE">NAME_REVERSE</a>
- Reverse compare of <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR">NAME_INSENSITIVE_COMPARATOR</a>
- Case-insensitive compare using <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_INSENSITIVE_REVERSE">NAME_INSENSITIVE_REVERSE</a>
- Reverse case-insensitive compare of <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_SYSTEM_COMPARATOR">NAME_SYSTEM_COMPARATOR</a>
- System sensitive compare using <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_SYSTEM_REVERSE">NAME_SYSTEM_REVERSE</a>
- Reverse system sensitive compare of <code>File.getName()</code> method.
</li>
</ul>
</li>
<li><a href="PathFileComparator.html">PathFileComparator</a> - compare file paths:
<ul>
<li><a href="PathFileComparator.html#PATH_COMPARATOR">PATH_COMPARATOR</a>
- Compare using <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_REVERSE">PATH_REVERSE</a>
- Reverse compare of <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_INSENSITIVE_COMPARATOR">PATH_INSENSITIVE_COMPARATOR</a>
- Case-insensitive compare using <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_INSENSITIVE_REVERSE">PATH_INSENSITIVE_REVERSE</a>
- Reverse case-insensitive compare of <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_SYSTEM_COMPARATOR">PATH_SYSTEM_COMPARATOR</a>
- System sensitive compare using <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_SYSTEM_REVERSE">PATH_SYSTEM_REVERSE</a>
- Reverse system sensitive compare of <code>File.getPath()</code> method.
</li>
</ul>
</li>
<li><a href="SizeFileComparator.html">SizeFileComparator</a> - compare the file's size:
<ul>
<li><a href="SizeFileComparator.html#SIZE_COMPARATOR">SIZE_COMPARATOR</a>
- Compare using <code>File.length()</code> method (directories treated as zero length).
</li>
<li><a href="SizeFileComparator.html#SIZE_REVERSE">LASTMODIFIED_REVERSE</a>
- Reverse compare of <code>File.length()</code> method (directories treated as zero length).
</li>
<li><a href="SizeFileComparator.html#SIZE_SUMDIR_COMPARATOR">SIZE_SUMDIR_COMPARATOR</a>
- Compare using <code>FileUtils.sizeOfDirectory(File)</code> method
(sums the size of a directory's contents).
</li>
<li><a href="SizeFileComparator.html#SIZE_SUMDIR_REVERSE">SIZE_SUMDIR_REVERSE</a>
- Reverse compare of <code>FileUtils.sizeOfDirectory(File)</code> method
(sums the size of a directory's contents).
</li>
</ul>
</li>
</ul>
</p>
<ul>
<li><a href="DefaultFileComparator.html">DefaultFileComparator</a> - default file compare:
<ul>
<li><a href="DefaultFileComparator.html#DEFAULT_COMPARATOR">DEFAULT_COMPARATOR</a>
- Compare using <code>File.compareTo(File)</code> method.
</li>
<li><a href="DefaultFileComparator.html#DEFAULT_REVERSE">DEFAULT_REVERSE</a>
- Reverse compare of <code>File.compareTo(File)</code> method.
</li>
</ul>
</li>
<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).
</li>
<li><a href="DirectoryFileComparator.html#DIRECTORY_REVERSE">DIRECTORY_REVERSE</a>
- Reverse compare of <code>File.isDirectory()</code> method (directories &gt;files).
</li>
</ul>
</li>
<li><a href="ExtensionFileComparator.html">ExtensionFileComparator</a> - compare file extenstions:
<ul>
<li><a href="ExtensionFileComparator.html#EXTENSION_COMPARATOR">EXTENSION_COMPARATOR</a>
- Compare using <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_REVERSE">EXTENSION_REVERSE</a>
- Reverse compare of <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_INSENSITIVE_COMPARATOR">EXTENSION_INSENSITIVE_COMPARATOR</a>
- Case-insensitive compare using <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_INSENSITIVE_REVERSE">EXTENSION_INSENSITIVE_REVERSE</a>
- Reverse case-insensitive compare of <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_SYSTEM_COMPARATOR">EXTENSION_SYSTEM_COMPARATOR</a>
- System sensitive compare using <code>FilenameUtils.getExtension(String)</code> method.
</li>
<li><a href="ExtensionFileComparator.html#EXTENSION_SYSTEM_REVERSE">EXTENSION_SYSTEM_REVERSE</a>
- Reverse system sensitive compare of <code>FilenameUtils.getExtension(String)</code> method.
</li>
</ul>
</li>
<li><a href="LastModifiedFileComparator.html">LastModifiedFileComparator</a>
- compare the file's last modified date/time:
<ul>
<li><a href="LastModifiedFileComparator.html#LASTMODIFIED_COMPARATOR">LASTMODIFIED_COMPARATOR</a>
- Compare using <code>File.lastModified()</code> method.
</li>
<li><a href="LastModifiedFileComparator.html#LASTMODIFIED_REVERSE">LASTMODIFIED_REVERSE</a>
- Reverse compare of <code>File.lastModified()</code> method.
</li>
</ul>
</li>
<li><a href="NameFileComparator.html">NameFileComparator</a> - compare file names:
<ul>
<li><a href="NameFileComparator.html#NAME_COMPARATOR">NAME_COMPARATOR</a>
- Compare using <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_REVERSE">NAME_REVERSE</a>
- Reverse compare of <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR">NAME_INSENSITIVE_COMPARATOR</a>
- Case-insensitive compare using <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_INSENSITIVE_REVERSE">NAME_INSENSITIVE_REVERSE</a>
- Reverse case-insensitive compare of <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_SYSTEM_COMPARATOR">NAME_SYSTEM_COMPARATOR</a>
- System sensitive compare using <code>File.getName()</code> method.
</li>
<li><a href="NameFileComparator.html#NAME_SYSTEM_REVERSE">NAME_SYSTEM_REVERSE</a>
- Reverse system sensitive compare of <code>File.getName()</code> method.
</li>
</ul>
</li>
<li><a href="PathFileComparator.html">PathFileComparator</a> - compare file paths:
<ul>
<li><a href="PathFileComparator.html#PATH_COMPARATOR">PATH_COMPARATOR</a>
- Compare using <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_REVERSE">PATH_REVERSE</a>
- Reverse compare of <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_INSENSITIVE_COMPARATOR">PATH_INSENSITIVE_COMPARATOR</a>
- Case-insensitive compare using <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_INSENSITIVE_REVERSE">PATH_INSENSITIVE_REVERSE</a>
- Reverse case-insensitive compare of <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_SYSTEM_COMPARATOR">PATH_SYSTEM_COMPARATOR</a>
- System sensitive compare using <code>File.getPath()</code> method.
</li>
<li><a href="PathFileComparator.html#PATH_SYSTEM_REVERSE">PATH_SYSTEM_REVERSE</a>
- Reverse system sensitive compare of <code>File.getPath()</code> method.
</li>
</ul>
</li>
<li><a href="SizeFileComparator.html">SizeFileComparator</a> - compare the file's size:
<ul>
<li><a href="SizeFileComparator.html#SIZE_COMPARATOR">SIZE_COMPARATOR</a>
- Compare using <code>File.length()</code> method (directories treated as zero length).
</li>
<li><a href="SizeFileComparator.html#SIZE_REVERSE">LASTMODIFIED_REVERSE</a>
- Reverse compare of <code>File.length()</code> method (directories treated as zero length).
</li>
<li><a href="SizeFileComparator.html#SIZE_SUMDIR_COMPARATOR">SIZE_SUMDIR_COMPARATOR</a>
- Compare using <code>FileUtils.sizeOfDirectory(File)</code> method
(sums the size of a directory's contents).
</li>
<li><a href="SizeFileComparator.html#SIZE_SUMDIR_REVERSE">SIZE_SUMDIR_REVERSE</a>
- Reverse compare of <code>FileUtils.sizeOfDirectory(File)</code> method
(sums the size of a directory's contents).
</li>
</ul>
</li>
</ul>
</body>
</html>

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -19,44 +19,42 @@ package com.fr.third.org.apache.commons.io.filefilter;
import java.io.File;
/**
* An abstract class which implements the Java FileFilter and FilenameFilter
* An abstract class which implements the Java FileFilter and FilenameFilter
* interfaces via the IOFileFilter interface.
* <p>
* Note that a subclass <b>must</b> override one of the accept methods,
* otherwise your class will infinitely loop.
*
* @since 1.0
* @version $Id$
* @version $Id: AbstractFileFilter.java 1415850 2012-11-30 20:51:39Z ggregory $
*/
public abstract class AbstractFileFilter implements IOFileFilter {
/**
* Checks to see if the File should be accepted by this filter.
*
*
* @param file the File to check
* @return true if this file matches the test
*/
@Override
public boolean accept(final File file) {
return accept(file.getParentFile(), file.getName());
}
/**
* Checks to see if the File should be accepted by this filter.
*
*
* @param dir the directory File to check
* @param name the filename within the directory to check
* @return true if this file matches the test
*/
@Override
public boolean accept(final File dir, final String name) {
return accept(new File(dir, name));
}
/**
* Provide a String representation of this file filter.
* Provide a String representaion of this file filter.
*
* @return a String representation
* @return a String representaion
*/
@Override
public String toString() {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable;
import java.util.Date;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.third.org.apache.commons.io.FileUtils;
/**
@ -40,6 +39,7 @@ import com.fr.third.org.apache.commons.io.FileUtils;
* }
* </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() {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -30,7 +30,7 @@ import java.util.List;
* {@code false}.
*
* @since 1.0
* @version $Id$
* @version $Id: AndFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
*
* @see FileFilterUtils#and(IOFileFilter...)
*/
@ -49,7 +49,7 @@ public class AndFileFilter
* @since 1.1
*/
public AndFileFilter() {
this.fileFilters = new ArrayList<>();
this.fileFilters = new ArrayList<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() {
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -22,7 +22,7 @@ import java.util.List;
* Defines operations for conditional file filters.
*
* @since 1.1
* @version $Id$
* @version $Id: ConditionalFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
*/
public interface ConditionalFileFilter {

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() {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -22,7 +22,7 @@ import java.io.Serializable;
/**
* This filter accepts <code>File</code>s that are directories.
* <p>
* For example, here is how to print out a list of the
* For example, here is how to print out a list of the
* current directory's subdirectories:
*
* <pre>
@ -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() {
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -23,7 +23,7 @@ import java.io.Serializable;
* A file filter that always returns false.
*
* @since 1.0
* @version $Id$
* @version $Id: FalseFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
*
* @see FileFilterUtils#falseFileFilter()
*/
@ -44,7 +44,7 @@ public class FalseFileFilter implements IOFileFilter, Serializable {
public static final IOFileFilter INSTANCE = FALSE;
/**
* Restrictive constructor.
* Restrictive consructor.
*/
protected FalseFileFilter() {
}
@ -55,7 +55,6 @@ public class FalseFileFilter implements IOFileFilter, Serializable {
* @param file the file to check (ignored)
* @return false
*/
@Override
public boolean accept(final File file) {
return false;
}
@ -67,7 +66,6 @@ public class FalseFileFilter implements IOFileFilter, Serializable {
* @param name the filename (ignored)
* @return false
*/
@Override
public boolean accept(final File dir, final String name) {
return false;
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -34,7 +34,7 @@ import java.io.Serializable;
* </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);
}

23
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.seek(byteOffset);
final int read = randomAccessFile.read(fileBytes);
if (read != magicNumbers.length) {
return false;
}
return Arrays.equals(this.magicNumbers, fileBytes);
final byte[] fileBytes = new byte[this.magicNumbers.length];
randomAccessFile = new RandomAccessFile(file, "r");
randomAccessFile.seek(byteOffset);
final int read = randomAccessFile.read(fileBytes);
if (read != magicNumbers.length) {
return false;
}
}
catch (final IOException ioe) {
return Arrays.equals(this.magicNumbers, fileBytes);
} catch (final IOException ioe) {
// Do nothing, fall through and do not accept file
} finally {
IOUtils.closeQuietly(randomAccessFile);
}
}

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() {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -30,7 +30,7 @@ import java.util.List;
* {@code true}.
*
* @since 1.0
* @version $Id$
* @version $Id: OrFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#or(IOFileFilter...)
*/
public class OrFileFilter
@ -47,7 +47,7 @@ public class OrFileFilter
* @since 1.1
*/
public OrFileFilter() {
this.fileFilters = new ArrayList<>();
this.fileFilters = new ArrayList<IOFileFilter>();
}
/**
@ -59,15 +59,15 @@ 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);
}
}
/**
* Constructs a new file filter that ORs the result of two other filters.
*
*
* @param filter1 the first filter, must not be null
* @param filter2 the second filter, must not be null
* @throws IllegalArgumentException if either filter is null
@ -76,7 +76,7 @@ public class OrFileFilter
if (filter1 == null || filter2 == null) {
throw new IllegalArgumentException("The filters must not be null");
}
this.fileFilters = new ArrayList<>(2);
this.fileFilters = new ArrayList<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() {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -20,7 +20,6 @@ import java.io.File;
import java.io.Serializable;
import java.util.regex.Pattern;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.IOCase;
/**
@ -40,6 +39,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* }
* </pre>
*
* @version $Id: RegexFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @since 1.4
*/
public class RegexFileFilter extends AbstractFileFilter implements Serializable {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -34,6 +34,7 @@ import java.io.Serializable;
* }
* </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)
@ -48,7 +49,7 @@ public class SizeFileFilter extends AbstractFileFilter implements Serializable {
private final boolean acceptLarger;
/**
* Constructs a new size file filter for files equal to or
* Constructs a new size file filter for files equal to or
* larger than a certain size.
*
* @param size the threshold size of the files
@ -94,9 +95,9 @@ public class SizeFileFilter extends AbstractFileFilter implements Serializable {
}
/**
* Provide a String representation of this file filter.
* Provide a String representaion of this file filter.
*
* @return a String representation
* @return a String representaion
*/
@Override
public String toString() {

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() {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -23,7 +23,7 @@ import java.io.Serializable;
* A file filter that always returns true.
*
* @since 1.0
* @version $Id$
* @version $Id: TrueFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
* @see FileFilterUtils#trueFileFilter()
*/
public class TrueFileFilter implements IOFileFilter, Serializable {
@ -54,7 +54,6 @@ public class TrueFileFilter implements IOFileFilter, Serializable {
* @param file the file to check (ignored)
* @return true
*/
@Override
public boolean accept(final File file) {
return true;
}
@ -66,7 +65,6 @@ public class TrueFileFilter implements IOFileFilter, Serializable {
* @param name the filename (ignored)
* @return true
*/
@Override
public boolean accept(final File dir, final String name) {
return true;
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -20,8 +20,6 @@ import java.io.File;
import java.io.Serializable;
import java.util.List;
import com.fr.third.org.apache.commons.io.FilenameUtils;
import com.fr.third.org.apache.commons.io.IOCase;
import com.fr.third.org.apache.commons.io.FilenameUtils;
import com.fr.third.org.apache.commons.io.IOCase;
@ -47,6 +45,7 @@ import com.fr.third.org.apache.commons.io.IOCase;
* }
* </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>

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
@ -35,6 +33,7 @@ import java.io.InputStream;
* closing the stream when no longer needed) or the underlying stream (by not
* releasing resources once the last byte has been read) do not do that.
*
* @version $Id: AutoCloseInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
* @since 1.4
*/
public class AutoCloseInputStream extends ProxyInputStream {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,25 +16,21 @@
*/
package com.fr.third.org.apache.commons.io.input;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.fr.third.org.apache.commons.io.ByteOrderMark;
import com.fr.third.org.apache.commons.io.IOUtils;
import com.fr.third.org.apache.commons.io.ByteOrderMark;
/**
* This class is used to wrap a stream that includes an encoded {@link ByteOrderMark} as its first bytes.
*
*
* This class detects these bytes and, if required, can automatically skip them and return the subsequent byte as the
* first byte in the stream.
*
*
* The {@link ByteOrderMark} implementation has the following pre-defined BOMs:
* <ul>
* <li>UTF-8 - {@link ByteOrderMark#UTF_8}</li>
@ -43,19 +39,19 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark;
* <li>UTF-32BE - {@link ByteOrderMark#UTF_32LE}</li>
* <li>UTF-32LE - {@link ByteOrderMark#UTF_32BE}</li>
* </ul>
*
*
*
*
* <h3>Example 1 - Detect and exclude a UTF-8 BOM</h3>
*
*
* <pre>
* BOMInputStream bomIn = new BOMInputStream(in);
* if (bomIn.hasBOM()) {
* // has a UTF-8 BOM
* }
* </pre>
*
*
* <h3>Example 2 - Detect a UTF-8 BOM (but don't exclude it)</h3>
*
*
* <pre>
* boolean include = true;
* BOMInputStream bomIn = new BOMInputStream(in, include);
@ -63,11 +59,11 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark;
* // has a UTF-8 BOM
* }
* </pre>
*
*
* <h3>Example 3 - Detect Multiple BOMs</h3>
*
*
* <pre>
* BOMInputStream bomIn = new BOMInputStream(in,
* BOMInputStream bomIn = new BOMInputStream(in,
* ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE,
* ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE
* );
@ -83,10 +79,10 @@ import com.fr.third.org.apache.commons.io.ByteOrderMark;
* // has a UTF-32BE BOM
* }
* </pre>
*
*
* @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 {
@ -104,7 +100,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Constructs a new BOM InputStream that excludes a {@link ByteOrderMark#UTF_8} BOM.
*
*
* @param delegate
* the InputStream to delegate to
*/
@ -114,7 +110,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Constructs a new BOM InputStream that detects a a {@link ByteOrderMark#UTF_8} and optionally includes it.
*
*
* @param delegate
* the InputStream to delegate to
* @param include
@ -126,7 +122,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Constructs a new BOM InputStream that excludes the specified BOMs.
*
*
* @param delegate
* the InputStream to delegate to
* @param boms
@ -141,7 +137,6 @@ public class BOMInputStream extends ProxyInputStream {
*/
private static final Comparator<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();
@ -157,7 +152,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them.
*
*
* @param delegate
* the InputStream to delegate to
* @param include
@ -171,16 +166,15 @@ public class BOMInputStream extends ProxyInputStream {
throw new IllegalArgumentException("No BOMs specified");
}
this.include = include;
final List<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);
}
/**
* Indicates whether the stream contains one of the specified BOMs.
*
*
* @return true if the stream has one of the specified BOMs, otherwise false if it does not
* @throws IOException
* if an error reading the first bytes of the stream occurs
@ -191,7 +185,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Indicates whether the stream contains the specified BOM.
*
*
* @param bom
* The BOM to check for
* @return true if the stream has the specified BOM, otherwise false if it does not
@ -204,13 +198,12 @@ public class BOMInputStream extends ProxyInputStream {
if (!boms.contains(bom)) {
throw new IllegalArgumentException("Stream not configure to detect " + bom);
}
getBOM();
return byteOrderMark != null && byteOrderMark.equals(bom);
return byteOrderMark != null && getBOM().equals(bom);
}
/**
* Return the BOM (Byte Order Mark).
*
*
* @return The BOM or null if none
* @throws IOException
* if an error reading the first bytes of the stream occurs
@ -246,11 +239,11 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Return the BOM charset Name - {@link ByteOrderMark#getCharsetName()}.
*
*
* @return The BOM charset Name or null if no BOM found
* @throws IOException
* if an error reading the first bytes of the stream occurs
*
*
*/
public String getBOMCharsetName() throws IOException {
getBOM();
@ -261,7 +254,7 @@ public class BOMInputStream extends ProxyInputStream {
* This method reads and either preserves or skips the first bytes in the stream. It behaves like the single-byte
* <code>read()</code> method, either returning a valid byte or -1 to indicate that the initial bytes have been
* processed already.
*
*
* @return the byte read (excluding BOM) or -1 if the end of stream
* @throws IOException
* if an I/O error occurs
@ -273,7 +266,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Find a BOM with the specified bytes.
*
*
* @return The matched BOM or null if none matched
*/
private ByteOrderMark find() {
@ -287,7 +280,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Check if the bytes match a BOM.
*
*
* @param bom
* The BOM
* @return true if the bytes match the bom, otherwise false
@ -311,7 +304,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Invokes the delegate's <code>read()</code> method, detecting and optionally skipping BOM.
*
*
* @return the byte read (excluding BOM) or -1 if the end of stream
* @throws IOException
* if an I/O error occurs
@ -324,7 +317,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Invokes the delegate's <code>read(byte[], int, int)</code> method, detecting and optionally skipping BOM.
*
*
* @param buf
* the buffer to read the bytes into
* @param off
@ -353,7 +346,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Invokes the delegate's <code>read(byte[])</code> method, detecting and optionally skipping BOM.
*
*
* @param buf
* the buffer to read the bytes into
* @return the number of bytes read (excluding BOM) or -1 if the end of stream
@ -367,7 +360,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Invokes the delegate's <code>mark(int)</code> method.
*
*
* @param readlimit
* read ahead limit
*/
@ -380,7 +373,7 @@ public class BOMInputStream extends ProxyInputStream {
/**
* Invokes the delegate's <code>reset()</code> method.
*
*
* @throws IOException
* if an I/O error occurs
*/
@ -395,8 +388,8 @@ 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
* @return the number of bytes to skipped or -1 if the end of stream
@ -404,7 +397,7 @@ public class BOMInputStream extends ProxyInputStream {
* if an I/O error occurs
*/
@Override
public long skip(final long n) throws IOException {
public long skip(long n) throws IOException {
int skipped = 0;
while ((n > skipped) && (readFirstBytes() >= 0)) {
skipped++;

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;
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

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;

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.Reader;
import java.io.Serializable;
@ -29,6 +27,7 @@ import java.io.Serializable;
* <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);
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -25,6 +25,7 @@ import java.io.InputStream;
* passed to a component that wants to explicitly close the stream even if
* more input would still be available to other components.
*
* @version $Id: CloseShieldInputStream.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 1.4
*/
public class CloseShieldInputStream extends ProxyInputStream {

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 {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
@ -30,6 +28,7 @@ import java.io.InputStream;
* A typical use case would be during debugging, to ensure that data is being
* read as expected.
*
* @version $Id: CountingInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
*/
public class CountingInputStream extends ProxyInputStream {
@ -95,8 +94,8 @@ public class CountingInputStream extends ProxyInputStream {
return (int) result;
}
/**
* Set the byte count back to 0.
/**
* Set the byte count back to 0.
* <p>
* NOTE: From v1.3 this method throws an ArithmeticException if the
* count is greater than can be expressed by an <code>int</code>.
@ -127,8 +126,8 @@ public class CountingInputStream extends ProxyInputStream {
return this.count;
}
/**
* Set the byte count back to 0.
/**
* Set the byte count back to 0.
* <p>
* NOTE: This method is an alternative for <code>resetCount()</code>
* and was added because that method returns an integer which will

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
@ -27,11 +25,12 @@ import java.io.InputStream;
* Data written to this stream is forwarded to a stream that has been associated
* with this thread.
*
* @version $Id: DemuxInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
*/
public class DemuxInputStream
extends InputStream
{
private final InheritableThreadLocal<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;
}
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@ -62,7 +60,7 @@ import java.io.InputStream;
* </pre>
*
* @since 1.3
* @version $Id$
* @version $Id: NullInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
*/
public class NullInputStream extends InputStream {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.EOFException;
import java.io.IOException;
import java.io.Reader;
@ -62,7 +60,7 @@ import java.io.Reader;
* </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 {

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,28 +18,27 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.FilterReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.CharBuffer;
/**
* A Proxy stream which acts as expected, that is it passes the method
* calls on to the proxied stream and doesn't change which methods are
* being called.
* A Proxy stream which acts as expected, that is it passes the method
* calls on to the proxied stream and doesn't change which methods are
* being called.
* <p>
* It is an alternative base class to FilterReader
* to increase reusability, because FilterReader changes the
* to increase reusability, because FilterReader changes the
* methods being called, such as read(char[]) to read(char[], int, int).
*
*
* @version $Id: ProxyReader.java 1586350 2014-04-10 15:57:20Z ggregory $
*/
public abstract class ProxyReader extends FilterReader {
/**
* Constructs a new ProxyReader.
*
*
* @param proxy the Reader to delegate to
*/
public ProxyReader(final Reader proxy) {

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

16
fine-commons-io/src/com/fr/third/org/apache/commons/io/input/ReversedLinesFileReader.java

@ -23,9 +23,7 @@ import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import com.fr.third.org.apache.commons.io.Charsets;
import com.fr.third.org.apache.commons.io.Charsets;
/**
@ -93,6 +91,7 @@ public class ReversedLinesFileReader implements Closeable {
* @throws IOException if an I/O error occurs
* @since 2.3
*/
@SuppressWarnings("deprecation") // unavoidable until Java 7
public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException {
this.blockSize = blockSize;
this.encoding = encoding;
@ -104,7 +103,7 @@ public class ReversedLinesFileReader implements Closeable {
if (maxBytesPerChar == 1f) {
// all one byte encodings are no problem
byteDecrement = 1;
} else if (charset == StandardCharsets.UTF_8) {
} else if (charset == Charsets.UTF_8) {
// UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte
// http://en.wikipedia.org/wiki/UTF-8
byteDecrement = 1;
@ -115,11 +114,11 @@ public class ReversedLinesFileReader implements Closeable {
charset == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese)
charset == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese)
byteDecrement = 1;
} else if (charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) {
} else if (charset == Charsets.UTF_16BE || charset == Charsets.UTF_16LE) {
// UTF-16 new line sequences are not allowed as second tuple of four byte sequences,
// however byte order has to be specified
byteDecrement = 2;
} else if (charset == StandardCharsets.UTF_16) {
} else if (charset == Charsets.UTF_16) {
throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte order (use UTF-16BE or " +
"UTF-16LE)");
} else {
@ -199,7 +198,6 @@ public class ReversedLinesFileReader implements Closeable {
*
* @throws IOException if an I/O error occurs
*/
@Override
public void close() throws IOException {
randomAccessFile.close();
}
@ -244,7 +242,7 @@ public class ReversedLinesFileReader implements Closeable {
/**
* Handles block rollover
*
*
* @return the new FilePart or null
* @throws IOException if there was a problem reading the file
*/
@ -269,7 +267,7 @@ public class ReversedLinesFileReader implements Closeable {
/**
* Reads a line.
*
*
* @return the line or null
* @throws IOException if there is an error reading from the file
*/
@ -344,7 +342,7 @@ public class ReversedLinesFileReader implements Closeable {
/**
* Finds the new-line sequence and return its length.
*
*
* @param data buffer to scan
* @param i start offset in buffer
* @return length of newline sequence or 0 if none found

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,8 +16,6 @@
*/
package com.fr.third.org.apache.commons.io.input;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.DataInput;
import java.io.EOFException;
import java.io.IOException;
@ -25,15 +23,15 @@ import java.io.InputStream;
import com.fr.third.org.apache.commons.io.EndianUtils;
import com.fr.third.org.apache.commons.io.IOUtils;
import com.fr.third.org.apache.commons.io.EndianUtils;
/**
* DataInput for systems relying on little endian data formats.
* When read, values will be changed from little endian to big
* endian formats for internal usage.
* When read, values will be changed from little endian to big
* endian formats for internal usage.
* <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
{
@ -102,12 +96,11 @@ public class SwappedDataInputStream extends ProxyInputStream
}
/**
* Delegates to {@link EndianUtils#readSwappedFloat(InputStream)}.
* Delegates to {@link EndianUtils#readSwappedFloat(InputStream)}.
* @return the read long
* @throws IOException if an I/O error occurs
* @throws EOFException if an end of file is reached unexpectedly
*/
@Override
public float readFloat()
throws IOException, EOFException
{
@ -116,12 +109,11 @@ public class SwappedDataInputStream extends ProxyInputStream
/**
* Invokes the delegate's <code>read(byte[] data, int, int)</code> method.
*
*
* @param data the buffer to read the bytes into
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public void readFully( final byte[] data )
throws IOException, EOFException
{
@ -131,14 +123,13 @@ public class SwappedDataInputStream extends ProxyInputStream
/**
* Invokes the delegate's <code>read(byte[] data, int, int)</code> method.
*
*
* @param data the buffer to read the bytes into
* @param offset The start offset
* @param length The number of bytes to read
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public void readFully( final byte[] data, final int offset, final int length )
throws IOException, EOFException
{
@ -159,12 +150,11 @@ public class SwappedDataInputStream extends ProxyInputStream
}
/**
* Delegates to {@link EndianUtils#readSwappedInteger(InputStream)}.
* Delegates to {@link EndianUtils#readSwappedInteger(InputStream)}.
* @return the read long
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public int readInt()
throws IOException, EOFException
{
@ -177,21 +167,19 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public String readLine()
throws IOException, EOFException
{
throw new UnsupportedOperationException(
throw new UnsupportedOperationException(
"Operation not supported: readLine()" );
}
/**
* Delegates to {@link EndianUtils#readSwappedLong(InputStream)}.
* Delegates to {@link EndianUtils#readSwappedLong(InputStream)}.
* @return the read long
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public long readLong()
throws IOException, EOFException
{
@ -199,12 +187,11 @@ public class SwappedDataInputStream extends ProxyInputStream
}
/**
* Delegates to {@link EndianUtils#readSwappedShort(InputStream)}.
* Delegates to {@link EndianUtils#readSwappedShort(InputStream)}.
* @return the read long
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public short readShort()
throws IOException, EOFException
{
@ -217,7 +204,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public int readUnsignedByte()
throws IOException, EOFException
{
@ -225,12 +211,11 @@ public class SwappedDataInputStream extends ProxyInputStream
}
/**
* Delegates to {@link EndianUtils#readSwappedUnsignedShort(InputStream)}.
* Delegates to {@link EndianUtils#readSwappedUnsignedShort(InputStream)}.
* @return the read long
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public int readUnsignedShort()
throws IOException, EOFException
{
@ -243,11 +228,10 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public String readUTF()
throws IOException, EOFException
{
throw new UnsupportedOperationException(
throw new UnsupportedOperationException(
"Operation not supported: readUTF()" );
}
@ -258,7 +242,6 @@ public class SwappedDataInputStream extends ProxyInputStream
* @throws EOFException if an end of file is reached unexpectedly
* @throws IOException if an I/O error occurs
*/
@Override
public int skipBytes( final int count )
throws IOException, EOFException
{

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -21,7 +21,6 @@ import java.io.InputStream;
import java.io.Serializable;
import java.util.UUID;
import com.fr.third.org.apache.commons.io.TaggedIOException;
import com.fr.third.org.apache.commons.io.TaggedIOException;
/**
@ -105,7 +104,7 @@ public class TaggedInputStream extends ProxyInputStream {
/**
* Tags any IOExceptions thrown, wrapping and re-throwing.
*
*
* @param e The IOException thrown
* @throws IOException if an I/O error occurs
*/

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

@ -16,8 +16,6 @@
*/
package com.fr.third.org.apache.commons.io.input;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
@ -27,11 +25,10 @@ import java.nio.charset.Charset;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.third.org.apache.commons.io.IOUtils;
import com.fr.third.org.apache.commons.io.FileUtils;
/**
* Simple implementation of the unix "tail -f" functionality.
*
*
* <h2>1. Create a TailerListener implementation</h2>
* <p>
* First you need to create a {@link TailerListener} implementation
@ -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()}
*/
@ -263,7 +260,7 @@ public class Tailer implements Runnable {
this.listener = listener;
listener.init(this);
this.reOpen = reOpen;
this.cset = cset;
this.cset = cset;
}
/**
@ -404,7 +401,6 @@ public class Tailer implements Runnable {
/**
* Follows changes in the file, calling the TailerListener's handle method for each new line.
*/
@Override
public void run() {
RandomAccessFile reader = null;
try {
@ -433,22 +429,24 @@ public class Tailer implements Runnable {
if (length < position) {
// File was rotated
listener.fileRotated();
// Reopen the reader after rotation ensuring that the old file is closed iff we re-open it
// successfully
try (RandomAccessFile save = reader) {
// Reopen the reader after rotation
try {
// Ensure that the old file is closed iff we re-open it successfully
final RandomAccessFile save = reader;
reader = new RandomAccessFile(file, RAF_MODE);
// At this point, we're sure that the old file is rotated
// Finish scanning the old file and then we'll start with the new one
try {
readLines(save);
} catch (final IOException ioe) {
} catch (IOException ioe) {
listener.handle(ioe);
}
position = 0;
// close old file explicitly rather than relying on GC picking up previous RAF
IOUtils.closeQuietly(save);
} catch (final FileNotFoundException e) {
// in this case we continue to use the previous reader and position values
listener.fileNotFound();
Thread.sleep(delayMillis);
}
continue;
} else {
@ -471,8 +469,8 @@ public class Tailer implements Runnable {
last = file.lastModified();
}
}
if (reOpen && reader != null) {
reader.close();
if (reOpen) {
IOUtils.closeQuietly(reader);
}
Thread.sleep(delayMillis);
if (getRun() && reOpen) {
@ -482,22 +480,23 @@ public class Tailer implements Runnable {
}
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
listener.handle(e);
stop(e);
} catch (final Exception e) {
listener.handle(e);
stop(e);
} finally {
try {
if (reader != null) {
reader.close();
}
}
catch (final IOException e) {
listener.handle(e);
}
stop();
IOUtils.closeQuietly(reader);
}
}
/**
* Stops the tailer with an exception
* @param e The exception to send to listener
*/
private void stop(final Exception e) {
listener.handle(e);
stop();
}
/**
* Allows the tailer to complete its current loop and return.
*/
@ -513,47 +512,47 @@ public class Tailer implements Runnable {
* @throws java.io.IOException if an I/O error occurs.
*/
private long readLines(final RandomAccessFile reader) throws IOException {
try (ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64)) {
long pos = reader.getFilePointer();
long rePos = pos; // position to re-read
int num;
boolean seenCR = false;
while (getRun() && ((num = reader.read(inbuf)) != IOUtils.EOF)) {
for (int i = 0; i < num; i++) {
final byte ch = inbuf[i];
switch ( ch ) {
case '\n':
seenCR = false; // swallow CR before LF
listener.handle(new String(lineBuf.toByteArray(), cset));
lineBuf.reset();
rePos = pos + i + 1;
break;
case '\r':
if (seenCR) {
lineBuf.write('\r');
}
seenCR = true;
break;
default:
if (seenCR) {
seenCR = false; // swallow final CR
listener.handle(new String(lineBuf.toByteArray(), cset));
lineBuf.reset();
rePos = pos + i + 1;
}
lineBuf.write(ch);
ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64);
long pos = reader.getFilePointer();
long rePos = pos; // position to re-read
int num;
boolean seenCR = false;
while (getRun() && ((num = reader.read(inbuf)) != IOUtils.EOF)) {
for (int i = 0; i < num; i++) {
final byte ch = inbuf[i];
switch (ch) {
case '\n':
seenCR = false; // swallow CR before LF
listener.handle(new String(lineBuf.toByteArray(), cset));
lineBuf.reset();
rePos = pos + i + 1;
break;
case '\r':
if (seenCR) {
lineBuf.write('\r');
}
seenCR = true;
break;
default:
if (seenCR) {
seenCR = false; // swallow final CR
listener.handle(new String(lineBuf.toByteArray(), cset));
lineBuf.reset();
rePos = pos + i + 1;
}
lineBuf.write(ch);
}
pos = reader.getFilePointer();
}
reader.seek(rePos); // Ensure we can re-read if necessary
if (listener instanceof TailerListenerAdapter) {
((TailerListenerAdapter) listener).endOfFileReached();
}
pos = reader.getFilePointer();
}
IOUtils.closeQuietly(lineBuf); // not strictly necessary
reader.seek(rePos); // Ensure we can re-read if necessary
return rePos;
if (listener instanceof TailerListenerAdapter) {
((TailerListenerAdapter) listener).endOfFileReached();
}
return rePos;
}
}

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) {
}

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,8 +18,6 @@ package com.fr.third.org.apache.commons.io.input;
import com.fr.third.org.apache.commons.io.IOUtils;
import static com.fr.third.org.apache.commons.io.IOUtils.EOF;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -35,8 +33,8 @@ import java.io.OutputStream;
* called on this proxy. It is configurable whether the associated output
* stream will also closed.
*
* @version $Id: TeeInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
* @since 1.4
* @see ObservableInputStream
*/
public class TeeInputStream extends ProxyInputStream {
@ -105,7 +103,7 @@ public class TeeInputStream extends ProxyInputStream {
* the associated output stream.
*
* @return next byte from the stream, or -1 if the stream has ended
* @throws IOException if the stream could not be read (or written)
* @throws IOException if the stream could not be read (or written)
*/
@Override
public int read() throws IOException {
@ -124,7 +122,7 @@ public class TeeInputStream extends ProxyInputStream {
* @param st start offset within the buffer
* @param end maximum number of bytes to read
* @return number of bytes read, or -1 if the stream has ended
* @throws IOException if the stream could not be read (or written)
* @throws IOException if the stream could not be read (or written)
*/
@Override
public int read(final byte[] bts, final int st, final int end) throws IOException {
@ -141,7 +139,7 @@ public class TeeInputStream extends ProxyInputStream {
*
* @param bts byte buffer
* @return number of bytes read, or -1 if the stream has ended
* @throws IOException if the stream could not be read (or written)
* @throws IOException if the stream could not be read (or written)
*/
@Override
public int read(final byte[] bts) throws IOException {

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 {

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

@ -21,9 +21,9 @@ import java.io.File;
* A listener that receives events of file system modifications.
* <p>
* Register {@link FileAlterationListener}s with a {@link FileAlterationObserver}.
*
*
* @see FileAlterationObserver
* @version $Id$
* @version $Id: FileAlterationListener.java 1304052 2012-03-22 20:55:29Z ggregory $
* @since 2.0
*/
public interface FileAlterationListener {
@ -37,42 +37,42 @@ public interface FileAlterationListener {
/**
* Directory created Event.
*
*
* @param directory The directory created
*/
void onDirectoryCreate(final File directory);
/**
* Directory changed Event.
*
*
* @param directory The directory changed
*/
void onDirectoryChange(final File directory);
/**
* Directory deleted Event.
*
*
* @param directory The directory deleted
*/
void onDirectoryDelete(final File directory);
/**
* File created Event.
*
*
* @param file The file created
*/
void onFileCreate(final File file);
/**
* File changed Event.
*
*
* @param file The file changed
*/
void onFileChange(final File file);
/**
* File deleted Event.
*
*
* @param file The file deleted
*/
void onFileDelete(final File file);

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

@ -20,9 +20,9 @@ import java.io.File;
/**
* Convenience {@link FileAlterationListener} implementation that does nothing.
*
*
* @see FileAlterationObserver
* @version $Id$
* @version $Id: FileAlterationListenerAdaptor.java 1304062 2012-03-22 21:10:46Z sebb $
* @since 2.0
*/
public class FileAlterationListenerAdaptor implements FileAlterationListener {
@ -32,61 +32,54 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param observer The file system observer (ignored)
*/
@Override
public void onStart(final FileAlterationObserver observer) {
}
/**
* Directory created Event.
*
*
* @param directory The directory created (ignored)
*/
@Override
public void onDirectoryCreate(final File directory) {
}
/**
* Directory changed Event.
*
*
* @param directory The directory changed (ignored)
*/
@Override
public void onDirectoryChange(final File directory) {
}
/**
* Directory deleted Event.
*
*
* @param directory The directory deleted (ignored)
*/
@Override
public void onDirectoryDelete(final File directory) {
}
/**
* File created Event.
*
*
* @param file The file created (ignored)
*/
@Override
public void onFileCreate(final File file) {
}
/**
* File changed Event.
*
*
* @param file The file changed (ignored)
*/
@Override
public void onFileChange(final File file) {
}
/**
* File deleted Event.
*
*
* @param file The file deleted (ignored)
*/
@Override
public void onFileDelete(final File file) {
}
@ -95,7 +88,6 @@ public class FileAlterationListenerAdaptor implements FileAlterationListener {
*
* @param observer The file system observer (ignored)
*/
@Override
public void onStop(final FileAlterationObserver observer) {
}

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

@ -23,15 +23,15 @@ import java.util.concurrent.ThreadFactory;
/**
* A runnable that spawns a monitoring thread triggering any
* registered {@link FileAlterationObserver} at a specified interval.
*
*
* @see FileAlterationObserver
* @version $Id$
* @version $Id: FileAlterationMonitor.java 1415850 2012-11-30 20:51:39Z ggregory $
* @since 2.0
*/
public final class FileAlterationMonitor implements Runnable {
private final long interval;
private final List<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.
*/
@ -112,7 +112,7 @@ public final class FileAlterationMonitor implements Runnable {
/**
* Returns the set of {@link FileAlterationObserver} registered with
* this monitor.
* this monitor.
*
* @return The set of {@link FileAlterationObserver}
*/
@ -176,7 +176,6 @@ public final class FileAlterationMonitor implements Runnable {
/**
* Run.
*/
@Override
public void run() {
while (running) {
for (final FileAlterationObserver observer : observers) {

17
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 = ...
@ -86,7 +83,7 @@ import com.fr.third.org.apache.commons.io.comparator.NameFileComparator;
* noise from <i>unwanted</i> file system events.
* <p>
* <a href="http://commons.apache.org/io/">Commons IO</a> has a good range of
* useful, ready made
* useful, ready made
* <a href="../filefilter/package-summary.html">File Filter</a>
* implementations for this purpose.
* <p>
@ -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++) {

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

@ -29,7 +29,7 @@ import java.io.Serializable;
* <li>Length (see {@link File#length()}) - directories treated as zero</li>
* <li>Children - contents of a directory (see {@link File#listFiles(java.io.FileFilter)})</li>
* </ul>
*
*
* <h3>Custom Implementations</h3>
* <p>
* If the state of additional {@link File} attributes is required then create a custom

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);
}

4
fine-commons-io/src/com/fr/third/org/apache/commons/io/output/BrokenOutputStream.java

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

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

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -46,7 +46,7 @@ public class ChunkedOutputStream extends FilterOutputStream {
* @param chunkSize the chunk size to use; must be a positive number.
* @throws IllegalArgumentException if the chunk size is &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();
@ -56,7 +56,7 @@ public class ChunkedOutputStream extends FilterOutputStream {
/**
* Creates a new stream that uses a chunk size of {@link #DEFAULT_CHUNK_SIZE}.
*
*
* @param stream the stream to wrap
*/
public ChunkedOutputStream(final OutputStream stream) {
@ -73,11 +73,11 @@ public class ChunkedOutputStream extends FilterOutputStream {
* @throws IOException if an I/O error occurs.
*/
@Override
public void write(final byte[] data, final int srcOffset, final int length) throws IOException {
public void write(byte[] data, int srcOffset, int length) throws IOException {
int bytes = length;
int dstOffset = srcOffset;
while(bytes > 0) {
final int chunk = Math.min(bytes, chunkSize);
int chunk = Math.min(bytes, chunkSize);
out.write(data, dstOffset, chunk);
bytes -= chunk;
dstOffset += chunk;

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -46,7 +46,7 @@ public class ChunkedWriter extends FilterWriter {
* @param chunkSize the chunk size to use; must be a positive number.
* @throws IllegalArgumentException if the chunk size is &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;

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

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -25,7 +25,7 @@ import java.io.OutputStream;
* passed to a component that wants to explicitly close the stream even if
* other components would still use the stream for output.
* </p>
* @version $Id$
* @version $Id: CloseShieldOutputStream.java 1674710 2015-04-20 00:25:55Z ggregory $
* @since 1.4
*/
public class CloseShieldOutputStream extends ProxyOutputStream {

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

Loading…
Cancel
Save