+ * Every implementation of the Java platform is required to support this character encoding.
+ *
+ *
+ * @see
+ * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
+ *
+ *
+ * Every implementation of the Java platform is required to support this character encoding.
+ *
+ *
+ * @see
+ * Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
+ * (either order accepted on input, big-endian used on output)
+ *
+ *
+ * Every implementation of the Java platform is required to support this character encoding.
+ *
+ *
+ * @see
+ * Sixteen-bit Unicode Transformation Format, big-endian byte order.
+ *
+ *
+ * Every implementation of the Java platform is required to support this character encoding.
+ *
+ *
+ * @see
+ * Sixteen-bit Unicode Transformation Format, little-endian byte order.
+ *
+ *
+ * Every implementation of the Java platform is required to support this character encoding.
+ *
+ *
+ * @see
+ * Every implementation of the Java platform is required to support this character encoding.
+ *
+ *
+ * @see
+ * Imagine that an InputStream's read() is a very expensive operation, which
+ * would usually suggest wrapping in a BufferedInputStream. The
+ * BufferedInputStream works by issuing infrequent
+ * {@link java.io.InputStream#read(byte[] b, int off, int len)} requests on the
+ * underlying InputStream, to fill an internal buffer, from which further
+ * read requests can inexpensively get their data (until the buffer
+ * runs out).
+ *
+ * Note that only the first two methods shuffle bytes; the rest use these
+ * two, or (if possible) copy using native Java copy methods. As there are
+ * method variants to specify the encoding, each row may
+ * correspond to up to 2 methods.
+ *
+ * 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
+ * throw NullPointerException).
+ */
+@Deprecated
+public class CopyUtils {
+
+ /**
+ * The default size of the buffer.
+ */
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+ /**
+ * Instances should NOT be constructed in standard programming.
+ */
+ public CopyUtils() { }
+
+ // ----------------------------------------------------------------
+ // byte[] -> OutputStream
+ // ----------------------------------------------------------------
+
+ /**
+ * Copy bytes from a byte[] to an OutputStream.
+ * @param input the byte array to read from
+ * @param output the OutputStream to write to
+ * @throws IOException In case of an I/O problem
+ */
+ public static void copy(final byte[] input, final OutputStream output)
+ throws IOException {
+ output.write(input);
+ }
+
+ // ----------------------------------------------------------------
+ // byte[] -> Writer
+ // ----------------------------------------------------------------
+
+ /**
+ * Copy and convert bytes from a byte[] to chars on a
+ * Writer.
+ * The platform's default encoding is used for the byte-to-char conversion.
+ * @param input the byte array to read from
+ * @param output the Writer to write to
+ * @throws IOException In case of an I/O problem
+ * @deprecated 2.5 use {@link #copy(byte[], Writer, String)} instead
+ */
+ @Deprecated
+ public static void copy(final byte[] input, final Writer output)
+ throws IOException {
+ final ByteArrayInputStream in = new ByteArrayInputStream(input);
+ copy(in, output);
+ }
+
+
+ /**
+ * Copy and convert bytes from a byte[] to chars on a
+ * Writer, using the specified encoding.
+ * @param input the byte array to read from
+ * @param output the Writer to write to
+ * @param encoding The name of a supported character encoding. See the
+ * IANA
+ * Charset Registry for a list of valid encoding types.
+ * @throws IOException In case of an I/O problem
+ */
+ public static void copy(
+ final byte[] input,
+ final Writer output,
+ final String encoding)
+ throws IOException {
+ final ByteArrayInputStream in = new ByteArrayInputStream(input);
+ copy(in, output, encoding);
+ }
+
+
+ // ----------------------------------------------------------------
+ // Core copy methods
+ // ----------------------------------------------------------------
+
+ /**
+ * Copy bytes from an InputStream to an
+ * OutputStream.
+ * @param input the InputStream to read from
+ * @param output the OutputStream to write to
+ * @return the number of bytes copied
+ * @throws IOException In case of an I/O problem
+ */
+ public static int copy(
+ final InputStream input,
+ final OutputStream output)
+ throws IOException {
+ final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+ int count = 0;
+ int n = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ // ----------------------------------------------------------------
+ // Reader -> Writer
+ // ----------------------------------------------------------------
+
+ /**
+ * Copy chars from a Reader to a Writer.
+ * @param input the Reader to read from
+ * @param output the Writer to write to
+ * @return the number of characters copied
+ * @throws IOException In case of an I/O problem
+ */
+ public static int copy(
+ final Reader input,
+ final Writer output)
+ throws IOException {
+ final char[] buffer = new char[DEFAULT_BUFFER_SIZE];
+ int count = 0;
+ int n = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ // ----------------------------------------------------------------
+ // InputStream -> Writer
+ // ----------------------------------------------------------------
+
+ /**
+ * Copy and convert bytes from an InputStream to chars on a
+ * Writer.
+ * The platform's default encoding is used for the byte-to-char conversion.
+ * @param input the InputStream to read from
+ * @param output the Writer to write to
+ * @throws IOException In case of an I/O problem
+ * @deprecated 2.5 use {@link #copy(InputStream, Writer, String)} instead
+ */
+ @Deprecated
+ public static void copy(
+ final InputStream input,
+ final Writer output)
+ throws IOException {
+ // make explicit the dependency on the default encoding
+ final InputStreamReader in = new InputStreamReader(input, Charset.defaultCharset());
+ copy(in, output);
+ }
+
+ /**
+ * Copy and convert bytes from an InputStream to chars on a
+ * Writer, using the specified encoding.
+ * @param input the InputStream to read from
+ * @param output the Writer to write to
+ * @param encoding The name of a supported character encoding. See the
+ * IANA
+ * Charset Registry for a list of valid encoding types.
+ * @throws IOException In case of an I/O problem
+ */
+ public static void copy(
+ final InputStream input,
+ final Writer output,
+ final String encoding)
+ throws IOException {
+ final InputStreamReader in = new InputStreamReader(input, encoding);
+ copy(in, output);
+ }
+
+
+ // ----------------------------------------------------------------
+ // Reader -> OutputStream
+ // ----------------------------------------------------------------
+
+ /**
+ * Serialize chars from a Reader to bytes on an
+ * OutputStream, and flush the OutputStream.
+ * Uses the default platform encoding.
+ * @param input the Reader to read from
+ * @param output the OutputStream to write to
+ * @throws IOException In case of an I/O problem
+ * @deprecated 2.5 use {@link #copy(Reader, OutputStream, String)} instead
+ */
+ @Deprecated
+ public static void copy(
+ final Reader input,
+ final OutputStream output)
+ throws IOException {
+ // make explicit the dependency on the default encoding
+ final OutputStreamWriter out = new OutputStreamWriter(output, Charset.defaultCharset());
+ copy(input, out);
+ // XXX Unless anyone is planning on rewriting OutputStreamWriter, we
+ // have to flush here.
+ out.flush();
+ }
+
+ /**
+ * Serialize chars from a Reader to bytes on an
+ * OutputStream, and flush the OutputStream.
+ * @param input the Reader to read from
+ * @param output the OutputStream to write to
+ * @param encoding The name of a supported character encoding. See the
+ * IANA
+ * Charset Registry for a list of valid encoding types.
+ * @throws IOException In case of an I/O problem
+ * @since 2.5
+ */
+ public static void copy(
+ final Reader input,
+ final OutputStream output,
+ final String encoding)
+ throws IOException {
+ final OutputStreamWriter out = new OutputStreamWriter(output, encoding);
+ copy(input, out);
+ // XXX Unless anyone is planning on rewriting OutputStreamWriter, we
+ // have to flush here.
+ out.flush();
+ }
+
+ // ----------------------------------------------------------------
+ // String -> OutputStream
+ // ----------------------------------------------------------------
+
+ /**
+ * Serialize chars from a String to bytes on an
+ * OutputStream, and
+ * flush the OutputStream.
+ * Uses the platform default encoding.
+ * @param input the String to read from
+ * @param output the OutputStream to write to
+ * @throws IOException In case of an I/O problem
+ * @deprecated 2.5 use {@link #copy(String, OutputStream, String)} instead
+ */
+ @Deprecated
+ public static void copy(
+ final String input,
+ final OutputStream output)
+ throws IOException {
+ final StringReader in = new StringReader(input);
+ // make explicit the dependency on the default encoding
+ final OutputStreamWriter out = new OutputStreamWriter(output, Charset.defaultCharset());
+ copy(in, out);
+ // XXX Unless anyone is planning on rewriting OutputStreamWriter, we
+ // have to flush here.
+ out.flush();
+ }
+
+ /**
+ * Serialize chars from a String to bytes on an
+ * OutputStream, and
+ * flush the OutputStream.
+ * @param input the String to read from
+ * @param output the OutputStream to write to
+ * @param encoding The name of a supported character encoding. See the
+ * IANA
+ * Charset Registry for a list of valid encoding types.
+ * @throws IOException In case of an I/O problem
+ * @since 2.5
+ */
+ public static void copy(
+ final String input,
+ final OutputStream output,
+ final String encoding)
+ throws IOException {
+ final StringReader in = new StringReader(input);
+ final OutputStreamWriter out = new OutputStreamWriter(output, encoding);
+ copy(in, out);
+ // XXX Unless anyone is planning on rewriting OutputStreamWriter, we
+ // have to flush here.
+ out.flush();
+ }
+
+ // ----------------------------------------------------------------
+ // String -> Writer
+ // ----------------------------------------------------------------
+
+ /**
+ * Copy chars from a String to a Writer.
+ * @param input the String to read from
+ * @param output the Writer to write to
+ * @throws IOException In case of an I/O problem
+ */
+ public static void copy(final String input, final Writer output)
+ throws IOException {
+ output.write(input);
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/DirectoryWalker.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/DirectoryWalker.java"
new file mode 100644
index 0000000000000000000000000000000000000000..356e0b3b1f2fd62e74d5861086cec14d80b8c02a
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/DirectoryWalker.java"
@@ -0,0 +1,642 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+
+/**
+ * Abstract class that walks through a directory hierarchy and provides
+ * subclasses with convenient hooks to add specific behaviour.
+ *
+ * This class operates with a {@link FileFilter} and maximum depth to
+ * limit the files and direcories visited.
+ * Commons IO supplies many common filter implementations in the
+ * filefilter package.
+ *
+ * The first option is to visit all directories and files.
+ * This is achieved via the no-args constructor.
+ *
+ * The second constructor option is to supply a single {@link FileFilter}
+ * that describes the files and directories to visit. Care must be taken
+ * with this option as the same filter is used for both directories
+ * and files.
+ *
+ * For example, if you wanted all directories which are not hidden
+ * and files which end in ".txt":
+ *
+ * The third constructor option is to specify separate filters, one for
+ * directories and one for files. These are combined internally to form
+ * the correct FileFilter, something which is very easy to
+ * get wrong when attempted manually, particularly when trying to
+ * express constructs like 'any file in directories named docs'.
+ *
+ * For example, if you wanted all directories which are not hidden
+ * and files which end in ".txt":
+ *
+ * The following sections provide example implementations for these two different
+ * scenarios.
+ *
+ *
+ *
{
+
+ /**
+ * The file filter to use to filter files and directories.
+ */
+ private final FileFilter filter;
+ /**
+ * The limit on the directory depth to walk.
+ */
+ private final int depthLimit;
+
+ /**
+ * Construct an instance with no filtering and unlimited depth .
+ */
+ protected DirectoryWalker() {
+ this(null, -1);
+ }
+
+ /**
+ * Construct an instance with a filter and limit the depth navigated to.
+ *
+ * The filter controls which files and directories will be navigated to as
+ * part of the walk. The {@link FileFilterUtils} class is useful for combining
+ * various filters together. A {@code null} filter means that no
+ * filtering should occur and all files and directories will be visited.
+ *
+ * @param filter the filter to apply, null means visit all files
+ * @param depthLimit controls how deep the hierarchy is
+ * navigated to (less than 0 means unlimited)
+ */
+ protected DirectoryWalker(final FileFilter filter, final int depthLimit) {
+ this.filter = filter;
+ this.depthLimit = depthLimit;
+ }
+
+ /**
+ * Construct an instance with a directory and a file filter and an optional
+ * limit on the depth navigated to.
+ *
+ * The filters control which files and directories will be navigated to as part
+ * of the walk. This constructor uses {@link FileFilterUtils#makeDirectoryOnly(IOFileFilter)}
+ * and {@link FileFilterUtils#makeFileOnly(IOFileFilter)} internally to combine the filters.
+ * A {@code null} filter means that no filtering should occur.
+ *
+ * @param directoryFilter the filter to apply to directories, null means visit all directories
+ * @param fileFilter the filter to apply to files, null means visit all files
+ * @param depthLimit controls how deep the hierarchy is
+ * navigated to (less than 0 means unlimited)
+ */
+ protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter, final int depthLimit) {
+ if (directoryFilter == null && fileFilter == null) {
+ this.filter = null;
+ } else {
+ directoryFilter = directoryFilter != null ? directoryFilter : TrueFileFilter.TRUE;
+ fileFilter = fileFilter != null ? fileFilter : TrueFileFilter.TRUE;
+ directoryFilter = FileFilterUtils.makeDirectoryOnly(directoryFilter);
+ fileFilter = FileFilterUtils.makeFileOnly(fileFilter);
+ this.filter = FileFilterUtils.or(directoryFilter, fileFilter);
+ }
+ this.depthLimit = depthLimit;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Internal method that walks the directory hierarchy in a depth-first manner.
+ *
+ * Users of this class do not need to call this method. This method will
+ * be called automatically by another (public) method on the specific subclass.
+ *
+ * Writers of subclasses should call this method to start the directory walk.
+ * Once called, this method will emit events as it walks the hierarchy.
+ * The event methods have the prefix handle.
+ *
+ * @param startDirectory the directory to start from, not null
+ * @param results the collection of result objects, may be updated
+ * @throws NullPointerException if the start directory is null
+ * @throws IOException if an I/O Error occurs
+ */
+ protected final void walk(final File startDirectory, final Collection results) throws IOException {
+ if (startDirectory == null) {
+ throw new NullPointerException("Start Directory is null");
+ }
+ try {
+ handleStart(startDirectory, results);
+ walk(startDirectory, 0, results);
+ handleEnd(results);
+ } catch(final CancelException cancel) {
+ handleCancelled(startDirectory, results, cancel);
+ }
+ }
+
+ /**
+ * Main recursive method to examine the directory hierarchy.
+ *
+ * @param directory the directory to examine, not null
+ * @param depth the directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ * @throws IOException if an I/O Error occurs
+ */
+ private void walk(final File directory, final int depth, final Collection results) throws IOException {
+ checkIfCancelled(directory, depth, results);
+ if (handleDirectory(directory, depth, results)) {
+ handleDirectoryStart(directory, depth, results);
+ final int childDepth = depth + 1;
+ if (depthLimit < 0 || childDepth <= depthLimit) {
+ checkIfCancelled(directory, depth, results);
+ File[] childFiles = filter == null ? directory.listFiles() : directory.listFiles(filter);
+ childFiles = filterDirectoryContents(directory, depth, childFiles);
+ if (childFiles == null) {
+ handleRestricted(directory, childDepth, results);
+ } else {
+ for (final File childFile : childFiles) {
+ if (childFile.isDirectory()) {
+ walk(childFile, childDepth, results);
+ } else {
+ checkIfCancelled(childFile, childDepth, results);
+ handleFile(childFile, childDepth, results);
+ checkIfCancelled(childFile, childDepth, results);
+ }
+ }
+ }
+ }
+ handleDirectoryEnd(directory, depth, results);
+ }
+ checkIfCancelled(directory, depth, results);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks whether the walk has been cancelled by calling {@link #handleIsCancelled},
+ * throwing a CancelException if it has.
+ *
+ * Writers of subclasses should not normally call this method as it is called
+ * automatically by the walk of the tree. However, sometimes a single method,
+ * typically {@link #handleFile}, may take a long time to run. In that case,
+ * you may wish to check for cancellation by calling this method.
+ *
+ * @param file the current file being processed
+ * @param depth the current file level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ * @throws IOException if an I/O Error occurs
+ */
+ protected final void checkIfCancelled(final File file, final int depth, final Collection results) throws
+ IOException {
+ if (handleIsCancelled(file, depth, results)) {
+ throw new CancelException(file, depth);
+ }
+ }
+
+ /**
+ * Overridable callback method invoked to determine if the entire walk
+ * operation should be immediately cancelled.
+ *
+ * This method should be implemented by those subclasses that want to
+ * provide a public cancel() method available from another
+ * thread. The design pattern for the subclass should be as follows:
+ *
+ * public class FooDirectoryWalker extends DirectoryWalker {
+ * private volatile boolean cancelled = false;
+ *
+ * public void cancel() {
+ * cancelled = true;
+ * }
+ * private void handleIsCancelled(File file, int depth, Collection results) {
+ * return cancelled;
+ * }
+ * protected void handleCancelled(File startDirectory,
+ * Collection results, CancelException cancel) {
+ * // implement processing required when a cancellation occurs
+ * }
+ * }
+ *
+ *
+ * If this method returns true, then the directory walk is immediately
+ * cancelled. The next callback method will be {@link #handleCancelled}.
+ *
+ * This implementation returns false.
+ *
+ * @param file the file or directory being processed
+ * @param depth the current directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ * @return true if the walk has been cancelled
+ * @throws IOException if an I/O Error occurs
+ */
+ protected boolean handleIsCancelled(
+ final File file, final int depth, final Collection results) throws IOException {
+ // do nothing - overridable by subclass
+ return false; // not cancelled
+ }
+
+ /**
+ * Overridable callback method invoked when the operation is cancelled.
+ * The file being processed when the cancellation occurred can be
+ * obtained from the exception.
+ *
+ * This implementation just re-throws the {@link CancelException}.
+ *
+ * @param startDirectory the directory that the walk started from
+ * @param results the collection of result objects, may be updated
+ * @param cancel the exception throw to cancel further processing
+ * containing details at the point of cancellation.
+ * @throws IOException if an I/O Error occurs
+ */
+ protected void handleCancelled(final File startDirectory, final Collection results,
+ final CancelException cancel) throws IOException {
+ // re-throw exception - overridable by subclass
+ throw cancel;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Overridable callback method invoked at the start of processing.
+ *
+ * This implementation does nothing.
+ *
+ * @param startDirectory the directory to start from
+ * @param results the collection of result objects, may be updated
+ * @throws IOException if an I/O Error occurs
+ */
+ protected void handleStart(final File startDirectory, final Collection results) throws IOException {
+ // do nothing - overridable by subclass
+ }
+
+ /**
+ * Overridable callback method invoked to determine if a directory should be processed.
+ *
+ * This method returns a boolean to indicate if the directory should be examined or not.
+ * If you return false, the entire directory and any subdirectories will be skipped.
+ * Note that this functionality is in addition to the filtering by file filter.
+ *
+ * This implementation does nothing and returns true.
+ *
+ * @param directory the current directory being processed
+ * @param depth the current directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ * @return true to process this directory, false to skip this directory
+ * @throws IOException if an I/O Error occurs
+ */
+ protected boolean handleDirectory(final File directory, final int depth, final Collection results) throws
+ IOException {
+ // do nothing - overridable by subclass
+ return true; // process directory
+ }
+
+ /**
+ * Overridable callback method invoked at the start of processing each directory.
+ *
+ * This implementation does nothing.
+ *
+ * @param directory the current directory being processed
+ * @param depth the current directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ * @throws IOException if an I/O Error occurs
+ */
+ protected void handleDirectoryStart(final File directory, final int depth, final Collection results) throws
+ IOException {
+ // do nothing - overridable by subclass
+ }
+
+ /**
+ * Overridable callback method invoked with the contents of each directory.
+ *
+ * This implementation returns the files unchanged
+ *
+ * @param directory the current directory being processed
+ * @param depth the current directory level (starting directory = 0)
+ * @param files the files (possibly filtered) in the directory, may be {@code null}
+ * @return the filtered list of files
+ * @throws IOException if an I/O Error occurs
+ * @since 2.0
+ */
+ protected File[] filterDirectoryContents(final File directory, final int depth, final File[] files) throws
+ IOException {
+ return files;
+ }
+
+ /**
+ * Overridable callback method invoked for each (non-directory) file.
+ *
+ * This implementation does nothing.
+ *
+ * @param file the current file being processed
+ * @param depth the current directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ * @throws IOException if an I/O Error occurs
+ */
+ protected void handleFile(final File file, final int depth, final Collection results) throws IOException {
+ // do nothing - overridable by subclass
+ }
+
+ /**
+ * Overridable callback method invoked for each restricted directory.
+ *
+ * This implementation does nothing.
+ *
+ * @param directory the restricted directory
+ * @param depth the current directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ * @throws IOException if an I/O Error occurs
+ */
+ protected void handleRestricted(final File directory, final int depth, final Collection results) throws
+ IOException {
+ // do nothing - overridable by subclass
+ }
+
+ /**
+ * Overridable callback method invoked at the end of processing each directory.
+ *
+ * This implementation does nothing.
+ *
+ * @param directory the directory being processed
+ * @param depth the current directory level (starting directory = 0)
+ * @param results the collection of result objects, may be updated
+ * @throws IOException if an I/O Error occurs
+ */
+ protected void handleDirectoryEnd(final File directory, final int depth, final Collection results) throws
+ IOException {
+ // do nothing - overridable by subclass
+ }
+
+ /**
+ * Overridable callback method invoked at the end of processing.
+ *
+ * This implementation does nothing.
+ *
+ * @param results the collection of result objects, may be updated
+ * @throws IOException if an I/O Error occurs
+ */
+ protected void handleEnd(final Collection results) throws IOException {
+ // do nothing - overridable by subclass
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * CancelException is thrown in DirectoryWalker to cancel the current
+ * processing.
+ */
+ public static class CancelException extends IOException {
+
+ /** Serialization id. */
+ private static final long serialVersionUID = 1347339620135041008L;
+
+ /** The file being processed when the exception was thrown. */
+ private final File file;
+ /** The file depth when the exception was thrown. */
+ private final int depth;
+
+ /**
+ * Constructs a CancelException with
+ * the file and depth when cancellation occurred.
+ *
+ * @param file the file when the operation was cancelled, may be null
+ * @param depth the depth when the operation was cancelled, may be null
+ */
+ public CancelException(final File file, final int depth) {
+ this("Operation Cancelled", file, depth);
+ }
+
+ /**
+ * Constructs a CancelException with
+ * an appropriate message and the file and depth when
+ * cancellation occurred.
+ *
+ * @param message the detail message
+ * @param file the file when the operation was cancelled
+ * @param depth the depth when the operation was cancelled
+ */
+ public CancelException(final String message, final File file, final int depth) {
+ super(message);
+ this.file = file;
+ this.depth = depth;
+ }
+
+ /**
+ * Return the file when the operation was cancelled.
+ *
+ * @return the file when the operation was cancelled
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * Return the depth when the operation was cancelled.
+ *
+ * @return the depth when the operation was cancelled
+ */
+ public int getDepth() {
+ return depth;
+ }
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/EndianUtils.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/EndianUtils.java"
new file mode 100644
index 0000000000000000000000000000000000000000..dba2d9bf3256695ea423de2d9f883806e030a2da
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/EndianUtils.java"
@@ -0,0 +1,482 @@
+/*
+ * 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 org.apache.commons.io;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Utility code for dealing with different endian systems.
+ *
+ * Different computer architectures adopt different conventions for
+ * byte ordering. In so-called "Little Endian" architectures (eg Intel),
+ * the low-order byte is stored in memory at the lowest address, and
+ * subsequent bytes at higher addresses. For "Big Endian" architectures
+ * (eg Motorola), the situation is reversed.
+ * This class helps you solve this incompatibility.
+ *
+ * Origin of code: Excalibur
+ *
+ * @version $Id: EndianUtils.java 1686450 2015-06-19 16:43:48Z krosenvold $
+ * @see org.apache.commons.io.input.SwappedDataInputStream
+ */
+public class EndianUtils {
+
+ /**
+ * Instances should NOT be constructed in standard programming.
+ */
+ public EndianUtils() {
+ super();
+ }
+
+ // ========================================== Swapping routines
+
+ /**
+ * Converts a "short" value between endian systems.
+ * @param value value to convert
+ * @return the converted value
+ */
+ public static short swapShort(final short value) {
+ return (short) ( ( ( ( value >> 0 ) & 0xff ) << 8 ) +
+ ( ( ( value >> 8 ) & 0xff ) << 0 ) );
+ }
+
+ /**
+ * Converts a "int" value between endian systems.
+ * @param value value to convert
+ * @return the converted value
+ */
+ public static int swapInteger(final int value) {
+ return
+ ( ( ( value >> 0 ) & 0xff ) << 24 ) +
+ ( ( ( value >> 8 ) & 0xff ) << 16 ) +
+ ( ( ( value >> 16 ) & 0xff ) << 8 ) +
+ ( ( ( value >> 24 ) & 0xff ) << 0 );
+ }
+
+ /**
+ * Converts a "long" value between endian systems.
+ * @param value value to convert
+ * @return the converted value
+ */
+ public static long swapLong(final long value) {
+ return
+ ( ( ( value >> 0 ) & 0xff ) << 56 ) +
+ ( ( ( value >> 8 ) & 0xff ) << 48 ) +
+ ( ( ( value >> 16 ) & 0xff ) << 40 ) +
+ ( ( ( value >> 24 ) & 0xff ) << 32 ) +
+ ( ( ( value >> 32 ) & 0xff ) << 24 ) +
+ ( ( ( value >> 40 ) & 0xff ) << 16 ) +
+ ( ( ( value >> 48 ) & 0xff ) << 8 ) +
+ ( ( ( value >> 56 ) & 0xff ) << 0 );
+ }
+
+ /**
+ * Converts a "float" value between endian systems.
+ * @param value value to convert
+ * @return the converted value
+ */
+ public static float swapFloat(final float value) {
+ return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) );
+ }
+
+ /**
+ * Converts a "double" value between endian systems.
+ * @param value value to convert
+ * @return the converted value
+ */
+ public static double swapDouble(final double value) {
+ return Double.longBitsToDouble( swapLong( Double.doubleToLongBits( value ) ) );
+ }
+
+ // ========================================== Swapping read/write routines
+
+ /**
+ * Writes a "short" value to a byte array at a given offset. The value is
+ * converted to the opposed endian system while writing.
+ * @param data target byte array
+ * @param offset starting offset in the byte array
+ * @param value value to write
+ */
+ public static void writeSwappedShort(final byte[] data, final int offset, final short value) {
+ data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
+ data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
+ }
+
+ /**
+ * Reads a "short" value from a byte array at a given offset. The value is
+ * converted to the opposed endian system while reading.
+ * @param data source byte array
+ * @param offset starting offset in the byte array
+ * @return the value read
+ */
+ public static short readSwappedShort(final byte[] data, final int offset) {
+ return (short)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
+ ( ( data[ offset + 1 ] & 0xff ) << 8 ) );
+ }
+
+ /**
+ * Reads an unsigned short (16-bit) value from a byte array at a given
+ * offset. The value is converted to the opposed endian system while
+ * reading.
+ * @param data source byte array
+ * @param offset starting offset in the byte array
+ * @return the value read
+ */
+ public static int readSwappedUnsignedShort(final byte[] data, final int offset) {
+ return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
+ ( ( data[ offset + 1 ] & 0xff ) << 8 ) );
+ }
+
+ /**
+ * Writes a "int" value to a byte array at a given offset. The value is
+ * converted to the opposed endian system while writing.
+ * @param data target byte array
+ * @param offset starting offset in the byte array
+ * @param value value to write
+ */
+ public static void writeSwappedInteger(final byte[] data, final int offset, final int value) {
+ data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
+ data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
+ data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff );
+ data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff );
+ }
+
+ /**
+ * Reads a "int" value from a byte array at a given offset. The value is
+ * converted to the opposed endian system while reading.
+ * @param data source byte array
+ * @param offset starting offset in the byte array
+ * @return the value read
+ */
+ public static int readSwappedInteger(final byte[] data, final int offset) {
+ return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
+ ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
+ ( ( data[ offset + 2 ] & 0xff ) << 16 ) +
+ ( ( data[ offset + 3 ] & 0xff ) << 24 ) );
+ }
+
+ /**
+ * Reads an unsigned integer (32-bit) value from a byte array at a given
+ * offset. The value is converted to the opposed endian system while
+ * reading.
+ * @param data source byte array
+ * @param offset starting offset in the byte array
+ * @return the value read
+ */
+ public static long readSwappedUnsignedInteger(final byte[] data, final int offset) {
+ final long low = ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
+ ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
+ ( ( data[ offset + 2 ] & 0xff ) << 16 ) );
+
+ final long high = data[ offset + 3 ] & 0xff;
+
+ return (high << 24) + (0xffffffffL & low);
+ }
+
+ /**
+ * Writes a "long" value to a byte array at a given offset. The value is
+ * converted to the opposed endian system while writing.
+ * @param data target byte array
+ * @param offset starting offset in the byte array
+ * @param value value to write
+ */
+ public static void writeSwappedLong(final byte[] data, final int offset, final long value) {
+ data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
+ data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
+ data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff );
+ data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff );
+ data[ offset + 4 ] = (byte)( ( value >> 32 ) & 0xff );
+ data[ offset + 5 ] = (byte)( ( value >> 40 ) & 0xff );
+ data[ offset + 6 ] = (byte)( ( value >> 48 ) & 0xff );
+ data[ offset + 7 ] = (byte)( ( value >> 56 ) & 0xff );
+ }
+
+ /**
+ * Reads a "long" value from a byte array at a given offset. The value is
+ * converted to the opposed endian system while reading.
+ * @param data source byte array
+ * @param offset starting offset in the byte array
+ * @return the value read
+ */
+ public static long readSwappedLong(final byte[] data, final int offset) {
+ final long low = readSwappedInteger(data, offset);
+ final long high = readSwappedInteger(data, offset + 4);
+ return (high << 32) + (0xffffffffL & low);
+ }
+
+ /**
+ * Writes a "float" value to a byte array at a given offset. The value is
+ * converted to the opposed endian system while writing.
+ * @param data target byte array
+ * @param offset starting offset in the byte array
+ * @param value value to write
+ */
+ public static void writeSwappedFloat(final byte[] data, final int offset, final float value) {
+ writeSwappedInteger( data, offset, Float.floatToIntBits( value ) );
+ }
+
+ /**
+ * Reads a "float" value from a byte array at a given offset. The value is
+ * converted to the opposed endian system while reading.
+ * @param data source byte array
+ * @param offset starting offset in the byte array
+ * @return the value read
+ */
+ public static float readSwappedFloat(final byte[] data, final int offset) {
+ return Float.intBitsToFloat( readSwappedInteger( data, offset ) );
+ }
+
+ /**
+ * Writes a "double" value to a byte array at a given offset. The value is
+ * converted to the opposed endian system while writing.
+ * @param data target byte array
+ * @param offset starting offset in the byte array
+ * @param value value to write
+ */
+ public static void writeSwappedDouble(final byte[] data, final int offset, final double value) {
+ writeSwappedLong( data, offset, Double.doubleToLongBits( value ) );
+ }
+
+ /**
+ * Reads a "double" value from a byte array at a given offset. The value is
+ * converted to the opposed endian system while reading.
+ * @param data source byte array
+ * @param offset starting offset in the byte array
+ * @return the value read
+ */
+ public static double readSwappedDouble(final byte[] data, final int offset) {
+ return Double.longBitsToDouble( readSwappedLong( data, offset ) );
+ }
+
+ /**
+ * Writes a "short" value to an OutputStream. The value is
+ * converted to the opposed endian system while writing.
+ * @param output target OutputStream
+ * @param value value to write
+ * @throws IOException in case of an I/O problem
+ */
+ public static void writeSwappedShort(final OutputStream output, final short value)
+ throws IOException
+ {
+ output.write( (byte)( ( value >> 0 ) & 0xff ) );
+ output.write( (byte)( ( value >> 8 ) & 0xff ) );
+ }
+
+ /**
+ * Reads a "short" value from an InputStream. The value is
+ * converted to the opposed endian system while reading.
+ * @param input source InputStream
+ * @return the value just read
+ * @throws IOException in case of an I/O problem
+ */
+ public static short readSwappedShort(final InputStream input)
+ throws IOException
+ {
+ return (short)( ( ( read( input ) & 0xff ) << 0 ) +
+ ( ( read( input ) & 0xff ) << 8 ) );
+ }
+
+ /**
+ * Reads a unsigned short (16-bit) from an InputStream. The value is
+ * converted to the opposed endian system while reading.
+ * @param input source InputStream
+ * @return the value just read
+ * @throws IOException in case of an I/O problem
+ */
+ public static int readSwappedUnsignedShort(final InputStream input)
+ throws IOException
+ {
+ final int value1 = read( input );
+ final int value2 = read( input );
+
+ return ( ( ( value1 & 0xff ) << 0 ) +
+ ( ( value2 & 0xff ) << 8 ) );
+ }
+
+ /**
+ * Writes a "int" value to an OutputStream. The value is
+ * converted to the opposed endian system while writing.
+ * @param output target OutputStream
+ * @param value value to write
+ * @throws IOException in case of an I/O problem
+ */
+ public static void writeSwappedInteger(final OutputStream output, final int value)
+ throws IOException
+ {
+ output.write( (byte)( ( value >> 0 ) & 0xff ) );
+ output.write( (byte)( ( value >> 8 ) & 0xff ) );
+ output.write( (byte)( ( value >> 16 ) & 0xff ) );
+ output.write( (byte)( ( value >> 24 ) & 0xff ) );
+ }
+
+ /**
+ * Reads a "int" value from an InputStream. The value is
+ * converted to the opposed endian system while reading.
+ * @param input source InputStream
+ * @return the value just read
+ * @throws IOException in case of an I/O problem
+ */
+ public static int readSwappedInteger(final InputStream input)
+ throws IOException
+ {
+ final int value1 = read( input );
+ final int value2 = read( input );
+ final int value3 = read( input );
+ final int value4 = read( input );
+
+ return ( ( value1 & 0xff ) << 0 ) +
+ ( ( value2 & 0xff ) << 8 ) +
+ ( ( value3 & 0xff ) << 16 ) +
+ ( ( value4 & 0xff ) << 24 );
+ }
+
+ /**
+ * Reads a unsigned integer (32-bit) from an InputStream. The value is
+ * converted to the opposed endian system while reading.
+ * @param input source InputStream
+ * @return the value just read
+ * @throws IOException in case of an I/O problem
+ */
+ public static long readSwappedUnsignedInteger(final InputStream input)
+ throws IOException
+ {
+ final int value1 = read( input );
+ final int value2 = read( input );
+ final int value3 = read( input );
+ final int value4 = read( input );
+
+ final long low = ( ( ( value1 & 0xff ) << 0 ) +
+ ( ( value2 & 0xff ) << 8 ) +
+ ( ( value3 & 0xff ) << 16 ) );
+
+ final long high = value4 & 0xff;
+
+ return (high << 24) + (0xffffffffL & low);
+ }
+
+ /**
+ * Writes a "long" value to an OutputStream. The value is
+ * converted to the opposed endian system while writing.
+ * @param output target OutputStream
+ * @param value value to write
+ * @throws IOException in case of an I/O problem
+ */
+ public static void writeSwappedLong(final OutputStream output, final long value)
+ throws IOException
+ {
+ output.write( (byte)( ( value >> 0 ) & 0xff ) );
+ output.write( (byte)( ( value >> 8 ) & 0xff ) );
+ output.write( (byte)( ( value >> 16 ) & 0xff ) );
+ output.write( (byte)( ( value >> 24 ) & 0xff ) );
+ output.write( (byte)( ( value >> 32 ) & 0xff ) );
+ output.write( (byte)( ( value >> 40 ) & 0xff ) );
+ output.write( (byte)( ( value >> 48 ) & 0xff ) );
+ output.write( (byte)( ( value >> 56 ) & 0xff ) );
+ }
+
+ /**
+ * Reads a "long" value from an InputStream. The value is
+ * converted to the opposed endian system while reading.
+ * @param input source InputStream
+ * @return the value just read
+ * @throws IOException in case of an I/O problem
+ */
+ public static long readSwappedLong(final InputStream input)
+ throws IOException
+ {
+ final byte[] bytes = new byte[8];
+ for ( int i=0; i<8; i++ ) {
+ bytes[i] = (byte) read( input );
+ }
+ return readSwappedLong( bytes, 0 );
+ }
+
+ /**
+ * Writes a "float" value to an OutputStream. The value is
+ * converted to the opposed endian system while writing.
+ * @param output target OutputStream
+ * @param value value to write
+ * @throws IOException in case of an I/O problem
+ */
+ public static void writeSwappedFloat(final OutputStream output, final float value)
+ throws IOException
+ {
+ writeSwappedInteger( output, Float.floatToIntBits( value ) );
+ }
+
+ /**
+ * Reads a "float" value from an InputStream. The value is
+ * converted to the opposed endian system while reading.
+ * @param input source InputStream
+ * @return the value just read
+ * @throws IOException in case of an I/O problem
+ */
+ public static float readSwappedFloat(final InputStream input)
+ throws IOException
+ {
+ return Float.intBitsToFloat( readSwappedInteger( input ) );
+ }
+
+ /**
+ * Writes a "double" value to an OutputStream. The value is
+ * converted to the opposed endian system while writing.
+ * @param output target OutputStream
+ * @param value value to write
+ * @throws IOException in case of an I/O problem
+ */
+ public static void writeSwappedDouble(final OutputStream output, final double value)
+ throws IOException
+ {
+ writeSwappedLong( output, Double.doubleToLongBits( value ) );
+ }
+
+ /**
+ * Reads a "double" value from an InputStream. The value is
+ * converted to the opposed endian system while reading.
+ * @param input source InputStream
+ * @return the value just read
+ * @throws IOException in case of an I/O problem
+ */
+ public static double readSwappedDouble(final InputStream input)
+ throws IOException
+ {
+ return Double.longBitsToDouble( readSwappedLong( input ) );
+ }
+
+ /**
+ * Reads the next byte from the input stream.
+ * @param input the stream
+ * @return the byte
+ * @throws IOException if the end of file is reached
+ */
+ private static int read(final InputStream input)
+ throws IOException
+ {
+ final int value = input.read();
+
+ if( EOF == value ) {
+ throw new EOFException( "Unexpected EOF reached" );
+ }
+
+ return value;
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaner.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaner.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d214e3400ab80baeb2fbb558912b84db4a5451a1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaner.java"
@@ -0,0 +1,160 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.File;
+
+/**
+ * Keeps track of files awaiting deletion, and deletes them when an associated
+ * marker object is reclaimed by the garbage collector.
+ *
+ * This utility creates a background thread to handle file deletion.
+ * Each file to be deleted is registered with a handler object.
+ * When the handler object is garbage collected, the file is deleted.
+ *
+ * In an environment with multiple class loaders (a servlet container, for
+ * example), you should consider stopping the background thread if it is no
+ * longer needed. This is done by invoking the method
+ * {@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
+public class FileCleaner {
+ /**
+ * The instance to use for the deprecated, static methods.
+ */
+ static final FileCleaningTracker theInstance = new FileCleaningTracker();
+
+ //-----------------------------------------------------------------------
+ /**
+ * Track the specified file, using the provided marker, deleting the file
+ * when the marker instance is garbage collected.
+ * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
+ *
+ * @param file the file to be tracked, not null
+ * @param marker the marker object used to track the file, not null
+ * @throws NullPointerException if the file is null
+ * @deprecated Use {@link FileCleaningTracker#track(File, Object)}.
+ */
+ @Deprecated
+ public static void track(final File file, final Object marker) {
+ theInstance.track(file, marker);
+ }
+
+ /**
+ * Track the specified file, using the provided marker, deleting the file
+ * when the marker instance is garbage collected.
+ * 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
+ * @param deleteStrategy the strategy to delete the file, null means normal
+ * @throws NullPointerException if the file is null
+ * @deprecated Use {@link FileCleaningTracker#track(File, Object, FileDeleteStrategy)}.
+ */
+ @Deprecated
+ public static void track(final File file, final Object marker, final FileDeleteStrategy deleteStrategy) {
+ theInstance.track(file, marker, deleteStrategy);
+ }
+
+ /**
+ * Track the specified file, using the provided marker, deleting the file
+ * when the marker instance is garbage collected.
+ * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be 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
+ * @throws NullPointerException if the path is null
+ * @deprecated Use {@link FileCleaningTracker#track(String, Object)}.
+ */
+ @Deprecated
+ public static void track(final String path, final Object marker) {
+ theInstance.track(path, marker);
+ }
+
+ /**
+ * Track the specified file, using the provided marker, deleting the file
+ * when the marker instance is garbage collected.
+ * 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
+ * @param deleteStrategy the strategy to delete the file, null means normal
+ * @throws NullPointerException if the path is null
+ * @deprecated Use {@link FileCleaningTracker#track(String, Object, FileDeleteStrategy)}.
+ */
+ @Deprecated
+ public static void track(final String path, final Object marker, final FileDeleteStrategy deleteStrategy) {
+ theInstance.track(path, marker, deleteStrategy);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Retrieve the number of files currently being tracked, and therefore
+ * awaiting deletion.
+ *
+ * @return the number of files being tracked
+ * @deprecated Use {@link FileCleaningTracker#getTrackCount()}.
+ */
+ @Deprecated
+ public static int getTrackCount() {
+ return theInstance.getTrackCount();
+ }
+
+ /**
+ * Call this method to cause the file cleaner thread to terminate when
+ * there are no more objects being tracked for deletion.
+ *
+ * In a simple environment, you don't need this method as the file cleaner
+ * 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 consitute a memory leak.
+ *
+ * For example, suppose that you have developed a web application, which
+ * contains the commons-io jar file in your WEB-INF/lib directory. In other
+ * words, the FileCleaner class is loaded through the class loader of your
+ * web application. If the web application is terminated, but the servlet
+ * container is still running, then the file cleaner thread will still exist,
+ * posing a memory leak.
+ *
+ * This method allows the thread to be terminated. Simply call this method
+ * 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()}.
+ */
+ @Deprecated
+ public static synchronized void exitWhenFinished() {
+ theInstance.exitWhenFinished();
+ }
+
+ /**
+ * Returns the singleton instance, which is used by the deprecated, static methods.
+ * 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() {
+ return theInstance;
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaningTracker.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaningTracker.java"
new file mode 100644
index 0000000000000000000000000000000000000000..cda40e97f5f0276f104e011c1aee3fbd29a3f892
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileCleaningTracker.java"
@@ -0,0 +1,288 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.File;
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+
+/**
+ * Keeps track of files awaiting deletion, and deletes them when an associated
+ * marker object is reclaimed by the garbage collector.
+ *
+ * This utility creates a background thread to handle file deletion.
+ * Each file to be deleted is registered with a handler object.
+ * When the handler object is garbage collected, the file is deleted.
+ *
+ * In an environment with multiple class loaders (a servlet container, for
+ * example), you should consider stopping the background thread if it is no
+ * longer needed. This is done by invoking the method
+ * {@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 {
+
+ // Note: fields are package protected to allow use by test cases
+
+ /**
+ * Queue of Tracker instances being watched.
+ */
+ ReferenceQueue q = new ReferenceQueue();
+ /**
+ * Collection of Tracker instances in existence.
+ */
+ final Collection trackers = Collections.synchronizedSet(new HashSet()); // synchronized
+ /**
+ * Collection of File paths that failed to delete.
+ */
+ final List deleteFailures = Collections.synchronizedList(new ArrayList());
+ /**
+ * Whether to terminate the thread when the tracking is complete.
+ */
+ volatile boolean exitWhenFinished = false;
+ /**
+ * The thread that will clean up registered files.
+ */
+ Thread reaper;
+
+ //-----------------------------------------------------------------------
+ /**
+ * Track the specified file, using the provided marker, deleting the file
+ * when the marker instance is garbage collected.
+ * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
+ *
+ * @param file the file to be tracked, not null
+ * @param marker the marker object used to track the file, not null
+ * @throws NullPointerException if the file is null
+ */
+ public void track(final File file, final Object marker) {
+ track(file, marker, null);
+ }
+
+ /**
+ * Track the specified file, using the provided marker, deleting the file
+ * when the marker instance is garbage collected.
+ * 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
+ * @param deleteStrategy the strategy to delete the file, null means normal
+ * @throws NullPointerException if the file is null
+ */
+ public void track(final File file, final Object marker, final FileDeleteStrategy deleteStrategy) {
+ if (file == null) {
+ throw new NullPointerException("The file must not be null");
+ }
+ addTracker(file.getPath(), marker, deleteStrategy);
+ }
+
+ /**
+ * Track the specified file, using the provided marker, deleting the file
+ * when the marker instance is garbage collected.
+ * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be 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
+ * @throws NullPointerException if the path is null
+ */
+ public void track(final String path, final Object marker) {
+ track(path, marker, null);
+ }
+
+ /**
+ * Track the specified file, using the provided marker, deleting the file
+ * when the marker instance is garbage collected.
+ * 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
+ * @param deleteStrategy the strategy to delete the file, null means normal
+ * @throws NullPointerException if the path is null
+ */
+ public void track(final String path, final Object marker, final FileDeleteStrategy deleteStrategy) {
+ if (path == null) {
+ throw new NullPointerException("The path must not be null");
+ }
+ addTracker(path, marker, deleteStrategy);
+ }
+
+ /**
+ * Adds a tracker to the list of trackers.
+ *
+ * @param path the full path to the file to be tracked, not null
+ * @param marker the marker object used to track the file, not null
+ * @param deleteStrategy the strategy to delete the file, null means normal
+ */
+ private synchronized void addTracker(final String path, final Object marker, final FileDeleteStrategy
+ deleteStrategy) {
+ // synchronized block protects reaper
+ if (exitWhenFinished) {
+ throw new IllegalStateException("No new trackers can be added once exitWhenFinished() is called");
+ }
+ if (reaper == null) {
+ reaper = new Reaper();
+ reaper.start();
+ }
+ trackers.add(new Tracker(path, deleteStrategy, marker, q));
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Retrieve the number of files currently being tracked, and therefore
+ * awaiting deletion.
+ *
+ * @return the number of files being tracked
+ */
+ public int getTrackCount() {
+ return trackers.size();
+ }
+
+ /**
+ * Return the file paths that failed to delete.
+ *
+ * @return the file paths that failed to delete
+ * @since 2.0
+ */
+ public List getDeleteFailures() {
+ return deleteFailures;
+ }
+
+ /**
+ * Call this method to cause the file cleaner thread to terminate when
+ * there are no more objects being tracked for deletion.
+ *
+ * In a simple environment, you don't need this method as the file cleaner
+ * 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 consitute a memory leak.
+ *
+ * For example, suppose that you have developed a web application, which
+ * contains the commons-io jar file in your WEB-INF/lib directory. In other
+ * words, the FileCleaner class is loaded through the class loader of your
+ * web application. If the web application is terminated, but the servlet
+ * container is still running, then the file cleaner thread will still exist,
+ * posing a memory leak.
+ *
+ * This method allows the thread to be terminated. Simply call this method
+ * in the resource cleanup code, such as
+ * {@code javax.servlet.ServletContextListener.contextDestroyed(javax.servlet.ServletContextEvent)}.
+ * Once called, no new objects can be tracked by the file cleaner.
+ */
+ public synchronized void exitWhenFinished() {
+ // synchronized block protects reaper
+ exitWhenFinished = true;
+ if (reaper != null) {
+ synchronized (reaper) {
+ reaper.interrupt();
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * The reaper thread.
+ */
+ private final class Reaper extends Thread {
+ /** Construct a new Reaper */
+ Reaper() {
+ super("File Reaper");
+ setPriority(Thread.MAX_PRIORITY);
+ setDaemon(true);
+ }
+
+ /**
+ * Run the reaper thread that will delete files as their associated
+ * marker objects are reclaimed by the garbage collector.
+ */
+ @Override
+ public void run() {
+ // thread exits when exitWhenFinished is true and there are no more tracked objects
+ while (exitWhenFinished == false || trackers.size() > 0) {
+ try {
+ // Wait for a tracker to remove.
+ final Tracker tracker = (Tracker) q.remove(); // cannot return null
+ trackers.remove(tracker);
+ if (!tracker.delete()) {
+ deleteFailures.add(tracker.getPath());
+ }
+ tracker.clear();
+ } catch (final InterruptedException e) {
+ continue;
+ }
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Inner class which acts as the reference for a file pending deletion.
+ */
+ private static final class Tracker extends PhantomReference {
+
+ /**
+ * The full path to the file being tracked.
+ */
+ private final String path;
+ /**
+ * The strategy for deleting files.
+ */
+ private final FileDeleteStrategy deleteStrategy;
+
+ /**
+ * Constructs an instance of this class from the supplied parameters.
+ *
+ * @param path the full path to the file to be tracked, not null
+ * @param deleteStrategy the strategy to delete the file, null means normal
+ * @param marker the marker object used to track the file, not null
+ * @param queue the queue on to which the tracker will be pushed, not null
+ */
+ Tracker(final String path, final FileDeleteStrategy deleteStrategy, final Object marker,
+ final ReferenceQueue super Object> queue) {
+ super(marker, queue);
+ this.path = path;
+ this.deleteStrategy = deleteStrategy == null ? FileDeleteStrategy.NORMAL : deleteStrategy;
+ }
+
+ /**
+ * Return the path.
+ *
+ * @return the path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Deletes the file associated with this tracker instance.
+ *
+ * @return {@code true} if the file was deleted successfully;
+ * {@code false} otherwise.
+ */
+ public boolean delete() {
+ return deleteStrategy.deleteQuietly(new File(path));
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileDeleteStrategy.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileDeleteStrategy.java"
new file mode 100644
index 0000000000000000000000000000000000000000..4bdc22dc153148b173a8de934221dcc8df958596
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileDeleteStrategy.java"
@@ -0,0 +1,157 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Strategy for deleting files.
+ *
+ * There is more than one way to delete a file.
+ * You may want to limit access to certain directories, to only delete
+ * directories if they are empty, or maybe to force deletion.
+ *
+ * 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 {
+
+ /**
+ * The singleton instance for normal file deletion, which does not permit
+ * the deletion of directories that are not empty.
+ */
+ public static final FileDeleteStrategy NORMAL = new FileDeleteStrategy("Normal");
+ /**
+ * The singleton instance for forced file deletion, which always deletes,
+ * even if the file represents a non-empty directory.
+ */
+ public static final FileDeleteStrategy FORCE = new ForceFileDeleteStrategy();
+
+ /** The name of the strategy. */
+ private final String name;
+
+ //-----------------------------------------------------------------------
+ /**
+ * Restricted constructor.
+ *
+ * @param name the name by which the strategy is known
+ */
+ protected FileDeleteStrategy(final String name) {
+ this.name = name;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Deletes the file object, which may be a file or a directory.
+ * All IOExceptions are caught and false returned instead.
+ * If the file does not exist or is null, true is returned.
+ *
+ * Subclass writers should override {@link #doDelete(File)}, not this method.
+ *
+ * @param fileToDelete the file to delete, null returns true
+ * @return true if the file was deleted, or there was no such file
+ */
+ public boolean deleteQuietly(final File fileToDelete) {
+ if (fileToDelete == null || fileToDelete.exists() == false) {
+ return true;
+ }
+ try {
+ return doDelete(fileToDelete);
+ } catch (final IOException ex) {
+ return false;
+ }
+ }
+
+ /**
+ * Deletes the file object, which may be a file or a directory.
+ * If the file does not exist, the method just returns.
+ *
+ * Subclass writers should override {@link #doDelete(File)}, not this method.
+ *
+ * @param fileToDelete the file to delete, not null
+ * @throws NullPointerException if the file is null
+ * @throws IOException if an error occurs during file deletion
+ */
+ public void delete(final File fileToDelete) throws IOException {
+ if (fileToDelete.exists() && doDelete(fileToDelete) == false) {
+ throw new IOException("Deletion failed: " + fileToDelete);
+ }
+ }
+
+ /**
+ * Actually deletes the file object, which may be a file or a directory.
+ *
+ * This method is designed for subclasses to override.
+ * The implementation may return either false or an IOException
+ * when deletion fails. The {@link #delete(File)} and {@link #deleteQuietly(File)}
+ * methods will handle either response appropriately.
+ * A check has been made to ensure that the file will exist.
+ *
+ * This implementation uses {@link File#delete()}.
+ *
+ * @param fileToDelete the file to delete, exists, not null
+ * @return true if the file was deleteds
+ * @throws NullPointerException if the file is null
+ * @throws IOException if an error occurs during file deletion
+ */
+ protected boolean doDelete(final File fileToDelete) throws IOException {
+ return fileToDelete.delete();
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets a string describing the delete strategy.
+ *
+ * @return a string describing the delete strategy
+ */
+ @Override
+ public String toString() {
+ return "FileDeleteStrategy[" + name + "]";
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Force file deletion strategy.
+ */
+ static class ForceFileDeleteStrategy extends FileDeleteStrategy {
+ /** Default Constructor */
+ ForceFileDeleteStrategy() {
+ super("Force");
+ }
+
+ /**
+ * Deletes the file object.
+ *
+ * This implementation uses FileUtils.forceDelete()
+ * if the file exists.
+ *
+ * @param fileToDelete the file to delete, not null
+ * @return Always returns {@code true}
+ * @throws NullPointerException if the file is null
+ * @throws IOException if an error occurs during file deletion
+ */
+ @Override
+ protected boolean doDelete(final File fileToDelete) throws IOException {
+ FileUtils.forceDelete(fileToDelete);
+ return true;
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileExistsException.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileExistsException.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d886efe3f1be2b344b6f628bc9c5deac54800bf3
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileExistsException.java"
@@ -0,0 +1,60 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.File;
+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 {
+
+ /**
+ * Defines the serial version UID.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Default Constructor.
+ */
+ public FileExistsException() {
+ super();
+ }
+
+ /**
+ * Construct an instance with the specified message.
+ *
+ * @param message The error message
+ */
+ public FileExistsException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Construct an instance with the specified file.
+ *
+ * @param file The file that exists
+ */
+ public FileExistsException(final File file) {
+ super("File " + file + " exists");
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileSystemUtils.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileSystemUtils.java"
new file mode 100644
index 0000000000000000000000000000000000000000..cefd2901b994ad2d92f795ad3492b6c2b84cbf62
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileSystemUtils.java"
@@ -0,0 +1,541 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+/**
+ * General File System utilities.
+ *
+ * This class provides static utility methods for general file system
+ * functions not provided via the JDK {@link java.io.File File} class.
+ *
+ * The current functions provided are:
+ *
+ * Get the free space on a drive
+ *
+ *
+ * @version $Id: FileSystemUtils.java 1686747 2015-06-21 18:44:49Z krosenvold $
+ * @since 1.1
+ */
+public class FileSystemUtils {
+
+ /** Singleton instance, used mainly for testing. */
+ private static final FileSystemUtils INSTANCE = new FileSystemUtils();
+
+ /** Operating system state flag for error. */
+ private static final int INIT_PROBLEM = -1;
+ /** Operating system state flag for neither Unix nor Windows. */
+ private static final int OTHER = 0;
+ /** Operating system state flag for Windows. */
+ private static final int WINDOWS = 1;
+ /** Operating system state flag for Unix. */
+ private static final int UNIX = 2;
+ /** Operating system state flag for Posix flavour Unix. */
+ private static final int POSIX_UNIX = 3;
+
+ /** The operating system flag. */
+ private static final int OS;
+
+ /** The path to df */
+ private static final String DF;
+
+ static {
+ int os = OTHER;
+ String dfPath = "df";
+ try {
+ String osName = System.getProperty("os.name");
+ if (osName == null) {
+ throw new IOException("os.name not found");
+ }
+ osName = osName.toLowerCase(Locale.ENGLISH);
+ // match
+ if (osName.contains("windows")) {
+ os = WINDOWS;
+ } else if (osName.contains("linux") ||
+ osName.contains("mpe/ix") ||
+ osName.contains("freebsd") ||
+ osName.contains("irix") ||
+ osName.contains("digital unix") ||
+ osName.contains("unix") ||
+ osName.contains("mac os x")) {
+ os = UNIX;
+ } else if (osName.contains("sun os") ||
+ osName.contains("sunos") ||
+ osName.contains("solaris")) {
+ os = POSIX_UNIX;
+ dfPath = "/usr/xpg4/bin/df";
+ } else if (osName.contains("hp-ux") ||
+ osName.contains("aix")) {
+ os = POSIX_UNIX;
+ } else {
+ os = OTHER;
+ }
+
+ } catch (final Exception ex) {
+ os = INIT_PROBLEM;
+ }
+ OS = os;
+ DF = dfPath;
+ }
+
+ /**
+ * Instances should NOT be constructed in standard programming.
+ */
+ public FileSystemUtils() {
+ super();
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns the free space on a drive or volume by invoking
+ * the command line.
+ * This method does not normalize the result, and typically returns
+ * bytes on Windows, 512 byte units on OS X and kilobytes on Unix.
+ * As this is not very useful, this method is deprecated in favour
+ * of {@link #freeSpaceKb(String)} which returns a result in kilobytes.
+ *
+ * Note that some OS's are NOT currently supported, including OS/390,
+ * OpenVMS.
+ *
+ * FileSystemUtils.freeSpace("C:"); // Windows
+ * FileSystemUtils.freeSpace("/volume"); // *nix
+ *
+ * The free space is calculated via the command line.
+ * It uses 'dir /-c' on Windows and 'df' on *nix.
+ *
+ * @param path the path to get free space for, not null, not empty on Unix
+ * @return the amount of free drive space on the drive or volume
+ * @throws IllegalArgumentException if the path is invalid
+ * @throws IllegalStateException if an error occurred in initialisation
+ * @throws IOException if an error occurs when finding the free space
+ * @since 1.1, enhanced OS support in 1.2 and 1.3
+ * @deprecated Use freeSpaceKb(String)
+ * Deprecated from 1.3, may be removed in 2.0
+ */
+ @Deprecated
+ public static long freeSpace(final String path) throws IOException {
+ return INSTANCE.freeSpaceOS(path, OS, false, -1);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns the free space on a drive or volume in kilobytes by invoking
+ * the command line.
+ *
+ * FileSystemUtils.freeSpaceKb("C:"); // Windows
+ * FileSystemUtils.freeSpaceKb("/volume"); // *nix
+ *
+ * The free space is calculated via the command line.
+ * It uses 'dir /-c' on Windows, 'df -kP' on AIX/HP-UX and 'df -k' on other Unix.
+ *
+ * In order to work, you must be running Windows, or have a implementation of
+ * Unix df that supports GNU format when passed -k (or -kP). If you are going
+ * to rely on this code, please check that it works on your OS by running
+ * some simple tests to compare the command line with the output from this class.
+ * If your operating system isn't supported, please raise a JIRA call detailing
+ * the exact result from df -k and as much other detail as possible, thanks.
+ *
+ * @param path the path to get free space for, not null, not empty on Unix
+ * @return the amount of free drive space on the drive or volume in kilobytes
+ * @throws IllegalArgumentException if the path is invalid
+ * @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
+ */
+ public static long freeSpaceKb(final String path) throws IOException {
+ return freeSpaceKb(path, -1);
+ }
+ /**
+ * Returns the free space on a drive or volume in kilobytes by invoking
+ * the command line.
+ *
+ * FileSystemUtils.freeSpaceKb("C:"); // Windows
+ * FileSystemUtils.freeSpaceKb("/volume"); // *nix
+ *
+ * The free space is calculated via the command line.
+ * It uses 'dir /-c' on Windows, 'df -kP' on AIX/HP-UX and 'df -k' on other Unix.
+ *
+ * In order to work, you must be running Windows, or have a implementation of
+ * Unix df that supports GNU format when passed -k (or -kP). If you are going
+ * to rely on this code, please check that it works on your OS by running
+ * some simple tests to compare the command line with the output from this class.
+ * If your operating system isn't supported, please raise a JIRA call detailing
+ * the exact result from df -k and as much other detail as possible, thanks.
+ *
+ * @param path the path to get free space for, not null, not empty on Unix
+ * @param timeout The timeout amount in milliseconds or no timeout if the value
+ * is zero or less
+ * @return the amount of free drive space on the drive or volume in kilobytes
+ * @throws IllegalArgumentException if the path is invalid
+ * @throws IllegalStateException if an error occurred in initialisation
+ * @throws IOException if an error occurs when finding the free space
+ * @since 2.0
+ */
+ public static long freeSpaceKb(final String path, final long timeout) throws IOException {
+ return INSTANCE.freeSpaceOS(path, OS, true, timeout);
+ }
+
+ /**
+ * Returns the disk size of the volume which holds the working directory.
+ *
+ * Identical to:
+ *
+ * freeSpaceKb(new File(".").getAbsolutePath())
+ *
+ * @return the amount of free drive space on the drive or volume in kilobytes
+ * @throws IllegalStateException if an error occurred in initialisation
+ * @throws IOException if an error occurs when finding the free space
+ * @since 2.0
+ */
+ public static long freeSpaceKb() throws IOException {
+ return freeSpaceKb(-1);
+ }
+
+ /**
+ * Returns the disk size of the volume which holds the working directory.
+ *
+ * Identical to:
+ *
+ * freeSpaceKb(new File(".").getAbsolutePath())
+ *
+ * @param timeout The timeout amount in milliseconds or no timeout if the value
+ * is zero or less
+ * @return the amount of free drive space on the drive or volume in kilobytes
+ * @throws IllegalStateException if an error occurred in initialisation
+ * @throws IOException if an error occurs when finding the free space
+ * @since 2.0
+ */
+ public static long freeSpaceKb(final long timeout) throws IOException {
+ return freeSpaceKb(new File(".").getAbsolutePath(), timeout);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns the free space on a drive or volume in a cross-platform manner.
+ * Note that some OS's are NOT currently supported, including OS/390.
+ *
+ * FileSystemUtils.freeSpace("C:"); // Windows
+ * FileSystemUtils.freeSpace("/volume"); // *nix
+ *
+ * The free space is calculated via the command line.
+ * It uses 'dir /-c' on Windows and 'df' on *nix.
+ *
+ * @param path the path to get free space for, not null, not empty on Unix
+ * @param os the operating system code
+ * @param kb whether to normalize to kilobytes
+ * @param timeout The timeout amount in milliseconds or no timeout if the value
+ * is zero or less
+ * @return the amount of free drive space on the drive or volume
+ * @throws IllegalArgumentException if the path is invalid
+ * @throws IllegalStateException if an error occurred in initialisation
+ * @throws IOException if an error occurs when finding the free space
+ */
+ long freeSpaceOS(final String path, final int os, final boolean kb, final long timeout) throws IOException {
+ if (path == null) {
+ throw new IllegalArgumentException("Path must not be null");
+ }
+ switch (os) {
+ case WINDOWS:
+ return kb ? freeSpaceWindows(path, timeout) / FileUtils.ONE_KB : freeSpaceWindows(path, timeout);
+ case UNIX:
+ return freeSpaceUnix(path, kb, false, timeout);
+ case POSIX_UNIX:
+ return freeSpaceUnix(path, kb, true, timeout);
+ case OTHER:
+ throw new IllegalStateException("Unsupported operating system");
+ default:
+ throw new IllegalStateException(
+ "Exception caught when determining operating system");
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Find free space on the Windows platform using the 'dir' command.
+ *
+ * @param path the path to get free space for, including the colon
+ * @param timeout The timeout amount in milliseconds or no timeout if the value
+ * is zero or less
+ * @return the amount of free drive space on the drive
+ * @throws IOException if an error occurs
+ */
+ 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 " + path};
+
+ // read in the output of the command to an ArrayList
+ final List lines = performCommand(cmdAttribs, Integer.MAX_VALUE, timeout);
+
+ // now iterate over the lines we just read and find the LAST
+ // non-empty line (the free space bytes should be in the last element
+ // of the ArrayList anyway, but this will ensure it works even if it's
+ // not, still assuming it is on the last non-blank line)
+ for (int i = lines.size() - 1; i >= 0; i--) {
+ final String line = lines.get(i);
+ if (line.length() > 0) {
+ return parseDir(line, path);
+ }
+ }
+ // all lines are blank
+ throw new IOException(
+ "Command line 'dir /-c' did not return any info " +
+ "for path '" + path + "'");
+ }
+
+ /**
+ * Parses the Windows dir response last line
+ *
+ * @param line the line to parse
+ * @param path the path that was sent
+ * @return the number of bytes
+ * @throws IOException if an error occurs
+ */
+ long parseDir(final String line, final String path) throws IOException {
+ // read from the end of the line to find the last numeric
+ // character on the line, then continue until we find the first
+ // non-numeric character, and everything between that and the last
+ // numeric character inclusive is our free space bytes count
+ int bytesStart = 0;
+ int bytesEnd = 0;
+ int j = line.length() - 1;
+ innerLoop1: while (j >= 0) {
+ final char c = line.charAt(j);
+ if (Character.isDigit(c)) {
+ // found the last numeric character, this is the end of
+ // the free space bytes count
+ bytesEnd = j + 1;
+ break innerLoop1;
+ }
+ j--;
+ }
+ innerLoop2: while (j >= 0) {
+ final char c = line.charAt(j);
+ if (!Character.isDigit(c) && c != ',' && c != '.') {
+ // found the next non-numeric character, this is the
+ // beginning of the free space bytes count
+ bytesStart = j + 1;
+ break innerLoop2;
+ }
+ j--;
+ }
+ if (j < 0) {
+ throw new IOException(
+ "Command line 'dir /-c' did not return valid info " +
+ "for path '" + path + "'");
+ }
+
+ // remove commas and dots in the bytes count
+ final StringBuilder buf = new StringBuilder(line.substring(bytesStart, bytesEnd));
+ for (int k = 0; k < buf.length(); k++) {
+ if (buf.charAt(k) == ',' || buf.charAt(k) == '.') {
+ buf.deleteCharAt(k--);
+ }
+ }
+ return parseBytes(buf.toString(), path);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Find free space on the *nix platform using the 'df' command.
+ *
+ * @param path the path to get free space for
+ * @param kb whether to normalize to kilobytes
+ * @param posix whether to use the POSIX standard format flag
+ * @param timeout The timeout amount in milliseconds or no timeout if the value
+ * is zero or less
+ * @return the amount of free drive space on the volume
+ * @throws IOException if an error occurs
+ */
+ long freeSpaceUnix(final String path, final boolean kb, final boolean posix, final long timeout)
+ throws IOException {
+ if (path.isEmpty()) {
+ throw new IllegalArgumentException("Path must not be empty");
+ }
+
+ // build and run the 'dir' command
+ String flags = "-";
+ if (kb) {
+ flags += "k";
+ }
+ if (posix) {
+ flags += "P";
+ }
+ final String[] cmdAttribs =
+ flags.length() > 1 ? new String[] {DF, flags, path} : new String[] {DF, path};
+
+ // perform the command, asking for up to 3 lines (header, interesting, overflow)
+ final List lines = performCommand(cmdAttribs, 3, timeout);
+ if (lines.size() < 2) {
+ // unknown problem, throw exception
+ throw new IOException(
+ "Command line '" + DF + "' did not return info as expected " +
+ "for path '" + path + "'- response was " + lines);
+ }
+ final String line2 = lines.get(1); // the line we're interested in
+
+ // Now, we tokenize the string. The fourth element is what we want.
+ StringTokenizer tok = new StringTokenizer(line2, " ");
+ if (tok.countTokens() < 4) {
+ // could be long Filesystem, thus data on third line
+ if (tok.countTokens() == 1 && lines.size() >= 3) {
+ final String line3 = lines.get(2); // the line may be interested in
+ tok = new StringTokenizer(line3, " ");
+ } else {
+ throw new IOException(
+ "Command line '" + DF + "' did not return data as expected " +
+ "for path '" + path + "'- check path is valid");
+ }
+ } else {
+ tok.nextToken(); // Ignore Filesystem
+ }
+ tok.nextToken(); // Ignore 1K-blocks
+ tok.nextToken(); // Ignore Used
+ final String freeSpace = tok.nextToken();
+ return parseBytes(freeSpace, path);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Parses the bytes from a string.
+ *
+ * @param freeSpace the free space string
+ * @param path the path
+ * @return the number of bytes
+ * @throws IOException if an error occurs
+ */
+ long parseBytes(final String freeSpace, final String path) throws IOException {
+ try {
+ final long bytes = Long.parseLong(freeSpace);
+ if (bytes < 0) {
+ throw new IOException(
+ "Command line '" + DF + "' did not find free space in response " +
+ "for path '" + path + "'- check path is valid");
+ }
+ return bytes;
+
+ } catch (final NumberFormatException ex) {
+ throw new IOException(
+ "Command line '" + DF + "' did not return numeric data as expected " +
+ "for path '" + path + "'- check path is valid", ex);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Performs the os command.
+ *
+ * @param cmdAttribs the command line parameters
+ * @param max The maximum limit for the lines returned
+ * @param timeout The timeout amount in milliseconds or no timeout if the value
+ * is zero or less
+ * @return the lines returned by the command, converted to lower-case
+ * @throws IOException if an error occurs
+ */
+ List performCommand(final String[] cmdAttribs, final int max, final long timeout) throws IOException {
+ // this method does what it can to avoid the 'Too many open files' error
+ // based on trial and error and these links:
+ // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692
+ // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4801027
+ // http://forum.java.sun.com/thread.jspa?threadID=533029&messageID=2572018
+ // however, its still not perfect as the JDK support is so poor
+ // (see commons-exec or Ant for a better multi-threaded multi-os solution)
+
+ final List lines = new ArrayList(20);
+ Process proc = null;
+ InputStream in = null;
+ OutputStream out = null;
+ InputStream err = null;
+ BufferedReader inr = null;
+ try {
+
+ final Thread monitor = ThreadMonitor.start(timeout);
+
+ proc = openProcess(cmdAttribs);
+ in = proc.getInputStream();
+ out = proc.getOutputStream();
+ err = proc.getErrorStream();
+ // default charset is most likely appropriate here
+ inr = new BufferedReader(new InputStreamReader(in, Charset.defaultCharset()));
+ String line = inr.readLine();
+ while (line != null && lines.size() < max) {
+ line = line.toLowerCase(Locale.ENGLISH).trim();
+ lines.add(line);
+ line = inr.readLine();
+ }
+
+ proc.waitFor();
+
+ ThreadMonitor.stop(monitor);
+
+ if (proc.exitValue() != 0) {
+ // os command problem, throw exception
+ throw new IOException(
+ "Command line returned OS error code '" + proc.exitValue() +
+ "' for command " + Arrays.asList(cmdAttribs));
+ }
+ if (lines.isEmpty()) {
+ // unknown problem, throw exception
+ throw new IOException(
+ "Command line did not return any info " +
+ "for command " + Arrays.asList(cmdAttribs));
+ }
+ return lines;
+
+ } catch (final InterruptedException ex) {
+ throw new IOException(
+ "Command line threw an InterruptedException " +
+ "for command " + Arrays.asList(cmdAttribs) + " timeout=" + timeout, ex);
+ } finally {
+ IOUtils.closeQuietly(in);
+ IOUtils.closeQuietly(out);
+ IOUtils.closeQuietly(err);
+ IOUtils.closeQuietly(inr);
+ if (proc != null) {
+ proc.destroy();
+ }
+ }
+ }
+
+ /**
+ * Opens the process to the operating system.
+ *
+ * @param cmdAttribs the command line parameters
+ * @return the process
+ * @throws IOException if an error occurs
+ */
+ Process openProcess(final String[] cmdAttribs) throws IOException {
+ return Runtime.getRuntime().exec(cmdAttribs);
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileUtils.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileUtils.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ddd80ffcb5e37cd765e4b556dc25d21941f9dc4b
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FileUtils.java"
@@ -0,0 +1,3146 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.math.BigInteger;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedInputStream;
+import java.util.zip.Checksum;
+
+import org.apache.commons.io.filefilter.DirectoryFileFilter;
+import org.apache.commons.io.filefilter.FalseFileFilter;
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.SuffixFileFilter;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.commons.io.output.NullOutputStream;
+
+/**
+ * General file manipulation utilities.
+ *
+ * Facilities are provided in the following areas:
+ *
+ * writing to a file
+ * reading from a file
+ * make a directory including parent directories
+ * copying files and directories
+ * deleting files and directories
+ * converting to and from a URL
+ * listing files and directories by filter and extension
+ * comparing file content
+ * file last changed date
+ * calculating a checksum
+ *
+ *
+ * Origin of code: Excalibur, Alexandria, Commons-Utils
+ *
+ * @version $Id: FileUtils.java 1722481 2016-01-01 01:42:04Z dbrosius $
+ */
+public class FileUtils {
+
+ /**
+ * Instances should NOT be constructed in standard programming.
+ */
+ public FileUtils() {
+ super();
+ }
+
+ /**
+ * The number of bytes in a kilobyte.
+ */
+ public static final long ONE_KB = 1024;
+
+ /**
+ * The number of bytes in a kilobyte.
+ *
+ * @since 2.4
+ */
+ public static final BigInteger ONE_KB_BI = BigInteger.valueOf(ONE_KB);
+
+ /**
+ * The number of bytes in a megabyte.
+ */
+ public static final long ONE_MB = ONE_KB * ONE_KB;
+
+ /**
+ * The number of bytes in a megabyte.
+ *
+ * @since 2.4
+ */
+ public static final BigInteger ONE_MB_BI = ONE_KB_BI.multiply(ONE_KB_BI);
+
+ /**
+ * The file copy buffer size (30 MB)
+ */
+ private static final long FILE_COPY_BUFFER_SIZE = ONE_MB * 30;
+
+ /**
+ * The number of bytes in a gigabyte.
+ */
+ public static final long ONE_GB = ONE_KB * ONE_MB;
+
+ /**
+ * The number of bytes in a gigabyte.
+ *
+ * @since 2.4
+ */
+ public static final BigInteger ONE_GB_BI = ONE_KB_BI.multiply(ONE_MB_BI);
+
+ /**
+ * The number of bytes in a terabyte.
+ */
+ public static final long ONE_TB = ONE_KB * ONE_GB;
+
+ /**
+ * The number of bytes in a terabyte.
+ *
+ * @since 2.4
+ */
+ public static final BigInteger ONE_TB_BI = ONE_KB_BI.multiply(ONE_GB_BI);
+
+ /**
+ * The number of bytes in a petabyte.
+ */
+ public static final long ONE_PB = ONE_KB * ONE_TB;
+
+ /**
+ * The number of bytes in a petabyte.
+ *
+ * @since 2.4
+ */
+ public static final BigInteger ONE_PB_BI = ONE_KB_BI.multiply(ONE_TB_BI);
+
+ /**
+ * The number of bytes in an exabyte.
+ */
+ public static final long ONE_EB = ONE_KB * ONE_PB;
+
+ /**
+ * The number of bytes in an exabyte.
+ *
+ * @since 2.4
+ */
+ public static final BigInteger ONE_EB_BI = ONE_KB_BI.multiply(ONE_PB_BI);
+
+ /**
+ * The number of bytes in a zettabyte.
+ */
+ public static final BigInteger ONE_ZB = BigInteger.valueOf(ONE_KB).multiply(BigInteger.valueOf(ONE_EB));
+
+ /**
+ * The number of bytes in a yottabyte.
+ */
+ public static final BigInteger ONE_YB = ONE_KB_BI.multiply(ONE_ZB);
+
+ /**
+ * An empty array of type File.
+ */
+ public static final File[] EMPTY_FILE_ARRAY = new File[0];
+
+ //-----------------------------------------------------------------------
+ /**
+ * Construct a file from the set of name elements.
+ *
+ * @param directory the parent directory
+ * @param names the name elements
+ * @return the file
+ * @since 2.1
+ */
+ public static File getFile(final File directory, final String... names) {
+ if (directory == null) {
+ throw new NullPointerException("directory must not be null");
+ }
+ if (names == null) {
+ throw new NullPointerException("names must not be null");
+ }
+ File file = directory;
+ for (final String name : names) {
+ file = new File(file, name);
+ }
+ return file;
+ }
+
+ /**
+ * Construct a file from the set of name elements.
+ *
+ * @param names the name elements
+ * @return the file
+ * @since 2.1
+ */
+ public static File getFile(final String... names) {
+ if (names == null) {
+ throw new NullPointerException("names must not be null");
+ }
+ File file = null;
+ for (final String name : names) {
+ if (file == null) {
+ file = new File(name);
+ } else {
+ file = new File(file, name);
+ }
+ }
+ return file;
+ }
+
+ /**
+ * Returns the path to the system temporary directory.
+ *
+ * @return the path to the system temporary directory.
+ *
+ * @since 2.0
+ */
+ public static String getTempDirectoryPath() {
+ return System.getProperty("java.io.tmpdir");
+ }
+
+ /**
+ * Returns a {@link File} representing the system temporary directory.
+ *
+ * @return the system temporary directory.
+ *
+ * @since 2.0
+ */
+ public static File getTempDirectory() {
+ return new File(getTempDirectoryPath());
+ }
+
+ /**
+ * Returns the path to the user's home directory.
+ *
+ * @return the path to the user's home directory.
+ *
+ * @since 2.0
+ */
+ public static String getUserDirectoryPath() {
+ return System.getProperty("user.home");
+ }
+
+ /**
+ * Returns a {@link File} representing the user's home directory.
+ *
+ * @return the user's home directory.
+ *
+ * @since 2.0
+ */
+ public static File getUserDirectory() {
+ return new File(getUserDirectoryPath());
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Opens a {@link FileInputStream} for the specified file, providing better
+ * error messages than simply calling new FileInputStream(file).
+ *
+ * At the end of the method either the stream will be successfully opened,
+ * or an exception will have been thrown.
+ *
+ * An exception is thrown if the file does not exist.
+ * An exception is thrown if the file object exists but is a directory.
+ * An exception is thrown if the file exists but cannot be read.
+ *
+ * @param file the file to open for input, must not be {@code null}
+ * @return a new {@link FileInputStream} for the specified file
+ * @throws FileNotFoundException if the file does not exist
+ * @throws IOException if the file object is a directory
+ * @throws IOException if the file cannot be read
+ * @since 1.3
+ */
+ public static FileInputStream openInputStream(final File file) throws IOException {
+ if (file.exists()) {
+ if (file.isDirectory()) {
+ throw new IOException("File '" + file + "' exists but is a directory");
+ }
+ if (file.canRead() == false) {
+ throw new IOException("File '" + file + "' cannot be read");
+ }
+ } else {
+ throw new FileNotFoundException("File '" + file + "' does not exist");
+ }
+ return new FileInputStream(file);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Opens a {@link FileOutputStream} for the specified file, checking and
+ * creating the parent directory if it does not exist.
+ *
+ * At the end of the method either the stream will be successfully opened,
+ * or an exception will have been thrown.
+ *
+ * The parent directory will be created if it does not exist.
+ * The file will be created if it does not exist.
+ * An exception is thrown if the file object exists but is a directory.
+ * An exception is thrown if the file exists but cannot be written to.
+ * An exception is thrown if the parent directory cannot be created.
+ *
+ * @param file the file to open for output, must not be {@code null}
+ * @return a new {@link FileOutputStream} for the specified file
+ * @throws IOException if the file object is a directory
+ * @throws IOException if the file cannot be written to
+ * @throws IOException if a parent directory needs creating but that fails
+ * @since 1.3
+ */
+ public static FileOutputStream openOutputStream(final File file) throws IOException {
+ return openOutputStream(file, false);
+ }
+
+ /**
+ * Opens a {@link FileOutputStream} for the specified file, checking and
+ * creating the parent directory if it does not exist.
+ *
+ * At the end of the method either the stream will be successfully opened,
+ * or an exception will have been thrown.
+ *
+ * The parent directory will be created if it does not exist.
+ * The file will be created if it does not exist.
+ * An exception is thrown if the file object exists but is a directory.
+ * An exception is thrown if the file exists but cannot be written to.
+ * An exception is thrown if the parent directory cannot be created.
+ *
+ * @param file the file to open for output, must not be {@code null}
+ * @param append if {@code true}, then bytes will be added to the
+ * end of the file rather than overwriting
+ * @return a new {@link FileOutputStream} for the specified file
+ * @throws IOException if the file object is a directory
+ * @throws IOException if the file cannot be written to
+ * @throws IOException if a parent directory needs creating but that fails
+ * @since 2.1
+ */
+ public static FileOutputStream openOutputStream(final File file, final boolean append) throws IOException {
+ if (file.exists()) {
+ if (file.isDirectory()) {
+ throw new IOException("File '" + file + "' exists but is a directory");
+ }
+ if (file.canWrite() == false) {
+ throw new IOException("File '" + file + "' cannot be written to");
+ }
+ } else {
+ final File parent = file.getParentFile();
+ if (parent != null) {
+ if (!parent.mkdirs() && !parent.isDirectory()) {
+ throw new IOException("Directory '" + parent + "' could not be created");
+ }
+ }
+ }
+ return new FileOutputStream(file, append);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns a human-readable version of the file size, where the input represents a specific number of bytes.
+ *
+ * If the size is over 1GB, the size is returned as the number of whole GB, i.e. the size is rounded down to the
+ * nearest GB boundary.
+ *
+ *
+ * Similarly for the 1MB and 1KB boundaries.
+ *
+ *
+ * @param size the number of bytes
+ * @return a human-readable display value (includes units - EB, PB, TB, GB, MB, KB or bytes)
+ * @see IO-226 - should the rounding be changed?
+ * @since 2.4
+ */
+ // See https://issues.apache.org/jira/browse/IO-226 - should the rounding be changed?
+ public static String byteCountToDisplaySize(final BigInteger size) {
+ String displaySize;
+
+ if (size.divide(ONE_EB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_EB_BI)) + " EB";
+ } else if (size.divide(ONE_PB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_PB_BI)) + " PB";
+ } else if (size.divide(ONE_TB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_TB_BI)) + " TB";
+ } else if (size.divide(ONE_GB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_GB_BI)) + " GB";
+ } else if (size.divide(ONE_MB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_MB_BI)) + " MB";
+ } else if (size.divide(ONE_KB_BI).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = String.valueOf(size.divide(ONE_KB_BI)) + " KB";
+ } else {
+ displaySize = String.valueOf(size) + " bytes";
+ }
+ return displaySize;
+ }
+
+ /**
+ * Returns a human-readable version of the file size, where the input represents a specific number of bytes.
+ *
+ * If the size is over 1GB, the size is returned as the number of whole GB, i.e. the size is rounded down to the
+ * nearest GB boundary.
+ *
+ *
+ * Similarly for the 1MB and 1KB boundaries.
+ *
+ *
+ * @param size the number of bytes
+ * @return a human-readable display value (includes units - EB, PB, TB, GB, MB, KB or bytes)
+ * @see IO-226 - should the rounding be changed?
+ */
+ // See https://issues.apache.org/jira/browse/IO-226 - should the rounding be changed?
+ public static String byteCountToDisplaySize(final long size) {
+ return byteCountToDisplaySize(BigInteger.valueOf(size));
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Implements the same behaviour as the "touch" utility on Unix. It creates
+ * a new file with size 0 or, if the file exists already, it is opened and
+ * closed without modifying it, but updating the file date and time.
+ *
+ * NOTE: As from v1.3, this method throws an IOException if the last
+ * modified date of the file cannot be set. Also, as from v1.3 this method
+ * creates parent directories if they do not exist.
+ *
+ * @param file the File to touch
+ * @throws IOException If an I/O problem occurs
+ */
+ public static void touch(final File file) throws IOException {
+ if (!file.exists()) {
+ final OutputStream out = openOutputStream(file);
+ IOUtils.closeQuietly(out);
+ }
+ final boolean success = file.setLastModified(System.currentTimeMillis());
+ if (!success) {
+ throw new IOException("Unable to set the last modification time for " + file);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Converts a Collection containing java.io.File instanced into array
+ * representation. This is to account for the difference between
+ * File.listFiles() and FileUtils.listFiles().
+ *
+ * @param files a Collection containing java.io.File instances
+ * @return an array of java.io.File
+ */
+ public static File[] convertFileCollectionToFileArray(final Collection files) {
+ return files.toArray(new File[files.size()]);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Finds files within a given directory (and optionally its
+ * subdirectories). All files found are filtered by an IOFileFilter.
+ *
+ * @param files the collection of files found.
+ * @param directory the directory to search in.
+ * @param filter the filter to apply to files and directories.
+ * @param includeSubDirectories indicates if will include the subdirectories themselves
+ */
+ private static void innerListFiles(final Collection files, final File directory,
+ final IOFileFilter filter, final boolean includeSubDirectories) {
+ final File[] found = directory.listFiles((FileFilter) filter);
+
+ if (found != null) {
+ for (final File file : found) {
+ if (file.isDirectory()) {
+ if (includeSubDirectories) {
+ files.add(file);
+ }
+ innerListFiles(files, file, filter, includeSubDirectories);
+ } else {
+ files.add(file);
+ }
+ }
+ }
+ }
+
+ /**
+ * Finds files within a given directory (and optionally its
+ * subdirectories). All files found are filtered by an IOFileFilter.
+ *
+ * If your search should recurse into subdirectories you can pass in
+ * an IOFileFilter for directories. You don't need to bind a
+ * DirectoryFileFilter (via logical AND) to this filter. This method does
+ * that for you.
+ *
+ * An example: If you want to search through all directories called
+ * "temp" you pass in FileFilterUtils.NameFileFilter("temp")
+ *
+ * Another common usage of this method is find files in a directory
+ * tree but ignoring the directories generated CVS. You can simply pass
+ * in FileFilterUtils.makeCVSAware(null).
+ *
+ * @param directory the directory to search in
+ * @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 TrueFileFilter.INSTANCE to match all directories.
+ * @return an collection of java.io.File with the matching files
+ * @see org.apache.commons.io.filefilter.FileFilterUtils
+ * @see org.apache.commons.io.filefilter.NameFileFilter
+ */
+ public static Collection listFiles(
+ final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) {
+ validateListFilesParameters(directory, fileFilter);
+
+ final IOFileFilter effFileFilter = setUpEffectiveFileFilter(fileFilter);
+ final IOFileFilter effDirFilter = setUpEffectiveDirFilter(dirFilter);
+
+ //Find files
+ final Collection files = new java.util.LinkedList();
+ innerListFiles(files, directory,
+ FileFilterUtils.or(effFileFilter, effDirFilter), false);
+ return files;
+ }
+
+ /**
+ * Validates the given arguments.
+ *
+ * Throws {@link IllegalArgumentException} if {@code directory} is not a directory
+ * Throws {@link NullPointerException} if {@code fileFilter} is null
+ *
+ *
+ * @param directory The File to test
+ * @param fileFilter The IOFileFilter to test
+ */
+ private static void validateListFilesParameters(final File directory, final IOFileFilter fileFilter) {
+ if (!directory.isDirectory()) {
+ throw new IllegalArgumentException("Parameter 'directory' is not a directory: " + directory);
+ }
+ if (fileFilter == null) {
+ throw new NullPointerException("Parameter 'fileFilter' is null");
+ }
+ }
+
+ /**
+ * Returns a filter that accepts files in addition to the {@link File} objects accepted by the given filter.
+ *
+ * @param fileFilter a base filter to add to
+ * @return a filter that accepts files
+ */
+ private static IOFileFilter setUpEffectiveFileFilter(final IOFileFilter fileFilter) {
+ return FileFilterUtils.and(fileFilter, FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE));
+ }
+
+ /**
+ * Returns a filter that accepts directories in addition to the {@link File} objects accepted by the given filter.
+ *
+ * @param dirFilter a base filter to add to
+ * @return a filter that accepts directories
+ */
+ private static IOFileFilter setUpEffectiveDirFilter(final IOFileFilter dirFilter) {
+ return dirFilter == null ? FalseFileFilter.INSTANCE : FileFilterUtils.and(dirFilter,
+ DirectoryFileFilter.INSTANCE);
+ }
+
+ /**
+ * Finds files within a given directory (and optionally its
+ * subdirectories). All files found are filtered by an IOFileFilter.
+ *
+ * The resulting collection includes the starting directory and
+ * any subdirectories that match the directory filter.
+ *
+ *
+ * @param directory the directory to search in
+ * @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 TrueFileFilter.INSTANCE to match all directories.
+ * @return an collection of java.io.File with the matching files
+ * @see org.apache.commons.io.FileUtils#listFiles
+ * @see org.apache.commons.io.filefilter.FileFilterUtils
+ * @see org.apache.commons.io.filefilter.NameFileFilter
+ * @since 2.2
+ */
+ public static Collection listFilesAndDirs(
+ final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) {
+ validateListFilesParameters(directory, fileFilter);
+
+ final IOFileFilter effFileFilter = setUpEffectiveFileFilter(fileFilter);
+ final IOFileFilter effDirFilter = setUpEffectiveDirFilter(dirFilter);
+
+ //Find files
+ final Collection files = new java.util.LinkedList();
+ if (directory.isDirectory()) {
+ files.add(directory);
+ }
+ innerListFiles(files, directory,
+ FileFilterUtils.or(effFileFilter, effDirFilter), true);
+ return files;
+ }
+
+ /**
+ * Allows iteration over the files in given directory (and optionally
+ * its subdirectories).
+ *
+ * All files found are filtered by an IOFileFilter. This method is
+ * based on {@link #listFiles(File, IOFileFilter, IOFileFilter)},
+ * which supports Iterable ('foreach' loop).
+ *
+ * @param directory the directory to search in
+ * @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 TrueFileFilter.INSTANCE to match all directories.
+ * @return an iterator of java.io.File for the matching files
+ * @see org.apache.commons.io.filefilter.FileFilterUtils
+ * @see org.apache.commons.io.filefilter.NameFileFilter
+ * @since 1.2
+ */
+ public static Iterator iterateFiles(
+ final File directory, final IOFileFilter fileFilter, final IOFileFilter dirFilter) {
+ return listFiles(directory, fileFilter, dirFilter).iterator();
+ }
+
+ /**
+ * Allows iteration over the files in given directory (and optionally
+ * its subdirectories).
+ *
+ * All files found are filtered by an IOFileFilter. This method is
+ * based on {@link #listFilesAndDirs(File, IOFileFilter, IOFileFilter)},
+ * which supports Iterable ('foreach' loop).
+ *
+ * The resulting iterator includes the subdirectories themselves.
+ *
+ * @param directory the directory to search in
+ * @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 TrueFileFilter.INSTANCE to match all directories.
+ * @return an iterator of java.io.File for the matching files
+ * @see org.apache.commons.io.filefilter.FileFilterUtils
+ * @see org.apache.commons.io.filefilter.NameFileFilter
+ * @since 2.2
+ */
+ public static Iterator iterateFilesAndDirs(final File directory, final IOFileFilter fileFilter,
+ final IOFileFilter dirFilter) {
+ return listFilesAndDirs(directory, fileFilter, dirFilter).iterator();
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Converts an array of file extensions to suffixes for use
+ * with IOFileFilters.
+ *
+ * @param extensions an array of extensions. Format: {"java", "xml"}
+ * @return an array of suffixes. Format: {".java", ".xml"}
+ */
+ private static String[] toSuffixes(final String[] extensions) {
+ final String[] suffixes = new String[extensions.length];
+ for (int i = 0; i < extensions.length; i++) {
+ suffixes[i] = "." + extensions[i];
+ }
+ return suffixes;
+ }
+
+
+ /**
+ * Finds files within a given directory (and optionally its subdirectories)
+ * which match an array of extensions.
+ *
+ * @param directory the directory to search in
+ * @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 an collection of java.io.File with the matching files
+ */
+ public static Collection listFiles(
+ final File directory, final String[] extensions, final boolean recursive) {
+ IOFileFilter filter;
+ if (extensions == null) {
+ filter = TrueFileFilter.INSTANCE;
+ } else {
+ final String[] suffixes = toSuffixes(extensions);
+ filter = new SuffixFileFilter(suffixes);
+ }
+ return listFiles(directory, filter,
+ recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE);
+ }
+
+ /**
+ * Allows iteration over the files in a given directory (and optionally
+ * its subdirectories) which match an array of extensions. This method
+ * is based on {@link #listFiles(File, String[], boolean)},
+ * which supports Iterable ('foreach' loop).
+ *
+ * @param directory the directory to search in
+ * @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 an iterator of java.io.File with the matching files
+ * @since 1.2
+ */
+ public static Iterator iterateFiles(
+ final File directory, final String[] extensions, final boolean recursive) {
+ return listFiles(directory, extensions, recursive).iterator();
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Compares the contents of two files to determine if they are equal or not.
+ *
+ * This method checks to see if the two files are different lengths
+ * or if they point to the same file, before resorting to byte-by-byte
+ * comparison of the contents.
+ *
+ * Code origin: Avalon
+ *
+ * @param file1 the first file
+ * @param file2 the second file
+ * @return true if the content of the files are equal or they both don't
+ * exist, false otherwise
+ * @throws IOException in case of an I/O error
+ */
+ public static boolean contentEquals(final File file1, final File file2) throws IOException {
+ final boolean file1Exists = file1.exists();
+ if (file1Exists != file2.exists()) {
+ return false;
+ }
+
+ if (!file1Exists) {
+ // two not existing files are equal
+ return true;
+ }
+
+ if (file1.isDirectory() || file2.isDirectory()) {
+ // don't want to compare directory contents
+ throw new IOException("Can't compare directories, only files");
+ }
+
+ if (file1.length() != file2.length()) {
+ // lengths differ, cannot be equal
+ return false;
+ }
+
+ if (file1.getCanonicalFile().equals(file2.getCanonicalFile())) {
+ // same file
+ return true;
+ }
+
+ 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);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Compares the contents of two files to determine if they are equal or not.
+ *
+ * This method checks to see if the two files point to the same file,
+ * before resorting to line-by-line comparison of the contents.
+ *
+ *
+ * @param file1 the first file
+ * @param file2 the second file
+ * @param charsetName the character encoding to be used.
+ * May be null, in which case the platform default is used
+ * @return true if the content of the files are equal or neither exists,
+ * false otherwise
+ * @throws IOException in case of an I/O error
+ * @see IOUtils#contentEqualsIgnoreEOL(Reader, Reader)
+ * @since 2.2
+ */
+ public static boolean contentEqualsIgnoreEOL(final File file1, final File file2, final String charsetName)
+ throws IOException {
+ final boolean file1Exists = file1.exists();
+ if (file1Exists != file2.exists()) {
+ return false;
+ }
+
+ if (!file1Exists) {
+ // two not existing files are equal
+ return true;
+ }
+
+ if (file1.isDirectory() || file2.isDirectory()) {
+ // don't want to compare directory contents
+ throw new IOException("Can't compare directories, only files");
+ }
+
+ if (file1.getCanonicalFile().equals(file2.getCanonicalFile())) {
+ // same file
+ return true;
+ }
+
+ 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);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Convert from a URL to a File.
+ *
+ * From version 1.1 this method will decode the URL.
+ * Syntax such as file:///my%20docs/file.txt will be
+ * correctly decoded to /my docs/file.txt. Starting with version
+ * 1.5, this method uses UTF-8 to decode percent-encoded octets to characters.
+ * Additionally, malformed percent-encoded octets are handled leniently by
+ * passing them through literally.
+ *
+ * @param url the file URL to convert, {@code null} returns {@code null}
+ * @return the equivalent File object, or {@code null}
+ * if the URL's protocol is not file
+ */
+ public static File toFile(final URL url) {
+ if (url == null || !"file".equalsIgnoreCase(url.getProtocol())) {
+ return null;
+ } else {
+ String filename = url.getFile().replace('/', File.separatorChar);
+ filename = decodeUrl(filename);
+ return new File(filename);
+ }
+ }
+
+ /**
+ * Decodes the specified URL as per RFC 3986, i.e. transforms
+ * percent-encoded octets to characters by decoding with the UTF-8 character
+ * set. This function is primarily intended for usage with
+ * {@link java.net.URL} which unfortunately does not enforce proper URLs. As
+ * such, this method will leniently accept invalid characters or malformed
+ * percent-encoded octets and simply pass them literally through to the
+ * result string. Except for rare edge cases, this will make unencoded URLs
+ * pass through unaltered.
+ *
+ * @param url The URL to decode, may be {@code null}.
+ * @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) {
+ final int n = url.length();
+ final StringBuilder buffer = new StringBuilder();
+ final ByteBuffer bytes = ByteBuffer.allocate(n);
+ for (int i = 0; i < n; ) {
+ if (url.charAt(i) == '%') {
+ try {
+ do {
+ final byte octet = (byte) Integer.parseInt(url.substring(i + 1, i + 3), 16);
+ bytes.put(octet);
+ i += 3;
+ } while (i < n && url.charAt(i) == '%');
+ continue;
+ } catch (final RuntimeException e) {
+ // malformed percent-encoded octet, fall through and
+ // append characters literally
+ } finally {
+ if (bytes.position() > 0) {
+ bytes.flip();
+ buffer.append(Charsets.UTF_8.decode(bytes).toString());
+ bytes.clear();
+ }
+ }
+ }
+ buffer.append(url.charAt(i++));
+ }
+ decoded = buffer.toString();
+ }
+ return decoded;
+ }
+
+ /**
+ * Converts each of an array of URL to a File.
+ *
+ * Returns an array of the same size as the input.
+ * If the input is {@code null}, an empty array is returned.
+ * If the input contains {@code null}, the output array contains {@code null} at the same
+ * index.
+ *
+ * This method will decode the URL.
+ * Syntax such as file:///my%20docs/file.txt will be
+ * correctly decoded to /my docs/file.txt.
+ *
+ * @param urls the file URLs to convert, {@code null} returns empty array
+ * @return a non-{@code null} array of Files matching the input, with a {@code null} item
+ * if there was a {@code null} at that index in the input array
+ * @throws IllegalArgumentException if any file is not a URL file
+ * @throws IllegalArgumentException if any file is incorrectly encoded
+ * @since 1.1
+ */
+ public static File[] toFiles(final URL[] urls) {
+ if (urls == null || urls.length == 0) {
+ return EMPTY_FILE_ARRAY;
+ }
+ final File[] files = new File[urls.length];
+ for (int i = 0; i < urls.length; i++) {
+ final URL url = urls[i];
+ if (url != null) {
+ if (url.getProtocol().equals("file") == false) {
+ throw new IllegalArgumentException(
+ "URL could not be converted to a File: " + url);
+ }
+ files[i] = toFile(url);
+ }
+ }
+ return files;
+ }
+
+ /**
+ * Converts each of an array of File to a URL.
+ *
+ * Returns an array of the same size as the input.
+ *
+ * @param files the files to convert, must not be {@code null}
+ * @return an array of URLs matching the input
+ * @throws IOException if a file cannot be converted
+ * @throws NullPointerException if the parameter is null
+ */
+ public static URL[] toURLs(final File[] files) throws IOException {
+ final URL[] urls = new URL[files.length];
+
+ for (int i = 0; i < urls.length; i++) {
+ urls[i] = files[i].toURI().toURL();
+ }
+
+ return urls;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Copies a file to a directory preserving the file date.
+ *
+ * This method copies the contents of the specified source file
+ * to a file of the same name in the specified destination directory.
+ * The destination directory is created if it does not exist.
+ * If the destination file exists, then this method will overwrite it.
+ *
+ * Note: This method tries to preserve the file's last
+ * modified date/times using {@link File#setLastModified(long)}, however
+ * it is not guaranteed that the operation will succeed.
+ * If the modification operation fails, no indication is provided.
+ *
+ * @param srcFile an existing file 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 #copyFile(File, File, boolean)
+ */
+ public static void copyFileToDirectory(final File srcFile, final File destDir) throws IOException {
+ copyFileToDirectory(srcFile, destDir, true);
+ }
+
+ /**
+ * Copies a file to a directory optionally preserving the file date.
+ *
+ * This method copies the contents of the specified source file
+ * to a file of the same name in the specified destination directory.
+ * The destination directory is created if it does not exist.
+ * If the destination file exists, then this method will overwrite it.
+ *
+ * Note: Setting preserveFileDate to
+ * {@code true} 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 srcFile an existing file to copy, must not be {@code null}
+ * @param destDir the directory to place the copy in, must not be {@code null}
+ * @param preserveFileDate true if the file date of the copy
+ * should be the same as the original
+ *
+ * @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
+ * @throws IOException if the output file length is not the same as the input file length after the copy
+ * completes
+ * @see #copyFile(File, File, boolean)
+ * @since 1.3
+ */
+ public static void copyFileToDirectory(final File srcFile, final File destDir, final boolean preserveFileDate)
+ throws IOException {
+ if (destDir == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (destDir.exists() && destDir.isDirectory() == false) {
+ throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory");
+ }
+ final File destFile = new File(destDir, srcFile.getName());
+ copyFile(srcFile, destFile, preserveFileDate);
+ }
+
+ /**
+ * Copies a file to a new location preserving the file date.
+ *
+ * This method copies the contents of the specified source file to the
+ * specified destination file. The directory holding the destination file is
+ * created if it does not exist. If the destination file exists, then this
+ * method will overwrite it.
+ *
+ * Note: This method tries to preserve the file's last
+ * modified date/times using {@link File#setLastModified(long)}, however
+ * it is not guaranteed that the operation will succeed.
+ * If the modification operation fails, no indication is provided.
+ *
+ * @param srcFile an existing file to copy, must not be {@code null}
+ * @param destFile the new file, 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
+ * @throws IOException if the output file length is not the same as the input file length after the copy
+ * completes
+ * @see #copyFileToDirectory(File, File)
+ * @see #copyFile(File, File, boolean)
+ */
+ public static void copyFile(final File srcFile, final File destFile) throws IOException {
+ copyFile(srcFile, destFile, true);
+ }
+
+ /**
+ * Copies a file to a new location.
+ *
+ * This method copies the contents of the specified source file
+ * to the specified destination file.
+ * The directory holding the destination file is created if it does not exist.
+ * If the destination file exists, then this method will overwrite it.
+ *
+ * Note: Setting preserveFileDate to
+ * {@code true} 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 srcFile an existing file to copy, must not be {@code null}
+ * @param destFile the new file, must not be {@code null}
+ * @param preserveFileDate true if the file date of the copy
+ * should be the same as the original
+ *
+ * @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
+ * @throws IOException if the output file length is not the same as the input file length after the copy
+ * completes
+ * @see #copyFileToDirectory(File, File, boolean)
+ * @see #doCopyFile(File, File, boolean)
+ */
+ public static void copyFile(final File srcFile, final File destFile,
+ final boolean preserveFileDate) throws IOException {
+ checkFileRequirements(srcFile, destFile);
+ if (srcFile.isDirectory()) {
+ throw new IOException("Source '" + srcFile + "' exists but is a directory");
+ }
+ if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {
+ throw new IOException("Source '" + srcFile + "' and destination '" + destFile + "' are the same");
+ }
+ final File parentFile = destFile.getParentFile();
+ if (parentFile != null) {
+ if (!parentFile.mkdirs() && !parentFile.isDirectory()) {
+ throw new IOException("Destination '" + parentFile + "' directory cannot be created");
+ }
+ }
+ if (destFile.exists() && destFile.canWrite() == false) {
+ throw new IOException("Destination '" + destFile + "' exists but is read-only");
+ }
+ doCopyFile(srcFile, destFile, preserveFileDate);
+ }
+
+ /**
+ * Copy bytes from a File to an OutputStream.
+ *
+ * This method buffers the input internally, so there is no need to use a BufferedInputStream.
+ *
+ *
+ * @param input the File to read from
+ * @param output the OutputStream to write to
+ * @return the number of bytes copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.1
+ */
+ public static long copyFile(final File input, final OutputStream output) throws IOException {
+ final FileInputStream fis = new FileInputStream(input);
+ try {
+ return IOUtils.copyLarge(fis, output);
+ } finally {
+ fis.close();
+ }
+ }
+
+ /**
+ * Internal copy file method.
+ * This caches the original file length, and throws an IOException
+ * if the output file length is different from the current input file length.
+ * So it may fail if the file changes size.
+ * It may also fail with "IllegalArgumentException: Negative size" if the input file is truncated part way
+ * through copying the data and the new file size is less than the current position.
+ *
+ * @param srcFile the validated source file, must not be {@code null}
+ * @param destFile the validated destination file, must not be {@code null}
+ * @param preserveFileDate whether to preserve the file date
+ * @throws IOException if an error occurs
+ * @throws IOException if the output file length is not the same as the input file length after the
+ * copy completes
+ * @throws IllegalArgumentException "Negative size" if the file is truncated so that the size is less than the
+ * position
+ */
+ private static void doCopyFile(final File srcFile, final File destFile, final boolean preserveFileDate)
+ throws IOException {
+ if (destFile.exists() && destFile.isDirectory()) {
+ throw new IOException("Destination '" + destFile + "' exists but is a directory");
+ }
+
+ 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;
+ while (pos < size) {
+ final long remain = size - pos;
+ count = remain > FILE_COPY_BUFFER_SIZE ? FILE_COPY_BUFFER_SIZE : remain;
+ final long bytesCopied = output.transferFrom(input, pos, count);
+ if (bytesCopied == 0) { // IO-385 - can happen if file is truncated after caching the size
+ break; // ensure we don't loop forever
+ }
+ pos += bytesCopied;
+ }
+ } finally {
+ IOUtils.closeQuietly(output, fos, input, fis);
+ }
+
+ final long srcLen = srcFile.length(); // TODO See IO-386
+ final long dstLen = destFile.length(); // TODO See IO-386
+ if (srcLen != dstLen) {
+ throw new IOException("Failed to copy full contents from '" +
+ srcFile + "' to '" + destFile + "' Expected length: " + srcLen + " Actual: " + dstLen);
+ }
+ if (preserveFileDate) {
+ destFile.setLastModified(srcFile.lastModified());
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Copies a directory to within another directory preserving the file dates.
+ *
+ * This method copies the source directory and all its contents to a
+ * directory of the same name in the specified destination directory.
+ *
+ * The destination directory is created if it does not exist.
+ * If the destination directory did exist, then this method merges
+ * the source with the destination, with the source taking precedence.
+ *
+ * Note: This method tries to preserve the files' last
+ * modified date/times using {@link File#setLastModified(long)}, however
+ * it is not guaranteed that those operations will succeed.
+ * If the modification operation fails, no indication is provided.
+ *
+ * @param srcDir an existing 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
+ * @since 1.2
+ */
+ public static void copyDirectoryToDirectory(final File srcDir, final File destDir) throws IOException {
+ if (srcDir == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (srcDir.exists() && srcDir.isDirectory() == false) {
+ throw new IllegalArgumentException("Source '" + destDir + "' is not a directory");
+ }
+ if (destDir == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (destDir.exists() && destDir.isDirectory() == false) {
+ throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory");
+ }
+ copyDirectory(srcDir, new File(destDir, srcDir.getName()), true);
+ }
+
+ /**
+ * Copies a whole directory to a new location preserving the file dates.
+ *
+ * This method copies the specified directory and all its child
+ * directories and files to the specified destination.
+ * The destination is the new location and name of the directory.
+ *
+ * The destination directory is created if it does not exist.
+ * If the destination directory did exist, then this method merges
+ * the source with the destination, with the source taking precedence.
+ *
+ * Note: This method tries to preserve the files' last
+ * modified date/times using {@link File#setLastModified(long)}, however
+ * it is not guaranteed that those operations will succeed.
+ * If the modification operation fails, no indication is provided.
+ *
+ * @param srcDir an existing directory to copy, must not be {@code null}
+ * @param destDir the new directory, 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
+ * @since 1.1
+ */
+ public static void copyDirectory(final File srcDir, final File destDir) throws IOException {
+ copyDirectory(srcDir, destDir, true);
+ }
+
+ /**
+ * Copies a whole directory to a new location.
+ *
+ * This method copies the contents of the specified source directory
+ * to within the specified destination directory.
+ *
+ * The destination directory is created if it does not exist.
+ * If the destination directory did exist, then this method merges
+ * the source with the destination, with the source taking precedence.
+ *
+ * Note: Setting preserveFileDate to
+ * {@code true} 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 srcDir an existing directory to copy, must not be {@code null}
+ * @param destDir the new directory, must not be {@code null}
+ * @param preserveFileDate true if the file date of the copy
+ * should be the same as the original
+ *
+ * @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
+ * @since 1.1
+ */
+ public static void copyDirectory(final File srcDir, final File destDir,
+ final boolean preserveFileDate) throws IOException {
+ copyDirectory(srcDir, destDir, null, preserveFileDate);
+ }
+
+ /**
+ * Copies a filtered directory to a new location preserving the file dates.
+ *
+ * This method copies the contents of the specified source directory
+ * to within the specified destination directory.
+ *
+ * The destination directory is created if it does not exist.
+ * If the destination directory did exist, then this method merges
+ * the source with the destination, with the source taking precedence.
+ *
+ * Note: This method tries to preserve the files' last
+ * modified date/times using {@link File#setLastModified(long)}, however
+ * it is not guaranteed that those operations will succeed.
+ * If the modification operation fails, no indication is provided.
+ *
+ * Example: Copy directories only
+ *
+ * // only copy the directory structure
+ * FileUtils.copyDirectory(srcDir, destDir, DirectoryFileFilter.DIRECTORY);
+ *
+ *
+ * Example: Copy directories and txt files
+ *
+ * // Create a filter for ".txt" files
+ * IOFileFilter txtSuffixFilter = FileFilterUtils.suffixFileFilter(".txt");
+ * IOFileFilter txtFiles = FileFilterUtils.andFileFilter(FileFileFilter.FILE, txtSuffixFilter);
+ *
+ * // Create a filter for either directories or ".txt" files
+ * FileFilter filter = FileFilterUtils.orFileFilter(DirectoryFileFilter.DIRECTORY, txtFiles);
+ *
+ * // Copy using the filter
+ * FileUtils.copyDirectory(srcDir, destDir, filter);
+ *
+ *
+ * @param srcDir an existing directory to copy, must not be {@code null}
+ * @param destDir the new directory, must not be {@code null}
+ * @param filter the filter to apply, null means copy all directories and files
+ * should be the same as the original
+ *
+ * @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
+ * @since 1.4
+ */
+ public static void copyDirectory(final File srcDir, final File destDir,
+ final FileFilter filter) throws IOException {
+ copyDirectory(srcDir, destDir, filter, true);
+ }
+
+ /**
+ * Copies a filtered directory to a new location.
+ *
+ * This method copies the contents of the specified source directory
+ * to within the specified destination directory.
+ *
+ * The destination directory is created if it does not exist.
+ * If the destination directory did exist, then this method merges
+ * the source with the destination, with the source taking precedence.
+ *
+ * Note: Setting preserveFileDate to
+ * {@code true} 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.
+ *
+ * Example: Copy directories only
+ *
+ * // only copy the directory structure
+ * FileUtils.copyDirectory(srcDir, destDir, DirectoryFileFilter.DIRECTORY, false);
+ *
+ *
+ * Example: Copy directories and txt files
+ *
+ * // Create a filter for ".txt" files
+ * IOFileFilter txtSuffixFilter = FileFilterUtils.suffixFileFilter(".txt");
+ * IOFileFilter txtFiles = FileFilterUtils.andFileFilter(FileFileFilter.FILE, txtSuffixFilter);
+ *
+ * // Create a filter for either directories or ".txt" files
+ * FileFilter filter = FileFilterUtils.orFileFilter(DirectoryFileFilter.DIRECTORY, txtFiles);
+ *
+ * // Copy using the filter
+ * FileUtils.copyDirectory(srcDir, destDir, filter, false);
+ *
+ *
+ * @param srcDir an existing directory to copy, must not be {@code null}
+ * @param destDir the new directory, must not be {@code null}
+ * @param filter the filter to apply, null means copy all directories and files
+ * @param preserveFileDate true if the file date of the copy
+ * should be the same as the original
+ *
+ * @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
+ * @since 1.4
+ */
+ public static void copyDirectory(final File srcDir, final File destDir,
+ final FileFilter filter, final boolean preserveFileDate) throws IOException {
+ checkFileRequirements(srcDir, destDir);
+ if (!srcDir.isDirectory()) {
+ throw new IOException("Source '" + srcDir + "' exists but is not a directory");
+ }
+ if (srcDir.getCanonicalPath().equals(destDir.getCanonicalPath())) {
+ throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are the same");
+ }
+
+ // Cater for destination being directory within the source directory (see IO-141)
+ List exclusionList = null;
+ 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);
+ for (final File srcFile : srcFiles) {
+ final File copiedFile = new File(destDir, srcFile.getName());
+ exclusionList.add(copiedFile.getCanonicalPath());
+ }
+ }
+ }
+ doCopyDirectory(srcDir, destDir, filter, preserveFileDate, exclusionList);
+ }
+
+ /**
+ * checks requirements for file copy
+ * @param src the source file
+ * @param dest the destination
+ * @throws FileNotFoundException if the destination does not exist
+ */
+ private static void checkFileRequirements(File src, File dest) throws FileNotFoundException {
+ if (src == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (dest == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (!src.exists()) {
+ throw new FileNotFoundException("Source '" + src + "' does not exist");
+ }
+ }
+
+ /**
+ * Internal copy directory method.
+ *
+ * @param srcDir the validated source directory, must not be {@code null}
+ * @param destDir the validated destination directory, must not be {@code null}
+ * @param filter the filter to apply, null means copy all directories and files
+ * @param preserveFileDate whether to preserve the file date
+ * @param exclusionList List of files and directories to exclude from the copy, may be null
+ * @throws IOException if an error occurs
+ * @since 1.1
+ */
+ private static void doCopyDirectory(final File srcDir, final File destDir, final FileFilter filter,
+ final boolean preserveFileDate, final List exclusionList)
+ throws IOException {
+ // recurse
+ final File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
+ if (srcFiles == null) { // null if abstract pathname does not denote a directory, or if an I/O error occurs
+ throw new IOException("Failed to list contents of " + srcDir);
+ }
+ if (destDir.exists()) {
+ if (destDir.isDirectory() == false) {
+ throw new IOException("Destination '" + destDir + "' exists but is not a directory");
+ }
+ } else {
+ if (!destDir.mkdirs() && !destDir.isDirectory()) {
+ throw new IOException("Destination '" + destDir + "' directory cannot be created");
+ }
+ }
+ if (destDir.canWrite() == false) {
+ throw new IOException("Destination '" + destDir + "' cannot be written to");
+ }
+ for (final File srcFile : srcFiles) {
+ final File dstFile = new File(destDir, srcFile.getName());
+ if (exclusionList == null || !exclusionList.contains(srcFile.getCanonicalPath())) {
+ if (srcFile.isDirectory()) {
+ doCopyDirectory(srcFile, dstFile, filter, preserveFileDate, exclusionList);
+ } else {
+ doCopyFile(srcFile, dstFile, preserveFileDate);
+ }
+ }
+ }
+
+ // Do this last, as the above has probably affected directory metadata
+ if (preserveFileDate) {
+ destDir.setLastModified(srcDir.lastModified());
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Copies bytes from the URL source to a file
+ * destination. The directories up to destination
+ * will be created if they don't already exist. destination
+ * will be overwritten if it already exists.
+ *
+ * Warning: this method does not set a connection or read timeout and thus
+ * might block forever. Use {@link #copyURLToFile(URL, File, int, int)}
+ * with reasonable timeouts to prevent this.
+ *
+ * @param source the URL to copy bytes from, must not be {@code null}
+ * @param destination the non-directory File to write bytes to
+ * (possibly overwriting), must not be {@code null}
+ * @throws IOException if source URL cannot be opened
+ * @throws IOException if destination is a directory
+ * @throws IOException if destination cannot be written
+ * @throws IOException if destination needs creating but can't be
+ * @throws IOException if an IO error occurs during copying
+ */
+ public static void copyURLToFile(final URL source, final File destination) throws IOException {
+ copyInputStreamToFile(source.openStream(), destination);
+ }
+
+ /**
+ * Copies bytes from the URL source to a file
+ * destination. The directories up to destination
+ * will be created if they don't already exist. destination
+ * will be overwritten if it already exists.
+ *
+ * @param source the URL to copy bytes from, must not be {@code null}
+ * @param destination the non-directory File to write bytes to
+ * (possibly overwriting), must not be {@code null}
+ * @param connectionTimeout the number of milliseconds until this method
+ * will timeout if no connection could be established to the source
+ * @param readTimeout the number of milliseconds until this method will
+ * timeout if no data could be read from the source
+ * @throws IOException if source URL cannot be opened
+ * @throws IOException if destination is a directory
+ * @throws IOException if destination cannot be written
+ * @throws IOException if destination needs creating but can't be
+ * @throws IOException if an IO error occurs during copying
+ * @since 2.0
+ */
+ public static void copyURLToFile(final URL source, final File destination,
+ final int connectionTimeout, final int readTimeout) throws IOException {
+ final URLConnection connection = source.openConnection();
+ connection.setConnectTimeout(connectionTimeout);
+ connection.setReadTimeout(readTimeout);
+ copyInputStreamToFile(connection.getInputStream(), destination);
+ }
+
+ /**
+ * Copies bytes from an {@link InputStream} source to a file
+ * destination. The directories up to destination
+ * will be created if they don't already exist. destination
+ * will be overwritten if it already exists.
+ * The {@code source} stream is closed.
+ * See {@link #copyToFile(InputStream, File)} for a method that does not close the input stream.
+ *
+ * @param source the InputStream to copy bytes from, must not be {@code null}, will be closed
+ * @param destination the non-directory File to write bytes to
+ * (possibly overwriting), must not be {@code null}
+ * @throws IOException if destination is a directory
+ * @throws IOException if destination cannot be written
+ * @throws IOException if destination needs creating but can't be
+ * @throws IOException if an IO error occurs during copying
+ * @since 2.0
+ */
+ public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException {
+ try {
+ copyToFile(source, destination);
+ } finally {
+ IOUtils.closeQuietly(source);
+ }
+ }
+
+ /**
+ * Copies bytes from an {@link InputStream} source to a file
+ * destination. The directories up to destination
+ * will be created if they don't already exist. destination
+ * will be overwritten if it already exists.
+ * The {@code source} stream is left open, e.g. for use with {@link java.util.zip.ZipInputStream ZipInputStream}.
+ * See {@link #copyInputStreamToFile(InputStream, File)} for a method that closes the input stream.
+ *
+ * @param source the InputStream to copy bytes from, must not be {@code null}
+ * @param destination the non-directory File to write bytes to
+ * (possibly overwriting), must not be {@code null}
+ * @throws IOException if destination is a directory
+ * @throws IOException if destination cannot be written
+ * @throws IOException if destination needs creating but can't be
+ * @throws IOException if an IO error occurs during copying
+ * @since 2.5
+ */
+ public static void copyToFile(final InputStream source, final File destination) throws IOException {
+ 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);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Deletes a directory recursively.
+ *
+ * @param directory directory to delete
+ * @throws IOException in case deletion is unsuccessful
+ * @throws IllegalArgumentException if {@code directory} does not exist or is not a directory
+ */
+ public static void deleteDirectory(final File directory) throws IOException {
+ if (!directory.exists()) {
+ return;
+ }
+
+ if (!isSymlink(directory)) {
+ cleanDirectory(directory);
+ }
+
+ if (!directory.delete()) {
+ final String message =
+ "Unable to delete directory " + directory + ".";
+ throw new IOException(message);
+ }
+ }
+
+ /**
+ * Deletes a file, never throwing an exception. If file is a directory, delete it and all sub-directories.
+ *
+ * The difference between File.delete() and this method are:
+ *
+ * A directory to be deleted does not have to be empty.
+ * No exceptions are thrown when a file or directory cannot be deleted.
+ *
+ *
+ * @param file file or directory to delete, can be {@code null}
+ * @return {@code true} if the file or directory was deleted, otherwise
+ * {@code false}
+ *
+ * @since 1.4
+ */
+ public static boolean deleteQuietly(final File file) {
+ if (file == null) {
+ return false;
+ }
+ try {
+ if (file.isDirectory()) {
+ cleanDirectory(file);
+ }
+ } catch (final Exception ignored) {
+ }
+
+ try {
+ return file.delete();
+ } catch (final Exception ignored) {
+ return false;
+ }
+ }
+
+ /**
+ * Determines whether the {@code parent} directory contains the {@code child} element (a file or directory).
+ *
+ * Files are normalized before comparison.
+ *
+ *
+ * Edge cases:
+ *
+ * A {@code directory} must not be null: if null, throw IllegalArgumentException
+ * A {@code directory} must be a directory: if not a directory, throw IllegalArgumentException
+ * A directory does not contain itself: return false
+ * A null child file is not contained in any parent: return false
+ *
+ *
+ * @param directory the file to consider as the parent.
+ * @param child the file to consider as the child.
+ * @return true is the candidate leaf is under by the specified composite. False otherwise.
+ * @throws IOException if an IO error occurs while checking the files.
+ * @throws IllegalArgumentException if {@code directory} is null or not a directory.
+ * @see FilenameUtils#directoryContains(String, String)
+ * @since 2.2
+ */
+ public static boolean directoryContains(final File directory, final File child) throws IOException {
+
+ // Fail fast against NullPointerException
+ if (directory == null) {
+ throw new IllegalArgumentException("Directory must not be null");
+ }
+
+ if (!directory.isDirectory()) {
+ throw new IllegalArgumentException("Not a directory: " + directory);
+ }
+
+ if (child == null) {
+ return false;
+ }
+
+ if (!directory.exists() || !child.exists()) {
+ return false;
+ }
+
+ // Canonicalize paths (normalizes relative paths)
+ final String canonicalParent = directory.getCanonicalPath();
+ final String canonicalChild = child.getCanonicalPath();
+
+ return FilenameUtils.directoryContains(canonicalParent, canonicalChild);
+ }
+
+ /**
+ * Cleans a directory without deleting it.
+ *
+ * @param directory directory to clean
+ * @throws IOException in case cleaning is unsuccessful
+ * @throws IllegalArgumentException if {@code directory} does not exist or is not a directory
+ */
+ public static void cleanDirectory(final File directory) throws IOException {
+ final File[] files = verifiedListFiles(directory);
+
+ IOException exception = null;
+ for (final File file : files) {
+ try {
+ forceDelete(file);
+ } catch (final IOException ioe) {
+ exception = ioe;
+ }
+ }
+
+ if (null != exception) {
+ throw exception;
+ }
+ }
+
+ /**
+ * Lists files in a directory, asserting that the supplied directory satisfies exists and is a directory
+ * @param directory The directory to list
+ * @return The files in the directory, never null.
+ * @throws IOException if an I/O error occurs
+ */
+ private static File[] verifiedListFiles(File directory) throws IOException {
+ if (!directory.exists()) {
+ final String message = directory + " does not exist";
+ throw new IllegalArgumentException(message);
+ }
+
+ if (!directory.isDirectory()) {
+ final String message = directory + " is not a directory";
+ throw new IllegalArgumentException(message);
+ }
+
+ final File[] files = directory.listFiles();
+ if (files == null) { // null if security restricted
+ throw new IOException("Failed to list contents of " + directory);
+ }
+ return files;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Waits for NFS to propagate a file creation, imposing a timeout.
+ *
+ * This method repeatedly tests {@link File#exists()} until it returns
+ * true up to the maximum time specified in seconds.
+ *
+ * @param file the file to check, must not be {@code null}
+ * @param seconds the maximum time in seconds to wait
+ * @return true if file exists
+ * @throws NullPointerException if the file is {@code null}
+ */
+ public static boolean waitFor(final File file, final int seconds) {
+ long finishAt = System.currentTimeMillis() + (seconds * 1000L);
+ boolean wasInterrupted = false;
+ try {
+ while (!file.exists()) {
+ long remaining = finishAt - System.currentTimeMillis();
+ if (remaining < 0){
+ return false;
+ }
+ try {
+ Thread.sleep(Math.min(100, remaining));
+ } catch (final InterruptedException ignore) {
+ wasInterrupted = true;
+ } catch (final Exception ex) {
+ break;
+ }
+ }
+ } finally {
+ if (wasInterrupted) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ return true;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Reads the contents of a file into a String.
+ * The file is always closed.
+ *
+ * @param file the file to read, must not be {@code null}
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @return the file contents, never {@code null}
+ * @throws IOException in case of an I/O error
+ * @since 2.3
+ */
+ public static String readFileToString(final File file, final Charset encoding) throws IOException {
+ InputStream in = null;
+ try {
+ in = openInputStream(file);
+ return IOUtils.toString(in, Charsets.toCharset(encoding));
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ /**
+ * Reads the contents of a file into a String. The file is always closed.
+ *
+ * @param file the file to read, must not be {@code null}
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @return the file contents, never {@code null}
+ * @throws IOException in case of an I/O error
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the encoding is not supported.
+ * @since 2.3
+ */
+ public static String readFileToString(final File file, final String encoding) throws IOException {
+ return readFileToString(file, Charsets.toCharset(encoding));
+ }
+
+
+ /**
+ * Reads the contents of a file into a String using the default encoding for the VM.
+ * The file is always closed.
+ *
+ * @param file the file to read, must not be {@code null}
+ * @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
+ */
+ @Deprecated
+ public static String readFileToString(final File file) throws IOException {
+ return readFileToString(file, Charset.defaultCharset());
+ }
+
+ /**
+ * Reads the contents of a file into a byte array.
+ * The file is always closed.
+ *
+ * @param file the file to read, must not be {@code null}
+ * @return the file contents, never {@code null}
+ * @throws IOException in case of an I/O error
+ * @since 1.1
+ */
+ public static byte[] readFileToByteArray(final File file) throws IOException {
+ InputStream in = null;
+ try {
+ in = openInputStream(file);
+ return IOUtils.toByteArray(in); // Do NOT use file.length() - see IO-453
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ /**
+ * Reads the contents of a file line by line to a List of Strings.
+ * The file is always closed.
+ *
+ * @param file the file to read, must not be {@code null}
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @return the list of Strings representing each line in the file, never {@code null}
+ * @throws IOException in case of an I/O error
+ * @since 2.3
+ */
+ public static List readLines(final File file, final Charset encoding) throws IOException {
+ InputStream in = null;
+ try {
+ in = openInputStream(file);
+ return IOUtils.readLines(in, Charsets.toCharset(encoding));
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ /**
+ * Reads the contents of a file line by line to a List of Strings. The file is always closed.
+ *
+ * @param file the file to read, must not be {@code null}
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @return the list of Strings representing each line in the file, never {@code null}
+ * @throws IOException in case of an I/O error
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the encoding is not supported.
+ * @since 1.1
+ */
+ public static List readLines(final File file, final String encoding) throws IOException {
+ return readLines(file, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Reads the contents of a file line by line to a List of Strings using the default encoding for the VM.
+ * The file is always closed.
+ *
+ * @param file the file to read, must not be {@code null}
+ * @return the list of Strings representing each line in the file, never {@code null}
+ * @throws IOException in case of an I/O error
+ * @since 1.3
+ * @deprecated 2.5 use {@link #readLines(File, Charset)} instead
+ */
+ @Deprecated
+ public static List readLines(final File file) throws IOException {
+ return readLines(file, Charset.defaultCharset());
+ }
+
+ /**
+ * Returns an Iterator for the lines in a File.
+ *
+ * This method opens an InputStream for the file.
+ * When you have finished with the iterator you should close the stream
+ * to free internal resources. This can be done by calling the
+ * {@link LineIterator#close()} or
+ * {@link LineIterator#closeQuietly(LineIterator)} method.
+ *
+ * The recommended usage pattern is:
+ *
+ * LineIterator it = FileUtils.lineIterator(file, "UTF-8");
+ * try {
+ * while (it.hasNext()) {
+ * String line = it.nextLine();
+ * /// do something with line
+ * }
+ * } finally {
+ * LineIterator.closeQuietly(iterator);
+ * }
+ *
+ *
+ * If an exception occurs during the creation of the iterator, the
+ * underlying stream is closed.
+ *
+ * @param file the file to open for input, must not be {@code null}
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @return an Iterator of the lines in the file, never {@code null}
+ * @throws IOException in case of an I/O error (file closed)
+ * @since 1.2
+ */
+ public static LineIterator lineIterator(final File file, final String encoding) throws IOException {
+ InputStream in = null;
+ try {
+ in = openInputStream(file);
+ return IOUtils.lineIterator(in, encoding);
+ } catch (final IOException ex) {
+ IOUtils.closeQuietly(in);
+ throw ex;
+ } catch (final RuntimeException ex) {
+ IOUtils.closeQuietly(in);
+ throw ex;
+ }
+ }
+
+ /**
+ * Returns an Iterator for the lines in a File using the default encoding for the VM.
+ *
+ * @param file the file to open for input, must not be {@code null}
+ * @return an Iterator of the lines in the file, never {@code null}
+ * @throws IOException in case of an I/O error (file closed)
+ * @see #lineIterator(File, String)
+ * @since 1.3
+ */
+ public static LineIterator lineIterator(final File file) throws IOException {
+ return lineIterator(file, null);
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Writes a String to a file creating the file if it does not exist.
+ *
+ * NOTE: As from v1.3, the parent directories of the file will be created
+ * if they do not exist.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @throws IOException in case of an I/O error
+ * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
+ * @since 2.4
+ */
+ public static void writeStringToFile(final File file, final String data, final Charset encoding)
+ throws IOException {
+ writeStringToFile(file, data, encoding, false);
+ }
+
+ /**
+ * Writes a String to a file creating the file if it does not exist.
+ *
+ * NOTE: As from v1.3, the parent directories of the file will be created
+ * if they do not exist.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @throws IOException in case of an I/O error
+ * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
+ */
+ public static void writeStringToFile(final File file, final String data, final String encoding) throws IOException {
+ writeStringToFile(file, data, encoding, false);
+ }
+
+ /**
+ * Writes a String to a file creating the file if it does not exist.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @param append if {@code true}, then the String will be added to the
+ * end of the file rather than overwriting
+ * @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 {
+ 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);
+ }
+ }
+
+ /**
+ * Writes a String to a file creating the file if it does not exist.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @param append if {@code true}, then the String will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the encoding is not supported by the VM
+ * @since 2.1
+ */
+ public static void writeStringToFile(final File file, final String data, final String encoding,
+ final boolean append) throws IOException {
+ writeStringToFile(file, data, Charsets.toCharset(encoding), append);
+ }
+
+ /**
+ * Writes a String to a file creating the file if it does not exist using the default encoding for the VM.
+ *
+ * @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
+ */
+ @Deprecated
+ public static void writeStringToFile(final File file, final String data) throws IOException {
+ writeStringToFile(file, data, Charset.defaultCharset(), false);
+ }
+
+ /**
+ * Writes a String to a file creating the file if it does not exist using the default encoding for the VM.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param append if {@code true}, then the String will be added to the
+ * 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
+ */
+ @Deprecated
+ public static void writeStringToFile(final File file, final String data, final boolean append) throws IOException {
+ writeStringToFile(file, data, Charset.defaultCharset(), append);
+ }
+
+ /**
+ * Writes a CharSequence to a file creating the file if it does not exist using the default encoding for the VM.
+ *
+ * @param file the file to write
+ * @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
+ */
+ @Deprecated
+ public static void write(final File file, final CharSequence data) throws IOException {
+ write(file, data, Charset.defaultCharset(), false);
+ }
+
+ /**
+ * Writes a CharSequence to a file creating the file if it does not exist using the default encoding for the VM.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param append if {@code true}, then the data will be added to the
+ * 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
+ */
+ @Deprecated
+ public static void write(final File file, final CharSequence data, final boolean append) throws IOException {
+ write(file, data, Charset.defaultCharset(), append);
+ }
+
+ /**
+ * Writes a CharSequence to a file creating the file if it does not exist.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @throws IOException in case of an I/O error
+ * @since 2.3
+ */
+ public static void write(final File file, final CharSequence data, final Charset encoding) throws IOException {
+ write(file, data, encoding, false);
+ }
+
+ /**
+ * Writes a CharSequence to a file creating the file if it does not exist.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @throws IOException in case of an I/O error
+ * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
+ * @since 2.0
+ */
+ public static void write(final File file, final CharSequence data, final String encoding) throws IOException {
+ write(file, data, encoding, false);
+ }
+
+ /**
+ * Writes a CharSequence to a file creating the file if it does not exist.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @param append if {@code true}, then the data will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @since 2.3
+ */
+ public static void write(final File file, final CharSequence data, final Charset encoding, final boolean append)
+ throws IOException {
+ final String str = data == null ? null : data.toString();
+ writeStringToFile(file, str, encoding, append);
+ }
+
+ /**
+ * Writes a CharSequence to a file creating the file if it does not exist.
+ *
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @param append if {@code true}, then the data will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the encoding is not supported by the VM
+ * @since 2.1
+ */
+ public static void write(final File file, final CharSequence data, final String encoding, final boolean append)
+ throws IOException {
+ write(file, data, Charsets.toCharset(encoding), append);
+ }
+
+ /**
+ * Writes a byte array to a file creating the file if it does not exist.
+ *
+ * NOTE: As from v1.3, the parent directories of the file will be created
+ * if they do not exist.
+ *
+ * @param file the file to write to
+ * @param data the content to write to the file
+ * @throws IOException in case of an I/O error
+ * @since 1.1
+ */
+ public static void writeByteArrayToFile(final File file, final byte[] data) throws IOException {
+ writeByteArrayToFile(file, data, false);
+ }
+
+ /**
+ * Writes a byte array to a file creating the file if it does not exist.
+ *
+ * @param file the file to write to
+ * @param data the content to write to the file
+ * @param append if {@code true}, then bytes will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @since 2.1
+ */
+ public static void writeByteArrayToFile(final File file, final byte[] data, final boolean append)
+ throws IOException {
+ writeByteArrayToFile(file, data, 0, data.length, append);
+ }
+
+ /**
+ * Writes {@code len} bytes from the specified byte array starting
+ * at offset {@code off} to a file, creating the file if it does
+ * not exist.
+ *
+ * @param file the file to write to
+ * @param data the content to write to the file
+ * @param off the start offset in the data
+ * @param len the number of bytes to write
+ * @throws IOException in case of an I/O error
+ * @since 2.5
+ */
+ public static void writeByteArrayToFile(final File file, final byte[] data, final int off, final int len)
+ throws IOException {
+ writeByteArrayToFile(file, data, off, len, false);
+ }
+
+ /**
+ * Writes {@code len} bytes from the specified byte array starting
+ * at offset {@code off} to a file, creating the file if it does
+ * not exist.
+ *
+ * @param file the file to write to
+ * @param data the content to write to the file
+ * @param off the start offset in the data
+ * @param len the number of bytes to write
+ * @param append if {@code true}, then bytes will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @since 2.5
+ */
+ public static void writeByteArrayToFile(final File file, final byte[] data, final int off, final int len,
+ final boolean append) throws IOException {
+ 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);
+ }
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * the specified File line by line.
+ * The specified character encoding and the default line ending will be used.
+ *
+ * NOTE: As from v1.3, the parent directories of the file will be created
+ * if they do not exist.
+ *
+ * @param file the file to write to
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @param lines the lines to write, {@code null} entries produce blank lines
+ * @throws IOException in case of an I/O error
+ * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
+ * @since 1.1
+ */
+ public static void writeLines(final File file, final String encoding, final Collection> lines)
+ throws IOException {
+ writeLines(file, encoding, lines, null, false);
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * the specified File line by line, optionally appending.
+ * The specified character encoding and the default line ending will be used.
+ *
+ * @param file the file to write to
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @param lines the lines to write, {@code null} entries produce blank lines
+ * @param append if {@code true}, then the lines will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
+ * @since 2.1
+ */
+ public static void writeLines(final File file, final String encoding, final Collection> lines,
+ final boolean append) throws IOException {
+ writeLines(file, encoding, lines, null, append);
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * the specified File line by line.
+ * The default VM encoding and the default line ending will be used.
+ *
+ * @param file the file to write to
+ * @param lines the lines to write, {@code null} entries produce blank lines
+ * @throws IOException in case of an I/O error
+ * @since 1.3
+ */
+ public static void writeLines(final File file, final Collection> lines) throws IOException {
+ writeLines(file, null, lines, null, false);
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * the specified File line by line.
+ * The default VM encoding and the default line ending will be used.
+ *
+ * @param file the file to write to
+ * @param lines the lines to write, {@code null} entries produce blank lines
+ * @param append if {@code true}, then the lines will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @since 2.1
+ */
+ public static void writeLines(final File file, final Collection> lines, final boolean append) throws IOException {
+ writeLines(file, null, lines, null, append);
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * the specified File line by line.
+ * The specified character encoding and the line ending will be used.
+ *
+ * NOTE: As from v1.3, the parent directories of the file will be created
+ * if they do not exist.
+ *
+ * @param file the file to write to
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @param lines the lines to write, {@code null} entries produce blank lines
+ * @param lineEnding the line separator to use, {@code null} is system default
+ * @throws IOException in case of an I/O error
+ * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
+ * @since 1.1
+ */
+ public static void writeLines(final File file, final String encoding, final Collection> lines,
+ final String lineEnding) throws IOException {
+ writeLines(file, encoding, lines, lineEnding, false);
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * the specified File line by line.
+ * The specified character encoding and the line ending will be used.
+ *
+ * @param file the file to write to
+ * @param encoding the encoding to use, {@code null} means platform default
+ * @param lines the lines to write, {@code null} entries produce blank lines
+ * @param lineEnding the line separator to use, {@code null} is system default
+ * @param append if {@code true}, then the lines will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
+ * @since 2.1
+ */
+ public static void writeLines(final File file, final String encoding, final Collection> lines,
+ final String lineEnding, final boolean append) throws IOException {
+ 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);
+ }
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * the specified File line by line.
+ * The default VM encoding and the specified line ending will be used.
+ *
+ * @param file the file to write to
+ * @param lines the lines to write, {@code null} entries produce blank lines
+ * @param lineEnding the line separator to use, {@code null} is system default
+ * @throws IOException in case of an I/O error
+ * @since 1.3
+ */
+ public static void writeLines(final File file, final Collection> lines, final String lineEnding)
+ throws IOException {
+ writeLines(file, null, lines, lineEnding, false);
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * the specified File line by line.
+ * The default VM encoding and the specified line ending will be used.
+ *
+ * @param file the file to write to
+ * @param lines the lines to write, {@code null} entries produce blank lines
+ * @param lineEnding the line separator to use, {@code null} is system default
+ * @param append if {@code true}, then the lines will be added to the
+ * end of the file rather than overwriting
+ * @throws IOException in case of an I/O error
+ * @since 2.1
+ */
+ public static void writeLines(final File file, final Collection> lines, final String lineEnding,
+ final boolean append) throws IOException {
+ writeLines(file, null, lines, lineEnding, append);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Deletes a file. If file is a directory, delete it and all sub-directories.
+ *
+ * The difference between File.delete() and this method are:
+ *
+ * A directory to be deleted does not have to be empty.
+ * You get exceptions when a file or directory cannot be deleted.
+ * (java.io.File methods returns a boolean)
+ *
+ *
+ * @param file file or directory to delete, must not be {@code null}
+ * @throws NullPointerException if the directory is {@code null}
+ * @throws FileNotFoundException if the file was not found
+ * @throws IOException in case deletion is unsuccessful
+ */
+ public static void forceDelete(final File file) throws IOException {
+ if (file.isDirectory()) {
+ deleteDirectory(file);
+ } else {
+ final boolean filePresent = file.exists();
+ if (!file.delete()) {
+ if (!filePresent) {
+ throw new FileNotFoundException("File does not exist: " + file);
+ }
+ final String message =
+ "Unable to delete file: " + file;
+ throw new IOException(message);
+ }
+ }
+ }
+
+ /**
+ * Schedules a file to be deleted when JVM exits.
+ * If file is directory delete it and all sub-directories.
+ *
+ * @param file file or directory to delete, must not be {@code null}
+ * @throws NullPointerException if the file is {@code null}
+ * @throws IOException in case deletion is unsuccessful
+ */
+ public static void forceDeleteOnExit(final File file) throws IOException {
+ if (file.isDirectory()) {
+ deleteDirectoryOnExit(file);
+ } else {
+ file.deleteOnExit();
+ }
+ }
+
+ /**
+ * Schedules a directory recursively for deletion on JVM exit.
+ *
+ * @param directory directory to delete, must not be {@code null}
+ * @throws NullPointerException if the directory is {@code null}
+ * @throws IOException in case deletion is unsuccessful
+ */
+ private static void deleteDirectoryOnExit(final File directory) throws IOException {
+ if (!directory.exists()) {
+ return;
+ }
+
+ directory.deleteOnExit();
+ if (!isSymlink(directory)) {
+ cleanDirectoryOnExit(directory);
+ }
+ }
+
+ /**
+ * Cleans a directory without deleting it.
+ *
+ * @param directory directory to clean, must not be {@code null}
+ * @throws NullPointerException if the directory is {@code null}
+ * @throws IOException in case cleaning is unsuccessful
+ */
+ private static void cleanDirectoryOnExit(final File directory) throws IOException {
+ final File[] files = verifiedListFiles(directory);
+
+ IOException exception = null;
+ for (final File file : files) {
+ try {
+ forceDeleteOnExit(file);
+ } catch (final IOException ioe) {
+ exception = ioe;
+ }
+ }
+
+ if (null != exception) {
+ throw exception;
+ }
+ }
+
+ /**
+ * Makes a directory, including any necessary but nonexistent parent
+ * directories. If a file already exists with specified name but it is
+ * not a directory then an IOException is thrown.
+ * If the directory cannot be created (or does not already exist)
+ * then an IOException is thrown.
+ *
+ * @param directory directory to create, must not be {@code null}
+ * @throws NullPointerException if the directory is {@code null}
+ * @throws IOException if the directory cannot be created or the file already exists but is not a directory
+ */
+ public static void forceMkdir(final File directory) throws IOException {
+ if (directory.exists()) {
+ if (!directory.isDirectory()) {
+ final String message =
+ "File "
+ + directory
+ + " exists and is "
+ + "not a directory. Unable to create directory.";
+ throw new IOException(message);
+ }
+ } else {
+ if (!directory.mkdirs()) {
+ // Double-check that some other thread or process hasn't made
+ // the directory in the background
+ if (!directory.isDirectory()) {
+ final String message =
+ "Unable to create directory " + directory;
+ throw new IOException(message);
+ }
+ }
+ }
+ }
+
+ /**
+ * Makes any necessary but nonexistent parent directories for a given File. If the parent directory cannot be
+ * created then an IOException is thrown.
+ *
+ * @param file file with parent to create, must not be {@code null}
+ * @throws NullPointerException if the file is {@code null}
+ * @throws IOException if the parent directory cannot be created
+ * @since 2.5
+ */
+ public static void forceMkdirParent(final File file) throws IOException {
+ final File parent = file.getParentFile();
+ if (parent == null) {
+ return;
+ }
+ forceMkdir(parent);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns the size of the specified file or directory. If the provided
+ * {@link File} is a regular file, then the file's length is returned.
+ * If the argument is a directory, then the size of the directory is
+ * calculated recursively. If a directory or subdirectory is security
+ * restricted, its size will not be included.
+ *
+ * Note that overflow is not detected, and the return value may be negative if
+ * overflow occurs. See {@link #sizeOfAsBigInteger(File)} for an alternative
+ * method that does not overflow.
+ *
+ * @param file the regular file or directory to return the size
+ * of (must not be {@code null}).
+ *
+ * @return the length of the file, or recursive size of the directory,
+ * provided (in bytes).
+ *
+ * @throws NullPointerException if the file is {@code null}
+ * @throws IllegalArgumentException if the file does not exist.
+ *
+ * @since 2.0
+ */
+ public static long sizeOf(final File file) {
+
+ if (!file.exists()) {
+ final String message = file + " does not exist";
+ throw new IllegalArgumentException(message);
+ }
+
+ if (file.isDirectory()) {
+ return sizeOfDirectory0(file); // private method; expects directory
+ } else {
+ return file.length();
+ }
+
+ }
+
+ /**
+ * Returns the size of the specified file or directory. If the provided
+ * {@link File} is a regular file, then the file's length is returned.
+ * If the argument is a directory, then the size of the directory is
+ * calculated recursively. If a directory or subdirectory is security
+ * restricted, its size will not be included.
+ *
+ * @param file the regular file or directory to return the size
+ * of (must not be {@code null}).
+ *
+ * @return the length of the file, or recursive size of the directory,
+ * provided (in bytes).
+ *
+ * @throws NullPointerException if the file is {@code null}
+ * @throws IllegalArgumentException if the file does not exist.
+ *
+ * @since 2.4
+ */
+ public static BigInteger sizeOfAsBigInteger(final File file) {
+
+ if (!file.exists()) {
+ final String message = file + " does not exist";
+ throw new IllegalArgumentException(message);
+ }
+
+ if (file.isDirectory()) {
+ return sizeOfDirectoryBig0(file); // internal method
+ } else {
+ return BigInteger.valueOf(file.length());
+ }
+
+ }
+
+ /**
+ * Counts the size of a directory recursively (sum of the length of all files).
+ *
+ * Note that overflow is not detected, and the return value may be negative if
+ * overflow occurs. See {@link #sizeOfDirectoryAsBigInteger(File)} for an alternative
+ * method that does not overflow.
+ *
+ * @param directory directory to inspect, must not be {@code null}
+ * @return size of directory in bytes, 0 if directory is security restricted, a negative number when the real total
+ * is greater than {@link Long#MAX_VALUE}.
+ * @throws NullPointerException if the directory is {@code null}
+ */
+ public static long sizeOfDirectory(final File directory) {
+ checkDirectory(directory);
+ return sizeOfDirectory0(directory);
+ }
+
+ // Private method, must be invoked will a directory parameter
+
+ /**
+ * the size of a director
+ * @param directory the directory to check
+ * @return the size
+ */
+ private static long sizeOfDirectory0(final File directory) {
+ final File[] files = directory.listFiles();
+ if (files == null) { // null if security restricted
+ return 0L;
+ }
+ long size = 0;
+
+ for (final File file : files) {
+ try {
+ if (!isSymlink(file)) {
+ size += sizeOf0(file); // internal method
+ if (size < 0) {
+ break;
+ }
+ }
+ } catch (final IOException ioe) {
+ // Ignore exceptions caught when asking if a File is a symlink.
+ }
+ }
+
+ return size;
+ }
+
+ // Internal method - does not check existence
+
+ /**
+ * the size of a file
+ * @param file the file to check
+ * @return the size of the fil
+ */
+ private static long sizeOf0(File file) {
+ if (file.isDirectory()) {
+ return sizeOfDirectory0(file);
+ } else {
+ return file.length(); // will be 0 if file does not exist
+ }
+ }
+
+ /**
+ * Counts the size of a directory recursively (sum of the length of all files).
+ *
+ * @param directory directory to inspect, must not be {@code null}
+ * @return size of directory in bytes, 0 if directory is security restricted.
+ * @throws NullPointerException if the directory is {@code null}
+ * @since 2.4
+ */
+ public static BigInteger sizeOfDirectoryAsBigInteger(final File directory) {
+ checkDirectory(directory);
+ return sizeOfDirectoryBig0(directory);
+ }
+
+ // Must be called with a directory
+
+ /**
+ * Finds the size of a directory
+ *
+ * @param directory The directory
+ * @return the size
+ */
+ private static BigInteger sizeOfDirectoryBig0(final File directory) {
+ final File[] files = directory.listFiles();
+ if (files == null) { // null if security restricted
+ return BigInteger.ZERO;
+ }
+ BigInteger size = BigInteger.ZERO;
+
+ for (final File file : files) {
+ try {
+ if (!isSymlink(file)) {
+ size = size.add(sizeOfBig0(file));
+ }
+ } catch (final IOException ioe) {
+ // Ignore exceptions caught when asking if a File is a symlink.
+ }
+ }
+
+ return size;
+ }
+
+ // internal method; if file does not exist will return 0
+
+ /**
+ * Returns the sid of a file
+ * @param fileOrDir The file
+ * @return the size
+ */
+ private static BigInteger sizeOfBig0(final File fileOrDir) {
+ if (fileOrDir.isDirectory()) {
+ return sizeOfDirectoryBig0(fileOrDir);
+ } else {
+ return BigInteger.valueOf(fileOrDir.length());
+ }
+ }
+
+ /**
+ * Checks that the given {@code File} exists and is a directory.
+ *
+ * @param directory The {@code File} to check.
+ * @throws IllegalArgumentException if the given {@code File} does not exist or is not a directory.
+ */
+ private static void checkDirectory(final File directory) {
+ if (!directory.exists()) {
+ throw new IllegalArgumentException(directory + " does not exist");
+ }
+ if (!directory.isDirectory()) {
+ throw new IllegalArgumentException(directory + " is not a directory");
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Tests if the specified File is newer than the reference
+ * File.
+ *
+ * @param file the File of which the modification date must
+ * be compared, must not be {@code null}
+ * @param reference the File of which the modification date
+ * is used, must not be {@code null}
+ * @return true if the File exists and has been modified more
+ * recently than the reference File
+ * @throws IllegalArgumentException if the file is {@code null}
+ * @throws IllegalArgumentException if the reference file is {@code null} or doesn't exist
+ */
+ public static boolean isFileNewer(final File file, final File reference) {
+ if (reference == null) {
+ throw new IllegalArgumentException("No specified reference file");
+ }
+ if (!reference.exists()) {
+ throw new IllegalArgumentException("The reference file '"
+ + reference + "' doesn't exist");
+ }
+ return isFileNewer(file, reference.lastModified());
+ }
+
+ /**
+ * Tests if the specified File is newer than the specified
+ * Date.
+ *
+ * @param file the File of which the modification date
+ * must be compared, must not be {@code null}
+ * @param date the date reference, must not be {@code null}
+ * @return true if the File exists and has been modified
+ * after the given Date.
+ * @throws IllegalArgumentException if the file is {@code null}
+ * @throws IllegalArgumentException if the date is {@code null}
+ */
+ public static boolean isFileNewer(final File file, final Date date) {
+ if (date == null) {
+ throw new IllegalArgumentException("No specified date");
+ }
+ return isFileNewer(file, date.getTime());
+ }
+
+ /**
+ * Tests if the specified File is newer than the specified
+ * time reference.
+ *
+ * @param file the File of which the modification date must
+ * be compared, must not be {@code null}
+ * @param timeMillis the time reference measured in milliseconds since the
+ * epoch (00:00:00 GMT, January 1, 1970)
+ * @return true if the File exists and has been modified after
+ * the given time reference.
+ * @throws IllegalArgumentException if the file is {@code null}
+ */
+ public static boolean isFileNewer(final File file, final long timeMillis) {
+ if (file == null) {
+ throw new IllegalArgumentException("No specified file");
+ }
+ if (!file.exists()) {
+ return false;
+ }
+ return file.lastModified() > timeMillis;
+ }
+
+
+ //-----------------------------------------------------------------------
+ /**
+ * Tests if the specified File is older than the reference
+ * File.
+ *
+ * @param file the File of which the modification date must
+ * be compared, must not be {@code null}
+ * @param reference the File of which the modification date
+ * is used, must not be {@code null}
+ * @return true if the File exists and has been modified before
+ * the reference File
+ * @throws IllegalArgumentException if the file is {@code null}
+ * @throws IllegalArgumentException if the reference file is {@code null} or doesn't exist
+ */
+ public static boolean isFileOlder(final File file, final File reference) {
+ if (reference == null) {
+ throw new IllegalArgumentException("No specified reference file");
+ }
+ if (!reference.exists()) {
+ throw new IllegalArgumentException("The reference file '"
+ + reference + "' doesn't exist");
+ }
+ return isFileOlder(file, reference.lastModified());
+ }
+
+ /**
+ * Tests if the specified File is older than the specified
+ * Date.
+ *
+ * @param file the File of which the modification date
+ * must be compared, must not be {@code null}
+ * @param date the date reference, must not be {@code null}
+ * @return true if the File exists and has been modified
+ * before the given Date.
+ * @throws IllegalArgumentException if the file is {@code null}
+ * @throws IllegalArgumentException if the date is {@code null}
+ */
+ public static boolean isFileOlder(final File file, final Date date) {
+ if (date == null) {
+ throw new IllegalArgumentException("No specified date");
+ }
+ return isFileOlder(file, date.getTime());
+ }
+
+ /**
+ * Tests if the specified File is older than the specified
+ * time reference.
+ *
+ * @param file the File of which the modification date must
+ * be compared, must not be {@code null}
+ * @param timeMillis the time reference measured in milliseconds since the
+ * epoch (00:00:00 GMT, January 1, 1970)
+ * @return true if the File exists and has been modified before
+ * the given time reference.
+ * @throws IllegalArgumentException if the file is {@code null}
+ */
+ public static boolean isFileOlder(final File file, final long timeMillis) {
+ if (file == null) {
+ throw new IllegalArgumentException("No specified file");
+ }
+ if (!file.exists()) {
+ return false;
+ }
+ return file.lastModified() < timeMillis;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Computes the checksum of a file using the CRC32 checksum routine.
+ * The value of the checksum is returned.
+ *
+ * @param file the file to checksum, must not be {@code null}
+ * @return the checksum value
+ * @throws NullPointerException if the file or checksum is {@code null}
+ * @throws IllegalArgumentException if the file is a directory
+ * @throws IOException if an IO error occurs reading the file
+ * @since 1.3
+ */
+ public static long checksumCRC32(final File file) throws IOException {
+ final CRC32 crc = new CRC32();
+ checksum(file, crc);
+ return crc.getValue();
+ }
+
+ /**
+ * Computes the checksum of a file using the specified checksum object.
+ * Multiple files may be checked using one Checksum instance
+ * if desired simply by reusing the same checksum object.
+ * For example:
+ *
+ * long csum = FileUtils.checksum(file, new CRC32()).getValue();
+ *
+ *
+ * @param file the file to checksum, must not be {@code null}
+ * @param checksum the checksum object to be used, must not be {@code null}
+ * @return the checksum specified, updated with the content of the file
+ * @throws NullPointerException if the file or checksum is {@code null}
+ * @throws IllegalArgumentException if the file is a directory
+ * @throws IOException if an IO error occurs reading the file
+ * @since 1.3
+ */
+ public static Checksum checksum(final File file, final Checksum checksum) throws IOException {
+ if (file.isDirectory()) {
+ throw new IllegalArgumentException("Checksums can't be computed on directories");
+ }
+ InputStream in = null;
+ try {
+ in = new CheckedInputStream(new FileInputStream(file), checksum);
+ IOUtils.copy(in, new NullOutputStream());
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ return checksum;
+ }
+
+ /**
+ * Moves a directory.
+ *
+ * When the destination directory is on another file system, do a "copy and delete".
+ *
+ * @param srcDir the directory to be moved
+ * @param destDir the destination directory
+ * @throws NullPointerException if source or destination is {@code null}
+ * @throws FileExistsException if the destination directory exists
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs moving the file
+ * @since 1.4
+ */
+ public static void moveDirectory(final File srcDir, final File destDir) throws IOException {
+ if (srcDir == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (destDir == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (!srcDir.exists()) {
+ throw new FileNotFoundException("Source '" + srcDir + "' does not exist");
+ }
+ if (!srcDir.isDirectory()) {
+ throw new IOException("Source '" + srcDir + "' is not a directory");
+ }
+ if (destDir.exists()) {
+ throw new FileExistsException("Destination '" + destDir + "' already exists");
+ }
+ final boolean rename = srcDir.renameTo(destDir);
+ if (!rename) {
+ if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath() + File.separator)) {
+ throw new IOException("Cannot move directory: " + srcDir + " to a subdirectory of itself: " + destDir);
+ }
+ copyDirectory(srcDir, destDir);
+ deleteDirectory(srcDir);
+ if (srcDir.exists()) {
+ throw new IOException("Failed to delete original directory '" + srcDir +
+ "' after copy to '" + destDir + "'");
+ }
+ }
+ }
+
+ /**
+ * Moves a directory to another directory.
+ *
+ * @param src the file to be moved
+ * @param destDir the destination file
+ * @param createDestDir If {@code true} create the destination directory,
+ * otherwise if {@code false} throw an IOException
+ * @throws NullPointerException if source or destination is {@code null}
+ * @throws FileExistsException if the directory exists in the destination directory
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs moving the file
+ * @since 1.4
+ */
+ public static void moveDirectoryToDirectory(final File src, final File destDir, final boolean createDestDir)
+ throws IOException {
+ if (src == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (destDir == null) {
+ throw new NullPointerException("Destination directory must not be null");
+ }
+ if (!destDir.exists() && createDestDir) {
+ destDir.mkdirs();
+ }
+ if (!destDir.exists()) {
+ throw new FileNotFoundException("Destination directory '" + destDir +
+ "' does not exist [createDestDir=" + createDestDir + "]");
+ }
+ if (!destDir.isDirectory()) {
+ throw new IOException("Destination '" + destDir + "' is not a directory");
+ }
+ moveDirectory(src, new File(destDir, src.getName()));
+
+ }
+
+ /**
+ * Moves a file.
+ *
+ * When the destination file is on another file system, do a "copy and delete".
+ *
+ * @param srcFile the file to be moved
+ * @param destFile the destination file
+ * @throws NullPointerException if source or destination is {@code null}
+ * @throws FileExistsException if the destination file exists
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs moving the file
+ * @since 1.4
+ */
+ public static void moveFile(final File srcFile, final File destFile) throws IOException {
+ if (srcFile == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (destFile == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (!srcFile.exists()) {
+ throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
+ }
+ if (srcFile.isDirectory()) {
+ throw new IOException("Source '" + srcFile + "' is a directory");
+ }
+ if (destFile.exists()) {
+ throw new FileExistsException("Destination '" + destFile + "' already exists");
+ }
+ if (destFile.isDirectory()) {
+ throw new IOException("Destination '" + destFile + "' is a directory");
+ }
+ final boolean rename = srcFile.renameTo(destFile);
+ if (!rename) {
+ copyFile(srcFile, destFile);
+ if (!srcFile.delete()) {
+ FileUtils.deleteQuietly(destFile);
+ throw new IOException("Failed to delete original file '" + srcFile +
+ "' after copy to '" + destFile + "'");
+ }
+ }
+ }
+
+ /**
+ * Moves a file to a directory.
+ *
+ * @param srcFile the file to be moved
+ * @param destDir the destination file
+ * @param createDestDir If {@code true} create the destination directory,
+ * otherwise if {@code false} throw an IOException
+ * @throws NullPointerException if source or destination is {@code null}
+ * @throws FileExistsException if the destination file exists
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs moving the file
+ * @since 1.4
+ */
+ public static void moveFileToDirectory(final File srcFile, final File destDir, final boolean createDestDir)
+ throws IOException {
+ if (srcFile == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (destDir == null) {
+ throw new NullPointerException("Destination directory must not be null");
+ }
+ if (!destDir.exists() && createDestDir) {
+ destDir.mkdirs();
+ }
+ if (!destDir.exists()) {
+ throw new FileNotFoundException("Destination directory '" + destDir +
+ "' does not exist [createDestDir=" + createDestDir + "]");
+ }
+ if (!destDir.isDirectory()) {
+ throw new IOException("Destination '" + destDir + "' is not a directory");
+ }
+ moveFile(srcFile, new File(destDir, srcFile.getName()));
+ }
+
+ /**
+ * Moves a file or directory to the destination directory.
+ *
+ * When the destination is on another file system, do a "copy and delete".
+ *
+ * @param src the file or directory to be moved
+ * @param destDir the destination directory
+ * @param createDestDir If {@code true} create the destination directory,
+ * otherwise if {@code false} throw an IOException
+ * @throws NullPointerException if source or destination is {@code null}
+ * @throws FileExistsException if the directory or file exists in the destination directory
+ * @throws IOException if source or destination is invalid
+ * @throws IOException if an IO error occurs moving the file
+ * @since 1.4
+ */
+ public static void moveToDirectory(final File src, final File destDir, final boolean createDestDir)
+ throws IOException {
+ if (src == null) {
+ throw new NullPointerException("Source must not be null");
+ }
+ if (destDir == null) {
+ throw new NullPointerException("Destination must not be null");
+ }
+ if (!src.exists()) {
+ throw new FileNotFoundException("Source '" + src + "' does not exist");
+ }
+ if (src.isDirectory()) {
+ moveDirectoryToDirectory(src, destDir, createDestDir);
+ } else {
+ moveFileToDirectory(src, destDir, createDestDir);
+ }
+ }
+
+ /**
+ * Determines whether the specified file is a Symbolic Link rather than an actual file.
+ *
+ * Will not return true if there is a Symbolic Link anywhere in the path,
+ * only if the specific file is.
+ *
+ * When using jdk1.7, this method delegates to {@code boolean java.nio.file.Files.isSymbolicLink(Path path)}
+ *
+ * Note: the current implementation always returns {@code false} if running on
+ * jkd1.6 and the system is detected as Windows using {@link FilenameUtils#isSystemWindows()}
+ *
+ * For code that runs on Java 1.7 or later, use the following method instead:
+ *
+ * {@code boolean java.nio.file.Files.isSymbolicLink(Path path)}
+ * @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
+ * @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");
+ }
+ if (FilenameUtils.isSystemWindows()) {
+ return false;
+ }
+ File fileInCanonicalDir = null;
+ if (file.getParent() == null) {
+ fileInCanonicalDir = file;
+ } else {
+ final File canonicalDir = file.getParentFile().getCanonicalFile();
+ fileInCanonicalDir = new File(canonicalDir, file.getName());
+ }
+
+ if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())) {
+ return isBrokenSymlink(file);
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Determines if the specified file is possibly a broken symbolic link.
+ *
+ * @param file the file to check
+
+ * @return true if the file is a Symbolic Link
+ * @throws IOException if an IO error occurs while checking the file
+ */
+ private static boolean isBrokenSymlink(final File file) throws IOException {
+ // if file exists then if it is a symlink it's not broken
+ if (file.exists()) {
+ return false;
+ }
+ // a broken symlink will show up in the list of files of its parent directory
+ final File canon = file.getCanonicalFile();
+ File parentDir = canon.getParentFile();
+ if (parentDir == null || !parentDir.exists()) {
+ return false;
+ }
+
+ // is it worthwhile to create a FileFilterUtil method for this?
+ // is it worthwhile to create an "identity" IOFileFilter for this?
+ File[] fileInDir = parentDir.listFiles(
+ new FileFilter() {
+ public boolean accept(File aFile) {
+ return aFile.equals(canon);
+ }
+ }
+ );
+ return fileInDir != null && fileInDir.length > 0;
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FilenameUtils.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FilenameUtils.java"
new file mode 100644
index 0000000000000000000000000000000000000000..0ccbe31516142b0b4cd09cdcabe42b0e868042a0
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/FilenameUtils.java"
@@ -0,0 +1,1452 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Stack;
+
+/**
+ * General filename and filepath manipulation utilities.
+ *
+ * When dealing with filenames you can hit problems when moving from a Windows
+ * based development machine to a Unix based production machine.
+ * This class aims to help avoid those problems.
+ *
+ * NOTE : You may be able to avoid using this class entirely simply by
+ * using JDK {@link java.io.File File} objects and the two argument constructor
+ * {@link java.io.File#File(java.io.File, java.lang.String) File(File,String)}.
+ *
+ * Most methods on this class are designed to work the same on both Unix and Windows.
+ * Those that don't include 'System', 'Unix' or 'Windows' in their name.
+ *
+ * Most methods recognise both separators (forward and back), and both
+ * sets of prefixes. See the javadoc of each method for details.
+ *
+ * This class defines six components within a filename
+ * (example C:\dev\project\file.txt):
+ *
+ * the prefix - C:\
+ * the path - dev\project\
+ * the full path - C:\dev\project\
+ * the name - file.txt
+ * the base name - file
+ * the extension - txt
+ *
+ * Note that this class works best if directory filenames end with a separator.
+ * If you omit the last separator, it is impossible to determine if the filename
+ * corresponds to a file or a directory. As a result, we have chosen to say
+ * it corresponds to a file.
+ *
+ * This class only supports Unix and Windows style names.
+ * Prefixes are matched as follows:
+ *
+ * Windows:
+ * a\b\c.txt --> "" --> relative
+ * \a\b\c.txt --> "\" --> current drive absolute
+ * C:a\b\c.txt --> "C:" --> drive relative
+ * C:\a\b\c.txt --> "C:\" --> absolute
+ * \\server\a\b\c.txt --> "\\server\" --> UNC
+ *
+ * Unix:
+ * a/b/c.txt --> "" --> relative
+ * /a/b/c.txt --> "/" --> absolute
+ * ~/a/b/c.txt --> "~/" --> current user
+ * ~ --> "~/" --> current user (slash added)
+ * ~user/a/b/c.txt --> "~user/" --> named user
+ * ~user --> "~user/" --> named user (slash added)
+ *
+ * Both prefix styles are matched always, irrespective of the machine that you are
+ * currently running on.
+ *
+ * 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 {
+
+ private static final int NOT_FOUND = -1;
+
+ /**
+ * The extension separator character.
+ * @since 1.4
+ */
+ public static final char EXTENSION_SEPARATOR = '.';
+
+ /**
+ * The extension separator String.
+ * @since 1.4
+ */
+ public static final String EXTENSION_SEPARATOR_STR = Character.toString(EXTENSION_SEPARATOR);
+
+ /**
+ * The Unix separator character.
+ */
+ private static final char UNIX_SEPARATOR = '/';
+
+ /**
+ * The Windows separator character.
+ */
+ private static final char WINDOWS_SEPARATOR = '\\';
+
+ /**
+ * The system separator character.
+ */
+ private static final char SYSTEM_SEPARATOR = File.separatorChar;
+
+ /**
+ * The separator character that is the opposite of the system separator.
+ */
+ private static final char OTHER_SEPARATOR;
+ static {
+ if (isSystemWindows()) {
+ OTHER_SEPARATOR = UNIX_SEPARATOR;
+ } else {
+ OTHER_SEPARATOR = WINDOWS_SEPARATOR;
+ }
+ }
+
+ /**
+ * Instances should NOT be constructed in standard programming.
+ */
+ public FilenameUtils() {
+ super();
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Determines if Windows file system is in use.
+ *
+ * @return true if the system is Windows
+ */
+ static boolean isSystemWindows() {
+ return SYSTEM_SEPARATOR == WINDOWS_SEPARATOR;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if the character is a separator.
+ *
+ * @param ch the character to check
+ * @return true if it is a separator character
+ */
+ private static boolean isSeparator(final char ch) {
+ return ch == UNIX_SEPARATOR || ch == WINDOWS_SEPARATOR;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Normalizes a path, removing double and single dot path steps.
+ *
+ * This method normalizes a path to a standard format.
+ * The input may contain separators in either Unix or Windows format.
+ * The output will contain separators in the format of the system.
+ *
+ * A trailing slash will be retained.
+ * A double slash will be merged to a single slash (but UNC names are handled).
+ * A single dot path segment will be removed.
+ * A double dot will cause that path segment and the one before to be removed.
+ * If the double dot has no parent path segment to work with, {@code null}
+ * is returned.
+ *
+ * The output will be the same on both Unix and Windows except
+ * for the separator character.
+ *
+ * /foo// --> /foo/
+ * /foo/./ --> /foo/
+ * /foo/../bar --> /bar
+ * /foo/../bar/ --> /bar/
+ * /foo/../bar/../baz --> /baz
+ * //foo//./bar --> /foo/bar
+ * /../ --> null
+ * ../foo --> null
+ * foo/bar/.. --> foo/
+ * foo/../../bar --> null
+ * foo/../bar --> bar
+ * //server/foo/../bar --> //server/bar
+ * //server/../bar --> null
+ * C:\foo\..\bar --> C:\bar
+ * C:\..\bar --> null
+ * ~/foo/../bar/ --> ~/bar/
+ * ~/../bar --> null
+ *
+ * (Note the file separator returned will be correct for Windows/Unix)
+ *
+ * @param filename the filename to normalize, null returns null
+ * @return the normalized filename, or null if invalid. Null bytes inside string will be removed
+ */
+ public static String normalize(final String filename) {
+ return doNormalize(filename, SYSTEM_SEPARATOR, true);
+ }
+ /**
+ * Normalizes a path, removing double and single dot path steps.
+ *
+ * This method normalizes a path to a standard format.
+ * The input may contain separators in either Unix or Windows format.
+ * The output will contain separators in the format specified.
+ *
+ * A trailing slash will be retained.
+ * A double slash will be merged to a single slash (but UNC names are handled).
+ * A single dot path segment will be removed.
+ * A double dot will cause that path segment and the one before to be removed.
+ * If the double dot has no parent path segment to work with, {@code null}
+ * is returned.
+ *
+ * The output will be the same on both Unix and Windows except
+ * for the separator character.
+ *
+ * /foo// --> /foo/
+ * /foo/./ --> /foo/
+ * /foo/../bar --> /bar
+ * /foo/../bar/ --> /bar/
+ * /foo/../bar/../baz --> /baz
+ * //foo//./bar --> /foo/bar
+ * /../ --> null
+ * ../foo --> null
+ * foo/bar/.. --> foo/
+ * foo/../../bar --> null
+ * foo/../bar --> bar
+ * //server/foo/../bar --> //server/bar
+ * //server/../bar --> null
+ * C:\foo\..\bar --> C:\bar
+ * C:\..\bar --> null
+ * ~/foo/../bar/ --> ~/bar/
+ * ~/../bar --> null
+ *
+ * The output will be the same on both Unix and Windows including
+ * the separator character.
+ *
+ * @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.
+ * @return the normalized filename, or null if invalid. Null bytes inside string will be removed
+ * @since 2.0
+ */
+ public static String normalize(final String filename, final boolean unixSeparator) {
+ final char separator = unixSeparator ? UNIX_SEPARATOR : WINDOWS_SEPARATOR;
+ return doNormalize(filename, separator, true);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Normalizes a path, removing double and single dot path steps,
+ * and removing any final directory separator.
+ *
+ * This method normalizes a path to a standard format.
+ * The input may contain separators in either Unix or Windows format.
+ * The output will contain separators in the format of the system.
+ *
+ * A trailing slash will be removed.
+ * A double slash will be merged to a single slash (but UNC names are handled).
+ * A single dot path segment will be removed.
+ * A double dot will cause that path segment and the one before to be removed.
+ * If the double dot has no parent path segment to work with, {@code null}
+ * is returned.
+ *
+ * The output will be the same on both Unix and Windows except
+ * for the separator character.
+ *
+ * /foo// --> /foo
+ * /foo/./ --> /foo
+ * /foo/../bar --> /bar
+ * /foo/../bar/ --> /bar
+ * /foo/../bar/../baz --> /baz
+ * //foo//./bar --> /foo/bar
+ * /../ --> null
+ * ../foo --> null
+ * foo/bar/.. --> foo
+ * foo/../../bar --> null
+ * foo/../bar --> bar
+ * //server/foo/../bar --> //server/bar
+ * //server/../bar --> null
+ * C:\foo\..\bar --> C:\bar
+ * C:\..\bar --> null
+ * ~/foo/../bar/ --> ~/bar
+ * ~/../bar --> null
+ *
+ * (Note the file separator returned will be correct for Windows/Unix)
+ *
+ * @param filename the filename to normalize, null returns null
+ * @return the normalized filename, or null if invalid. Null bytes inside string will be removed
+ */
+ public static String normalizeNoEndSeparator(final String filename) {
+ return doNormalize(filename, SYSTEM_SEPARATOR, false);
+ }
+
+ /**
+ * Normalizes a path, removing double and single dot path steps,
+ * and removing any final directory separator.
+ *
+ * This method normalizes a path to a standard format.
+ * The input may contain separators in either Unix or Windows format.
+ * The output will contain separators in the format specified.
+ *
+ * A trailing slash will be removed.
+ * A double slash will be merged to a single slash (but UNC names are handled).
+ * A single dot path segment will be removed.
+ * A double dot will cause that path segment and the one before to be removed.
+ * If the double dot has no parent path segment to work with, {@code null}
+ * is returned.
+ *
+ * The output will be the same on both Unix and Windows including
+ * the separator character.
+ *
+ * /foo// --> /foo
+ * /foo/./ --> /foo
+ * /foo/../bar --> /bar
+ * /foo/../bar/ --> /bar
+ * /foo/../bar/../baz --> /baz
+ * //foo//./bar --> /foo/bar
+ * /../ --> null
+ * ../foo --> null
+ * foo/bar/.. --> foo
+ * foo/../../bar --> null
+ * foo/../bar --> bar
+ * //server/foo/../bar --> //server/bar
+ * //server/../bar --> null
+ * C:\foo\..\bar --> C:\bar
+ * C:\..\bar --> null
+ * ~/foo/../bar/ --> ~/bar
+ * ~/../bar --> null
+ *
+ *
+ * @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 separtor should be used.
+ * @return the normalized filename, or null if invalid. Null bytes inside string will be removed
+ * @since 2.0
+ */
+ public static String normalizeNoEndSeparator(final String filename, final boolean unixSeparator) {
+ final char separator = unixSeparator ? UNIX_SEPARATOR : WINDOWS_SEPARATOR;
+ return doNormalize(filename, separator, false);
+ }
+
+ /**
+ * Internal method to perform the normalization.
+ *
+ * @param filename the filename
+ * @param separator The separator character to use
+ * @param keepSeparator true to keep the final separator
+ * @return the normalized filename. Null bytes inside string will be removed.
+ */
+ private static String doNormalize(final String filename, final char separator, final boolean keepSeparator) {
+ if (filename == null) {
+ return null;
+ }
+
+ failIfNullBytePresent(filename);
+
+ int size = filename.length();
+ if (size == 0) {
+ return filename;
+ }
+ final int prefix = getPrefixLength(filename);
+ if (prefix < 0) {
+ return null;
+ }
+
+ final char[] array = new char[size + 2]; // +1 for possible extra slash, +2 for arraycopy
+ filename.getChars(0, filename.length(), array, 0);
+
+ // fix separators throughout
+ final char otherSeparator = separator == SYSTEM_SEPARATOR ? OTHER_SEPARATOR : SYSTEM_SEPARATOR;
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == otherSeparator) {
+ array[i] = separator;
+ }
+ }
+
+ // add extra separator on the end to simplify code below
+ boolean lastIsDirectory = true;
+ if (array[size - 1] != separator) {
+ array[size++] = separator;
+ lastIsDirectory = false;
+ }
+
+ // adjoining slashes
+ for (int i = prefix + 1; i < size; i++) {
+ if (array[i] == separator && array[i - 1] == separator) {
+ System.arraycopy(array, i, array, i - 1, size - i);
+ size--;
+ i--;
+ }
+ }
+
+ // dot slash
+ for (int i = prefix + 1; i < size; i++) {
+ if (array[i] == separator && array[i - 1] == '.' &&
+ (i == prefix + 1 || array[i - 2] == separator)) {
+ if (i == size - 1) {
+ lastIsDirectory = true;
+ }
+ System.arraycopy(array, i + 1, array, i - 1, size - i);
+ size -=2;
+ i--;
+ }
+ }
+
+ // double dot slash
+ outer:
+ for (int i = prefix + 2; i < size; i++) {
+ if (array[i] == separator && array[i - 1] == '.' && array[i - 2] == '.' &&
+ (i == prefix + 2 || array[i - 3] == separator)) {
+ if (i == prefix + 2) {
+ return null;
+ }
+ if (i == size - 1) {
+ lastIsDirectory = true;
+ }
+ int j;
+ for (j = i - 4 ; j >= prefix; j--) {
+ if (array[j] == separator) {
+ // remove b/../ from a/b/../c
+ System.arraycopy(array, i + 1, array, j + 1, size - i);
+ size -= i - j;
+ i = j + 1;
+ continue outer;
+ }
+ }
+ // remove a/../ from a/../c
+ System.arraycopy(array, i + 1, array, prefix, size - i);
+ size -= i + 1 - prefix;
+ i = prefix + 1;
+ }
+ }
+
+ if (size <= 0) { // should never be less than 0
+ return "";
+ }
+ if (size <= prefix) { // should never be less than prefix
+ return new String(array, 0, size);
+ }
+ if (lastIsDirectory && keepSeparator) {
+ return new String(array, 0, size); // keep trailing separator
+ }
+ return new String(array, 0, size - 1); // lose trailing separator
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Concatenates a filename to a base path using normal command line style rules.
+ *
+ * The effect is equivalent to resultant directory after changing
+ * directory to the first argument, followed by changing directory to
+ * the second argument.
+ *
+ * The first argument is the base path, the second is the path to concatenate.
+ * The returned path is always normalized via {@link #normalize(String)},
+ * thus .. is handled.
+ *
+ * If pathToAdd is absolute (has an absolute prefix), then
+ * it will be normalized and returned.
+ * Otherwise, the paths will be joined, normalized and returned.
+ *
+ * The output will be the same on both Unix and Windows except
+ * for the separator character.
+ *
+ * /foo/ + bar --> /foo/bar
+ * /foo + bar --> /foo/bar
+ * /foo + /bar --> /bar
+ * /foo + C:/bar --> C:/bar
+ * /foo + C:bar --> C:bar (*)
+ * /foo/a/ + ../bar --> foo/bar
+ * /foo/ + ../../bar --> null
+ * /foo/ + /bar --> /bar
+ * /foo/.. + /bar --> /bar
+ * /foo + bar/c.txt --> /foo/bar/c.txt
+ * /foo/c.txt + bar --> /foo/c.txt/bar (!)
+ *
+ * (*) Note that the Windows relative drive prefix is unreliable when
+ * used with this method.
+ * (!) Note that the first parameter must be a path. If it ends with a name, then
+ * the name will be built into the concatenated path. If this might be a problem,
+ * use {@link #getFullPath(String)} on the base path argument.
+ *
+ * @param basePath the base path to attach to, always treated as a path
+ * @param fullFilenameToAdd the filename (or path) to attach to the base
+ * @return the concatenated path, or null if invalid. Null bytes inside string will be removed
+ */
+ public static String concat(final String basePath, final String fullFilenameToAdd) {
+ final int prefix = getPrefixLength(fullFilenameToAdd);
+ if (prefix < 0) {
+ return null;
+ }
+ if (prefix > 0) {
+ return normalize(fullFilenameToAdd);
+ }
+ if (basePath == null) {
+ return null;
+ }
+ final int len = basePath.length();
+ if (len == 0) {
+ return normalize(fullFilenameToAdd);
+ }
+ final char ch = basePath.charAt(len - 1);
+ if (isSeparator(ch)) {
+ return normalize(basePath + fullFilenameToAdd);
+ } else {
+ return normalize(basePath + '/' + fullFilenameToAdd);
+ }
+ }
+
+ /**
+ * Determines whether the {@code parent} directory contains the {@code child} element (a file or directory).
+ *
+ * The files names are expected to be normalized.
+ *
+ *
+ * Edge cases:
+ *
+ * A {@code directory} must not be null: if null, throw IllegalArgumentException
+ * A directory does not contain itself: return false
+ * A null child file is not contained in any parent: return false
+ *
+ *
+ * @param canonicalParent
+ * the file to consider as the parent.
+ * @param canonicalChild
+ * the file to consider as the child.
+ * @return true is the candidate leaf is under by the specified composite. False otherwise.
+ * @throws IOException
+ * if an IO error occurs while checking the files.
+ * @since 2.2
+ * @see FileUtils#directoryContains(File, File)
+ */
+ public static boolean directoryContains(final String canonicalParent, final String canonicalChild)
+ throws IOException {
+
+ // Fail fast against NullPointerException
+ if (canonicalParent == null) {
+ throw new IllegalArgumentException("Directory must not be null");
+ }
+
+ if (canonicalChild == null) {
+ return false;
+ }
+
+ if (IOCase.SYSTEM.checkEquals(canonicalParent, canonicalChild)) {
+ return false;
+ }
+
+ return IOCase.SYSTEM.checkStartsWith(canonicalChild, canonicalParent);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Converts all separators to the Unix separator of forward slash.
+ *
+ * @param path the path to be changed, null ignored
+ * @return the updated path
+ */
+ public static String separatorsToUnix(final String path) {
+ if (path == null || path.indexOf(WINDOWS_SEPARATOR) == NOT_FOUND) {
+ return path;
+ }
+ return path.replace(WINDOWS_SEPARATOR, UNIX_SEPARATOR);
+ }
+
+ /**
+ * Converts all separators to the Windows separator of backslash.
+ *
+ * @param path the path to be changed, null ignored
+ * @return the updated path
+ */
+ public static String separatorsToWindows(final String path) {
+ if (path == null || path.indexOf(UNIX_SEPARATOR) == NOT_FOUND) {
+ return path;
+ }
+ return path.replace(UNIX_SEPARATOR, WINDOWS_SEPARATOR);
+ }
+
+ /**
+ * Converts all separators to the system separator.
+ *
+ * @param path the path to be changed, null ignored
+ * @return the updated path
+ */
+ public static String separatorsToSystem(final String path) {
+ if (path == null) {
+ return null;
+ }
+ if (isSystemWindows()) {
+ return separatorsToWindows(path);
+ } else {
+ return separatorsToUnix(path);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns the length of the filename prefix, such as C:/ or ~/.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ *
+ * The prefix length includes the first slash in the full filename
+ * if applicable. Thus, it is possible that the length returned is greater
+ * than the length of the input string.
+ *
+ * Windows:
+ * a\b\c.txt --> "" --> relative
+ * \a\b\c.txt --> "\" --> current drive absolute
+ * C:a\b\c.txt --> "C:" --> drive relative
+ * C:\a\b\c.txt --> "C:\" --> absolute
+ * \\server\a\b\c.txt --> "\\server\" --> UNC
+ * \\\a\b\c.txt --> error, length = -1
+ *
+ * Unix:
+ * a/b/c.txt --> "" --> relative
+ * /a/b/c.txt --> "/" --> absolute
+ * ~/a/b/c.txt --> "~/" --> current user
+ * ~ --> "~/" --> current user (slash added)
+ * ~user/a/b/c.txt --> "~user/" --> named user
+ * ~user --> "~user/" --> named user (slash added)
+ * //server/a/b/c.txt --> "//server/"
+ * ///a/b/c.txt --> error, length = -1
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ * ie. both Unix and Windows prefixes are matched regardless.
+ *
+ * Note that a leading // (or \\) is used to indicate a UNC name on Windows.
+ * These must be followed by a server name, so double-slashes are not collapsed
+ * to a single slash at the start of the filename.
+ *
+ * @param filename the filename to find the prefix in, null returns -1
+ * @return the length of the prefix, -1 if invalid or null
+ */
+ public static int getPrefixLength(final String filename) {
+ if (filename == null) {
+ return NOT_FOUND;
+ }
+ final int len = filename.length();
+ if (len == 0) {
+ return 0;
+ }
+ char ch0 = filename.charAt(0);
+ if (ch0 == ':') {
+ return NOT_FOUND;
+ }
+ if (len == 1) {
+ if (ch0 == '~') {
+ return 2; // return a length greater than the input
+ }
+ return isSeparator(ch0) ? 1 : 0;
+ } else {
+ if (ch0 == '~') {
+ int posUnix = filename.indexOf(UNIX_SEPARATOR, 1);
+ int posWin = filename.indexOf(WINDOWS_SEPARATOR, 1);
+ if (posUnix == NOT_FOUND && posWin == NOT_FOUND) {
+ return len + 1; // return a length greater than the input
+ }
+ posUnix = posUnix == NOT_FOUND ? posWin : posUnix;
+ posWin = posWin == NOT_FOUND ? posUnix : posWin;
+ return Math.min(posUnix, posWin) + 1;
+ }
+ final char ch1 = filename.charAt(1);
+ if (ch1 == ':') {
+ ch0 = Character.toUpperCase(ch0);
+ if (ch0 >= 'A' && ch0 <= 'Z') {
+ if (len == 2 || isSeparator(filename.charAt(2)) == false) {
+ return 2;
+ }
+ return 3;
+ }
+ return NOT_FOUND;
+
+ } else if (isSeparator(ch0) && isSeparator(ch1)) {
+ int posUnix = filename.indexOf(UNIX_SEPARATOR, 2);
+ int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2);
+ if (posUnix == NOT_FOUND && posWin == NOT_FOUND || posUnix == 2 || posWin == 2) {
+ return NOT_FOUND;
+ }
+ posUnix = posUnix == NOT_FOUND ? posWin : posUnix;
+ posWin = posWin == NOT_FOUND ? posUnix : posWin;
+ return Math.min(posUnix, posWin) + 1;
+ } else {
+ return isSeparator(ch0) ? 1 : 0;
+ }
+ }
+ }
+
+ /**
+ * Returns the index of the last directory separator character.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ * The position of the last forward or backslash is returned.
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * @param filename the filename to find the last path separator in, null returns -1
+ * @return the index of the last separator character, or -1 if there
+ * is no such character
+ */
+ public static int indexOfLastSeparator(final String filename) {
+ if (filename == null) {
+ return NOT_FOUND;
+ }
+ final int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR);
+ final int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR);
+ return Math.max(lastUnixPos, lastWindowsPos);
+ }
+
+ /**
+ * Returns the index of the last extension separator character, which is a dot.
+ *
+ * This method also checks that there is no directory separator after the last dot. To do this it uses
+ * {@link #indexOfLastSeparator(String)} which will handle a file in either Unix or Windows format.
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ *
+ * @param filename
+ * the filename to find the last extension separator in, null returns -1
+ * @return the index of the last extension separator character, or -1 if there is no such character
+ */
+ public static int indexOfExtension(final String filename) {
+ if (filename == null) {
+ return NOT_FOUND;
+ }
+ final int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR);
+ final int lastSeparator = indexOfLastSeparator(filename);
+ return lastSeparator > extensionPos ? NOT_FOUND : extensionPos;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the prefix from a full filename, such as C:/
+ * or ~/.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ * The prefix includes the first slash in the full filename where applicable.
+ *
+ * Windows:
+ * a\b\c.txt --> "" --> relative
+ * \a\b\c.txt --> "\" --> current drive absolute
+ * C:a\b\c.txt --> "C:" --> drive relative
+ * C:\a\b\c.txt --> "C:\" --> absolute
+ * \\server\a\b\c.txt --> "\\server\" --> UNC
+ *
+ * Unix:
+ * a/b/c.txt --> "" --> relative
+ * /a/b/c.txt --> "/" --> absolute
+ * ~/a/b/c.txt --> "~/" --> current user
+ * ~ --> "~/" --> current user (slash added)
+ * ~user/a/b/c.txt --> "~user/" --> named user
+ * ~user --> "~user/" --> named user (slash added)
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ * ie. both Unix and Windows prefixes are matched regardless.
+ *
+ * @param filename the filename to query, null returns null
+ * @return the prefix of the file, null if invalid. Null bytes inside string will be removed
+ */
+ public static String getPrefix(final String filename) {
+ if (filename == null) {
+ return null;
+ }
+ final int len = getPrefixLength(filename);
+ if (len < 0) {
+ return null;
+ }
+ if (len > filename.length()) {
+ failIfNullBytePresent(filename + UNIX_SEPARATOR);
+ return filename + UNIX_SEPARATOR;
+ }
+ String path = filename.substring(0, len);
+ failIfNullBytePresent(path);
+ return path;
+ }
+
+ /**
+ * Gets the path from a full filename, which excludes the prefix.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ * The method is entirely text based, and returns the text before and
+ * including the last forward or backslash.
+ *
+ * C:\a\b\c.txt --> a\b\
+ * ~/a/b/c.txt --> a/b/
+ * a.txt --> ""
+ * a/b/c --> a/b/
+ * a/b/c/ --> a/b/c/
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * This method drops the prefix from the result.
+ * See {@link #getFullPath(String)} for the method that retains the prefix.
+ *
+ * @param filename the filename to query, null returns null
+ * @return the path of the file, an empty string if none exists, null if invalid.
+ * Null bytes inside string will be removed
+ */
+ public static String getPath(final String filename) {
+ return doGetPath(filename, 1);
+ }
+
+ /**
+ * Gets the path from a full filename, which excludes the prefix, and
+ * also excluding the final directory separator.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ * The method is entirely text based, and returns the text before the
+ * last forward or backslash.
+ *
+ * C:\a\b\c.txt --> a\b
+ * ~/a/b/c.txt --> a/b
+ * a.txt --> ""
+ * a/b/c --> a/b
+ * a/b/c/ --> a/b/c
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * This method drops the prefix from the result.
+ * See {@link #getFullPathNoEndSeparator(String)} for the method that retains the prefix.
+ *
+ * @param filename the filename to query, null returns null
+ * @return the path of the file, an empty string if none exists, null if invalid.
+ * Null bytes inside string will be removed
+ */
+ public static String getPathNoEndSeparator(final String filename) {
+ return doGetPath(filename, 0);
+ }
+
+ /**
+ * Does the work of getting the path.
+ *
+ * @param filename the filename
+ * @param separatorAdd 0 to omit the end separator, 1 to return it
+ * @return the path. Null bytes inside string will be removed
+ */
+ private static String doGetPath(final String filename, final int separatorAdd) {
+ if (filename == null) {
+ return null;
+ }
+ final int prefix = getPrefixLength(filename);
+ if (prefix < 0) {
+ return null;
+ }
+ final int index = indexOfLastSeparator(filename);
+ final int endIndex = index+separatorAdd;
+ if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
+ return "";
+ }
+ String path = filename.substring(prefix, endIndex);
+ failIfNullBytePresent(path);
+ return path;
+ }
+
+ /**
+ * Gets the full path from a full filename, which is the prefix + path.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ * The method is entirely text based, and returns the text before and
+ * including the last forward or backslash.
+ *
+ * C:\a\b\c.txt --> C:\a\b\
+ * ~/a/b/c.txt --> ~/a/b/
+ * a.txt --> ""
+ * a/b/c --> a/b/
+ * a/b/c/ --> a/b/c/
+ * C: --> C:
+ * C:\ --> C:\
+ * ~ --> ~/
+ * ~/ --> ~/
+ * ~user --> ~user/
+ * ~user/ --> ~user/
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * @param filename the filename to query, null returns null
+ * @return the path of the file, an empty string if none exists, null if invalid
+ */
+ public static String getFullPath(final String filename) {
+ return doGetFullPath(filename, true);
+ }
+
+ /**
+ * Gets the full path from a full filename, which is the prefix + path,
+ * and also excluding the final directory separator.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ * The method is entirely text based, and returns the text before the
+ * last forward or backslash.
+ *
+ * C:\a\b\c.txt --> C:\a\b
+ * ~/a/b/c.txt --> ~/a/b
+ * a.txt --> ""
+ * a/b/c --> a/b
+ * a/b/c/ --> a/b/c
+ * C: --> C:
+ * C:\ --> C:\
+ * ~ --> ~
+ * ~/ --> ~
+ * ~user --> ~user
+ * ~user/ --> ~user
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * @param filename the filename to query, null returns null
+ * @return the path of the file, an empty string if none exists, null if invalid
+ */
+ public static String getFullPathNoEndSeparator(final String filename) {
+ return doGetFullPath(filename, false);
+ }
+
+ /**
+ * Does the work of getting the path.
+ *
+ * @param filename the filename
+ * @param includeSeparator true to include the end separator
+ * @return the path
+ */
+ private static String doGetFullPath(final String filename, final boolean includeSeparator) {
+ if (filename == null) {
+ return null;
+ }
+ final int prefix = getPrefixLength(filename);
+ if (prefix < 0) {
+ return null;
+ }
+ if (prefix >= filename.length()) {
+ if (includeSeparator) {
+ return getPrefix(filename); // add end slash if necessary
+ } else {
+ return filename;
+ }
+ }
+ final int index = indexOfLastSeparator(filename);
+ if (index < 0) {
+ return filename.substring(0, prefix);
+ }
+ int end = index + (includeSeparator ? 1 : 0);
+ if (end == 0) {
+ end++;
+ }
+ return filename.substring(0, end);
+ }
+
+ /**
+ * Gets the name minus the path from a full filename.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ * The text after the last forward or backslash is returned.
+ *
+ * a/b/c.txt --> c.txt
+ * a.txt --> a.txt
+ * a/b/c --> c
+ * a/b/c/ --> ""
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * @param filename the filename to query, null returns null
+ * @return the name of the file without the path, or an empty string if none exists.
+ * Null bytes inside string will be removed
+ */
+ public static String getName(final String filename) {
+ if (filename == null) {
+ return null;
+ }
+ failIfNullBytePresent(filename);
+ final int index = indexOfLastSeparator(filename);
+ return filename.substring(index + 1);
+ }
+
+ /**
+ * Check the input for null bytes, a sign of unsanitized data being passed to to file level functions.
+ *
+ * This may be used for poison byte attacks.
+ * @param path the path to check
+ */
+ 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 " +
+ "known legitimate use cases for such data, but several injection attacks may use it");
+ }
+ }
+ }
+
+ /**
+ * Gets the base name, minus the full path and extension, from a full filename.
+ *
+ * This method will handle a file in either Unix or Windows format.
+ * The text after the last forward or backslash and before the last dot is returned.
+ *
+ * a/b/c.txt --> c
+ * a.txt --> a
+ * a/b/c --> c
+ * a/b/c/ --> ""
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * @param filename the filename to query, null returns null
+ * @return the name of the file without the path, or an empty string if none exists. Null bytes inside string
+ * will be removed
+ */
+ public static String getBaseName(final String filename) {
+ return removeExtension(getName(filename));
+ }
+
+ /**
+ * Gets the extension of a filename.
+ *
+ * This method returns the textual part of the filename after the last dot.
+ * There must be no directory separator after the dot.
+ *
+ * foo.txt --> "txt"
+ * a/b/c.jpg --> "jpg"
+ * a/b.txt/c --> ""
+ * a/b/c --> ""
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * @param filename the filename to retrieve the extension of.
+ * @return the extension of the file or an empty string if none exists or {@code null}
+ * if the filename is {@code null}.
+ */
+ public static String getExtension(final String filename) {
+ if (filename == null) {
+ return null;
+ }
+ final int index = indexOfExtension(filename);
+ if (index == NOT_FOUND) {
+ return "";
+ } else {
+ return filename.substring(index + 1);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Removes the extension from a filename.
+ *
+ * This method returns the textual part of the filename before the last dot.
+ * There must be no directory separator after the dot.
+ *
+ * foo.txt --> foo
+ * a\b\c.jpg --> a\b\c
+ * a\b\c --> a\b\c
+ * a.b\c --> a.b\c
+ *
+ *
+ * The output will be the same irrespective of the machine that the code is running on.
+ *
+ * @param filename the filename to query, null returns null
+ * @return the filename minus the extension
+ */
+ public static String removeExtension(final String filename) {
+ if (filename == null) {
+ return null;
+ }
+ failIfNullBytePresent(filename);
+
+ final int index = indexOfExtension(filename);
+ if (index == NOT_FOUND) {
+ return filename;
+ } else {
+ return filename.substring(0, index);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks whether two filenames are equal exactly.
+ *
+ * No processing is performed on the filenames other than comparison,
+ * thus this is merely a null-safe case-sensitive equals.
+ *
+ * @param filename1 the first filename to query, may be null
+ * @param filename2 the second filename to query, may be null
+ * @return true if the filenames are equal, null equals null
+ * @see IOCase#SENSITIVE
+ */
+ public static boolean equals(final String filename1, final String filename2) {
+ return equals(filename1, filename2, false, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Checks whether two filenames are equal using the case rules of the system.
+ *
+ * No processing is performed on the filenames other than comparison.
+ * The check is case-sensitive on Unix and case-insensitive on Windows.
+ *
+ * @param filename1 the first filename to query, may be null
+ * @param filename2 the second filename to query, may be null
+ * @return true if the filenames are equal, null equals null
+ * @see IOCase#SYSTEM
+ */
+ public static boolean equalsOnSystem(final String filename1, final String filename2) {
+ return equals(filename1, filename2, false, IOCase.SYSTEM);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks whether two filenames are equal after both have been normalized.
+ *
+ * Both filenames are first passed to {@link #normalize(String)}.
+ * The check is then performed in a case-sensitive manner.
+ *
+ * @param filename1 the first filename to query, may be null
+ * @param filename2 the second filename to query, may be null
+ * @return true if the filenames are equal, null equals null
+ * @see IOCase#SENSITIVE
+ */
+ public static boolean equalsNormalized(final String filename1, final String filename2) {
+ return equals(filename1, filename2, true, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Checks whether two filenames are equal after both have been normalized
+ * and using the case rules of the system.
+ *
+ * Both filenames are first passed to {@link #normalize(String)}.
+ * The check is then performed case-sensitive on Unix and
+ * case-insensitive on Windows.
+ *
+ * @param filename1 the first filename to query, may be null
+ * @param filename2 the second filename to query, may be null
+ * @return true if the filenames are equal, null equals null
+ * @see IOCase#SYSTEM
+ */
+ public static boolean equalsNormalizedOnSystem(final String filename1, final String filename2) {
+ return equals(filename1, filename2, true, IOCase.SYSTEM);
+ }
+
+ /**
+ * Checks whether two filenames are equal, optionally normalizing and providing
+ * control over the case-sensitivity.
+ *
+ * @param filename1 the first filename to query, may be null
+ * @param filename2 the second filename to query, may be null
+ * @param normalized whether to normalize the filenames
+ * @param caseSensitivity what case sensitivity rule to use, null means case-sensitive
+ * @return true if the filenames are equal, null equals null
+ * @since 1.3
+ */
+ public static boolean equals(
+ String filename1, String filename2,
+ final boolean normalized, IOCase caseSensitivity) {
+
+ if (filename1 == null || filename2 == null) {
+ return filename1 == null && filename2 == null;
+ }
+ if (normalized) {
+ filename1 = normalize(filename1);
+ filename2 = normalize(filename2);
+ if (filename1 == null || filename2 == null) {
+ throw new NullPointerException(
+ "Error normalizing one or both of the file names");
+ }
+ }
+ if (caseSensitivity == null) {
+ caseSensitivity = IOCase.SENSITIVE;
+ }
+ return caseSensitivity.checkEquals(filename1, filename2);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks whether the extension of the filename is that specified.
+ *
+ * This method obtains the extension as the textual part of the filename
+ * after the last dot. There must be no directory separator after the dot.
+ * The extension check is case-sensitive on all platforms.
+ *
+ * @param filename the filename to query, null returns false
+ * @param extension the extension to check for, null or empty checks for no extension
+ * @return true if the filename has the specified extension
+ * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
+ */
+ public static boolean isExtension(final String filename, final String extension) {
+ if (filename == null) {
+ return false;
+ }
+ failIfNullBytePresent(filename);
+
+ if (extension == null || extension.isEmpty()) {
+ return indexOfExtension(filename) == NOT_FOUND;
+ }
+ final String fileExt = getExtension(filename);
+ return fileExt.equals(extension);
+ }
+
+ /**
+ * Checks whether the extension of the filename is one of those specified.
+ *
+ * This method obtains the extension as the textual part of the filename
+ * after the last dot. There must be no directory separator after the dot.
+ * The extension check is case-sensitive on all platforms.
+ *
+ * @param filename the filename to query, null returns false
+ * @param extensions the extensions to check for, null checks for no extension
+ * @return true if the filename is one of the extensions
+ * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
+ */
+ public static boolean isExtension(final String filename, final String[] extensions) {
+ if (filename == null) {
+ return false;
+ }
+ failIfNullBytePresent(filename);
+
+ if (extensions == null || extensions.length == 0) {
+ return indexOfExtension(filename) == NOT_FOUND;
+ }
+ final String fileExt = getExtension(filename);
+ for (final String extension : extensions) {
+ if (fileExt.equals(extension)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks whether the extension of the filename is one of those specified.
+ *
+ * This method obtains the extension as the textual part of the filename
+ * after the last dot. There must be no directory separator after the dot.
+ * The extension check is case-sensitive on all platforms.
+ *
+ * @param filename the filename to query, null returns false
+ * @param extensions the extensions to check for, null checks for no extension
+ * @return true if the filename is one of the extensions
+ * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
+ */
+ public static boolean isExtension(final String filename, final Collection extensions) {
+ if (filename == null) {
+ return false;
+ }
+ failIfNullBytePresent(filename);
+
+ if (extensions == null || extensions.isEmpty()) {
+ return indexOfExtension(filename) == NOT_FOUND;
+ }
+ final String fileExt = getExtension(filename);
+ for (final String extension : extensions) {
+ if (fileExt.equals(extension)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks a filename to see if it matches the specified wildcard matcher,
+ * always testing case-sensitive.
+ *
+ * The wildcard matcher uses the characters '?' and '*' to represent a
+ * single or multiple (zero or more) wildcard characters.
+ * This is the same as often found on Dos/Unix command lines.
+ * The check is case-sensitive always.
+ *
+ * wildcardMatch("c.txt", "*.txt") --> true
+ * wildcardMatch("c.txt", "*.jpg") --> false
+ * wildcardMatch("a/b/c.txt", "a/b/*") --> true
+ * wildcardMatch("c.txt", "*.???") --> true
+ * wildcardMatch("c.txt", "*.????") --> false
+ *
+ * N.B. the sequence "*?" does not work properly at present in match strings.
+ *
+ * @param filename the filename to match on
+ * @param wildcardMatcher the wildcard string to match against
+ * @return true if the filename matches the wilcard string
+ * @see IOCase#SENSITIVE
+ */
+ public static boolean wildcardMatch(final String filename, final String wildcardMatcher) {
+ return wildcardMatch(filename, wildcardMatcher, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Checks a filename to see if it matches the specified wildcard matcher
+ * using the case rules of the system.
+ *
+ * The wildcard matcher uses the characters '?' and '*' to represent a
+ * single or multiple (zero or more) wildcard characters.
+ * This is the same as often found on Dos/Unix command lines.
+ * The check is case-sensitive on Unix and case-insensitive on Windows.
+ *
+ * wildcardMatch("c.txt", "*.txt") --> true
+ * wildcardMatch("c.txt", "*.jpg") --> false
+ * wildcardMatch("a/b/c.txt", "a/b/*") --> true
+ * wildcardMatch("c.txt", "*.???") --> true
+ * wildcardMatch("c.txt", "*.????") --> false
+ *
+ * N.B. the sequence "*?" does not work properly at present in match strings.
+ *
+ * @param filename the filename to match on
+ * @param wildcardMatcher the wildcard string to match against
+ * @return true if the filename matches the wilcard string
+ * @see IOCase#SYSTEM
+ */
+ public static boolean wildcardMatchOnSystem(final String filename, final String wildcardMatcher) {
+ return wildcardMatch(filename, wildcardMatcher, IOCase.SYSTEM);
+ }
+
+ /**
+ * Checks a filename to see if it matches the specified wildcard matcher
+ * allowing control over case-sensitivity.
+ *
+ * The wildcard matcher uses the characters '?' and '*' to represent a
+ * single or multiple (zero or more) wildcard characters.
+ * N.B. the sequence "*?" does not work properly at present in match strings.
+ *
+ * @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 wilcard string
+ * @since 1.3
+ */
+ public static boolean wildcardMatch(final String filename, final String wildcardMatcher, IOCase caseSensitivity) {
+ if (filename == null && wildcardMatcher == null) {
+ return true;
+ }
+ if (filename == null || wildcardMatcher == null) {
+ return false;
+ }
+ if (caseSensitivity == null) {
+ caseSensitivity = IOCase.SENSITIVE;
+ }
+ final String[] wcs = splitOnTokens(wildcardMatcher);
+ boolean anyChars = false;
+ int textIdx = 0;
+ int wcsIdx = 0;
+ final Stack backtrack = new Stack();
+
+ // loop around a backtrack stack, to handle complex * matching
+ do {
+ if (backtrack.size() > 0) {
+ final int[] array = backtrack.pop();
+ wcsIdx = array[0];
+ textIdx = array[1];
+ anyChars = true;
+ }
+
+ // loop whilst tokens and text left to process
+ while (wcsIdx < wcs.length) {
+
+ if (wcs[wcsIdx].equals("?")) {
+ // ? so move to next text char
+ textIdx++;
+ if (textIdx > filename.length()) {
+ break;
+ }
+ anyChars = false;
+
+ } else if (wcs[wcsIdx].equals("*")) {
+ // set any chars status
+ anyChars = true;
+ if (wcsIdx == wcs.length - 1) {
+ textIdx = filename.length();
+ }
+
+ } else {
+ // matching text token
+ if (anyChars) {
+ // any chars then try to locate text token
+ textIdx = caseSensitivity.checkIndexOf(filename, textIdx, wcs[wcsIdx]);
+ if (textIdx == NOT_FOUND) {
+ // token not found
+ break;
+ }
+ final int repeat = caseSensitivity.checkIndexOf(filename, textIdx + 1, wcs[wcsIdx]);
+ if (repeat >= 0) {
+ backtrack.push(new int[] {wcsIdx, repeat});
+ }
+ } else {
+ // matching from current position
+ if (!caseSensitivity.checkRegionMatches(filename, textIdx, wcs[wcsIdx])) {
+ // couldnt match token
+ break;
+ }
+ }
+
+ // matched text token, move text index to end of matched token
+ textIdx += wcs[wcsIdx].length();
+ anyChars = false;
+ }
+
+ wcsIdx++;
+ }
+
+ // full match
+ if (wcsIdx == wcs.length && textIdx == filename.length()) {
+ return true;
+ }
+
+ } while (backtrack.size() > 0);
+
+ return false;
+ }
+
+ /**
+ * Splits a string into a number of tokens.
+ * The text is split by '?' and '*'.
+ * Where multiple '*' occur consecutively they are collapsed into a single '*'.
+ *
+ * @param text the text to split
+ * @return the array of tokens, never null
+ */
+ static String[] splitOnTokens(final String text) {
+ // used by wildcardMatch
+ // package level so a unit test may run on this
+
+ if (text.indexOf('?') == NOT_FOUND && text.indexOf('*') == NOT_FOUND) {
+ return new String[] { text };
+ }
+
+ final char[] array = text.toCharArray();
+ final ArrayList list = new ArrayList();
+ final StringBuilder buffer = new StringBuilder();
+ char prevChar = 0;
+ for (final char ch : array) {
+ if (ch == '?' || ch == '*') {
+ if (buffer.length() != 0) {
+ list.add(buffer.toString());
+ buffer.setLength(0);
+ }
+ if (ch == '?') {
+ list.add("?");
+ } else if (prevChar != '*') {// ch == '*' here; check if previous char was '*'
+ list.add("*");
+ }
+ } else {
+ buffer.append(ch);
+ }
+ prevChar = ch;
+ }
+ if (buffer.length() != 0) {
+ list.add(buffer.toString());
+ }
+
+ return list.toArray( new String[ list.size() ] );
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/HexDump.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/HexDump.java"
new file mode 100644
index 0000000000000000000000000000000000000000..7199ae206deb87cb3d80467687949dd041b521b9
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/HexDump.java"
@@ -0,0 +1,163 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+
+/**
+ * Dumps data in hexadecimal format.
+ *
+ * Provides a single function to take an array of bytes and display it
+ * in hexadecimal form.
+ *
+ * Origin of code: POI.
+ *
+ * @version $Id: HexDump.java 1471767 2013-04-24 23:24:19Z sebb $
+ */
+public class HexDump {
+
+ /**
+ * Instances should NOT be constructed in standard programming.
+ */
+ public HexDump() {
+ super();
+ }
+
+ /**
+ * Dump an array of bytes to an OutputStream. The output is formatted
+ * for human inspection, with a hexadecimal offset followed by the
+ * hexadecimal values of the next 16 bytes of data and the printable ASCII
+ * characters (if any) that those bytes represent printed per each line
+ * of output.
+ *
+ * The offset argument specifies the start offset of the data array
+ * within a larger entity like a file or an incoming stream. For example,
+ * if the data array contains the third kibibyte of a file, then the
+ * offset argument should be set to 2048. The offset value printed
+ * at the beginning of each line indicates where in that larger entity
+ * the first byte on that line is located.
+ *
+ * All bytes between the given index (inclusive) and the end of the
+ * data array are dumped.
+ *
+ * @param data the byte array to be dumped
+ * @param offset offset of the byte array within a larger entity
+ * @param stream the OutputStream to which the data is to be
+ * written
+ * @param index initial index into the byte array
+ *
+ * @throws IOException is thrown if anything goes wrong writing
+ * the data to stream
+ * @throws ArrayIndexOutOfBoundsException if the index is
+ * outside the data array's bounds
+ * @throws IllegalArgumentException if the output stream is null
+ */
+
+ public static void dump(final byte[] data, final long offset,
+ final OutputStream stream, final int index)
+ throws IOException, ArrayIndexOutOfBoundsException,
+ IllegalArgumentException {
+
+ if (index < 0 || index >= data.length) {
+ throw new ArrayIndexOutOfBoundsException(
+ "illegal index: " + index + " into array of length "
+ + data.length);
+ }
+ if (stream == null) {
+ throw new IllegalArgumentException("cannot write to nullstream");
+ }
+ long display_offset = offset + index;
+ final StringBuilder buffer = new StringBuilder(74);
+
+ for (int j = index; j < data.length; j += 16) {
+ int chars_read = data.length - j;
+
+ if (chars_read > 16) {
+ chars_read = 16;
+ }
+ dump(buffer, display_offset).append(' ');
+ for (int k = 0; k < 16; k++) {
+ if (k < chars_read) {
+ dump(buffer, data[k + j]);
+ } else {
+ buffer.append(" ");
+ }
+ buffer.append(' ');
+ }
+ for (int k = 0; k < chars_read; k++) {
+ if (data[k + j] >= ' ' && data[k + j] < 127) {
+ buffer.append((char) data[k + j]);
+ } else {
+ buffer.append('.');
+ }
+ }
+ buffer.append(EOL);
+ // make explicit the dependency on the default encoding
+ stream.write(buffer.toString().getBytes(Charset.defaultCharset()));
+ stream.flush();
+ buffer.setLength(0);
+ display_offset += chars_read;
+ }
+ }
+
+ /**
+ * The line-separator (initializes to "line.separator" system property.
+ */
+ public static final String EOL =
+ System.getProperty("line.separator");
+ private static final char[] _hexcodes =
+ {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'A', 'B', 'C', 'D', 'E', 'F'
+ };
+ private static final int[] _shifts =
+ {
+ 28, 24, 20, 16, 12, 8, 4, 0
+ };
+
+ /**
+ * Dump a long value into a StringBuilder.
+ *
+ * @param _lbuffer the StringBuilder to dump the value in
+ * @param value the long value to be dumped
+ * @return StringBuilder containing the dumped value.
+ */
+ private static StringBuilder dump(final StringBuilder _lbuffer, final long value) {
+ for (int j = 0; j < 8; j++) {
+ _lbuffer
+ .append(_hexcodes[(int) (value >> _shifts[j]) & 15]);
+ }
+ return _lbuffer;
+ }
+
+ /**
+ * Dump a byte value into a StringBuilder.
+ *
+ * @param _cbuffer the StringBuilder to dump the value in
+ * @param value the byte value to be dumped
+ * @return StringBuilder containing the dumped value.
+ */
+ private static StringBuilder dump(final StringBuilder _cbuffer, final byte value) {
+ for (int j = 0; j < 2; j++) {
+ _cbuffer.append(_hexcodes[value >> _shifts[j + 6] & 15]);
+ }
+ return _cbuffer;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..f9c823db0ccf8714cbc065771f5ecffc7dacda91
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOCase.java"
@@ -0,0 +1,254 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.Serializable;
+
+/**
+ * Enumeration of IO case sensitivity.
+ *
+ * Different filing systems have different rules for case-sensitivity.
+ * Windows is case-insensitive, Unix is case-sensitive.
+ *
+ * This class captures that difference, providing an enumeration to
+ * control how filename comparisons should be performed. It also provides
+ * methods that use the enumeration to perform comparisons.
+ *
+ * Wherever possible, you should use the check methods in this
+ * class to compare filenames.
+ *
+ * @version $Id: IOCase.java 1483915 2013-05-17 17:02:35Z sebb $
+ * @since 1.3
+ */
+public enum IOCase implements Serializable {
+
+ /**
+ * The constant for case sensitive regardless of operating system.
+ */
+ SENSITIVE ("Sensitive", true),
+
+ /**
+ * The constant for case insensitive regardless of operating system.
+ */
+ INSENSITIVE ("Insensitive", false),
+
+ /**
+ * The constant for case sensitivity determined by the current operating system.
+ * Windows is case-insensitive when comparing filenames, Unix is case-sensitive.
+ *
+ * Note: This only caters for Windows and Unix. Other operating
+ * systems (e.g. OSX and OpenVMS) are treated as case sensitive if they use the
+ * Unix file separator and case-insensitive if they use the Windows file separator
+ * (see {@link java.io.File#separatorChar}).
+ *
+ * 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());
+
+ /** Serialization version. */
+ private static final long serialVersionUID = -6343169151696340687L;
+
+ /** The enumeration name. */
+ private final String name;
+
+ /** The sensitivity flag. */
+ private final transient boolean sensitive;
+
+ //-----------------------------------------------------------------------
+ /**
+ * Factory method to create an IOCase from a name.
+ *
+ * @param name the name to find
+ * @return the IOCase object
+ * @throws IllegalArgumentException if the name is invalid
+ */
+ public static IOCase forName(final String name) {
+ for (IOCase ioCase : IOCase.values())
+ {
+ if (ioCase.getName().equals(name))
+ {
+ return ioCase;
+ }
+ }
+ throw new IllegalArgumentException("Invalid IOCase name: " + name);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Private constructor.
+ *
+ * @param name the name
+ * @param sensitive the sensitivity
+ */
+ private IOCase(final String name, final boolean sensitive) {
+ this.name = name;
+ this.sensitive = sensitive;
+ }
+
+ /**
+ * Replaces the enumeration from the stream with a real one.
+ * This ensures that the correct flag is set for SYSTEM.
+ *
+ * @return the resolved object
+ */
+ private Object readResolve() {
+ return forName(name);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the name of the constant.
+ *
+ * @return the name of the constant
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Does the object represent case sensitive comparison.
+ *
+ * @return true if case sensitive
+ */
+ public boolean isCaseSensitive() {
+ return sensitive;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Compares two strings using the case-sensitivity rule.
+ *
+ * This method mimics {@link String#compareTo} but takes case-sensitivity
+ * into account.
+ *
+ * @param str1 the first string to compare, not null
+ * @param str2 the second string to compare, not null
+ * @return true if equal using the case rules
+ * @throws NullPointerException if either string is null
+ */
+ public int checkCompareTo(final String str1, final String str2) {
+ if (str1 == null || str2 == null) {
+ throw new NullPointerException("The strings must not be null");
+ }
+ return sensitive ? str1.compareTo(str2) : str1.compareToIgnoreCase(str2);
+ }
+
+ /**
+ * Compares two strings using the case-sensitivity rule.
+ *
+ * This method mimics {@link String#equals} but takes case-sensitivity
+ * into account.
+ *
+ * @param str1 the first string to compare, not null
+ * @param str2 the second string to compare, not null
+ * @return true if equal using the case rules
+ * @throws NullPointerException if either string is null
+ */
+ public boolean checkEquals(final String str1, final String str2) {
+ if (str1 == null || str2 == null) {
+ throw new NullPointerException("The strings must not be null");
+ }
+ return sensitive ? str1.equals(str2) : str1.equalsIgnoreCase(str2);
+ }
+
+ /**
+ * Checks if one string starts with another using the case-sensitivity rule.
+ *
+ * This method mimics {@link String#startsWith(String)} but takes case-sensitivity
+ * into account.
+ *
+ * @param str the string to check, not null
+ * @param start the start to compare against, not null
+ * @return true if equal using the case rules
+ * @throws NullPointerException if either string is null
+ */
+ public boolean checkStartsWith(final String str, final String start) {
+ return str.regionMatches(!sensitive, 0, start, 0, start.length());
+ }
+
+ /**
+ * Checks if one string ends with another using the case-sensitivity rule.
+ *
+ * This method mimics {@link String#endsWith} but takes case-sensitivity
+ * into account.
+ *
+ * @param str the string to check, not null
+ * @param end the end to compare against, not null
+ * @return true if equal using the case rules
+ * @throws NullPointerException if either string is null
+ */
+ public boolean checkEndsWith(final String str, final String end) {
+ final int endLen = end.length();
+ return str.regionMatches(!sensitive, str.length() - endLen, end, 0, endLen);
+ }
+
+ /**
+ * Checks if one string contains another starting at a specific index using the
+ * case-sensitivity rule.
+ *
+ * This method mimics parts of {@link String#indexOf(String, int)}
+ * but takes case-sensitivity into account.
+ *
+ * @param str the string to check, not null
+ * @param strStartIndex the index to start at in str
+ * @param search the start to search for, not null
+ * @return the first index of the search String,
+ * -1 if no match or {@code null} string input
+ * @throws NullPointerException if either string is null
+ * @since 2.0
+ */
+ public int checkIndexOf(final String str, final int strStartIndex, final String search) {
+ final int endIndex = str.length() - search.length();
+ if (endIndex >= strStartIndex) {
+ for (int i = strStartIndex; i <= endIndex; i++) {
+ if (checkRegionMatches(str, i, search)) {
+ return i;
+ }
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Checks if one string contains another at a specific index using the case-sensitivity rule.
+ *
+ * This method mimics parts of {@link String#regionMatches(boolean, int, String, int, int)}
+ * but takes case-sensitivity into account.
+ *
+ * @param str the string to check, not null
+ * @param strStartIndex the index to start at in str
+ * @param search the start to search for, not null
+ * @return true if equal using the case rules
+ * @throws NullPointerException if either string is null
+ */
+ public boolean checkRegionMatches(final String str, final int strStartIndex, final String search) {
+ return str.regionMatches(!sensitive, strStartIndex, search, 0, search.length());
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets a string describing the sensitivity.
+ *
+ * @return a string describing the sensitivity
+ */
+ @Override
+ public String toString() {
+ return name;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOExceptionWithCause.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOExceptionWithCause.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ad652943e7f5559a14fce19d67271096bc56d418
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOExceptionWithCause.java"
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.commons.io;
+
+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
+ */
+@Deprecated
+public class IOExceptionWithCause extends IOException {
+
+ /**
+ * Defines the serial version UID.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructs a new instance with the given message and cause.
+ *
+ * As specified in {@link Throwable}, the message in the given cause is not used in this instance's
+ * message.
+ *
+ *
+ * @param message
+ * the message (see {@link #getMessage()})
+ * @param cause
+ * the cause (see {@link #getCause()}). A {@code null} value is allowed.
+ */
+ public IOExceptionWithCause(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new instance with the given cause.
+ *
+ * The message is set to cause==null ? null : cause.toString(), which by default contains the class
+ * and message of cause. This constructor is useful for call sites that just wrap another throwable.
+ *
+ *
+ * @param cause
+ * the cause (see {@link #getCause()}). A {@code null} value is allowed.
+ */
+ public IOExceptionWithCause(final Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOUtils.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOUtils.java"
new file mode 100644
index 0000000000000000000000000000000000000000..9da6933d7977be3a8bacd20c463235d5b812d120
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/IOUtils.java"
@@ -0,0 +1,3078 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.CharArrayWriter;
+import java.io.Closeable;
+import java.io.EOFException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.HttpURLConnection;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.Selector;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.io.output.StringBuilderWriter;
+
+/**
+ * General IO stream manipulation utilities.
+ *
+ * This class provides static utility methods for input/output operations.
+ *
+ * closeQuietly - these methods close a stream ignoring nulls and exceptions
+ * toXxx/read - these methods read data from a stream
+ * write - these methods write data to a stream
+ * copy - these methods copy all the data from one stream to another
+ * contentEquals - these methods compare the content of two streams
+ *
+ *
+ * The byte-to-char methods and char-to-byte methods involve a conversion step.
+ * Two methods are provided in each case, one that uses the platform default
+ * encoding and the other which allows you to specify an encoding. You are
+ * encouraged to always specify an encoding because relying on the platform
+ * default can lead to unexpected results, for example when moving from
+ * development to production.
+ *
+ * All the methods in this class that read a stream are buffered internally.
+ * This means that there is no cause to use a BufferedInputStream
+ * or BufferedReader. The default buffer size of 4K has been shown
+ * to be efficient in tests.
+ *
+ * The various copy methods all delegate the actual copying to one of the following methods:
+ *
+ * {@link #copyLarge(InputStream, OutputStream, byte[])}
+ * {@link #copyLarge(InputStream, OutputStream, long, long, byte[])}
+ * {@link #copyLarge(Reader, Writer, char[])}
+ * {@link #copyLarge(Reader, Writer, long, long, char[])}
+ *
+ * For example, {@link #copy(InputStream, OutputStream)} calls {@link #copyLarge(InputStream, OutputStream)}
+ * which calls {@link #copy(InputStream, OutputStream, int)} which creates the buffer and calls
+ * {@link #copyLarge(InputStream, OutputStream, byte[])}.
+ *
+ * Applications can re-use buffers by using the underlying methods directly.
+ * This may improve performance for applications that need to do a lot of copying.
+ *
+ * Wherever possible, the methods in this class do not flush or close
+ * the stream. This is to avoid making non-portable assumptions about the
+ * streams' origin and further use. Thus the caller is still responsible for
+ * closing streams after use.
+ *
+ * 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
+ // Writer. Each method should take at least one of these as a parameter,
+ // or return one of them.
+
+ /**
+ * Represents the end-of-file (or stream).
+ * @since 2.5 (made public)
+ */
+ public static final int EOF = -1;
+
+ /**
+ * The Unix directory separator character.
+ */
+ public static final char DIR_SEPARATOR_UNIX = '/';
+ /**
+ * The Windows directory separator character.
+ */
+ public static final char DIR_SEPARATOR_WINDOWS = '\\';
+ /**
+ * The system directory separator character.
+ */
+ public static final char DIR_SEPARATOR = File.separatorChar;
+ /**
+ * The Unix line separator string.
+ */
+ public static final String LINE_SEPARATOR_UNIX = "\n";
+ /**
+ * The Windows line separator string.
+ */
+ public static final String LINE_SEPARATOR_WINDOWS = "\r\n";
+ /**
+ * The system line separator string.
+ */
+ public static final String LINE_SEPARATOR;
+
+ static {
+ // avoid security issues
+ final StringBuilderWriter buf = new StringBuilderWriter(4);
+ final PrintWriter out = new PrintWriter(buf);
+ out.println();
+ LINE_SEPARATOR = buf.toString();
+ out.close();
+ }
+
+ /**
+ * The default buffer size ({@value}) to use for
+ * {@link #copyLarge(InputStream, OutputStream)}
+ * and
+ * {@link #copyLarge(Reader, Writer)}
+ */
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+ /**
+ * The default buffer size to use for the skip() methods.
+ */
+ private static final int SKIP_BUFFER_SIZE = 2048;
+
+ // Allocated in the relevant skip method if necessary.
+ /*
+ * These buffers are static and are shared between threads.
+ * This is possible because the buffers are write-only - the contents are never read.
+ *
+ * N.B. there is no need to synchronize when creating these because:
+ * - we don't care if the buffer is created multiple times (the data is ignored)
+ * - we always use the same size buffer, so if it it is recreated it will still be OK
+ * (if the buffer size were variable, we would need to synch. to ensure some other thread
+ * did not create a smaller one)
+ */
+ private static char[] SKIP_CHAR_BUFFER;
+ private static byte[] SKIP_BYTE_BUFFER;
+
+ /**
+ * Instances should NOT be constructed in standard programming.
+ */
+ public IOUtils() {
+ super();
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Closes a URLConnection.
+ *
+ * @param conn the connection to close.
+ * @since 2.4
+ */
+ public static void close(final URLConnection conn) {
+ if (conn instanceof HttpURLConnection) {
+ ((HttpURLConnection) conn).disconnect();
+ }
+ }
+
+ /**
+ * Closes an Reader unconditionally.
+ *
+ * Equivalent to {@link Reader#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * Example code:
+ *
+ * char[] data = new char[1024];
+ * Reader in = null;
+ * try {
+ * in = new FileReader("foo.txt");
+ * in.read(data);
+ * in.close(); //close errors are handled
+ * } catch (Exception e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(in);
+ * }
+ *
+ *
+ * @param input the Reader to close, may be null or already closed
+ */
+ public static void closeQuietly(final Reader input) {
+ closeQuietly((Closeable) input);
+ }
+
+ /**
+ * Closes an Writer unconditionally.
+ *
+ * Equivalent to {@link Writer#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * Example code:
+ *
+ * Writer out = null;
+ * try {
+ * out = new StringWriter();
+ * out.write("Hello World");
+ * out.close(); //close errors are handled
+ * } catch (Exception e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(out);
+ * }
+ *
+ *
+ * @param output the Writer to close, may be null or already closed
+ */
+ public static void closeQuietly(final Writer output) {
+ closeQuietly((Closeable) output);
+ }
+
+ /**
+ * Closes an InputStream unconditionally.
+ *
+ * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * Example code:
+ *
+ * byte[] data = new byte[1024];
+ * InputStream in = null;
+ * try {
+ * in = new FileInputStream("foo.txt");
+ * in.read(data);
+ * in.close(); //close errors are handled
+ * } catch (Exception e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(in);
+ * }
+ *
+ *
+ * @param input the InputStream to close, may be null or already closed
+ */
+ public static void closeQuietly(final InputStream input) {
+ closeQuietly((Closeable) input);
+ }
+
+ /**
+ * Closes an OutputStream unconditionally.
+ *
+ * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * Example code:
+ *
+ * byte[] data = "Hello, World".getBytes();
+ *
+ * OutputStream out = null;
+ * try {
+ * out = new FileOutputStream("foo.txt");
+ * out.write(data);
+ * out.close(); //close errors are handled
+ * } catch (IOException e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(out);
+ * }
+ *
+ *
+ * @param output the OutputStream to close, may be null or already closed
+ */
+ public static void closeQuietly(final OutputStream output) {
+ closeQuietly((Closeable) output);
+ }
+
+ /**
+ * Closes a Closeable unconditionally.
+ *
+ * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored. This is typically used in
+ * finally blocks.
+ *
+ * Example code:
+ *
+ *
+ * Closeable closeable = null;
+ * try {
+ * closeable = new FileReader("foo.txt");
+ * // process closeable
+ * closeable.close();
+ * } catch (Exception e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(closeable);
+ * }
+ *
+ *
+ * Closing all streams:
+ *
+ *
+ * try {
+ * return IOUtils.copy(inputStream, outputStream);
+ * } finally {
+ * IOUtils.closeQuietly(inputStream);
+ * IOUtils.closeQuietly(outputStream);
+ * }
+ *
+ *
+ * @param closeable the objects to close, may be null or already closed
+ * @since 2.0
+ */
+ public static void closeQuietly(final Closeable closeable) {
+ try {
+ if (closeable != null) {
+ closeable.close();
+ }
+ } catch (final IOException ioe) {
+ // ignore
+ }
+ }
+
+ /**
+ * Closes a Closeable unconditionally.
+ *
+ * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored.
+ *
+ * This is typically used in finally blocks to ensure that the closeable is closed
+ * even if an Exception was thrown before the normal close statement was reached.
+ *
+ * It should not be used to replace the close statement(s)
+ * which should be present for the non-exceptional case.
+ *
+ * It is only intended to simplify tidying up where normal processing has already failed
+ * and reporting close failure as well is not necessary or useful.
+ *
+ * Example code:
+ *
+ *
+ * Closeable closeable = null;
+ * try {
+ * closeable = new FileReader("foo.txt");
+ * // processing using the closeable; may throw an Exception
+ * closeable.close(); // Normal close - exceptions not ignored
+ * } catch (Exception e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(closeable); // In case normal close was skipped due to Exception
+ * }
+ *
+ *
+ * Closing all streams:
+ *
+ *
+ * try {
+ * return IOUtils.copy(inputStream, outputStream);
+ * } finally {
+ * IOUtils.closeQuietly(inputStream, outputStream);
+ * }
+ *
+ *
+ * @param closeables the objects to close, may be null or already closed
+ * @see #closeQuietly(Closeable)
+ * @since 2.5
+ */
+ public static void closeQuietly(final Closeable... closeables) {
+ if (closeables == null) {
+ return;
+ }
+ for (final Closeable closeable : closeables) {
+ closeQuietly(closeable);
+ }
+ }
+
+ /**
+ * Closes a Socket unconditionally.
+ *
+ * Equivalent to {@link Socket#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * Example code:
+ *
+ * Socket socket = null;
+ * try {
+ * socket = new Socket("http://www.foo.com/", 80);
+ * // process socket
+ * socket.close();
+ * } catch (Exception e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(socket);
+ * }
+ *
+ *
+ * @param sock the Socket to close, may be null or already closed
+ * @since 2.0
+ */
+ public static void closeQuietly(final Socket sock) {
+ if (sock != null) {
+ try {
+ sock.close();
+ } catch (final IOException ioe) {
+ // ignored
+ }
+ }
+ }
+
+ /**
+ * Closes a Selector unconditionally.
+ *
+ * Equivalent to {@link Selector#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * Example code:
+ *
+ * Selector selector = null;
+ * try {
+ * selector = Selector.open();
+ * // process socket
+ *
+ * } catch (Exception e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(selector);
+ * }
+ *
+ *
+ * @param selector the Selector to close, may be null or already closed
+ * @since 2.2
+ */
+ public static void closeQuietly(final Selector selector) {
+ if (selector != null) {
+ try {
+ selector.close();
+ } catch (final IOException ioe) {
+ // ignored
+ }
+ }
+ }
+
+ /**
+ * Closes a ServerSocket unconditionally.
+ *
+ * Equivalent to {@link ServerSocket#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * Example code:
+ *
+ * ServerSocket socket = null;
+ * try {
+ * socket = new ServerSocket();
+ * // process socket
+ * socket.close();
+ * } catch (Exception e) {
+ * // error handling
+ * } finally {
+ * IOUtils.closeQuietly(socket);
+ * }
+ *
+ *
+ * @param sock the ServerSocket to close, may be null or already closed
+ * @since 2.2
+ */
+ public static void closeQuietly(final ServerSocket sock) {
+ if (sock != null) {
+ try {
+ sock.close();
+ } catch (final IOException ioe) {
+ // ignored
+ }
+ }
+ }
+
+ /**
+ * Fetches entire contents of an InputStream and represent
+ * same data as result InputStream.
+ *
+ * This method is useful where,
+ *
+ * Source InputStream is slow.
+ * It has network resources associated, so we cannot keep it open for
+ * long time.
+ * It has network timeout associated.
+ *
+ * It can be used in favor of {@link #toByteArray(InputStream)}, since it
+ * avoids unnecessary allocation and copy of byte[].
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input Stream to be fully buffered.
+ * @return A fully buffered stream.
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ public static InputStream toBufferedInputStream(final InputStream input) throws IOException {
+ return ByteArrayOutputStream.toBufferedInputStream(input);
+ }
+
+ /**
+ * Fetches entire contents of an InputStream and represent
+ * same data as result InputStream.
+ *
+ * This method is useful where,
+ *
+ * Source InputStream is slow.
+ * It has network resources associated, so we cannot keep it open for
+ * long time.
+ * It has network timeout associated.
+ *
+ * It can be used in favor of {@link #toByteArray(InputStream)}, since it
+ * avoids unnecessary allocation and copy of byte[].
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input Stream to be fully buffered.
+ * @param size the initial buffer size
+ * @return A fully buffered stream.
+ * @throws IOException if an I/O error occurs
+ * @since 2.5
+ */
+ public static InputStream toBufferedInputStream(final InputStream input, int size) throws IOException {
+ return ByteArrayOutputStream.toBufferedInputStream(input, size);
+ }
+
+ /**
+ * Returns the given reader if it is a {@link BufferedReader}, otherwise creates a BufferedReader from the given
+ * reader.
+ *
+ * @param reader the reader to wrap or return (not null)
+ * @return the given reader or a new {@link BufferedReader} for the given reader
+ * @throws NullPointerException if the input parameter is null
+ * @see #buffer(Reader)
+ * @since 2.2
+ */
+ public static BufferedReader toBufferedReader(final Reader reader) {
+ return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
+ }
+
+ /**
+ * Returns the given reader if it is a {@link BufferedReader}, otherwise creates a BufferedReader from the given
+ * reader.
+ *
+ * @param reader the reader to wrap or return (not null)
+ * @param size the buffer size, if a new BufferedReader is created.
+ * @return the given reader or a new {@link BufferedReader} for the given reader
+ * @throws NullPointerException if the input parameter is null
+ * @see #buffer(Reader)
+ * @since 2.5
+ */
+ public static BufferedReader toBufferedReader(final Reader reader, int size) {
+ return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, size);
+ }
+
+ /**
+ * Returns the given reader if it is already a {@link BufferedReader}, otherwise creates a BufferedReader from
+ * the given reader.
+ *
+ * @param reader the reader to wrap or return (not null)
+ * @return the given reader or a new {@link BufferedReader} for the given reader
+ * @throws NullPointerException if the input parameter is null
+ * @since 2.5
+ */
+ public static BufferedReader buffer(final Reader reader) {
+ return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
+ }
+
+ /**
+ * Returns the given reader if it is already a {@link BufferedReader}, otherwise creates a BufferedReader from the
+ * given reader.
+ *
+ * @param reader the reader to wrap or return (not null)
+ * @param size the buffer size, if a new BufferedReader is created.
+ * @return the given reader or a new {@link BufferedReader} for the given reader
+ * @throws NullPointerException if the input parameter is null
+ * @since 2.5
+ */
+ public static BufferedReader buffer(final Reader reader, int size) {
+ return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, size);
+ }
+
+ /**
+ * Returns the given Writer if it is already a {@link BufferedWriter}, otherwise creates a BufferedWriter from the
+ * given Writer.
+ *
+ * @param writer the Writer to wrap or return (not null)
+ * @return the given Writer or a new {@link BufferedWriter} for the given Writer
+ * @throws NullPointerException if the input parameter is null
+ * @since 2.5
+ */
+ public static BufferedWriter buffer(final Writer writer) {
+ return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer);
+ }
+
+ /**
+ * Returns the given Writer if it is already a {@link BufferedWriter}, otherwise creates a BufferedWriter from the
+ * given Writer.
+ *
+ * @param writer the Writer to wrap or return (not null)
+ * @param size the buffer size, if a new BufferedWriter is created.
+ * @return the given Writer or a new {@link BufferedWriter} for the given Writer
+ * @throws NullPointerException if the input parameter is null
+ * @since 2.5
+ */
+ public static BufferedWriter buffer(final Writer writer, int size) {
+ return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer, size);
+ }
+
+ /**
+ * Returns the given OutputStream if it is already a {@link BufferedOutputStream}, otherwise creates a
+ * BufferedOutputStream from the given OutputStream.
+ *
+ * @param outputStream the OutputStream to wrap or return (not null)
+ * @return the given OutputStream or a new {@link BufferedOutputStream} for the given OutputStream
+ * @throws NullPointerException if the input parameter is null
+ * @since 2.5
+ */
+ public static BufferedOutputStream buffer(final OutputStream outputStream) {
+ // reject null early on rather than waiting for IO operation to fail
+ if (outputStream == null) { // not checked by BufferedOutputStream
+ throw new NullPointerException();
+ }
+ return outputStream instanceof BufferedOutputStream ?
+ (BufferedOutputStream) outputStream : new BufferedOutputStream(outputStream);
+ }
+
+ /**
+ * Returns the given OutputStream if it is already a {@link BufferedOutputStream}, otherwise creates a
+ * BufferedOutputStream from the given OutputStream.
+ *
+ * @param outputStream the OutputStream to wrap or return (not null)
+ * @param size the buffer size, if a new BufferedOutputStream is created.
+ * @return the given OutputStream or a new {@link BufferedOutputStream} for the given OutputStream
+ * @throws NullPointerException if the input parameter is null
+ * @since 2.5
+ */
+ 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();
+ }
+ return outputStream instanceof BufferedOutputStream ?
+ (BufferedOutputStream) outputStream : new BufferedOutputStream(outputStream, size);
+ }
+
+ /**
+ * Returns the given InputStream if it is already a {@link BufferedInputStream}, otherwise creates a
+ * BufferedInputStream from the given InputStream.
+ *
+ * @param inputStream the InputStream to wrap or return (not null)
+ * @return the given InputStream or a new {@link BufferedInputStream} for the given InputStream
+ * @throws NullPointerException if the input parameter is null
+ * @since 2.5
+ */
+ public static BufferedInputStream buffer(final InputStream inputStream) {
+ // reject null early on rather than waiting for IO operation to fail
+ if (inputStream == null) { // not checked by BufferedInputStream
+ throw new NullPointerException();
+ }
+ return inputStream instanceof BufferedInputStream ?
+ (BufferedInputStream) inputStream : new BufferedInputStream(inputStream);
+ }
+
+ /**
+ * Returns the given InputStream if it is already a {@link BufferedInputStream}, otherwise creates a
+ * BufferedInputStream from the given InputStream.
+ *
+ * @param inputStream the InputStream to wrap or return (not null)
+ * @param size the buffer size, if a new BufferedInputStream is created.
+ * @return the given InputStream or a new {@link BufferedInputStream} for the given InputStream
+ * @throws NullPointerException if the input parameter is null
+ * @since 2.5
+ */
+ 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();
+ }
+ return inputStream instanceof BufferedInputStream ?
+ (BufferedInputStream) inputStream : new BufferedInputStream(inputStream, size);
+ }
+
+ // read toByteArray
+ //-----------------------------------------------------------------------
+
+ /**
+ * Gets the contents of an InputStream as a byte[].
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input the InputStream to read from
+ * @return the requested byte array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ */
+ public static byte[] toByteArray(final InputStream input) throws IOException {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ copy(input, output);
+ return output.toByteArray();
+ }
+
+ /**
+ * Gets contents of an InputStream as a byte[].
+ * Use this method instead of toByteArray(InputStream)
+ * when InputStream size is known.
+ * NOTE: the method checks that the length can safely be cast to an int without truncation
+ * before using {@link IOUtils#toByteArray(java.io.InputStream, int)} to read into the byte array.
+ * (Arrays can have no more than Integer.MAX_VALUE entries anyway)
+ *
+ * @param input the InputStream to read from
+ * @param size the size of InputStream
+ * @return the requested byte array
+ * @throws IOException if an I/O error occurs or InputStream size differ from parameter
+ * size
+ * @throws IllegalArgumentException if size is less than zero or size is greater than Integer.MAX_VALUE
+ * @see IOUtils#toByteArray(java.io.InputStream, int)
+ * @since 2.1
+ */
+ public static byte[] toByteArray(final InputStream input, final long size) throws IOException {
+
+ if (size > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size);
+ }
+
+ return toByteArray(input, (int) size);
+ }
+
+ /**
+ * Gets the contents of an InputStream as a byte[].
+ * Use this method instead of toByteArray(InputStream)
+ * when InputStream size is known
+ *
+ * @param input the InputStream to read from
+ * @param size the size of InputStream
+ * @return the requested byte array
+ * @throws IOException if an I/O error occurs or InputStream size differ from parameter
+ * size
+ * @throws IllegalArgumentException if size is less than zero
+ * @since 2.1
+ */
+ public static byte[] toByteArray(final InputStream input, final int size) throws IOException {
+
+ if (size < 0) {
+ throw new IllegalArgumentException("Size must be equal or greater than zero: " + size);
+ }
+
+ if (size == 0) {
+ return new byte[0];
+ }
+
+ final byte[] data = new byte[size];
+ int offset = 0;
+ int readed;
+
+ while (offset < size && (readed = input.read(data, offset, size - offset)) != EOF) {
+ offset += readed;
+ }
+
+ if (offset != size) {
+ throw new IOException("Unexpected readed size. current: " + offset + ", excepted: " + size);
+ }
+
+ return data;
+ }
+
+ /**
+ * Gets the contents of a Reader as a byte[]
+ * using the default character encoding of the platform.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * @param input the Reader to read from
+ * @return the requested byte array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @deprecated 2.5 use {@link #toByteArray(Reader, Charset)} instead
+ */
+ @Deprecated
+ public static byte[] toByteArray(final Reader input) throws IOException {
+ return toByteArray(input, Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the contents of a Reader as a byte[]
+ * using the specified character encoding.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * @param input the Reader to read from
+ * @param encoding the encoding to use, null means platform default
+ * @return the requested byte array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static byte[] toByteArray(final Reader input, final Charset encoding) throws IOException {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ copy(input, output, encoding);
+ return output.toByteArray();
+ }
+
+ /**
+ * Gets the contents of a Reader as a byte[]
+ * using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * @param input the Reader to read from
+ * @param encoding the encoding to use, null means platform default
+ * @return the requested byte array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.1
+ */
+ public static byte[] toByteArray(final Reader input, final String encoding) throws IOException {
+ return toByteArray(input, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Gets the contents of a String as a byte[]
+ * using the default character encoding of the platform.
+ *
+ * This is the same as {@link String#getBytes()}.
+ *
+ * @param input the String to convert
+ * @return the requested byte array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs (never occurs)
+ * @deprecated 2.5 Use {@link String#getBytes()} instead
+ */
+ @Deprecated
+ public static byte[] toByteArray(final String input) throws IOException {
+ // make explicit the use of the default charset
+ return input.getBytes(Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the contents of a URI as a byte[].
+ *
+ * @param uri the URI to read
+ * @return the requested byte array
+ * @throws NullPointerException if the uri is null
+ * @throws IOException if an I/O exception occurs
+ * @since 2.4
+ */
+ public static byte[] toByteArray(final URI uri) throws IOException {
+ return IOUtils.toByteArray(uri.toURL());
+ }
+
+ /**
+ * Gets the contents of a URL as a byte[].
+ *
+ * @param url the URL to read
+ * @return the requested byte array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O exception occurs
+ * @since 2.4
+ */
+ public static byte[] toByteArray(final URL url) throws IOException {
+ final URLConnection conn = url.openConnection();
+ try {
+ return IOUtils.toByteArray(conn);
+ } finally {
+ close(conn);
+ }
+ }
+
+ /**
+ * Gets the contents of a URLConnection as a byte[].
+ *
+ * @param urlConn the URLConnection to read
+ * @return the requested byte array
+ * @throws NullPointerException if the urlConn is null
+ * @throws IOException if an I/O exception occurs
+ * @since 2.4
+ */
+ public static byte[] toByteArray(final URLConnection urlConn) throws IOException {
+ final InputStream inputStream = urlConn.getInputStream();
+ try {
+ return IOUtils.toByteArray(inputStream);
+ } finally {
+ inputStream.close();
+ }
+ }
+
+ // read char[]
+ //-----------------------------------------------------------------------
+
+ /**
+ * Gets the contents of an InputStream as a character array
+ * using the default character encoding of the platform.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param is the InputStream to read from
+ * @return the requested character array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated 2.5 use {@link #toCharArray(InputStream, Charset)} instead
+ */
+ @Deprecated
+ public static char[] toCharArray(final InputStream is) throws IOException {
+ return toCharArray(is, Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the contents of an InputStream as a character array
+ * using the specified character encoding.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param is the InputStream to read from
+ * @param encoding the encoding to use, null means platform default
+ * @return the requested character array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static char[] toCharArray(final InputStream is, final Charset encoding)
+ throws IOException {
+ final CharArrayWriter output = new CharArrayWriter();
+ copy(is, output, encoding);
+ return output.toCharArray();
+ }
+
+ /**
+ * Gets the contents of an InputStream as a character array
+ * using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param is the InputStream to read from
+ * @param encoding the encoding to use, null means platform default
+ * @return the requested character array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.1
+ */
+ public static char[] toCharArray(final InputStream is, final String encoding) throws IOException {
+ return toCharArray(is, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Gets the contents of a Reader as a character array.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * @param input the Reader to read from
+ * @return the requested character array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static char[] toCharArray(final Reader input) throws IOException {
+ final CharArrayWriter sw = new CharArrayWriter();
+ copy(input, sw);
+ return sw.toCharArray();
+ }
+
+ // read toString
+ //-----------------------------------------------------------------------
+
+ /**
+ * Gets the contents of an InputStream as a String
+ * using the default character encoding of the platform.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input the InputStream to read from
+ * @return the requested String
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @deprecated 2.5 use {@link #toString(InputStream, Charset)} instead
+ */
+ @Deprecated
+ public static String toString(final InputStream input) throws IOException {
+ return toString(input, Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the contents of an InputStream as a String
+ * using the specified character encoding.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ *
+ * @param input the InputStream to read from
+ * @param encoding the encoding to use, null means platform default
+ * @return the requested String
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static String toString(final InputStream input, final Charset encoding) throws IOException {
+ final StringBuilderWriter sw = new StringBuilderWriter();
+ copy(input, sw, encoding);
+ return sw.toString();
+ }
+
+ /**
+ * Gets the contents of an InputStream as a String
+ * using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input the InputStream to read from
+ * @param encoding the encoding to use, null means platform default
+ * @return the requested String
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ */
+ public static String toString(final InputStream input, final String encoding)
+ throws IOException {
+ return toString(input, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Gets the contents of a Reader as a String.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * @param input the Reader to read from
+ * @return the requested String
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ */
+ public static String toString(final Reader input) throws IOException {
+ final StringBuilderWriter sw = new StringBuilderWriter();
+ copy(input, sw);
+ return sw.toString();
+ }
+
+ /**
+ * Gets the contents at the given URI.
+ *
+ * @param uri The URI source.
+ * @return The contents of the URL as a String.
+ * @throws IOException if an I/O exception occurs.
+ * @since 2.1
+ * @deprecated 2.5 use {@link #toString(URI, Charset)} instead
+ */
+ @Deprecated
+ public static String toString(final URI uri) throws IOException {
+ return toString(uri, Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the contents at the given URI.
+ *
+ * @param uri The URI source.
+ * @param encoding The encoding name for the URL contents.
+ * @return The contents of the URL as a String.
+ * @throws IOException if an I/O exception occurs.
+ * @since 2.3.
+ */
+ public static String toString(final URI uri, final Charset encoding) throws IOException {
+ return toString(uri.toURL(), Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Gets the contents at the given URI.
+ *
+ * @param uri The URI source.
+ * @param encoding The encoding name for the URL contents.
+ * @return The contents of the URL as a String.
+ * @throws IOException if an I/O exception occurs.
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 2.1
+ */
+ public static String toString(final URI uri, final String encoding) throws IOException {
+ return toString(uri, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Gets the contents at the given URL.
+ *
+ * @param url The URL source.
+ * @return The contents of the URL as a String.
+ * @throws IOException if an I/O exception occurs.
+ * @since 2.1
+ * @deprecated 2.5 use {@link #toString(URL, Charset)} instead
+ */
+ @Deprecated
+ public static String toString(final URL url) throws IOException {
+ return toString(url, Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the contents at the given URL.
+ *
+ * @param url The URL source.
+ * @param encoding The encoding name for the URL contents.
+ * @return The contents of the URL as a String.
+ * @throws IOException if an I/O exception occurs.
+ * @since 2.3
+ */
+ public static String toString(final URL url, final Charset encoding) throws IOException {
+ final InputStream inputStream = url.openStream();
+ try {
+ return toString(inputStream, encoding);
+ } finally {
+ inputStream.close();
+ }
+ }
+
+ /**
+ * Gets the contents at the given URL.
+ *
+ * @param url The URL source.
+ * @param encoding The encoding name for the URL contents.
+ * @return The contents of the URL as a String.
+ * @throws IOException if an I/O exception occurs.
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 2.1
+ */
+ public static String toString(final URL url, final String encoding) throws IOException {
+ return toString(url, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Gets the contents of a byte[] as a String
+ * using the default character encoding of the platform.
+ *
+ * @param input the byte array to read from
+ * @return the requested String
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs (never occurs)
+ * @deprecated 2.5 Use {@link String#String(byte[])} instead
+ */
+ @Deprecated
+ public static String toString(final byte[] input) throws IOException {
+ // make explicit the use of the default charset
+ return new String(input, Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the contents of a byte[] as a String
+ * using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * @param input the byte array to read from
+ * @param encoding the encoding to use, null means platform default
+ * @return the requested String
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs (never occurs)
+ */
+ public static String toString(final byte[] input, final String encoding) throws IOException {
+ return new String(input, Charsets.toCharset(encoding));
+ }
+
+ // readLines
+ //-----------------------------------------------------------------------
+
+ /**
+ * Gets the contents of an InputStream as a list of Strings,
+ * one entry per line, using the default character encoding of the platform.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input the InputStream to read from, not null
+ * @return the list of Strings, never null
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated 2.5 use {@link #readLines(InputStream, Charset)} instead
+ */
+ @Deprecated
+ public static List readLines(final InputStream input) throws IOException {
+ return readLines(input, Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the contents of an InputStream as a list of Strings,
+ * one entry per line, using the specified character encoding.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input the InputStream to read from, not null
+ * @param encoding the encoding to use, null means platform default
+ * @return the list of Strings, never null
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static List readLines(final InputStream input, final Charset encoding) throws IOException {
+ final InputStreamReader reader = new InputStreamReader(input, Charsets.toCharset(encoding));
+ return readLines(reader);
+ }
+
+ /**
+ * Gets the contents of an InputStream as a list of Strings,
+ * one entry per line, using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input the InputStream to read from, not null
+ * @param encoding the encoding to use, null means platform default
+ * @return the list of Strings, never null
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.1
+ */
+ public static List readLines(final InputStream input, final String encoding) throws IOException {
+ return readLines(input, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Gets the contents of a Reader as a list of Strings,
+ * one entry per line.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * @param input the Reader to read from, not null
+ * @return the list of Strings, never null
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static List readLines(final Reader input) throws IOException {
+ final BufferedReader reader = toBufferedReader(input);
+ final List list = new ArrayList();
+ String line = reader.readLine();
+ while (line != null) {
+ list.add(line);
+ line = reader.readLine();
+ }
+ return list;
+ }
+
+ // lineIterator
+ //-----------------------------------------------------------------------
+
+ /**
+ * Returns an Iterator for the lines in a Reader.
+ *
+ * LineIterator holds a reference to the open
+ * Reader specified here. When you have finished with the
+ * iterator you should close the reader to free internal resources.
+ * This can be done by closing the reader directly, or by calling
+ * {@link LineIterator#close()} or {@link LineIterator#closeQuietly(LineIterator)}.
+ *
+ * The recommended usage pattern is:
+ *
+ * try {
+ * LineIterator it = IOUtils.lineIterator(reader);
+ * while (it.hasNext()) {
+ * String line = it.nextLine();
+ * /// do something with line
+ * }
+ * } finally {
+ * IOUtils.closeQuietly(reader);
+ * }
+ *
+ *
+ * @param reader the Reader to read from, not null
+ * @return an Iterator of the lines in the reader, never null
+ * @throws IllegalArgumentException if the reader is null
+ * @since 1.2
+ */
+ public static LineIterator lineIterator(final Reader reader) {
+ return new LineIterator(reader);
+ }
+
+ /**
+ * Returns an Iterator for the lines in an InputStream, using
+ * the character encoding specified (or default encoding if null).
+ *
+ * LineIterator holds a reference to the open
+ * InputStream specified here. When you have finished with
+ * the iterator you should close the stream to free internal resources.
+ * This can be done by closing the stream directly, or by calling
+ * {@link LineIterator#close()} or {@link LineIterator#closeQuietly(LineIterator)}.
+ *
+ * The recommended usage pattern is:
+ *
+ * try {
+ * LineIterator it = IOUtils.lineIterator(stream, charset);
+ * while (it.hasNext()) {
+ * String line = it.nextLine();
+ * /// do something with line
+ * }
+ * } finally {
+ * IOUtils.closeQuietly(stream);
+ * }
+ *
+ *
+ * @param input the InputStream to read from, not null
+ * @param encoding the encoding to use, null means platform default
+ * @return an Iterator of the lines in the reader, never null
+ * @throws IllegalArgumentException if the input is null
+ * @throws IOException if an I/O error occurs, such as if the encoding is invalid
+ * @since 2.3
+ */
+ public static LineIterator lineIterator(final InputStream input, final Charset encoding) throws IOException {
+ return new LineIterator(new InputStreamReader(input, Charsets.toCharset(encoding)));
+ }
+
+ /**
+ * Returns an Iterator for the lines in an InputStream, using
+ * the character encoding specified (or default encoding if null).
+ *
+ * LineIterator holds a reference to the open
+ * InputStream specified here. When you have finished with
+ * the iterator you should close the stream to free internal resources.
+ * This can be done by closing the stream directly, or by calling
+ * {@link LineIterator#close()} or {@link LineIterator#closeQuietly(LineIterator)}.
+ *
+ * The recommended usage pattern is:
+ *
+ * try {
+ * LineIterator it = IOUtils.lineIterator(stream, "UTF-8");
+ * while (it.hasNext()) {
+ * String line = it.nextLine();
+ * /// do something with line
+ * }
+ * } finally {
+ * IOUtils.closeQuietly(stream);
+ * }
+ *
+ *
+ * @param input the InputStream to read from, not null
+ * @param encoding the encoding to use, null means platform default
+ * @return an Iterator of the lines in the reader, never null
+ * @throws IllegalArgumentException if the input is null
+ * @throws IOException if an I/O error occurs, such as if the encoding is invalid
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.2
+ */
+ public static LineIterator lineIterator(final InputStream input, final String encoding) throws IOException {
+ return lineIterator(input, Charsets.toCharset(encoding));
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Converts the specified CharSequence to an input stream, encoded as bytes
+ * using the default character encoding of the platform.
+ *
+ * @param input the CharSequence to convert
+ * @return an input stream
+ * @since 2.0
+ * @deprecated 2.5 use {@link #toInputStream(CharSequence, Charset)} instead
+ */
+ @Deprecated
+ public static InputStream toInputStream(final CharSequence input) {
+ return toInputStream(input, Charset.defaultCharset());
+ }
+
+ /**
+ * Converts the specified CharSequence to an input stream, encoded as bytes
+ * using the specified character encoding.
+ *
+ * @param input the CharSequence to convert
+ * @param encoding the encoding to use, null means platform default
+ * @return an input stream
+ * @since 2.3
+ */
+ public static InputStream toInputStream(final CharSequence input, final Charset encoding) {
+ return toInputStream(input.toString(), encoding);
+ }
+
+ /**
+ * Converts the specified CharSequence to an input stream, encoded as bytes
+ * using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * @param input the CharSequence to convert
+ * @param encoding the encoding to use, null means platform default
+ * @return an input stream
+ * @throws IOException if the encoding is invalid
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 2.0
+ */
+ public static InputStream toInputStream(final CharSequence input, final String encoding) throws IOException {
+ return toInputStream(input, Charsets.toCharset(encoding));
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Converts the specified string to an input stream, encoded as bytes
+ * using the default character encoding of the platform.
+ *
+ * @param input the string to convert
+ * @return an input stream
+ * @since 1.1
+ * @deprecated 2.5 use {@link #toInputStream(String, Charset)} instead
+ */
+ @Deprecated
+ public static InputStream toInputStream(final String input) {
+ return toInputStream(input, Charset.defaultCharset());
+ }
+
+ /**
+ * Converts the specified string to an input stream, encoded as bytes
+ * using the specified character encoding.
+ *
+ * @param input the string to convert
+ * @param encoding the encoding to use, null means platform default
+ * @return an input stream
+ * @since 2.3
+ */
+ public static InputStream toInputStream(final String input, final Charset encoding) {
+ return new ByteArrayInputStream(input.getBytes(Charsets.toCharset(encoding)));
+ }
+
+ /**
+ * Converts the specified string to an input stream, encoded as bytes
+ * using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * @param input the string to convert
+ * @param encoding the encoding to use, null means platform default
+ * @return an input stream
+ * @throws IOException if the encoding is invalid
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.1
+ */
+ public static InputStream toInputStream(final String input, final String encoding) throws IOException {
+ final byte[] bytes = input.getBytes(Charsets.toCharset(encoding));
+ return new ByteArrayInputStream(bytes);
+ }
+
+ // write byte[]
+ //-----------------------------------------------------------------------
+
+ /**
+ * Writes bytes from a byte[] to an OutputStream.
+ *
+ * @param data the byte array to write, do not modify during output,
+ * null ignored
+ * @param output the OutputStream to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static void write(final byte[] data, final OutputStream output)
+ throws IOException {
+ if (data != null) {
+ output.write(data);
+ }
+ }
+
+ /**
+ * Writes bytes from a byte[] to an OutputStream using chunked writes.
+ * This is intended for writing very large byte arrays which might otherwise cause excessive
+ * memory usage if the native code has to allocate a copy.
+ *
+ * @param data the byte array to write, do not modify during output,
+ * null ignored
+ * @param output the OutputStream to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.5
+ */
+ public static void writeChunked(final byte[] data, final OutputStream output)
+ throws IOException {
+ if (data != null) {
+ int bytes = data.length;
+ int offset = 0;
+ while (bytes > 0) {
+ int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
+ output.write(data, offset, chunk);
+ bytes -= chunk;
+ offset += chunk;
+ }
+ }
+ }
+
+ /**
+ * Writes bytes from a byte[] to chars on a Writer
+ * using the default character encoding of the platform.
+ *
+ * This method uses {@link String#String(byte[])}.
+ *
+ * @param data the byte array to write, do not modify during output,
+ * null ignored
+ * @param output the Writer to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated 2.5 use {@link #write(byte[], Writer, Charset)} instead
+ */
+ @Deprecated
+ public static void write(final byte[] data, final Writer output) throws IOException {
+ write(data, output, Charset.defaultCharset());
+ }
+
+ /**
+ * Writes bytes from a byte[] to chars on a Writer
+ * using the specified character encoding.
+ *
+ * This method uses {@link String#String(byte[], String)}.
+ *
+ * @param data the byte array to write, do not modify during output,
+ * null ignored
+ * @param output the Writer to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static void write(final byte[] data, final Writer output, final Charset encoding) throws IOException {
+ if (data != null) {
+ output.write(new String(data, Charsets.toCharset(encoding)));
+ }
+ }
+
+ /**
+ * Writes bytes from a byte[] to chars on a Writer
+ * using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method uses {@link String#String(byte[], String)}.
+ *
+ * @param data the byte array to write, do not modify during output,
+ * null ignored
+ * @param output the Writer to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.1
+ */
+ public static void write(final byte[] data, final Writer output, final String encoding) throws IOException {
+ write(data, output, Charsets.toCharset(encoding));
+ }
+
+ // write char[]
+ //-----------------------------------------------------------------------
+
+ /**
+ * Writes chars from a char[] to a Writer
+ *
+ * @param data the char array to write, do not modify during output,
+ * null ignored
+ * @param output the Writer to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static void write(final char[] data, final Writer output) throws IOException {
+ if (data != null) {
+ output.write(data);
+ }
+ }
+
+ /**
+ * Writes chars from a char[] to a Writer using chunked writes.
+ * This is intended for writing very large byte arrays which might otherwise cause excessive
+ * memory usage if the native code has to allocate a copy.
+ *
+ * @param data the char array to write, do not modify during output,
+ * null ignored
+ * @param output the Writer to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.5
+ */
+ public static void writeChunked(final char[] data, final Writer output) throws IOException {
+ if (data != null) {
+ int bytes = data.length;
+ int offset = 0;
+ while (bytes > 0) {
+ int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
+ output.write(data, offset, chunk);
+ bytes -= chunk;
+ offset += chunk;
+ }
+ }
+ }
+
+ /**
+ * Writes chars from a char[] to bytes on an
+ * OutputStream.
+ *
+ * This method uses {@link String#String(char[])} and
+ * {@link String#getBytes()}.
+ *
+ * @param data the char array to write, do not modify during output,
+ * null ignored
+ * @param output the OutputStream to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated 2.5 use {@link #write(char[], OutputStream, Charset)} instead
+ */
+ @Deprecated
+ public static void write(final char[] data, final OutputStream output)
+ throws IOException {
+ write(data, output, Charset.defaultCharset());
+ }
+
+ /**
+ * Writes chars from a char[] to bytes on an
+ * OutputStream using the specified character encoding.
+ *
+ * This method uses {@link String#String(char[])} and
+ * {@link String#getBytes(String)}.
+ *
+ * @param data the char array to write, do not modify during output,
+ * null ignored
+ * @param output the OutputStream to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static void write(final char[] data, final OutputStream output, final Charset encoding) throws IOException {
+ if (data != null) {
+ output.write(new String(data).getBytes(Charsets.toCharset(encoding)));
+ }
+ }
+
+ /**
+ * Writes chars from a char[] to bytes on an
+ * OutputStream using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method uses {@link String#String(char[])} and
+ * {@link String#getBytes(String)}.
+ *
+ * @param data the char array to write, do not modify during output,
+ * null ignored
+ * @param output the OutputStream to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the encoding is not supported.
+ * @since 1.1
+ */
+ public static void write(final char[] data, final OutputStream output, final String encoding)
+ throws IOException {
+ write(data, output, Charsets.toCharset(encoding));
+ }
+
+ // write CharSequence
+ //-----------------------------------------------------------------------
+
+ /**
+ * Writes chars from a CharSequence to a Writer.
+ *
+ * @param data the CharSequence to write, null ignored
+ * @param output the Writer to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ public static void write(final CharSequence data, final Writer output) throws IOException {
+ if (data != null) {
+ write(data.toString(), output);
+ }
+ }
+
+ /**
+ * Writes chars from a CharSequence to bytes on an
+ * OutputStream using the default character encoding of the
+ * platform.
+ *
+ * This method uses {@link String#getBytes()}.
+ *
+ * @param data the CharSequence to write, null ignored
+ * @param output the OutputStream to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ * @deprecated 2.5 use {@link #write(CharSequence, OutputStream, Charset)} instead
+ */
+ @Deprecated
+ public static void write(final CharSequence data, final OutputStream output)
+ throws IOException {
+ write(data, output, Charset.defaultCharset());
+ }
+
+ /**
+ * Writes chars from a CharSequence to bytes on an
+ * OutputStream using the specified character encoding.
+ *
+ * This method uses {@link String#getBytes(String)}.
+ *
+ * @param data the CharSequence to write, null ignored
+ * @param output the OutputStream to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static void write(final CharSequence data, final OutputStream output, final Charset encoding)
+ throws IOException {
+ if (data != null) {
+ write(data.toString(), output, encoding);
+ }
+ }
+
+ /**
+ * Writes chars from a CharSequence to bytes on an
+ * OutputStream using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method uses {@link String#getBytes(String)}.
+ *
+ * @param data the CharSequence to write, null ignored
+ * @param output the OutputStream to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the encoding is not supported.
+ * @since 2.0
+ */
+ public static void write(final CharSequence data, final OutputStream output, final String encoding)
+ throws IOException {
+ write(data, output, Charsets.toCharset(encoding));
+ }
+
+ // write String
+ //-----------------------------------------------------------------------
+
+ /**
+ * Writes chars from a String to a Writer.
+ *
+ * @param data the String to write, null ignored
+ * @param output the Writer to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static void write(final String data, final Writer output) throws IOException {
+ if (data != null) {
+ output.write(data);
+ }
+ }
+
+ /**
+ * Writes chars from a String to bytes on an
+ * OutputStream using the default character encoding of the
+ * platform.
+ *
+ * This method uses {@link String#getBytes()}.
+ *
+ * @param data the String to write, null ignored
+ * @param output the OutputStream to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated 2.5 use {@link #write(String, OutputStream, Charset)} instead
+ */
+ @Deprecated
+ public static void write(final String data, final OutputStream output)
+ throws IOException {
+ write(data, output, Charset.defaultCharset());
+ }
+
+ /**
+ * Writes chars from a String to bytes on an
+ * OutputStream using the specified character encoding.
+ *
+ * This method uses {@link String#getBytes(String)}.
+ *
+ * @param data the String to write, null ignored
+ * @param output the OutputStream to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static void write(final String data, final OutputStream output, final Charset encoding) throws IOException {
+ if (data != null) {
+ output.write(data.getBytes(Charsets.toCharset(encoding)));
+ }
+ }
+
+ /**
+ * Writes chars from a String to bytes on an
+ * OutputStream using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method uses {@link String#getBytes(String)}.
+ *
+ * @param data the String to write, null ignored
+ * @param output the OutputStream to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the encoding is not supported.
+ * @since 1.1
+ */
+ public static void write(final String data, final OutputStream output, final String encoding)
+ throws IOException {
+ write(data, output, Charsets.toCharset(encoding));
+ }
+
+ // write StringBuffer
+ //-----------------------------------------------------------------------
+
+ /**
+ * Writes chars from a StringBuffer to a Writer.
+ *
+ * @param data the StringBuffer to write, null ignored
+ * @param output the Writer to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated replaced by write(CharSequence, Writer)
+ */
+ @Deprecated
+ public static void write(final StringBuffer data, final Writer output)
+ throws IOException {
+ if (data != null) {
+ output.write(data.toString());
+ }
+ }
+
+ /**
+ * Writes chars from a StringBuffer to bytes on an
+ * OutputStream using the default character encoding of the
+ * platform.
+ *
+ * This method uses {@link String#getBytes()}.
+ *
+ * @param data the StringBuffer to write, null ignored
+ * @param output the OutputStream to write to
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated replaced by write(CharSequence, OutputStream)
+ */
+ @Deprecated
+ public static void write(final StringBuffer data, final OutputStream output)
+ throws IOException {
+ write(data, output, (String) null);
+ }
+
+ /**
+ * Writes chars from a StringBuffer to bytes on an
+ * OutputStream using the specified character encoding.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method uses {@link String#getBytes(String)}.
+ *
+ * @param data the StringBuffer to write, null ignored
+ * @param output the OutputStream to write to
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if output is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the encoding is not supported.
+ * @since 1.1
+ * @deprecated replaced by write(CharSequence, OutputStream, String)
+ */
+ @Deprecated
+ public static void write(final StringBuffer data, final OutputStream output, final String encoding)
+ throws IOException {
+ if (data != null) {
+ output.write(data.toString().getBytes(Charsets.toCharset(encoding)));
+ }
+ }
+
+ // writeLines
+ //-----------------------------------------------------------------------
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * an OutputStream line by line, using the default character
+ * encoding of the platform and the specified line ending.
+ *
+ * @param lines the lines to write, null entries produce blank lines
+ * @param lineEnding the line separator to use, null is system default
+ * @param output the OutputStream to write to, not null, not closed
+ * @throws NullPointerException if the output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated 2.5 use {@link #writeLines(Collection, String, OutputStream, Charset)} instead
+ */
+ @Deprecated
+ public static void writeLines(final Collection> lines, final String lineEnding,
+ final OutputStream output) throws IOException {
+ writeLines(lines, lineEnding, output, Charset.defaultCharset());
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * an OutputStream line by line, using the specified character
+ * encoding and the specified line ending.
+ *
+ * @param lines the lines to write, null entries produce blank lines
+ * @param lineEnding the line separator to use, null is system default
+ * @param output the OutputStream to write to, not null, not closed
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if the output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static void writeLines(final Collection> lines, String lineEnding, final OutputStream output,
+ final Charset encoding) throws IOException {
+ if (lines == null) {
+ return;
+ }
+ if (lineEnding == null) {
+ lineEnding = LINE_SEPARATOR;
+ }
+ final Charset cs = Charsets.toCharset(encoding);
+ for (final Object line : lines) {
+ if (line != null) {
+ output.write(line.toString().getBytes(cs));
+ }
+ output.write(lineEnding.getBytes(cs));
+ }
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * an OutputStream line by line, using the specified character
+ * encoding and the specified line ending.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * @param lines the lines to write, null entries produce blank lines
+ * @param lineEnding the line separator to use, null is system default
+ * @param output the OutputStream to write to, not null, not closed
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if the output is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.1
+ */
+ public static void writeLines(final Collection> lines, final String lineEnding,
+ final OutputStream output, final String encoding) throws IOException {
+ writeLines(lines, lineEnding, output, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Writes the toString() value of each item in a collection to
+ * a Writer line by line, using the specified line ending.
+ *
+ * @param lines the lines to write, null entries produce blank lines
+ * @param lineEnding the line separator to use, null is system default
+ * @param writer the Writer to write to, not null, not closed
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static void writeLines(final Collection> lines, String lineEnding,
+ final Writer writer) throws IOException {
+ if (lines == null) {
+ return;
+ }
+ if (lineEnding == null) {
+ lineEnding = LINE_SEPARATOR;
+ }
+ for (final Object line : lines) {
+ if (line != null) {
+ writer.write(line.toString());
+ }
+ writer.write(lineEnding);
+ }
+ }
+
+ // copy from InputStream
+ //-----------------------------------------------------------------------
+
+ /**
+ * Copies bytes from an InputStream to an
+ * OutputStream.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * Large streams (over 2GB) will return a bytes copied value of
+ * -1 after the copy has completed since the correct
+ * number of bytes cannot be returned as an int. For large streams
+ * use the copyLarge(InputStream, OutputStream) method.
+ *
+ * @param input the InputStream to read from
+ * @param output the OutputStream to write to
+ * @return the number of bytes copied, or -1 if > Integer.MAX_VALUE
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static int copy(final InputStream input, final OutputStream output) throws IOException {
+ final long count = copyLarge(input, output);
+ if (count > Integer.MAX_VALUE) {
+ return -1;
+ }
+ return (int) count;
+ }
+
+ /**
+ * Copies bytes from an InputStream to an OutputStream using an internal buffer of the
+ * given size.
+ *
+ * This method buffers the input internally, so there is no need to use a BufferedInputStream.
+ *
+ *
+ * @param input the InputStream to read from
+ * @param output the OutputStream to write to
+ * @param bufferSize the bufferSize used to copy from the input to the output
+ * @return the number of bytes copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.5
+ */
+ public static long copy(final InputStream input, final OutputStream output, final int bufferSize)
+ throws IOException {
+ return copyLarge(input, output, new byte[bufferSize]);
+ }
+
+ /**
+ * Copies bytes from a large (over 2GB) InputStream to an
+ * OutputStream.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
+ *
+ * @param input the InputStream to read from
+ * @param output the OutputStream to write to
+ * @return the number of bytes copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.3
+ */
+ public static long copyLarge(final InputStream input, final OutputStream output)
+ throws IOException {
+ return copy(input, output, DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Copies bytes from a large (over 2GB) InputStream to an
+ * OutputStream.
+ *
+ * This method uses the provided buffer, so there is no need to use a
+ * BufferedInputStream.
+ *
+ *
+ * @param input the InputStream to read from
+ * @param output the OutputStream to write to
+ * @param buffer the buffer to use for the copy
+ * @return the number of bytes copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.2
+ */
+ public static long copyLarge(final InputStream input, final OutputStream output, final byte[] buffer)
+ throws IOException {
+ long count = 0;
+ int n;
+ while (EOF != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ /**
+ * Copies some or all bytes from a large (over 2GB) InputStream to an
+ * OutputStream, optionally skipping input bytes.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ *
+ * Note that the implementation uses {@link #skip(InputStream, long)}.
+ * This means that the method may be considerably less efficient than using the actual skip implementation,
+ * this is done to guarantee that the correct number of characters are skipped.
+ *
+ * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
+ *
+ * @param input the InputStream to read from
+ * @param output the OutputStream to write to
+ * @param inputOffset : number of bytes to skip from input before copying
+ * -ve values are ignored
+ * @param length : number of bytes to copy. -ve means all
+ * @return the number of bytes copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.2
+ */
+ public static long copyLarge(final InputStream input, final OutputStream output, final long inputOffset,
+ final long length) throws IOException {
+ return copyLarge(input, output, inputOffset, length, new byte[DEFAULT_BUFFER_SIZE]);
+ }
+
+ /**
+ * Copies some or all bytes from a large (over 2GB) InputStream to an
+ * OutputStream, optionally skipping input bytes.
+ *
+ * This method uses the provided buffer, so there is no need to use a
+ * BufferedInputStream.
+ *
+ *
+ * Note that the implementation uses {@link #skip(InputStream, long)}.
+ * This means that the method may be considerably less efficient than using the actual skip implementation,
+ * this is done to guarantee that the correct number of characters are skipped.
+ *
+ *
+ * @param input the InputStream to read from
+ * @param output the OutputStream to write to
+ * @param inputOffset : number of bytes to skip from input before copying
+ * -ve values are ignored
+ * @param length : number of bytes to copy. -ve means all
+ * @param buffer the buffer to use for the copy
+ * @return the number of bytes copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.2
+ */
+ public static long copyLarge(final InputStream input, final OutputStream output,
+ final long inputOffset, final long length, final byte[] buffer) throws IOException {
+ if (inputOffset > 0) {
+ skipFully(input, inputOffset);
+ }
+ if (length == 0) {
+ return 0;
+ }
+ final int bufferLength = buffer.length;
+ int bytesToRead = bufferLength;
+ if (length > 0 && length < bufferLength) {
+ bytesToRead = (int) length;
+ }
+ int read;
+ long totalRead = 0;
+ while (bytesToRead > 0 && EOF != (read = input.read(buffer, 0, bytesToRead))) {
+ output.write(buffer, 0, read);
+ totalRead += read;
+ if (length > 0) { // only adjust length if not reading to the end
+ // Note the cast must work because buffer.length is an integer
+ bytesToRead = (int) Math.min(length - totalRead, bufferLength);
+ }
+ }
+ return totalRead;
+ }
+
+ /**
+ * Copies bytes from an InputStream to chars on a
+ * Writer using the default character encoding of the platform.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * This method uses {@link InputStreamReader}.
+ *
+ * @param input the InputStream to read from
+ * @param output the Writer to write to
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated 2.5 use {@link #copy(InputStream, Writer, Charset)} instead
+ */
+ @Deprecated
+ public static void copy(final InputStream input, final Writer output)
+ throws IOException {
+ copy(input, output, Charset.defaultCharset());
+ }
+
+ /**
+ * Copies bytes from an InputStream to chars on a
+ * Writer using the specified character encoding.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * This method uses {@link InputStreamReader}.
+ *
+ * @param input the InputStream to read from
+ * @param output the Writer to write to
+ * @param inputEncoding the encoding to use for the input stream, null means platform default
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static void copy(final InputStream input, final Writer output, final Charset inputEncoding)
+ throws IOException {
+ final InputStreamReader in = new InputStreamReader(input, Charsets.toCharset(inputEncoding));
+ copy(in, output);
+ }
+
+ /**
+ * Copies bytes from an InputStream to chars on a
+ * Writer using the specified character encoding.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * This method uses {@link InputStreamReader}.
+ *
+ * @param input the InputStream to read from
+ * @param output the Writer to write to
+ * @param inputEncoding the encoding to use for the InputStream, null means platform default
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.1
+ */
+ public static void copy(final InputStream input, final Writer output, final String inputEncoding)
+ throws IOException {
+ copy(input, output, Charsets.toCharset(inputEncoding));
+ }
+
+ // copy from Reader
+ //-----------------------------------------------------------------------
+
+ /**
+ * Copies chars from a Reader to a Writer.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * Large streams (over 2GB) will return a chars copied value of
+ * -1 after the copy has completed since the correct
+ * number of chars cannot be returned as an int. For large streams
+ * use the copyLarge(Reader, Writer) method.
+ *
+ * @param input the Reader to read from
+ * @param output the Writer to write to
+ * @return the number of characters copied, or -1 if > Integer.MAX_VALUE
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static int copy(final Reader input, final Writer output) throws IOException {
+ final long count = copyLarge(input, output);
+ if (count > Integer.MAX_VALUE) {
+ return -1;
+ }
+ return (int) count;
+ }
+
+ /**
+ * Copies chars from a large (over 2GB) Reader to a Writer.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
+ *
+ * @param input the Reader to read from
+ * @param output the Writer to write to
+ * @return the number of characters copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.3
+ */
+ public static long copyLarge(final Reader input, final Writer output) throws IOException {
+ return copyLarge(input, output, new char[DEFAULT_BUFFER_SIZE]);
+ }
+
+ /**
+ * Copies chars from a large (over 2GB) Reader to a Writer.
+ *
+ * This method uses the provided buffer, so there is no need to use a
+ * BufferedReader.
+ *
+ *
+ * @param input the Reader to read from
+ * @param output the Writer to write to
+ * @param buffer the buffer to be used for the copy
+ * @return the number of characters copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.2
+ */
+ public static long copyLarge(final Reader input, final Writer output, final char[] buffer) throws IOException {
+ long count = 0;
+ int n;
+ while (EOF != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ /**
+ * Copies some or all chars from a large (over 2GB) InputStream to an
+ * OutputStream, optionally skipping input chars.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
+ *
+ * @param input the Reader to read from
+ * @param output the Writer to write to
+ * @param inputOffset : number of chars to skip from input before copying
+ * -ve values are ignored
+ * @param length : number of chars to copy. -ve means all
+ * @return the number of chars copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.2
+ */
+ public static long copyLarge(final Reader input, final Writer output, final long inputOffset, final long length)
+ throws IOException {
+ return copyLarge(input, output, inputOffset, length, new char[DEFAULT_BUFFER_SIZE]);
+ }
+
+ /**
+ * Copies some or all chars from a large (over 2GB) InputStream to an
+ * OutputStream, optionally skipping input chars.
+ *
+ * This method uses the provided buffer, so there is no need to use a
+ * BufferedReader.
+ *
+ *
+ * @param input the Reader to read from
+ * @param output the Writer to write to
+ * @param inputOffset : number of chars to skip from input before copying
+ * -ve values are ignored
+ * @param length : number of chars to copy. -ve means all
+ * @param buffer the buffer to be used for the copy
+ * @return the number of chars copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.2
+ */
+ public static long copyLarge(final Reader input, final Writer output, final long inputOffset, final long length,
+ final char[] buffer)
+ throws IOException {
+ if (inputOffset > 0) {
+ skipFully(input, inputOffset);
+ }
+ if (length == 0) {
+ return 0;
+ }
+ int bytesToRead = buffer.length;
+ if (length > 0 && length < buffer.length) {
+ bytesToRead = (int) length;
+ }
+ int read;
+ long totalRead = 0;
+ while (bytesToRead > 0 && EOF != (read = input.read(buffer, 0, bytesToRead))) {
+ output.write(buffer, 0, read);
+ totalRead += read;
+ if (length > 0) { // only adjust length if not reading to the end
+ // Note the cast must work because buffer.length is an integer
+ bytesToRead = (int) Math.min(length - totalRead, buffer.length);
+ }
+ }
+ return totalRead;
+ }
+
+ /**
+ * Copies chars from a Reader to bytes on an
+ * OutputStream using the default character encoding of the
+ * platform, and calling flush.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * Due to the implementation of OutputStreamWriter, this method performs a
+ * flush.
+ *
+ * This method uses {@link OutputStreamWriter}.
+ *
+ * @param input the Reader to read from
+ * @param output the OutputStream to write to
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ * @deprecated 2.5 use {@link #copy(Reader, OutputStream, Charset)} instead
+ */
+ @Deprecated
+ public static void copy(final Reader input, final OutputStream output)
+ throws IOException {
+ copy(input, output, Charset.defaultCharset());
+ }
+
+ /**
+ * Copies chars from a Reader to bytes on an
+ * OutputStream using the specified character encoding, and
+ * calling flush.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ *
+ * Due to the implementation of OutputStreamWriter, this method performs a
+ * flush.
+ *
+ *
+ * This method uses {@link OutputStreamWriter}.
+ *
+ *
+ * @param input the Reader to read from
+ * @param output the OutputStream to write to
+ * @param outputEncoding the encoding to use for the OutputStream, null means platform default
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.3
+ */
+ public static void copy(final Reader input, final OutputStream output, final Charset outputEncoding)
+ throws IOException {
+ final OutputStreamWriter out = new OutputStreamWriter(output, Charsets.toCharset(outputEncoding));
+ copy(input, out);
+ // XXX Unless anyone is planning on rewriting OutputStreamWriter,
+ // we have to flush here.
+ out.flush();
+ }
+
+ /**
+ * Copies chars from a Reader to bytes on an
+ * OutputStream using the specified character encoding, and
+ * calling flush.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedReader.
+ *
+ * Character encoding names can be found at
+ * IANA .
+ *
+ * Due to the implementation of OutputStreamWriter, this method performs a
+ * flush.
+ *
+ * This method uses {@link OutputStreamWriter}.
+ *
+ * @param input the Reader to read from
+ * @param output the OutputStream to write to
+ * @param outputEncoding the encoding to use for the OutputStream, null means platform default
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
+ * .UnsupportedEncodingException} in version 2.2 if the
+ * encoding is not supported.
+ * @since 1.1
+ */
+ public static void copy(final Reader input, final OutputStream output, final String outputEncoding)
+ throws IOException {
+ copy(input, output, Charsets.toCharset(outputEncoding));
+ }
+
+ // content equals
+ //-----------------------------------------------------------------------
+
+ /**
+ * Compares the contents of two Streams to determine if they are equal or
+ * not.
+ *
+ * This method buffers the input internally using
+ * BufferedInputStream if they are not already buffered.
+ *
+ * @param input1 the first stream
+ * @param input2 the second stream
+ * @return true if the content of the streams are equal or they both don't
+ * exist, false otherwise
+ * @throws NullPointerException if either input is null
+ * @throws IOException if an I/O error occurs
+ */
+ public static boolean contentEquals(InputStream input1, InputStream input2)
+ throws IOException {
+ if (input1 == input2) {
+ return true;
+ }
+ if (!(input1 instanceof BufferedInputStream)) {
+ input1 = new BufferedInputStream(input1);
+ }
+ if (!(input2 instanceof BufferedInputStream)) {
+ input2 = new BufferedInputStream(input2);
+ }
+
+ int ch = input1.read();
+ while (EOF != ch) {
+ final int ch2 = input2.read();
+ if (ch != ch2) {
+ return false;
+ }
+ ch = input1.read();
+ }
+
+ final int ch2 = input2.read();
+ return ch2 == EOF;
+ }
+
+ /**
+ * Compares the contents of two Readers to determine if they are equal or
+ * not.
+ *
+ * This method buffers the input internally using
+ * BufferedReader if they are not already buffered.
+ *
+ * @param input1 the first reader
+ * @param input2 the second reader
+ * @return true if the content of the readers are equal or they both don't
+ * exist, false otherwise
+ * @throws NullPointerException if either input is null
+ * @throws IOException if an I/O error occurs
+ * @since 1.1
+ */
+ public static boolean contentEquals(Reader input1, Reader input2)
+ throws IOException {
+ if (input1 == input2) {
+ return true;
+ }
+
+ input1 = toBufferedReader(input1);
+ input2 = toBufferedReader(input2);
+
+ int ch = input1.read();
+ while (EOF != ch) {
+ final int ch2 = input2.read();
+ if (ch != ch2) {
+ return false;
+ }
+ ch = input1.read();
+ }
+
+ final int ch2 = input2.read();
+ return ch2 == EOF;
+ }
+
+ /**
+ * Compares the contents of two Readers to determine if they are equal or
+ * not, ignoring EOL characters.
+ *
+ * This method buffers the input internally using
+ * BufferedReader if they are not already buffered.
+ *
+ * @param input1 the first reader
+ * @param input2 the second reader
+ * @return true if the content of the readers are equal (ignoring EOL differences), false otherwise
+ * @throws NullPointerException if either input is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.2
+ */
+ public static boolean contentEqualsIgnoreEOL(final Reader input1, final Reader input2)
+ throws IOException {
+ if (input1 == input2) {
+ return true;
+ }
+ final BufferedReader br1 = toBufferedReader(input1);
+ final BufferedReader br2 = toBufferedReader(input2);
+
+ String line1 = br1.readLine();
+ String line2 = br2.readLine();
+ while (line1 != null && line2 != null && line1.equals(line2)) {
+ line1 = br1.readLine();
+ line2 = br2.readLine();
+ }
+ return line1 == null ? line2 == null ? true : false : line1.equals(line2);
+ }
+
+ /**
+ * Skips bytes from an input byte stream.
+ * This implementation guarantees that it will read as many bytes
+ * as possible before giving up; this may not always be the case for
+ * skip() implementations in subclasses of {@link InputStream}.
+ *
+ * Note that the implementation uses {@link InputStream#read(byte[], int, int)} rather
+ * than delegating to {@link InputStream#skip(long)}.
+ * This means that the method may be considerably less efficient than using the actual skip implementation,
+ * this is done to guarantee that the correct number of bytes are skipped.
+ *
+ *
+ * @param input byte stream to skip
+ * @param toSkip number of bytes to skip.
+ * @return number of bytes actually skipped.
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if toSkip is negative
+ * @see InputStream#skip(long)
+ * @see IO-203 - Add skipFully() method for InputStreams
+ * @since 2.0
+ */
+ public static long skip(final InputStream input, final long toSkip) throws IOException {
+ if (toSkip < 0) {
+ throw new IllegalArgumentException("Skip count must be non-negative, actual: " + toSkip);
+ }
+ /*
+ * N.B. no need to synchronize this because: - we don't care if the buffer is created multiple times (the data
+ * is ignored) - we always use the same size buffer, so if it it is recreated it will still be OK (if the buffer
+ * size were variable, we would need to synch. to ensure some other thread did not create a smaller one)
+ */
+ if (SKIP_BYTE_BUFFER == null) {
+ SKIP_BYTE_BUFFER = new byte[SKIP_BUFFER_SIZE];
+ }
+ long remain = toSkip;
+ while (remain > 0) {
+ // See https://issues.apache.org/jira/browse/IO-203 for why we use read() rather than delegating to skip()
+ final long n = input.read(SKIP_BYTE_BUFFER, 0, (int) Math.min(remain, SKIP_BUFFER_SIZE));
+ if (n < 0) { // EOF
+ break;
+ }
+ remain -= n;
+ }
+ return toSkip - remain;
+ }
+
+ /**
+ * Skips bytes from a ReadableByteChannel.
+ * This implementation guarantees that it will read as many bytes
+ * as possible before giving up.
+ *
+ * @param input ReadableByteChannel to skip
+ * @param toSkip number of bytes to skip.
+ * @return number of bytes actually skipped.
+ * @throws IOException if there is a problem reading the ReadableByteChannel
+ * @throws IllegalArgumentException if toSkip is negative
+ * @since 2.5
+ */
+ public static long skip(final ReadableByteChannel input, final long toSkip) throws IOException {
+ if (toSkip < 0) {
+ throw new IllegalArgumentException("Skip count must be non-negative, actual: " + toSkip);
+ }
+ final ByteBuffer skipByteBuffer = ByteBuffer.allocate((int) Math.min(toSkip, SKIP_BUFFER_SIZE));
+ long remain = toSkip;
+ while (remain > 0) {
+ skipByteBuffer.position(0);
+ skipByteBuffer.limit((int) Math.min(remain, SKIP_BUFFER_SIZE));
+ final int n = input.read(skipByteBuffer);
+ if (n == EOF) {
+ break;
+ }
+ remain -= n;
+ }
+ return toSkip - remain;
+ }
+
+ /**
+ * Skips characters from an input character stream.
+ * This implementation guarantees that it will read as many characters
+ * as possible before giving up; this may not always be the case for
+ * skip() implementations in subclasses of {@link Reader}.
+ *
+ * Note that the implementation uses {@link Reader#read(char[], int, int)} rather
+ * than delegating to {@link Reader#skip(long)}.
+ * This means that the method may be considerably less efficient than using the actual skip implementation,
+ * this is done to guarantee that the correct number of characters are skipped.
+ *
+ *
+ * @param input character stream to skip
+ * @param toSkip number of characters to skip.
+ * @return number of characters actually skipped.
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if toSkip is negative
+ * @see Reader#skip(long)
+ * @see IO-203 - Add skipFully() method for InputStreams
+ * @since 2.0
+ */
+ public static long skip(final Reader input, final long toSkip) throws IOException {
+ if (toSkip < 0) {
+ throw new IllegalArgumentException("Skip count must be non-negative, actual: " + toSkip);
+ }
+ /*
+ * N.B. no need to synchronize this because: - we don't care if the buffer is created multiple times (the data
+ * is ignored) - we always use the same size buffer, so if it it is recreated it will still be OK (if the buffer
+ * size were variable, we would need to synch. to ensure some other thread did not create a smaller one)
+ */
+ if (SKIP_CHAR_BUFFER == null) {
+ SKIP_CHAR_BUFFER = new char[SKIP_BUFFER_SIZE];
+ }
+ long remain = toSkip;
+ while (remain > 0) {
+ // See https://issues.apache.org/jira/browse/IO-203 for why we use read() rather than delegating to skip()
+ final long n = input.read(SKIP_CHAR_BUFFER, 0, (int) Math.min(remain, SKIP_BUFFER_SIZE));
+ if (n < 0) { // EOF
+ break;
+ }
+ remain -= n;
+ }
+ return toSkip - remain;
+ }
+
+ /**
+ * Skips the requested number of bytes or fail if there are not enough left.
+ *
+ * This allows for the possibility that {@link InputStream#skip(long)} may
+ * not skip as many bytes as requested (most likely because of reaching EOF).
+ *
+ * Note that the implementation uses {@link #skip(InputStream, long)}.
+ * This means that the method may be considerably less efficient than using the actual skip implementation,
+ * this is done to guarantee that the correct number of characters are skipped.
+ *
+ *
+ * @param input stream to skip
+ * @param toSkip the number of bytes to skip
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if toSkip is negative
+ * @throws EOFException if the number of bytes skipped was incorrect
+ * @see InputStream#skip(long)
+ * @since 2.0
+ */
+ public static void skipFully(final InputStream input, final long toSkip) throws IOException {
+ if (toSkip < 0) {
+ throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip);
+ }
+ final long skipped = skip(input, toSkip);
+ if (skipped != toSkip) {
+ throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped);
+ }
+ }
+
+ /**
+ * Skips the requested number of bytes or fail if there are not enough left.
+ *
+ * @param input ReadableByteChannel to skip
+ * @param toSkip the number of bytes to skip
+ * @throws IOException if there is a problem reading the ReadableByteChannel
+ * @throws IllegalArgumentException if toSkip is negative
+ * @throws EOFException if the number of bytes skipped was incorrect
+ * @since 2.5
+ */
+ public static void skipFully(final ReadableByteChannel input, final long toSkip) throws IOException {
+ if (toSkip < 0) {
+ throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip);
+ }
+ final long skipped = skip(input, toSkip);
+ if (skipped != toSkip) {
+ throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped);
+ }
+ }
+
+ /**
+ * Skips the requested number of characters or fail if there are not enough left.
+ *
+ * This allows for the possibility that {@link Reader#skip(long)} may
+ * not skip as many characters as requested (most likely because of reaching EOF).
+ *
+ * Note that the implementation uses {@link #skip(Reader, long)}.
+ * This means that the method may be considerably less efficient than using the actual skip implementation,
+ * this is done to guarantee that the correct number of characters are skipped.
+ *
+ *
+ * @param input stream to skip
+ * @param toSkip the number of characters to skip
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if toSkip is negative
+ * @throws EOFException if the number of characters skipped was incorrect
+ * @see Reader#skip(long)
+ * @since 2.0
+ */
+ public static void skipFully(final Reader input, final long toSkip) throws IOException {
+ final long skipped = skip(input, toSkip);
+ if (skipped != toSkip) {
+ throw new EOFException("Chars to skip: " + toSkip + " actual: " + skipped);
+ }
+ }
+
+
+ /**
+ * Reads characters from an input character stream.
+ * This implementation guarantees that it will read as many characters
+ * as possible before giving up; this may not always be the case for
+ * subclasses of {@link Reader}.
+ *
+ * @param input where to read input from
+ * @param buffer destination
+ * @param offset initial offset into buffer
+ * @param length length to read, must be >= 0
+ * @return actual length read; may be less than requested if EOF was reached
+ * @throws IOException if a read error occurs
+ * @since 2.2
+ */
+ public static int read(final Reader input, final char[] buffer, final int offset, final int length)
+ throws IOException {
+ if (length < 0) {
+ throw new IllegalArgumentException("Length must not be negative: " + length);
+ }
+ int remaining = length;
+ while (remaining > 0) {
+ final int location = length - remaining;
+ final int count = input.read(buffer, offset + location, remaining);
+ if (EOF == count) { // EOF
+ break;
+ }
+ remaining -= count;
+ }
+ return length - remaining;
+ }
+
+ /**
+ * Reads characters from an input character stream.
+ * This implementation guarantees that it will read as many characters
+ * as possible before giving up; this may not always be the case for
+ * subclasses of {@link Reader}.
+ *
+ * @param input where to read input from
+ * @param buffer destination
+ * @return actual length read; may be less than requested if EOF was reached
+ * @throws IOException if a read error occurs
+ * @since 2.2
+ */
+ public static int read(final Reader input, final char[] buffer) throws IOException {
+ return read(input, buffer, 0, buffer.length);
+ }
+
+ /**
+ * Reads bytes from an input stream.
+ * This implementation guarantees that it will read as many bytes
+ * as possible before giving up; this may not always be the case for
+ * subclasses of {@link InputStream}.
+ *
+ * @param input where to read input from
+ * @param buffer destination
+ * @param offset initial offset into buffer
+ * @param length length to read, must be >= 0
+ * @return actual length read; may be less than requested if EOF was reached
+ * @throws IOException if a read error occurs
+ * @since 2.2
+ */
+ public static int read(final InputStream input, final byte[] buffer, final int offset, final int length)
+ throws IOException {
+ if (length < 0) {
+ throw new IllegalArgumentException("Length must not be negative: " + length);
+ }
+ int remaining = length;
+ while (remaining > 0) {
+ final int location = length - remaining;
+ final int count = input.read(buffer, offset + location, remaining);
+ if (EOF == count) { // EOF
+ break;
+ }
+ remaining -= count;
+ }
+ return length - remaining;
+ }
+
+ /**
+ * Reads bytes from an input stream.
+ * This implementation guarantees that it will read as many bytes
+ * as possible before giving up; this may not always be the case for
+ * subclasses of {@link InputStream}.
+ *
+ * @param input where to read input from
+ * @param buffer destination
+ * @return actual length read; may be less than requested if EOF was reached
+ * @throws IOException if a read error occurs
+ * @since 2.2
+ */
+ public static int read(final InputStream input, final byte[] buffer) throws IOException {
+ return read(input, buffer, 0, buffer.length);
+ }
+
+ /**
+ * Reads bytes from a ReadableByteChannel.
+ *
+ * This implementation guarantees that it will read as many bytes
+ * as possible before giving up; this may not always be the case for
+ * subclasses of {@link ReadableByteChannel}.
+ *
+ * @param input the byte channel to read
+ * @param buffer byte buffer destination
+ * @return the actual length read; may be less than requested if EOF was reached
+ * @throws IOException if a read error occurs
+ * @since 2.5
+ */
+ public static int read(final ReadableByteChannel input, final ByteBuffer buffer) throws IOException {
+ final int length = buffer.remaining();
+ while (buffer.remaining() > 0) {
+ final int count = input.read(buffer);
+ if (EOF == count) { // EOF
+ break;
+ }
+ }
+ return length - buffer.remaining();
+ }
+
+ /**
+ * Reads the requested number of characters or fail if there are not enough left.
+ *
+ * This allows for the possibility that {@link Reader#read(char[], int, int)} may
+ * not read as many characters as requested (most likely because of reaching EOF).
+ *
+ * @param input where to read input from
+ * @param buffer destination
+ * @param offset initial offset into buffer
+ * @param length length to read, must be >= 0
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if length is negative
+ * @throws EOFException if the number of characters read was incorrect
+ * @since 2.2
+ */
+ public static void readFully(final Reader input, final char[] buffer, final int offset, final int length)
+ throws IOException {
+ final int actual = read(input, buffer, offset, length);
+ if (actual != length) {
+ throw new EOFException("Length to read: " + length + " actual: " + actual);
+ }
+ }
+
+ /**
+ * Reads the requested number of characters or fail if there are not enough left.
+ *
+ * This allows for the possibility that {@link Reader#read(char[], int, int)} may
+ * not read as many characters as requested (most likely because of reaching EOF).
+ *
+ * @param input where to read input from
+ * @param buffer destination
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if length is negative
+ * @throws EOFException if the number of characters read was incorrect
+ * @since 2.2
+ */
+ public static void readFully(final Reader input, final char[] buffer) throws IOException {
+ readFully(input, buffer, 0, buffer.length);
+ }
+
+ /**
+ * Reads the requested number of bytes or fail if there are not enough left.
+ *
+ * This allows for the possibility that {@link InputStream#read(byte[], int, int)} may
+ * not read as many bytes as requested (most likely because of reaching EOF).
+ *
+ * @param input where to read input from
+ * @param buffer destination
+ * @param offset initial offset into buffer
+ * @param length length to read, must be >= 0
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if length is negative
+ * @throws EOFException if the number of bytes read was incorrect
+ * @since 2.2
+ */
+ public static void readFully(final InputStream input, final byte[] buffer, final int offset, final int length)
+ throws IOException {
+ final int actual = read(input, buffer, offset, length);
+ if (actual != length) {
+ throw new EOFException("Length to read: " + length + " actual: " + actual);
+ }
+ }
+
+ /**
+ * Reads the requested number of bytes or fail if there are not enough left.
+ *
+ * This allows for the possibility that {@link InputStream#read(byte[], int, int)} may
+ * not read as many bytes as requested (most likely because of reaching EOF).
+ *
+ * @param input where to read input from
+ * @param buffer destination
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if length is negative
+ * @throws EOFException if the number of bytes read was incorrect
+ * @since 2.2
+ */
+ public static void readFully(final InputStream input, final byte[] buffer) throws IOException {
+ readFully(input, buffer, 0, buffer.length);
+ }
+
+ /**
+ * Reads the requested number of bytes or fail if there are not enough left.
+ *
+ * This allows for the possibility that {@link InputStream#read(byte[], int, int)} may
+ * not read as many bytes as requested (most likely because of reaching EOF).
+ *
+ * @param input where to read input from
+ * @param length length to read, must be >= 0
+ * @return the bytes read from input
+ * @throws IOException if there is a problem reading the file
+ * @throws IllegalArgumentException if length is negative
+ * @throws EOFException if the number of bytes read was incorrect
+ * @since 2.5
+ */
+ public static byte[] readFully(final InputStream input, final int length) throws IOException {
+ final byte[] buffer = new byte[length];
+ readFully(input, buffer, 0, buffer.length);
+ return buffer;
+ }
+
+ /**
+ * Reads the requested number of bytes or fail if there are not enough left.
+ *
+ * This allows for the possibility that {@link ReadableByteChannel#read(ByteBuffer)} may
+ * not read as many bytes as requested (most likely because of reaching EOF).
+ *
+ * @param input the byte channel to read
+ * @param buffer byte buffer destination
+ * @throws IOException if there is a problem reading the file
+ * @throws EOFException if the number of bytes read was incorrect
+ * @since 2.5
+ */
+ public static void readFully(final ReadableByteChannel input, final ByteBuffer buffer) throws IOException {
+ final int expected = buffer.remaining();
+ final int actual = read(input, buffer);
+ if (actual != expected) {
+ throw new EOFException("Length to read: " + expected + " actual: " + actual);
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/Java7Support.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/Java7Support.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d9033a457644c4de4bb71936fff229f30084b329
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/Java7Support.java"
@@ -0,0 +1,190 @@
+package org.apache.commons.io;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Java7 feature detection and reflection based feature access.
+ *
+ * Taken from maven-shared-utils, only for private usage until we go full java7
+ */
+class Java7Support {
+
+ private static final boolean IS_JAVA7;
+
+ private static Method isSymbolicLink;
+
+ private static Method delete;
+
+ private static Method toPath;
+
+ private static Method exists;
+
+ private static Method toFile;
+
+ private static Method readSymlink;
+
+ private static Method createSymlink;
+
+ private static Object emptyLinkOpts;
+
+ private static Object emptyFileAttributes;
+
+ static {
+ boolean isJava7x = true;
+ try {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Class> files = cl.loadClass("java.nio.file.Files");
+ Class> path = cl.loadClass("java.nio.file.Path");
+ Class> fa = cl.loadClass("java.nio.file.attribute.FileAttribute");
+ Class> linkOption = cl.loadClass("java.nio.file.LinkOption");
+ isSymbolicLink = files.getMethod("isSymbolicLink", path);
+ delete = files.getMethod("delete", path);
+ readSymlink = files.getMethod("readSymbolicLink", path);
+
+ emptyFileAttributes = Array.newInstance(fa, 0);
+ createSymlink = files.getMethod("createSymbolicLink", path, path, emptyFileAttributes.getClass());
+ emptyLinkOpts = Array.newInstance(linkOption, 0);
+ exists = files.getMethod("exists", path, emptyLinkOpts.getClass());
+ toPath = File.class.getMethod("toPath");
+ toFile = path.getMethod("toFile");
+ } catch (ClassNotFoundException e) {
+ isJava7x = false;
+ } catch (NoSuchMethodException e) {
+ isJava7x = false;
+ }
+ IS_JAVA7 = isJava7x;
+ }
+
+ /**
+ * Invokes java7 isSymbolicLink
+ * @param file The file to check
+ * @return true if the file is a symbolic link
+ */
+ public static boolean isSymLink(File file) {
+ try {
+ Object path = toPath.invoke(file);
+ Boolean result = (Boolean) isSymbolicLink.invoke(null, path);
+ return result.booleanValue();
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Reads the target of a symbolic link
+ * @param symlink The symlink to read
+ * @return The location the symlink is pointing to
+ * @throws IOException Upon failure
+ */
+
+ public static File readSymbolicLink(File symlink)
+ throws IOException {
+ try {
+ Object path = toPath.invoke(symlink);
+ Object resultPath = readSymlink.invoke(null, path);
+ return (File) toFile.invoke(resultPath);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /**
+ * Indicates if a symlunk target exists
+ * @param file The symlink file
+ * @return true if the target exists
+ * @throws IOException upon error
+ */
+ private static boolean exists(File file)
+ throws IOException {
+ try {
+ Object path = toPath.invoke(file);
+ final Boolean result = (Boolean) exists.invoke(null, path, emptyLinkOpts);
+ return result.booleanValue();
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw (RuntimeException) e.getTargetException();
+ }
+
+ }
+
+ /**
+ * Creates a symbolic link
+ * @param symlink The symlink to create
+ * @param target Where it should point
+ * @return The newly created symlink
+ * @throws IOException upon error
+ */
+ public static File createSymbolicLink(File symlink, File target)
+ throws IOException {
+ try {
+ if (!exists(symlink)) {
+ Object link = toPath.invoke(symlink);
+ Object path = createSymlink.invoke(null, link, toPath.invoke(target), emptyFileAttributes);
+ return (File) toFile.invoke(path);
+ }
+ return symlink;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ final Throwable targetException = e.getTargetException();
+ throw (IOException) targetException;
+ }
+
+ }
+
+ /**
+ * Performs a nio delete
+ *
+ * @param file the file to delete
+ * @throws IOException Upon error
+ */
+ public static void delete(File file)
+ throws IOException {
+ try {
+ Object path = toPath.invoke(file);
+ delete.invoke(null, path);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw (IOException) e.getTargetException();
+ }
+ }
+
+ /**
+ * Indicates if the current vm has java7 lubrary support
+ * @return true if java7 library support
+ */
+ public static boolean isAtLeastJava7() {
+ return IS_JAVA7;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/LineIterator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/LineIterator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..8d56f583bd90e0af6f3d1a8a0e50d9c5f7ad4372
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/LineIterator.java"
@@ -0,0 +1,180 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * An Iterator over the lines in a Reader.
+ *
+ * LineIterator holds a reference to an open Reader.
+ * When you have finished with the iterator you should close the reader
+ * to free internal resources. This can be done by closing the reader directly,
+ * or by calling the {@link #close()} or {@link #closeQuietly(LineIterator)}
+ * method on the iterator.
+ *
+ * The recommended usage pattern is:
+ *
+ * LineIterator it = FileUtils.lineIterator(file, "UTF-8");
+ * try {
+ * while (it.hasNext()) {
+ * String line = it.nextLine();
+ * // do something with line
+ * }
+ * } finally {
+ * it.close();
+ * }
+ *
+ *
+ * @version $Id: LineIterator.java 1471767 2013-04-24 23:24:19Z sebb $
+ * @since 1.2
+ */
+public class LineIterator implements Iterator {
+
+ // N.B. This class deliberately does not implement Iterable, see https://issues.apache.org/jira/browse/IO-181
+
+ /** The reader that is being read. */
+ private final BufferedReader bufferedReader;
+ /** The current line. */
+ private String cachedLine;
+ /** A flag indicating if the iterator has been fully read. */
+ private boolean finished = false;
+
+ /**
+ * Constructs an iterator of the lines for a Reader.
+ *
+ * @param reader the Reader to read from, not null
+ * @throws IllegalArgumentException if the reader is null
+ */
+ public LineIterator(final Reader reader) throws IllegalArgumentException {
+ if (reader == null) {
+ throw new IllegalArgumentException("Reader must not be null");
+ }
+ if (reader instanceof BufferedReader) {
+ bufferedReader = (BufferedReader) reader;
+ } else {
+ bufferedReader = new BufferedReader(reader);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Indicates whether the Reader has more lines.
+ * If there is an IOException then {@link #close()} will
+ * be called on this instance.
+ *
+ * @return {@code true} if the Reader has more lines
+ * @throws IllegalStateException if an IO exception occurs
+ */
+ public boolean hasNext() {
+ if (cachedLine != null) {
+ return true;
+ } else if (finished) {
+ return false;
+ } else {
+ try {
+ while (true) {
+ final String line = bufferedReader.readLine();
+ if (line == null) {
+ finished = true;
+ return false;
+ } else if (isValidLine(line)) {
+ cachedLine = line;
+ return true;
+ }
+ }
+ } catch(final IOException ioe) {
+ close();
+ throw new IllegalStateException(ioe);
+ }
+ }
+ }
+
+ /**
+ * Overridable method to validate each line that is returned.
+ * This implementation always returns true.
+ * @param line the line that is to be validated
+ * @return true if valid, false to remove from the iterator
+ */
+ protected boolean isValidLine(final String line) {
+ return true;
+ }
+
+ /**
+ * Returns the next line in the wrapped Reader.
+ *
+ * @return the next line from the input
+ * @throws NoSuchElementException if there is no line to return
+ */
+ public String next() {
+ return nextLine();
+ }
+
+ /**
+ * Returns the next line in the wrapped Reader.
+ *
+ * @return the next line from the input
+ * @throws NoSuchElementException if there is no line to return
+ */
+ public String nextLine() {
+ if (!hasNext()) {
+ throw new NoSuchElementException("No more lines");
+ }
+ final String currentLine = cachedLine;
+ cachedLine = null;
+ return currentLine;
+ }
+
+ /**
+ * Closes the underlying Reader quietly.
+ * This method is useful if you only want to process the first few
+ * lines of a larger file. If you do not close the iterator
+ * then the Reader remains open.
+ * This method can safely be called multiple times.
+ */
+ public void close() {
+ finished = true;
+ IOUtils.closeQuietly(bufferedReader);
+ cachedLine = null;
+ }
+
+ /**
+ * Unsupported.
+ *
+ * @throws UnsupportedOperationException always
+ */
+ public void remove() {
+ throw new UnsupportedOperationException("Remove unsupported on LineIterator");
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Closes the iterator, handling null and ignoring exceptions.
+ *
+ * @param iterator the iterator to close
+ */
+ public static void closeQuietly(final LineIterator iterator) {
+ if (iterator != null) {
+ iterator.close();
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/TaggedIOException.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/TaggedIOException.java"
new file mode 100644
index 0000000000000000000000000000000000000000..228384797ca823fd6e5ac58e19de9e30b3c5f3db
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/TaggedIOException.java"
@@ -0,0 +1,136 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * An {@link IOException} decorator that adds a serializable tag to the
+ * wrapped exception. Both the tag and the original exception can be used
+ * to determine further processing when this exception is caught.
+ *
+ * @since 2.0
+ */
+@SuppressWarnings("deprecation") // needs to extend deprecated IOExceptionWithCause to preserve binary compatibility
+public class TaggedIOException extends IOExceptionWithCause {
+
+ /**
+ * Generated serial version UID.
+ */
+ private static final long serialVersionUID = -6994123481142850163L;
+
+ /**
+ * Checks whether the given throwable is tagged with the given tag.
+ *
+ * This check can only succeed if the throwable is a
+ * {@link TaggedIOException} and the tag is {@link Serializable}, but
+ * the argument types are intentionally more generic to make it easier
+ * to use this method without type casts.
+ *
+ * A typical use for this method is in a catch block to
+ * determine how a caught exception should be handled:
+ *
+ * Serializable tag = ...;
+ * try {
+ * ...;
+ * } catch (Throwable t) {
+ * if (TaggedIOExcepton.isTaggedWith(t, tag)) {
+ * // special processing for tagged exception
+ * } else {
+ * // handling of other kinds of exceptions
+ * }
+ * }
+ *
+ *
+ * @param throwable The Throwable object to check
+ * @param tag tag object
+ * @return {@code true} if the throwable has the specified tag,
+ * otherwise {@code false}
+ */
+ public static boolean isTaggedWith(final Throwable throwable, final Object tag) {
+ return tag != null
+ && throwable instanceof TaggedIOException
+ && tag.equals(((TaggedIOException) throwable).tag);
+ }
+
+ /**
+ * Throws the original {@link IOException} if the given throwable is
+ * a {@link TaggedIOException} decorator the given tag. Does nothing
+ * if the given throwable is of a different type or if it is tagged
+ * with some other tag.
+ *
+ * This method is typically used in a catch block to
+ * selectively rethrow tagged exceptions.
+ *
+ * Serializable tag = ...;
+ * try {
+ * ...;
+ * } catch (Throwable t) {
+ * TaggedIOExcepton.throwCauseIfTagged(t, tag);
+ * // handle other kinds of exceptions
+ * }
+ *
+ *
+ * @param throwable an exception
+ * @param tag tag object
+ * @throws IOException original exception from the tagged decorator, if any
+ */
+ public static void throwCauseIfTaggedWith(final Throwable throwable, final Object tag)
+ throws IOException {
+ if (isTaggedWith(throwable, tag)) {
+ throw ((TaggedIOException) throwable).getCause();
+ }
+ }
+
+ /**
+ * The tag of this exception.
+ */
+ private final Serializable tag;
+
+ /**
+ * Creates a tagged wrapper for the given exception.
+ *
+ * @param original the exception to be tagged
+ * @param tag tag of this exception
+ */
+ public TaggedIOException(final IOException original, final Serializable tag) {
+ super(original.getMessage(), original);
+ this.tag = tag;
+ }
+
+ /**
+ * Returns the serializable tag object.
+ *
+ * @return tag object
+ */
+ public Serializable getTag() {
+ return tag;
+ }
+
+ /**
+ * Returns the wrapped exception. The only difference to the overridden
+ * {@link Throwable#getCause()} method is the narrower return type.
+ *
+ * @return wrapped exception
+ */
+ @Override
+ public IOException getCause() {
+ return (IOException) super.getCause();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/ThreadMonitor.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/ThreadMonitor.java"
new file mode 100644
index 0000000000000000000000000000000000000000..e97ae3c62c1aaf92943633b8fcd922bbe6a502f0
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/ThreadMonitor.java"
@@ -0,0 +1,134 @@
+/*
+ * 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 org.apache.commons.io;
+
+/**
+ * Monitors a thread, interrupting it if it reaches the specified timeout.
+ *
+ * This works by sleeping until the specified timeout amount and then
+ * interrupting the thread being monitored. If the thread being monitored
+ * completes its work before being interrupted, it should interrupt()
+ * the monitor thread.
+ *
+ *
+ *
+ * long timeoutInMillis = 1000;
+ * try {
+ * Thread monitor = ThreadMonitor.start(timeoutInMillis);
+ * // do some work here
+ * ThreadMonitor.stop(monitor);
+ * } catch (InterruptedException e) {
+ * // timed amount was reached
+ * }
+ *
+ *
+ * @version $Id: ThreadMonitor.java 1718945 2015-12-09 19:51:14Z krosenvold $
+ */
+class ThreadMonitor implements Runnable {
+
+ private final Thread thread;
+ private final long timeout;
+
+ /**
+ * Start monitoring the current thread.
+ *
+ * @param timeout The timeout amount in milliseconds
+ * or no timeout if the value is zero or less
+ * @return The monitor thread or {@code null}
+ * if the timeout amount is not greater than zero
+ */
+ public static Thread start(final long timeout) {
+ return start(Thread.currentThread(), timeout);
+ }
+
+ /**
+ * Start monitoring the specified thread.
+ *
+ * @param thread The thread The thread to monitor
+ * @param timeout The timeout amount in milliseconds
+ * or no timeout if the value is zero or less
+ * @return The monitor thread or {@code null}
+ * if the timeout amount is not greater than zero
+ */
+ public static Thread start(final Thread thread, final long timeout) {
+ Thread monitor = null;
+ if (timeout > 0) {
+ final ThreadMonitor timout = new ThreadMonitor(thread, timeout);
+ monitor = new Thread(timout, ThreadMonitor.class.getSimpleName());
+ monitor.setDaemon(true);
+ monitor.start();
+ }
+ return monitor;
+ }
+
+ /**
+ * Stop monitoring the specified thread.
+ *
+ * @param thread The monitor thread, may be {@code null}
+ */
+ public static void stop(final Thread thread) {
+ if (thread != null) {
+ thread.interrupt();
+ }
+ }
+
+ /**
+ * Construct and new monitor.
+ *
+ * @param thread The thread to monitor
+ * @param timeout The timeout amount in milliseconds
+ */
+ private ThreadMonitor(final Thread thread, final long timeout) {
+ this.thread = thread;
+ this.timeout = timeout;
+ }
+
+ /**
+ * Sleep until the specified timeout amount and then
+ * interrupt the thread being monitored.
+ *
+ * @see Runnable#run()
+ */
+ public void run() {
+ try {
+ sleep(timeout);
+ thread.interrupt();
+ } catch (final InterruptedException e) {
+ // timeout not reached
+ }
+ }
+
+ /**
+ * Sleep for a guaranteed minimum number of milliseconds unless interrupted.
+ *
+ * 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(long ms) throws InterruptedException {
+ long finishAt = System.currentTimeMillis() + ms;
+ long remaining = ms;
+ do {
+ Thread.sleep(remaining);
+ remaining = finishAt - System.currentTimeMillis();
+ } while (remaining > 0);
+ }
+
+
+}
\ No newline at end of file
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..92822fbe37f1b668d744a819de3608367f47b626
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/AbstractFileComparator.java"
@@ -0,0 +1,76 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+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 {
+
+ /**
+ * Sort an array of files.
+ *
+ * This method uses {@link Arrays#sort(Object[], Comparator)}
+ * and returns the original array.
+ *
+ * @param files The files to sort, may be null
+ * @return The sorted array
+ * @since 2.0
+ */
+ public File[] sort(final File... files) {
+ if (files != null) {
+ Arrays.sort(files, this);
+ }
+ return files;
+ }
+
+ /**
+ * Sort a List of files.
+ *
+ * This method uses {@link Collections#sort(List, Comparator)}
+ * and returns the original list.
+ *
+ * @param files The files to sort, may be null
+ * @return The sorted list
+ * @since 2.0
+ */
+ public List sort(final List files) {
+ if (files != null) {
+ Collections.sort(files, this);
+ }
+ return files;
+ }
+
+ /**
+ * String representation of this file comparator.
+ *
+ * @return String representation of this file comparator
+ */
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..04aa5ba614c0e6750e173f14edd0587883c85c35
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/CompositeFileComparator.java"
@@ -0,0 +1,122 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Compare two files using a set of delegate file {@link Comparator}.
+ *
+ * This comparator can be used to sort lists or arrays of files
+ * by combining a number other comparators.
+ *
+ * Example of sorting a list of files by type (i.e. directory or file)
+ * and then by name:
+ *
+ * CompositeFileComparator comparator =
+ * new CompositeFileComparator(
+ * (AbstractFileComparator) DirectoryFileComparator.DIRECTORY_COMPARATOR,
+ * (AbstractFileComparator) NameFileComparator.NAME_COMPARATOR);
+ * List<File> list = ...
+ * comparator.sort(list);
+ *
+ *
+ * @version $Id: CompositeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 2.0
+ */
+public class CompositeFileComparator extends AbstractFileComparator implements Serializable {
+
+ private static final long serialVersionUID = -2224170307287243428L;
+ private static final Comparator>[] NO_COMPARATORS = {};
+ private final Comparator[] delegates;
+
+ /**
+ * Create a composite comparator for the set of delegate comparators.
+ *
+ * @param delegates The delegate file comparators
+ */
+ @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct
+ public CompositeFileComparator(final Comparator... delegates) {
+ if (delegates == null) {
+ this.delegates = (Comparator[]) NO_COMPARATORS;//1
+ } else {
+ this.delegates = (Comparator[]) new Comparator>[delegates.length];//2
+ System.arraycopy(delegates, 0, this.delegates, 0, delegates.length);
+ }
+ }
+
+ /**
+ * Create a composite comparator for the set of delegate comparators.
+ *
+ * @param delegates The delegate file comparators
+ */
+ @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct
+ public CompositeFileComparator(final Iterable> delegates) {
+ if (delegates == null) {
+ this.delegates = (Comparator[]) NO_COMPARATORS; //1
+ } else {
+ final List> list = new ArrayList>();
+ for (final Comparator comparator : delegates) {
+ list.add(comparator);
+ }
+ this.delegates = (Comparator[]) list.toArray(new Comparator>[list.size()]); //2
+ }
+ }
+
+ /**
+ * 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.
+ */
+ public int compare(final File file1, final File file2) {
+ int result = 0;
+ for (final Comparator delegate : delegates) {
+ result = delegate.compare(file1, file2);
+ if (result != 0) {
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * String representation of this file comparator.
+ *
+ * @return String representation of this file comparator
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(super.toString());
+ builder.append('{');
+ for (int i = 0; i < delegates.length; i++) {
+ if (i > 0) {
+ builder.append(',');
+ }
+ builder.append(delegates[i]);
+ }
+ builder.append('}');
+ return builder.toString();
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d19e3830d69e9c14fedff94022414c5e952ab9d6
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DefaultFileComparator.java"
@@ -0,0 +1,68 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Compare two files using the default {@link File#compareTo(File)} method.
+ *
+ * This comparator can be used to sort lists or arrays of files
+ * by using the default file comparison.
+ *
+ * Example of sorting a list of files using the
+ * {@link #DEFAULT_COMPARATOR} singleton instance:
+ *
+ * List<File> list = ...
+ * ((AbstractFileComparator) DefaultFileComparator.DEFAULT_COMPARATOR).sort(list);
+ *
+ *
+ * Example of doing a reverse sort of an array of files using the
+ * {@link #DEFAULT_REVERSE} singleton instance:
+ *
+ * File[] array = ...
+ * ((AbstractFileComparator) DefaultFileComparator.DEFAULT_REVERSE).sort(array);
+ *
+ *
+ *
+ * @version $Id: DefaultFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.4
+ */
+public class DefaultFileComparator extends AbstractFileComparator implements Serializable {
+
+ private static final long serialVersionUID = 3260141861365313518L;
+
+ /** Singleton default comparator instance */
+ public static final Comparator DEFAULT_COMPARATOR = new DefaultFileComparator();
+
+ /** Singleton reverse default comparator instance */
+ public static final Comparator DEFAULT_REVERSE = new ReverseComparator(DEFAULT_COMPARATOR);
+
+ /**
+ * 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.
+ */
+ public int compare(final File file1, final File file2) {
+ return file1.compareTo(file2);
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..cb789394b11a324d448fb2d9552f3273c9350f09
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/DirectoryFileComparator.java"
@@ -0,0 +1,81 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Compare two files using the {@link File#isDirectory()} method.
+ *
+ * This comparator can be used to sort lists or arrays by directories and files.
+ *
+ * Example of sorting a list of files/directories using the
+ * {@link #DIRECTORY_COMPARATOR} singleton instance:
+ *
+ * List<File> list = ...
+ * ((AbstractFileComparator) DirectoryFileComparator.DIRECTORY_COMPARATOR).sort(list);
+ *
+ *
+ * Example of doing a reverse sort of an array of files/directories using the
+ * {@link #DIRECTORY_REVERSE} singleton instance:
+ *
+ * File[] array = ...
+ * ((AbstractFileComparator) DirectoryFileComparator.DIRECTORY_REVERSE).sort(array);
+ *
+ *
+ *
+ * @version $Id: DirectoryFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 2.0
+ */
+public class DirectoryFileComparator extends AbstractFileComparator implements Serializable {
+
+ private static final long serialVersionUID = 296132640160964395L;
+
+ /** Singleton default comparator instance */
+ public static final Comparator DIRECTORY_COMPARATOR = new DirectoryFileComparator();
+
+ /** Singleton reverse default comparator instance */
+ public static final Comparator DIRECTORY_REVERSE = new ReverseComparator(DIRECTORY_COMPARATOR);
+
+ /**
+ * 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.
+ */
+ public int compare(final File file1, final File file2) {
+ return getType(file1) - getType(file2);
+ }
+
+ /**
+ * Convert type to numeric value.
+ *
+ * @param file The file
+ * @return 1 for directories and 2 for files
+ */
+ private int getType(final File file) {
+ if (file.isDirectory()) {
+ return 1;
+ } else {
+ return 2;
+ }
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..03a104ebb9223dcef7dee16ec7aa16a43f713bbb
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ExtensionFileComparator.java"
@@ -0,0 +1,123 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOCase;
+
+/**
+ * Compare the file name extensions for order
+ * (see {@link FilenameUtils#getExtension(String)}).
+ *
+ * This comparator can be used to sort lists or arrays of files
+ * by their file extension either in a case-sensitive, case-insensitive or
+ * system dependent case sensitive way. A number of singleton instances
+ * are provided for the various case sensitivity options (using {@link IOCase})
+ * and the reverse of those options.
+ *
+ * Example of a case-sensitive file extension sort using the
+ * {@link #EXTENSION_COMPARATOR} singleton instance:
+ *
+ * List<File> list = ...
+ * ((AbstractFileComparator) ExtensionFileComparator.EXTENSION_COMPARATOR).sort(list);
+ *
+ *
+ * Example of a reverse case-insensitive file extension sort using the
+ * {@link #EXTENSION_INSENSITIVE_REVERSE} singleton instance:
+ *
+ * File[] array = ...
+ * ((AbstractFileComparator) ExtensionFileComparator.EXTENSION_INSENSITIVE_REVERSE).sort(array);
+ *
+ *
+ *
+ * @version $Id: ExtensionFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.4
+ */
+public class ExtensionFileComparator extends AbstractFileComparator implements Serializable {
+
+ private static final long serialVersionUID = 1928235200184222815L;
+
+ /** Case-sensitive extension comparator instance (see {@link IOCase#SENSITIVE}) */
+ public static final Comparator EXTENSION_COMPARATOR = new ExtensionFileComparator();
+
+ /** Reverse case-sensitive extension comparator instance (see {@link IOCase#SENSITIVE}) */
+ public static final Comparator EXTENSION_REVERSE = new ReverseComparator(EXTENSION_COMPARATOR);
+
+ /** Case-insensitive extension comparator instance (see {@link IOCase#INSENSITIVE}) */
+ public static final Comparator EXTENSION_INSENSITIVE_COMPARATOR
+ = new ExtensionFileComparator(IOCase.INSENSITIVE);
+
+ /** Reverse case-insensitive extension comparator instance (see {@link IOCase#INSENSITIVE}) */
+ public static final Comparator EXTENSION_INSENSITIVE_REVERSE
+ = new ReverseComparator(EXTENSION_INSENSITIVE_COMPARATOR);
+
+ /** System sensitive extension comparator instance (see {@link IOCase#SYSTEM}) */
+ public static final Comparator EXTENSION_SYSTEM_COMPARATOR = new ExtensionFileComparator(IOCase.SYSTEM);
+
+ /** Reverse system sensitive path comparator instance (see {@link IOCase#SYSTEM}) */
+ public static final Comparator EXTENSION_SYSTEM_REVERSE = new ReverseComparator(EXTENSION_SYSTEM_COMPARATOR);
+
+ /** Whether the comparison is case sensitive. */
+ private final IOCase caseSensitivity;
+
+ /**
+ * Construct a case sensitive file extension comparator instance.
+ */
+ public ExtensionFileComparator() {
+ this.caseSensitivity = IOCase.SENSITIVE;
+ }
+
+ /**
+ * Construct a file extension comparator instance with the specified case-sensitivity.
+ *
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ */
+ public ExtensionFileComparator(final IOCase caseSensitivity) {
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * 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.
+ *
+ */
+ public int compare(final File file1, final File file2) {
+ final String suffix1 = FilenameUtils.getExtension(file1.getName());
+ final String suffix2 = FilenameUtils.getExtension(file2.getName());
+ return caseSensitivity.checkCompareTo(suffix1, suffix2);
+ }
+
+ /**
+ * String representation of this file comparator.
+ *
+ * @return String representation of this file comparator
+ */
+ @Override
+ public String toString() {
+ return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/LastModifiedFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/LastModifiedFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..8596d899d546f743823c3b9373083a9465124a4a
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/LastModifiedFileComparator.java"
@@ -0,0 +1,79 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Compare the last modified date/time of two files for order
+ * (see {@link File#lastModified()}).
+ *
+ * This comparator can be used to sort lists or arrays of files
+ * by their last modified date/time.
+ *
+ * Example of sorting a list of files using the
+ * {@link #LASTMODIFIED_COMPARATOR} singleton instance:
+ *
+ * List<File> list = ...
+ * ((AbstractFileComparator) LastModifiedFileComparator.LASTMODIFIED_COMPARATOR).sort(list);
+ *
+ *
+ * Example of doing a reverse sort of an array of files using the
+ * {@link #LASTMODIFIED_REVERSE} singleton instance:
+ *
+ * File[] array = ...
+ * ((AbstractFileComparator) LastModifiedFileComparator.LASTMODIFIED_REVERSE).sort(array);
+ *
+ *
+ *
+ * @version $Id: LastModifiedFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.4
+ */
+public class LastModifiedFileComparator extends AbstractFileComparator implements Serializable {
+
+ private static final long serialVersionUID = 7372168004395734046L;
+
+ /** Last modified comparator instance */
+ public static final Comparator LASTMODIFIED_COMPARATOR = new LastModifiedFileComparator();
+
+ /** Reverse last modified comparator instance */
+ public static final Comparator LASTMODIFIED_REVERSE = new ReverseComparator(LASTMODIFIED_COMPARATOR);
+
+ /**
+ * 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.
+ *
+ */
+ public int compare(final File file1, final File file2) {
+ final long result = file1.lastModified() - file2.lastModified();
+ if (result < 0) {
+ return -1;
+ } else if (result > 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..58a31a7df89d4ccfbd158aa2afc10c5055c5301d
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/NameFileComparator.java"
@@ -0,0 +1,116 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.apache.commons.io.IOCase;
+
+/**
+ * Compare the names of two files for order (see {@link File#getName()}).
+ *
+ * This comparator can be used to sort lists or arrays of files
+ * by their name either in a case-sensitive, case-insensitive or
+ * system dependent case sensitive way. A number of singleton instances
+ * are provided for the various case sensitivity options (using {@link IOCase})
+ * and the reverse of those options.
+ *
+ * Example of a case-sensitive file name sort using the
+ * {@link #NAME_COMPARATOR} singleton instance:
+ *
+ * List<File> list = ...
+ * ((AbstractFileComparator) NameFileComparator.NAME_COMPARATOR).sort(list);
+ *
+ *
+ * Example of a reverse case-insensitive file name sort using the
+ * {@link #NAME_INSENSITIVE_REVERSE} singleton instance:
+ *
+ * File[] array = ...
+ * ((AbstractFileComparator) NameFileComparator.NAME_INSENSITIVE_REVERSE).sort(array);
+ *
+ *
+ *
+ * @version $Id: NameFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.4
+ */
+public class NameFileComparator extends AbstractFileComparator implements Serializable {
+
+ private static final long serialVersionUID = 8397947749814525798L;
+
+ /** Case-sensitive name comparator instance (see {@link IOCase#SENSITIVE}) */
+ public static final Comparator NAME_COMPARATOR = new NameFileComparator();
+
+ /** Reverse case-sensitive name comparator instance (see {@link IOCase#SENSITIVE}) */
+ public static final Comparator NAME_REVERSE = new ReverseComparator(NAME_COMPARATOR);
+
+ /** Case-insensitive name comparator instance (see {@link IOCase#INSENSITIVE}) */
+ public static final Comparator NAME_INSENSITIVE_COMPARATOR = new NameFileComparator(IOCase.INSENSITIVE);
+
+ /** Reverse case-insensitive name comparator instance (see {@link IOCase#INSENSITIVE}) */
+ public static final Comparator NAME_INSENSITIVE_REVERSE = new ReverseComparator(NAME_INSENSITIVE_COMPARATOR);
+
+ /** System sensitive name comparator instance (see {@link IOCase#SYSTEM}) */
+ public static final Comparator NAME_SYSTEM_COMPARATOR = new NameFileComparator(IOCase.SYSTEM);
+
+ /** Reverse system sensitive name comparator instance (see {@link IOCase#SYSTEM}) */
+ public static final Comparator NAME_SYSTEM_REVERSE = new ReverseComparator(NAME_SYSTEM_COMPARATOR);
+
+ /** Whether the comparison is case sensitive. */
+ private final IOCase caseSensitivity;
+
+ /**
+ * Construct a case sensitive file name comparator instance.
+ */
+ public NameFileComparator() {
+ this.caseSensitivity = IOCase.SENSITIVE;
+ }
+
+ /**
+ * Construct a file name comparator instance with the specified case-sensitivity.
+ *
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ */
+ public NameFileComparator(final IOCase caseSensitivity) {
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * 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
+ * is less than the second, zero if the names are the
+ * same and a positive value if the first files name
+ * is greater than the second file.
+ */
+ public int compare(final File file1, final File file2) {
+ return caseSensitivity.checkCompareTo(file1.getName(), file2.getName());
+ }
+
+ /**
+ * String representation of this file comparator.
+ *
+ * @return String representation of this file comparator
+ */
+ @Override
+ public String toString() {
+ return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..57b453440289ba52fee344b27f4a236bad4ad228
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/PathFileComparator.java"
@@ -0,0 +1,117 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.apache.commons.io.IOCase;
+
+/**
+ * Compare the path of two files for order (see {@link File#getPath()}).
+ *
+ * This comparator can be used to sort lists or arrays of files
+ * by their path either in a case-sensitive, case-insensitive or
+ * system dependent case sensitive way. A number of singleton instances
+ * are provided for the various case sensitivity options (using {@link IOCase})
+ * and the reverse of those options.
+ *
+ * Example of a case-sensitive file path sort using the
+ * {@link #PATH_COMPARATOR} singleton instance:
+ *
+ * List<File> list = ...
+ * ((AbstractFileComparator) PathFileComparator.PATH_COMPARATOR).sort(list);
+ *
+ *
+ * Example of a reverse case-insensitive file path sort using the
+ * {@link #PATH_INSENSITIVE_REVERSE} singleton instance:
+ *
+ * File[] array = ...
+ * ((AbstractFileComparator) PathFileComparator.PATH_INSENSITIVE_REVERSE).sort(array);
+ *
+ *
+ *
+ * @version $Id: PathFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.4
+ */
+public class PathFileComparator extends AbstractFileComparator implements Serializable {
+
+ private static final long serialVersionUID = 6527501707585768673L;
+
+ /** Case-sensitive path comparator instance (see {@link IOCase#SENSITIVE}) */
+ public static final Comparator PATH_COMPARATOR = new PathFileComparator();
+
+ /** Reverse case-sensitive path comparator instance (see {@link IOCase#SENSITIVE}) */
+ public static final Comparator PATH_REVERSE = new ReverseComparator(PATH_COMPARATOR);
+
+ /** Case-insensitive path comparator instance (see {@link IOCase#INSENSITIVE}) */
+ public static final Comparator PATH_INSENSITIVE_COMPARATOR = new PathFileComparator(IOCase.INSENSITIVE);
+
+ /** Reverse case-insensitive path comparator instance (see {@link IOCase#INSENSITIVE}) */
+ public static final Comparator PATH_INSENSITIVE_REVERSE = new ReverseComparator(PATH_INSENSITIVE_COMPARATOR);
+
+ /** System sensitive path comparator instance (see {@link IOCase#SYSTEM}) */
+ public static final Comparator PATH_SYSTEM_COMPARATOR = new PathFileComparator(IOCase.SYSTEM);
+
+ /** Reverse system sensitive path comparator instance (see {@link IOCase#SYSTEM}) */
+ public static final Comparator PATH_SYSTEM_REVERSE = new ReverseComparator(PATH_SYSTEM_COMPARATOR);
+
+ /** Whether the comparison is case sensitive. */
+ private final IOCase caseSensitivity;
+
+ /**
+ * Construct a case sensitive file path comparator instance.
+ */
+ public PathFileComparator() {
+ this.caseSensitivity = IOCase.SENSITIVE;
+ }
+
+ /**
+ * Construct a file path comparator instance with the specified case-sensitivity.
+ *
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ */
+ public PathFileComparator(final IOCase caseSensitivity) {
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * 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.
+ *
+ */
+ public int compare(final File file1, final File file2) {
+ return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath());
+ }
+
+ /**
+ * String representation of this file comparator.
+ *
+ * @return String representation of this file comparator
+ */
+ @Override
+ public String toString() {
+ return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ReverseComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ReverseComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..bf0f63e69c7c3e6efab688d9429303b94c844658
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/ReverseComparator.java"
@@ -0,0 +1,69 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+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 {
+
+ private static final long serialVersionUID = -4808255005272229056L;
+ private final Comparator delegate;
+
+ /**
+ * Construct an instance with the sepecified delegate {@link Comparator}.
+ *
+ * @param delegate The comparator to delegate to
+ */
+ public ReverseComparator(final Comparator delegate) {
+ if (delegate == null) {
+ throw new IllegalArgumentException("Delegate comparator is missing");
+ }
+ this.delegate = delegate;
+ }
+
+ /**
+ * 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)
+ */
+ public int compare(final File file1, final File file2) {
+ return delegate.compare(file2, file1); // parameters switched round
+ }
+
+ /**
+ * String representation of this file comparator.
+ *
+ * @return String representation of this file comparator
+ */
+ @Override
+ public String toString() {
+ return super.toString() + "[" + delegate.toString() + "]";
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java"
new file mode 100644
index 0000000000000000000000000000000000000000..7351f9267cb30f38ca880014dbda64aededc5164
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/SizeFileComparator.java"
@@ -0,0 +1,142 @@
+/*
+ * 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 org.apache.commons.io.comparator;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Compare the length/size of two files for order (see
+ * {@link File#length()} and {@link FileUtils#sizeOfDirectory(File)}).
+ *
+ * This comparator can be used to sort lists or arrays of files
+ * by their length/size.
+ *
+ * Example of sorting a list of files using the
+ * {@link #SIZE_COMPARATOR} singleton instance:
+ *
+ * List<File> list = ...
+ * ((AbstractFileComparator) SizeFileComparator.SIZE_COMPARATOR).sort(list);
+ *
+ *
+ * Example of doing a reverse sort of an array of files using the
+ * {@link #SIZE_REVERSE} singleton instance:
+ *
+ * File[] array = ...
+ * ((AbstractFileComparator) SizeFileComparator.SIZE_REVERSE).sort(array);
+ *
+ *
+ * N.B. Directories are treated as zero size unless
+ * sumDirectoryContents is {@code true}.
+ *
+ * @version $Id: SizeFileComparator.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.4
+ */
+public class SizeFileComparator extends AbstractFileComparator implements Serializable {
+
+ private static final long serialVersionUID = -1201561106411416190L;
+
+ /** Size comparator instance - directories are treated as zero size */
+ public static final Comparator SIZE_COMPARATOR = new SizeFileComparator();
+
+ /** Reverse size comparator instance - directories are treated as zero size */
+ public static final Comparator SIZE_REVERSE = new ReverseComparator(SIZE_COMPARATOR);
+
+ /**
+ * Size comparator instance which sums the size of a directory's contents
+ * using {@link FileUtils#sizeOfDirectory(File)}
+ */
+ public static final Comparator SIZE_SUMDIR_COMPARATOR = new SizeFileComparator(true);
+
+ /**
+ * Reverse size comparator instance which sums the size of a directory's contents
+ * using {@link FileUtils#sizeOfDirectory(File)}
+ */
+ public static final Comparator SIZE_SUMDIR_REVERSE = new ReverseComparator(SIZE_SUMDIR_COMPARATOR);
+
+ /** Whether the sum of the directory's contents should be calculated. */
+ private final boolean sumDirectoryContents;
+
+ /**
+ * Construct a file size comparator instance (directories treated as zero size).
+ */
+ public SizeFileComparator() {
+ this.sumDirectoryContents = false;
+ }
+
+ /**
+ * Construct a file size comparator instance specifying whether the size of
+ * the directory contents should be aggregated.
+ *
+ * If the sumDirectoryContents is {@code true} The size of
+ * directories is calculated using {@link FileUtils#sizeOfDirectory(File)}.
+ *
+ * @param sumDirectoryContents {@code true} if the sum of the directoryies contents
+ * should be calculated, otherwise {@code false} if directories should be treated
+ * as size zero (see {@link FileUtils#sizeOfDirectory(File)}).
+ */
+ public SizeFileComparator(final boolean sumDirectoryContents) {
+ this.sumDirectoryContents = sumDirectoryContents;
+ }
+
+ /**
+ * 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.
+ *
+ */
+ public int compare(final File file1, final File file2) {
+ long size1 = 0;
+ if (file1.isDirectory()) {
+ size1 = sumDirectoryContents && file1.exists() ? FileUtils.sizeOfDirectory(file1) : 0;
+ } else {
+ size1 = file1.length();
+ }
+ long size2 = 0;
+ if (file2.isDirectory()) {
+ size2 = sumDirectoryContents && file2.exists() ? FileUtils.sizeOfDirectory(file2) : 0;
+ } else {
+ size2 = file2.length();
+ }
+ final long result = size1 - size2;
+ if (result < 0) {
+ return -1;
+ } else if (result > 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * String representation of this file comparator.
+ *
+ * @return String representation of this file comparator
+ */
+ @Override
+ public String toString() {
+ return super.toString() + "[sumDirectoryContents=" + sumDirectoryContents + "]";
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/package.html" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/package.html"
new file mode 100644
index 0000000000000000000000000000000000000000..d0071583e2b57feb43201a2a85faf42057ca0125
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/comparator/package.html"
@@ -0,0 +1,188 @@
+
+
+
+
+This package provides various {@link java.util.Comparator} implementations
+for {@link java.io.File}s.
+
+Sorting
+
+ All the compartors include convenience utility sort(File...) and
+ sort(List) methods.
+
+
+ For example, to sort the files in a directory by name:
+
+
+ File[] files = dir.listFiles();
+ NameFileComparator.NAME_COMPARATOR.sort(files);
+
+
+ ...alternatively you can do this in one line:
+
+
+
+ File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
+
+
+
+Composite Comparator
+
+ The CompositeFileComparator can be used
+ to compare (and sort lists or arrays of files) by combining a number other comparators.
+
+
+ For example, to sort an array of files by type (i.e. directory or file)
+ and then by name:
+
+
+
+ CompositeFileComparator comparator =
+ new CompositeFileComparator(
+ DirectoryFileComparator.DIRECTORY_COMPARATOR,
+ NameFileComparator.NAME_COMPARATOR);
+ File[] files = dir.listFiles();
+ comparator.sort(files);
+
+
+
+Singleton Instances (thread-safe)
+
+ The {@link java.util.Comparator} implementations have some convenience
+ singleton(thread-safe ) instances ready to use:
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AbstractFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AbstractFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..2e4d5974f6454994cf24c77dac5a495763ba20d1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AbstractFileFilter.java"
@@ -0,0 +1,64 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+
+/**
+ * An abstract class which implements the Java FileFilter and FilenameFilter
+ * interfaces via the IOFileFilter interface.
+ *
+ * Note that a subclass must override one of the accept methods,
+ * otherwise your class will infinitely loop.
+ *
+ * @since 1.0
+ * @version $Id: 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
+ */
+ 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
+ */
+ public boolean accept(final File dir, final String name) {
+ return accept(new File(dir, name));
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..bc8081e0e642be9deb880f6e5bf6c9623a817100
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java"
@@ -0,0 +1,159 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.Date;
+
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Filters files based on a cutoff time, can filter either newer
+ * files or files equal to or older.
+ *
+ * For example, to print all files and directories in the
+ * current directory older than one day:
+ *
+ *
+ * File dir = new File(".");
+ * // We are interested in files older than one day
+ * long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000);
+ * String[] files = dir.list( new AgeFileFilter(cutoff) );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @version $Id: AgeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @see FileFilterUtils#ageFileFilter(Date)
+ * @see FileFilterUtils#ageFileFilter(File)
+ * @see FileFilterUtils#ageFileFilter(long)
+ * @see FileFilterUtils#ageFileFilter(Date, boolean)
+ * @see FileFilterUtils#ageFileFilter(File, boolean)
+ * @see FileFilterUtils#ageFileFilter(long, boolean)
+ * @since 1.2
+ */
+public class AgeFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = -2132740084016138541L;
+
+ /** The cutoff time threshold. */
+ private final long cutoff;
+ /** Whether the files accepted will be older or newer. */
+ private final boolean acceptOlder;
+
+ /**
+ * Constructs a new age file filter for files equal to or older than
+ * a certain cutoff
+ *
+ * @param cutoff the threshold age of the files
+ */
+ public AgeFileFilter(final long cutoff) {
+ this(cutoff, true);
+ }
+
+ /**
+ * Constructs a new age file filter for files on any one side
+ * of a certain cutoff.
+ *
+ * @param cutoff 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).
+ */
+ public AgeFileFilter(final long cutoff, final boolean acceptOlder) {
+ this.acceptOlder = acceptOlder;
+ this.cutoff = cutoff;
+ }
+
+ /**
+ * Constructs a new age file filter for files older than (at or before)
+ * a certain cutoff date.
+ *
+ * @param cutoffDate the threshold age of the files
+ */
+ public AgeFileFilter(final Date cutoffDate) {
+ this(cutoffDate, true);
+ }
+
+ /**
+ * Constructs a new age file filter for files on any one side
+ * of a certain cutoff date.
+ *
+ * @param cutoffDate 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).
+ */
+ public AgeFileFilter(final Date cutoffDate, final boolean acceptOlder) {
+ this(cutoffDate.getTime(), acceptOlder);
+ }
+
+ /**
+ * Constructs a new age file filter for files older than (at or before)
+ * a certain File (whose last modification time will be used as reference).
+ *
+ * @param cutoffReference the file whose last modification
+ * time is usesd as the threshold age of the files
+ */
+ public AgeFileFilter(final File cutoffReference) {
+ this(cutoffReference, true);
+ }
+
+ /**
+ * Constructs a new age file filter for files on any one side
+ * of a certain File (whose last modification time will be used as
+ * reference).
+ *
+ * @param cutoffReference the file whose last modification
+ * 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).
+ */
+ public AgeFileFilter(final File cutoffReference, final boolean acceptOlder) {
+ this(cutoffReference.lastModified(), acceptOlder);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks to see if the last modification of the file matches cutoff
+ * favorably.
+ *
+ * If last modification time equals cutoff and newer files are required,
+ * file IS NOT selected.
+ * If last modification time equals cutoff and older files are required,
+ * file IS selected.
+ *
+ * @param file the File to check
+ * @return true if the filename matches
+ */
+ @Override
+ public boolean accept(final File file) {
+ final boolean newer = FileUtils.isFileNewer(file, cutoff);
+ return acceptOlder ? !newer : newer;
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ final String condition = acceptOlder ? "<=" : ">";
+ return super.toString() + "(" + condition + cutoff + ")";
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..2352aeb3a6492c980ba21e32f9b698cbe2fa94f3
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java"
@@ -0,0 +1,170 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A {@link java.io.FileFilter} providing conditional AND logic across a list of
+ * file filters. This filter returns {@code true} if all filters in the
+ * list return {@code true}. Otherwise, it returns {@code false}.
+ * Checking of the file filter list stops when the first filter returns
+ * {@code false}.
+ *
+ * @since 1.0
+ * @version $Id: AndFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ *
+ * @see FileFilterUtils#and(IOFileFilter...)
+ */
+public class AndFileFilter
+ extends AbstractFileFilter
+ implements ConditionalFileFilter, Serializable {
+
+ private static final long serialVersionUID = 7215974688563965257L;
+
+ /** The list of file filters. */
+ private final List fileFilters;
+
+ /**
+ * Constructs a new instance of AndFileFilter.
+ *
+ * @since 1.1
+ */
+ public AndFileFilter() {
+ this.fileFilters = new ArrayList();
+ }
+
+ /**
+ * Constructs a new instance of AndFileFilter
+ * with the specified list of filters.
+ *
+ * @param fileFilters a List of IOFileFilter instances, copied, null ignored
+ * @since 1.1
+ */
+ public AndFileFilter(final List fileFilters) {
+ if (fileFilters == null) {
+ this.fileFilters = new ArrayList();
+ } else {
+ this.fileFilters = new ArrayList(fileFilters);
+ }
+ }
+
+ /**
+ * Constructs a new file filter that ANDs 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
+ */
+ public AndFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) {
+ if (filter1 == null || filter2 == null) {
+ throw new IllegalArgumentException("The filters must not be null");
+ }
+ this.fileFilters = new ArrayList(2);
+ addFileFilter(filter1);
+ addFileFilter(filter2);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addFileFilter(final IOFileFilter ioFileFilter) {
+ this.fileFilters.add(ioFileFilter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List getFileFilters() {
+ return Collections.unmodifiableList(this.fileFilters);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean removeFileFilter(final IOFileFilter ioFileFilter) {
+ return this.fileFilters.remove(ioFileFilter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setFileFilters(final List fileFilters) {
+ this.fileFilters.clear();
+ this.fileFilters.addAll(fileFilters);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean accept(final File file) {
+ if (this.fileFilters.isEmpty()) {
+ return false;
+ }
+ for (final IOFileFilter fileFilter : fileFilters) {
+ if (!fileFilter.accept(file)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean accept(final File file, final String name) {
+ if (this.fileFilters.isEmpty()) {
+ return false;
+ }
+ for (final IOFileFilter fileFilter : fileFilters) {
+ if (!fileFilter.accept(file, name)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append(super.toString());
+ buffer.append("(");
+ if (fileFilters != null) {
+ for (int i = 0; i < fileFilters.size(); i++) {
+ if (i > 0) {
+ buffer.append(",");
+ }
+ final Object filter = fileFilters.get(i);
+ buffer.append(filter == null ? "null" : filter.toString());
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..2c06133604eef03b5099a3c3b299c346f8f67529
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/CanReadFileFilter.java"
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * This filter accepts Files that can be read.
+ *
+ * Example, showing how to print out a list of the
+ * current directory's readable files:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( CanReadFileFilter.CAN_READ );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ *
+ * Example, showing how to print out a list of the
+ * current directory's un-readable files:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( CanReadFileFilter.CANNOT_READ );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ *
+ * Example, showing how to print out a list of the
+ * current directory's read-only files:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( CanReadFileFilter.READ_ONLY );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @since 1.3
+ * @version $Id: CanReadFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ */
+public class CanReadFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 3179904805251622989L;
+
+ /** Singleton instance of readable filter */
+ public static final IOFileFilter CAN_READ = new CanReadFileFilter();
+
+ /** Singleton instance of not readable filter */
+ public static final IOFileFilter CANNOT_READ = new NotFileFilter(CAN_READ);
+
+ /** Singleton instance of read-only filter */
+ public static final IOFileFilter READ_ONLY = new AndFileFilter(CAN_READ,
+ CanWriteFileFilter.CANNOT_WRITE);
+
+ /**
+ * Restrictive consructor.
+ */
+ protected CanReadFileFilter() {
+ }
+
+ /**
+ * Checks to see if the file can be read.
+ *
+ * @param file the File to check.
+ * @return {@code true} if the file can be
+ * read, otherwise {@code false}.
+ */
+ @Override
+ public boolean accept(final File file) {
+ return file.canRead();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..eebee7d1e2004ce6a204ac15affdee4f3e3b089d
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/CanWriteFileFilter.java"
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * This filter accepts Files that can be written to.
+ *
+ * Example, showing how to print out a list of the
+ * current directory's writable files:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( CanWriteFileFilter.CAN_WRITE );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ *
+ * Example, showing how to print out a list of the
+ * current directory's un-writable files:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( CanWriteFileFilter.CANNOT_WRITE );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ *
+ * N.B. For read-only files, use
+ * CanReadFileFilter.READ_ONLY.
+ *
+ * @since 1.3
+ * @version $Id: CanWriteFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ */
+public class CanWriteFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 5132005214688990379L;
+
+ /** Singleton instance of writable filter */
+ public static final IOFileFilter CAN_WRITE = new CanWriteFileFilter();
+
+ /** Singleton instance of not writable filter */
+ public static final IOFileFilter CANNOT_WRITE = new NotFileFilter(CAN_WRITE);
+
+ /**
+ * Restrictive consructor.
+ */
+ protected CanWriteFileFilter() {
+ }
+
+ /**
+ * Checks to see if the file can be written to.
+ *
+ * @param file the File to check
+ * @return {@code true} if the file can be
+ * written to, otherwise {@code false}.
+ */
+ @Override
+ public boolean accept(final File file) {
+ return file.canWrite();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/ConditionalFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/ConditionalFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..b577b99452d30ff933d3ca096af4e0d4e6b67b11
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/ConditionalFileFilter.java"
@@ -0,0 +1,65 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.util.List;
+
+/**
+ * Defines operations for conditional file filters.
+ *
+ * @since 1.1
+ * @version $Id: ConditionalFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
+ */
+public interface ConditionalFileFilter {
+
+ /**
+ * Adds the specified file filter to the list of file filters at the end of
+ * the list.
+ *
+ * @param ioFileFilter the filter to be added
+ * @since 1.1
+ */
+ void addFileFilter(IOFileFilter ioFileFilter);
+
+ /**
+ * Returns this conditional file filter's list of file filters.
+ *
+ * @return the file filter list
+ * @since 1.1
+ */
+ List getFileFilters();
+
+ /**
+ * Removes the specified file filter.
+ *
+ * @param ioFileFilter filter to be removed
+ * @return {@code true} if the filter was found in the list,
+ * {@code false} otherwise
+ * @since 1.1
+ */
+ boolean removeFileFilter(IOFileFilter ioFileFilter);
+
+ /**
+ * Sets the list of file filters, replacing any previously configured
+ * file filters on this filter.
+ *
+ * @param fileFilters the list of filters
+ * @since 1.1
+ */
+ void setFileFilters(List fileFilters);
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/DelegateFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/DelegateFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..789b00fecd60a382339be6647fffb3334d1473e3
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/DelegateFileFilter.java"
@@ -0,0 +1,109 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.io.Serializable;
+
+/**
+ * This class turns a Java FileFilter or FilenameFilter into an IO FileFilter.
+ *
+ * @since 1.0
+ * @version $Id: DelegateFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ *
+ * @see FileFilterUtils#asFileFilter(FileFilter)
+ * @see FileFilterUtils#asFileFilter(FilenameFilter)
+ */
+public class DelegateFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = -8723373124984771318L;
+ /** The Filename filter */
+ private final FilenameFilter filenameFilter;
+ /** The File filter */
+ private final FileFilter fileFilter;
+
+ /**
+ * Constructs a delegate file filter around an existing FilenameFilter.
+ *
+ * @param filter the filter to decorate
+ */
+ public DelegateFileFilter(final FilenameFilter filter) {
+ if (filter == null) {
+ throw new IllegalArgumentException("The FilenameFilter must not be null");
+ }
+ this.filenameFilter = filter;
+ this.fileFilter = null;
+ }
+
+ /**
+ * Constructs a delegate file filter around an existing FileFilter.
+ *
+ * @param filter the filter to decorate
+ */
+ public DelegateFileFilter(final FileFilter filter) {
+ if (filter == null) {
+ throw new IllegalArgumentException("The FileFilter must not be null");
+ }
+ this.fileFilter = filter;
+ this.filenameFilter = null;
+ }
+
+ /**
+ * Checks the filter.
+ *
+ * @param file the file to check
+ * @return true if the filter matches
+ */
+ @Override
+ public boolean accept(final File file) {
+ if (fileFilter != null) {
+ return fileFilter.accept(file);
+ } else {
+ return super.accept(file);
+ }
+ }
+
+ /**
+ * Checks the filter.
+ *
+ * @param dir the directory
+ * @param name the filename in the directory
+ * @return true if the filter matches
+ */
+ @Override
+ public boolean accept(final File dir, final String name) {
+ if (filenameFilter != null) {
+ return filenameFilter.accept(dir, name);
+ } else {
+ return super.accept(dir, name);
+ }
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ final String delegate = fileFilter != null ? fileFilter.toString() : filenameFilter.toString();
+ return super.toString() + "(" + delegate + ")";
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..1c7f1c088122204f867b430387c1b7df30203186
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/DirectoryFileFilter.java"
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * This filter accepts Files that are directories.
+ *
+ * For example, here is how to print out a list of the
+ * current directory's subdirectories:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( DirectoryFileFilter.INSTANCE );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @since 1.0
+ * @version $Id: DirectoryFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ *
+ * @see FileFilterUtils#directoryFileFilter()
+ */
+public class DirectoryFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = -5148237843784525732L;
+ /**
+ * Singleton instance of directory filter.
+ * @since 1.3
+ */
+ public static final IOFileFilter DIRECTORY = new DirectoryFileFilter();
+ /**
+ * Singleton instance of directory filter.
+ * Please use the identical DirectoryFileFilter.DIRECTORY constant.
+ * The new name is more JDK 1.5 friendly as it doesn't clash with other
+ * values when using static imports.
+ */
+ public static final IOFileFilter INSTANCE = DIRECTORY;
+
+ /**
+ * Restrictive consructor.
+ */
+ protected DirectoryFileFilter() {
+ }
+
+ /**
+ * Checks to see if the file is a directory.
+ *
+ * @param file the File to check
+ * @return true if the file is a directory
+ */
+ @Override
+ public boolean accept(final File file) {
+ return file.isDirectory();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..241aa60e7bd837952174cdfcf3a79d9eeb6ff3d1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/EmptyFileFilter.java"
@@ -0,0 +1,87 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * This filter accepts files or directories that are empty.
+ *
+ * If the File is a directory it checks that
+ * it contains no files.
+ *
+ * Example, showing how to print out a list of the
+ * current directory's empty files/directories:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( EmptyFileFilter.EMPTY );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ *
+ * Example, showing how to print out a list of the
+ * current directory's non-empty files/directories:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( EmptyFileFilter.NOT_EMPTY );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @since 1.3
+ * @version $Id: EmptyFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ */
+public class EmptyFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 3631422087512832211L;
+
+ /** Singleton instance of empty filter */
+ public static final IOFileFilter EMPTY = new EmptyFileFilter();
+
+ /** Singleton instance of not-empty filter */
+ public static final IOFileFilter NOT_EMPTY = new NotFileFilter(EMPTY);
+
+ /**
+ * Restrictive consructor.
+ */
+ protected EmptyFileFilter() {
+ }
+
+ /**
+ * Checks to see if the file is empty.
+ *
+ * @param file the file or directory to check
+ * @return {@code true} if the file or directory
+ * is empty , otherwise {@code false}.
+ */
+ @Override
+ public boolean accept(final File file) {
+ if (file.isDirectory()) {
+ final File[] files = file.listFiles();
+ return files == null || files.length == 0;
+ } else {
+ return file.length() == 0;
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FalseFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FalseFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..6378c5566b2a11b36d1455ce09dbd568b3a16bd2
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FalseFileFilter.java"
@@ -0,0 +1,73 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * A file filter that always returns false.
+ *
+ * @since 1.0
+ * @version $Id: FalseFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ *
+ * @see FileFilterUtils#falseFileFilter()
+ */
+public class FalseFileFilter implements IOFileFilter, Serializable {
+
+ private static final long serialVersionUID = 6210271677940926200L;
+ /**
+ * Singleton instance of false filter.
+ * @since 1.3
+ */
+ public static final IOFileFilter FALSE = new FalseFileFilter();
+ /**
+ * Singleton instance of false filter.
+ * Please use the identical FalseFileFilter.FALSE constant.
+ * The new name is more JDK 1.5 friendly as it doesn't clash with other
+ * values when using static imports.
+ */
+ public static final IOFileFilter INSTANCE = FALSE;
+
+ /**
+ * Restrictive consructor.
+ */
+ protected FalseFileFilter() {
+ }
+
+ /**
+ * Returns false.
+ *
+ * @param file the file to check (ignored)
+ * @return false
+ */
+ public boolean accept(final File file) {
+ return false;
+ }
+
+ /**
+ * Returns false.
+ *
+ * @param dir the directory to check (ignored)
+ * @param name the filename (ignored)
+ * @return false
+ */
+ public boolean accept(final File dir, final String name) {
+ return false;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..e858974b3849da9d691deb367456369d6f080405
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java"
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * This filter accepts Files that are files (not directories).
+ *
+ * For example, here is how to print out a list of the real files
+ * within the current directory:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( FileFileFilter.FILE );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @since 1.3
+ * @version $Id: FileFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @see FileFilterUtils#fileFileFilter()
+ */
+public class FileFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 5345244090827540862L;
+ /** Singleton instance of file filter */
+ public static final IOFileFilter FILE = new FileFileFilter();
+
+ /**
+ * Restrictive consructor.
+ */
+ protected FileFileFilter() {
+ }
+
+ /**
+ * Checks to see if the file is a file.
+ *
+ * @param file the File to check
+ * @return true if the file is a file
+ */
+ @Override
+ public boolean accept(final File file) {
+ return file.isFile();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java"
new file mode 100644
index 0000000000000000000000000000000000000000..7bdbe3c32c372b66ba003d27a704c088ecd3d987
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java"
@@ -0,0 +1,796 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.io.IOCase;
+
+/**
+ * Useful utilities for working with file filters. It provides access to all
+ * file filter implementations in this package so you don't have to import
+ * every class you use.
+ *
+ * @since 1.0
+ * @version $Id: FileFilterUtils.java 1471767 2013-04-24 23:24:19Z sebb $
+ */
+public class FileFilterUtils {
+
+ /**
+ * FileFilterUtils is not normally instantiated.
+ */
+ public FileFilterUtils() {
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ *
+ * Applies an {@link IOFileFilter} to the provided {@link File}
+ * objects. The resulting array is a subset of the original file list that
+ * matches the provided filter.
+ *
+ *
+ *
+ * The {@link Set} returned by this method is not guaranteed to be thread safe.
+ *
+ *
+ *
+ * Set<File> allFiles = ...
+ * Set<File> javaFiles = FileFilterUtils.filterSet(allFiles,
+ * FileFilterUtils.suffixFileFilter(".java"));
+ *
+ * @param filter the filter to apply to the set of files.
+ * @param files the array of files to apply the filter to.
+ *
+ * @return a subset of files that is accepted by the
+ * file filter.
+ * @throws IllegalArgumentException if the filter is {@code null}
+ * or files contains a {@code null} value.
+ *
+ * @since 2.0
+ */
+ public static File[] filter(final IOFileFilter filter, final File... files) {
+ if (filter == null) {
+ throw new IllegalArgumentException("file filter is null");
+ }
+ if (files == null) {
+ return new File[0];
+ }
+ final List acceptedFiles = new ArrayList();
+ for (final File file : files) {
+ if (file == null) {
+ throw new IllegalArgumentException("file array contains null");
+ }
+ if (filter.accept(file)) {
+ acceptedFiles.add(file);
+ }
+ }
+ return acceptedFiles.toArray(new File[acceptedFiles.size()]);
+ }
+
+ /**
+ *
+ * Applies an {@link IOFileFilter} to the provided {@link File}
+ * objects. The resulting array is a subset of the original file list that
+ * matches the provided filter.
+ *
+ *
+ *
+ * The {@link Set} returned by this method is not guaranteed to be thread safe.
+ *
+ *
+ *
+ * Set<File> allFiles = ...
+ * Set<File> javaFiles = FileFilterUtils.filterSet(allFiles,
+ * FileFilterUtils.suffixFileFilter(".java"));
+ *
+ * @param filter the filter to apply to the set of files.
+ * @param files the array of files to apply the filter to.
+ *
+ * @return a subset of files that is accepted by the
+ * file filter.
+ * @throws IllegalArgumentException if the filter is {@code null}
+ * or files contains a {@code null} value.
+ *
+ * @since 2.0
+ */
+ public static File[] filter(final IOFileFilter filter, final Iterable files) {
+ final List acceptedFiles = filterList(filter, files);
+ return acceptedFiles.toArray(new File[acceptedFiles.size()]);
+ }
+
+ /**
+ *
+ * Applies an {@link IOFileFilter} to the provided {@link File}
+ * objects. The resulting list is a subset of the original files that
+ * matches the provided filter.
+ *
+ *
+ *
+ * The {@link List} returned by this method is not guaranteed to be thread safe.
+ *
+ *
+ *
+ * List<File> filesAndDirectories = ...
+ * List<File> directories = FileFilterUtils.filterList(filesAndDirectories,
+ * FileFilterUtils.directoryFileFilter());
+ *
+ * @param filter the filter to apply to each files in the list.
+ * @param files the collection of files to apply the filter to.
+ *
+ * @return a subset of files that is accepted by the
+ * file filter.
+ * @throws IllegalArgumentException if the filter is {@code null}
+ * or files contains a {@code null} value.
+ * @since 2.0
+ */
+ public static List filterList(final IOFileFilter filter, final Iterable files) {
+ return filter(filter, files, new ArrayList());
+ }
+
+ /**
+ *
+ * Applies an {@link IOFileFilter} to the provided {@link File}
+ * objects. The resulting list is a subset of the original files that
+ * matches the provided filter.
+ *
+ *
+ *
+ * The {@link List} returned by this method is not guaranteed to be thread safe.
+ *
+ *
+ *
+ * List<File> filesAndDirectories = ...
+ * List<File> directories = FileFilterUtils.filterList(filesAndDirectories,
+ * FileFilterUtils.directoryFileFilter());
+ *
+ * @param filter the filter to apply to each files in the list.
+ * @param files the collection of files to apply the filter to.
+ *
+ * @return a subset of files that is accepted by the
+ * file filter.
+ * @throws IllegalArgumentException if the filter is {@code null}
+ * or files contains a {@code null} value.
+ * @since 2.0
+ */
+ public static List filterList(final IOFileFilter filter, final File... files) {
+ final File[] acceptedFiles = filter(filter, files);
+ return Arrays.asList(acceptedFiles);
+ }
+
+ /**
+ *
+ * Applies an {@link IOFileFilter} to the provided {@link File}
+ * objects. The resulting set is a subset of the original file list that
+ * matches the provided filter.
+ *
+ *
+ *
+ * The {@link Set} returned by this method is not guaranteed to be thread safe.
+ *
+ *
+ *
+ * Set<File> allFiles = ...
+ * Set<File> javaFiles = FileFilterUtils.filterSet(allFiles,
+ * FileFilterUtils.suffixFileFilter(".java"));
+ *
+ * @param filter the filter to apply to the set of files.
+ * @param files the collection of files to apply the filter to.
+ *
+ * @return a subset of files that is accepted by the
+ * file filter.
+ * @throws IllegalArgumentException if the filter is {@code null}
+ * or files contains a {@code null} value.
+ *
+ * @since 2.0
+ */
+ public static Set filterSet(final IOFileFilter filter, final File... files) {
+ final File[] acceptedFiles = filter(filter, files);
+ return new HashSet(Arrays.asList(acceptedFiles));
+ }
+
+ /**
+ *
+ * Applies an {@link IOFileFilter} to the provided {@link File}
+ * objects. The resulting set is a subset of the original file list that
+ * matches the provided filter.
+ *
+ *
+ *
+ * The {@link Set} returned by this method is not guaranteed to be thread safe.
+ *
+ *
+ *
+ * Set<File> allFiles = ...
+ * Set<File> javaFiles = FileFilterUtils.filterSet(allFiles,
+ * FileFilterUtils.suffixFileFilter(".java"));
+ *
+ * @param filter the filter to apply to the set of files.
+ * @param files the collection of files to apply the filter to.
+ *
+ * @return a subset of files that is accepted by the
+ * file filter.
+ * @throws IllegalArgumentException if the filter is {@code null}
+ * or files contains a {@code null} value.
+ *
+ * @since 2.0
+ */
+ public static Set filterSet(final IOFileFilter filter, final Iterable files) {
+ return filter(filter, files, new HashSet());
+ }
+
+ /**
+ *
+ * Applies an {@link IOFileFilter} to the provided {@link File}
+ * objects and appends the accepted files to the other supplied collection.
+ *
+ *
+ *
+ * List<File> files = ...
+ * List<File> directories = FileFilterUtils.filterList(files,
+ * FileFilterUtils.sizeFileFilter(FileUtils.FIFTY_MB),
+ * new ArrayList<File>());
+ *
+ * @param filter the filter to apply to the collection of files.
+ * @param files the collection of files to apply the filter to.
+ * @param acceptedFiles the list of files to add accepted files to.
+ *
+ * @param the type of the file collection.
+ * @return a subset of files that is accepted by the
+ * file filter.
+ * @throws IllegalArgumentException if the filter is {@code null}
+ * or files contains a {@code null} value.
+ */
+ private static > T filter(final IOFileFilter filter,
+ final Iterable files, final T acceptedFiles) {
+ if (filter == null) {
+ throw new IllegalArgumentException("file filter is null");
+ }
+ if (files != null) {
+ for (final File file : files) {
+ if (file == null) {
+ throw new IllegalArgumentException("file collection contains null");
+ }
+ if (filter.accept(file)) {
+ acceptedFiles.add(file);
+ }
+ }
+ }
+ return acceptedFiles;
+ }
+
+ /**
+ * Returns a filter that returns true if the filename starts with the specified text.
+ *
+ * @param prefix the filename prefix
+ * @return a prefix checking filter
+ * @see PrefixFileFilter
+ */
+ public static IOFileFilter prefixFileFilter(final String prefix) {
+ return new PrefixFileFilter(prefix);
+ }
+
+ /**
+ * Returns a filter that returns true if the filename starts with the specified text.
+ *
+ * @param prefix the filename prefix
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @return a prefix checking filter
+ * @see PrefixFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter prefixFileFilter(final String prefix, final IOCase caseSensitivity) {
+ return new PrefixFileFilter(prefix, caseSensitivity);
+ }
+
+ /**
+ * Returns a filter that returns true if the filename ends with the specified text.
+ *
+ * @param suffix the filename suffix
+ * @return a suffix checking filter
+ * @see SuffixFileFilter
+ */
+ public static IOFileFilter suffixFileFilter(final String suffix) {
+ return new SuffixFileFilter(suffix);
+ }
+
+ /**
+ * Returns a filter that returns true if the filename ends with the specified text.
+ *
+ * @param suffix the filename suffix
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @return a suffix checking filter
+ * @see SuffixFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter suffixFileFilter(final String suffix, final IOCase caseSensitivity) {
+ return new SuffixFileFilter(suffix, caseSensitivity);
+ }
+
+ /**
+ * Returns a filter that returns true if the filename matches the specified text.
+ *
+ * @param name the filename
+ * @return a name checking filter
+ * @see NameFileFilter
+ */
+ public static IOFileFilter nameFileFilter(final String name) {
+ return new NameFileFilter(name);
+ }
+
+ /**
+ * Returns a filter that returns true if the filename matches the specified text.
+ *
+ * @param name the filename
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @return a name checking filter
+ * @see NameFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter nameFileFilter(final String name, final IOCase caseSensitivity) {
+ return new NameFileFilter(name, caseSensitivity);
+ }
+
+ /**
+ * Returns a filter that checks if the file is a directory.
+ *
+ * @return file filter that accepts only directories and not files
+ * @see DirectoryFileFilter#DIRECTORY
+ */
+ public static IOFileFilter directoryFileFilter() {
+ return DirectoryFileFilter.DIRECTORY;
+ }
+
+ /**
+ * Returns a filter that checks if the file is a file (and not a directory).
+ *
+ * @return file filter that accepts only files and not directories
+ * @see FileFileFilter#FILE
+ */
+ public static IOFileFilter fileFileFilter() {
+ return FileFileFilter.FILE;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns a filter that ANDs the two specified filters.
+ *
+ * @param filter1 the first filter
+ * @param filter2 the second filter
+ * @return a filter that ANDs the two specified filters
+ * @see #and(IOFileFilter...)
+ * @see AndFileFilter
+ * @deprecated use {@link #and(IOFileFilter...)}
+ */
+ @Deprecated
+ public static IOFileFilter andFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) {
+ return new AndFileFilter(filter1, filter2);
+ }
+
+ /**
+ * Returns a filter that ORs the two specified filters.
+ *
+ * @param filter1 the first filter
+ * @param filter2 the second filter
+ * @return a filter that ORs the two specified filters
+ * @see #or(IOFileFilter...)
+ * @see OrFileFilter
+ * @deprecated use {@link #or(IOFileFilter...)}
+ */
+ @Deprecated
+ public static IOFileFilter orFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) {
+ return new OrFileFilter(filter1, filter2);
+ }
+
+ /**
+ * Returns a filter that ANDs the specified filters.
+ *
+ * @param filters the IOFileFilters that will be ANDed together.
+ * @return a filter that ANDs the specified filters
+ *
+ * @throws IllegalArgumentException if the filters are null or contain a
+ * null value.
+ * @see AndFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter and(final IOFileFilter... filters) {
+ return new AndFileFilter(toList(filters));
+ }
+
+ /**
+ * Returns a filter that ORs the specified filters.
+ *
+ * @param filters the IOFileFilters that will be ORed together.
+ * @return a filter that ORs the specified filters
+ *
+ * @throws IllegalArgumentException if the filters are null or contain a
+ * null value.
+ * @see OrFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter or(final IOFileFilter... filters) {
+ return new OrFileFilter(toList(filters));
+ }
+
+ /**
+ * Create a List of file filters.
+ *
+ * @param filters The file filters
+ * @return The list of file filters
+ * @throws IllegalArgumentException if the filters are null or contain a
+ * null value.
+ * @since 2.0
+ */
+ public static List toList(final IOFileFilter... filters) {
+ if (filters == null) {
+ throw new IllegalArgumentException("The filters must not be null");
+ }
+ final List list = new ArrayList(filters.length);
+ for (int i = 0; i < filters.length; i++) {
+ if (filters[i] == null) {
+ throw new IllegalArgumentException("The filter[" + i + "] is null");
+ }
+ list.add(filters[i]);
+ }
+ return list;
+ }
+
+ /**
+ * Returns a filter that NOTs the specified filter.
+ *
+ * @param filter the filter to invert
+ * @return a filter that NOTs the specified filter
+ * @see NotFileFilter
+ */
+ public static IOFileFilter notFileFilter(final IOFileFilter filter) {
+ return new NotFileFilter(filter);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns a filter that always returns true.
+ *
+ * @return a true filter
+ * @see TrueFileFilter#TRUE
+ */
+ public static IOFileFilter trueFileFilter() {
+ return TrueFileFilter.TRUE;
+ }
+
+ /**
+ * Returns a filter that always returns false.
+ *
+ * @return a false filter
+ * @see FalseFileFilter#FALSE
+ */
+ public static IOFileFilter falseFileFilter() {
+ return FalseFileFilter.FALSE;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns an IOFileFilter that wraps the
+ * FileFilter instance.
+ *
+ * @param filter the filter to be wrapped
+ * @return a new filter that implements IOFileFilter
+ * @see DelegateFileFilter
+ */
+ public static IOFileFilter asFileFilter(final FileFilter filter) {
+ return new DelegateFileFilter(filter);
+ }
+
+ /**
+ * Returns an IOFileFilter that wraps the
+ * FilenameFilter instance.
+ *
+ * @param filter the filter to be wrapped
+ * @return a new filter that implements IOFileFilter
+ * @see DelegateFileFilter
+ */
+ public static IOFileFilter asFileFilter(final FilenameFilter filter) {
+ return new DelegateFileFilter(filter);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * 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
+ * @see AgeFileFilter
+ * @since 1.2
+ */
+ public static IOFileFilter ageFileFilter(final long cutoff) {
+ return new AgeFileFilter(cutoff);
+ }
+
+ /**
+ * Returns a filter that filters files based on a cutoff time.
+ *
+ * @param cutoff the time threshold
+ * @param acceptOlder if true, older files get accepted, if false, newer
+ * @return an appropriately configured age file filter
+ * @see AgeFileFilter
+ * @since 1.2
+ */
+ public static IOFileFilter ageFileFilter(final long cutoff, final boolean acceptOlder) {
+ return new AgeFileFilter(cutoff, acceptOlder);
+ }
+
+ /**
+ * 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
+ * @see AgeFileFilter
+ * @since 1.2
+ */
+ public static IOFileFilter ageFileFilter(final Date cutoffDate) {
+ return new AgeFileFilter(cutoffDate);
+ }
+
+ /**
+ * Returns a filter that filters files based on a cutoff date.
+ *
+ * @param cutoffDate the time threshold
+ * @param acceptOlder if true, older files get accepted, if false, newer
+ * @return an appropriately configured age file filter
+ * @see AgeFileFilter
+ * @since 1.2
+ */
+ public static IOFileFilter ageFileFilter(final Date cutoffDate, final boolean acceptOlder) {
+ return new AgeFileFilter(cutoffDate, acceptOlder);
+ }
+
+ /**
+ * 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 usesd as the threshold age of the files
+ * @return an appropriately configured age file filter
+ * @see AgeFileFilter
+ * @since 1.2
+ */
+ public static IOFileFilter ageFileFilter(final File cutoffReference) {
+ return new AgeFileFilter(cutoffReference);
+ }
+
+ /**
+ * Returns a filter that filters files based on a cutoff reference file.
+ *
+ * @param cutoffReference the file whose last modification
+ * 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
+ * @since 1.2
+ */
+ public static IOFileFilter ageFileFilter(final File cutoffReference, final boolean acceptOlder) {
+ return new AgeFileFilter(cutoffReference, acceptOlder);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Returns a filter that returns true if the file is bigger than a certain size.
+ *
+ * @param threshold the file size threshold
+ * @return an appropriately configured SizeFileFilter
+ * @see SizeFileFilter
+ * @since 1.2
+ */
+ public static IOFileFilter sizeFileFilter(final long threshold) {
+ return new SizeFileFilter(threshold);
+ }
+
+ /**
+ * Returns a filter that filters based on file size.
+ *
+ * @param threshold the file size threshold
+ * @param acceptLarger if true, larger files get accepted, if false, smaller
+ * @return an appropriately configured SizeFileFilter
+ * @see SizeFileFilter
+ * @since 1.2
+ */
+ public static IOFileFilter sizeFileFilter(final long threshold, final boolean acceptLarger) {
+ return new SizeFileFilter(threshold, acceptLarger);
+ }
+
+ /**
+ * Returns a filter that accepts files whose size is >= minimum size
+ * and <= maximum size.
+ *
+ * @param minSizeInclusive the minimum file size (inclusive)
+ * @param maxSizeInclusive the maximum file size (inclusive)
+ * @return an appropriately configured IOFileFilter
+ * @see SizeFileFilter
+ * @since 1.3
+ */
+ public static IOFileFilter sizeRangeFileFilter(final long minSizeInclusive, final long maxSizeInclusive ) {
+ final IOFileFilter minimumFilter = new SizeFileFilter(minSizeInclusive, true);
+ final IOFileFilter maximumFilter = new SizeFileFilter(maxSizeInclusive + 1L, false);
+ return new AndFileFilter(minimumFilter, maximumFilter);
+ }
+
+ /**
+ * Returns a filter that accepts files that begin with the provided magic
+ * number.
+ *
+ * @param magicNumber the magic number (byte sequence) to match at the
+ * beginning of each file.
+ *
+ * @return an IOFileFilter that accepts files beginning with the provided
+ * magic number.
+ *
+ * @throws IllegalArgumentException if magicNumber is
+ * {@code null} or the empty String.
+ * @see MagicNumberFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter magicNumberFileFilter(final String magicNumber) {
+ return new MagicNumberFileFilter(magicNumber);
+ }
+
+ /**
+ * Returns a filter that accepts files that contains the provided magic
+ * number at a specified offset within the file.
+ *
+ * @param magicNumber the magic number (byte sequence) to match at the
+ * provided offset in each file.
+ * @param offset the offset within the files to look for the magic number.
+ *
+ * @return an IOFileFilter that accepts files containing the magic number
+ * at the specified offset.
+ *
+ * @throws IllegalArgumentException if magicNumber is
+ * {@code null} or the empty String, or if offset is a
+ * negative number.
+ * @see MagicNumberFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter magicNumberFileFilter(final String magicNumber, final long offset) {
+ return new MagicNumberFileFilter(magicNumber, offset);
+ }
+
+ /**
+ * Returns a filter that accepts files that begin with the provided magic
+ * number.
+ *
+ * @param magicNumber the magic number (byte sequence) to match at the
+ * beginning of each file.
+ *
+ * @return an IOFileFilter that accepts files beginning with the provided
+ * magic number.
+ *
+ * @throws IllegalArgumentException if magicNumber is
+ * {@code null} or is of length zero.
+ * @see MagicNumberFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber) {
+ return new MagicNumberFileFilter(magicNumber);
+ }
+
+ /**
+ * Returns a filter that accepts files that contains the provided magic
+ * number at a specified offset within the file.
+ *
+ * @param magicNumber the magic number (byte sequence) to match at the
+ * provided offset in each file.
+ * @param offset the offset within the files to look for the magic number.
+ *
+ * @return an IOFileFilter that accepts files containing the magic number
+ * at the specified offset.
+ *
+ * @throws IllegalArgumentException if magicNumber is
+ * {@code null}, or contains no bytes, or offset
+ * is a negative number.
+ * @see MagicNumberFileFilter
+ * @since 2.0
+ */
+ public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber, final long offset) {
+ return new MagicNumberFileFilter(magicNumber, offset);
+ }
+
+ //-----------------------------------------------------------------------
+ /* Constructed on demand and then cached */
+ private static final IOFileFilter cvsFilter = notFileFilter(
+ and(directoryFileFilter(), nameFileFilter("CVS")));
+
+ /* Constructed on demand and then cached */
+ private static final IOFileFilter svnFilter = notFileFilter(
+ and(directoryFileFilter(), nameFileFilter(".svn")));
+
+ /**
+ * Decorates a filter to make it ignore CVS directories.
+ * Passing in {@code null} will return a filter that accepts everything
+ * except CVS directories.
+ *
+ * @param filter the filter to decorate, null means an unrestricted filter
+ * @return the decorated filter, never null
+ * @since 1.1 (method existed but had bug in 1.0)
+ */
+ public static IOFileFilter makeCVSAware(final IOFileFilter filter) {
+ if (filter == null) {
+ return cvsFilter;
+ } else {
+ return and(filter, cvsFilter);
+ }
+ }
+
+ /**
+ * Decorates a filter to make it ignore SVN directories.
+ * Passing in {@code null} will return a filter that accepts everything
+ * except SVN directories.
+ *
+ * @param filter the filter to decorate, null means an unrestricted filter
+ * @return the decorated filter, never null
+ * @since 1.1
+ */
+ public static IOFileFilter makeSVNAware(final IOFileFilter filter) {
+ if (filter == null) {
+ return svnFilter;
+ } else {
+ return and(filter, svnFilter);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Decorates a filter so that it only applies to directories and not to files.
+ *
+ * @param filter the filter to decorate, null means an unrestricted filter
+ * @return the decorated filter, never null
+ * @see DirectoryFileFilter#DIRECTORY
+ * @since 1.3
+ */
+ public static IOFileFilter makeDirectoryOnly(final IOFileFilter filter) {
+ if (filter == null) {
+ return DirectoryFileFilter.DIRECTORY;
+ }
+ return new AndFileFilter(DirectoryFileFilter.DIRECTORY, filter);
+ }
+
+ /**
+ * Decorates a filter so that it only applies to files and not to directories.
+ *
+ * @param filter the filter to decorate, null means an unrestricted filter
+ * @return the decorated filter, never null
+ * @see FileFileFilter#FILE
+ * @since 1.3
+ */
+ public static IOFileFilter makeFileOnly(final IOFileFilter filter) {
+ if (filter == null) {
+ return FileFileFilter.FILE;
+ }
+ return new AndFileFilter(FileFileFilter.FILE, filter);
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..c7dcf9c540f6861fa4ec6d169c9150b2c157e3c3
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/HiddenFileFilter.java"
@@ -0,0 +1,79 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * This filter accepts Files that are hidden.
+ *
+ * Example, showing how to print out a list of the
+ * current directory's hidden files:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( HiddenFileFilter.HIDDEN );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ *
+ * Example, showing how to print out a list of the
+ * current directory's visible (i.e. not hidden) files:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( HiddenFileFilter.VISIBLE );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @since 1.3
+ * @version $Id: HiddenFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ */
+public class HiddenFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 8930842316112759062L;
+
+ /** Singleton instance of hidden filter */
+ public static final IOFileFilter HIDDEN = new HiddenFileFilter();
+
+ /** Singleton instance of visible filter */
+ public static final IOFileFilter VISIBLE = new NotFileFilter(HIDDEN);
+
+ /**
+ * Restrictive consructor.
+ */
+ protected HiddenFileFilter() {
+ }
+
+ /**
+ * Checks to see if the file is hidden.
+ *
+ * @param file the File to check
+ * @return {@code true} if the file is
+ * hidden , otherwise {@code false}.
+ */
+ @Override
+ public boolean accept(final File file) {
+ return file.isHidden();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ea840f399930a7014612b0ca3f683f7b654a32fa
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java"
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+
+/**
+ * An interface which brings the FileFilter and FilenameFilter
+ * interfaces together.
+ *
+ * @since 1.0
+ * @version $Id: IOFileFilter.java 1471767 2013-04-24 23:24:19Z sebb $
+ */
+public interface IOFileFilter extends FileFilter, FilenameFilter {
+
+ /**
+ * Checks to see if the File should be accepted by this filter.
+ *
+ * Defined in {@link java.io.FileFilter}.
+ *
+ * @param file the File to check
+ * @return true if this file matches the test
+ */
+ boolean accept(File file);
+
+ /**
+ * Checks to see if the File should be accepted by this filter.
+ *
+ * Defined in {@link java.io.FilenameFilter}.
+ *
+ * @param dir the directory File to check
+ * @param name the filename within the directory to check
+ * @return true if this file matches the test
+ */
+ boolean accept(File dir, String name);
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..00aa9962280af801e855f18dd5ecfd9bc2c62597
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java"
@@ -0,0 +1,274 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+import org.apache.commons.io.IOUtils;
+
+/**
+ *
+ * File filter for matching files containing a "magic number". A magic number
+ * is a unique series of bytes common to all files of a specific file format.
+ * For instance, all Java class files begin with the bytes
+ * 0xCAFEBABE.
+ *
+ *
+ *
+ * File dir = new File(".");
+ * MagicNumberFileFilter javaClassFileFilter =
+ * MagicNumberFileFilter(new byte[] {(byte) 0xCA, (byte) 0xFE,
+ * (byte) 0xBA, (byte) 0xBE});
+ * String[] javaClassFiles = dir.list(javaClassFileFilter);
+ * for (String javaClassFile : javaClassFiles) {
+ * System.out.println(javaClassFile);
+ * }
+ *
+ *
+ *
+ * Sometimes, such as in the case of TAR files, the
+ * magic number will be offset by a certain number of bytes in the file. In the
+ * case of TAR archive files, this offset is 257 bytes.
+ *
+ *
+ *
+ * File dir = new File(".");
+ * MagicNumberFileFilter tarFileFilter =
+ * MagicNumberFileFilter("ustar", 257);
+ * String[] tarFiles = dir.list(tarFileFilter);
+ * for (String tarFile : tarFiles) {
+ * System.out.println(tarFile);
+ * }
+ *
+ *
+ * @since 2.0
+ * @see FileFilterUtils#magicNumberFileFilter(byte[])
+ * @see FileFilterUtils#magicNumberFileFilter(String)
+ * @see FileFilterUtils#magicNumberFileFilter(byte[], long)
+ * @see FileFilterUtils#magicNumberFileFilter(String, long)
+ */
+public class MagicNumberFileFilter extends AbstractFileFilter implements
+ Serializable {
+
+ /**
+ * The serialization version unique identifier.
+ */
+ private static final long serialVersionUID = -547733176983104172L;
+
+ /**
+ * The magic number to compare against the file's bytes at the provided
+ * offset.
+ */
+ private final byte[] magicNumbers;
+
+ /**
+ * The offset (in bytes) within the files that the magic number's bytes
+ * should appear.
+ */
+ private final long byteOffset;
+
+ /**
+ *
+ * Constructs a new MagicNumberFileFilter and associates it with the magic
+ * number to test for in files. This constructor assumes a starting offset
+ * of 0.
+ *
+ *
+ *
+ * It is important to note that the array is not cloned and that
+ * any changes to the magic number array after construction will affect the
+ * behavior of this file filter.
+ *
+ *
+ *
+ * MagicNumberFileFilter javaClassFileFilter =
+ * MagicNumberFileFilter(new byte[] {(byte) 0xCA, (byte) 0xFE,
+ * (byte) 0xBA, (byte) 0xBE});
+ *
+ *
+ * @param magicNumber the magic number to look for in the file.
+ *
+ * @throws IllegalArgumentException if magicNumber is
+ * {@code null}, or contains no bytes.
+ */
+ public MagicNumberFileFilter(final byte[] magicNumber) {
+ this(magicNumber, 0);
+ }
+
+ /**
+ *
+ * Constructs a new MagicNumberFileFilter and associates it with the magic
+ * number to test for in files. This constructor assumes a starting offset
+ * of 0.
+ *
+ *
+ * Example usage:
+ *
+ * {@code
+ * MagicNumberFileFilter xmlFileFilter =
+ * MagicNumberFileFilter("
+ *
+ * @param magicNumber the magic number to look for in the file.
+ * The string is converted to bytes using the platform default charset.
+ *
+ * @throws IllegalArgumentException if magicNumber is
+ * {@code null} or the empty String.
+ */
+ public MagicNumberFileFilter(final String magicNumber) {
+ this(magicNumber, 0);
+ }
+
+ /**
+ *
+ * Constructs a new MagicNumberFileFilter and associates it with the magic
+ * number to test for in files and the byte offset location in the file to
+ * to look for that magic number.
+ *
+ *
+ *
+ * MagicNumberFileFilter tarFileFilter =
+ * MagicNumberFileFilter("ustar", 257);
+ *
+ *
+ * @param magicNumber the magic number to look for in the file.
+ * The string is converted to bytes using the platform default charset.
+ * @param offset the byte offset in the file to start comparing bytes.
+ *
+ * @throws IllegalArgumentException if magicNumber is
+ * {@code null} or the empty String, or offset is
+ * a negative number.
+ */
+ public MagicNumberFileFilter(final String magicNumber, final long offset) {
+ if (magicNumber == null) {
+ throw new IllegalArgumentException("The magic number cannot be null");
+ }
+ if (magicNumber.isEmpty()) {
+ throw new IllegalArgumentException("The magic number must contain at least one byte");
+ }
+ if (offset < 0) {
+ throw new IllegalArgumentException("The offset cannot be negative");
+ }
+
+ this.magicNumbers = magicNumber.getBytes(Charset.defaultCharset()); // explicitly uses the platform default
+ // charset
+ this.byteOffset = offset;
+ }
+
+ /**
+ *
+ * Constructs a new MagicNumberFileFilter and associates it with the magic
+ * number to test for in files and the byte offset location in the file to
+ * to look for that magic number.
+ *
+ *
+ *
+ * MagicNumberFileFilter tarFileFilter =
+ * MagicNumberFileFilter(new byte[] {0x75, 0x73, 0x74, 0x61, 0x72}, 257);
+ *
+ *
+ *
+ * MagicNumberFileFilter javaClassFileFilter =
+ * MagicNumberFileFilter(new byte[] {0xCA, 0xFE, 0xBA, 0xBE}, 0);
+ *
+ *
+ * @param magicNumber the magic number to look for in the file.
+ * @param offset the byte offset in the file to start comparing bytes.
+ *
+ * @throws IllegalArgumentException if magicNumber is
+ * {@code null}, or contains no bytes, or offset
+ * is a negative number.
+ */
+ public MagicNumberFileFilter(final byte[] magicNumber, final long offset) {
+ if (magicNumber == null) {
+ throw new IllegalArgumentException("The magic number cannot be null");
+ }
+ if (magicNumber.length == 0) {
+ throw new IllegalArgumentException("The magic number must contain at least one byte");
+ }
+ if (offset < 0) {
+ throw new IllegalArgumentException("The offset cannot be negative");
+ }
+
+ this.magicNumbers = new byte[magicNumber.length];
+ System.arraycopy(magicNumber, 0, this.magicNumbers, 0, magicNumber.length);
+ this.byteOffset = offset;
+ }
+
+ /**
+ *
+ * Accepts the provided file if the file contains the file filter's magic
+ * number at the specified offset.
+ *
+ *
+ *
+ * If any {@link IOException}s occur while reading the file, the file will
+ * be rejected.
+ *
+ *
+ * @param file the file to accept or reject.
+ *
+ * @return {@code true} if the file contains the filter's magic number
+ * at the specified offset, {@code false} otherwise.
+ */
+ @Override
+ public boolean accept(final File file) {
+ if (file != null && file.isFile() && file.canRead()) {
+ RandomAccessFile randomAccessFile = null;
+ try {
+ final byte[] fileBytes = new byte[this.magicNumbers.length];
+ randomAccessFile = new RandomAccessFile(file, "r");
+ randomAccessFile.seek(byteOffset);
+ final int read = randomAccessFile.read(fileBytes);
+ if (read != magicNumbers.length) {
+ return false;
+ }
+ return Arrays.equals(this.magicNumbers, fileBytes);
+ } catch (final IOException ioe) {
+ // Do nothing, fall through and do not accept file
+ } finally {
+ IOUtils.closeQuietly(randomAccessFile);
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns a String representation of the file filter, which includes the
+ * magic number bytes and byte offset.
+ *
+ * @return a String representation of the file filter.
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder(super.toString());
+ builder.append("(");
+ builder.append(new String(magicNumbers, Charset.defaultCharset()));// TODO perhaps use hex if value is not
+ // printable
+ builder.append(",");
+ builder.append(this.byteOffset);
+ builder.append(")");
+ return builder.toString();
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..99521e4fd7294134bd45a2c08807a4effd2c07cd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/NameFileFilter.java"
@@ -0,0 +1,190 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.commons.io.IOCase;
+
+/**
+ * Filters filenames for a certain name.
+ *
+ * For example, to print all files and directories in the
+ * current directory whose name is Test:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( new NameFileFilter("Test") );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @since 1.0
+ * @version $Id: NameFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @see FileFilterUtils#nameFileFilter(String)
+ * @see FileFilterUtils#nameFileFilter(String, IOCase)
+ */
+public class NameFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 176844364689077340L;
+ /** The filenames to search for */
+ private final String[] names;
+ /** Whether the comparison is case sensitive. */
+ private final IOCase caseSensitivity;
+
+ /**
+ * Constructs a new case-sensitive name file filter for a single name.
+ *
+ * @param name the name to allow, must not be null
+ * @throws IllegalArgumentException if the name is null
+ */
+ public NameFileFilter(final String name) {
+ this(name, null);
+ }
+
+ /**
+ * Construct a new name file filter specifying case-sensitivity.
+ *
+ * @param name the name to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the name is null
+ */
+ public NameFileFilter(final String name, final IOCase caseSensitivity) {
+ if (name == null) {
+ throw new IllegalArgumentException("The wildcard must not be null");
+ }
+ this.names = new String[] {name};
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Constructs a new case-sensitive name file filter for an array of names.
+ *
+ * The array is not cloned, so could be changed after constructing the
+ * instance. This would be inadvisable however.
+ *
+ * @param names the names to allow, must not be null
+ * @throws IllegalArgumentException if the names array is null
+ */
+ public NameFileFilter(final String[] names) {
+ this(names, null);
+ }
+
+ /**
+ * Constructs a new name file filter for an array of names specifying case-sensitivity.
+ *
+ * @param names the names to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the names array is null
+ */
+ public NameFileFilter(final String[] names, final IOCase caseSensitivity) {
+ if (names == null) {
+ throw new IllegalArgumentException("The array of names must not be null");
+ }
+ this.names = new String[names.length];
+ System.arraycopy(names, 0, this.names, 0, names.length);
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Constructs a new case-sensitive name file filter for a list of names.
+ *
+ * @param names the names to allow, must not be null
+ * @throws IllegalArgumentException if the name list is null
+ * @throws ClassCastException if the list does not contain Strings
+ */
+ public NameFileFilter(final List names) {
+ this(names, null);
+ }
+
+ /**
+ * Constructs a new name file filter for a list of names specifying case-sensitivity.
+ *
+ * @param names the names to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the name list is null
+ * @throws ClassCastException if the list does not contain Strings
+ */
+ public NameFileFilter(final List names, final IOCase caseSensitivity) {
+ if (names == null) {
+ throw new IllegalArgumentException("The list of names must not be null");
+ }
+ this.names = names.toArray(new String[names.size()]);
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks to see if the filename matches.
+ *
+ * @param file the File to check
+ * @return true if the filename matches
+ */
+ @Override
+ public boolean accept(final File file) {
+ final String name = file.getName();
+ for (final String name2 : this.names) {
+ if (caseSensitivity.checkEquals(name, name2)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks to see if the filename matches.
+ *
+ * @param dir the File directory (ignored)
+ * @param name the filename
+ * @return true if the filename matches
+ */
+ @Override
+ public boolean accept(final File dir, final String name) {
+ for (final String name2 : names) {
+ if (caseSensitivity.checkEquals(name, name2)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append(super.toString());
+ buffer.append("(");
+ if (names != null) {
+ for (int i = 0; i < names.length; i++) {
+ if (i > 0) {
+ buffer.append(",");
+ }
+ buffer.append(names[i]);
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/NotFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/NotFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d86e382e1053037d92fa7121698f774734150b1c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/NotFileFilter.java"
@@ -0,0 +1,81 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * This filter produces a logical NOT of the filters specified.
+ *
+ * @since 1.0
+ * @version $Id: NotFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @see FileFilterUtils#notFileFilter(IOFileFilter)
+ */
+public class NotFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 6131563330944994230L;
+ /** The filter */
+ private final IOFileFilter filter;
+
+ /**
+ * Constructs a new file filter that NOTs the result of another filter.
+ *
+ * @param filter the filter, must not be null
+ * @throws IllegalArgumentException if the filter is null
+ */
+ public NotFileFilter(final IOFileFilter filter) {
+ if (filter == null) {
+ throw new IllegalArgumentException("The filter must not be null");
+ }
+ this.filter = filter;
+ }
+
+ /**
+ * Returns the logical NOT of the underlying filter's return value for the same File.
+ *
+ * @param file the File to check
+ * @return true if the filter returns false
+ */
+ @Override
+ public boolean accept(final File file) {
+ return ! filter.accept(file);
+ }
+
+ /**
+ * Returns the logical NOT of the underlying filter's return value for the same arguments.
+ *
+ * @param file the File directory
+ * @param name the filename
+ * @return true if the filter returns false
+ */
+ @Override
+ public boolean accept(final File file, final String name) {
+ return ! filter.accept(file, name);
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ return super.toString() + "(" + filter.toString() + ")";
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/OrFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/OrFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..75332dec24cc1fc7da71bc07c413a841bc5cfabd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/OrFileFilter.java"
@@ -0,0 +1,162 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A {@link java.io.FileFilter} providing conditional OR logic across a list of
+ * file filters. This filter returns {@code true} if any filters in the
+ * list return {@code true}. Otherwise, it returns {@code false}.
+ * Checking of the file filter list stops when the first filter returns
+ * {@code true}.
+ *
+ * @since 1.0
+ * @version $Id: OrFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @see FileFilterUtils#or(IOFileFilter...)
+ */
+public class OrFileFilter
+ extends AbstractFileFilter
+ implements ConditionalFileFilter, Serializable {
+
+ private static final long serialVersionUID = 5767770777065432721L;
+ /** The list of file filters. */
+ private final List fileFilters;
+
+ /**
+ * Constructs a new instance of OrFileFilter.
+ *
+ * @since 1.1
+ */
+ public OrFileFilter() {
+ this.fileFilters = new ArrayList();
+ }
+
+ /**
+ * Constructs a new instance of OrFileFilter
+ * with the specified filters.
+ *
+ * @param fileFilters the file filters for this filter, copied, null ignored
+ * @since 1.1
+ */
+ public OrFileFilter(final List fileFilters) {
+ if (fileFilters == null) {
+ this.fileFilters = new ArrayList();
+ } else {
+ this.fileFilters = new ArrayList(fileFilters);
+ }
+ }
+
+ /**
+ * Constructs a new file filter that ORs the result of two other filters.
+ *
+ * @param filter1 the first filter, must not be null
+ * @param filter2 the second filter, must not be null
+ * @throws IllegalArgumentException if either filter is null
+ */
+ public OrFileFilter(final IOFileFilter filter1, final IOFileFilter filter2) {
+ if (filter1 == null || filter2 == null) {
+ throw new IllegalArgumentException("The filters must not be null");
+ }
+ this.fileFilters = new ArrayList(2);
+ addFileFilter(filter1);
+ addFileFilter(filter2);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addFileFilter(final IOFileFilter ioFileFilter) {
+ this.fileFilters.add(ioFileFilter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List getFileFilters() {
+ return Collections.unmodifiableList(this.fileFilters);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean removeFileFilter(final IOFileFilter ioFileFilter) {
+ return this.fileFilters.remove(ioFileFilter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setFileFilters(final List fileFilters) {
+ this.fileFilters.clear();
+ this.fileFilters.addAll(fileFilters);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean accept(final File file) {
+ for (final IOFileFilter fileFilter : fileFilters) {
+ if (fileFilter.accept(file)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean accept(final File file, final String name) {
+ for (final IOFileFilter fileFilter : fileFilters) {
+ if (fileFilter.accept(file, name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append(super.toString());
+ buffer.append("(");
+ if (fileFilters != null) {
+ for (int i = 0; i < fileFilters.size(); i++) {
+ if (i > 0) {
+ buffer.append(",");
+ }
+ final Object filter = fileFilters.get(i);
+ buffer.append(filter == null ? "null" : filter.toString());
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..22c386bb45f4e142fd9d4a470bdbe4998b8cbd28
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/PrefixFileFilter.java"
@@ -0,0 +1,197 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.commons.io.IOCase;
+
+/**
+ * Filters filenames for a certain prefix.
+ *
+ * For example, to print all files and directories in the
+ * current directory whose name starts with Test:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( new PrefixFileFilter("Test") );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @since 1.0
+ * @version $Id: PrefixFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @see FileFilterUtils#prefixFileFilter(String)
+ * @see FileFilterUtils#prefixFileFilter(String, IOCase)
+ */
+public class PrefixFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 8533897440809599867L;
+
+ /** The filename prefixes to search for */
+ private final String[] prefixes;
+
+ /** Whether the comparison is case sensitive. */
+ private final IOCase caseSensitivity;
+
+ /**
+ * Constructs a new Prefix file filter for a single prefix.
+ *
+ * @param prefix the prefix to allow, must not be null
+ * @throws IllegalArgumentException if the prefix is null
+ */
+ public PrefixFileFilter(final String prefix) {
+ this(prefix, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Constructs a new Prefix file filter for a single prefix
+ * specifying case-sensitivity.
+ *
+ * @param prefix the prefix to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the prefix is null
+ * @since 1.4
+ */
+ public PrefixFileFilter(final String prefix, final IOCase caseSensitivity) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("The prefix must not be null");
+ }
+ this.prefixes = new String[] {prefix};
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Constructs a new Prefix file filter for any of an array of prefixes.
+ *
+ * The array is not cloned, so could be changed after constructing the
+ * instance. This would be inadvisable however.
+ *
+ * @param prefixes the prefixes to allow, must not be null
+ * @throws IllegalArgumentException if the prefix array is null
+ */
+ public PrefixFileFilter(final String[] prefixes) {
+ this(prefixes, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Constructs a new Prefix file filter for any of an array of prefixes
+ * specifying case-sensitivity.
+ *
+ * @param prefixes the prefixes to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the prefix is null
+ * @since 1.4
+ */
+ public PrefixFileFilter(final String[] prefixes, final IOCase caseSensitivity) {
+ if (prefixes == null) {
+ throw new IllegalArgumentException("The array of prefixes must not be null");
+ }
+ this.prefixes = new String[prefixes.length];
+ System.arraycopy(prefixes, 0, this.prefixes, 0, prefixes.length);
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Constructs a new Prefix file filter for a list of prefixes.
+ *
+ * @param prefixes the prefixes to allow, must not be null
+ * @throws IllegalArgumentException if the prefix list is null
+ * @throws ClassCastException if the list does not contain Strings
+ */
+ public PrefixFileFilter(final List prefixes) {
+ this(prefixes, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Constructs a new Prefix file filter for a list of prefixes
+ * specifying case-sensitivity.
+ *
+ * @param prefixes the prefixes to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the prefix list is null
+ * @throws ClassCastException if the list does not contain Strings
+ * @since 1.4
+ */
+ public PrefixFileFilter(final List prefixes, final IOCase caseSensitivity) {
+ if (prefixes == null) {
+ throw new IllegalArgumentException("The list of prefixes must not be null");
+ }
+ this.prefixes = prefixes.toArray(new String[prefixes.size()]);
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Checks to see if the filename starts with the prefix.
+ *
+ * @param file the File to check
+ * @return true if the filename starts with one of our prefixes
+ */
+ @Override
+ public boolean accept(final File file) {
+ final String name = file.getName();
+ for (final String prefix : this.prefixes) {
+ if (caseSensitivity.checkStartsWith(name, prefix)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks to see if the filename starts with the prefix.
+ *
+ * @param file the File directory
+ * @param name the filename
+ * @return true if the filename starts with one of our prefixes
+ */
+ @Override
+ public boolean accept(final File file, final String name) {
+ for (final String prefix : prefixes) {
+ if (caseSensitivity.checkStartsWith(name, prefix)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append(super.toString());
+ buffer.append("(");
+ if (prefixes != null) {
+ for (int i = 0; i < prefixes.length; i++) {
+ if (i > 0) {
+ buffer.append(",");
+ }
+ buffer.append(prefixes[i]);
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..0d462c7ea5f2100b4a1a9a4041597db11d818d5e
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/RegexFileFilter.java"
@@ -0,0 +1,123 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.regex.Pattern;
+
+import org.apache.commons.io.IOCase;
+
+/**
+ * Filters files using supplied regular expression(s).
+ *
+ * See java.util.regex.Pattern for regex matching rules
+ *
+ *
+ *
+ * e.g.
+ *
+ * File dir = new File(".");
+ * FileFilter fileFilter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$");
+ * File[] files = dir.listFiles(fileFilter);
+ * for (int i = 0; i < files.length; i++) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @version $Id: RegexFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.4
+ */
+public class RegexFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 4269646126155225062L;
+ /** The regular expression pattern that will be used to match filenames */
+ private final Pattern pattern;
+
+ /**
+ * Construct a new regular expression filter.
+ *
+ * @param pattern regular string expression to match
+ * @throws IllegalArgumentException if the pattern is null
+ */
+ public RegexFileFilter(final String pattern) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("Pattern is missing");
+ }
+
+ this.pattern = Pattern.compile(pattern);
+ }
+
+ /**
+ * Construct a new regular expression filter with the specified flags case sensitivity.
+ *
+ * @param pattern regular string expression to match
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the pattern is null
+ */
+ public RegexFileFilter(final String pattern, final IOCase caseSensitivity) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("Pattern is missing");
+ }
+ int flags = 0;
+ if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) {
+ flags = Pattern.CASE_INSENSITIVE;
+ }
+ this.pattern = Pattern.compile(pattern, flags);
+ }
+
+ /**
+ * Construct a new regular expression filter with the specified flags.
+ *
+ * @param pattern regular string expression to match
+ * @param flags pattern flags - e.g. {@link Pattern#CASE_INSENSITIVE}
+ * @throws IllegalArgumentException if the pattern is null
+ */
+ public RegexFileFilter(final String pattern, final int flags) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("Pattern is missing");
+ }
+ this.pattern = Pattern.compile(pattern, flags);
+ }
+
+ /**
+ * Construct a new regular expression filter for a compiled regular expression
+ *
+ * @param pattern regular expression to match
+ * @throws IllegalArgumentException if the pattern is null
+ */
+ public RegexFileFilter(final Pattern pattern) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("Pattern is missing");
+ }
+
+ this.pattern = pattern;
+ }
+
+ /**
+ * Checks to see if the filename matches one of the regular expressions.
+ *
+ * @param dir the file directory (ignored)
+ * @param name the filename
+ * @return true if the filename matches one of the regular expressions
+ */
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return pattern.matcher(name).matches();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/SizeFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/SizeFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..1623e255e930139d0021d93d560ff4fe1776fda1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/SizeFileFilter.java"
@@ -0,0 +1,108 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * Filters files based on size, can filter either smaller files or
+ * files equal to or larger than a given threshold.
+ *
+ * For example, to print all files and directories in the
+ * current directory whose size is greater than 1 MB:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( new SizeFileFilter(1024 * 1024) );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @version $Id: SizeFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.2
+ * @see FileFilterUtils#sizeFileFilter(long)
+ * @see FileFilterUtils#sizeFileFilter(long, boolean)
+ * @see FileFilterUtils#sizeRangeFileFilter(long, long)
+ */
+public class SizeFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = 7388077430788600069L;
+ /** The size threshold. */
+ private final long size;
+ /** Whether the files accepted will be larger or smaller. */
+ private final boolean acceptLarger;
+
+ /**
+ * Constructs a new size file filter for files equal to or
+ * larger than a certain size.
+ *
+ * @param size the threshold size of the files
+ * @throws IllegalArgumentException if the size is negative
+ */
+ public SizeFileFilter(final long size) {
+ this(size, true);
+ }
+
+ /**
+ * Constructs a new size file filter for files based on a certain size
+ * threshold.
+ *
+ * @param size the threshold size of the files
+ * @param acceptLarger if true, files equal to or larger are accepted,
+ * otherwise smaller ones (but not equal to)
+ * @throws IllegalArgumentException if the size is negative
+ */
+ public SizeFileFilter(final long size, final boolean acceptLarger) {
+ if (size < 0) {
+ throw new IllegalArgumentException("The size must be non-negative");
+ }
+ this.size = size;
+ this.acceptLarger = acceptLarger;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks to see if the size of the file is favorable.
+ *
+ * If size equals threshold and smaller files are required,
+ * file IS NOT selected.
+ * If size equals threshold and larger files are required,
+ * file IS selected.
+ *
+ * @param file the File to check
+ * @return true if the filename matches
+ */
+ @Override
+ public boolean accept(final File file) {
+ final boolean smaller = file.length() < size;
+ return acceptLarger ? !smaller : smaller;
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ final String condition = acceptLarger ? ">=" : "<";
+ return super.toString() + "(" + condition + size + ")";
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..cd5a9d057afd43a182580eaa96093c00c412f4fd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java"
@@ -0,0 +1,198 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.commons.io.IOCase;
+
+/**
+ * Filters files based on the suffix (what the filename ends with).
+ * This is used in retrieving all the files of a particular type.
+ *
+ * For example, to retrieve and print all *.java files
+ * in the current directory:
+ *
+ *
+ * File dir = new File(".");
+ * String[] files = dir.list( new SuffixFileFilter(".java") );
+ * for (int i = 0; i < files.length; i++) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @since 1.0
+ * @version $Id: SuffixFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @see FileFilterUtils#suffixFileFilter(String)
+ * @see FileFilterUtils#suffixFileFilter(String, IOCase)
+ */
+public class SuffixFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = -3389157631240246157L;
+
+ /** The filename suffixes to search for */
+ private final String[] suffixes;
+
+ /** Whether the comparison is case sensitive. */
+ private final IOCase caseSensitivity;
+
+ /**
+ * Constructs a new Suffix file filter for a single extension.
+ *
+ * @param suffix the suffix to allow, must not be null
+ * @throws IllegalArgumentException if the suffix is null
+ */
+ public SuffixFileFilter(final String suffix) {
+ this(suffix, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Constructs a new Suffix file filter for a single extension
+ * specifying case-sensitivity.
+ *
+ * @param suffix the suffix to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the suffix is null
+ * @since 1.4
+ */
+ public SuffixFileFilter(final String suffix, final IOCase caseSensitivity) {
+ if (suffix == null) {
+ throw new IllegalArgumentException("The suffix must not be null");
+ }
+ this.suffixes = new String[] {suffix};
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Constructs a new Suffix file filter for an array of suffixs.
+ *
+ * The array is not cloned, so could be changed after constructing the
+ * instance. This would be inadvisable however.
+ *
+ * @param suffixes the suffixes to allow, must not be null
+ * @throws IllegalArgumentException if the suffix array is null
+ */
+ public SuffixFileFilter(final String[] suffixes) {
+ this(suffixes, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Constructs a new Suffix file filter for an array of suffixs
+ * specifying case-sensitivity.
+ *
+ * @param suffixes the suffixes to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the suffix array is null
+ * @since 1.4
+ */
+ public SuffixFileFilter(final String[] suffixes, final IOCase caseSensitivity) {
+ if (suffixes == null) {
+ throw new IllegalArgumentException("The array of suffixes must not be null");
+ }
+ this.suffixes = new String[suffixes.length];
+ System.arraycopy(suffixes, 0, this.suffixes, 0, suffixes.length);
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Constructs a new Suffix file filter for a list of suffixes.
+ *
+ * @param suffixes the suffixes to allow, must not be null
+ * @throws IllegalArgumentException if the suffix list is null
+ * @throws ClassCastException if the list does not contain Strings
+ */
+ public SuffixFileFilter(final List suffixes) {
+ this(suffixes, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Constructs a new Suffix file filter for a list of suffixes
+ * specifying case-sensitivity.
+ *
+ * @param suffixes the suffixes to allow, must not be null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the suffix list is null
+ * @throws ClassCastException if the list does not contain Strings
+ * @since 1.4
+ */
+ public SuffixFileFilter(final List suffixes, final IOCase caseSensitivity) {
+ if (suffixes == null) {
+ throw new IllegalArgumentException("The list of suffixes must not be null");
+ }
+ this.suffixes = suffixes.toArray(new String[suffixes.size()]);
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Checks to see if the filename ends with the suffix.
+ *
+ * @param file the File to check
+ * @return true if the filename ends with one of our suffixes
+ */
+ @Override
+ public boolean accept(final File file) {
+ final String name = file.getName();
+ for (final String suffix : this.suffixes) {
+ if (caseSensitivity.checkEndsWith(name, suffix)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks to see if the filename ends with the suffix.
+ *
+ * @param file the File directory
+ * @param name the filename
+ * @return true if the filename ends with one of our suffixes
+ */
+ @Override
+ public boolean accept(final File file, final String name) {
+ for (final String suffix : this.suffixes) {
+ if (caseSensitivity.checkEndsWith(name, suffix)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Provide a String representaion of this file filter.
+ *
+ * @return a String representaion
+ */
+ @Override
+ public String toString() {
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append(super.toString());
+ buffer.append("(");
+ if (suffixes != null) {
+ for (int i = 0; i < suffixes.length; i++) {
+ if (i > 0) {
+ buffer.append(",");
+ }
+ buffer.append(suffixes[i]);
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/TrueFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/TrueFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..61028605591f9f355f8884e8cb59b526dbcf0206
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/TrueFileFilter.java"
@@ -0,0 +1,72 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * A file filter that always returns true.
+ *
+ * @since 1.0
+ * @version $Id: TrueFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @see FileFilterUtils#trueFileFilter()
+ */
+public class TrueFileFilter implements IOFileFilter, Serializable {
+
+ private static final long serialVersionUID = 8782512160909720199L;
+ /**
+ * Singleton instance of true filter.
+ * @since 1.3
+ */
+ public static final IOFileFilter TRUE = new TrueFileFilter();
+ /**
+ * Singleton instance of true filter.
+ * Please use the identical TrueFileFilter.TRUE constant.
+ * The new name is more JDK 1.5 friendly as it doesn't clash with other
+ * values when using static imports.
+ */
+ public static final IOFileFilter INSTANCE = TRUE;
+
+ /**
+ * Restrictive constructor.
+ */
+ protected TrueFileFilter() {
+ }
+
+ /**
+ * Returns true.
+ *
+ * @param file the file to check (ignored)
+ * @return true
+ */
+ public boolean accept(final File file) {
+ return true;
+ }
+
+ /**
+ * Returns true.
+ *
+ * @param dir the directory to check (ignored)
+ * @param name the filename (ignored)
+ * @return true
+ */
+ public boolean accept(final File dir, final String name) {
+ return true;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..02a5f23dc6b9cbde2ec9a4c9f9470cf6bcfd65ba
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/WildcardFileFilter.java"
@@ -0,0 +1,196 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOCase;
+
+/**
+ * Filters files using the supplied wildcards.
+ *
+ * This filter selects files and directories based on one or more wildcards.
+ * Testing is case-sensitive by default, but this can be configured.
+ *
+ * The wildcard matcher uses the characters '?' and '*' to represent a
+ * single or multiple wildcard characters.
+ * This is the same as often found on Dos/Unix command lines.
+ * The check is case-sensitive by default.
+ * See {@link FilenameUtils#wildcardMatchOnSystem} for more information.
+ *
+ * For example:
+ *
+ * File dir = new File(".");
+ * FileFilter fileFilter = new WildcardFileFilter("*test*.java~*~");
+ * File[] files = dir.listFiles(fileFilter);
+ * for (int i = 0; i < files.length; i++) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @version $Id: WildcardFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.3
+ */
+public class WildcardFileFilter extends AbstractFileFilter implements Serializable {
+
+ private static final long serialVersionUID = -7426486598995782105L;
+ /** The wildcards that will be used to match filenames. */
+ private final String[] wildcards;
+ /** Whether the comparison is case sensitive. */
+ private final IOCase caseSensitivity;
+
+ /**
+ * Construct a new case-sensitive wildcard filter for a single wildcard.
+ *
+ * @param wildcard the wildcard to match
+ * @throws IllegalArgumentException if the pattern is null
+ */
+ public WildcardFileFilter(final String wildcard) {
+ this(wildcard, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Construct a new wildcard filter for a single wildcard specifying case-sensitivity.
+ *
+ * @param wildcard the wildcard to match, not null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the pattern is null
+ */
+ public WildcardFileFilter(final String wildcard, final IOCase caseSensitivity) {
+ if (wildcard == null) {
+ throw new IllegalArgumentException("The wildcard must not be null");
+ }
+ this.wildcards = new String[] { wildcard };
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Construct a new case-sensitive wildcard filter for an array of wildcards.
+ *
+ *
+ * @param wildcards the array of wildcards to match
+ * @throws IllegalArgumentException if the pattern array is null
+ */
+ public WildcardFileFilter(final String[] wildcards) {
+ this(wildcards, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Construct a new wildcard filter for an array of wildcards specifying case-sensitivity.
+ *
+ *
+ * @param wildcards the array of wildcards to match, not null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the pattern array is null
+ */
+ public WildcardFileFilter(final String[] wildcards, final IOCase caseSensitivity) {
+ if (wildcards == null) {
+ throw new IllegalArgumentException("The wildcard array must not be null");
+ }
+ this.wildcards = new String[wildcards.length];
+ System.arraycopy(wildcards, 0, this.wildcards, 0, wildcards.length);
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ /**
+ * Construct a new case-sensitive wildcard filter for a list of wildcards.
+ *
+ * @param wildcards the list of wildcards to match, not null
+ * @throws IllegalArgumentException if the pattern list is null
+ * @throws ClassCastException if the list does not contain Strings
+ */
+ public WildcardFileFilter(final List wildcards) {
+ this(wildcards, IOCase.SENSITIVE);
+ }
+
+ /**
+ * Construct a new wildcard filter for a list of wildcards specifying case-sensitivity.
+ *
+ * @param wildcards the list of wildcards to match, not null
+ * @param caseSensitivity how to handle case sensitivity, null means case-sensitive
+ * @throws IllegalArgumentException if the pattern list is null
+ * @throws ClassCastException if the list does not contain Strings
+ */
+ public WildcardFileFilter(final List wildcards, final IOCase caseSensitivity) {
+ if (wildcards == null) {
+ throw new IllegalArgumentException("The wildcard list must not be null");
+ }
+ this.wildcards = wildcards.toArray(new String[wildcards.size()]);
+ this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks to see if the filename matches one of the wildcards.
+ *
+ * @param dir the file directory (ignored)
+ * @param name the filename
+ * @return true if the filename matches one of the wildcards
+ */
+ @Override
+ public boolean accept(final File dir, final String name) {
+ for (final String wildcard : wildcards) {
+ if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks to see if the filename matches one of the wildcards.
+ *
+ * @param file the file to check
+ * @return true if the filename matches one of the wildcards
+ */
+ @Override
+ public boolean accept(final File file) {
+ final String name = file.getName();
+ for (final String wildcard : wildcards) {
+ if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Provide a String representation of this file filter.
+ *
+ * @return a String representation
+ */
+ @Override
+ public String toString() {
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append(super.toString());
+ buffer.append("(");
+ if (wildcards != null) {
+ for (int i = 0; i < wildcards.length; i++) {
+ if (i > 0) {
+ buffer.append(",");
+ }
+ buffer.append(wildcards[i]);
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..e1c38d3518c57919ea5dd42f9c57ef54e3dd4815
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/WildcardFilter.java"
@@ -0,0 +1,144 @@
+/*
+ * 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 org.apache.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.commons.io.FilenameUtils;
+
+/**
+ * Filters files using the supplied wildcards.
+ *
+ * This filter selects files, but not directories, based on one or more wildcards
+ * and using case-sensitive comparison.
+ *
+ * The wildcard matcher uses the characters '?' and '*' to represent a
+ * single or multiple wildcard characters.
+ * This is the same as often found on Dos/Unix command lines.
+ * The extension check is case-sensitive.
+ * See {@link FilenameUtils#wildcardMatch(String, String)} for more information.
+ *
+ * For example:
+ *
+ * File dir = new File(".");
+ * FileFilter fileFilter = new WildcardFilter("*test*.java~*~");
+ * File[] files = dir.listFiles(fileFilter);
+ * for (int i = 0; i < files.length; i++) {
+ * System.out.println(files[i]);
+ * }
+ *
+ *
+ * @version $Id: WildcardFilter.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.1
+ * @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 {
+
+ private static final long serialVersionUID = -5037645902506953517L;
+ /** The wildcards that will be used to match filenames. */
+ private final String[] wildcards;
+
+ /**
+ * Construct a new case-sensitive wildcard filter for a single wildcard.
+ *
+ * @param wildcard the wildcard to match
+ * @throws IllegalArgumentException if the pattern is null
+ */
+ public WildcardFilter(final String wildcard) {
+ if (wildcard == null) {
+ throw new IllegalArgumentException("The wildcard must not be null");
+ }
+ this.wildcards = new String[] { wildcard };
+ }
+
+ /**
+ * Construct a new case-sensitive wildcard filter for an array of wildcards.
+ *
+ * @param wildcards the array of wildcards to match
+ * @throws IllegalArgumentException if the pattern array is null
+ */
+ public WildcardFilter(final String[] wildcards) {
+ if (wildcards == null) {
+ throw new IllegalArgumentException("The wildcard array must not be null");
+ }
+ this.wildcards = new String[wildcards.length];
+ System.arraycopy(wildcards, 0, this.wildcards, 0, wildcards.length);
+ }
+
+ /**
+ * Construct a new case-sensitive wildcard filter for a list of wildcards.
+ *
+ * @param wildcards the list of wildcards to match
+ * @throws IllegalArgumentException if the pattern list is null
+ * @throws ClassCastException if the list does not contain Strings
+ */
+ public WildcardFilter(final List wildcards) {
+ if (wildcards == null) {
+ throw new IllegalArgumentException("The wildcard list must not be null");
+ }
+ this.wildcards = wildcards.toArray(new String[wildcards.size()]);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks to see if the filename matches one of the wildcards.
+ *
+ * @param dir the file directory
+ * @param name the filename
+ * @return true if the filename matches one of the wildcards
+ */
+ @Override
+ public boolean accept(final File dir, final String name) {
+ if (dir != null && new File(dir, name).isDirectory()) {
+ return false;
+ }
+
+ for (final String wildcard : wildcards) {
+ if (FilenameUtils.wildcardMatch(name, wildcard)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Checks to see if the filename matches one of the wildcards.
+ *
+ * @param file the file to check
+ * @return true if the filename matches one of the wildcards
+ */
+ @Override
+ public boolean accept(final File file) {
+ if (file.isDirectory()) {
+ return false;
+ }
+
+ for (final String wildcard : wildcards) {
+ if (FilenameUtils.wildcardMatch(file.getName(), wildcard)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/package.html" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/package.html"
new file mode 100644
index 0000000000000000000000000000000000000000..e495e9521399b04ab0241dc8eb2675a33a2bf37c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/filefilter/package.html"
@@ -0,0 +1,143 @@
+
+
+
+
+This package defines an interface (IOFileFilter) that combines both
+{@link java.io.FileFilter} and {@link java.io.FilenameFilter}. Besides
+that the package offers a series of ready-to-use implementations of the
+IOFileFilter interface including implementation that allow you to combine
+other such filters.
+These filter can be used to list files or in {@link java.awt.FileDialog},
+for example.
+
+There are a number of 'primitive' filters:
+
+
+
+And there are five 'boolean' filters:
+
+
+
+These boolean FilenameFilters can be nested, to allow arbitrary expressions.
+For example, here is how one could print all non-directory files in the
+current directory, starting with "A", and ending in ".java" or ".class":
+
+
+ File dir = new File(".");
+ String[] files = dir.list(
+ new AndFileFilter(
+ new AndFileFilter(
+ new PrefixFileFilter("A"),
+ new OrFileFilter(
+ new SuffixFileFilter(".class"),
+ new SuffixFileFilter(".java")
+ )
+ ),
+ new NotFileFilter(
+ new DirectoryFileFilter()
+ )
+ )
+ );
+ for ( int i=0; i<files.length; i++ ) {
+ System.out.println(files[i]);
+ }
+
+
+This package also contains a utility class:
+FileFilterUtils . It allows you to use all
+file filters without having to put them in the import section. Here's how the
+above example will look using FileFilterUtils:
+
+ File dir = new File(".");
+ String[] files = dir.list(
+ FileFilterUtils.andFileFilter(
+ FileFilterUtils.andFileFilter(
+ FileFilterUtils.prefixFileFilter("A"),
+ FileFilterUtils.orFileFilter(
+ FileFilterUtils.suffixFileFilter(".class"),
+ FileFilterUtils.suffixFileFilter(".java")
+ )
+ ),
+ FileFilterUtils.notFileFilter(
+ FileFilterUtils.directoryFileFilter()
+ )
+ )
+ );
+ for ( int i=0; i<files.length; i++ ) {
+ System.out.println(files[i]);
+ }
+
+There are a few other goodies in that class so please have a look at the
+documentation in detail.
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..660cae3abbb03a9a25a6d27f1e44c22ef85117a1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java"
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Proxy stream that closes and discards the underlying stream as soon as the
+ * end of input has been reached or when the stream is explicitly closed.
+ * Not even a reference to the underlying stream is kept after it has been
+ * closed, so any allocated in-memory buffers can be freed even if the
+ * client application still keeps a reference to the proxy stream.
+ *
+ * This class is typically used to release any resources related to an open
+ * stream as soon as possible even if the client application (by not explicitly
+ * 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 {
+
+ /**
+ * Creates an automatically closing proxy for the given input stream.
+ *
+ * @param in underlying input stream
+ */
+ public AutoCloseInputStream(final InputStream in) {
+ super(in);
+ }
+
+ /**
+ * Closes the underlying input stream and replaces the reference to it
+ * with a {@link ClosedInputStream} instance.
+ *
+ * This method is automatically called by the read methods when the end
+ * of input has been reached.
+ *
+ * Note that it is safe to call this method any number of times. The original
+ * underlying input stream is closed and discarded only once when this
+ * method is first called.
+ *
+ * @throws IOException if the underlying input stream can not be closed
+ */
+ @Override
+ public void close() throws IOException {
+ in.close();
+ in = new ClosedInputStream();
+ }
+
+ /**
+ * Automatically closes the stream if the end of stream was reached.
+ *
+ * @param n number of bytes read, or -1 if no more bytes are available
+ * @throws IOException if the stream could not be closed
+ * @since 2.0
+ */
+ @Override
+ protected void afterRead(final int n) throws IOException {
+ if (n == EOF) {
+ close();
+ }
+ }
+
+ /**
+ * Ensures that the stream is closed before it gets garbage-collected.
+ * As mentioned in {@link #close()}, this is a no-op if the stream has
+ * already been closed.
+ * @throws Throwable if an error occurs
+ */
+ @Override
+ protected void finalize() throws Throwable {
+ close();
+ super.finalize();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BOMInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BOMInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..6aef06f90a5b20d3032449a4517c10841e4e792c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BOMInputStream.java"
@@ -0,0 +1,408 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.commons.io.ByteOrderMark;
+
+/**
+ * This class is used to wrap a stream that includes an encoded {@link ByteOrderMark} as its first bytes.
+ *
+ * This class detects these bytes and, if required, can automatically skip them and return the subsequent byte as the
+ * first byte in the stream.
+ *
+ * The {@link ByteOrderMark} implementation has the following pre-defined BOMs:
+ *
+ * UTF-8 - {@link ByteOrderMark#UTF_8}
+ * UTF-16BE - {@link ByteOrderMark#UTF_16LE}
+ * UTF-16LE - {@link ByteOrderMark#UTF_16BE}
+ * UTF-32BE - {@link ByteOrderMark#UTF_32LE}
+ * UTF-32LE - {@link ByteOrderMark#UTF_32BE}
+ *
+ *
+ *
+ * Example 1 - Detect and exclude a UTF-8 BOM
+ *
+ *
+ * BOMInputStream bomIn = new BOMInputStream(in);
+ * if (bomIn.hasBOM()) {
+ * // has a UTF-8 BOM
+ * }
+ *
+ *
+ * Example 2 - Detect a UTF-8 BOM (but don't exclude it)
+ *
+ *
+ * boolean include = true;
+ * BOMInputStream bomIn = new BOMInputStream(in, include);
+ * if (bomIn.hasBOM()) {
+ * // has a UTF-8 BOM
+ * }
+ *
+ *
+ * Example 3 - Detect Multiple BOMs
+ *
+ *
+ * BOMInputStream bomIn = new BOMInputStream(in,
+ * ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE,
+ * ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE
+ * );
+ * if (bomIn.hasBOM() == false) {
+ * // No BOM found
+ * } else if (bomIn.hasBOM(ByteOrderMark.UTF_16LE)) {
+ * // has a UTF-16LE BOM
+ * } else if (bomIn.hasBOM(ByteOrderMark.UTF_16BE)) {
+ * // has a UTF-16BE BOM
+ * } else if (bomIn.hasBOM(ByteOrderMark.UTF_32LE)) {
+ * // has a UTF-32LE BOM
+ * } else if (bomIn.hasBOM(ByteOrderMark.UTF_32BE)) {
+ * // has a UTF-32BE BOM
+ * }
+ *
+ *
+ * @see org.apache.commons.io.ByteOrderMark
+ * @see Wikipedia - Byte Order Mark
+ * @version $Id: BOMInputStream.java 1686527 2015-06-20 06:31:39Z krosenvold $
+ * @since 2.0
+ */
+public class BOMInputStream extends ProxyInputStream {
+ private final boolean include;
+ /**
+ * BOMs are sorted from longest to shortest.
+ */
+ private final List boms;
+ private ByteOrderMark byteOrderMark;
+ private int[] firstBytes;
+ private int fbLength;
+ private int fbIndex;
+ private int markFbIndex;
+ private boolean markedAtStart;
+
+ /**
+ * Constructs a new BOM InputStream that excludes a {@link ByteOrderMark#UTF_8} BOM.
+ *
+ * @param delegate
+ * the InputStream to delegate to
+ */
+ public BOMInputStream(final InputStream delegate) {
+ this(delegate, false, ByteOrderMark.UTF_8);
+ }
+
+ /**
+ * 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
+ * true to include the UTF-8 BOM or false to exclude it
+ */
+ public BOMInputStream(final InputStream delegate, final boolean include) {
+ this(delegate, include, ByteOrderMark.UTF_8);
+ }
+
+ /**
+ * Constructs a new BOM InputStream that excludes the specified BOMs.
+ *
+ * @param delegate
+ * the InputStream to delegate to
+ * @param boms
+ * The BOMs to detect and exclude
+ */
+ public BOMInputStream(final InputStream delegate, final ByteOrderMark... boms) {
+ this(delegate, false, boms);
+ }
+
+ /**
+ * Compares ByteOrderMark objects in descending length order.
+ */
+ private static final Comparator ByteOrderMarkLengthComparator = new Comparator() {
+
+ public int compare(final ByteOrderMark bom1, final ByteOrderMark bom2) {
+ final int len1 = bom1.length();
+ final int len2 = bom2.length();
+ if (len1 > len2) {
+ return EOF;
+ }
+ if (len2 > len1) {
+ return 1;
+ }
+ return 0;
+ }
+ };
+
+ /**
+ * Constructs a new BOM InputStream that detects the specified BOMs and optionally includes them.
+ *
+ * @param delegate
+ * the InputStream to delegate to
+ * @param include
+ * true to include the specified BOMs or false to exclude them
+ * @param boms
+ * The BOMs to detect and optionally exclude
+ */
+ public BOMInputStream(final InputStream delegate, final boolean include, final ByteOrderMark... boms) {
+ super(delegate);
+ if (boms == null || boms.length == 0) {
+ throw new IllegalArgumentException("No BOMs specified");
+ }
+ this.include = include;
+ // Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes.
+ 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
+ */
+ public boolean hasBOM() throws IOException {
+ return getBOM() != null;
+ }
+
+ /**
+ * 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
+ * @throws IllegalArgumentException
+ * if the BOM is not one the stream is configured to detect
+ * @throws IOException
+ * if an error reading the first bytes of the stream occurs
+ */
+ public boolean hasBOM(final ByteOrderMark bom) throws IOException {
+ if (!boms.contains(bom)) {
+ throw new IllegalArgumentException("Stream not configure to detect " + 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
+ */
+ public ByteOrderMark getBOM() throws IOException {
+ if (firstBytes == null) {
+ fbLength = 0;
+ // BOMs are sorted from longest to shortest
+ final int maxBomSize = boms.get(0).length();
+ firstBytes = new int[maxBomSize];
+ // Read first maxBomSize bytes
+ for (int i = 0; i < firstBytes.length; i++) {
+ firstBytes[i] = in.read();
+ fbLength++;
+ if (firstBytes[i] < 0) {
+ break;
+ }
+ }
+ // match BOM in firstBytes
+ byteOrderMark = find();
+ if (byteOrderMark != null) {
+ if (!include) {
+ if (byteOrderMark.length() < firstBytes.length) {
+ fbIndex = byteOrderMark.length();
+ } else {
+ fbLength = 0;
+ }
+ }
+ }
+ }
+ return byteOrderMark;
+ }
+
+ /**
+ * 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();
+ return byteOrderMark == null ? null : byteOrderMark.getCharsetName();
+ }
+
+ /**
+ * This method reads and either preserves or skips the first bytes in the stream. It behaves like the single-byte
+ * read() method, either returning a valid byte or -1 to indicate that the initial bytes have been
+ * processed already.
+ *
+ * @return the byte read (excluding BOM) or -1 if the end of stream
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ private int readFirstBytes() throws IOException {
+ getBOM();
+ return fbIndex < fbLength ? firstBytes[fbIndex++] : EOF;
+ }
+
+ /**
+ * Find a BOM with the specified bytes.
+ *
+ * @return The matched BOM or null if none matched
+ */
+ private ByteOrderMark find() {
+ for (final ByteOrderMark bom : boms) {
+ if (matches(bom)) {
+ return bom;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Check if the bytes match a BOM.
+ *
+ * @param bom
+ * The BOM
+ * @return true if the bytes match the bom, otherwise false
+ */
+ private boolean matches(final ByteOrderMark bom) {
+ // if (bom.length() != fbLength) {
+ // return false;
+ // }
+ // firstBytes may be bigger than the BOM bytes
+ for (int i = 0; i < bom.length(); i++) {
+ if (bom.get(i) != firstBytes[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // ----------------------------------------------------------------------------
+ // Implementation of InputStream
+ // ----------------------------------------------------------------------------
+
+ /**
+ * Invokes the delegate's read() method, detecting and optionally skipping BOM.
+ *
+ * @return the byte read (excluding BOM) or -1 if the end of stream
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ @Override
+ public int read() throws IOException {
+ final int b = readFirstBytes();
+ return b >= 0 ? b : in.read();
+ }
+
+ /**
+ * Invokes the delegate's read(byte[], int, int) method, detecting and optionally skipping BOM.
+ *
+ * @param buf
+ * the buffer to read the bytes into
+ * @param off
+ * The start offset
+ * @param len
+ * The number of bytes to read (excluding BOM)
+ * @return the number of bytes read or -1 if the end of stream
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ @Override
+ public int read(final byte[] buf, int off, int len) throws IOException {
+ int firstCount = 0;
+ int b = 0;
+ while (len > 0 && b >= 0) {
+ b = readFirstBytes();
+ if (b >= 0) {
+ buf[off++] = (byte) (b & 0xFF);
+ len--;
+ firstCount++;
+ }
+ }
+ final int secondCount = in.read(buf, off, len);
+ return secondCount < 0 ? firstCount > 0 ? firstCount : EOF : firstCount + secondCount;
+ }
+
+ /**
+ * Invokes the delegate's read(byte[]) method, detecting and optionally skipping BOM.
+ *
+ * @param buf
+ * the buffer to read the bytes into
+ * @return the number of bytes read (excluding BOM) or -1 if the end of stream
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ @Override
+ public int read(final byte[] buf) throws IOException {
+ return read(buf, 0, buf.length);
+ }
+
+ /**
+ * Invokes the delegate's mark(int) method.
+ *
+ * @param readlimit
+ * read ahead limit
+ */
+ @Override
+ public synchronized void mark(final int readlimit) {
+ markFbIndex = fbIndex;
+ markedAtStart = firstBytes == null;
+ in.mark(readlimit);
+ }
+
+ /**
+ * Invokes the delegate's reset() method.
+ *
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ @Override
+ public synchronized void reset() throws IOException {
+ fbIndex = markFbIndex;
+ if (markedAtStart) {
+ firstBytes = null;
+ }
+
+ in.reset();
+ }
+
+ /**
+ * Invokes the delegate's skip(long) method, detecting and optionallyskipping BOM.
+ *
+ * @param n
+ * the number of bytes to skip
+ * @return the number of bytes to skipped or -1 if the end of stream
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ @Override
+ public long skip(long n) throws IOException {
+ int skipped = 0;
+ while ((n > skipped) && (readFirstBytes() >= 0)) {
+ skipped++;
+ }
+ return in.skip(n - skipped) + skipped;
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BoundedInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BoundedInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ba7a18468a4e29d4bc5ff5c1c828fc7081777bf7
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BoundedInputStream.java"
@@ -0,0 +1,232 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * This is a stream that will only supply bytes up to a certain length - if its
+ * position goes above that, it will stop.
+ *
+ * This is useful to wrap ServletInputStreams. The ServletInputStream will block
+ * if you try to read content from it that isn't there, because it doesn't know
+ * whether the content hasn't arrived yet or whether the content has finished.
+ * So, one of these, initialized with the Content-length sent in the
+ * 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 {
+
+ /** the wrapped input stream */
+ private final InputStream in;
+
+ /** the max length to provide */
+ private final long max;
+
+ /** the number of bytes already returned */
+ private long pos = 0;
+
+ /** the marked position */
+ private long mark = EOF;
+
+ /** flag if close shoud be propagated */
+ private boolean propagateClose = true;
+
+ /**
+ * Creates a new BoundedInputStream that wraps the given input
+ * stream and limits it to a certain size.
+ *
+ * @param in The wrapped input stream
+ * @param size The maximum number of bytes to return
+ */
+ public BoundedInputStream(final InputStream in, final long size) {
+ // Some badly designed methods - eg the servlet API - overload length
+ // such that "-1" means stream finished
+ this.max = size;
+ this.in = in;
+ }
+
+ /**
+ * Creates a new BoundedInputStream that wraps the given input
+ * stream and is unlimited.
+ *
+ * @param in The wrapped input stream
+ */
+ public BoundedInputStream(final InputStream in) {
+ this(in, EOF);
+ }
+
+ /**
+ * Invokes the delegate's read() method if
+ * the current position is less than the limit.
+ * @return the byte read or -1 if the end of stream or
+ * the limit has been reached.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read() throws IOException {
+ if (max >= 0 && pos >= max) {
+ return EOF;
+ }
+ final int result = in.read();
+ pos++;
+ return result;
+ }
+
+ /**
+ * Invokes the delegate's read(byte[]) method.
+ * @param b the buffer to read the bytes into
+ * @return the number of bytes read or -1 if the end of stream or
+ * the limit has been reached.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final byte[] b) throws IOException {
+ return this.read(b, 0, b.length);
+ }
+
+ /**
+ * Invokes the delegate's read(byte[], int, int) method.
+ * @param b the buffer to read the bytes into
+ * @param off The start offset
+ * @param len The number of bytes to read
+ * @return the number of bytes read or -1 if the end of stream or
+ * the limit has been reached.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final byte[] b, final int off, final int len) throws IOException {
+ if (max>=0 && pos>=max) {
+ return EOF;
+ }
+ final long maxRead = max>=0 ? Math.min(len, max-pos) : len;
+ final int bytesRead = in.read(b, off, (int)maxRead);
+
+ if (bytesRead==EOF) {
+ return EOF;
+ }
+
+ pos+=bytesRead;
+ return bytesRead;
+ }
+
+ /**
+ * Invokes the delegate's skip(long) method.
+ * @param n the number of bytes to skip
+ * @return the actual number of bytes skipped
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public long skip(final long n) throws IOException {
+ final long toSkip = max>=0 ? Math.min(n, max-pos) : n;
+ final long skippedBytes = in.skip(toSkip);
+ pos+=skippedBytes;
+ return skippedBytes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int available() throws IOException {
+ if (max>=0 && pos>=max) {
+ return 0;
+ }
+ return in.available();
+ }
+
+ /**
+ * Invokes the delegate's toString() method.
+ * @return the delegate's toString()
+ */
+ @Override
+ public String toString() {
+ return in.toString();
+ }
+
+ /**
+ * Invokes the delegate's close() method
+ * if {@link #isPropagateClose()} is {@code true}.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ if (propagateClose) {
+ in.close();
+ }
+ }
+
+ /**
+ * Invokes the delegate's reset() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public synchronized void reset() throws IOException {
+ in.reset();
+ pos = mark;
+ }
+
+ /**
+ * Invokes the delegate's mark(int) method.
+ * @param readlimit read ahead limit
+ */
+ @Override
+ public synchronized void mark(final int readlimit) {
+ in.mark(readlimit);
+ mark = pos;
+ }
+
+ /**
+ * Invokes the delegate's markSupported() method.
+ * @return true if mark is supported, otherwise false
+ */
+ @Override
+ public boolean markSupported() {
+ return in.markSupported();
+ }
+
+ /**
+ * Indicates whether the {@link #close()} method
+ * should propagate to the underling {@link InputStream}.
+ *
+ * @return {@code true} if calling {@link #close()}
+ * propagates to the close() method of the
+ * underlying stream or {@code false} if it does not.
+ */
+ public boolean isPropagateClose() {
+ return propagateClose;
+ }
+
+ /**
+ * Set whether the {@link #close()} method
+ * should propagate to the underling {@link InputStream}.
+ *
+ * @param propagateClose {@code true} if calling
+ * {@link #close()} propagates to the close()
+ * method of the underlying stream or
+ * {@code false} if it does not.
+ */
+ public void setPropagateClose(final boolean propagateClose) {
+ this.propagateClose = propagateClose;
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BoundedReader.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BoundedReader.java"
new file mode 100644
index 0000000000000000000000000000000000000000..a20b51c18a4cc3873b47fcb63ac746e8c603bb6b
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BoundedReader.java"
@@ -0,0 +1,148 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * A reader that imposes a limit to the number of characters that can be read from
+ * an underlying reader, returning eof when this limit is reached -regardless of state of
+ * underlying reader.
+ *
+ *
+ * One use case is to avoid overrunning the readAheadLimit supplied to
+ * java.io.Reader#mark(int), since reading too many characters removes the
+ * ability to do a successful reset.
+ *
+ *
+ * @since 2.5
+ */
+public class BoundedReader
+ extends Reader
+{
+
+ private static final int INVALID = -1;
+
+ private final Reader target;
+
+ private int charsRead = 0;
+
+ private int markedAt = INVALID;
+
+ private int readAheadLimit; // Internally, this value will never exceed the allowed size
+
+ private final int maxCharsFromTargetReader;
+
+ /**
+ * Constructs a bounded reader
+ *
+ * @param target The target stream that will be used
+ * @param maxCharsFromTargetReader The maximum number of characters that can be read from target
+ * @throws IOException if mark fails
+ */
+ public BoundedReader( Reader target, int maxCharsFromTargetReader ) throws IOException {
+ this.target = target;
+ this.maxCharsFromTargetReader = maxCharsFromTargetReader;
+ }
+
+ /**
+ * Closes the target
+ *
+ * @throws IOException If an I/O error occurs while calling the underlying reader's close method
+ */
+ @Override
+ public void close() throws IOException {
+ target.close();
+ }
+
+ /**
+ * 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
+ */
+ @Override
+ public void reset() throws IOException {
+ charsRead = markedAt;
+ target.reset();
+ }
+
+ /**
+ * 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().
+ * Note that this parameter is not validated with respect to
+ * maxCharsFromTargetReader. There is no way to pass
+ * past maxCharsFromTargetReader, even if this value is
+ * greater.
+ *
+ * @throws IOException If an I/O error occurs while calling the underlying reader's mark method
+ */
+ @Override
+ public void mark( int readAheadLimit ) throws IOException {
+ this.readAheadLimit = readAheadLimit - charsRead;
+
+ markedAt = charsRead;
+
+ target.mark( readAheadLimit );
+ }
+
+ /**
+ * 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
+ */
+ @Override
+ public int read() throws IOException {
+
+ if ( charsRead >= maxCharsFromTargetReader ) {
+ return -1;
+ }
+
+ if ( markedAt >= 0 && ( charsRead - markedAt ) >= readAheadLimit ) {
+ return -1;
+ }
+ charsRead++;
+ return target.read();
+ }
+
+ /**
+ * 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
+ */
+ @Override
+ 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;
+ }
+ cbuf[off + i] = (char) c;
+ }
+ return len;
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BrokenInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BrokenInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..a8b0fe9073fbfe6fa42a97695c265e367723c897
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/BrokenInputStream.java"
@@ -0,0 +1,108 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Broken input stream. This stream always throws an {@link IOException} from
+ * all the {@link InputStream} methods where the exception is declared.
+ *
+ * This class is mostly useful for testing error handling in code that uses an
+ * input stream.
+ *
+ * @since 2.0
+ */
+public class BrokenInputStream extends InputStream {
+
+ /**
+ * The exception that is thrown by all methods of this class.
+ */
+ private final IOException exception;
+
+ /**
+ * Creates a new stream that always throws the given exception.
+ *
+ * @param exception the exception to be thrown
+ */
+ public BrokenInputStream(final IOException exception) {
+ this.exception = exception;
+ }
+
+ /**
+ * Creates a new stream that always throws an {@link IOException}
+ */
+ public BrokenInputStream() {
+ this(new IOException("Broken input stream"));
+ }
+
+ /**
+ * Throws the configured exception.
+ *
+ * @return nothing
+ * @throws IOException always thrown
+ */
+ @Override
+ public int read() throws IOException {
+ throw exception;
+ }
+
+ /**
+ * Throws the configured exception.
+ *
+ * @return nothing
+ * @throws IOException always thrown
+ */
+ @Override
+ public int available() throws IOException {
+ throw exception;
+ }
+
+ /**
+ * Throws the configured exception.
+ *
+ * @param n ignored
+ * @return nothing
+ * @throws IOException always thrown
+ */
+ @Override
+ public long skip(final long n) throws IOException {
+ throw exception;
+ }
+
+ /**
+ * Throws the configured exception.
+ *
+ * @throws IOException always thrown
+ */
+ @Override
+ public synchronized void reset() throws IOException {
+ throw exception;
+ }
+
+ /**
+ * Throws the configured exception.
+ *
+ * @throws IOException always thrown
+ */
+ @Override
+ public void close() throws IOException {
+ throw exception;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..c7cdd558dd308fd96626c422dbfa6c9b7db65a9f
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java"
@@ -0,0 +1,269 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+
+/**
+ * {@link InputStream} implementation that can read from String, StringBuffer,
+ * StringBuilder or CharBuffer.
+ *
+ * Note: Supports {@link #mark(int)} and {@link #reset()}.
+ *
+ * @since 2.2
+ */
+public class CharSequenceInputStream extends InputStream {
+
+ private static final int BUFFER_SIZE = 2048;
+
+ private static final int NO_MARK = -1;
+
+ private final CharsetEncoder encoder;
+ private final CharBuffer cbuf;
+ private final ByteBuffer bbuf;
+
+ private int mark_cbuf; // position in cbuf
+ private int mark_bbuf; // position in bbuf
+
+ /**
+ * Constructor.
+ *
+ * @param cs the input character sequence
+ * @param charset the character set name to use
+ * @param bufferSize the buffer size to use.
+ * @throws IllegalArgumentException if the buffer is not large enough to hold a complete character
+ */
+ public CharSequenceInputStream(final CharSequence cs, final Charset charset, final int bufferSize) {
+ super();
+ this.encoder = charset.newEncoder()
+ .onMalformedInput(CodingErrorAction.REPLACE)
+ .onUnmappableCharacter(CodingErrorAction.REPLACE);
+ // Ensure that buffer is long enough to hold a complete character
+ final float maxBytesPerChar = encoder.maxBytesPerChar();
+ if (bufferSize < maxBytesPerChar) {
+ throw new IllegalArgumentException("Buffer size " + bufferSize + " is less than maxBytesPerChar " +
+ maxBytesPerChar);
+ }
+ this.bbuf = ByteBuffer.allocate(bufferSize);
+ this.bbuf.flip();
+ this.cbuf = CharBuffer.wrap(cs);
+ this.mark_cbuf = NO_MARK;
+ this.mark_bbuf = NO_MARK;
+ }
+
+ /**
+ * Constructor, calls {@link #CharSequenceInputStream(CharSequence, Charset, int)}.
+ *
+ * @param cs the input character sequence
+ * @param charset the character set name to use
+ * @param bufferSize the buffer size to use.
+ * @throws IllegalArgumentException if the buffer is not large enough to hold a complete character
+ */
+ public CharSequenceInputStream(final CharSequence cs, final String charset, final int bufferSize) {
+ this(cs, Charset.forName(charset), bufferSize);
+ }
+
+ /**
+ * Constructor, calls {@link #CharSequenceInputStream(CharSequence, Charset, int)}
+ * with a buffer size of 2048.
+ *
+ * @param cs the input character sequence
+ * @param charset the character set name to use
+ * @throws IllegalArgumentException if the buffer is not large enough to hold a complete character
+ */
+ public CharSequenceInputStream(final CharSequence cs, final Charset charset) {
+ this(cs, charset, BUFFER_SIZE);
+ }
+
+ /**
+ * Constructor, calls {@link #CharSequenceInputStream(CharSequence, String, int)}
+ * with a buffer size of 2048.
+ *
+ * @param cs the input character sequence
+ * @param charset the character set name to use
+ * @throws IllegalArgumentException if the buffer is not large enough to hold a complete character
+ */
+ public CharSequenceInputStream(final CharSequence cs, final String charset) {
+ this(cs, charset, BUFFER_SIZE);
+ }
+
+ /**
+ * Fills the byte output buffer from the input char buffer.
+ *
+ * @throws CharacterCodingException
+ * an error encoding data
+ */
+ private void fillBuffer() throws CharacterCodingException {
+ this.bbuf.compact();
+ final CoderResult result = this.encoder.encode(this.cbuf, this.bbuf, true);
+ if (result.isError()) {
+ result.throwException();
+ }
+ this.bbuf.flip();
+ }
+
+ @Override
+ public int read(final byte[] b, int off, int len) throws IOException {
+ if (b == null) {
+ throw new NullPointerException("Byte array is null");
+ }
+ if (len < 0 || (off + len) > b.length) {
+ throw new IndexOutOfBoundsException("Array Size=" + b.length +
+ ", offset=" + off + ", length=" + len);
+ }
+ if (len == 0) {
+ return 0; // must return 0 for zero length read
+ }
+ if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) {
+ return EOF;
+ }
+ int bytesRead = 0;
+ while (len > 0) {
+ if (this.bbuf.hasRemaining()) {
+ final int chunk = Math.min(this.bbuf.remaining(), len);
+ this.bbuf.get(b, off, chunk);
+ off += chunk;
+ len -= chunk;
+ bytesRead += chunk;
+ } else {
+ fillBuffer();
+ if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) {
+ break;
+ }
+ }
+ }
+ return bytesRead == 0 && !this.cbuf.hasRemaining() ? EOF : bytesRead;
+ }
+
+ @Override
+ public int read() throws IOException {
+ for (;;) {
+ if (this.bbuf.hasRemaining()) {
+ return this.bbuf.get() & 0xFF;
+ }
+ fillBuffer();
+ if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) {
+ return EOF;
+ }
+ }
+ }
+
+ @Override
+ public int read(final byte[] b) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ /*
+ * This could be made more efficient by using position to skip within the current buffer.
+ */
+ long skipped = 0;
+ while (n > 0 && available() > 0) {
+ this.read();
+ n--;
+ skipped++;
+ }
+ return skipped;
+ }
+
+ /**
+ * Return an estimate of the number of bytes remaining in the byte stream.
+ * @return the count of bytes that can be read without blocking (or returning EOF).
+ *
+ * @throws IOException if an error occurs (probably not possible)
+ */
+ @Override
+ public int available() throws IOException {
+ // The cached entries are in bbuf; since encoding always creates at least one byte
+ // per character, we can add the two to get a better estimate (e.g. if bbuf is empty)
+ // Note that the previous implementation (2.4) could return zero even though there were
+ // encoded bytes still available.
+ return this.bbuf.remaining() + this.cbuf.remaining();
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param readlimit max read limit (ignored)
+ */
+ @Override
+ public synchronized void mark(final int readlimit) {
+ this.mark_cbuf = this.cbuf.position();
+ this.mark_bbuf = this.bbuf.position();
+ this.cbuf.mark();
+ this.bbuf.mark();
+ // It would be nice to be able to use mark & reset on the cbuf and bbuf;
+ // however the bbuf is re-used so that won't work
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ /*
+ * This is not the most efficient implementation, as it re-encodes from the beginning.
+ *
+ * Since the bbuf is re-used, in general it's necessary to re-encode the data.
+ *
+ * It should be possible to apply some optimisations however:
+ * + use mark/reset on the cbuf and bbuf. This would only work if the buffer had not been (re)filled since
+ * the mark. The code would have to catch InvalidMarkException - does not seem possible to check if mark is
+ * valid otherwise. + Try saving the state of the cbuf before each fillBuffer; it might be possible to
+ * restart from there.
+ */
+ if (this.mark_cbuf != NO_MARK) {
+ // if cbuf is at 0, we have not started reading anything, so skip re-encoding
+ if (this.cbuf.position() != 0) {
+ this.encoder.reset();
+ this.cbuf.rewind();
+ this.bbuf.rewind();
+ this.bbuf.limit(0); // rewind does not clear the buffer
+ while(this.cbuf.position() < this.mark_cbuf) {
+ this.bbuf.rewind(); // empty the buffer (we only refill when empty during normal processing)
+ this.bbuf.limit(0);
+ fillBuffer();
+ }
+ }
+ if (this.cbuf.position() != this.mark_cbuf) {
+ throw new IllegalStateException("Unexpected CharBuffer postion: actual=" + cbuf.position() + " " +
+ "expected=" + this.mark_cbuf);
+ }
+ this.bbuf.position(this.mark_bbuf);
+ this.mark_cbuf = NO_MARK;
+ this.mark_bbuf = NO_MARK;
+ }
+ }
+
+ @Override
+ public boolean markSupported() {
+ return true;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CharSequenceReader.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CharSequenceReader.java"
new file mode 100644
index 0000000000000000000000000000000000000000..a290b747414f2119b6dd254371ed8276d267b993
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CharSequenceReader.java"
@@ -0,0 +1,166 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.Reader;
+import java.io.Serializable;
+
+/**
+ * {@link Reader} implementation that can read from String, StringBuffer,
+ * StringBuilder or CharBuffer.
+ *
+ * Note: Supports {@link #mark(int)} and {@link #reset()}.
+ *
+ * @version $Id: CharSequenceReader.java 1642757 2014-12-01 21:09:30Z sebb $
+ * @since 1.4
+ */
+public class CharSequenceReader extends Reader implements Serializable {
+
+ private static final long serialVersionUID = 3724187752191401220L;
+ private final CharSequence charSequence;
+ private int idx;
+ private int mark;
+
+ /**
+ * Construct a new instance with the specified character sequence.
+ *
+ * @param charSequence The character sequence, may be {@code null}
+ */
+ public CharSequenceReader(final CharSequence charSequence) {
+ this.charSequence = charSequence != null ? charSequence : "";
+ }
+
+ /**
+ * Close resets the file back to the start and removes any marked position.
+ */
+ @Override
+ public void close() {
+ idx = 0;
+ mark = 0;
+ }
+
+ /**
+ * Mark the current position.
+ *
+ * @param readAheadLimit ignored
+ */
+ @Override
+ public void mark(final int readAheadLimit) {
+ mark = idx;
+ }
+
+ /**
+ * Mark is supported (returns true).
+ *
+ * @return {@code true}
+ */
+ @Override
+ public boolean markSupported() {
+ return true;
+ }
+
+ /**
+ * Read a single character.
+ *
+ * @return the next character from the character sequence
+ * or -1 if the end has been reached.
+ */
+ @Override
+ public int read() {
+ if (idx >= charSequence.length()) {
+ return EOF;
+ } else {
+ return charSequence.charAt(idx++);
+ }
+ }
+
+ /**
+ * 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
+ * @param length The maximum number of characters to read
+ * @return The number of characters read or -1 if there are
+ * no more
+ */
+ @Override
+ public int read(final char[] array, final int offset, final int length) {
+ if (idx >= charSequence.length()) {
+ return EOF;
+ }
+ if (array == null) {
+ throw new NullPointerException("Character array is missing");
+ }
+ if (length < 0 || offset < 0 || offset + length > array.length) {
+ throw new IndexOutOfBoundsException("Array Size=" + array.length +
+ ", offset=" + offset + ", length=" + length);
+ }
+ int count = 0;
+ for (int i = 0; i < length; i++) {
+ final int c = read();
+ if (c == EOF) {
+ return count;
+ }
+ array[offset + i] = (char)c;
+ count++;
+ }
+ return count;
+ }
+
+ /**
+ * Reset the reader to the last marked position (or the beginning if
+ * mark has not been called).
+ */
+ @Override
+ public void reset() {
+ idx = mark;
+ }
+
+ /**
+ * Skip the specified number of characters.
+ *
+ * @param n The number of characters to skip
+ * @return The actual number of characters skipped
+ */
+ @Override
+ public long skip(final long n) {
+ if (n < 0) {
+ throw new IllegalArgumentException(
+ "Number of characters to skip is less than zero: " + n);
+ }
+ if (idx >= charSequence.length()) {
+ return EOF;
+ }
+ final int dest = (int)Math.min(charSequence.length(), idx + n);
+ final int count = dest - idx;
+ idx = dest;
+ return count;
+ }
+
+ /**
+ * Return a String representation of the underlying
+ * character sequence.
+ *
+ * @return The contents of the character sequence
+ */
+ @Override
+ public String toString() {
+ return charSequence.toString();
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..f801052530bf7fd0332eaceaaa51f68a734eef93
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java"
@@ -0,0 +1,101 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.io.StreamCorruptedException;
+import java.lang.reflect.Proxy;
+
+/**
+ * A special ObjectInputStream that loads a class based on a specified
+ * ClassLoader rather than the system default.
+ *
+ * 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 {
+
+ /** The class loader to use. */
+ private final ClassLoader classLoader;
+
+ /**
+ * Constructs a new ClassLoaderObjectInputStream.
+ *
+ * @param classLoader the ClassLoader from which classes should be loaded
+ * @param inputStream the InputStream to work on
+ * @throws IOException in case of an I/O error
+ * @throws StreamCorruptedException if the stream is corrupted
+ */
+ public ClassLoaderObjectInputStream(
+ final ClassLoader classLoader, final InputStream inputStream)
+ throws IOException, StreamCorruptedException {
+ super(inputStream);
+ this.classLoader = classLoader;
+ }
+
+ /**
+ * Resolve a class specified by the descriptor using the
+ * specified ClassLoader or the super ClassLoader.
+ *
+ * @param objectStreamClass descriptor of the class
+ * @return the Class object described by the ObjectStreamClass
+ * @throws IOException in case of an I/O error
+ * @throws ClassNotFoundException if the Class cannot be found
+ */
+ @Override
+ protected Class> resolveClass(final ObjectStreamClass objectStreamClass)
+ throws IOException, ClassNotFoundException {
+
+ try {
+ return Class.forName(objectStreamClass.getName(), false, classLoader);
+ } catch (ClassNotFoundException cnfe) {
+ // delegate to super class loader which can resolve primitives
+ return super.resolveClass(objectStreamClass);
+ }
+ }
+
+ /**
+ * Create a proxy class that implements the specified interfaces using
+ * the specified ClassLoader or the super ClassLoader.
+ *
+ * @param interfaces the interfaces to implement
+ * @return a proxy class implementing the interfaces
+ * @throws IOException in case of an I/O error
+ * @throws ClassNotFoundException if the Class cannot be found
+ * @see java.io.ObjectInputStream#resolveProxyClass(java.lang.String[])
+ * @since 2.1
+ */
+ @Override
+ protected Class> resolveProxyClass(final String[] interfaces) throws IOException,
+ ClassNotFoundException {
+ final Class>[] interfaceClasses = new Class[interfaces.length];
+ for (int i = 0; i < interfaces.length; i++) {
+ interfaceClasses[i] = Class.forName(interfaces[i], false, classLoader);
+ }
+ try {
+ return Proxy.getProxyClass(classLoader, interfaceClasses);
+ } catch (final IllegalArgumentException e) {
+ return super.resolveProxyClass(interfaces);
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..6dcd3b7901376dc9628bf3354ba5067cfa781ab4
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java"
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.InputStream;
+
+/**
+ * Proxy stream that prevents the underlying input stream from being closed.
+ *
+ * This class is typically used in cases where an input stream needs to be
+ * 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 {
+
+ /**
+ * Creates a proxy that shields the given input stream from being
+ * closed.
+ *
+ * @param in underlying input stream
+ */
+ public CloseShieldInputStream(final InputStream in) {
+ super(in);
+ }
+
+ /**
+ * Replaces the underlying input stream with a {@link ClosedInputStream}
+ * sentinel. The original input stream will remain open, but this proxy
+ * will appear closed.
+ */
+ @Override
+ public void close() {
+ in = new ClosedInputStream();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ClosedInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ClosedInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..4230905ce1ec2f9a802cfcee77ff70448c5c2ea5
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ClosedInputStream.java"
@@ -0,0 +1,51 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.InputStream;
+
+/**
+ * Closed input stream. This stream returns EOF to all attempts to read
+ * something from the stream.
+ *
+ * Typically uses of this class include testing for corner cases in methods
+ * 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 {
+
+ /**
+ * A singleton.
+ */
+ public static final ClosedInputStream CLOSED_INPUT_STREAM = new ClosedInputStream();
+
+ /**
+ * Returns -1 to indicate that the stream is closed.
+ *
+ * @return always -1
+ */
+ @Override
+ public int read() {
+ return EOF;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CountingInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CountingInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..6d01a4e0eeb584da9c331ceb6eb6e56f7d8ce9e1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/CountingInputStream.java"
@@ -0,0 +1,145 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A decorating input stream that counts the number of bytes that have passed
+ * through the stream so far.
+ *
+ * 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 {
+
+ /** The count of bytes that have passed. */
+ private long count;
+
+ /**
+ * Constructs a new CountingInputStream.
+ *
+ * @param in the InputStream to delegate to
+ */
+ public CountingInputStream(final InputStream in) {
+ super(in);
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Skips the stream over the specified number of bytes, adding the skipped
+ * amount to the count.
+ *
+ * @param length the number of bytes to skip
+ * @return the actual number of bytes skipped
+ * @throws IOException if an I/O error occurs
+ * @see java.io.InputStream#skip(long)
+ */
+ @Override
+ public synchronized long skip(final long length) throws IOException {
+ final long skip = super.skip(length);
+ this.count += skip;
+ return skip;
+ }
+
+ /**
+ * Adds the number of read bytes to the count.
+ *
+ * @param n number of bytes read, or -1 if no more bytes are available
+ * @since 2.0
+ */
+ @Override
+ protected synchronized void afterRead(final int n) {
+ if (n != EOF) {
+ this.count += n;
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * The number of bytes that have passed through this stream.
+ *
+ * NOTE: From v1.3 this method throws an ArithmeticException if the
+ * count is greater than can be expressed by an int.
+ * See {@link #getByteCount()} for a method using a long.
+ *
+ * @return the number of bytes accumulated
+ * @throws ArithmeticException if the byte count is too large
+ */
+ public int getCount() {
+ final long result = getByteCount();
+ if (result > Integer.MAX_VALUE) {
+ throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");
+ }
+ return (int) result;
+ }
+
+ /**
+ * Set the byte count back to 0.
+ *
+ * NOTE: From v1.3 this method throws an ArithmeticException if the
+ * count is greater than can be expressed by an int.
+ * See {@link #resetByteCount()} for a method using a long.
+ *
+ * @return the count previous to resetting
+ * @throws ArithmeticException if the byte count is too large
+ */
+ public int resetCount() {
+ final long result = resetByteCount();
+ if (result > Integer.MAX_VALUE) {
+ throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");
+ }
+ return (int) result;
+ }
+
+ /**
+ * The number of bytes that have passed through this stream.
+ *
+ * NOTE: This method is an alternative for getCount()
+ * and was added because that method returns an integer which will
+ * result in incorrect count for files over 2GB.
+ *
+ * @return the number of bytes accumulated
+ * @since 1.3
+ */
+ public synchronized long getByteCount() {
+ return this.count;
+ }
+
+ /**
+ * Set the byte count back to 0.
+ *
+ * NOTE: This method is an alternative for resetCount()
+ * and was added because that method returns an integer which will
+ * result in incorrect count for files over 2GB.
+ *
+ * @return the count previous to resetting
+ * @since 1.3
+ */
+ public synchronized long resetByteCount() {
+ final long tmp = this.count;
+ this.count = 0;
+ return tmp;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/DemuxInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/DemuxInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d4c31ed04c8bd1f7cdb10e2e51c6dd6070d7e745
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/DemuxInputStream.java"
@@ -0,0 +1,84 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Data written to this stream is forwarded to a stream that has been associated
+ * with this thread.
+ *
+ * @version $Id: DemuxInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
+ */
+public class DemuxInputStream
+ extends InputStream
+{
+ private final InheritableThreadLocal m_streams = new InheritableThreadLocal();
+
+ /**
+ * Bind the specified stream to the current thread.
+ *
+ * @param input the stream to bind
+ * @return the InputStream that was previously active
+ */
+ public InputStream bindStream( final InputStream input )
+ {
+ final InputStream oldValue = m_streams.get();
+ m_streams.set( input );
+ return oldValue;
+ }
+
+ /**
+ * Closes stream associated with current thread.
+ *
+ * @throws IOException if an error occurs
+ */
+ @Override
+ public void close()
+ throws IOException
+ {
+ final InputStream input = m_streams.get();
+ if( null != input )
+ {
+ input.close();
+ }
+ }
+
+ /**
+ * Read byte from stream associated with current thread.
+ *
+ * @return the byte read from stream
+ * @throws IOException if an error occurs
+ */
+ @Override
+ public int read()
+ throws IOException
+ {
+ final InputStream input = m_streams.get();
+ if( null != input )
+ {
+ return input.read();
+ }
+ else
+ {
+ return EOF;
+ }
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/NullInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/NullInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..e2911753a934d2aa7220d8ac2e2313332802b8b9
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/NullInputStream.java"
@@ -0,0 +1,340 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A functional, light weight {@link InputStream} that emulates
+ * a stream of a specified size.
+ *
+ * This implementation provides a light weight
+ * object for testing with an {@link InputStream}
+ * where the contents don't matter.
+ *
+ * One use case would be for testing the handling of
+ * large {@link InputStream} as it can emulate that
+ * scenario without the overhead of actually processing
+ * large numbers of bytes - significantly speeding up
+ * test execution times.
+ *
+ * This implementation returns zero from the method that
+ * reads a byte and leaves the array unchanged in the read
+ * methods that are passed a byte array.
+ * If alternative data is required the processByte() and
+ * processBytes() methods can be implemented to generate
+ * data, for example:
+ *
+ *
+ * public class TestInputStream extends NullInputStream {
+ * public TestInputStream(int size) {
+ * super(size);
+ * }
+ * protected int processByte() {
+ * return ... // return required value here
+ * }
+ * protected void processBytes(byte[] bytes, int offset, int length) {
+ * for (int i = offset; i < length; i++) {
+ * bytes[i] = ... // set array value here
+ * }
+ * }
+ * }
+ *
+ *
+ * @since 1.3
+ * @version $Id: NullInputStream.java 1586350 2014-04-10 15:57:20Z ggregory $
+ */
+public class NullInputStream extends InputStream {
+
+ private final long size;
+ private long position;
+ private long mark = -1;
+ private long readlimit;
+ private boolean eof;
+ private final boolean throwEofException;
+ private final boolean markSupported;
+
+ /**
+ * Create an {@link InputStream} that emulates a specified size
+ * which supports marking and does not throw EOFException.
+ *
+ * @param size The size of the input stream to emulate.
+ */
+ public NullInputStream(final long size) {
+ this(size, true, false);
+ }
+
+ /**
+ * Create an {@link InputStream} that emulates a specified
+ * size with option settings.
+ *
+ * @param size The size of the input stream to emulate.
+ * @param markSupported Whether this instance will support
+ * the mark() functionality.
+ * @param throwEofException Whether this implementation
+ * will throw an {@link EOFException} or return -1 when the
+ * end of file is reached.
+ */
+ public NullInputStream(final long size, final boolean markSupported, final boolean throwEofException) {
+ this.size = size;
+ this.markSupported = markSupported;
+ this.throwEofException = throwEofException;
+ }
+
+ /**
+ * Return the current position.
+ *
+ * @return the current position.
+ */
+ public long getPosition() {
+ return position;
+ }
+
+ /**
+ * Return the size this {@link InputStream} emulates.
+ *
+ * @return The size of the input stream to emulate.
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
+ * Return the number of bytes that can be read.
+ *
+ * @return The number of bytes that can be read.
+ */
+ @Override
+ public int available() {
+ final long avail = size - position;
+ if (avail <= 0) {
+ return 0;
+ } else if (avail > Integer.MAX_VALUE) {
+ return Integer.MAX_VALUE;
+ } else {
+ return (int)avail;
+ }
+ }
+
+ /**
+ * Close this input stream - resets the internal state to
+ * the initial values.
+ *
+ * @throws IOException If an error occurs.
+ */
+ @Override
+ public void close() throws IOException {
+ eof = false;
+ position = 0;
+ mark = -1;
+ }
+
+ /**
+ * Mark the current position.
+ *
+ * @param readlimit The number of bytes before this marked position
+ * is invalid.
+ * @throws UnsupportedOperationException if mark is not supported.
+ */
+ @Override
+ public synchronized void mark(final int readlimit) {
+ if (!markSupported) {
+ throw new UnsupportedOperationException("Mark not supported");
+ }
+ mark = position;
+ this.readlimit = readlimit;
+ }
+
+ /**
+ * Indicates whether mark is supported.
+ *
+ * @return Whether mark is supported or not.
+ */
+ @Override
+ public boolean markSupported() {
+ return markSupported;
+ }
+
+ /**
+ * Read a byte.
+ *
+ * @return Either The byte value returned by processByte()
+ * or -1 if the end of file has been reached and
+ * throwEofException is set to {@code false}.
+ * @throws EOFException if the end of file is reached and
+ * throwEofException is set to {@code true}.
+ * @throws IOException if trying to read past the end of file.
+ */
+ @Override
+ public int read() throws IOException {
+ if (eof) {
+ throw new IOException("Read after end of file");
+ }
+ if (position == size) {
+ return doEndOfFile();
+ }
+ position++;
+ return processByte();
+ }
+
+ /**
+ * Read some bytes into the specified array.
+ *
+ * @param bytes The byte array to read into
+ * @return The number of bytes read or -1
+ * if the end of file has been reached and
+ * throwEofException is set to {@code false}.
+ * @throws EOFException if the end of file is reached and
+ * throwEofException is set to {@code true}.
+ * @throws IOException if trying to read past the end of file.
+ */
+ @Override
+ public int read(final byte[] bytes) throws IOException {
+ return read(bytes, 0, bytes.length);
+ }
+
+ /**
+ * Read the specified number bytes into an array.
+ *
+ * @param bytes The byte array to read into.
+ * @param offset The offset to start reading bytes into.
+ * @param length The number of bytes to read.
+ * @return The number of bytes read or -1
+ * if the end of file has been reached and
+ * throwEofException is set to {@code false}.
+ * @throws EOFException if the end of file is reached and
+ * throwEofException is set to {@code true}.
+ * @throws IOException if trying to read past the end of file.
+ */
+ @Override
+ public int read(final byte[] bytes, final int offset, final int length) throws IOException {
+ if (eof) {
+ throw new IOException("Read after end of file");
+ }
+ if (position == size) {
+ return doEndOfFile();
+ }
+ position += length;
+ int returnLength = length;
+ if (position > size) {
+ returnLength = length - (int)(position - size);
+ position = size;
+ }
+ processBytes(bytes, offset, returnLength);
+ return returnLength;
+ }
+
+ /**
+ * Reset the stream to the point when mark was last called.
+ *
+ * @throws UnsupportedOperationException if mark is not supported.
+ * @throws IOException If no position has been marked
+ * or the read limit has been exceed since the last position was
+ * marked.
+ */
+ @Override
+ public synchronized void reset() throws IOException {
+ if (!markSupported) {
+ throw new UnsupportedOperationException("Mark not supported");
+ }
+ if (mark < 0) {
+ throw new IOException("No position has been marked");
+ }
+ if (position > mark + readlimit) {
+ throw new IOException("Marked position [" + mark +
+ "] is no longer valid - passed the read limit [" +
+ readlimit + "]");
+ }
+ position = mark;
+ eof = false;
+ }
+
+ /**
+ * Skip a specified number of bytes.
+ *
+ * @param numberOfBytes The number of bytes to skip.
+ * @return The number of bytes skipped or -1
+ * if the end of file has been reached and
+ * throwEofException is set to {@code false}.
+ * @throws EOFException if the end of file is reached and
+ * throwEofException is set to {@code true}.
+ * @throws IOException if trying to read past the end of file.
+ */
+ @Override
+ public long skip(final long numberOfBytes) throws IOException {
+ if (eof) {
+ throw new IOException("Skip after end of file");
+ }
+ if (position == size) {
+ return doEndOfFile();
+ }
+ position += numberOfBytes;
+ long returnLength = numberOfBytes;
+ if (position > size) {
+ returnLength = numberOfBytes - (position - size);
+ position = size;
+ }
+ return returnLength;
+ }
+
+ /**
+ * Return a byte value for the read() method.
+ *
+ * This implementation returns zero.
+ *
+ * @return This implementation always returns zero.
+ */
+ protected int processByte() {
+ // do nothing - overridable by subclass
+ return 0;
+ }
+
+ /**
+ * Process the bytes for the read(byte[], offset, length)
+ * method.
+ *
+ * This implementation leaves the byte array unchanged.
+ *
+ * @param bytes The byte array
+ * @param offset The offset to start at.
+ * @param length The number of bytes.
+ */
+ protected void processBytes(final byte[] bytes, final int offset, final int length) {
+ // do nothing - overridable by subclass
+ }
+
+ /**
+ * Handle End of File.
+ *
+ * @return -1 if throwEofException is
+ * set to {@code false}
+ * @throws EOFException if throwEofException is set
+ * to {@code true}.
+ */
+ private int doEndOfFile() throws EOFException {
+ eof = true;
+ if (throwEofException) {
+ throw new EOFException();
+ }
+ return EOF;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/NullReader.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/NullReader.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d7c7cd7d004550592ce76592d41ed8705e7fd1e4
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/NullReader.java"
@@ -0,0 +1,323 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * A functional, light weight {@link Reader} that emulates
+ * a reader of a specified size.
+ *
+ * This implementation provides a light weight
+ * object for testing with an {@link Reader}
+ * where the contents don't matter.
+ *
+ * One use case would be for testing the handling of
+ * large {@link Reader} as it can emulate that
+ * scenario without the overhead of actually processing
+ * large numbers of characters - significantly speeding up
+ * test execution times.
+ *
+ * This implementation returns a space from the method that
+ * reads a character and leaves the array unchanged in the read
+ * methods that are passed a character array.
+ * If alternative data is required the processChar() and
+ * processChars() methods can be implemented to generate
+ * data, for example:
+ *
+ *
+ * public class TestReader extends NullReader {
+ * public TestReader(int size) {
+ * super(size);
+ * }
+ * protected char processChar() {
+ * return ... // return required value here
+ * }
+ * protected void processChars(char[] chars, int offset, int length) {
+ * for (int i = offset; i < length; i++) {
+ * chars[i] = ... // set array value here
+ * }
+ * }
+ * }
+ *
+ *
+ * @since 1.3
+ * @version $Id: NullReader.java 1586350 2014-04-10 15:57:20Z ggregory $
+ */
+public class NullReader extends Reader {
+
+ private final long size;
+ private long position;
+ private long mark = -1;
+ private long readlimit;
+ private boolean eof;
+ private final boolean throwEofException;
+ private final boolean markSupported;
+
+ /**
+ * Create a {@link Reader} that emulates a specified size
+ * which supports marking and does not throw EOFException.
+ *
+ * @param size The size of the reader to emulate.
+ */
+ public NullReader(final long size) {
+ this(size, true, false);
+ }
+
+ /**
+ * Create a {@link Reader} that emulates a specified
+ * size with option settings.
+ *
+ * @param size The size of the reader to emulate.
+ * @param markSupported Whether this instance will support
+ * the mark() functionality.
+ * @param throwEofException Whether this implementation
+ * will throw an {@link EOFException} or return -1 when the
+ * end of file is reached.
+ */
+ public NullReader(final long size, final boolean markSupported, final boolean throwEofException) {
+ this.size = size;
+ this.markSupported = markSupported;
+ this.throwEofException = throwEofException;
+ }
+
+ /**
+ * Return the current position.
+ *
+ * @return the current position.
+ */
+ public long getPosition() {
+ return position;
+ }
+
+ /**
+ * Return the size this {@link Reader} emulates.
+ *
+ * @return The size of the reader to emulate.
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
+ * Close this Reader - resets the internal state to
+ * the initial values.
+ *
+ * @throws IOException If an error occurs.
+ */
+ @Override
+ public void close() throws IOException {
+ eof = false;
+ position = 0;
+ mark = -1;
+ }
+
+ /**
+ * Mark the current position.
+ *
+ * @param readlimit The number of characters before this marked position
+ * is invalid.
+ * @throws UnsupportedOperationException if mark is not supported.
+ */
+ @Override
+ public synchronized void mark(final int readlimit) {
+ if (!markSupported) {
+ throw new UnsupportedOperationException("Mark not supported");
+ }
+ mark = position;
+ this.readlimit = readlimit;
+ }
+
+ /**
+ * Indicates whether mark is supported.
+ *
+ * @return Whether mark is supported or not.
+ */
+ @Override
+ public boolean markSupported() {
+ return markSupported;
+ }
+
+ /**
+ * Read a character.
+ *
+ * @return Either The character value returned by processChar()
+ * or -1 if the end of file has been reached and
+ * throwEofException is set to {@code false}.
+ * @throws EOFException if the end of file is reached and
+ * throwEofException is set to {@code true}.
+ * @throws IOException if trying to read past the end of file.
+ */
+ @Override
+ public int read() throws IOException {
+ if (eof) {
+ throw new IOException("Read after end of file");
+ }
+ if (position == size) {
+ return doEndOfFile();
+ }
+ position++;
+ return processChar();
+ }
+
+ /**
+ * Read some characters into the specified array.
+ *
+ * @param chars The character array to read into
+ * @return The number of characters read or -1
+ * if the end of file has been reached and
+ * throwEofException is set to {@code false}.
+ * @throws EOFException if the end of file is reached and
+ * throwEofException is set to {@code true}.
+ * @throws IOException if trying to read past the end of file.
+ */
+ @Override
+ public int read(final char[] chars) throws IOException {
+ return read(chars, 0, chars.length);
+ }
+
+ /**
+ * Read the specified number characters into an array.
+ *
+ * @param chars The character array to read into.
+ * @param offset The offset to start reading characters into.
+ * @param length The number of characters to read.
+ * @return The number of characters read or -1
+ * if the end of file has been reached and
+ * throwEofException is set to {@code false}.
+ * @throws EOFException if the end of file is reached and
+ * throwEofException is set to {@code true}.
+ * @throws IOException if trying to read past the end of file.
+ */
+ @Override
+ public int read(final char[] chars, final int offset, final int length) throws IOException {
+ if (eof) {
+ throw new IOException("Read after end of file");
+ }
+ if (position == size) {
+ return doEndOfFile();
+ }
+ position += length;
+ int returnLength = length;
+ if (position > size) {
+ returnLength = length - (int)(position - size);
+ position = size;
+ }
+ processChars(chars, offset, returnLength);
+ return returnLength;
+ }
+
+ /**
+ * Reset the stream to the point when mark was last called.
+ *
+ * @throws UnsupportedOperationException if mark is not supported.
+ * @throws IOException If no position has been marked
+ * or the read limit has been exceed since the last position was
+ * marked.
+ */
+ @Override
+ public synchronized void reset() throws IOException {
+ if (!markSupported) {
+ throw new UnsupportedOperationException("Mark not supported");
+ }
+ if (mark < 0) {
+ throw new IOException("No position has been marked");
+ }
+ if (position > mark + readlimit) {
+ throw new IOException("Marked position [" + mark +
+ "] is no longer valid - passed the read limit [" +
+ readlimit + "]");
+ }
+ position = mark;
+ eof = false;
+ }
+
+ /**
+ * Skip a specified number of characters.
+ *
+ * @param numberOfChars The number of characters to skip.
+ * @return The number of characters skipped or -1
+ * if the end of file has been reached and
+ * throwEofException is set to {@code false}.
+ * @throws EOFException if the end of file is reached and
+ * throwEofException is set to {@code true}.
+ * @throws IOException if trying to read past the end of file.
+ */
+ @Override
+ public long skip(final long numberOfChars) throws IOException {
+ if (eof) {
+ throw new IOException("Skip after end of file");
+ }
+ if (position == size) {
+ return doEndOfFile();
+ }
+ position += numberOfChars;
+ long returnLength = numberOfChars;
+ if (position > size) {
+ returnLength = numberOfChars - (position - size);
+ position = size;
+ }
+ return returnLength;
+ }
+
+ /**
+ * Return a character value for the read() method.
+ *
+ * This implementation returns zero.
+ *
+ * @return This implementation always returns zero.
+ */
+ protected int processChar() {
+ // do nothing - overridable by subclass
+ return 0;
+ }
+
+ /**
+ * Process the characters for the read(char[], offset, length)
+ * method.
+ *
+ * This implementation leaves the character array unchanged.
+ *
+ * @param chars The character array
+ * @param offset The offset to start at.
+ * @param length The number of characters.
+ */
+ protected void processChars(final char[] chars, final int offset, final int length) {
+ // do nothing - overridable by subclass
+ }
+
+ /**
+ * Handle End of File.
+ *
+ * @return -1 if throwEofException is
+ * set to {@code false}
+ * @throws EOFException if throwEofException is set
+ * to {@code true}.
+ */
+ private int doEndOfFile() throws EOFException {
+ eof = true;
+ if (throwEofException) {
+ throw new EOFException();
+ }
+ return EOF;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ProxyInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ProxyInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..e5614f239683f84d88711a608006c0e3b27e81b3
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ProxyInputStream.java"
@@ -0,0 +1,240 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A Proxy stream which acts as expected, that is it passes the method
+ * calls on to the proxied stream and doesn't change which methods are
+ * being called.
+ *
+ * It is an alternative base class to FilterInputStream
+ * to increase reusability, because FilterInputStream changes the
+ * methods being called, such as read(byte[]) to read(byte[], int, int).
+ *
+ * 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 {
+
+ /**
+ * Constructs a new ProxyInputStream.
+ *
+ * @param proxy the InputStream to delegate to
+ */
+ public ProxyInputStream(final InputStream proxy) {
+ super(proxy);
+ // the proxy is stored in a protected superclass variable named 'in'
+ }
+
+ /**
+ * Invokes the delegate's read() method.
+ * @return the byte read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read() throws IOException {
+ try {
+ beforeRead(1);
+ final int b = in.read();
+ afterRead(b != EOF ? 1 : EOF);
+ return b;
+ } catch (final IOException e) {
+ handleIOException(e);
+ return EOF;
+ }
+ }
+
+ /**
+ * Invokes the delegate's read(byte[]) method.
+ * @param bts the buffer to read the bytes into
+ * @return the number of bytes read or EOF if the end of stream
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final byte[] bts) throws IOException {
+ try {
+ beforeRead(bts != null ? bts.length : 0);
+ final int n = in.read(bts);
+ afterRead(n);
+ return n;
+ } catch (final IOException e) {
+ handleIOException(e);
+ return EOF;
+ }
+ }
+
+ /**
+ * Invokes the delegate's read(byte[], int, int) method.
+ * @param bts the buffer to read the bytes into
+ * @param off The start offset
+ * @param len The number of bytes to read
+ * @return the number of bytes read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final byte[] bts, final int off, final int len) throws IOException {
+ try {
+ beforeRead(len);
+ final int n = in.read(bts, off, len);
+ afterRead(n);
+ return n;
+ } catch (final IOException e) {
+ handleIOException(e);
+ return EOF;
+ }
+ }
+
+ /**
+ * Invokes the delegate's skip(long) method.
+ * @param ln the number of bytes to skip
+ * @return the actual number of bytes skipped
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public long skip(final long ln) throws IOException {
+ try {
+ return in.skip(ln);
+ } catch (final IOException e) {
+ handleIOException(e);
+ return 0;
+ }
+ }
+
+ /**
+ * Invokes the delegate's available() method.
+ * @return the number of available bytes
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int available() throws IOException {
+ try {
+ return super.available();
+ } catch (final IOException e) {
+ handleIOException(e);
+ return 0;
+ }
+ }
+
+ /**
+ * Invokes the delegate's close() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ try {
+ in.close();
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's mark(int) method.
+ * @param readlimit read ahead limit
+ */
+ @Override
+ public synchronized void mark(final int readlimit) {
+ in.mark(readlimit);
+ }
+
+ /**
+ * Invokes the delegate's reset() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public synchronized void reset() throws IOException {
+ try {
+ in.reset();
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's markSupported() method.
+ * @return true if mark is supported, otherwise false
+ */
+ @Override
+ public boolean markSupported() {
+ return in.markSupported();
+ }
+
+ /**
+ * Invoked by the read methods before the call is proxied. The number
+ * of bytes that the caller wanted to read (1 for the {@link #read()}
+ * method, buffer length for {@link #read(byte[])}, etc.) is given as
+ * an argument.
+ *
+ * Subclasses can override this method to add common pre-processing
+ * functionality without having to override all the read methods.
+ * The default implementation does nothing.
+ *
+ * Note this method is not called from {@link #skip(long)} or
+ * {@link #reset()}. You need to explicitly override those methods if
+ * you want to add pre-processing steps also to them.
+ *
+ * @since 2.0
+ * @param n number of bytes that the caller asked to be read
+ * @throws IOException if the pre-processing fails
+ */
+ protected void beforeRead(final int n) throws IOException {
+ // no-op
+ }
+
+ /**
+ * Invoked by the read methods after the proxied call has returned
+ * successfully. The number of bytes returned to the caller (or -1 if
+ * the end of stream was reached) is given as an argument.
+ *
+ * Subclasses can override this method to add common post-processing
+ * functionality without having to override all the read methods.
+ * The default implementation does nothing.
+ *
+ * Note this method is not called from {@link #skip(long)} or
+ * {@link #reset()}. You need to explicitly override those methods if
+ * you want to add post-processing steps also to them.
+ *
+ * @since 2.0
+ * @param n number of bytes read, or -1 if the end of stream was reached
+ * @throws IOException if the post-processing fails
+ */
+ protected void afterRead(final int n) throws IOException {
+ // no-op
+ }
+
+ /**
+ * Handle any IOExceptions thrown.
+ *
+ * This method provides a point to implement custom exception
+ * handling. The default behaviour is to re-throw the exception.
+ * @param e The IOException thrown
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ protected void handleIOException(final IOException e) throws IOException {
+ throw e;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ProxyReader.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ProxyReader.java"
new file mode 100644
index 0000000000000000000000000000000000000000..b8cb9a9bb2e9908b607b42a60e6a02562a762958
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ProxyReader.java"
@@ -0,0 +1,261 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static 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.
+ *
+ * It is an alternative base class to FilterReader
+ * 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) {
+ super(proxy);
+ // the proxy is stored in a protected superclass variable named 'in'
+ }
+
+ /**
+ * Invokes the delegate's read() method.
+ * @return the character read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read() throws IOException {
+ try {
+ beforeRead(1);
+ final int c = in.read();
+ afterRead(c != EOF ? 1 : EOF);
+ return c;
+ } catch (final IOException e) {
+ handleIOException(e);
+ return EOF;
+ }
+ }
+
+ /**
+ * Invokes the delegate's read(char[]) method.
+ * @param chr the buffer to read the characters into
+ * @return the number of characters read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final char[] chr) throws IOException {
+ try {
+ beforeRead(chr != null ? chr.length : 0);
+ final int n = in.read(chr);
+ afterRead(n);
+ return n;
+ } catch (final IOException e) {
+ handleIOException(e);
+ return EOF;
+ }
+ }
+
+ /**
+ * Invokes the delegate's read(char[], int, int) method.
+ * @param chr the buffer to read the characters into
+ * @param st The start offset
+ * @param len The number of bytes to read
+ * @return the number of characters read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final char[] chr, final int st, final int len) throws IOException {
+ try {
+ beforeRead(len);
+ final int n = in.read(chr, st, len);
+ afterRead(n);
+ return n;
+ } catch (final IOException e) {
+ handleIOException(e);
+ return EOF;
+ }
+ }
+
+ /**
+ * Invokes the delegate's read(CharBuffer) method.
+ * @param target the char buffer to read the characters into
+ * @return the number of characters read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ @Override
+ public int read(final CharBuffer target) throws IOException {
+ try {
+ beforeRead(target != null ? target.length() : 0);
+ final int n = in.read(target);
+ afterRead(n);
+ return n;
+ } catch (final IOException e) {
+ handleIOException(e);
+ return EOF;
+ }
+ }
+
+ /**
+ * Invokes the delegate's skip(long) method.
+ * @param ln the number of bytes to skip
+ * @return the number of bytes to skipped or EOF if the end of stream
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public long skip(final long ln) throws IOException {
+ try {
+ return in.skip(ln);
+ } catch (final IOException e) {
+ handleIOException(e);
+ return 0;
+ }
+ }
+
+ /**
+ * Invokes the delegate's ready() method.
+ * @return true if the stream is ready to be read
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public boolean ready() throws IOException {
+ try {
+ return in.ready();
+ } catch (final IOException e) {
+ handleIOException(e);
+ return false;
+ }
+ }
+
+ /**
+ * Invokes the delegate's close() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ try {
+ in.close();
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's mark(int) method.
+ * @param idx read ahead limit
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public synchronized void mark(final int idx) throws IOException {
+ try {
+ in.mark(idx);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's reset() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public synchronized void reset() throws IOException {
+ try {
+ in.reset();
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's markSupported() method.
+ * @return true if mark is supported, otherwise false
+ */
+ @Override
+ public boolean markSupported() {
+ return in.markSupported();
+ }
+
+ /**
+ * Invoked by the read methods before the call is proxied. The number
+ * of chars that the caller wanted to read (1 for the {@link #read()}
+ * method, buffer length for {@link #read(char[])}, etc.) is given as
+ * an argument.
+ *
+ * Subclasses can override this method to add common pre-processing
+ * functionality without having to override all the read methods.
+ * The default implementation does nothing.
+ *
+ * Note this method is not called from {@link #skip(long)} or
+ * {@link #reset()}. You need to explicitly override those methods if
+ * you want to add pre-processing steps also to them.
+ *
+ * @since 2.0
+ * @param n number of chars that the caller asked to be read
+ * @throws IOException if the pre-processing fails
+ */
+ protected void beforeRead(final int n) throws IOException {
+ }
+
+ /**
+ * Invoked by the read methods after the proxied call has returned
+ * successfully. The number of chars returned to the caller (or -1 if
+ * the end of stream was reached) is given as an argument.
+ *
+ * Subclasses can override this method to add common post-processing
+ * functionality without having to override all the read methods.
+ * The default implementation does nothing.
+ *
+ * Note this method is not called from {@link #skip(long)} or
+ * {@link #reset()}. You need to explicitly override those methods if
+ * you want to add post-processing steps also to them.
+ *
+ * @since 2.0
+ * @param n number of chars read, or -1 if the end of stream was reached
+ * @throws IOException if the post-processing fails
+ */
+ protected void afterRead(final int n) throws IOException {
+ }
+
+ /**
+ * Handle any IOExceptions thrown.
+ *
+ * This method provides a point to implement custom exception
+ * handling. The default behaviour is to re-throw the exception.
+ * @param e The IOException thrown
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ protected void handleIOException(final IOException e) throws IOException {
+ throw e;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ReaderInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ReaderInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..b8e151fc6b407278491e904205fa2bcdd301e4dc
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ReaderInputStream.java"
@@ -0,0 +1,297 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+
+/**
+ * {@link InputStream} implementation that reads a character stream from a {@link Reader}
+ * and transforms it to a byte stream using a specified charset encoding. The stream
+ * is transformed using a {@link CharsetEncoder} object, guaranteeing that all charset
+ * encodings supported by the JRE are handled correctly. In particular for charsets such as
+ * UTF-16, the implementation ensures that one and only one byte order marker
+ * is produced.
+ *
+ * Since in general it is not possible to predict the number of characters to be read from the
+ * {@link Reader} to satisfy a read request on the {@link ReaderInputStream}, all reads from
+ * the {@link Reader} are buffered. There is therefore no well defined correlation
+ * between the current position of the {@link Reader} and that of the {@link ReaderInputStream}.
+ * This also implies that in general there is no need to wrap the underlying {@link Reader}
+ * in a {@link java.io.BufferedReader}.
+ *
+ * {@link ReaderInputStream} implements the inverse transformation of {@link java.io.InputStreamReader};
+ * in the following example, reading from {@code in2} would return the same byte
+ * sequence as reading from {@code in} (provided that the initial byte sequence is legal
+ * with respect to the charset encoding):
+ *
+ * InputStream in = ...
+ * Charset cs = ...
+ * InputStreamReader reader = new InputStreamReader(in, cs);
+ * ReaderInputStream in2 = new ReaderInputStream(reader, cs);
+ * {@link ReaderInputStream} implements the same transformation as {@link java.io.OutputStreamWriter},
+ * except that the control flow is reversed: both classes transform a character stream
+ * into a byte stream, but {@link java.io.OutputStreamWriter} pushes data to the underlying stream,
+ * while {@link ReaderInputStream} pulls it from the underlying stream.
+ *
+ * Note that while there are use cases where there is no alternative to using
+ * this class, very often the need to use this class is an indication of a flaw
+ * 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 {@link javax.activation.DataSource}
+ * interface from the Java Activation Framework.
+ *
+ * Given the fact that the {@link Reader} class doesn't provide any way to predict whether the next
+ * read operation will block or not, it is not possible to provide a meaningful
+ * implementation of the {@link InputStream#available()} method. A call to this method
+ * will always return 0. Also, this class doesn't support {@link InputStream#mark(int)}.
+ *
+ * Instances of {@link ReaderInputStream} are not thread safe.
+ *
+ * @see org.apache.commons.io.output.WriterOutputStream
+ *
+ * @since 2.0
+ */
+public class ReaderInputStream extends InputStream {
+ private static final int DEFAULT_BUFFER_SIZE = 1024;
+
+ private final Reader reader;
+ private final CharsetEncoder encoder;
+
+ /**
+ * CharBuffer used as input for the decoder. It should be reasonably
+ * large as we read data from the underlying Reader into this buffer.
+ */
+ private final CharBuffer encoderIn;
+
+ /**
+ * ByteBuffer used as output for the decoder. This buffer can be small
+ * as it is only used to transfer data from the decoder to the
+ * buffer provided by the caller.
+ */
+ private final ByteBuffer encoderOut;
+
+ private CoderResult lastCoderResult;
+ private boolean endOfInput;
+
+ /**
+ * Construct a new {@link ReaderInputStream}.
+ *
+ * @param reader the target {@link Reader}
+ * @param encoder the charset encoder
+ * @since 2.1
+ */
+ public ReaderInputStream(final Reader reader, final CharsetEncoder encoder) {
+ this(reader, encoder, DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Construct a new {@link ReaderInputStream}.
+ *
+ * @param reader the target {@link Reader}
+ * @param encoder the charset encoder
+ * @param bufferSize the size of the input buffer in number of characters
+ * @since 2.1
+ */
+ public ReaderInputStream(final Reader reader, final CharsetEncoder encoder, final int bufferSize) {
+ this.reader = reader;
+ this.encoder = encoder;
+ this.encoderIn = CharBuffer.allocate(bufferSize);
+ this.encoderIn.flip();
+ this.encoderOut = ByteBuffer.allocate(128);
+ this.encoderOut.flip();
+ }
+
+ /**
+ * Construct a new {@link ReaderInputStream}.
+ *
+ * @param reader the target {@link Reader}
+ * @param charset the charset encoding
+ * @param bufferSize the size of the input buffer in number of characters
+ */
+ public ReaderInputStream(final Reader reader, final Charset charset, final int bufferSize) {
+ this(reader,
+ charset.newEncoder()
+ .onMalformedInput(CodingErrorAction.REPLACE)
+ .onUnmappableCharacter(CodingErrorAction.REPLACE),
+ bufferSize);
+ }
+
+ /**
+ * Construct a new {@link ReaderInputStream} with a default input buffer size of
+ * 1024 characters.
+ *
+ * @param reader the target {@link Reader}
+ * @param charset the charset encoding
+ */
+ public ReaderInputStream(final Reader reader, final Charset charset) {
+ this(reader, charset, DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Construct a new {@link ReaderInputStream}.
+ *
+ * @param reader the target {@link Reader}
+ * @param charsetName the name of the charset encoding
+ * @param bufferSize the size of the input buffer in number of characters
+ */
+ public ReaderInputStream(final Reader reader, final String charsetName, final int bufferSize) {
+ this(reader, Charset.forName(charsetName), bufferSize);
+ }
+
+ /**
+ * Construct a new {@link ReaderInputStream} with a default input buffer size of
+ * 1024 characters.
+ *
+ * @param reader the target {@link Reader}
+ * @param charsetName the name of the charset encoding
+ */
+ public ReaderInputStream(final Reader reader, final String charsetName) {
+ this(reader, charsetName, DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Construct a new {@link ReaderInputStream} that uses the default character encoding
+ * with a default input buffer size of 1024 characters.
+ *
+ * @param reader the target {@link Reader}
+ * @deprecated 2.5 use {@link #ReaderInputStream(Reader, Charset)} instead
+ */
+ @Deprecated
+ public ReaderInputStream(final Reader reader) {
+ this(reader, Charset.defaultCharset());
+ }
+
+ /**
+ * Fills the internal char buffer from the reader.
+ *
+ * @throws IOException
+ * If an I/O error occurs
+ */
+ private void fillBuffer() throws IOException {
+ if (!endOfInput && (lastCoderResult == null || lastCoderResult.isUnderflow())) {
+ encoderIn.compact();
+ final int position = encoderIn.position();
+ // We don't use Reader#read(CharBuffer) here because it is more efficient
+ // to write directly to the underlying char array (the default implementation
+ // copies data to a temporary char array).
+ final int c = reader.read(encoderIn.array(), position, encoderIn.remaining());
+ if (c == EOF) {
+ endOfInput = true;
+ } else {
+ encoderIn.position(position+c);
+ }
+ encoderIn.flip();
+ }
+ encoderOut.compact();
+ lastCoderResult = encoder.encode(encoderIn, encoderOut, endOfInput);
+ encoderOut.flip();
+ }
+
+ /**
+ * Read the specified number of bytes into an array.
+ *
+ * @param b the byte array to read into
+ * @param off the offset to start reading bytes into
+ * @param len the number of bytes to read
+ * @return the number of bytes read or -1
+ * if the end of the stream has been reached
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final byte[] b, int off, int len) throws IOException {
+ if (b == null) {
+ throw new NullPointerException("Byte array must not be null");
+ }
+ if (len < 0 || off < 0 || (off + len) > b.length) {
+ throw new IndexOutOfBoundsException("Array Size=" + b.length +
+ ", offset=" + off + ", length=" + len);
+ }
+ int read = 0;
+ if (len == 0) {
+ return 0; // Always return 0 if len == 0
+ }
+ while (len > 0) {
+ if (encoderOut.hasRemaining()) {
+ final int c = Math.min(encoderOut.remaining(), len);
+ encoderOut.get(b, off, c);
+ off += c;
+ len -= c;
+ read += c;
+ } else {
+ fillBuffer();
+ if (endOfInput && !encoderOut.hasRemaining()) {
+ break;
+ }
+ }
+ }
+ return read == 0 && endOfInput ? EOF : read;
+ }
+
+ /**
+ * Read the specified number of bytes into an array.
+ *
+ * @param b the byte array to read into
+ * @return the number of bytes read or -1
+ * if the end of the stream has been reached
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final byte[] b) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ /**
+ * Read a single byte.
+ *
+ * @return either the byte read or -1 if the end of the stream
+ * has been reached
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read() throws IOException {
+ for (;;) {
+ if (encoderOut.hasRemaining()) {
+ return encoderOut.get() & 0xFF;
+ }
+ fillBuffer();
+ if (endOfInput && !encoderOut.hasRemaining()) {
+ return EOF;
+ }
+ }
+ }
+
+ /**
+ * Close the stream. This method will cause the underlying {@link Reader}
+ * to be closed.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ reader.close();
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java"
new file mode 100644
index 0000000000000000000000000000000000000000..7522d84f46fbf43e7489d39986bba648a17e3d04
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java"
@@ -0,0 +1,365 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+
+import org.apache.commons.io.Charsets;
+
+/**
+ * Reads lines in a file reversely (similar to a BufferedReader, but starting at
+ * the last line). Useful for e.g. searching in log files.
+ *
+ * @since 2.2
+ */
+public class ReversedLinesFileReader implements Closeable {
+
+ private final int blockSize;
+ private final Charset encoding;
+
+ private final RandomAccessFile randomAccessFile;
+
+ private final long totalByteLength;
+ private final long totalBlockCount;
+
+ private final byte[][] newLineSequences;
+ private final int avoidNewlineSplitBufferSize;
+ private final int byteDecrement;
+
+ private FilePart currentFilePart;
+
+ private boolean trailingNewlineOfFileSkipped = false;
+
+ /**
+ * Creates a ReversedLinesFileReader with default block size of 4KB and the
+ * platform's default encoding.
+ *
+ * @param file
+ * the file to be read
+ * @throws IOException if an I/O error occurs
+ * @deprecated 2.5 use {@link #ReversedLinesFileReader(File, Charset)} instead
+ */
+ @Deprecated
+ public ReversedLinesFileReader(final File file) throws IOException {
+ this(file, 4096, Charset.defaultCharset());
+ }
+
+ /**
+ * Creates a ReversedLinesFileReader with default block size of 4KB and the
+ * specified encoding.
+ *
+ * @param file
+ * the file to be read
+ * @param charset the encoding to use
+ * @throws IOException if an I/O error occurs
+ * @since 2.5
+ */
+ public ReversedLinesFileReader(final File file, final Charset charset) throws IOException {
+ this(file, 4096, charset);
+ }
+
+ /**
+ * Creates a ReversedLinesFileReader with the given block size and encoding.
+ *
+ * @param file
+ * the file to be read
+ * @param blockSize
+ * size of the internal buffer (for ideal performance this should
+ * match with the block size of the underlying file system).
+ * @param encoding
+ * the encoding of the file
+ * @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;
+
+ // --- check & prepare encoding ---
+ final Charset charset = Charsets.toCharset(encoding);
+ final CharsetEncoder charsetEncoder = charset.newEncoder();
+ final float maxBytesPerChar = charsetEncoder.maxBytesPerChar();
+ if (maxBytesPerChar == 1f) {
+ // all one byte encodings are no problem
+ byteDecrement = 1;
+ } 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;
+ } else if(charset == Charset.forName("Shift_JIS") || // Same as for UTF-8
+ // http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
+ charset == Charset.forName("windows-31j") || // Windows code page 932 (Japanese)
+ charset == Charset.forName("x-windows-949") || // Windows code page 949 (Korean)
+ 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 == 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 == Charsets.UTF_16) {
+ throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte order (use UTF-16BE or " +
+ "UTF-16LE)");
+ } else {
+ throw new UnsupportedEncodingException("Encoding " + encoding + " is not supported yet (feel free to " +
+ "submit a patch)");
+ }
+
+ // NOTE: The new line sequences are matched in the order given, so it is important that \r\n is BEFORE \n
+ newLineSequences = new byte[][] { "\r\n".getBytes(encoding), "\n".getBytes(encoding), "\r".getBytes(encoding) };
+
+ avoidNewlineSplitBufferSize = newLineSequences[0].length;
+
+ // Open file
+ randomAccessFile = new RandomAccessFile(file, "r");
+ totalByteLength = randomAccessFile.length();
+ int lastBlockLength = (int) (totalByteLength % blockSize);
+ if (lastBlockLength > 0) {
+ totalBlockCount = totalByteLength / blockSize + 1;
+ } else {
+ totalBlockCount = totalByteLength / blockSize;
+ if (totalByteLength > 0) {
+ lastBlockLength = blockSize;
+ }
+ }
+ currentFilePart = new FilePart(totalBlockCount, lastBlockLength, null);
+
+ }
+
+ /**
+ * Creates a ReversedLinesFileReader with the given block size and encoding.
+ *
+ * @param file
+ * the file to be read
+ * @param blockSize
+ * size of the internal buffer (for ideal performance this should
+ * match with the block size of the underlying file system).
+ * @param encoding
+ * the encoding of the file
+ * @throws IOException if an I/O error occurs
+ * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link UnsupportedEncodingException} in
+ * version 2.2 if the encoding is not supported.
+ */
+ public ReversedLinesFileReader(final File file, final int blockSize, final String encoding) throws IOException {
+ this(file, blockSize, Charsets.toCharset(encoding));
+ }
+
+ /**
+ * Returns the lines of the file from bottom to top.
+ *
+ * @return the next line or null if the start of the file is reached
+ * @throws IOException if an I/O error occurs
+ */
+ public String readLine() throws IOException {
+
+ String line = currentFilePart.readLine();
+ while (line == null) {
+ currentFilePart = currentFilePart.rollOver();
+ if (currentFilePart != null) {
+ line = currentFilePart.readLine();
+ } else {
+ // no more fileparts: we're done, leave line set to null
+ break;
+ }
+ }
+
+ // aligned behaviour with BufferedReader that doesn't return a last, empty line
+ if("".equals(line) && !trailingNewlineOfFileSkipped) {
+ trailingNewlineOfFileSkipped = true;
+ line = readLine();
+ }
+
+ return line;
+ }
+
+ /**
+ * Closes underlying resources.
+ *
+ * @throws IOException if an I/O error occurs
+ */
+ public void close() throws IOException {
+ randomAccessFile.close();
+ }
+
+ private class FilePart {
+ private final long no;
+
+ private final byte[] data;
+
+ private byte[] leftOver;
+
+ private int currentLastBytePos;
+
+ /**
+ * ctor
+ * @param no the part number
+ * @param length its length
+ * @param leftOverOfLastFilePart remainder
+ * @throws IOException if there is a problem reading the file
+ */
+ private FilePart(final long no, final int length, final byte[] leftOverOfLastFilePart) throws IOException {
+ this.no = no;
+ final int dataLength = length + (leftOverOfLastFilePart != null ? leftOverOfLastFilePart.length : 0);
+ this.data = new byte[dataLength];
+ final long off = (no - 1) * blockSize;
+
+ // read data
+ if (no > 0 /* file not empty */) {
+ randomAccessFile.seek(off);
+ final int countRead = randomAccessFile.read(data, 0, length);
+ if (countRead != length) {
+ throw new IllegalStateException("Count of requested bytes and actually read bytes don't match");
+ }
+ }
+ // copy left over part into data arr
+ if (leftOverOfLastFilePart != null) {
+ System.arraycopy(leftOverOfLastFilePart, 0, data, length, leftOverOfLastFilePart.length);
+ }
+ this.currentLastBytePos = data.length - 1;
+ this.leftOver = null;
+ }
+
+ /**
+ * Handles block rollover
+ *
+ * @return the new FilePart or null
+ * @throws IOException if there was a problem reading the file
+ */
+ private FilePart rollOver() throws IOException {
+
+ if (currentLastBytePos > -1) {
+ throw new IllegalStateException("Current currentLastCharPos unexpectedly positive... "
+ + "last readLine() should have returned something! currentLastCharPos=" + currentLastBytePos);
+ }
+
+ if (no > 1) {
+ return new FilePart(no - 1, blockSize, leftOver);
+ } else {
+ // NO 1 was the last FilePart, we're finished
+ if (leftOver != null) {
+ throw new IllegalStateException("Unexpected leftover of the last block: leftOverOfThisFilePart="
+ + new String(leftOver, encoding));
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Reads a line.
+ *
+ * @return the line or null
+ * @throws IOException if there is an error reading from the file
+ */
+ private String readLine() throws IOException {
+
+ String line = null;
+ int newLineMatchByteCount;
+
+ final boolean isLastFilePart = no == 1;
+
+ int i = currentLastBytePos;
+ while (i > -1) {
+
+ if (!isLastFilePart && i < avoidNewlineSplitBufferSize) {
+ // avoidNewlineSplitBuffer: for all except the last file part we
+ // take a few bytes to the next file part to avoid splitting of newlines
+ createLeftOver();
+ break; // skip last few bytes and leave it to the next file part
+ }
+
+ // --- check for newline ---
+ if ((newLineMatchByteCount = getNewLineMatchByteCount(data, i)) > 0 /* found newline */) {
+ final int lineStart = i + 1;
+ final int lineLengthBytes = currentLastBytePos - lineStart + 1;
+
+ if (lineLengthBytes < 0) {
+ throw new IllegalStateException("Unexpected negative line length="+lineLengthBytes);
+ }
+ final byte[] lineData = new byte[lineLengthBytes];
+ System.arraycopy(data, lineStart, lineData, 0, lineLengthBytes);
+
+ line = new String(lineData, encoding);
+
+ currentLastBytePos = i - newLineMatchByteCount;
+ break; // found line
+ }
+
+ // --- move cursor ---
+ i -= byteDecrement;
+
+ // --- end of file part handling ---
+ if (i < 0) {
+ createLeftOver();
+ break; // end of file part
+ }
+ }
+
+ // --- last file part handling ---
+ if (isLastFilePart && leftOver != null) {
+ // there will be no line break anymore, this is the first line of the file
+ line = new String(leftOver, encoding);
+ leftOver = null;
+ }
+
+ return line;
+ }
+
+ /**
+ * Creates the buffer containing any left over bytes.
+ */
+ private void createLeftOver() {
+ final int lineLengthBytes = currentLastBytePos + 1;
+ if (lineLengthBytes > 0) {
+ // create left over for next block
+ leftOver = new byte[lineLengthBytes];
+ System.arraycopy(data, 0, leftOver, 0, lineLengthBytes);
+ } else {
+ leftOver = null;
+ }
+ currentLastBytePos = -1;
+ }
+
+ /**
+ * 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
+ */
+ private int getNewLineMatchByteCount(final byte[] data, final int i) {
+ for (final byte[] newLineSequence : newLineSequences) {
+ boolean match = true;
+ for (int j = newLineSequence.length - 1; j >= 0; j--) {
+ final int k = i + j - (newLineSequence.length - 1);
+ match &= k >= 0 && data[k] == newLineSequence[j];
+ }
+ if (match) {
+ return newLineSequence.length;
+ }
+ }
+ return 0;
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/SwappedDataInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/SwappedDataInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..bde5bebd98ca7530460bd334efa524291628f23a
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/SwappedDataInputStream.java"
@@ -0,0 +1,252 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.DataInput;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import 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.
+ *
+ * Origin of code: Avalon Excalibur (IO)
+ *
+ * @version CVS $Revision: 1302050 $
+ */
+public class SwappedDataInputStream extends ProxyInputStream
+ implements DataInput
+{
+
+ /**
+ * Constructs a SwappedDataInputStream.
+ *
+ * @param input InputStream to read from
+ */
+ public SwappedDataInputStream( final InputStream input )
+ {
+ super( input );
+ }
+
+ /**
+ * Return {@link #readByte()} != 0
+ * @return false if the byte read is zero, otherwise true
+ * @throws IOException if an I/O error occurs
+ * @throws EOFException if an end of file is reached unexpectedly
+ */
+ public boolean readBoolean()
+ throws IOException, EOFException
+ {
+ return 0 != readByte();
+ }
+
+ /**
+ * Invokes the delegate's read() method.
+ * @return the byte read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ * @throws EOFException if an end of file is reached unexpectedly
+ */
+ public byte readByte()
+ throws IOException, EOFException
+ {
+ return (byte)in.read();
+ }
+
+ /**
+ * Reads a character delegating to {@link #readShort()}.
+ * @return the byte read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ * @throws EOFException if an end of file is reached unexpectedly
+ */
+ public char readChar()
+ throws IOException, EOFException
+ {
+ return (char)readShort();
+ }
+
+ /**
+ * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}.
+ * @return the read long
+ * @throws IOException if an I/O error occurs
+ * @throws EOFException if an end of file is reached unexpectedly
+ */
+ public double readDouble()
+ throws IOException, EOFException
+ {
+ return EndianUtils.readSwappedDouble( in );
+ }
+
+ /**
+ * 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
+ */
+ public float readFloat()
+ throws IOException, EOFException
+ {
+ return EndianUtils.readSwappedFloat( in );
+ }
+
+ /**
+ * Invokes the delegate's read(byte[] data, int, int) method.
+ *
+ * @param data the buffer to read the bytes into
+ * @throws EOFException if an end of file is reached unexpectedly
+ * @throws IOException if an I/O error occurs
+ */
+ public void readFully( final byte[] data )
+ throws IOException, EOFException
+ {
+ readFully( data, 0, data.length );
+ }
+
+
+ /**
+ * Invokes the delegate's read(byte[] data, int, int) method.
+ *
+ * @param data the buffer to read the bytes into
+ * @param offset The start offset
+ * @param length The number of bytes to read
+ * @throws EOFException if an end of file is reached unexpectedly
+ * @throws IOException if an I/O error occurs
+ */
+ public void readFully( final byte[] data, final int offset, final int length )
+ throws IOException, EOFException
+ {
+ int remaining = length;
+
+ while( remaining > 0 )
+ {
+ final int location = offset + length - remaining;
+ final int count = read( data, location, remaining );
+
+ if (EOF == count)
+ {
+ throw new EOFException();
+ }
+
+ remaining -= count;
+ }
+ }
+
+ /**
+ * 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
+ */
+ public int readInt()
+ throws IOException, EOFException
+ {
+ return EndianUtils.readSwappedInteger( in );
+ }
+
+ /**
+ * Not currently supported - throws {@link UnsupportedOperationException}.
+ * @return the line read
+ * @throws EOFException if an end of file is reached unexpectedly
+ * @throws IOException if an I/O error occurs
+ */
+ public String readLine()
+ throws IOException, EOFException
+ {
+ throw new UnsupportedOperationException(
+ "Operation not supported: readLine()" );
+ }
+
+ /**
+ * 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
+ */
+ public long readLong()
+ throws IOException, EOFException
+ {
+ return EndianUtils.readSwappedLong( in );
+ }
+
+ /**
+ * 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
+ */
+ public short readShort()
+ throws IOException, EOFException
+ {
+ return EndianUtils.readSwappedShort( in );
+ }
+
+ /**
+ * Invokes the delegate's read() method.
+ * @return the byte read or -1 if the end of stream
+ * @throws EOFException if an end of file is reached unexpectedly
+ * @throws IOException if an I/O error occurs
+ */
+ public int readUnsignedByte()
+ throws IOException, EOFException
+ {
+ return in.read();
+ }
+
+ /**
+ * 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
+ */
+ public int readUnsignedShort()
+ throws IOException, EOFException
+ {
+ return EndianUtils.readSwappedUnsignedShort( in );
+ }
+
+ /**
+ * Not currently supported - throws {@link UnsupportedOperationException}.
+ * @return UTF String read
+ * @throws EOFException if an end of file is reached unexpectedly
+ * @throws IOException if an I/O error occurs
+ */
+ public String readUTF()
+ throws IOException, EOFException
+ {
+ throw new UnsupportedOperationException(
+ "Operation not supported: readUTF()" );
+ }
+
+ /**
+ * Invokes the delegate's skip(int) method.
+ * @param count the number of bytes to skip
+ * @return the number of bytes to skipped or -1 if the end of stream
+ * @throws EOFException if an end of file is reached unexpectedly
+ * @throws IOException if an I/O error occurs
+ */
+ public int skipBytes( final int count )
+ throws IOException, EOFException
+ {
+ return (int)in.skip( count );
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TaggedInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TaggedInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..451e2bd1815eabff78bc008fe590768947bc43bd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TaggedInputStream.java"
@@ -0,0 +1,116 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.UUID;
+
+import org.apache.commons.io.TaggedIOException;
+
+/**
+ * An input stream decorator that tags potential exceptions so that the
+ * stream that caused the exception can easily be identified. This is
+ * done by using the {@link TaggedIOException} class to wrap all thrown
+ * {@link IOException}s. See below for an example of using this class.
+ *
+ * TaggedInputStream stream = new TaggedInputStream(...);
+ * try {
+ * // Processing that may throw an IOException either from this stream
+ * // or from some other IO activity like temporary files, etc.
+ * processStream(stream);
+ * } catch (IOException e) {
+ * if (stream.isCauseOf(e)) {
+ * // The exception was caused by this stream.
+ * // Use e.getCause() to get the original exception.
+ * } else {
+ * // The exception was caused by something else.
+ * }
+ * }
+ *
+ *
+ * Alternatively, the {@link #throwIfCauseOf(Throwable)} method can be
+ * used to let higher levels of code handle the exception caused by this
+ * stream while other processing errors are being taken care of at this
+ * lower level.
+ *
+ * TaggedInputStream stream = new TaggedInputStream(...);
+ * try {
+ * processStream(stream);
+ * } catch (IOException e) {
+ * stream.throwIfCauseOf(e);
+ * // ... or process the exception that was caused by something else
+ * }
+ *
+ *
+ * @see TaggedIOException
+ * @since 2.0
+ */
+public class TaggedInputStream extends ProxyInputStream {
+
+ /**
+ * The unique tag associated with exceptions from stream.
+ */
+ private final Serializable tag = UUID.randomUUID();
+
+ /**
+ * Creates a tagging decorator for the given input stream.
+ *
+ * @param proxy input stream to be decorated
+ */
+ public TaggedInputStream(final InputStream proxy) {
+ super(proxy);
+ }
+
+ /**
+ * Tests if the given exception was caused by this stream.
+ *
+ * @param exception an exception
+ * @return {@code true} if the exception was thrown by this stream,
+ * {@code false} otherwise
+ */
+ public boolean isCauseOf(final Throwable exception) {
+ return TaggedIOException.isTaggedWith(exception, tag);
+ }
+
+ /**
+ * Re-throws the original exception thrown by this stream. This method
+ * first checks whether the given exception is a {@link TaggedIOException}
+ * wrapper created by this decorator, and then unwraps and throws the
+ * original wrapped exception. Returns normally if the exception was
+ * not thrown by this stream.
+ *
+ * @param throwable an exception
+ * @throws IOException original exception, if any, thrown by this stream
+ */
+ public void throwIfCauseOf(final Throwable throwable) throws IOException {
+ TaggedIOException.throwCauseIfTaggedWith(throwable, tag);
+ }
+
+ /**
+ * Tags any IOExceptions thrown, wrapping and re-throwing.
+ *
+ * @param e The IOException thrown
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void handleIOException(final IOException e) throws IOException {
+ throw new TaggedIOException(e, tag);
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/Tailer.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/Tailer.java"
new file mode 100644
index 0000000000000000000000000000000000000000..e7ec91a9d39c462d162d05a7aee348cdfd46eaa1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/Tailer.java"
@@ -0,0 +1,560 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.charset.Charset;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * Simple implementation of the unix "tail -f" functionality.
+ *
+ * 1. Create a TailerListener implementation
+ *
+ * First you need to create a {@link TailerListener} implementation
+ * ({@link TailerListenerAdapter} is provided for convenience so that you don't have to
+ * implement every method).
+ *
+ *
+ * For example:
+ *
+ * public class MyTailerListener extends TailerListenerAdapter {
+ * public void handle(String line) {
+ * System.out.println(line);
+ * }
+ * }
+ *
+ * 2. Using a Tailer
+ *
+ *
+ * You can create and use a Tailer in one of three ways:
+ *
+ *
+ * Using one of the static helper methods:
+ *
+ * {@link Tailer#create(File, TailerListener)}
+ * {@link Tailer#create(File, TailerListener, long)}
+ * {@link Tailer#create(File, TailerListener, long, boolean)}
+ *
+ *
+ * Using an {@link java.util.concurrent.Executor}
+ * Using an {@link Thread}
+ *
+ *
+ *
+ * An example of each of these is shown below.
+ *
+ *
+ * 2.1 Using the static helper method
+ *
+ *
+ * TailerListener listener = new MyTailerListener();
+ * Tailer tailer = Tailer.create(file, listener, delay);
+ *
+ * 2.2 Using an Executor
+ *
+ *
+ * TailerListener listener = new MyTailerListener();
+ * Tailer tailer = new Tailer(file, listener, delay);
+ *
+ * // stupid executor impl. for demo purposes
+ * Executor executor = new Executor() {
+ * public void execute(Runnable command) {
+ * command.run();
+ * }
+ * };
+ *
+ * executor.execute(tailer);
+ *
+ *
+ *
+ * 2.3 Using a Thread
+ *
+ * TailerListener listener = new MyTailerListener();
+ * Tailer tailer = new Tailer(file, listener, delay);
+ * Thread thread = new Thread(tailer);
+ * thread.setDaemon(true); // optional
+ * thread.start();
+ *
+ * 3. Stopping a Tailer
+ * Remember to stop the tailer when you have done with it:
+ *
+ * tailer.stop();
+ *
+ *
+ * 4. Interrupting a Tailer
+ * You can interrupt the thread a tailer is running on by calling {@link Thread#interrupt()}.
+ *
+ * thread.interrupt();
+ *
+ * If you interrupt a tailer, the tailer listener is called with the {@link InterruptedException}.
+ *
+ * The file is read using the default charset; this can be overriden if necessary
+ * @see TailerListener
+ * @see TailerListenerAdapter
+ * @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()}
+ */
+public class Tailer implements Runnable {
+
+ private static final int DEFAULT_DELAY_MILLIS = 1000;
+
+ private static final String RAF_MODE = "r";
+
+ private static final int DEFAULT_BUFSIZE = 4096;
+
+ // The default charset used for reading files
+ private static final Charset DEFAULT_CHARSET = Charset.defaultCharset();
+
+ /**
+ * Buffer on top of RandomAccessFile.
+ */
+ private final byte inbuf[];
+
+ /**
+ * The file which will be tailed.
+ */
+ private final File file;
+
+ /**
+ * The character set that will be used to read the file.
+ */
+ private final Charset cset;
+
+ /**
+ * The amount of time to wait for the file to be updated.
+ */
+ private final long delayMillis;
+
+ /**
+ * Whether to tail from the end or start of file
+ */
+ private final boolean end;
+
+ /**
+ * The listener to notify of events when tailing.
+ */
+ private final TailerListener listener;
+
+ /**
+ * Whether to close and reopen the file whilst waiting for more input.
+ */
+ private final boolean reOpen;
+
+ /**
+ * The tailer will run as long as this value is true.
+ */
+ private volatile boolean run = true;
+
+ /**
+ * Creates a Tailer for the given file, starting from the beginning, with the default delay of 1.0s.
+ * @param file The file to follow.
+ * @param listener the TailerListener to use.
+ */
+ public Tailer(final File file, final TailerListener listener) {
+ this(file, listener, DEFAULT_DELAY_MILLIS);
+ }
+
+ /**
+ * Creates a Tailer for the given file, starting from the beginning.
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ */
+ public Tailer(final File file, final TailerListener listener, final long delayMillis) {
+ this(file, listener, delayMillis, false);
+ }
+
+ /**
+ * Creates a Tailer for the given file, with a delay other than the default 1.0s.
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ */
+ public Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end) {
+ this(file, listener, delayMillis, end, DEFAULT_BUFSIZE);
+ }
+
+ /**
+ * Creates a Tailer for the given file, with a delay other than the default 1.0s.
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @param reOpen if true, close and reopen the file between reading chunks
+ */
+ public Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
+ final boolean reOpen) {
+ this(file, listener, delayMillis, end, reOpen, DEFAULT_BUFSIZE);
+ }
+
+ /**
+ * Creates a Tailer for the given file, with a specified buffer size.
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @param bufSize Buffer size
+ */
+ public Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
+ final int bufSize) {
+ this(file, listener, delayMillis, end, false, bufSize);
+ }
+
+ /**
+ * Creates a Tailer for the given file, with a specified buffer size.
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @param reOpen if true, close and reopen the file between reading chunks
+ * @param bufSize Buffer size
+ */
+ public Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
+ final boolean reOpen, final int bufSize) {
+ this(file, DEFAULT_CHARSET, listener, delayMillis, end, reOpen, bufSize);
+ }
+
+ /**
+ * Creates a Tailer for the given file, with a specified buffer size.
+ * @param file the file to follow.
+ * @param cset the Charset to be used for reading the file
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @param reOpen if true, close and reopen the file between reading chunks
+ * @param bufSize Buffer size
+ */
+ public Tailer(final File file, final Charset cset, final TailerListener listener, final long delayMillis,
+ final boolean end, final boolean reOpen
+ , final int bufSize) {
+ this.file = file;
+ this.delayMillis = delayMillis;
+ this.end = end;
+
+ this.inbuf = new byte[bufSize];
+
+ // Save and prepare the listener
+ this.listener = listener;
+ listener.init(this);
+ this.reOpen = reOpen;
+ this.cset = cset;
+ }
+
+ /**
+ * Creates and starts a Tailer for the given file.
+ *
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @param bufSize buffer size.
+ * @return The new tailer
+ */
+ public static Tailer create(final File file, final TailerListener listener, final long delayMillis,
+ final boolean end, final int bufSize) {
+ return create(file, listener, delayMillis, end, false, bufSize);
+ }
+
+ /**
+ * Creates and starts a Tailer for the given file.
+ *
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @param reOpen whether to close/reopen the file between chunks
+ * @param bufSize buffer size.
+ * @return The new tailer
+ */
+ public static Tailer create(final File file, final TailerListener listener, final long delayMillis,
+ final boolean end, final boolean reOpen,
+ final int bufSize) {
+ return create(file, DEFAULT_CHARSET, listener, delayMillis, end, reOpen, bufSize);
+ }
+
+ /**
+ * Creates and starts a Tailer for the given file.
+ *
+ * @param file the file to follow.
+ * @param charset the character set to use for reading the file
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @param reOpen whether to close/reopen the file between chunks
+ * @param bufSize buffer size.
+ * @return The new tailer
+ */
+ public static Tailer create(final File file, final Charset charset, final TailerListener listener,
+ final long delayMillis, final boolean end, final boolean reOpen
+ ,final int bufSize) {
+ final Tailer tailer = new Tailer(file, charset, listener, delayMillis, end, reOpen, bufSize);
+ final Thread thread = new Thread(tailer);
+ thread.setDaemon(true);
+ thread.start();
+ return tailer;
+ }
+
+ /**
+ * Creates and starts a Tailer for the given file with default buffer size.
+ *
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @return The new tailer
+ */
+ public static Tailer create(final File file, final TailerListener listener, final long delayMillis,
+ final boolean end) {
+ return create(file, listener, delayMillis, end, DEFAULT_BUFSIZE);
+ }
+
+ /**
+ * Creates and starts a Tailer for the given file with default buffer size.
+ *
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
+ * @param reOpen whether to close/reopen the file between chunks
+ * @return The new tailer
+ */
+ public static Tailer create(final File file, final TailerListener listener, final long delayMillis,
+ final boolean end, final boolean reOpen) {
+ return create(file, listener, delayMillis, end, reOpen, DEFAULT_BUFSIZE);
+ }
+
+ /**
+ * Creates and starts a Tailer for the given file, starting at the beginning of the file
+ *
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @param delayMillis the delay between checks of the file for new content in milliseconds.
+ * @return The new tailer
+ */
+ public static Tailer create(final File file, final TailerListener listener, final long delayMillis) {
+ return create(file, listener, delayMillis, false);
+ }
+
+ /**
+ * Creates and starts a Tailer for the given file, starting at the beginning of the file
+ * with the default delay of 1.0s
+ *
+ * @param file the file to follow.
+ * @param listener the TailerListener to use.
+ * @return The new tailer
+ */
+ public static Tailer create(final File file, final TailerListener listener) {
+ return create(file, listener, DEFAULT_DELAY_MILLIS, false);
+ }
+
+ /**
+ * Return the file.
+ *
+ * @return the file
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * Gets whether to keep on running.
+ *
+ * @return whether to keep on running.
+ * @since 2.5
+ */
+ protected boolean getRun() {
+ return run;
+ }
+
+ /**
+ * Return the delay in milliseconds.
+ *
+ * @return the delay in milliseconds.
+ */
+ public long getDelay() {
+ return delayMillis;
+ }
+
+ /**
+ * Follows changes in the file, calling the TailerListener's handle method for each new line.
+ */
+ public void run() {
+ RandomAccessFile reader = null;
+ try {
+ long last = 0; // The last time the file was checked for changes
+ long position = 0; // position within the file
+ // Open the file
+ while (getRun() && reader == null) {
+ try {
+ reader = new RandomAccessFile(file, RAF_MODE);
+ } catch (final FileNotFoundException e) {
+ listener.fileNotFound();
+ }
+ if (reader == null) {
+ Thread.sleep(delayMillis);
+ } else {
+ // The current position in the file
+ position = end ? file.length() : 0;
+ last = file.lastModified();
+ reader.seek(position);
+ }
+ }
+ while (getRun()) {
+ final boolean newer = FileUtils.isFileNewer(file, last); // IO-279, must be done first
+ // Check the file length to see if it was rotated
+ final long length = file.length();
+ if (length < position) {
+ // File was rotated
+ listener.fileRotated();
+ // 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 (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();
+ }
+ continue;
+ } else {
+ // File was not rotated
+ // See if the file needs to be read again
+ if (length > position) {
+ // The file has more content than it did last time
+ position = readLines(reader);
+ last = file.lastModified();
+ } else if (newer) {
+ /*
+ * This can happen if the file is truncated or overwritten with the exact same length of
+ * information. In cases like this, the file position needs to be reset
+ */
+ position = 0;
+ reader.seek(position); // cannot be null here
+
+ // Now we can read new lines
+ position = readLines(reader);
+ last = file.lastModified();
+ }
+ }
+ if (reOpen) {
+ IOUtils.closeQuietly(reader);
+ }
+ Thread.sleep(delayMillis);
+ if (getRun() && reOpen) {
+ reader = new RandomAccessFile(file, RAF_MODE);
+ reader.seek(position);
+ }
+ }
+ } catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
+ stop(e);
+ } catch (final Exception e) {
+ stop(e);
+ } finally {
+ 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.
+ */
+ public void stop() {
+ this.run = false;
+ }
+
+ /**
+ * Read new lines.
+ *
+ * @param reader The file to read
+ * @return The new position after the lines have been read
+ * @throws java.io.IOException if an I/O error occurs.
+ */
+ private long readLines(final RandomAccessFile reader) throws IOException {
+ 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)) != 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();
+ }
+ IOUtils.closeQuietly(lineBuf); // not strictly necessary
+ reader.seek(rePos); // Ensure we can re-read if necessary
+
+ if (listener instanceof TailerListenerAdapter) {
+ ((TailerListenerAdapter) listener).endOfFileReached();
+ }
+
+ return rePos;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TailerListener.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TailerListener.java"
new file mode 100644
index 0000000000000000000000000000000000000000..b8f7f2f9543d22e5c4633956b26d792de836f640
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TailerListener.java"
@@ -0,0 +1,67 @@
+/*
+ * 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 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 {
+
+ /**
+ * The tailer will call this method during construction,
+ * giving the listener a method of stopping the tailer.
+ * @param tailer the tailer.
+ */
+ void init(Tailer tailer);
+
+ /**
+ * This method is called if the tailed file is not found.
+ *
+ * Note: this is called from the tailer thread.
+ */
+ void fileNotFound();
+
+ /**
+ * Called if a file rotation is detected.
+ *
+ * This method is called before the file is reopened, and fileNotFound may
+ * be called if the new file has not yet been created.
+ *
+ * Note: this is called from the tailer thread.
+ */
+ void fileRotated();
+
+ /**
+ * Handles a line from a Tailer.
+ *
+ * Note: this is called from the tailer thread.
+ * @param line the line.
+ */
+ void handle(String line);
+
+ /**
+ * Handles an Exception .
+ *
+ * Note: this is called from the tailer thread.
+ * @param ex the exception.
+ */
+ void handle(Exception ex);
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TailerListenerAdapter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TailerListenerAdapter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..c9626412e96d0c000684891444f108ba9cc26645
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TailerListenerAdapter.java"
@@ -0,0 +1,76 @@
+/*
+ * 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 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 {
+
+ /**
+ * The tailer will call this method during construction,
+ * giving the listener a method of stopping the tailer.
+ * @param tailer the tailer.
+ */
+ public void init(final Tailer tailer) {
+ }
+
+ /**
+ * This method is called if the tailed file is not found.
+ */
+ public void fileNotFound() {
+ }
+
+ /**
+ * Called if a file rotation is detected.
+ *
+ * This method is called before the file is reopened, and fileNotFound may
+ * be called if the new file has not yet been created.
+ */
+ public void fileRotated() {
+ }
+
+ /**
+ * Handles a line from a Tailer.
+ * @param line the line.
+ */
+ public void handle(final String line) {
+ }
+
+ /**
+ * Handles an Exception .
+ * @param ex the exception.
+ */
+ public void handle(final Exception ex) {
+ }
+
+ /**
+ * Called each time the Tailer reaches the end of the file.
+ *
+ * Note: this is called from the tailer thread.
+ *
+ * Note: a future version of commons-io will pull this method up to the TailerListener interface,
+ * for now clients must subclass this class to use this feature.
+ *
+ * @since 2.5
+ */
+ public void endOfFileReached() {
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TeeInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TeeInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..1f01b36c873b24ba0f8bdd96c0e8a372ae36fe0d
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/TeeInputStream.java"
@@ -0,0 +1,153 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * InputStream proxy that transparently writes a copy of all bytes read
+ * from the proxied stream to a given OutputStream. Using {@link #skip(long)}
+ * or {@link #mark(int)}/{@link #reset()} on the stream will result on some
+ * bytes from the input stream being skipped or duplicated in the output
+ * stream.
+ *
+ * The proxied input stream is closed when the {@link #close()} method is
+ * 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
+ */
+public class TeeInputStream extends ProxyInputStream {
+
+ /**
+ * The output stream that will receive a copy of all bytes read from the
+ * proxied input stream.
+ */
+ private final OutputStream branch;
+
+ /**
+ * Flag for closing also the associated output stream when this
+ * stream is closed.
+ */
+ private final boolean closeBranch;
+
+ /**
+ * Creates a TeeInputStream that proxies the given {@link InputStream}
+ * and copies all read bytes to the given {@link OutputStream}. The given
+ * output stream will not be closed when this stream gets closed.
+ *
+ * @param input input stream to be proxied
+ * @param branch output stream that will receive a copy of all bytes read
+ */
+ public TeeInputStream(final InputStream input, final OutputStream branch) {
+ this(input, branch, false);
+ }
+
+ /**
+ * Creates a TeeInputStream that proxies the given {@link InputStream}
+ * and copies all read bytes to the given {@link OutputStream}. The given
+ * output stream will be closed when this stream gets closed if the
+ * closeBranch parameter is {@code true}.
+ *
+ * @param input input stream to be proxied
+ * @param branch output stream that will receive a copy of all bytes read
+ * @param closeBranch flag for closing also the output stream when this
+ * stream is closed
+ */
+ public TeeInputStream(
+ final InputStream input, final OutputStream branch, final boolean closeBranch) {
+ super(input);
+ this.branch = branch;
+ this.closeBranch = closeBranch;
+ }
+
+ /**
+ * Closes the proxied input stream and, if so configured, the associated
+ * output stream. An exception thrown from one stream will not prevent
+ * closing of the other stream.
+ *
+ * @throws IOException if either of the streams could not be closed
+ */
+ @Override
+ public void close() throws IOException {
+ try {
+ super.close();
+ } finally {
+ if (closeBranch) {
+ branch.close();
+ }
+ }
+ }
+
+ /**
+ * Reads a single byte from the proxied input stream and writes it to
+ * 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)
+ */
+ @Override
+ public int read() throws IOException {
+ final int ch = super.read();
+ if (ch != EOF) {
+ branch.write(ch);
+ }
+ return ch;
+ }
+
+ /**
+ * Reads bytes from the proxied input stream and writes the read bytes
+ * to the associated output stream.
+ *
+ * @param bts byte buffer
+ * @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)
+ */
+ @Override
+ public int read(final byte[] bts, final int st, final int end) throws IOException {
+ final int n = super.read(bts, st, end);
+ if (n != -1) {
+ branch.write(bts, st, n);
+ }
+ return n;
+ }
+
+ /**
+ * Reads bytes from the proxied input stream and writes the read bytes
+ * to the associated output stream.
+ *
+ * @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)
+ */
+ @Override
+ public int read(final byte[] bts) throws IOException {
+ final int n = super.read(bts);
+ if (n != EOF) {
+ branch.write(bts, 0, n);
+ }
+ return n;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..7464c359ce1f8930f82f1f65e06f5c7bd6d03090
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java"
@@ -0,0 +1,128 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A filtering input stream that ensures the content will have unix-style line endings, LF.
+ *
+ * @since 2.5
+ */
+public class UnixLineEndingInputStream extends InputStream {
+
+ private boolean slashNSeen = false;
+
+ private boolean slashRSeen = false;
+
+ private boolean eofSeen = false;
+
+ private final InputStream target;
+
+ private final boolean ensureLineFeedAtEndOfFile;
+
+ /**
+ * Create an input stream that filters another stream
+ *
+ * @param in The input stream to wrap
+ * @param ensureLineFeedAtEndOfFile true to ensure that the file ends with LF
+ */
+ public UnixLineEndingInputStream( InputStream in, boolean ensureLineFeedAtEndOfFile ) {
+ this.target = in;
+ this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
+ }
+
+ /**
+ * Reads the next item from the target, updating internal flags in the process
+ * @return the next int read from the target stream
+ * @throws IOException upon error
+ */
+ private int readWithUpdate() throws IOException {
+ final int target = this.target.read();
+ eofSeen = target == -1;
+ if ( eofSeen ) {
+ return target;
+ }
+ slashNSeen = target == '\n';
+ slashRSeen = target == '\r';
+ return target;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int read() throws IOException {
+ boolean previousWasSlashR = slashRSeen;
+ if ( eofSeen ) {
+ return eofGame(previousWasSlashR);
+ }
+ else {
+ int target = readWithUpdate();
+ if ( eofSeen ) {
+ return eofGame(previousWasSlashR);
+ }
+ if (slashRSeen)
+ {
+ return '\n';
+ }
+
+ if ( previousWasSlashR && slashNSeen){
+ return read();
+ }
+
+ return target;
+ }
+ }
+
+ /**
+ * Handles the eof-handling at the end of the stream
+ * @param previousWasSlashR Indicates if the last seen was a \r
+ * @return The next char to output to the stream
+ */
+ private int eofGame(boolean previousWasSlashR) {
+ if ( previousWasSlashR || !ensureLineFeedAtEndOfFile ) {
+ return -1;
+ }
+ if ( !slashNSeen ) {
+ slashNSeen = true;
+ return '\n';
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * Closes the stream. Also closes the underlying stream.
+ * @throws IOException upon error
+ */
+ @Override
+ public void close() throws IOException {
+ super.close();
+ target.close();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized void mark( int readlimit ) {
+ throw new UnsupportedOperationException( "Mark notsupported" );
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..e1665188f393d2875e0d92ae62e06f4e77500293
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java"
@@ -0,0 +1,134 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A filtering input stream that ensures the content will have windows line endings, CRLF.
+ *
+ * @since 2.5
+ */
+public class WindowsLineEndingInputStream extends InputStream {
+
+ private boolean slashRSeen = false;
+
+ private boolean slashNSeen = false;
+
+ private boolean injectSlashN = false;
+
+ private boolean eofSeen = false;
+
+ private final InputStream target;
+
+ private final boolean ensureLineFeedAtEndOfFile;
+
+ /**
+ * Create an input stream that filters another stream
+ *
+ * @param in The input stream to wrap
+ * @param ensureLineFeedAtEndOfFile true to ensure that the file ends with CRLF
+ */
+ public WindowsLineEndingInputStream( InputStream in, boolean ensureLineFeedAtEndOfFile ) {
+ this.target = in;
+ this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
+ }
+
+ /**
+ * Reads the next item from the target, updating internal flags in the process
+ * @return the next int read from the target stream
+ * @throws IOException upon error
+ */
+ private int readWithUpdate() throws IOException {
+ final int target = this.target.read();
+ eofSeen = target == -1;
+ if ( eofSeen ) {
+ return target;
+ }
+ slashRSeen = target == '\r';
+ slashNSeen = target == '\n';
+ return target;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int read() throws IOException {
+ if ( eofSeen ) {
+ return eofGame();
+ } else if ( injectSlashN ) {
+ injectSlashN = false;
+ return '\n';
+ } else {
+ boolean prevWasSlashR = slashRSeen;
+ int target = readWithUpdate();
+ if ( eofSeen ) {
+ return eofGame();
+ }
+ if ( target == '\n' ) {
+ if ( !prevWasSlashR )
+ {
+ injectSlashN = true;
+ return '\r';
+ }
+ }
+ return target;
+ }
+ }
+
+ /**
+ * Handles the eof-handling at the end of the stream
+ * @return The next char to output to the stream
+ */
+
+ private int eofGame() {
+ if ( !ensureLineFeedAtEndOfFile ) {
+ return -1;
+ }
+ if ( !slashNSeen && !slashRSeen ) {
+ slashRSeen = true;
+ return '\r';
+ }
+ if ( !slashNSeen ) {
+ slashRSeen = false;
+ slashNSeen = true;
+ return '\n';
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * Closes the stream. Also closes the underlying stream.
+ * @throws IOException upon error
+ */
+ @Override
+ public void close() throws IOException {
+ super.close();
+ target.close();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized void mark( int readlimit ) {
+ throw new UnsupportedOperationException( "Mark not supported" );
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/XmlStreamReader.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/XmlStreamReader.java"
new file mode 100644
index 0000000000000000000000000000000000000000..5ac60e2ff25d62cec5185b1d4b8d6ef40126519f
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/XmlStreamReader.java"
@@ -0,0 +1,797 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.io.ByteOrderMark;
+
+/**
+ * Character stream that handles all the necessary Voodo to figure out the
+ * charset encoding of the XML document within the stream.
+ *
+ * IMPORTANT: This class is not related in any way to the org.xml.sax.XMLReader.
+ * This one IS a character stream.
+ *
+ * All this has to be done without consuming characters from the stream, if not
+ * the XML parser will not recognized the document as a valid XML. This is not
+ * 100% true, but it's close enough (UTF-8 BOM is not handled by all parsers
+ * right now, XmlStreamReader handles it and things work in all parsers).
+ *
+ * The XmlStreamReader class handles the charset encoding of XML documents in
+ * Files, raw streams and HTTP streams by offering a wide set of constructors.
+ *
+ * By default the charset encoding detection is lenient, the constructor with
+ * the lenient flag can be used for an script (following HTTP MIME and XML
+ * specifications). All this is nicely explained by Mark Pilgrim in his blog,
+ * Determining the character encoding of a feed .
+ *
+ * Originally developed for ROME under
+ * Apache License 2.0.
+ *
+ * @version $Id: XmlStreamReader.java 1686747 2015-06-21 18:44:49Z krosenvold $
+ * @see org.apache.commons.io.output.XmlStreamWriter
+ * @since 2.0
+ */
+public class XmlStreamReader extends Reader {
+ private static final int BUFFER_SIZE = 4096;
+
+ private static final String UTF_8 = "UTF-8";
+
+ private static final String US_ASCII = "US-ASCII";
+
+ private static final String UTF_16BE = "UTF-16BE";
+
+ private static final String UTF_16LE = "UTF-16LE";
+
+ private static final String UTF_32BE = "UTF-32BE";
+
+ private static final String UTF_32LE = "UTF-32LE";
+
+ private static final String UTF_16 = "UTF-16";
+
+ private static final String UTF_32 = "UTF-32";
+
+ private static final String EBCDIC = "CP1047";
+
+ private static final ByteOrderMark[] BOMS = new ByteOrderMark[] {
+ ByteOrderMark.UTF_8,
+ ByteOrderMark.UTF_16BE,
+ ByteOrderMark.UTF_16LE,
+ ByteOrderMark.UTF_32BE,
+ ByteOrderMark.UTF_32LE
+ };
+
+ // UTF_16LE and UTF_32LE have the same two starting BOM bytes.
+ private static final ByteOrderMark[] XML_GUESS_BYTES = new ByteOrderMark[] {
+ new ByteOrderMark(UTF_8, 0x3C, 0x3F, 0x78, 0x6D),
+ new ByteOrderMark(UTF_16BE, 0x00, 0x3C, 0x00, 0x3F),
+ new ByteOrderMark(UTF_16LE, 0x3C, 0x00, 0x3F, 0x00),
+ new ByteOrderMark(UTF_32BE, 0x00, 0x00, 0x00, 0x3C,
+ 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x6D),
+ new ByteOrderMark(UTF_32LE, 0x3C, 0x00, 0x00, 0x00,
+ 0x3F, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x6D, 0x00, 0x00, 0x00),
+ new ByteOrderMark(EBCDIC, 0x4C, 0x6F, 0xA7, 0x94)
+ };
+
+ private final Reader reader;
+
+ private final String encoding;
+
+ private final String defaultEncoding;
+
+ /**
+ * Returns the default encoding to use if none is set in HTTP content-type,
+ * XML prolog and the rules based on content-type are not adequate.
+ *
+ * If it is NULL the content-type based rules are used.
+ *
+ * @return the default encoding to use.
+ */
+ public String getDefaultEncoding() {
+ return defaultEncoding;
+ }
+
+ /**
+ * Creates a Reader for a File.
+ *
+ * It looks for the UTF-8 BOM first, if none sniffs the XML prolog charset,
+ * if this is also missing defaults to UTF-8.
+ *
+ * It does a lenient charset encoding detection, check the constructor with
+ * the lenient parameter for details.
+ *
+ * @param file File to create a Reader from.
+ * @throws IOException thrown if there is a problem reading the file.
+ */
+ public XmlStreamReader(final File file) throws IOException {
+ this(new FileInputStream(file));
+ }
+
+ /**
+ * Creates a Reader for a raw InputStream.
+ *
+ * It follows the same logic used for files.
+ *
+ * It does a lenient charset encoding detection, check the constructor with
+ * the lenient parameter for details.
+ *
+ * @param is InputStream to create a Reader from.
+ * @throws IOException thrown if there is a problem reading the stream.
+ */
+ public XmlStreamReader(final InputStream is) throws IOException {
+ this(is, true);
+ }
+
+ /**
+ * Creates a Reader for a raw InputStream.
+ *
+ * It follows the same logic used for files.
+ *
+ * If lenient detection is indicated and the detection above fails as per
+ * specifications it then attempts the following:
+ *
+ * If the content type was 'text/html' it replaces it with 'text/xml' and
+ * tries the detection again.
+ *
+ * Else if the XML prolog had a charset encoding that encoding is used.
+ *
+ * Else if the content type had a charset encoding that encoding is used.
+ *
+ * Else 'UTF-8' is used.
+ *
+ * If lenient detection is indicated an XmlStreamReaderException is never
+ * thrown.
+ *
+ * @param is InputStream to create a Reader from.
+ * @param lenient indicates if the charset encoding detection should be
+ * relaxed.
+ * @throws IOException thrown if there is a problem reading the stream.
+ * @throws XmlStreamReaderException thrown if the charset encoding could not
+ * be determined according to the specs.
+ */
+ public XmlStreamReader(final InputStream is, final boolean lenient) throws IOException {
+ this(is, lenient, null);
+ }
+
+ /**
+ * Creates a Reader for a raw InputStream.
+ *
+ * It follows the same logic used for files.
+ *
+ * If lenient detection is indicated and the detection above fails as per
+ * specifications it then attempts the following:
+ *
+ * If the content type was 'text/html' it replaces it with 'text/xml' and
+ * tries the detection again.
+ *
+ * Else if the XML prolog had a charset encoding that encoding is used.
+ *
+ * Else if the content type had a charset encoding that encoding is used.
+ *
+ * Else 'UTF-8' is used.
+ *
+ * If lenient detection is indicated an XmlStreamReaderException is never
+ * thrown.
+ *
+ * @param is InputStream to create a Reader from.
+ * @param lenient indicates if the charset encoding detection should be
+ * relaxed.
+ * @param defaultEncoding The default encoding
+ * @throws IOException thrown if there is a problem reading the stream.
+ * @throws XmlStreamReaderException thrown if the charset encoding could not
+ * be determined according to the specs.
+ */
+ public XmlStreamReader(final InputStream is, final boolean lenient, final String defaultEncoding)
+ throws IOException {
+ this.defaultEncoding = defaultEncoding;
+ final BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, BUFFER_SIZE), false, BOMS);
+ final BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
+ this.encoding = doRawStream(bom, pis, lenient);
+ this.reader = new InputStreamReader(pis, encoding);
+ }
+
+ /**
+ * Creates a Reader using the InputStream of a URL.
+ *
+ * If the URL is not of type HTTP and there is not 'content-type' header in
+ * the fetched data it uses the same logic used for Files.
+ *
+ * If the URL is a HTTP Url or there is a 'content-type' header in the
+ * fetched data it uses the same logic used for an InputStream with
+ * content-type.
+ *
+ * It does a lenient charset encoding detection, check the constructor with
+ * the lenient parameter for details.
+ *
+ * @param url URL to create a Reader from.
+ * @throws IOException thrown if there is a problem reading the stream of
+ * the URL.
+ */
+ public XmlStreamReader(final URL url) throws IOException {
+ this(url.openConnection(), null);
+ }
+
+ /**
+ * Creates a Reader using the InputStream of a URLConnection.
+ *
+ * If the URLConnection is not of type HttpURLConnection and there is not
+ * 'content-type' header in the fetched data it uses the same logic used for
+ * files.
+ *
+ * If the URLConnection is a HTTP Url or there is a 'content-type' header in
+ * the fetched data it uses the same logic used for an InputStream with
+ * content-type.
+ *
+ * It does a lenient charset encoding detection, check the constructor with
+ * the lenient parameter for details.
+ *
+ * @param conn URLConnection to create a Reader from.
+ * @param defaultEncoding The default encoding
+ * @throws IOException thrown if there is a problem reading the stream of
+ * the URLConnection.
+ */
+ public XmlStreamReader(final URLConnection conn, final String defaultEncoding) throws IOException {
+ this.defaultEncoding = defaultEncoding;
+ final boolean lenient = true;
+ final String contentType = conn.getContentType();
+ final InputStream is = conn.getInputStream();
+ final BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, BUFFER_SIZE), false, BOMS);
+ final BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
+ if (conn instanceof HttpURLConnection || contentType != null) {
+ this.encoding = doHttpStream(bom, pis, contentType, lenient);
+ } else {
+ this.encoding = doRawStream(bom, pis, lenient);
+ }
+ this.reader = new InputStreamReader(pis, encoding);
+ }
+
+ /**
+ * Creates a Reader using an InputStream an the associated content-type
+ * header.
+ *
+ * First it checks if the stream has BOM. If there is not BOM checks the
+ * content-type encoding. If there is not content-type encoding checks the
+ * XML prolog encoding. If there is not XML prolog encoding uses the default
+ * encoding mandated by the content-type MIME type.
+ *
+ * It does a lenient charset encoding detection, check the constructor with
+ * the lenient parameter for details.
+ *
+ * @param is InputStream to create the reader from.
+ * @param httpContentType content-type header to use for the resolution of
+ * the charset encoding.
+ * @throws IOException thrown if there is a problem reading the file.
+ */
+ public XmlStreamReader(final InputStream is, final String httpContentType)
+ throws IOException {
+ this(is, httpContentType, true);
+ }
+
+ /**
+ * Creates a Reader using an InputStream an the associated content-type
+ * header. This constructor is lenient regarding the encoding detection.
+ *
+ * First it checks if the stream has BOM. If there is not BOM checks the
+ * content-type encoding. If there is not content-type encoding checks the
+ * XML prolog encoding. If there is not XML prolog encoding uses the default
+ * encoding mandated by the content-type MIME type.
+ *
+ * If lenient detection is indicated and the detection above fails as per
+ * specifications it then attempts the following:
+ *
+ * If the content type was 'text/html' it replaces it with 'text/xml' and
+ * tries the detection again.
+ *
+ * Else if the XML prolog had a charset encoding that encoding is used.
+ *
+ * Else if the content type had a charset encoding that encoding is used.
+ *
+ * Else 'UTF-8' is used.
+ *
+ * If lenient detection is indicated an XmlStreamReaderException is never
+ * thrown.
+ *
+ * @param is InputStream to create the reader from.
+ * @param httpContentType content-type header to use for the resolution of
+ * the charset encoding.
+ * @param lenient indicates if the charset encoding detection should be
+ * relaxed.
+ * @param defaultEncoding The default encoding
+ * @throws IOException thrown if there is a problem reading the file.
+ * @throws XmlStreamReaderException thrown if the charset encoding could not
+ * be determined according to the specs.
+ */
+ public XmlStreamReader(final InputStream is, final String httpContentType,
+ final boolean lenient, final String defaultEncoding) throws IOException {
+ this.defaultEncoding = defaultEncoding;
+ final BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, BUFFER_SIZE), false, BOMS);
+ final BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);
+ this.encoding = doHttpStream(bom, pis, httpContentType, lenient);
+ this.reader = new InputStreamReader(pis, encoding);
+ }
+
+ /**
+ * Creates a Reader using an InputStream an the associated content-type
+ * header. This constructor is lenient regarding the encoding detection.
+ *
+ * First it checks if the stream has BOM. If there is not BOM checks the
+ * content-type encoding. If there is not content-type encoding checks the
+ * XML prolog encoding. If there is not XML prolog encoding uses the default
+ * encoding mandated by the content-type MIME type.
+ *
+ * If lenient detection is indicated and the detection above fails as per
+ * specifications it then attempts the following:
+ *
+ * If the content type was 'text/html' it replaces it with 'text/xml' and
+ * tries the detection again.
+ *
+ * Else if the XML prolog had a charset encoding that encoding is used.
+ *
+ * Else if the content type had a charset encoding that encoding is used.
+ *
+ * Else 'UTF-8' is used.
+ *
+ * If lenient detection is indicated an XmlStreamReaderException is never
+ * thrown.
+ *
+ * @param is InputStream to create the reader from.
+ * @param httpContentType content-type header to use for the resolution of
+ * the charset encoding.
+ * @param lenient indicates if the charset encoding detection should be
+ * relaxed.
+ * @throws IOException thrown if there is a problem reading the file.
+ * @throws XmlStreamReaderException thrown if the charset encoding could not
+ * be determined according to the specs.
+ */
+ public XmlStreamReader(final InputStream is, final String httpContentType,
+ final boolean lenient) throws IOException {
+ this(is, httpContentType, lenient, null);
+ }
+
+ /**
+ * Returns the charset encoding of the XmlStreamReader.
+ *
+ * @return charset encoding.
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * Invokes the underlying reader's read(char[], int, int) method.
+ * @param buf the buffer to read the characters into
+ * @param offset The start offset
+ * @param len The number of bytes to read
+ * @return the number of characters read or -1 if the end of stream
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public int read(final char[] buf, final int offset, final int len) throws IOException {
+ return reader.read(buf, offset, len);
+ }
+
+ /**
+ * Closes the XmlStreamReader stream.
+ *
+ * @throws IOException thrown if there was a problem closing the stream.
+ */
+ @Override
+ public void close() throws IOException {
+ reader.close();
+ }
+
+ /**
+ * Process the raw stream.
+ *
+ * @param bom BOMInputStream to detect byte order marks
+ * @param pis BOMInputStream to guess XML encoding
+ * @param lenient indicates if the charset encoding detection should be
+ * relaxed.
+ * @return the encoding to be used
+ * @throws IOException thrown if there is a problem reading the stream.
+ */
+ private String doRawStream(final BOMInputStream bom, final BOMInputStream pis, final boolean lenient)
+ throws IOException {
+ final String bomEnc = bom.getBOMCharsetName();
+ final String xmlGuessEnc = pis.getBOMCharsetName();
+ final String xmlEnc = getXmlProlog(pis, xmlGuessEnc);
+ try {
+ return calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc);
+ } catch (final XmlStreamReaderException ex) {
+ if (lenient) {
+ return doLenientDetection(null, ex);
+ } else {
+ throw ex;
+ }
+ }
+ }
+
+ /**
+ * Process a HTTP stream.
+ *
+ * @param bom BOMInputStream to detect byte order marks
+ * @param pis BOMInputStream to guess XML encoding
+ * @param httpContentType The HTTP content type
+ * @param lenient indicates if the charset encoding detection should be
+ * relaxed.
+ * @return the encoding to be used
+ * @throws IOException thrown if there is a problem reading the stream.
+ */
+ private String doHttpStream(final BOMInputStream bom, final BOMInputStream pis, final String httpContentType,
+ final boolean lenient) throws IOException {
+ final String bomEnc = bom.getBOMCharsetName();
+ final String xmlGuessEnc = pis.getBOMCharsetName();
+ final String xmlEnc = getXmlProlog(pis, xmlGuessEnc);
+ try {
+ return calculateHttpEncoding(httpContentType, bomEnc,
+ xmlGuessEnc, xmlEnc, lenient);
+ } catch (final XmlStreamReaderException ex) {
+ if (lenient) {
+ return doLenientDetection(httpContentType, ex);
+ } else {
+ throw ex;
+ }
+ }
+ }
+
+ /**
+ * Do lenient detection.
+ *
+ * @param httpContentType content-type header to use for the resolution of
+ * the charset encoding.
+ * @param ex The thrown exception
+ * @return the encoding
+ * @throws IOException thrown if there is a problem reading the stream.
+ */
+ private String doLenientDetection(String httpContentType,
+ XmlStreamReaderException ex) throws IOException {
+ if (httpContentType != null && httpContentType.startsWith("text/html")) {
+ httpContentType = httpContentType.substring("text/html".length());
+ httpContentType = "text/xml" + httpContentType;
+ try {
+ return calculateHttpEncoding(httpContentType, ex.getBomEncoding(),
+ ex.getXmlGuessEncoding(), ex.getXmlEncoding(), true);
+ } catch (final XmlStreamReaderException ex2) {
+ ex = ex2;
+ }
+ }
+ String encoding = ex.getXmlEncoding();
+ if (encoding == null) {
+ encoding = ex.getContentTypeEncoding();
+ }
+ if (encoding == null) {
+ encoding = defaultEncoding == null ? UTF_8 : defaultEncoding;
+ }
+ return encoding;
+ }
+
+ /**
+ * Calculate the raw encoding.
+ *
+ * @param bomEnc BOM encoding
+ * @param xmlGuessEnc XML Guess encoding
+ * @param xmlEnc XML encoding
+ * @return the raw encoding
+ * @throws IOException thrown if there is a problem reading the stream.
+ */
+ String calculateRawEncoding(final String bomEnc, final String xmlGuessEnc,
+ final String xmlEnc) throws IOException {
+
+ // BOM is Null
+ if (bomEnc == null) {
+ if (xmlGuessEnc == null || xmlEnc == null) {
+ return defaultEncoding == null ? UTF_8 : defaultEncoding;
+ }
+ if (xmlEnc.equals(UTF_16) &&
+ (xmlGuessEnc.equals(UTF_16BE) || xmlGuessEnc.equals(UTF_16LE))) {
+ return xmlGuessEnc;
+ }
+ return xmlEnc;
+ }
+
+ // BOM is UTF-8
+ if (bomEnc.equals(UTF_8)) {
+ if (xmlGuessEnc != null && !xmlGuessEnc.equals(UTF_8)) {
+ final String msg = MessageFormat.format(RAW_EX_1, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+ if (xmlEnc != null && !xmlEnc.equals(UTF_8)) {
+ final String msg = MessageFormat.format(RAW_EX_1, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+ return bomEnc;
+ }
+
+ // BOM is UTF-16BE or UTF-16LE
+ if (bomEnc.equals(UTF_16BE) || bomEnc.equals(UTF_16LE)) {
+ if (xmlGuessEnc != null && !xmlGuessEnc.equals(bomEnc)) {
+ final String msg = MessageFormat.format(RAW_EX_1, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+ if (xmlEnc != null && !xmlEnc.equals(UTF_16) && !xmlEnc.equals(bomEnc)) {
+ final String msg = MessageFormat.format(RAW_EX_1, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+ return bomEnc;
+ }
+
+ // BOM is UTF-32BE or UTF-32LE
+ if (bomEnc.equals(UTF_32BE) || bomEnc.equals(UTF_32LE)) {
+ if (xmlGuessEnc != null && !xmlGuessEnc.equals(bomEnc)) {
+ final String msg = MessageFormat.format(RAW_EX_1, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+ if (xmlEnc != null && !xmlEnc.equals(UTF_32) && !xmlEnc.equals(bomEnc)) {
+ final String msg = MessageFormat.format(RAW_EX_1, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+ return bomEnc;
+ }
+
+ // BOM is something else
+ final String msg = MessageFormat.format(RAW_EX_2, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+
+
+ /**
+ * Calculate the HTTP encoding.
+ *
+ * @param httpContentType The HTTP content type
+ * @param bomEnc BOM encoding
+ * @param xmlGuessEnc XML Guess encoding
+ * @param xmlEnc XML encoding
+ * @param lenient indicates if the charset encoding detection should be
+ * relaxed.
+ * @return the HTTP encoding
+ * @throws IOException thrown if there is a problem reading the stream.
+ */
+ String calculateHttpEncoding(final String httpContentType,
+ final String bomEnc, final String xmlGuessEnc, final String xmlEnc,
+ final boolean lenient) throws IOException {
+
+ // Lenient and has XML encoding
+ if (lenient && xmlEnc != null) {
+ return xmlEnc;
+ }
+
+ // Determine mime/encoding content types from HTTP Content Type
+ final String cTMime = getContentTypeMime(httpContentType);
+ final String cTEnc = getContentTypeEncoding(httpContentType);
+ final boolean appXml = isAppXml(cTMime);
+ final boolean textXml = isTextXml(cTMime);
+
+ // Mime type NOT "application/xml" or "text/xml"
+ if (!appXml && !textXml) {
+ final String msg = MessageFormat.format(HTTP_EX_3, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+
+ // No content type encoding
+ if (cTEnc == null) {
+ if (appXml) {
+ return calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc);
+ } else {
+ return defaultEncoding == null ? US_ASCII : defaultEncoding;
+ }
+ }
+
+ // UTF-16BE or UTF-16LE content type encoding
+ if (cTEnc.equals(UTF_16BE) || cTEnc.equals(UTF_16LE)) {
+ if (bomEnc != null) {
+ final String msg = MessageFormat.format(HTTP_EX_1, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+ return cTEnc;
+ }
+
+ // UTF-16 content type encoding
+ if (cTEnc.equals(UTF_16)) {
+ if (bomEnc != null && bomEnc.startsWith(UTF_16)) {
+ return bomEnc;
+ }
+ final String msg = MessageFormat.format(HTTP_EX_2, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+
+ // UTF-32BE or UTF-132E content type encoding
+ if (cTEnc.equals(UTF_32BE) || cTEnc.equals(UTF_32LE)) {
+ if (bomEnc != null) {
+ final String msg = MessageFormat.format(HTTP_EX_1, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+ return cTEnc;
+ }
+
+ // UTF-32 content type encoding
+ if (cTEnc.equals(UTF_32)) {
+ if (bomEnc != null && bomEnc.startsWith(UTF_32)) {
+ return bomEnc;
+ }
+ final String msg = MessageFormat.format(HTTP_EX_2, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ throw new XmlStreamReaderException(msg, cTMime, cTEnc, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+
+ return cTEnc;
+ }
+
+ /**
+ * Returns MIME type or NULL if httpContentType is NULL.
+ *
+ * @param httpContentType the HTTP content type
+ * @return The mime content type
+ */
+ static String getContentTypeMime(final String httpContentType) {
+ String mime = null;
+ if (httpContentType != null) {
+ final int i = httpContentType.indexOf(";");
+ if (i >= 0) {
+ mime = httpContentType.substring(0, i);
+ } else {
+ mime = httpContentType;
+ }
+ mime = mime.trim();
+ }
+ return mime;
+ }
+
+ private static final Pattern CHARSET_PATTERN = Pattern
+ .compile("charset=[\"']?([.[^; \"']]*)[\"']?");
+
+ /**
+ * Returns charset parameter value, NULL if not present, NULL if
+ * httpContentType is NULL.
+ *
+ * @param httpContentType the HTTP content type
+ * @return The content type encoding (upcased)
+ */
+ static String getContentTypeEncoding(final String httpContentType) {
+ String encoding = null;
+ if (httpContentType != null) {
+ final int i = httpContentType.indexOf(";");
+ if (i > -1) {
+ final String postMime = httpContentType.substring(i + 1);
+ final Matcher m = CHARSET_PATTERN.matcher(postMime);
+ encoding = m.find() ? m.group(1) : null;
+ encoding = encoding != null ? encoding.toUpperCase(Locale.US) : null;
+ }
+ }
+ return encoding;
+ }
+
+ public static final Pattern ENCODING_PATTERN = Pattern.compile(
+ "<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:'.[^']*'))",
+ Pattern.MULTILINE);
+
+ /**
+ * Returns the encoding declared in the , NULL if none.
+ *
+ * @param is InputStream to create the reader from.
+ * @param guessedEnc guessed encoding
+ * @return the encoding declared in the
+ * @throws IOException thrown if there is a problem reading the stream.
+ */
+ private static String getXmlProlog(final InputStream is, final String guessedEnc)
+ throws IOException {
+ String encoding = null;
+ if (guessedEnc != null) {
+ final byte[] bytes = new byte[BUFFER_SIZE];
+ is.mark(BUFFER_SIZE);
+ int offset = 0;
+ int max = BUFFER_SIZE;
+ int c = is.read(bytes, offset, max);
+ int firstGT = -1;
+ String xmlProlog = ""; // avoid possible NPE warning (cannot happen; this just silences the warning)
+ while (c != -1 && firstGT == -1 && offset < BUFFER_SIZE) {
+ offset += c;
+ max -= c;
+ c = is.read(bytes, offset, max);
+ xmlProlog = new String(bytes, 0, offset, guessedEnc);
+ firstGT = xmlProlog.indexOf('>');
+ }
+ if (firstGT == -1) {
+ if (c == -1) {
+ throw new IOException("Unexpected end of XML stream");
+ } else {
+ throw new IOException(
+ "XML prolog or ROOT element not found on first "
+ + offset + " bytes");
+ }
+ }
+ final int bytesRead = offset;
+ if (bytesRead > 0) {
+ is.reset();
+ final BufferedReader bReader = new BufferedReader(new StringReader(
+ xmlProlog.substring(0, firstGT + 1)));
+ final StringBuffer prolog = new StringBuffer();
+ String line = bReader.readLine();
+ while (line != null) {
+ prolog.append(line);
+ line = bReader.readLine();
+ }
+ final Matcher m = ENCODING_PATTERN.matcher(prolog);
+ if (m.find()) {
+ encoding = m.group(1).toUpperCase();
+ encoding = encoding.substring(1, encoding.length() - 1);
+ }
+ }
+ }
+ return encoding;
+ }
+
+ /**
+ * Indicates if the MIME type belongs to the APPLICATION XML family.
+ *
+ * @param mime The mime type
+ * @return true if the mime type belongs to the APPLICATION XML family,
+ * otherwise false
+ */
+ static boolean isAppXml(final String mime) {
+ return mime != null &&
+ (mime.equals("application/xml") ||
+ mime.equals("application/xml-dtd") ||
+ mime.equals("application/xml-external-parsed-entity") ||
+ mime.startsWith("application/") && mime.endsWith("+xml"));
+ }
+
+ /**
+ * Indicates if the MIME type belongs to the TEXT XML family.
+ *
+ * @param mime The mime type
+ * @return true if the mime type belongs to the TEXT XML family,
+ * otherwise false
+ */
+ static boolean isTextXml(final String mime) {
+ return mime != null &&
+ (mime.equals("text/xml") ||
+ mime.equals("text/xml-external-parsed-entity") ||
+ mime.startsWith("text/") && mime.endsWith("+xml"));
+ }
+
+ private static final String RAW_EX_1 =
+ "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch";
+
+ private static final String RAW_EX_2 =
+ "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM";
+
+ private static final String HTTP_EX_1 =
+ "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL";
+
+ private static final String HTTP_EX_2 =
+ "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch";
+
+ private static final String HTTP_EX_3 =
+ "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Invalid MIME";
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/XmlStreamReaderException.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/XmlStreamReaderException.java"
new file mode 100644
index 0000000000000000000000000000000000000000..0037100c3d977c22bebdb1d11a5b0323629de5ef
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/XmlStreamReaderException.java"
@@ -0,0 +1,136 @@
+/*
+ * 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 org.apache.commons.io.input;
+
+import java.io.IOException;
+
+/**
+ * The XmlStreamReaderException is thrown by the XmlStreamReader constructors if
+ * the charset encoding can not be determined according to the XML 1.0
+ * specification and RFC 3023.
+ *
+ * The exception returns the unconsumed InputStream to allow the application to
+ * do an alternate processing with the stream. Note that the original
+ * 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 {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String bomEncoding;
+
+ private final String xmlGuessEncoding;
+
+ private final String xmlEncoding;
+
+ private final String contentTypeMime;
+
+ private final String contentTypeEncoding;
+
+ /**
+ * Creates an exception instance if the charset encoding could not be
+ * determined.
+ *
+ * Instances of this exception are thrown by the XmlStreamReader.
+ *
+ * @param msg message describing the reason for the exception.
+ * @param bomEnc BOM encoding.
+ * @param xmlGuessEnc XML guess encoding.
+ * @param xmlEnc XML prolog encoding.
+ */
+ public XmlStreamReaderException(final String msg, final String bomEnc,
+ final String xmlGuessEnc, final String xmlEnc) {
+ this(msg, null, null, bomEnc, xmlGuessEnc, xmlEnc);
+ }
+
+ /**
+ * Creates an exception instance if the charset encoding could not be
+ * determined.
+ *
+ * Instances of this exception are thrown by the XmlStreamReader.
+ *
+ * @param msg message describing the reason for the exception.
+ * @param ctMime MIME type in the content-type.
+ * @param ctEnc encoding in the content-type.
+ * @param bomEnc BOM encoding.
+ * @param xmlGuessEnc XML guess encoding.
+ * @param xmlEnc XML prolog encoding.
+ */
+ public XmlStreamReaderException(final String msg, final String ctMime, final String ctEnc,
+ final String bomEnc, final String xmlGuessEnc, final String xmlEnc) {
+ super(msg);
+ contentTypeMime = ctMime;
+ contentTypeEncoding = ctEnc;
+ bomEncoding = bomEnc;
+ xmlGuessEncoding = xmlGuessEnc;
+ xmlEncoding = xmlEnc;
+ }
+
+ /**
+ * Returns the BOM encoding found in the InputStream.
+ *
+ * @return the BOM encoding, null if none.
+ */
+ public String getBomEncoding() {
+ return bomEncoding;
+ }
+
+ /**
+ * Returns the encoding guess based on the first bytes of the InputStream.
+ *
+ * @return the encoding guess, null if it couldn't be guessed.
+ */
+ public String getXmlGuessEncoding() {
+ return xmlGuessEncoding;
+ }
+
+ /**
+ * Returns the encoding found in the XML prolog of the InputStream.
+ *
+ * @return the encoding of the XML prolog, null if none.
+ */
+ public String getXmlEncoding() {
+ return xmlEncoding;
+ }
+
+ /**
+ * Returns the MIME type in the content-type used to attempt determining the
+ * encoding.
+ *
+ * @return the MIME type in the content-type, null if there was not
+ * content-type or the encoding detection did not involve HTTP.
+ */
+ public String getContentTypeMime() {
+ return contentTypeMime;
+ }
+
+ /**
+ * Returns the encoding in the content-type used to attempt determining the
+ * encoding.
+ *
+ * @return the encoding in the content-type, null if there was not
+ * content-type, no encoding in it or the encoding detection did not
+ * involve HTTP.
+ */
+ public String getContentTypeEncoding() {
+ return contentTypeEncoding;
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/package.html" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/package.html"
new file mode 100644
index 0000000000000000000000000000000000000000..440fa0f7ee52a73adc66a0d95aadb56cc3ebea7c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/input/package.html"
@@ -0,0 +1,25 @@
+
+
+
+
+
+This package provides implementations of input classes, such as
+InputStream and Reader.
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationListener.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationListener.java"
new file mode 100644
index 0000000000000000000000000000000000000000..1bff081f07bee6b665efcb4fd300105d84637a8c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationListener.java"
@@ -0,0 +1,86 @@
+/*
+ * 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 org.apache.commons.io.monitor;
+import java.io.File;
+
+/**
+ * A listener that receives events of file system modifications.
+ *
+ * Register {@link FileAlterationListener}s with a {@link FileAlterationObserver}.
+ *
+ * @see FileAlterationObserver
+ * @version $Id: FileAlterationListener.java 1304052 2012-03-22 20:55:29Z ggregory $
+ * @since 2.0
+ */
+public interface FileAlterationListener {
+
+ /**
+ * File system observer started checking event.
+ *
+ * @param observer The file system observer
+ */
+ void onStart(final FileAlterationObserver observer);
+
+ /**
+ * 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);
+
+ /**
+ * File system observer finished checking event.
+ *
+ * @param observer The file system observer
+ */
+ void onStop(final FileAlterationObserver observer);
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java"
new file mode 100644
index 0000000000000000000000000000000000000000..9afad6e853839d5448502ffb89bb66ef2df8fecd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java"
@@ -0,0 +1,94 @@
+/*
+ * 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 org.apache.commons.io.monitor;
+
+import java.io.File;
+
+/**
+ * Convenience {@link FileAlterationListener} implementation that does nothing.
+ *
+ * @see FileAlterationObserver
+ * @version $Id: FileAlterationListenerAdaptor.java 1304062 2012-03-22 21:10:46Z sebb $
+ * @since 2.0
+ */
+public class FileAlterationListenerAdaptor implements FileAlterationListener {
+
+ /**
+ * File system observer started checking event.
+ *
+ * @param observer The file system observer (ignored)
+ */
+ public void onStart(final FileAlterationObserver observer) {
+ }
+
+ /**
+ * Directory created Event.
+ *
+ * @param directory The directory created (ignored)
+ */
+ public void onDirectoryCreate(final File directory) {
+ }
+
+ /**
+ * Directory changed Event.
+ *
+ * @param directory The directory changed (ignored)
+ */
+ public void onDirectoryChange(final File directory) {
+ }
+
+ /**
+ * Directory deleted Event.
+ *
+ * @param directory The directory deleted (ignored)
+ */
+ public void onDirectoryDelete(final File directory) {
+ }
+
+ /**
+ * File created Event.
+ *
+ * @param file The file created (ignored)
+ */
+ public void onFileCreate(final File file) {
+ }
+
+ /**
+ * File changed Event.
+ *
+ * @param file The file changed (ignored)
+ */
+ public void onFileChange(final File file) {
+ }
+
+ /**
+ * File deleted Event.
+ *
+ * @param file The file deleted (ignored)
+ */
+ public void onFileDelete(final File file) {
+ }
+
+ /**
+ * File system observer finished checking event.
+ *
+ * @param observer The file system observer (ignored)
+ */
+ public void onStop(final FileAlterationObserver observer) {
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java"
new file mode 100644
index 0000000000000000000000000000000000000000..344371998db12de38d9db350998661d47df114f6
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java"
@@ -0,0 +1,193 @@
+/*
+ * 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 org.apache.commons.io.monitor;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+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: FileAlterationMonitor.java 1415850 2012-11-30 20:51:39Z ggregory $
+ * @since 2.0
+ */
+public final class FileAlterationMonitor implements Runnable {
+
+ private final long interval;
+ private final List observers = new CopyOnWriteArrayList();
+ private Thread thread = null;
+ private ThreadFactory threadFactory;
+ private volatile boolean running = false;
+
+ /**
+ * Construct a monitor with a default interval of 10 seconds.
+ */
+ public FileAlterationMonitor() {
+ this(10000);
+ }
+
+ /**
+ * Construct a monitor with the specified interval.
+ *
+ * @param interval The amount of time in miliseconds to wait between
+ * checks of the file system
+ */
+ public FileAlterationMonitor(final long interval) {
+ this.interval = interval;
+ }
+
+ /**
+ * Construct a monitor with the specified interval and set of observers.
+ *
+ * @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.
+ */
+ public FileAlterationMonitor(final long interval, final FileAlterationObserver... observers) {
+ this(interval);
+ if (observers != null) {
+ for (final FileAlterationObserver observer : observers) {
+ addObserver(observer);
+ }
+ }
+ }
+
+ /**
+ * Return the interval.
+ *
+ * @return the interval
+ */
+ public long getInterval() {
+ return interval;
+ }
+
+ /**
+ * Set the thread factory.
+ *
+ * @param threadFactory the thread factory
+ */
+ public synchronized void setThreadFactory(final ThreadFactory threadFactory) {
+ this.threadFactory = threadFactory;
+ }
+
+ /**
+ * Add a file system observer to this monitor.
+ *
+ * @param observer The file system observer to add
+ */
+ public void addObserver(final FileAlterationObserver observer) {
+ if (observer != null) {
+ observers.add(observer);
+ }
+ }
+
+ /**
+ * Remove a file system observer from this monitor.
+ *
+ * @param observer The file system observer to remove
+ */
+ public void removeObserver(final FileAlterationObserver observer) {
+ if (observer != null) {
+ while (observers.remove(observer)) {
+ }
+ }
+ }
+
+ /**
+ * Returns the set of {@link FileAlterationObserver} registered with
+ * this monitor.
+ *
+ * @return The set of {@link FileAlterationObserver}
+ */
+ public Iterable getObservers() {
+ return observers;
+ }
+
+ /**
+ * Start monitoring.
+ *
+ * @throws Exception if an error occurs initializing the observer
+ */
+ public synchronized void start() throws Exception {
+ if (running) {
+ throw new IllegalStateException("Monitor is already running");
+ }
+ for (final FileAlterationObserver observer : observers) {
+ observer.initialize();
+ }
+ running = true;
+ if (threadFactory != null) {
+ thread = threadFactory.newThread(this);
+ } else {
+ thread = new Thread(this);
+ }
+ thread.start();
+ }
+
+ /**
+ * Stop monitoring.
+ *
+ * @throws Exception if an error occurs initializing the observer
+ */
+ public synchronized void stop() throws Exception {
+ stop(interval);
+ }
+
+ /**
+ * Stop monitoring.
+ *
+ * @param stopInterval the amount of time in milliseconds to wait for the thread to finish.
+ * A value of zero will wait until the thread is finished (see {@link Thread#join(long)}).
+ * @throws Exception if an error occurs initializing the observer
+ * @since 2.1
+ */
+ public synchronized void stop(final long stopInterval) throws Exception {
+ if (running == false) {
+ throw new IllegalStateException("Monitor is not running");
+ }
+ running = false;
+ try {
+ thread.join(stopInterval);
+ } catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ for (final FileAlterationObserver observer : observers) {
+ observer.destroy();
+ }
+ }
+
+ /**
+ * Run.
+ */
+ public void run() {
+ while (running) {
+ for (final FileAlterationObserver observer : observers) {
+ observer.checkAndNotify();
+ }
+ if (!running) {
+ break;
+ }
+ try {
+ Thread.sleep(interval);
+ } catch (final InterruptedException ignored) {
+ }
+ }
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d28248dbff1ffe535f91d3b6752ca851695468bc
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java"
@@ -0,0 +1,474 @@
+/*
+ * 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 org.apache.commons.io.monitor;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOCase;
+import org.apache.commons.io.comparator.NameFileComparator;
+
+/**
+ * FileAlterationObserver represents the state of files below a root directory,
+ * checking the filesystem and notifying listeners of create, change or
+ * delete events.
+ *
+ * To use this implementation:
+ *
+ * Create {@link FileAlterationListener} implementation(s) that process
+ * the file/directory create, change and delete events
+ * Register the listener(s) with a {@link FileAlterationObserver} for
+ * the appropriate directory.
+ * Either register the observer(s) with a {@link FileAlterationMonitor} or
+ * run manually.
+ *
+ *
+ * Basic Usage
+ * Create a {@link FileAlterationObserver} for the directory and register the listeners:
+ *
+ * File directory = new File(new File("."), "src");
+ * FileAlterationObserver observer = new FileAlterationObserver(directory);
+ * observer.addListener(...);
+ * observer.addListener(...);
+ *
+ * To manually observe a directory, initialize the observer and invoked the
+ * {@link #checkAndNotify()} method as required:
+ *
+ * // intialize
+ * observer.init();
+ * ...
+ * // invoke as required
+ * observer.checkAndNotify();
+ * ...
+ * observer.checkAndNotify();
+ * ...
+ * // finished
+ * observer.finish();
+ *
+ * Alternatively, register the oberver(s) with a {@link FileAlterationMonitor},
+ * which creates a new thread, invoking the observer at the specified interval:
+ *
+ * long interval = ...
+ * FileAlterationMonitor monitor = new FileAlterationMonitor(interval);
+ * monitor.addObserver(observer);
+ * monitor.start();
+ * ...
+ * monitor.stop();
+ *
+ *
+ * File Filters
+ * This implementation can monitor portions of the file system
+ * by using {@link FileFilter}s to observe only the files and/or directories
+ * that are of interest. This makes it more efficient and reduces the
+ * noise from unwanted file system events.
+ *
+ * Commons IO has a good range of
+ * useful, ready made
+ * File Filter
+ * implementations for this purpose.
+ *
+ * For example, to only observe 1) visible directories and 2) files with a ".java" suffix
+ * in a root directory called "src" you could set up a {@link FileAlterationObserver} in the following
+ * way:
+ *
+ * // Create a FileFilter
+ * IOFileFilter directories = FileFilterUtils.and(
+ * FileFilterUtils.directoryFileFilter(),
+ * HiddenFileFilter.VISIBLE);
+ * IOFileFilter files = FileFilterUtils.and(
+ * FileFilterUtils.fileFileFilter(),
+ * FileFilterUtils.suffixFileFilter(".java"));
+ * IOFileFilter filter = FileFilterUtils.or(directories, files);
+ *
+ * // Create the File system observer and register File Listeners
+ * FileAlterationObserver observer = new FileAlterationObserver(new File("src"), filter);
+ * observer.addListener(...);
+ * observer.addListener(...);
+ *
+ *
+ * FileEntry
+ * {@link FileEntry} represents the state of a file or directory, capturing
+ * {@link File} attributes at a point in time. Custom implementations of
+ * {@link FileEntry} can be used to capture additional properties that the
+ * basic implementation does not support. The {@link FileEntry#refresh(File)}
+ * method is used to determine if a file or directory has changed since the last
+ * check and stores the current state of the {@link File}'s properties.
+ *
+ * @see FileAlterationListener
+ * @see FileAlterationMonitor
+ * @version $Id: FileAlterationObserver.java 1686747 2015-06-21 18:44:49Z krosenvold $
+ * @since 2.0
+ */
+public class FileAlterationObserver implements Serializable {
+
+ private static final long serialVersionUID = 1185122225658782848L;
+ private final List listeners = new CopyOnWriteArrayList();
+ private final FileEntry rootEntry;
+ private final FileFilter fileFilter;
+ private final Comparator comparator;
+
+ /**
+ * Construct an observer for the specified directory.
+ *
+ * @param directoryName the name of the directory to observe
+ */
+ public FileAlterationObserver(final String directoryName) {
+ this(new File(directoryName));
+ }
+
+ /**
+ * Construct an observer for the specified directory and file filter.
+ *
+ * @param directoryName the name of the directory to observe
+ * @param fileFilter The file filter or null if none
+ */
+ public FileAlterationObserver(final String directoryName, final FileFilter fileFilter) {
+ this(new File(directoryName), fileFilter);
+ }
+
+ /**
+ * Construct an observer for the specified directory, file filter and
+ * file comparator.
+ *
+ * @param directoryName the name of the directory to observe
+ * @param fileFilter The file filter or null if none
+ * @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive
+ */
+ public FileAlterationObserver(final String directoryName, final FileFilter fileFilter,
+ final IOCase caseSensitivity) {
+ this(new File(directoryName), fileFilter, caseSensitivity);
+ }
+
+ /**
+ * Construct an observer for the specified directory.
+ *
+ * @param directory the directory to observe
+ */
+ public FileAlterationObserver(final File directory) {
+ this(directory, null);
+ }
+
+ /**
+ * Construct an observer for the specified directory and file filter.
+ *
+ * @param directory the directory to observe
+ * @param fileFilter The file filter or null if none
+ */
+ public FileAlterationObserver(final File directory, final FileFilter fileFilter) {
+ this(directory, fileFilter, null);
+ }
+
+ /**
+ * Construct an observer for the specified directory, file filter and
+ * file comparator.
+ *
+ * @param directory the directory to observe
+ * @param fileFilter The file filter or null if none
+ * @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive
+ */
+ public FileAlterationObserver(final File directory, final FileFilter fileFilter, final IOCase caseSensitivity) {
+ this(new FileEntry(directory), fileFilter, caseSensitivity);
+ }
+
+ /**
+ * Construct an observer for the specified directory, file filter and
+ * file comparator.
+ *
+ * @param rootEntry the root directory to observe
+ * @param fileFilter The file filter or null if none
+ * @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive
+ */
+ protected FileAlterationObserver(final FileEntry rootEntry, final FileFilter fileFilter,
+ final IOCase caseSensitivity) {
+ if (rootEntry == null) {
+ throw new IllegalArgumentException("Root entry is missing");
+ }
+ if (rootEntry.getFile() == null) {
+ throw new IllegalArgumentException("Root directory is missing");
+ }
+ this.rootEntry = rootEntry;
+ this.fileFilter = fileFilter;
+ if (caseSensitivity == null || caseSensitivity.equals(IOCase.SYSTEM)) {
+ this.comparator = NameFileComparator.NAME_SYSTEM_COMPARATOR;
+ } else if (caseSensitivity.equals(IOCase.INSENSITIVE)) {
+ this.comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR;
+ } else {
+ this.comparator = NameFileComparator.NAME_COMPARATOR;
+ }
+ }
+
+ /**
+ * Return the directory being observed.
+ *
+ * @return the directory being observed
+ */
+ public File getDirectory() {
+ return rootEntry.getFile();
+ }
+
+ /**
+ * Return the fileFilter.
+ *
+ * @return the fileFilter
+ * @since 2.1
+ */
+ public FileFilter getFileFilter() {
+ return fileFilter;
+ }
+
+ /**
+ * Add a file system listener.
+ *
+ * @param listener The file system listener
+ */
+ public void addListener(final FileAlterationListener listener) {
+ if (listener != null) {
+ listeners.add(listener);
+ }
+ }
+
+ /**
+ * Remove a file system listener.
+ *
+ * @param listener The file system listener
+ */
+ public void removeListener(final FileAlterationListener listener) {
+ if (listener != null) {
+ while (listeners.remove(listener)) {
+ }
+ }
+ }
+
+ /**
+ * Returns the set of registered file system listeners.
+ *
+ * @return The file system listeners
+ */
+ public Iterable getListeners() {
+ return listeners;
+ }
+
+ /**
+ * Initialize the observer.
+ *
+ * @throws Exception if an error occurs
+ */
+ public void initialize() throws Exception {
+ rootEntry.refresh(rootEntry.getFile());
+ final FileEntry[] children = doListFiles(rootEntry.getFile(), rootEntry);
+ rootEntry.setChildren(children);
+ }
+
+ /**
+ * Final processing.
+ *
+ * @throws Exception if an error occurs
+ */
+ public void destroy() throws Exception {
+ }
+
+ /**
+ * Check whether the file and its chlidren have been created, modified or deleted.
+ */
+ public void checkAndNotify() {
+
+ /* fire onStart() */
+ for (final FileAlterationListener listener : listeners) {
+ listener.onStart(this);
+ }
+
+ /* fire directory/file events */
+ final File rootFile = rootEntry.getFile();
+ if (rootFile.exists()) {
+ checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootFile));
+ } else if (rootEntry.isExists()) {
+ checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY);
+ } else {
+ // Didn't exist and still doesn't
+ }
+
+ /* fire onStop() */
+ for (final FileAlterationListener listener : listeners) {
+ listener.onStop(this);
+ }
+ }
+
+ /**
+ * Compare two file lists for files which have been created, modified or deleted.
+ *
+ * @param parent The parent entry
+ * @param previous The original list of files
+ * @param files The current list of files
+ */
+ private void checkAndNotify(final FileEntry parent, final FileEntry[] previous, final File[] files) {
+ int c = 0;
+ final FileEntry[] current = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES;
+ for (final FileEntry entry : previous) {
+ while (c < files.length && comparator.compare(entry.getFile(), files[c]) > 0) {
+ current[c] = createFileEntry(parent, files[c]);
+ doCreate(current[c]);
+ c++;
+ }
+ if (c < files.length && comparator.compare(entry.getFile(), files[c]) == 0) {
+ doMatch(entry, files[c]);
+ checkAndNotify(entry, entry.getChildren(), listFiles(files[c]));
+ current[c] = entry;
+ c++;
+ } else {
+ checkAndNotify(entry, entry.getChildren(), FileUtils.EMPTY_FILE_ARRAY);
+ doDelete(entry);
+ }
+ }
+ for (; c < files.length; c++) {
+ current[c] = createFileEntry(parent, files[c]);
+ doCreate(current[c]);
+ }
+ parent.setChildren(current);
+ }
+
+ /**
+ * Create a new file entry for the specified file.
+ *
+ * @param parent The parent file entry
+ * @param file The file to create an entry for
+ * @return A new file entry
+ */
+ private FileEntry createFileEntry(final FileEntry parent, final File file) {
+ final FileEntry entry = parent.newChildInstance(file);
+ entry.refresh(file);
+ final FileEntry[] children = doListFiles(file, entry);
+ entry.setChildren(children);
+ return entry;
+ }
+
+ /**
+ * List the files
+ * @param file The file to list files for
+ * @param entry the parent entry
+ * @return The child files
+ */
+ 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++) {
+ children[i] = createFileEntry(entry, files[i]);
+ }
+ return children;
+ }
+
+ /**
+ * Fire directory/file created events to the registered listeners.
+ *
+ * @param entry The file entry
+ */
+ private void doCreate(final FileEntry entry) {
+ for (final FileAlterationListener listener : listeners) {
+ if (entry.isDirectory()) {
+ listener.onDirectoryCreate(entry.getFile());
+ } else {
+ listener.onFileCreate(entry.getFile());
+ }
+ }
+ final FileEntry[] children = entry.getChildren();
+ for (final FileEntry aChildren : children) {
+ doCreate(aChildren);
+ }
+ }
+
+ /**
+ * Fire directory/file change events to the registered listeners.
+ *
+ * @param entry The previous file system entry
+ * @param file The current file
+ */
+ private void doMatch(final FileEntry entry, final File file) {
+ if (entry.refresh(file)) {
+ for (final FileAlterationListener listener : listeners) {
+ if (entry.isDirectory()) {
+ listener.onDirectoryChange(file);
+ } else {
+ listener.onFileChange(file);
+ }
+ }
+ }
+ }
+
+ /**
+ * Fire directory/file delete events to the registered listeners.
+ *
+ * @param entry The file entry
+ */
+ private void doDelete(final FileEntry entry) {
+ for (final FileAlterationListener listener : listeners) {
+ if (entry.isDirectory()) {
+ listener.onDirectoryDelete(entry.getFile());
+ } else {
+ listener.onFileDelete(entry.getFile());
+ }
+ }
+ }
+
+ /**
+ * List the contents of a directory
+ *
+ * @param file The file to list the contents of
+ * @return the directory contents or a zero length array if
+ * the empty or the file is not a directory
+ */
+ private File[] listFiles(final File file) {
+ File[] children = null;
+ if (file.isDirectory()) {
+ children = fileFilter == null ? file.listFiles() : file.listFiles(fileFilter);
+ }
+ if (children == null) {
+ children = FileUtils.EMPTY_FILE_ARRAY;
+ }
+ if (comparator != null && children.length > 1) {
+ Arrays.sort(children, comparator);
+ }
+ return children;
+ }
+
+ /**
+ * Provide a String representation of this observer.
+ *
+ * @return a String representation of this observer
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(getClass().getSimpleName());
+ builder.append("[file='");
+ builder.append(getDirectory().getPath());
+ builder.append('\'');
+ if (fileFilter != null) {
+ builder.append(", ");
+ builder.append(fileFilter.toString());
+ }
+ builder.append(", listeners=");
+ builder.append(listeners.size());
+ builder.append("]");
+ return builder.toString();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileEntry.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileEntry.java"
new file mode 100644
index 0000000000000000000000000000000000000000..bbd942bd5e58c37b6c864682b8bab9dd3145eff7
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/FileEntry.java"
@@ -0,0 +1,271 @@
+/*
+ * 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 org.apache.commons.io.monitor;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * The state of a file or directory, capturing the following {@link File} attributes at a point in time.
+ *
+ * File Name (see {@link File#getName()})
+ * Exists - whether the file exists or not (see {@link File#exists()})
+ * Directory - whether the file is a directory or not (see {@link File#isDirectory()})
+ * Last Modified Date/Time (see {@link File#lastModified()})
+ * Length (see {@link File#length()}) - directories treated as zero
+ * Children - contents of a directory (see {@link File#listFiles(java.io.FileFilter)})
+ *
+ *
+ * Custom Implementations
+ *
+ * If the state of additional {@link File} attributes is required then create a custom
+ * {@link FileEntry} with properties for those attributes. Override the
+ * {@link #newChildInstance(File)} to return a new instance of the appropriate type.
+ * You may also want to override the {@link #refresh(File)} method.
+ *
+ * @see FileAlterationObserver
+ * @since 2.0
+ */
+public class FileEntry implements Serializable {
+
+ private static final long serialVersionUID = -2505664948818681153L;
+
+ static final FileEntry[] EMPTY_ENTRIES = new FileEntry[0];
+
+ private final FileEntry parent;
+ private FileEntry[] children;
+ private final File file;
+ private String name;
+ private boolean exists;
+ private boolean directory;
+ private long lastModified;
+ private long length;
+
+ /**
+ * Construct a new monitor for a specified {@link File}.
+ *
+ * @param file The file being monitored
+ */
+ public FileEntry(final File file) {
+ this(null, file);
+ }
+
+ /**
+ * Construct a new monitor for a specified {@link File}.
+ *
+ * @param parent The parent
+ * @param file The file being monitored
+ */
+ public FileEntry(final FileEntry parent, final File file) {
+ if (file == null) {
+ throw new IllegalArgumentException("File is missing");
+ }
+ this.file = file;
+ this.parent = parent;
+ this.name = file.getName();
+ }
+
+ /**
+ * Refresh the attributes from the {@link File}, indicating
+ * whether the file has changed.
+ *
+ * This implementation refreshes the name, exists,
+ * directory, lastModified and length
+ * properties.
+ *
+ * The exists, directory, lastModified
+ * and length properties are compared for changes
+ *
+ * @param file the file instance to compare to
+ * @return {@code true} if the file has changed, otherwise {@code false}
+ */
+ public boolean refresh(final File file) {
+
+ // cache original values
+ final boolean origExists = exists;
+ final long origLastModified = lastModified;
+ final boolean origDirectory = directory;
+ final long origLength = length;
+
+ // refresh the values
+ name = file.getName();
+ exists = file.exists();
+ directory = exists && file.isDirectory();
+ lastModified = exists ? file.lastModified() : 0;
+ length = exists && !directory ? file.length() : 0;
+
+ // Return if there are changes
+ return exists != origExists ||
+ lastModified != origLastModified ||
+ directory != origDirectory ||
+ length != origLength;
+ }
+
+ /**
+ * Create a new child instance.
+ *
+ * Custom implementations should override this method to return
+ * a new instance of the appropriate type.
+ *
+ * @param file The child file
+ * @return a new child instance
+ */
+ public FileEntry newChildInstance(final File file) {
+ return new FileEntry(this, file);
+ }
+
+ /**
+ * Return the parent entry.
+ *
+ * @return the parent entry
+ */
+ public FileEntry getParent() {
+ return parent;
+ }
+
+ /**
+ * Return the level
+ *
+ * @return the level
+ */
+ public int getLevel() {
+ return parent == null ? 0 : parent.getLevel() + 1;
+ }
+
+ /**
+ * Return the directory's files.
+ *
+ * @return This directory's files or an empty
+ * array if the file is not a directory or the
+ * directory is empty
+ */
+ public FileEntry[] getChildren() {
+ return children != null ? children : EMPTY_ENTRIES;
+ }
+
+ /**
+ * Set the directory's files.
+ *
+ * @param children This directory's files, may be null
+ */
+ public void setChildren(final FileEntry[] children) {
+ this.children = children;
+ }
+
+ /**
+ * Return the file being monitored.
+ *
+ * @return the file being monitored
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * Return the file name.
+ *
+ * @return the file name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set the file name.
+ *
+ * @param name the file name
+ */
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Return the last modified time from the last time it
+ * was checked.
+ *
+ * @return the last modified time
+ */
+ public long getLastModified() {
+ return lastModified;
+ }
+
+ /**
+ * Return the last modified time from the last time it
+ * was checked.
+ *
+ * @param lastModified The last modified time
+ */
+ public void setLastModified(final long lastModified) {
+ this.lastModified = lastModified;
+ }
+
+ /**
+ * Return the length.
+ *
+ * @return the length
+ */
+ public long getLength() {
+ return length;
+ }
+
+ /**
+ * Set the length.
+ *
+ * @param length the length
+ */
+ public void setLength(final long length) {
+ this.length = length;
+ }
+
+ /**
+ * Indicate whether the file existed the last time it
+ * was checked.
+ *
+ * @return whether the file existed
+ */
+ public boolean isExists() {
+ return exists;
+ }
+
+ /**
+ * Set whether the file existed the last time it
+ * was checked.
+ *
+ * @param exists whether the file exists or not
+ */
+ public void setExists(final boolean exists) {
+ this.exists = exists;
+ }
+
+ /**
+ * Indicate whether the file is a directory or not.
+ *
+ * @return whether the file is a directory or not
+ */
+ public boolean isDirectory() {
+ return directory;
+ }
+
+ /**
+ * Set whether the file is a directory or not.
+ *
+ * @param directory whether the file is a directory or not
+ */
+ public void setDirectory(final boolean directory) {
+ this.directory = directory;
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/package.html" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/package.html"
new file mode 100644
index 0000000000000000000000000000000000000000..82c1eaede9472eb1cb323c8d5899ccb69050f987
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/monitor/package.html"
@@ -0,0 +1,25 @@
+
+
+
+
+
+This package provides a component for monitoring file system events
+(directory and file create, update and delete events).
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/AppendableOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/AppendableOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..379be10e079f2a9230eb4bfd2225a89945594c76
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/AppendableOutputStream.java"
@@ -0,0 +1,66 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * OutputStream implementation that writes the data to an {@link Appendable}
+ * Object.
+ *
+ * For example, can be used with any {@link java.io.Writer} or a {@link java.lang.StringBuilder}
+ * or {@link java.lang.StringBuffer}.
+ *
+ * @since 2.5
+ * @see java.lang.Appendable
+ * @version $Id: AppendableOutputStream.java 1687815 2015-06-26 17:18:56Z krosenvold $
+ */
+public class AppendableOutputStream extends OutputStream {
+
+ private final T appendable;
+
+ /**
+ * Construct a new instance with the specified appendable.
+ *
+ * @param appendable the appendable to write to
+ */
+ public AppendableOutputStream(T appendable) {
+ this.appendable = appendable;
+ }
+
+ /**
+ * Write a character to the underlying appendable.
+ *
+ * @param b the character to write
+ * @throws IOException upon error
+ */
+ @Override
+ public void write(int b) throws IOException {
+ appendable.append((char)b);
+ }
+
+ /**
+ * Return the target appendable.
+ *
+ * @return the target appendable
+ */
+ public T getAppendable() {
+ return appendable;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/BrokenOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/BrokenOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..1f149ffa870d4f4d9e1945669f656fd9ebe2f973
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/BrokenOutputStream.java"
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Broken output stream. This stream always throws an {@link IOException} from
+ * all {@link OutputStream} methods.
+ *
+ * This class is mostly useful for testing error handling in code that uses an
+ * output stream.
+ *
+ * @since 2.0
+ */
+public class BrokenOutputStream extends OutputStream {
+
+ /**
+ * The exception that is thrown by all methods of this class.
+ */
+ private final IOException exception;
+
+ /**
+ * Creates a new stream that always throws the given exception.
+ *
+ * @param exception the exception to be thrown
+ */
+ public BrokenOutputStream(final IOException exception) {
+ this.exception = exception;
+ }
+
+ /**
+ * Creates a new stream that always throws an {@link IOException}
+ */
+ public BrokenOutputStream() {
+ this(new IOException("Broken output stream"));
+ }
+
+ /**
+ * Throws the configured exception.
+ *
+ * @param b ignored
+ * @throws IOException always thrown
+ */
+ @Override
+ public void write(final int b) throws IOException {
+ throw exception;
+ }
+
+ /**
+ * Throws the configured exception.
+ *
+ * @throws IOException always thrown
+ */
+ @Override
+ public void flush() throws IOException {
+ throw exception;
+ }
+
+ /**
+ * Throws the configured exception.
+ *
+ * @throws IOException always thrown
+ */
+ @Override
+ public void close() throws IOException {
+ throw exception;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ba87e9b3dc1b4f605b1d6849bb7c8d639441bcf3
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java"
@@ -0,0 +1,420 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import static org.apache.commons.io.IOUtils.EOF;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.SequenceInputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.io.input.ClosedInputStream;
+
+/**
+ * This class implements an output stream in which the data is
+ * written into a byte array. The buffer automatically grows as data
+ * is written to it.
+ *
+ * The data can be retrieved using toByteArray() and
+ * toString().
+ *
+ * Closing a {@code ByteArrayOutputStream} has no effect. The methods in
+ * this class can be called after the stream has been closed without
+ * generating an {@code IOException}.
+ *
+ * This is an alternative implementation of the {@link java.io.ByteArrayOutputStream}
+ * class. The original implementation only allocates 32 bytes at the beginning.
+ * As this class is designed for heavy duty it starts at 1024 bytes. In contrast
+ * to the original it doesn't reallocate the whole memory block but allocates
+ * additional buffers. This way no buffers need to be garbage collected and
+ * the contents don't have to be copied to the new buffer. This class is
+ * 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 {
+
+ /** A singleton empty byte array. */
+ private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+
+ /** The list of buffers, which grows and never reduces. */
+ private final List buffers = new ArrayList();
+ /** The index of the current buffer. */
+ private int currentBufferIndex;
+ /** The total count of bytes in all the filled buffers. */
+ private int filledBufferSum;
+ /** The current buffer. */
+ private byte[] currentBuffer;
+ /** The total count of bytes written. */
+ private int count;
+ /** Flag to indicate if the buffers can be reused after reset */
+ private boolean reuseBuffers = true;
+
+ /**
+ * Creates a new byte array output stream. The buffer capacity is
+ * initially 1024 bytes, though its size increases if necessary.
+ */
+ public ByteArrayOutputStream() {
+ this(1024);
+ }
+
+ /**
+ * Creates a new byte array output stream, with a buffer capacity of
+ * the specified size, in bytes.
+ *
+ * @param size the initial size
+ * @throws IllegalArgumentException if size is negative
+ */
+ public ByteArrayOutputStream(final int size) {
+ if (size < 0) {
+ throw new IllegalArgumentException(
+ "Negative initial size: " + size);
+ }
+ synchronized (this) {
+ needNewBuffer(size);
+ }
+ }
+
+ /**
+ * Makes a new buffer available either by allocating
+ * a new one or re-cycling an existing one.
+ *
+ * @param newcount the size of the buffer if one is created
+ */
+ private void needNewBuffer(final int newcount) {
+ if (currentBufferIndex < buffers.size() - 1) {
+ //Recycling old buffer
+ filledBufferSum += currentBuffer.length;
+
+ currentBufferIndex++;
+ currentBuffer = buffers.get(currentBufferIndex);
+ } else {
+ //Creating new buffer
+ int newBufferSize;
+ if (currentBuffer == null) {
+ newBufferSize = newcount;
+ filledBufferSum = 0;
+ } else {
+ newBufferSize = Math.max(
+ currentBuffer.length << 1,
+ newcount - filledBufferSum);
+ filledBufferSum += currentBuffer.length;
+ }
+
+ currentBufferIndex++;
+ currentBuffer = new byte[newBufferSize];
+ buffers.add(currentBuffer);
+ }
+ }
+
+ /**
+ * Write the bytes to byte array.
+ * @param b the bytes to write
+ * @param off The start offset
+ * @param len The number of bytes to write
+ */
+ @Override
+ public void write(final byte[] b, final int off, final int len) {
+ if ((off < 0)
+ || (off > b.length)
+ || (len < 0)
+ || ((off + len) > b.length)
+ || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return;
+ }
+ synchronized (this) {
+ final int newcount = count + len;
+ int remaining = len;
+ int inBufferPos = count - filledBufferSum;
+ while (remaining > 0) {
+ final int part = Math.min(remaining, currentBuffer.length - inBufferPos);
+ System.arraycopy(b, off + len - remaining, currentBuffer, inBufferPos, part);
+ remaining -= part;
+ if (remaining > 0) {
+ needNewBuffer(newcount);
+ inBufferPos = 0;
+ }
+ }
+ count = newcount;
+ }
+ }
+
+ /**
+ * Write a byte to byte array.
+ * @param b the byte to write
+ */
+ @Override
+ public synchronized void write(final int b) {
+ int inBufferPos = count - filledBufferSum;
+ if (inBufferPos == currentBuffer.length) {
+ needNewBuffer(count + 1);
+ inBufferPos = 0;
+ }
+ currentBuffer[inBufferPos] = (byte) b;
+ count++;
+ }
+
+ /**
+ * Writes the entire contents of the specified input stream to this
+ * byte stream. Bytes from the input stream are read directly into the
+ * internal buffers of this streams.
+ *
+ * @param in the input stream to read from
+ * @return total number of bytes read from the input stream
+ * (and written to this stream)
+ * @throws IOException if an I/O error occurs while reading the input stream
+ * @since 1.4
+ */
+ public synchronized int write(final InputStream in) throws IOException {
+ int readCount = 0;
+ int inBufferPos = count - filledBufferSum;
+ int n = in.read(currentBuffer, inBufferPos, currentBuffer.length - inBufferPos);
+ while (n != EOF) {
+ readCount += n;
+ inBufferPos += n;
+ count += n;
+ if (inBufferPos == currentBuffer.length) {
+ needNewBuffer(currentBuffer.length);
+ inBufferPos = 0;
+ }
+ n = in.read(currentBuffer, inBufferPos, currentBuffer.length - inBufferPos);
+ }
+ return readCount;
+ }
+
+ /**
+ * Return the current size of the byte array.
+ * @return the current size of the byte array
+ */
+ public synchronized int size() {
+ return count;
+ }
+
+ /**
+ * Closing a {@code ByteArrayOutputStream} has no effect. The methods in
+ * this class can be called after the stream has been closed without
+ * generating an {@code IOException}.
+ *
+ * @throws IOException never (this method should not declare this exception
+ * but it has to now due to backwards compatibility)
+ */
+ @Override
+ public void close() throws IOException {
+ //nop
+ }
+
+ /**
+ * @see java.io.ByteArrayOutputStream#reset()
+ */
+ public synchronized void reset() {
+ count = 0;
+ filledBufferSum = 0;
+ currentBufferIndex = 0;
+ if (reuseBuffers) {
+ currentBuffer = buffers.get(currentBufferIndex);
+ } else {
+ //Throw away old buffers
+ currentBuffer = null;
+ int size = buffers.get(0).length;
+ buffers.clear();
+ needNewBuffer(size);
+ reuseBuffers = true;
+ }
+ }
+
+ /**
+ * Writes the entire contents of this byte stream to the
+ * specified output stream.
+ *
+ * @param out the output stream to write to
+ * @throws IOException if an I/O error occurs, such as if the stream is closed
+ * @see java.io.ByteArrayOutputStream#writeTo(OutputStream)
+ */
+ public synchronized void writeTo(final OutputStream out) throws IOException {
+ int remaining = count;
+ for (final byte[] buf : buffers) {
+ final int c = Math.min(buf.length, remaining);
+ out.write(buf, 0, c);
+ remaining -= c;
+ if (remaining == 0) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * Fetches entire contents of an InputStream and represent
+ * same data as result InputStream.
+ *
+ * This method is useful where,
+ *
+ * Source InputStream is slow.
+ * It has network resources associated, so we cannot keep it open for
+ * long time.
+ * It has network timeout associated.
+ *
+ * It can be used in favor of {@link #toByteArray()}, since it
+ * avoids unnecessary allocation and copy of byte[].
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input Stream to be fully buffered.
+ * @return A fully buffered stream.
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ public static InputStream toBufferedInputStream(final InputStream input)
+ throws IOException {
+ return toBufferedInputStream(input, 1024);
+ }
+
+ /**
+ * Fetches entire contents of an InputStream and represent
+ * same data as result InputStream.
+ *
+ * This method is useful where,
+ *
+ * Source InputStream is slow.
+ * It has network resources associated, so we cannot keep it open for
+ * long time.
+ * It has network timeout associated.
+ *
+ * It can be used in favor of {@link #toByteArray()}, since it
+ * avoids unnecessary allocation and copy of byte[].
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream.
+ *
+ * @param input Stream to be fully buffered.
+ * @param size the initial buffer size
+ * @return A fully buffered stream.
+ * @throws IOException if an I/O error occurs
+ * @since 2.5
+ */
+ 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")
+ final ByteArrayOutputStream output = new ByteArrayOutputStream(size);
+ output.write(input);
+ return output.toInputStream();
+ }
+
+ /**
+ * Gets the current contents of this byte stream as a Input Stream. The
+ * returned stream is backed by buffers of this stream,
+ * avoiding memory allocation and copy, thus saving space and time.
+ *
+ * @return the current contents of this output stream.
+ * @see java.io.ByteArrayOutputStream#toByteArray()
+ * @see #reset()
+ * @since 2.5
+ */
+ public synchronized InputStream toInputStream() {
+ int remaining = count;
+ if (remaining == 0) {
+ return new ClosedInputStream();
+ }
+ final List list = new ArrayList(buffers.size());
+ for (final byte[] buf : buffers) {
+ final int c = Math.min(buf.length, remaining);
+ list.add(new ByteArrayInputStream(buf, 0, c));
+ remaining -= c;
+ if (remaining == 0) {
+ break;
+ }
+ }
+ reuseBuffers = false;
+ return new SequenceInputStream(Collections.enumeration(list));
+ }
+
+ /**
+ * 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
+ * @see java.io.ByteArrayOutputStream#toByteArray()
+ */
+ public synchronized byte[] toByteArray() {
+ int remaining = count;
+ if (remaining == 0) {
+ return EMPTY_BYTE_ARRAY;
+ }
+ final byte newbuf[] = new byte[remaining];
+ int pos = 0;
+ for (final byte[] buf : buffers) {
+ final int c = Math.min(buf.length, remaining);
+ System.arraycopy(buf, 0, newbuf, pos, c);
+ pos += c;
+ remaining -= c;
+ if (remaining == 0) {
+ break;
+ }
+ }
+ return newbuf;
+ }
+
+ /**
+ * 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()
+ * @deprecated 2.5 use {@link #toString(String)} instead
+ */
+ @Override
+ @Deprecated
+ public String toString() {
+ // make explicit the use of the default charset
+ return new String(toByteArray(), Charset.defaultCharset());
+ }
+
+ /**
+ * Gets the curent contents of this byte stream as a string
+ * using the specified encoding.
+ *
+ * @param enc the name of the character encoding
+ * @return the string converted from the byte array
+ * @throws UnsupportedEncodingException if the encoding is not supported
+ * @see java.io.ByteArrayOutputStream#toString(String)
+ */
+ public String toString(final String enc) throws UnsupportedEncodingException {
+ return new String(toByteArray(), enc);
+ }
+
+ /**
+ * Gets the curent contents of this byte stream as a string
+ * using the specified encoding.
+ *
+ * @param charset the character encoding
+ * @return the string converted from the byte array
+ * @see java.io.ByteArrayOutputStream#toString(String)
+ * @since 2.5
+ */
+ public String toString(final Charset charset) {
+ return new String(toByteArray(), charset);
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..995ca0d10b091e7436c2c4c4da886049af5f4703
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java"
@@ -0,0 +1,87 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * OutputStream which breaks larger output blocks into chunks.
+ * Native code may need to copy the input array; if the write buffer
+ * is very large this can cause OOME.
+ *
+ * @since 2.5
+ */
+public class ChunkedOutputStream extends FilterOutputStream {
+
+ /**
+ * The default chunk size to use, i.e. {@value} bytes.
+ */
+ private static final int DEFAULT_CHUNK_SIZE = 1024 * 4;
+
+ /**
+ * The maximum chunk size to us when writing data arrays
+ */
+ private final int chunkSize;
+
+ /**
+ * Creates a new stream that uses the specified chunk size.
+ *
+ * @param stream the stream to wrap
+ * @param chunkSize the chunk size to use; must be a positive number.
+ * @throws IllegalArgumentException if the chunk size is <= 0
+ */
+ public ChunkedOutputStream(final OutputStream stream, int chunkSize) {
+ super(stream);
+ if (chunkSize <= 0) {
+ throw new IllegalArgumentException();
+ }
+ this.chunkSize = chunkSize;
+ }
+
+ /**
+ * 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) {
+ this(stream, DEFAULT_CHUNK_SIZE);
+ }
+
+ /**
+ * Writes the data buffer in chunks to the underlying stream
+ *
+ * @param data the data to write
+ * @param srcOffset the offset
+ * @param length the length of data to write
+ *
+ * @throws IOException if an I/O error occurs.
+ */
+ @Override
+ public void write(byte[] data, int srcOffset, int length) throws IOException {
+ int bytes = length;
+ int dstOffset = srcOffset;
+ while(bytes > 0) {
+ int chunk = Math.min(bytes, chunkSize);
+ out.write(data, dstOffset, chunk);
+ bytes -= chunk;
+ dstOffset += chunk;
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ChunkedWriter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ChunkedWriter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..13826debc9ede17a8a0fcb0129cc82f031cc926e
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ChunkedWriter.java"
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * Writer which breaks larger output blocks into chunks.
+ * Native code may need to copy the input array; if the write buffer
+ * is very large this can cause OOME.
+ *
+ * @since 2.5
+ */
+public class ChunkedWriter extends FilterWriter {
+
+ /**
+ * The default chunk size to use, i.e. {@value} bytes.
+ */
+ private static final int DEFAULT_CHUNK_SIZE = 1024 * 4;
+
+ /**
+ * The maximum chunk size to us when writing data arrays
+ */
+ private final int chunkSize;
+
+ /**
+ * Creates a new writer that uses the specified chunk size.
+ *
+ * @param writer the writer to wrap
+ * @param chunkSize the chunk size to use; must be a positive number.
+ * @throws IllegalArgumentException if the chunk size is <= 0
+ */
+ public ChunkedWriter(final Writer writer, int chunkSize) {
+ super(writer);
+ if (chunkSize <= 0) {
+ throw new IllegalArgumentException();
+ }
+ this.chunkSize = chunkSize;
+ }
+
+ /**
+ * Creates a new writer that uses a chunk size of {@link #DEFAULT_CHUNK_SIZE}
+ * @param writer the writer to wrap
+ */
+ public ChunkedWriter(final Writer writer) {
+ this(writer, DEFAULT_CHUNK_SIZE);
+ }
+
+ /**
+ * writes the data buffer in chunks to the underlying writer
+ * @param data The data
+ * @param srcOffset the offset
+ * @param length the number of bytes to write
+ *
+ * @throws IOException upon error
+ */
+ @Override
+ public void write(char[] data, int srcOffset, int length) throws IOException {
+ int bytes = length;
+ int dstOffset = srcOffset;
+ while(bytes > 0) {
+ int chunk = Math.min(bytes, chunkSize);
+ out.write(data, dstOffset, chunk);
+ bytes -= chunk;
+ dstOffset += chunk;
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ded1c8887dbfd28e49e53f8caa15a53f903204fd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java"
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.OutputStream;
+
+/**
+ * Proxy stream that prevents the underlying output stream from being closed.
+ *
+ * This class is typically used in cases where an output stream needs to be
+ * passed to a component that wants to explicitly close the stream even if
+ * other components would still use the stream for output.
+ *
+ * @version $Id: CloseShieldOutputStream.java 1674710 2015-04-20 00:25:55Z ggregory $
+ * @since 1.4
+ */
+public class CloseShieldOutputStream extends ProxyOutputStream {
+
+ /**
+ * Creates a proxy that shields the given output stream from being
+ * closed.
+ *
+ * @param out underlying output stream
+ */
+ public CloseShieldOutputStream(final OutputStream out) {
+ super(out);
+ }
+
+ /**
+ * Replaces the underlying output stream with a {@link ClosedOutputStream}
+ * sentinel. The original output stream will remain open, but this proxy
+ * will appear closed.
+ */
+ @Override
+ public void close() {
+ out = new ClosedOutputStream();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ClosedOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ClosedOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..d339abb546006c04270cfdbfdfcdd78459321491
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ClosedOutputStream.java"
@@ -0,0 +1,51 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Closed output stream. This stream throws an exception on all attempts to
+ * write something to the stream.
+ *
+ * Typically uses of this class include testing for corner cases in methods
+ * that accept an output stream and acting as a sentinel value instead of
+ * a {@code null} output stream.
+ *
+ * @version $Id: ClosedOutputStream.java 1471767 2013-04-24 23:24:19Z sebb $
+ * @since 1.4
+ */
+public class ClosedOutputStream extends OutputStream {
+
+ /**
+ * A singleton.
+ */
+ public static final ClosedOutputStream CLOSED_OUTPUT_STREAM = new ClosedOutputStream();
+
+ /**
+ * Throws an {@link IOException} to indicate that the stream is closed.
+ *
+ * @param b ignored
+ * @throws IOException always thrown
+ */
+ @Override
+ public void write(final int b) throws IOException {
+ throw new IOException("write(" + b + ") failed: stream is closed");
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/CountingOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/CountingOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..7bad42b23fbbb4491f76650e5ffa231d8547dc6f
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/CountingOutputStream.java"
@@ -0,0 +1,124 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.OutputStream;
+
+/**
+ * A decorating output stream that counts the number of bytes that have passed
+ * through the stream so far.
+ *
+ * A typical use case would be during debugging, to ensure that data is being
+ * written as expected.
+ *
+ * @version $Id: CountingOutputStream.java 1415850 2012-11-30 20:51:39Z ggregory $
+ */
+public class CountingOutputStream extends ProxyOutputStream {
+
+ /** The count of bytes that have passed. */
+ private long count = 0;
+
+ /**
+ * Constructs a new CountingOutputStream.
+ *
+ * @param out the OutputStream to write to
+ */
+ public CountingOutputStream( final OutputStream out ) {
+ super(out);
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Updates the count with the number of bytes that are being written.
+ *
+ * @param n number of bytes to be written to the stream
+ * @since 2.0
+ */
+ @Override
+ protected synchronized void beforeWrite(final int n) {
+ count += n;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * The number of bytes that have passed through this stream.
+ *
+ * NOTE: From v1.3 this method throws an ArithmeticException if the
+ * count is greater than can be expressed by an int.
+ * See {@link #getByteCount()} for a method using a long.
+ *
+ * @return the number of bytes accumulated
+ * @throws ArithmeticException if the byte count is too large
+ */
+ public int getCount() {
+ final long result = getByteCount();
+ if (result > Integer.MAX_VALUE) {
+ throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");
+ }
+ return (int) result;
+ }
+
+ /**
+ * Set the byte count back to 0.
+ *
+ * NOTE: From v1.3 this method throws an ArithmeticException if the
+ * count is greater than can be expressed by an int.
+ * See {@link #resetByteCount()} for a method using a long.
+ *
+ * @return the count previous to resetting
+ * @throws ArithmeticException if the byte count is too large
+ */
+ public int resetCount() {
+ final long result = resetByteCount();
+ if (result > Integer.MAX_VALUE) {
+ throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");
+ }
+ return (int) result;
+ }
+
+ /**
+ * The number of bytes that have passed through this stream.
+ *
+ * NOTE: This method is an alternative for getCount().
+ * It was added because that method returns an integer which will
+ * result in incorrect count for files over 2GB.
+ *
+ * @return the number of bytes accumulated
+ * @since 1.3
+ */
+ public synchronized long getByteCount() {
+ return this.count;
+ }
+
+ /**
+ * Set the byte count back to 0.
+ *
+ * NOTE: This method is an alternative for resetCount().
+ * It was added because that method returns an integer which will
+ * result in incorrect count for files over 2GB.
+ *
+ * @return the count previous to resetting
+ * @since 1.3
+ */
+ public synchronized long resetByteCount() {
+ final long tmp = this.count;
+ this.count = 0;
+ return tmp;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..56ad2ff8dc2c752f2f707c1f75843d38a48f3d03
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java"
@@ -0,0 +1,289 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+
+
+/**
+ * An output stream which will retain data in memory until a specified
+ * threshold is reached, and only then commit it to disk. If the stream is
+ * closed before the threshold is reached, the data will not be written to
+ * disk at all.
+ *
+ * This class originated in FileUpload processing. In this use case, you do
+ * not know in advance the size of the file being uploaded. If the file is small
+ * you want to store it in memory (for speed), but if the file is large you want
+ * to store it to file (to avoid memory issues).
+ *
+ * @version $Id: DeferredFileOutputStream.java 1686747 2015-06-21 18:44:49Z krosenvold $
+ */
+public class DeferredFileOutputStream
+ extends ThresholdingOutputStream
+{
+
+ // ----------------------------------------------------------- Data members
+
+
+ /**
+ * The output stream to which data will be written prior to the theshold
+ * being reached.
+ */
+ private ByteArrayOutputStream memoryOutputStream;
+
+
+ /**
+ * The output stream to which data will be written at any given time. This
+ * will always be one of memoryOutputStream or
+ * diskOutputStream.
+ */
+ private OutputStream currentOutputStream;
+
+
+ /**
+ * The file to which output will be directed if the threshold is exceeded.
+ */
+ private File outputFile;
+
+ /**
+ * The temporary file prefix.
+ */
+ private final String prefix;
+
+ /**
+ * The temporary file suffix.
+ */
+ private final String suffix;
+
+ /**
+ * The directory to use for temporary files.
+ */
+ private final File directory;
+
+
+ /**
+ * True when close() has been called successfully.
+ */
+ private boolean closed = false;
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Constructs an instance of this class which will trigger an event at the
+ * specified threshold, and save data to a file beyond that point.
+ *
+ * @param threshold The number of bytes at which to trigger an event.
+ * @param outputFile The file to which data is saved beyond the threshold.
+ */
+ public DeferredFileOutputStream(final int threshold, final File outputFile)
+ {
+ this(threshold, outputFile, null, null, null);
+ }
+
+
+ /**
+ * Constructs an instance of this class which will trigger an event at the
+ * specified threshold, and save data to a temporary file beyond that point.
+ *
+ * @param threshold The number of bytes at which to trigger an event.
+ * @param prefix Prefix to use for the temporary file.
+ * @param suffix Suffix to use for the temporary file.
+ * @param directory Temporary file directory.
+ *
+ * @since 1.4
+ */
+ public DeferredFileOutputStream(final int threshold, final String prefix, final String suffix, final File directory)
+ {
+ this(threshold, null, prefix, suffix, directory);
+ if (prefix == null) {
+ throw new IllegalArgumentException("Temporary file prefix is missing");
+ }
+ }
+
+ /**
+ * Constructs an instance of this class which will trigger an event at the
+ * specified threshold, and save data either to a file beyond that point.
+ *
+ * @param threshold The number of bytes at which to trigger an event.
+ * @param outputFile The file to which data is saved beyond the threshold.
+ * @param prefix Prefix to use for the temporary file.
+ * @param suffix Suffix to use for the temporary file.
+ * @param directory Temporary file directory.
+ */
+ private DeferredFileOutputStream(final int threshold, final File outputFile, final String prefix,
+ final String suffix, final File directory) {
+ super(threshold);
+ this.outputFile = outputFile;
+
+ memoryOutputStream = new ByteArrayOutputStream();
+ currentOutputStream = memoryOutputStream;
+ this.prefix = prefix;
+ this.suffix = suffix;
+ this.directory = directory;
+ }
+
+
+ // --------------------------------------- ThresholdingOutputStream methods
+
+
+ /**
+ * Returns the current output stream. This may be memory based or disk
+ * based, depending on the current state with respect to the threshold.
+ *
+ * @return The underlying output stream.
+ *
+ * @exception IOException if an error occurs.
+ */
+ @Override
+ protected OutputStream getStream() throws IOException
+ {
+ return currentOutputStream;
+ }
+
+
+ /**
+ * Switches the underlying output stream from a memory based stream to one
+ * that is backed by disk. This is the point at which we realise that too
+ * much data is being written to keep in memory, so we elect to switch to
+ * disk-based storage.
+ *
+ * @exception IOException if an error occurs.
+ */
+ @Override
+ protected void thresholdReached() throws IOException
+ {
+ if (prefix != null) {
+ outputFile = File.createTempFile(prefix, suffix, directory);
+ }
+ final FileOutputStream fos = new FileOutputStream(outputFile);
+ try {
+ memoryOutputStream.writeTo(fos);
+ } catch (IOException e){
+ fos.close();
+ throw e;
+ }
+ currentOutputStream = fos;
+ memoryOutputStream = null;
+ }
+
+
+ // --------------------------------------------------------- Public methods
+
+
+ /**
+ * Determines whether or not the data for this output stream has been
+ * retained in memory.
+ *
+ * @return {@code true} if the data is available in memory;
+ * {@code false} otherwise.
+ */
+ public boolean isInMemory()
+ {
+ return !isThresholdExceeded();
+ }
+
+
+ /**
+ * Returns the data for this output stream as an array of bytes, assuming
+ * that the data has been retained in memory. If the data was written to
+ * disk, this method returns {@code null}.
+ *
+ * @return The data for this output stream, or {@code null} if no such
+ * data is available.
+ */
+ public byte[] getData()
+ {
+ if (memoryOutputStream != null)
+ {
+ return memoryOutputStream.toByteArray();
+ }
+ return null;
+ }
+
+
+ /**
+ * Returns either the output file specified in the constructor or
+ * the temporary file created or null.
+ *
+ * If the constructor specifying the file is used then it returns that
+ * same output file, even when threshold has not been reached.
+ *
+ * If constructor specifying a temporary file prefix/suffix is used
+ * then the temporary file created once the threshold is reached is returned
+ * If the threshold was not reached then {@code null} is returned.
+ *
+ * @return The file for this output stream, or {@code null} if no such
+ * file exists.
+ */
+ public File getFile()
+ {
+ return outputFile;
+ }
+
+
+ /**
+ * Closes underlying output stream, and mark this as closed
+ *
+ * @exception IOException if an error occurs.
+ */
+ @Override
+ public void close() throws IOException
+ {
+ super.close();
+ closed = true;
+ }
+
+
+ /**
+ * Writes the data from this output stream to the specified output stream,
+ * after it has been closed.
+ *
+ * @param out output stream to write to.
+ * @exception IOException if this stream is not yet closed or an error occurs.
+ */
+ public void writeTo(final OutputStream out) throws IOException
+ {
+ // we may only need to check if this is closed if we are working with a file
+ // but we should force the habit of closing wether we are working with
+ // a file or memory.
+ if (!closed)
+ {
+ throw new IOException("Stream not closed");
+ }
+
+ if(isInMemory())
+ {
+ memoryOutputStream.writeTo(out);
+ }
+ else
+ {
+ final FileInputStream fis = new FileInputStream(outputFile);
+ try {
+ IOUtils.copy(fis, out);
+ } finally {
+ IOUtils.closeQuietly(fis);
+ }
+ }
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/DemuxOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/DemuxOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..49db43b9d259a1b300b9fb139eb9cdf118706a0c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/DemuxOutputStream.java"
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Forwards data to a stream that has been associated with this thread.
+ *
+ * @version $Id: DemuxOutputStream.java 1737901 2016-04-06 00:23:36Z ggregory $
+ */
+public class DemuxOutputStream extends OutputStream {
+ private final InheritableThreadLocal outputStreamThreadLocal = new InheritableThreadLocal();
+
+ /**
+ * Binds the specified stream to the current thread.
+ *
+ * @param output
+ * the stream to bind
+ * @return the OutputStream that was previously active
+ */
+ public OutputStream bindStream(final OutputStream output) {
+ final OutputStream stream = outputStreamThreadLocal.get();
+ outputStreamThreadLocal.set(output);
+ return stream;
+ }
+
+ /**
+ * Closes stream associated with current thread.
+ *
+ * @throws IOException
+ * if an error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ final OutputStream output = outputStreamThreadLocal.get();
+ if (null != output) {
+ output.close();
+ }
+ }
+
+ /**
+ * Flushes stream associated with current thread.
+ *
+ * @throws IOException
+ * if an error occurs
+ */
+ @Override
+ public void flush() throws IOException {
+ @SuppressWarnings("resource")
+ final OutputStream output = outputStreamThreadLocal.get();
+ if (null != output) {
+ output.flush();
+ }
+ }
+
+ /**
+ * Writes byte to stream associated with current thread.
+ *
+ * @param ch
+ * the byte to write to stream
+ * @throws IOException
+ * if an error occurs
+ */
+ @Override
+ public void write(final int ch) throws IOException {
+ @SuppressWarnings("resource")
+ final OutputStream output = outputStreamThreadLocal.get();
+ if (null != output) {
+ output.write(ch);
+ }
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java"
new file mode 100644
index 0000000000000000000000000000000000000000..4959156a7efa2c0eef23c6def34b1262fdcc359d
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java"
@@ -0,0 +1,335 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * Writer of files that allows the encoding to be set.
+ *
+ * This class provides a simple alternative to FileWriter
+ * that allows an encoding to be set. Unfortunately, it cannot subclass
+ * FileWriter.
+ *
+ * By default, the file will be overwritten, but this may be changed to append.
+ *
+ * The encoding must be specified using either the name of the {@link Charset},
+ * the {@link Charset}, or a {@link CharsetEncoder}. If the default encoding
+ * is required then use the {@link java.io.FileWriter} directly, rather than
+ * this implementation.
+ *
+ *
+ *
+ * @since 1.4
+ * @version $Id: FileWriterWithEncoding.java 1686747 2015-06-21 18:44:49Z krosenvold $
+ */
+public class FileWriterWithEncoding extends Writer {
+ // Cannot extend ProxyWriter, as requires writer to be
+ // known when super() is called
+
+ /** The writer to decorate. */
+ private final Writer out;
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param filename the name of the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @throws NullPointerException if the file name or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final String filename, final String encoding) throws IOException {
+ this(new File(filename), encoding, false);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param filename the name of the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @param append true if content should be appended, false to overwrite
+ * @throws NullPointerException if the file name or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final String filename, final String encoding, final boolean append)
+ throws IOException {
+ this(new File(filename), encoding, append);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param filename the name of the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @throws NullPointerException if the file name or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final String filename, final Charset encoding) throws IOException {
+ this(new File(filename), encoding, false);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param filename the name of the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @param append true if content should be appended, false to overwrite
+ * @throws NullPointerException if the file name or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final String filename, final Charset encoding, final boolean append)
+ throws IOException {
+ this(new File(filename), encoding, append);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param filename the name of the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @throws NullPointerException if the file name or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final String filename, final CharsetEncoder encoding) throws IOException {
+ this(new File(filename), encoding, false);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param filename the name of the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @param append true if content should be appended, false to overwrite
+ * @throws NullPointerException if the file name or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final String filename, final CharsetEncoder encoding, final boolean append)
+ throws IOException {
+ this(new File(filename), encoding, append);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @throws NullPointerException if the file or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final File file, final String encoding) throws IOException {
+ this(file, encoding, false);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @param append true if content should be appended, false to overwrite
+ * @throws NullPointerException if the file or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final File file, final String encoding, final boolean append) throws IOException {
+ super();
+ this.out = initWriter(file, encoding, append);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @throws NullPointerException if the file or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final File file, final Charset encoding) throws IOException {
+ this(file, encoding, false);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @param append true if content should be appended, false to overwrite
+ * @throws NullPointerException if the file or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final File file, final Charset encoding, final boolean append) throws IOException {
+ super();
+ this.out = initWriter(file, encoding, append);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @throws NullPointerException if the file or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final File file, final CharsetEncoder encoding) throws IOException {
+ this(file, encoding, false);
+ }
+
+ /**
+ * Constructs a FileWriterWithEncoding with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, not null
+ * @param append true if content should be appended, false to overwrite
+ * @throws NullPointerException if the file or encoding is null
+ * @throws IOException in case of an I/O error
+ */
+ public FileWriterWithEncoding(final File file, final CharsetEncoder encoding, final boolean append)
+ throws IOException {
+ super();
+ this.out = initWriter(file, encoding, append);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Initialise the wrapped file writer.
+ * Ensure that a cleanup occurs if the writer creation fails.
+ *
+ * @param file the file to be accessed
+ * @param encoding the encoding to use - may be Charset, CharsetEncoder or String
+ * @param append true to append
+ * @return the initialised writer
+ * @throws NullPointerException if the file or encoding is null
+ * @throws IOException if an error occurs
+ */
+ private static Writer initWriter(final File file, final Object encoding, final boolean append) throws IOException {
+ if (file == null) {
+ throw new NullPointerException("File is missing");
+ }
+ if (encoding == null) {
+ throw new NullPointerException("Encoding is missing");
+ }
+ final boolean fileExistedAlready = file.exists();
+ OutputStream stream = null;
+ Writer writer = null;
+ try {
+ stream = new FileOutputStream(file, append);
+ if (encoding instanceof Charset) {
+ writer = new OutputStreamWriter(stream, (Charset)encoding);
+ } else if (encoding instanceof CharsetEncoder) {
+ writer = new OutputStreamWriter(stream, (CharsetEncoder)encoding);
+ } else {
+ writer = new OutputStreamWriter(stream, (String)encoding);
+ }
+ } catch (final IOException ex) {
+ IOUtils.closeQuietly(writer);
+ IOUtils.closeQuietly(stream);
+ if (fileExistedAlready == false) {
+ FileUtils.deleteQuietly(file);
+ }
+ throw ex;
+ } catch (final RuntimeException ex) {
+ IOUtils.closeQuietly(writer);
+ IOUtils.closeQuietly(stream);
+ if (fileExistedAlready == false) {
+ FileUtils.deleteQuietly(file);
+ }
+ throw ex;
+ }
+ return writer;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Write a character.
+ * @param idx the character to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final int idx) throws IOException {
+ out.write(idx);
+ }
+
+ /**
+ * Write the characters from an array.
+ * @param chr the characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final char[] chr) throws IOException {
+ out.write(chr);
+ }
+
+ /**
+ * Write the specified characters from an array.
+ * @param chr the characters to write
+ * @param st The start offset
+ * @param end The number of characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final char[] chr, final int st, final int end) throws IOException {
+ out.write(chr, st, end);
+ }
+
+ /**
+ * Write the characters from a string.
+ * @param str the string to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final String str) throws IOException {
+ out.write(str);
+ }
+
+ /**
+ * Write the specified characters from a string.
+ * @param str the string to write
+ * @param st The start offset
+ * @param end The number of characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final String str, final int st, final int end) throws IOException {
+ out.write(str, st, end);
+ }
+
+ /**
+ * Flush the stream.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void flush() throws IOException {
+ out.flush();
+ }
+
+ /**
+ * Close the stream.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/LockableFileWriter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/LockableFileWriter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..a68289c88709875bbcca0abd94da8aeba9ff9452
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/LockableFileWriter.java"
@@ -0,0 +1,374 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
+
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * FileWriter that will create and honor lock files to allow simple
+ * cross thread file lock handling.
+ *
+ * This class provides a simple alternative to FileWriter
+ * that will use a lock file to prevent duplicate writes.
+ *
+ * N.B. the lock file is deleted when {@link #close()} is called
+ * - or if the main file cannot be opened initially.
+ * In the (unlikely) event that the lockfile cannot be deleted,
+ * this is not reported, and subsequent requests using
+ * the same lockfile will fail.
+ *
+ * By default, the file will be overwritten, but this may be changed to append.
+ * The lock directory may be specified, but defaults to the system property
+ * java.io.tmpdir.
+ * The encoding may also be specified, and defaults to the platform default.
+ *
+ * @version $Id: LockableFileWriter.java 1686747 2015-06-21 18:44:49Z krosenvold $
+ */
+public class LockableFileWriter extends Writer {
+ // Cannot extend ProxyWriter, as requires writer to be
+ // known when super() is called
+
+ /** The extension for the lock file. */
+ private static final String LCK = ".lck";
+
+ /** The writer to decorate. */
+ private final Writer out;
+ /** The lock file. */
+ private final File lockFile;
+
+ /**
+ * Constructs a LockableFileWriter.
+ * If the file exists, it is overwritten.
+ *
+ * @param fileName the file to write to, not null
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ */
+ public LockableFileWriter(final String fileName) throws IOException {
+ this(fileName, false, null);
+ }
+
+ /**
+ * Constructs a LockableFileWriter.
+ *
+ * @param fileName file to write to, not null
+ * @param append true if content should be appended, false to overwrite
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ */
+ public LockableFileWriter(final String fileName, final boolean append) throws IOException {
+ this(fileName, append, null);
+ }
+
+ /**
+ * Constructs a LockableFileWriter.
+ *
+ * @param fileName the file to write to, not null
+ * @param append true if content should be appended, false to overwrite
+ * @param lockDir the directory in which the lock file should be held
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ */
+ public LockableFileWriter(final String fileName, final boolean append, final String lockDir) throws IOException {
+ this(new File(fileName), append, lockDir);
+ }
+
+ /**
+ * Constructs a LockableFileWriter.
+ * If the file exists, it is overwritten.
+ *
+ * @param file the file to write to, not null
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ */
+ public LockableFileWriter(final File file) throws IOException {
+ this(file, false, null);
+ }
+
+ /**
+ * Constructs a LockableFileWriter.
+ *
+ * @param file the file to write to, not null
+ * @param append true if content should be appended, false to overwrite
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ */
+ public LockableFileWriter(final File file, final boolean append) throws IOException {
+ this(file, append, null);
+ }
+
+ /**
+ * Constructs a LockableFileWriter.
+ *
+ * @param file the file to write to, not null
+ * @param append true if content should be appended, false to overwrite
+ * @param lockDir the directory in which the lock file should be held
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ * @deprecated 2.5 use {@link #LockableFileWriter(File, Charset, boolean, String)} instead
+ */
+ @Deprecated
+ public LockableFileWriter(final File file, final boolean append, final String lockDir) throws IOException {
+ this(file, Charset.defaultCharset(), append, lockDir);
+ }
+
+ /**
+ * Constructs a LockableFileWriter with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ * @since 2.3
+ */
+ public LockableFileWriter(final File file, final Charset encoding) throws IOException {
+ this(file, encoding, false, null);
+ }
+
+ /**
+ * Constructs a LockableFileWriter with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, null means platform default
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ * @throws java.nio.charset.UnsupportedCharsetException
+ * thrown instead of {@link java.io.UnsupportedEncodingException} in version 2.2 if the encoding is not
+ * supported.
+ */
+ public LockableFileWriter(final File file, final String encoding) throws IOException {
+ this(file, encoding, false, null);
+ }
+
+ /**
+ * Constructs a LockableFileWriter with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, null means platform default
+ * @param append true if content should be appended, false to overwrite
+ * @param lockDir the directory in which the lock file should be held
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ * @since 2.3
+ */
+ public LockableFileWriter(File file, final Charset encoding, final boolean append,
+ String lockDir) throws IOException {
+ super();
+ // init file to create/append
+ file = file.getAbsoluteFile();
+ if (file.getParentFile() != null) {
+ FileUtils.forceMkdir(file.getParentFile());
+ }
+ if (file.isDirectory()) {
+ throw new IOException("File specified is a directory");
+ }
+
+ // init lock file
+ if (lockDir == null) {
+ lockDir = System.getProperty("java.io.tmpdir");
+ }
+ final File lockDirFile = new File(lockDir);
+ FileUtils.forceMkdir(lockDirFile);
+ testLockDir(lockDirFile);
+ lockFile = new File(lockDirFile, file.getName() + LCK);
+
+ // check if locked
+ createLock();
+
+ // init wrapped writer
+ out = initWriter(file, encoding, append);
+ }
+
+ /**
+ * Constructs a LockableFileWriter with a file encoding.
+ *
+ * @param file the file to write to, not null
+ * @param encoding the encoding to use, null means platform default
+ * @param append true if content should be appended, false to overwrite
+ * @param lockDir the directory in which the lock file should be held
+ * @throws NullPointerException if the file is null
+ * @throws IOException in case of an I/O error
+ * @throws java.nio.charset.UnsupportedCharsetException
+ * thrown instead of {@link java.io.UnsupportedEncodingException} in version 2.2 if the encoding is not
+ * supported.
+ */
+ public LockableFileWriter(final File file, final String encoding, final boolean append,
+ final String lockDir) throws IOException {
+ this(file, Charsets.toCharset(encoding), append, lockDir);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Tests that we can write to the lock directory.
+ *
+ * @param lockDir the File representing the lock directory
+ * @throws IOException if we cannot write to the lock directory
+ * @throws IOException if we cannot find the lock file
+ */
+ private void testLockDir(final File lockDir) throws IOException {
+ if (!lockDir.exists()) {
+ throw new IOException(
+ "Could not find lockDir: " + lockDir.getAbsolutePath());
+ }
+ if (!lockDir.canWrite()) {
+ throw new IOException(
+ "Could not write to lockDir: " + lockDir.getAbsolutePath());
+ }
+ }
+
+ /**
+ * Creates the lock file.
+ *
+ * @throws IOException if we cannot create the file
+ */
+ private void createLock() throws IOException {
+ synchronized (LockableFileWriter.class) {
+ if (!lockFile.createNewFile()) {
+ throw new IOException("Can't write file, lock " +
+ lockFile.getAbsolutePath() + " exists");
+ }
+ lockFile.deleteOnExit();
+ }
+ }
+
+ /**
+ * Initialise the wrapped file writer.
+ * Ensure that a cleanup occurs if the writer creation fails.
+ *
+ * @param file the file to be accessed
+ * @param encoding the encoding to use
+ * @param append true to append
+ * @return The initialised writer
+ * @throws IOException if an error occurs
+ */
+ private Writer initWriter(final File file, final Charset encoding, final boolean append) throws IOException {
+ final boolean fileExistedAlready = file.exists();
+ OutputStream stream = null;
+ Writer writer = null;
+ try {
+ stream = new FileOutputStream(file.getAbsolutePath(), append);
+ writer = new OutputStreamWriter(stream, Charsets.toCharset(encoding));
+ } catch (final IOException ex) {
+ IOUtils.closeQuietly(writer);
+ IOUtils.closeQuietly(stream);
+ FileUtils.deleteQuietly(lockFile);
+ if (fileExistedAlready == false) {
+ FileUtils.deleteQuietly(file);
+ }
+ throw ex;
+ } catch (final RuntimeException ex) {
+ IOUtils.closeQuietly(writer);
+ IOUtils.closeQuietly(stream);
+ FileUtils.deleteQuietly(lockFile);
+ if (fileExistedAlready == false) {
+ FileUtils.deleteQuietly(file);
+ }
+ throw ex;
+ }
+ return writer;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Closes the file writer and deletes the lockfile (if possible).
+ *
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ try {
+ out.close();
+ } finally {
+ lockFile.delete();
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Write a character.
+ * @param idx the character to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final int idx) throws IOException {
+ out.write(idx);
+ }
+
+ /**
+ * Write the characters from an array.
+ * @param chr the characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final char[] chr) throws IOException {
+ out.write(chr);
+ }
+
+ /**
+ * Write the specified characters from an array.
+ * @param chr the characters to write
+ * @param st The start offset
+ * @param end The number of characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final char[] chr, final int st, final int end) throws IOException {
+ out.write(chr, st, end);
+ }
+
+ /**
+ * Write the characters from a string.
+ * @param str the string to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final String str) throws IOException {
+ out.write(str);
+ }
+
+ /**
+ * Write the specified characters from a string.
+ * @param str the string to write
+ * @param st The start offset
+ * @param end The number of characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final String str, final int st, final int end) throws IOException {
+ out.write(str, st, end);
+ }
+
+ /**
+ * Flush the stream.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void flush() throws IOException {
+ out.flush();
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/NullOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/NullOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..b933e2ed8098c715032846c87907f6bc06ec9ad0
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/NullOutputStream.java"
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * This OutputStream writes all data to the famous /dev/null .
+ *
+ * This output stream has no destination (file/socket etc.) and all
+ * bytes written to it are ignored and lost.
+ *
+ * @version $Id: NullOutputStream.java 1674708 2015-04-20 00:02:45Z ggregory $
+ */
+public class NullOutputStream extends OutputStream {
+
+ /**
+ * A singleton.
+ */
+ public static final NullOutputStream NULL_OUTPUT_STREAM = new NullOutputStream();
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param b The bytes to write
+ * @param off The start offset
+ * @param len The number of bytes to write
+ */
+ @Override
+ public void write(final byte[] b, final int off, final int len) {
+ //to /dev/null
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param b The byte to write
+ */
+ @Override
+ public void write(final int b) {
+ //to /dev/null
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param b The bytes to write
+ * @throws IOException never
+ */
+ @Override
+ public void write(final byte[] b) throws IOException {
+ //to /dev/null
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/NullWriter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/NullWriter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..322dc82464266124e71635f6249ea465c3f3f355
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/NullWriter.java"
@@ -0,0 +1,141 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.Writer;
+
+/**
+ * This {@link Writer} writes all data to the famous /dev/null .
+ *
+ * This Writer has no destination (file/socket etc.) and all
+ * characters written to it are ignored and lost.
+ *
+ * @version $Id: NullWriter.java 1471767 2013-04-24 23:24:19Z sebb $
+ */
+public class NullWriter extends Writer {
+
+ /**
+ * A singleton.
+ */
+ public static final NullWriter NULL_WRITER = new NullWriter();
+
+ /**
+ * Constructs a new NullWriter.
+ */
+ public NullWriter() {
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param c The character to write
+ * @return this writer
+ * @since 2.0
+ */
+ @Override
+ public Writer append(final char c) {
+ //to /dev/null
+ return this;
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param csq The character sequence to write
+ * @param start The index of the first character to write
+ * @param end The index of the first character to write (exclusive)
+ * @return this writer
+ * @since 2.0
+ */
+ @Override
+ public Writer append(final CharSequence csq, final int start, final int end) {
+ //to /dev/null
+ return this;
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param csq The character sequence to write
+ * @return this writer
+ * @since 2.0
+ */
+ @Override
+ public Writer append(final CharSequence csq) {
+ //to /dev/null
+ return this;
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param idx The character to write
+ */
+ @Override
+ public void write(final int idx) {
+ //to /dev/null
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param chr The characters to write
+ */
+ @Override
+ public void write(final char[] chr) {
+ //to /dev/null
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param chr The characters to write
+ * @param st The start offset
+ * @param end The number of characters to write
+ */
+ @Override
+ public void write(final char[] chr, final int st, final int end) {
+ //to /dev/null
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param str The string to write
+ */
+ @Override
+ public void write(final String str) {
+ //to /dev/null
+ }
+
+ /**
+ * Does nothing - output to /dev/null.
+ * @param str The string to write
+ * @param st The start offset
+ * @param end The number of characters to write
+ */
+ @Override
+ public void write(final String str, final int st, final int end) {
+ //to /dev/null
+ }
+
+ /** @see java.io.Writer#flush() */
+ @Override
+ public void flush() {
+ //to /dev/null
+ }
+
+ /** @see java.io.Writer#close() */
+ @Override
+ public void close() {
+ //to /dev/null
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ProxyOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ProxyOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..8f78594589ff8f34774b669b1599db89dbb4740c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ProxyOutputStream.java"
@@ -0,0 +1,169 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * A Proxy stream which acts as expected, that is it passes the method
+ * calls on to the proxied stream and doesn't change which methods are
+ * being called. It is an alternative base class to FilterOutputStream
+ * to increase reusability.
+ *
+ * See the protected methods for ways in which a subclass can easily decorate
+ * a stream with custom pre-, post- or error processing functionality.
+ *
+ * @version $Id: ProxyOutputStream.java 1415850 2012-11-30 20:51:39Z ggregory $
+ */
+public class ProxyOutputStream extends FilterOutputStream {
+
+ /**
+ * Constructs a new ProxyOutputStream.
+ *
+ * @param proxy the OutputStream to delegate to
+ */
+ public ProxyOutputStream(final OutputStream proxy) {
+ super(proxy);
+ // the proxy is stored in a protected superclass variable named 'out'
+ }
+
+ /**
+ * Invokes the delegate's write(int) method.
+ * @param idx the byte to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final int idx) throws IOException {
+ try {
+ beforeWrite(1);
+ out.write(idx);
+ afterWrite(1);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's write(byte[]) method.
+ * @param bts the bytes to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final byte[] bts) throws IOException {
+ try {
+ final int len = bts != null ? bts.length : 0;
+ beforeWrite(len);
+ out.write(bts);
+ afterWrite(len);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's write(byte[]) method.
+ * @param bts the bytes to write
+ * @param st The start offset
+ * @param end The number of bytes to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final byte[] bts, final int st, final int end) throws IOException {
+ try {
+ beforeWrite(end);
+ out.write(bts, st, end);
+ afterWrite(end);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's flush() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void flush() throws IOException {
+ try {
+ out.flush();
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's close() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ try {
+ out.close();
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invoked by the write methods before the call is proxied. The number
+ * of bytes to be written (1 for the {@link #write(int)} method, buffer
+ * length for {@link #write(byte[])}, etc.) is given as an argument.
+ *
+ * Subclasses can override this method to add common pre-processing
+ * functionality without having to override all the write methods.
+ * The default implementation does nothing.
+ *
+ * @since 2.0
+ * @param n number of bytes to be written
+ * @throws IOException if the pre-processing fails
+ */
+ protected void beforeWrite(final int n) throws IOException {
+ }
+
+ /**
+ * Invoked by the write methods after the proxied call has returned
+ * successfully. The number of bytes written (1 for the
+ * {@link #write(int)} method, buffer length for {@link #write(byte[])},
+ * etc.) is given as an argument.
+ *
+ * Subclasses can override this method to add common post-processing
+ * functionality without having to override all the write methods.
+ * The default implementation does nothing.
+ *
+ * @since 2.0
+ * @param n number of bytes written
+ * @throws IOException if the post-processing fails
+ */
+ protected void afterWrite(final int n) throws IOException {
+ }
+
+ /**
+ * Handle any IOExceptions thrown.
+ *
+ * This method provides a point to implement custom exception
+ * handling. The default behaviour is to re-throw the exception.
+ * @param e The IOException thrown
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ protected void handleIOException(final IOException e) throws IOException {
+ throw e;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ProxyWriter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ProxyWriter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..0e3eda756fbb536a19baafe123dfcc96037972fe
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ProxyWriter.java"
@@ -0,0 +1,275 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * A Proxy stream which acts as expected, that is it passes the method
+ * calls on to the proxied stream and doesn't change which methods are
+ * being called. It is an alternative base class to FilterWriter
+ * to increase reusability, because FilterWriter changes the
+ * methods being called, such as write(char[]) to write(char[], int, int)
+ * and write(String) to write(String, int, int).
+ *
+ * @version $Id: ProxyWriter.java 1415850 2012-11-30 20:51:39Z ggregory $
+ */
+public class ProxyWriter extends FilterWriter {
+
+ /**
+ * Constructs a new ProxyWriter.
+ *
+ * @param proxy the Writer to delegate to
+ */
+ public ProxyWriter(final Writer proxy) {
+ super(proxy);
+ // the proxy is stored in a protected superclass variable named 'out'
+ }
+
+ /**
+ * Invokes the delegate's append(char) method.
+ * @param c The character to write
+ * @return this writer
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ @Override
+ public Writer append(final char c) throws IOException {
+ try {
+ beforeWrite(1);
+ out.append(c);
+ afterWrite(1);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ return this;
+ }
+
+ /**
+ * Invokes the delegate's append(CharSequence, int, int) method.
+ * @param csq The character sequence to write
+ * @param start The index of the first character to write
+ * @param end The index of the first character to write (exclusive)
+ * @return this writer
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ @Override
+ public Writer append(final CharSequence csq, final int start, final int end) throws IOException {
+ try {
+ beforeWrite(end - start);
+ out.append(csq, start, end);
+ afterWrite(end - start);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ return this;
+ }
+
+ /**
+ * Invokes the delegate's append(CharSequence) method.
+ * @param csq The character sequence to write
+ * @return this writer
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ @Override
+ public Writer append(final CharSequence csq) throws IOException {
+ try {
+ int len = 0;
+ if (csq != null) {
+ len = csq.length();
+ }
+
+ beforeWrite(len);
+ out.append(csq);
+ afterWrite(len);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ return this;
+ }
+
+ /**
+ * Invokes the delegate's write(int) method.
+ * @param idx the character to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final int idx) throws IOException {
+ try {
+ beforeWrite(1);
+ out.write(idx);
+ afterWrite(1);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's write(char[]) method.
+ * @param chr the characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final char[] chr) throws IOException {
+ try {
+ int len = 0;
+ if (chr != null) {
+ len = chr.length;
+ }
+
+ beforeWrite(len);
+ out.write(chr);
+ afterWrite(len);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's write(char[], int, int) method.
+ * @param chr the characters to write
+ * @param st The start offset
+ * @param len The number of characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final char[] chr, final int st, final int len) throws IOException {
+ try {
+ beforeWrite(len);
+ out.write(chr, st, len);
+ afterWrite(len);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's write(String) method.
+ * @param str the string to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final String str) throws IOException {
+ try {
+ int len = 0;
+ if (str != null) {
+ len = str.length();
+ }
+
+ beforeWrite(len);
+ out.write(str);
+ afterWrite(len);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's write(String) method.
+ * @param str the string to write
+ * @param st The start offset
+ * @param len The number of characters to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final String str, final int st, final int len) throws IOException {
+ try {
+ beforeWrite(len);
+ out.write(str, st, len);
+ afterWrite(len);
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's flush() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void flush() throws IOException {
+ try {
+ out.flush();
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invokes the delegate's close() method.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ try {
+ out.close();
+ } catch (final IOException e) {
+ handleIOException(e);
+ }
+ }
+
+ /**
+ * Invoked by the write methods before the call is proxied. The number
+ * of chars to be written (1 for the {@link #write(int)} method, buffer
+ * length for {@link #write(char[])}, etc.) is given as an argument.
+ *
+ * Subclasses can override this method to add common pre-processing
+ * functionality without having to override all the write methods.
+ * The default implementation does nothing.
+ *
+ * @since 2.0
+ * @param n number of chars to be written
+ * @throws IOException if the pre-processing fails
+ */
+ protected void beforeWrite(final int n) throws IOException {
+ }
+
+ /**
+ * Invoked by the write methods after the proxied call has returned
+ * successfully. The number of chars written (1 for the
+ * {@link #write(int)} method, buffer length for {@link #write(char[])},
+ * etc.) is given as an argument.
+ *
+ * Subclasses can override this method to add common post-processing
+ * functionality without having to override all the write methods.
+ * The default implementation does nothing.
+ *
+ * @since 2.0
+ * @param n number of chars written
+ * @throws IOException if the post-processing fails
+ */
+ protected void afterWrite(final int n) throws IOException {
+ }
+
+ /**
+ * Handle any IOExceptions thrown.
+ *
+ * This method provides a point to implement custom exception
+ * handling. The default behaviour is to re-throw the exception.
+ * @param e The IOException thrown
+ * @throws IOException if an I/O error occurs
+ * @since 2.0
+ */
+ protected void handleIOException(final IOException e) throws IOException {
+ throw e;
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/StringBuilderWriter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/StringBuilderWriter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..df75627b3a17095addc67aef1598fff845f10078
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/StringBuilderWriter.java"
@@ -0,0 +1,165 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.Serializable;
+import java.io.Writer;
+
+/**
+ * {@link Writer} implementation that outputs to a {@link StringBuilder}.
+ *
+ * NOTE: This implementation, as an alternative to
+ * java.io.StringWriter, provides an un-synchronized
+ * (i.e. for use in a single thread) implementation for better performance.
+ * For safe usage with multiple {@link Thread}s then
+ * java.io.StringWriter should be used.
+ *
+ * @version $Id: StringBuilderWriter.java 1722253 2015-12-30 00:36:12Z ggregory $
+ * @since 2.0
+ */
+public class StringBuilderWriter extends Writer implements Serializable {
+
+ private static final long serialVersionUID = -146927496096066153L;
+ private final StringBuilder builder;
+
+ /**
+ * Constructs a new {@link StringBuilder} instance with default capacity.
+ */
+ public StringBuilderWriter() {
+ this.builder = new StringBuilder();
+ }
+
+ /**
+ * Constructs a new {@link StringBuilder} instance with the specified capacity.
+ *
+ * @param capacity The initial capacity of the underlying {@link StringBuilder}
+ */
+ public StringBuilderWriter(final int capacity) {
+ this.builder = new StringBuilder(capacity);
+ }
+
+ /**
+ * Constructs a new instance with the specified {@link StringBuilder}.
+ *
+ *
If {@code builder} is null a new instance with default capacity will be created.
+ *
+ * @param builder The String builder. May be null.
+ */
+ public StringBuilderWriter(final StringBuilder builder) {
+ this.builder = builder != null ? builder : new StringBuilder();
+ }
+
+ /**
+ * Appends a single character to this Writer.
+ *
+ * @param value The character to append
+ * @return This writer instance
+ */
+ @Override
+ public Writer append(final char value) {
+ builder.append(value);
+ return this;
+ }
+
+ /**
+ * Appends a character sequence to this Writer.
+ *
+ * @param value The character to append
+ * @return This writer instance
+ */
+ @Override
+ public Writer append(final CharSequence value) {
+ builder.append(value);
+ return this;
+ }
+
+ /**
+ * Appends a portion of a character sequence to the {@link StringBuilder}.
+ *
+ * @param value The character to append
+ * @param start The index of the first character
+ * @param end The index of the last character + 1
+ * @return This writer instance
+ */
+ @Override
+ public Writer append(final CharSequence value, final int start, final int end) {
+ builder.append(value, start, end);
+ return this;
+ }
+
+ /**
+ * Closing this writer has no effect.
+ */
+ @Override
+ public void close() {
+ // no-op
+ }
+
+ /**
+ * Flushing this writer has no effect.
+ */
+ @Override
+ public void flush() {
+ // no-op
+ }
+
+
+ /**
+ * Writes a String to the {@link StringBuilder}.
+ *
+ * @param value The value to write
+ */
+ @Override
+ public void write(final String value) {
+ if (value != null) {
+ builder.append(value);
+ }
+ }
+
+ /**
+ * Writes a portion of a character array to the {@link StringBuilder}.
+ *
+ * @param value The value to write
+ * @param offset The index of the first character
+ * @param length The number of characters to write
+ */
+ @Override
+ public void write(final char[] value, final int offset, final int length) {
+ if (value != null) {
+ builder.append(value, offset, length);
+ }
+ }
+
+ /**
+ * Returns the underlying builder.
+ *
+ * @return The underlying builder
+ */
+ public StringBuilder getBuilder() {
+ return builder;
+ }
+
+ /**
+ * Returns {@link StringBuilder#toString()}.
+ *
+ * @return The contents of the String builder.
+ */
+ @Override
+ public String toString() {
+ return builder.toString();
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/TaggedOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/TaggedOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ae63a7d57f90623010fc7c6686d9b150ac91ca4e
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/TaggedOutputStream.java"
@@ -0,0 +1,116 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.UUID;
+
+import org.apache.commons.io.TaggedIOException;
+
+/**
+ * An output stream decorator that tags potential exceptions so that the
+ * stream that caused the exception can easily be identified. This is
+ * done by using the {@link TaggedIOException} class to wrap all thrown
+ * {@link IOException}s. See below for an example of using this class.
+ *
+ * TaggedOutputStream stream = new TaggedOutputStream(...);
+ * try {
+ * // Processing that may throw an IOException either from this stream
+ * // or from some other IO activity like temporary files, etc.
+ * writeToStream(stream);
+ * } catch (IOException e) {
+ * if (stream.isCauseOf(e)) {
+ * // The exception was caused by this stream.
+ * // Use e.getCause() to get the original exception.
+ * } else {
+ * // The exception was caused by something else.
+ * }
+ * }
+ *
+ *
+ * Alternatively, the {@link #throwIfCauseOf(Exception)} method can be
+ * used to let higher levels of code handle the exception caused by this
+ * stream while other processing errors are being taken care of at this
+ * lower level.
+ *
+ * TaggedOutputStream stream = new TaggedOutputStream(...);
+ * try {
+ * writeToStream(stream);
+ * } catch (IOException e) {
+ * stream.throwIfCauseOf(e);
+ * // ... or process the exception that was caused by something else
+ * }
+ *
+ *
+ * @see TaggedIOException
+ * @since 2.0
+ */
+public class TaggedOutputStream extends ProxyOutputStream {
+
+ /**
+ * The unique tag associated with exceptions from stream.
+ */
+ private final Serializable tag = UUID.randomUUID();
+
+ /**
+ * Creates a tagging decorator for the given output stream.
+ *
+ * @param proxy output stream to be decorated
+ */
+ public TaggedOutputStream(final OutputStream proxy) {
+ super(proxy);
+ }
+
+ /**
+ * Tests if the given exception was caused by this stream.
+ *
+ * @param exception an exception
+ * @return {@code true} if the exception was thrown by this stream,
+ * {@code false} otherwise
+ */
+ public boolean isCauseOf(final Exception exception) {
+ return TaggedIOException.isTaggedWith(exception, tag);
+ }
+
+ /**
+ * Re-throws the original exception thrown by this stream. This method
+ * first checks whether the given exception is a {@link TaggedIOException}
+ * wrapper created by this decorator, and then unwraps and throws the
+ * original wrapped exception. Returns normally if the exception was
+ * not thrown by this stream.
+ *
+ * @param exception an exception
+ * @throws IOException original exception, if any, thrown by this stream
+ */
+ public void throwIfCauseOf(final Exception exception) throws IOException {
+ TaggedIOException.throwCauseIfTaggedWith(exception, tag);
+ }
+
+ /**
+ * Tags any IOExceptions thrown, wrapping and re-throwing.
+ *
+ * @param e The IOException thrown
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void handleIOException(final IOException e) throws IOException {
+ throw new TaggedIOException(e, tag);
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/TeeOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/TeeOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..9200c26825e4946894022d42a82c7f818101a27d
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/TeeOutputStream.java"
@@ -0,0 +1,109 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Classic splitter of OutputStream. Named after the unix 'tee'
+ * command. It allows a stream to be branched off so there
+ * are now two streams.
+ *
+ * @version $Id: TeeOutputStream.java 1686503 2015-06-19 21:32:13Z sebb $
+ */
+public class TeeOutputStream extends ProxyOutputStream {
+
+ /** the second OutputStream to write to */
+ protected OutputStream branch; //TODO consider making this private
+
+ /**
+ * Constructs a TeeOutputStream.
+ * @param out the main OutputStream
+ * @param branch the second OutputStream
+ */
+ public TeeOutputStream(final OutputStream out, final OutputStream branch) {
+ super(out);
+ this.branch = branch;
+ }
+
+ /**
+ * Write the bytes to both streams.
+ * @param b the bytes to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public synchronized void write(final byte[] b) throws IOException {
+ super.write(b);
+ this.branch.write(b);
+ }
+
+ /**
+ * Write the specified bytes to both streams.
+ * @param b the bytes to write
+ * @param off The start offset
+ * @param len The number of bytes to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public synchronized void write(final byte[] b, final int off, final int len) throws IOException {
+ super.write(b, off, len);
+ this.branch.write(b, off, len);
+ }
+
+ /**
+ * Write a byte to both streams.
+ * @param b the byte to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public synchronized void write(final int b) throws IOException {
+ super.write(b);
+ this.branch.write(b);
+ }
+
+ /**
+ * Flushes both streams.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void flush() throws IOException {
+ super.flush();
+ this.branch.flush();
+ }
+
+ /**
+ * Closes both output streams.
+ *
+ * If closing the main output stream throws an exception, attempt to close the branch output stream.
+ *
+ * If closing the main and branch output streams both throw exceptions, which exceptions is thrown by this method is
+ * currently unspecified and subject to change.
+ *
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ try {
+ super.close();
+ } finally {
+ this.branch.close();
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ThresholdingOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ThresholdingOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..bb7c34e2b89c72194d7ee485119a04949ce937dd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/ThresholdingOutputStream.java"
@@ -0,0 +1,274 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/**
+ * An output stream which triggers an event when a specified number of bytes of
+ * data have been written to it. The event can be used, for example, to throw
+ * an exception if a maximum has been reached, or to switch the underlying
+ * stream type when the threshold is exceeded.
+ *
+ * This class overrides all OutputStream methods. However, these
+ * overrides ultimately call the corresponding methods in the underlying output
+ * stream implementation.
+ *
+ * NOTE: This implementation may trigger the event before the threshold
+ * is actually reached, since it triggers when a pending write operation would
+ * cause the threshold to be exceeded.
+ *
+ * @version $Id: ThresholdingOutputStream.java 1687815 2015-06-26 17:18:56Z krosenvold $
+ */
+public abstract class ThresholdingOutputStream
+ extends OutputStream
+{
+
+ // ----------------------------------------------------------- Data members
+
+
+ /**
+ * The threshold at which the event will be triggered.
+ */
+ private final int threshold;
+
+
+ /**
+ * The number of bytes written to the output stream.
+ */
+ private long written;
+
+
+ /**
+ * Whether or not the configured threshold has been exceeded.
+ */
+ private boolean thresholdExceeded;
+
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Constructs an instance of this class which will trigger an event at the
+ * specified threshold.
+ *
+ * @param threshold The number of bytes at which to trigger an event.
+ */
+ public ThresholdingOutputStream(final int threshold)
+ {
+ this.threshold = threshold;
+ }
+
+
+ // --------------------------------------------------- OutputStream methods
+
+
+ /**
+ * Writes the specified byte to this output stream.
+ *
+ * @param b The byte to be written.
+ *
+ * @exception IOException if an error occurs.
+ */
+ @Override
+ public void write(final int b) throws IOException
+ {
+ checkThreshold(1);
+ getStream().write(b);
+ written++;
+ }
+
+
+ /**
+ * Writes b.length bytes from the specified byte array to this
+ * output stream.
+ *
+ * @param b The array of bytes to be written.
+ *
+ * @exception IOException if an error occurs.
+ */
+ @Override
+ public void write(final byte b[]) throws IOException
+ {
+ checkThreshold(b.length);
+ getStream().write(b);
+ written += b.length;
+ }
+
+
+ /**
+ * Writes len bytes from the specified byte array starting at
+ * offset off to this output stream.
+ *
+ * @param b The byte array from which the data will be written.
+ * @param off The start offset in the byte array.
+ * @param len The number of bytes to write.
+ *
+ * @exception IOException if an error occurs.
+ */
+ @Override
+ public void write(final byte b[], final int off, final int len) throws IOException
+ {
+ checkThreshold(len);
+ getStream().write(b, off, len);
+ written += len;
+ }
+
+
+ /**
+ * Flushes this output stream and forces any buffered output bytes to be
+ * written out.
+ *
+ * @exception IOException if an error occurs.
+ */
+ @Override
+ public void flush() throws IOException
+ {
+ getStream().flush();
+ }
+
+
+ /**
+ * Closes this output stream and releases any system resources associated
+ * with this stream.
+ *
+ * @exception IOException if an error occurs.
+ */
+ @Override
+ public void close() throws IOException
+ {
+ try
+ {
+ flush();
+ }
+ catch (final IOException ignored)
+ {
+ // ignore
+ }
+ getStream().close();
+ }
+
+
+ // --------------------------------------------------------- Public methods
+
+
+ /**
+ * Returns the threshold, in bytes, at which an event will be triggered.
+ *
+ * @return The threshold point, in bytes.
+ */
+ public int getThreshold()
+ {
+ return threshold;
+ }
+
+
+ /**
+ * Returns the number of bytes that have been written to this output stream.
+ *
+ * @return The number of bytes written.
+ */
+ public long getByteCount()
+ {
+ return written;
+ }
+
+
+ /**
+ * Determines whether or not the configured threshold has been exceeded for
+ * this output stream.
+ *
+ * @return {@code true} if the threshold has been reached;
+ * {@code false} otherwise.
+ */
+ public boolean isThresholdExceeded()
+ {
+ return written > threshold;
+ }
+
+
+ // ------------------------------------------------------ Protected methods
+
+
+ /**
+ * Checks to see if writing the specified number of bytes would cause the
+ * configured threshold to be exceeded. If so, triggers an event to allow
+ * a concrete implementation to take action on this.
+ *
+ * @param count The number of bytes about to be written to the underlying
+ * output stream.
+ *
+ * @exception IOException if an error occurs.
+ */
+ protected void checkThreshold(final int count) throws IOException
+ {
+ if (!thresholdExceeded && written + count > threshold)
+ {
+ thresholdExceeded = true;
+ thresholdReached();
+ }
+ }
+
+ /**
+ * Resets the byteCount to zero. You can call this from
+ * {@link #thresholdReached()} if you want the event to be triggered again.
+ */
+ protected void resetByteCount()
+ {
+ this.thresholdExceeded = false;
+ this.written = 0;
+ }
+
+ /**
+ * Sets the byteCount to count. Usefull for re-opening an output stream
+ * that been previously written to.
+ *
+ * @param count The number of bytes that have already been written to the
+ * output stream
+ *
+ * @since 2.5
+ */
+ protected void setByteCount(final long count) {
+ this.written = count;
+ }
+
+
+ // ------------------------------------------------------- Abstract methods
+
+
+ /**
+ * Returns the underlying output stream, to which the corresponding
+ * OutputStream methods in this class will ultimately delegate.
+ *
+ * @return The underlying output stream.
+ *
+ * @exception IOException if an error occurs.
+ */
+ protected abstract OutputStream getStream() throws IOException;
+
+
+ /**
+ * Indicates that the configured threshold has been reached, and that a
+ * subclass should take whatever action necessary on this event. This may
+ * include changing the underlying output stream.
+ *
+ * @exception IOException if an error occurs.
+ */
+ protected abstract void thresholdReached() throws IOException;
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/WriterOutputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/WriterOutputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..8f818cac0acb86a53a84dca4d0d3219d155d5972
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/WriterOutputStream.java"
@@ -0,0 +1,340 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+
+/**
+ * {@link OutputStream} implementation that transforms a byte stream to a
+ * character stream using a specified charset encoding and writes the resulting
+ * stream to a {@link Writer}. The stream is transformed using a
+ * {@link CharsetDecoder} object, guaranteeing that all charset
+ * encodings supported by the JRE are handled correctly.
+ *
+ * The output of the {@link CharsetDecoder} is buffered using a fixed size buffer.
+ * This implies that the data is written to the underlying {@link Writer} in chunks
+ * that are no larger than the size of this buffer. By default, the buffer is
+ * flushed only when it overflows or when {@link #flush()} or {@link #close()}
+ * is called. In general there is therefore no need to wrap the underlying {@link Writer}
+ * in a {@link java.io.BufferedWriter}. {@link WriterOutputStream} can also
+ * be instructed to flush the buffer after each write operation. In this case, all
+ * available data is written immediately to the underlying {@link Writer}, implying that
+ * the current position of the {@link Writer} is correlated to the current position
+ * of the {@link WriterOutputStream}.
+ *
+ * {@link WriterOutputStream} implements the inverse transformation of {@link java.io.OutputStreamWriter};
+ * in the following example, writing to {@code out2} would have the same result as writing to
+ * {@code out} directly (provided that the byte sequence is legal with respect to the
+ * charset encoding):
+ *
+ * OutputStream out = ...
+ * Charset cs = ...
+ * OutputStreamWriter writer = new OutputStreamWriter(out, cs);
+ * WriterOutputStream out2 = new WriterOutputStream(writer, cs);
+ * {@link WriterOutputStream} implements the same transformation as {@link java.io.InputStreamReader},
+ * except that the control flow is reversed: both classes transform a byte stream
+ * into a character stream, but {@link java.io.InputStreamReader} pulls data from the underlying stream,
+ * while {@link WriterOutputStream} pushes it to the underlying stream.
+ *
+ * Note that while there are use cases where there is no alternative to using
+ * this class, very often the need to use this class is an indication of a flaw
+ * in the design of the code. This class is typically used in situations where an existing
+ * API only accepts an {@link OutputStream} object, but where the stream is known to represent
+ * character data that must be decoded for further use.
+ *
+ * Instances of {@link WriterOutputStream} are not thread safe.
+ *
+ * @see org.apache.commons.io.input.ReaderInputStream
+ *
+ * @since 2.0
+ */
+public class WriterOutputStream extends OutputStream {
+ private static final int DEFAULT_BUFFER_SIZE = 1024;
+
+ private final Writer writer;
+ private final CharsetDecoder decoder;
+ private final boolean writeImmediately;
+
+ /**
+ * ByteBuffer used as input for the decoder. This buffer can be small
+ * as it is used only to transfer the received data to the
+ * decoder.
+ */
+ private final ByteBuffer decoderIn = ByteBuffer.allocate(128);
+
+ /**
+ * CharBuffer used as output for the decoder. It should be
+ * somewhat larger as we write from this buffer to the
+ * underlying Writer.
+ */
+ private final CharBuffer decoderOut;
+
+ /**
+ * Constructs a new {@link WriterOutputStream} with a default output buffer size of
+ * 1024 characters. The output buffer will only be flushed when it overflows or when
+ * {@link #flush()} or {@link #close()} is called.
+ *
+ * @param writer the target {@link Writer}
+ * @param decoder the charset decoder
+ * @since 2.1
+ */
+ public WriterOutputStream(final Writer writer, final CharsetDecoder decoder) {
+ this(writer, decoder, DEFAULT_BUFFER_SIZE, false);
+ }
+
+ /**
+ * Constructs a new {@link WriterOutputStream}.
+ *
+ * @param writer the target {@link Writer}
+ * @param decoder the charset decoder
+ * @param bufferSize the size of the output buffer in number of characters
+ * @param writeImmediately If {@code true} the output buffer will be flushed after each
+ * write operation, i.e. all available data will be written to the
+ * underlying {@link Writer} immediately. If {@code false}, the
+ * output buffer will only be flushed when it overflows or when
+ * {@link #flush()} or {@link #close()} is called.
+ * @since 2.1
+ */
+ public WriterOutputStream(final Writer writer, final CharsetDecoder decoder, final int bufferSize,
+ final boolean writeImmediately) {
+ checkIbmJdkWithBrokenUTF16( decoder.charset());
+ this.writer = writer;
+ this.decoder = decoder;
+ this.writeImmediately = writeImmediately;
+ decoderOut = CharBuffer.allocate(bufferSize);
+ }
+
+ /**
+ * Constructs a new {@link WriterOutputStream}.
+ *
+ * @param writer the target {@link Writer}
+ * @param charset the charset encoding
+ * @param bufferSize the size of the output buffer in number of characters
+ * @param writeImmediately If {@code true} the output buffer will be flushed after each
+ * write operation, i.e. all available data will be written to the
+ * underlying {@link Writer} immediately. If {@code false}, the
+ * output buffer will only be flushed when it overflows or when
+ * {@link #flush()} or {@link #close()} is called.
+ */
+ public WriterOutputStream(final Writer writer, final Charset charset, final int bufferSize,
+ final boolean writeImmediately) {
+ this(writer,
+ charset.newDecoder()
+ .onMalformedInput(CodingErrorAction.REPLACE)
+ .onUnmappableCharacter(CodingErrorAction.REPLACE)
+ .replaceWith("?"),
+ bufferSize,
+ writeImmediately);
+ }
+
+ /**
+ * Constructs a new {@link WriterOutputStream} with a default output buffer size of
+ * 1024 characters. The output buffer will only be flushed when it overflows or when
+ * {@link #flush()} or {@link #close()} is called.
+ *
+ * @param writer the target {@link Writer}
+ * @param charset the charset encoding
+ */
+ public WriterOutputStream(final Writer writer, final Charset charset) {
+ this(writer, charset, DEFAULT_BUFFER_SIZE, false);
+ }
+
+ /**
+ * Constructs a new {@link WriterOutputStream}.
+ *
+ * @param writer the target {@link Writer}
+ * @param charsetName the name of the charset encoding
+ * @param bufferSize the size of the output buffer in number of characters
+ * @param writeImmediately If {@code true} the output buffer will be flushed after each
+ * write operation, i.e. all available data will be written to the
+ * underlying {@link Writer} immediately. If {@code false}, the
+ * output buffer will only be flushed when it overflows or when
+ * {@link #flush()} or {@link #close()} is called.
+ */
+ public WriterOutputStream(final Writer writer, final String charsetName, final int bufferSize,
+ final boolean writeImmediately) {
+ this(writer, Charset.forName(charsetName), bufferSize, writeImmediately);
+ }
+
+ /**
+ * Constructs a new {@link WriterOutputStream} with a default output buffer size of
+ * 1024 characters. The output buffer will only be flushed when it overflows or when
+ * {@link #flush()} or {@link #close()} is called.
+ *
+ * @param writer the target {@link Writer}
+ * @param charsetName the name of the charset encoding
+ */
+ public WriterOutputStream(final Writer writer, final String charsetName) {
+ this(writer, charsetName, DEFAULT_BUFFER_SIZE, false);
+ }
+
+ /**
+ * Constructs a new {@link WriterOutputStream} that uses the default character encoding
+ * and with a default output buffer size of 1024 characters. The output buffer will only
+ * be flushed when it overflows or when {@link #flush()} or {@link #close()} is called.
+ *
+ * @param writer the target {@link Writer}
+ * @deprecated 2.5 use {@link #WriterOutputStream(Writer, Charset)} instead
+ */
+ @Deprecated
+ public WriterOutputStream(final Writer writer) {
+ this(writer, Charset.defaultCharset(), DEFAULT_BUFFER_SIZE, false);
+ }
+
+ /**
+ * Write bytes from the specified byte array to the stream.
+ *
+ * @param b the byte array containing the bytes to write
+ * @param off the start offset in the byte array
+ * @param len the number of bytes to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final byte[] b, int off, int len) throws IOException {
+ while (len > 0) {
+ final int c = Math.min(len, decoderIn.remaining());
+ decoderIn.put(b, off, c);
+ processInput(false);
+ len -= c;
+ off += c;
+ }
+ if (writeImmediately) {
+ flushOutput();
+ }
+ }
+
+ /**
+ * Write bytes from the specified byte array to the stream.
+ *
+ * @param b the byte array containing the bytes to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final byte[] b) throws IOException {
+ write(b, 0, b.length);
+ }
+
+ /**
+ * Write a single byte to the stream.
+ *
+ * @param b the byte to write
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void write(final int b) throws IOException {
+ write(new byte[] { (byte)b }, 0, 1);
+ }
+
+ /**
+ * Flush the stream. Any remaining content accumulated in the output buffer
+ * will be written to the underlying {@link Writer}. After that
+ * {@link Writer#flush()} will be called.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void flush() throws IOException {
+ flushOutput();
+ writer.flush();
+ }
+
+ /**
+ * Close the stream. Any remaining content accumulated in the output buffer
+ * will be written to the underlying {@link Writer}. After that
+ * {@link Writer#close()} will be called.
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ processInput(true);
+ flushOutput();
+ writer.close();
+ }
+
+ /**
+ * Decode the contents of the input ByteBuffer into a CharBuffer.
+ *
+ * @param endOfInput indicates end of input
+ * @throws IOException if an I/O error occurs
+ */
+ private void processInput(final boolean endOfInput) throws IOException {
+ // Prepare decoderIn for reading
+ decoderIn.flip();
+ CoderResult coderResult;
+ while (true) {
+ coderResult = decoder.decode(decoderIn, decoderOut, endOfInput);
+ if (coderResult.isOverflow()) {
+ flushOutput();
+ } else if (coderResult.isUnderflow()) {
+ break;
+ } else {
+ // The decoder is configured to replace malformed input and unmappable characters,
+ // so we should not get here.
+ throw new IOException("Unexpected coder result");
+ }
+ }
+ // Discard the bytes that have been read
+ decoderIn.compact();
+ }
+
+ /**
+ * Flush the output.
+ *
+ * @throws IOException if an I/O error occurs
+ */
+ private void flushOutput() throws IOException {
+ if (decoderOut.position() > 0) {
+ writer.write(decoderOut.array(), 0, decoderOut.position());
+ decoderOut.rewind();
+ }
+ }
+
+ private static void checkIbmJdkWithBrokenUTF16(Charset charset){
+ if (!"UTF-16".equals(charset.name())) return;
+ final String TEST_STRING_2 = "v\u00e9s";
+ byte[] bytes = TEST_STRING_2.getBytes(charset);
+
+ final CharsetDecoder charsetDecoder2 = charset.newDecoder();
+ ByteBuffer bb2 = ByteBuffer.allocate(16);
+ CharBuffer cb2 = CharBuffer.allocate(TEST_STRING_2.length());
+ final int len = bytes.length;
+ for (int i = 0; i < len; i++) {
+ bb2.put(bytes[i]);
+ bb2.flip();
+ try {
+ charsetDecoder2.decode(bb2, cb2, i == (len - 1));
+ } catch ( IllegalArgumentException e){
+ throw new UnsupportedOperationException("UTF-16 requested when runninng on an IBM JDK with broken UTF-16 support. " +
+ "Please find a JDK that supports UTF-16 if you intend to use UF-16 with WriterOutputStream");
+ }
+ bb2.compact();
+ }
+ cb2.rewind();
+ if (!TEST_STRING_2.equals(cb2.toString())){
+ throw new UnsupportedOperationException("UTF-16 requested when runninng on an IBM JDK with broken UTF-16 support. " +
+ "Please find a JDK that supports UTF-16 if you intend to use UF-16 with WriterOutputStream");
+ };
+
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/XmlStreamWriter.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/XmlStreamWriter.java"
new file mode 100644
index 0000000000000000000000000000000000000000..57d78bd55f08f8ded019ff02554422f9fcaa8d77
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/XmlStreamWriter.java"
@@ -0,0 +1,220 @@
+/*
+ * 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 org.apache.commons.io.output;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.io.input.XmlStreamReader;
+
+/**
+ * Character stream that handles all the necessary Voodo to figure out the
+ * charset encoding of the XML document written to the stream.
+ *
+ * @version $Id: XmlStreamWriter.java 1415850 2012-11-30 20:51:39Z ggregory $
+ * @see XmlStreamReader
+ * @since 2.0
+ */
+public class XmlStreamWriter extends Writer {
+ private static final int BUFFER_SIZE = 4096;
+
+ private final OutputStream out;
+
+ private final String defaultEncoding;
+
+ private StringWriter xmlPrologWriter = new StringWriter(BUFFER_SIZE);
+
+ private Writer writer;
+
+ private String encoding;
+
+ /**
+ * Construct an new XML stream writer for the specified output stream
+ * with a default encoding of UTF-8.
+ *
+ * @param out The output stream
+ */
+ public XmlStreamWriter(final OutputStream out) {
+ this(out, null);
+ }
+
+ /**
+ * Construct an new XML stream writer for the specified output stream
+ * with the specified default encoding.
+ *
+ * @param out The output stream
+ * @param defaultEncoding The default encoding if not encoding could be detected
+ */
+ public XmlStreamWriter(final OutputStream out, final String defaultEncoding) {
+ this.out = out;
+ this.defaultEncoding = defaultEncoding != null ? defaultEncoding : "UTF-8";
+ }
+
+ /**
+ * Construct an new XML stream writer for the specified file
+ * with a default encoding of UTF-8.
+ *
+ * @param file The file to write to
+ * @throws FileNotFoundException if there is an error creating or
+ * opening the file
+ */
+ public XmlStreamWriter(final File file) throws FileNotFoundException {
+ this(file, null);
+ }
+
+ /**
+ * Construct an new XML stream writer for the specified file
+ * with the specified default encoding.
+ *
+ * @param file The file to write to
+ * @param defaultEncoding The default encoding if not encoding could be detected
+ * @throws FileNotFoundException if there is an error creating or
+ * opening the file
+ */
+ public XmlStreamWriter(final File file, final String defaultEncoding) throws FileNotFoundException {
+ this(new FileOutputStream(file), defaultEncoding);
+ }
+
+ /**
+ * Return the detected encoding.
+ *
+ * @return the detected encoding
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * Return the default encoding.
+ *
+ * @return the default encoding
+ */
+ public String getDefaultEncoding() {
+ return defaultEncoding;
+ }
+
+ /**
+ * Close the underlying writer.
+ *
+ * @throws IOException if an error occurs closing the underlying writer
+ */
+ @Override
+ public void close() throws IOException {
+ if (writer == null) {
+ encoding = defaultEncoding;
+ writer = new OutputStreamWriter(out, encoding);
+ writer.write(xmlPrologWriter.toString());
+ }
+ writer.close();
+ }
+
+ /**
+ * Flush the underlying writer.
+ *
+ * @throws IOException if an error occurs flushing the underlying writer
+ */
+ @Override
+ public void flush() throws IOException {
+ if (writer != null) {
+ writer.flush();
+ }
+ }
+
+ /**
+ * Detect the encoding.
+ *
+ * @param cbuf the buffer to write the characters from
+ * @param off The start offset
+ * @param len The number of characters to write
+ * @throws IOException if an error occurs detecting the encoding
+ */
+ private void detectEncoding(final char[] cbuf, final int off, final int len)
+ throws IOException {
+ int size = len;
+ final StringBuffer xmlProlog = xmlPrologWriter.getBuffer();
+ if (xmlProlog.length() + len > BUFFER_SIZE) {
+ size = BUFFER_SIZE - xmlProlog.length();
+ }
+ xmlPrologWriter.write(cbuf, off, size);
+
+ // try to determine encoding
+ if (xmlProlog.length() >= 5) {
+ if (xmlProlog.substring(0, 5).equals("");
+ if (xmlPrologEnd > 0) {
+ // ok, full XML prolog written: let's extract encoding
+ final Matcher m = ENCODING_PATTERN.matcher(xmlProlog.substring(0,
+ xmlPrologEnd));
+ if (m.find()) {
+ encoding = m.group(1).toUpperCase();
+ encoding = encoding.substring(1, encoding.length() - 1);
+ } else {
+ // no encoding found in XML prolog: using default
+ // encoding
+ encoding = defaultEncoding;
+ }
+ } else {
+ if (xmlProlog.length() >= BUFFER_SIZE) {
+ // no encoding found in first characters: using default
+ // encoding
+ encoding = defaultEncoding;
+ }
+ }
+ } else {
+ // no XML prolog: using default encoding
+ encoding = defaultEncoding;
+ }
+ if (encoding != null) {
+ // encoding has been chosen: let's do it
+ xmlPrologWriter = null;
+ writer = new OutputStreamWriter(out, encoding);
+ writer.write(xmlProlog.toString());
+ if (len > size) {
+ writer.write(cbuf, off + size, len - size);
+ }
+ }
+ }
+ }
+
+ /**
+ * Write the characters to the underlying writer, detecing encoding.
+ *
+ * @param cbuf the buffer to write the characters from
+ * @param off The start offset
+ * @param len The number of characters to write
+ * @throws IOException if an error occurs detecting the encoding
+ */
+ @Override
+ public void write(final char[] cbuf, final int off, final int len) throws IOException {
+ if (xmlPrologWriter != null) {
+ detectEncoding(cbuf, off, len);
+ } else {
+ writer.write(cbuf, off, len);
+ }
+ }
+
+ static final Pattern ENCODING_PATTERN = XmlStreamReader.ENCODING_PATTERN;
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/package.html" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/package.html"
new file mode 100644
index 0000000000000000000000000000000000000000..44156133099931af89a39850a604cf96188722d0
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/output/package.html"
@@ -0,0 +1,25 @@
+
+
+
+
+
+This package provides implementations of output classes, such as
+OutputStream and Writer.
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/overview.html" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/overview.html"
new file mode 100644
index 0000000000000000000000000000000000000000..5f2ff1e77a3c9c9d854d43485f6ef43bb6337895
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/overview.html"
@@ -0,0 +1,32 @@
+
+
+
+
+
+The commons-io component contains utility classes,
+filters, streams, readers and writers.
+
+
+These classes aim to add to the standard JDK IO classes.
+The utilities provide convenience wrappers around the JDK, simplifying
+various operations into pre-tested units of code.
+The filters and streams provide useful implementations that perhaps should
+be in the JDK itself.
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/package.html" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/package.html"
new file mode 100644
index 0000000000000000000000000000000000000000..914a0a60c1a42eda8bea5a2a6d9f818d856a76a5
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/package.html"
@@ -0,0 +1,47 @@
+
+
+
+
+
+This package defines utility classes for working with streams, readers,
+writers and files. The most commonly used classes are described here:
+
+
+IOUtils is the most frequently used class.
+It provides operations to read, write, copy and close streams.
+
+
+FileUtils provides operations based around the JDK File class.
+These include reading, writing, copying, comparing and deleting.
+
+
+FilenameUtils provides utilities based on filenames.
+This utility class manipulates filenames without using File objects.
+It aims to simplify the transition between Windows and Unix.
+Before using this class however, you should consider whether you should
+be using File objects.
+
+
+FileSystemUtils allows access to the filing system in ways the JDK
+does not support. At present this allows you to get the free space on a drive.
+
+
+EndianUtils swaps data between Big-Endian and Little-Endian formats.
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/ClassNameMatcher.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/ClassNameMatcher.java"
new file mode 100644
index 0000000000000000000000000000000000000000..00c2a6585f688a1a35c612c0709bd8b6dda36699
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/ClassNameMatcher.java"
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.commons.io.serialization;
+
+/**
+ * An object that matches a Class name to a condition.
+ */
+public interface ClassNameMatcher {
+
+ /**
+ * Returns true if the supplied class name matches this object's condition.
+ *
+ * @param className fully qualified class name
+ * @return true if the class name matches this object's condition
+ */
+ boolean matches(String className);
+}
\ No newline at end of file
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/FullClassNameMatcher.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/FullClassNameMatcher.java"
new file mode 100644
index 0000000000000000000000000000000000000000..55f5e4c4380e2f83c35acdf5b0b1b9f2f6aeec90
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/FullClassNameMatcher.java"
@@ -0,0 +1,49 @@
+/*
+ * 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 org.apache.commons.io.serialization;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A {@link ClassNameMatcher} that matches on full class names.
+ *
+ * This object is immutable and thread-safe.
+ *
+ */
+final class FullClassNameMatcher implements ClassNameMatcher {
+
+ private final Set classesSet;
+
+ /**
+ * Constructs an object based on the specified class names.
+ *
+ * @param classes a list of class names
+ */
+ public FullClassNameMatcher(String... classes) {
+ classesSet = Collections.unmodifiableSet(new HashSet(Arrays.asList(classes)));
+ }
+
+ @Override
+ public boolean matches(String className) {
+ return classesSet.contains(className);
+ }
+}
\ No newline at end of file
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/RegexpClassNameMatcher.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/RegexpClassNameMatcher.java"
new file mode 100644
index 0000000000000000000000000000000000000000..2b8d18fe0f190eebbc2b46cff5a8a2e334d48f23
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/RegexpClassNameMatcher.java"
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.commons.io.serialization;
+
+import java.util.regex.Pattern;
+
+/**
+ * A {@link ClassNameMatcher} that uses regular expressions.
+ *
+ * This object is immutable and thread-safe.
+ *
+ */
+final class RegexpClassNameMatcher implements ClassNameMatcher {
+
+ private final Pattern pattern; // Class is thread-safe
+
+ /**
+ * Constructs an object based on the specified regular expression.
+ *
+ * @param regex a regular expression for evaluating acceptable class names
+ */
+ public RegexpClassNameMatcher(String regex) {
+ this(Pattern.compile(regex));
+ }
+
+ /**
+ * Constructs an object based on the specified pattern.
+ *
+ * @param pattern a pattern for evaluating acceptable class names
+ * @throws IllegalArgumentException if pattern is null
+ */
+ public RegexpClassNameMatcher(Pattern pattern) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("Null pattern");
+ }
+ this.pattern = pattern;
+ }
+
+ @Override
+ public boolean matches(String className) {
+ return pattern.matcher(className).matches();
+ }
+}
\ No newline at end of file
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/ValidatingObjectInputStream.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/ValidatingObjectInputStream.java"
new file mode 100644
index 0000000000000000000000000000000000000000..05e910dea6b6a171662957e30455c25e63539330
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/ValidatingObjectInputStream.java"
@@ -0,0 +1,209 @@
+/*
+ * 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 org.apache.commons.io.serialization;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InvalidClassException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * An ObjectInputStream that's restricted to deserialize
+ * a limited set of classes.
+ *
+ *
+ * Various accept/reject methods allow for specifying which classes
+ * can be deserialized.
+ *
+ *
+ *
+ * Design inspired by IBM
+ * DeveloperWorks Article .
+ *
+ */
+public class ValidatingObjectInputStream extends ObjectInputStream {
+ private final List acceptMatchers = new ArrayList();
+ private final List rejectMatchers = new ArrayList();
+
+ /**
+ * Constructs an object to deserialize the specified input stream.
+ * At least one accept method needs to be called to specify which
+ * classes can be deserialized, as by default no classes are
+ * accepted.
+ *
+ * @param input an input stream
+ * @throws IOException if an I/O error occurs while reading stream header
+ */
+ public ValidatingObjectInputStream(InputStream input) throws IOException {
+ super(input);
+ }
+
+ /** Check that the classname conforms to requirements.
+ * @param name The class name
+ * @throws InvalidClassException when a non-accepted class is encountered
+ */
+ private void validateClassName(String name) throws InvalidClassException {
+ // Reject has precedence over accept
+ for (ClassNameMatcher m : rejectMatchers) {
+ if (m.matches(name)) {
+ invalidClassNameFound(name);
+ }
+ }
+
+ boolean ok = false;
+ for (ClassNameMatcher m : acceptMatchers) {
+ if (m.matches(name)) {
+ ok = true;
+ break;
+ }
+ }
+ if (!ok) {
+ invalidClassNameFound(name);
+ }
+ }
+
+ /**
+ * Called to throw InvalidClassException if an invalid
+ * class name is found during deserialization. Can be overridden, for example
+ * to log those class names.
+ *
+ * @param className name of the invalid class
+ * @throws InvalidClassException if the specified class is not allowed
+ */
+ protected void invalidClassNameFound(String className) throws InvalidClassException {
+ throw new InvalidClassException("Class name not accepted: " + className);
+ }
+
+ @Override
+ protected Class> resolveClass(ObjectStreamClass osc) throws IOException, ClassNotFoundException {
+ validateClassName(osc.getName());
+ return super.resolveClass(osc);
+ }
+
+ /**
+ * Accept the specified classes for deserialization, unless they
+ * are otherwise rejected.
+ *
+ * @param classes Classes to accept
+ * @return this object
+ */
+ public ValidatingObjectInputStream accept(Class>... classes) {
+ for (Class> c : classes) {
+ acceptMatchers.add(new FullClassNameMatcher(c.getName()));
+ }
+ return this;
+ }
+
+ /**
+ * Reject the specified classes for deserialization, even if they
+ * are otherwise accepted.
+ *
+ * @param classes Classes to reject
+ * @return this object
+ */
+ public ValidatingObjectInputStream reject(Class>... classes) {
+ for (Class> c : classes) {
+ rejectMatchers.add(new FullClassNameMatcher(c.getName()));
+ }
+ return this;
+ }
+
+ /**
+ * Accept the wildcard specified classes for deserialization,
+ * unless they are otherwise rejected.
+ *
+ * @param patterns Wildcard filename patterns as defined by
+ * {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String) FilenameUtils.wildcardMatch}
+ * @return this object
+ */
+ public ValidatingObjectInputStream accept(String... patterns) {
+ for (String pattern : patterns) {
+ acceptMatchers.add(new WildcardClassNameMatcher(pattern));
+ }
+ return this;
+ }
+
+ /**
+ * Reject the wildcard specified classes for deserialization,
+ * even if they are otherwise accepted.
+ *
+ * @param patterns Wildcard filename patterns as defined by
+ * {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String) FilenameUtils.wildcardMatch}
+ * @return this object
+ */
+ public ValidatingObjectInputStream reject(String... patterns) {
+ for (String pattern : patterns) {
+ rejectMatchers.add(new WildcardClassNameMatcher(pattern));
+ }
+ return this;
+ }
+
+ /**
+ * Accept class names that match the supplied pattern for
+ * deserialization, unless they are otherwise rejected.
+ *
+ * @param pattern standard Java regexp
+ * @return this object
+ */
+ public ValidatingObjectInputStream accept(Pattern pattern) {
+ acceptMatchers.add(new RegexpClassNameMatcher(pattern));
+ return this;
+ }
+
+ /**
+ * Reject class names that match the supplied pattern for
+ * deserialization, even if they are otherwise accepted.
+ *
+ * @param pattern standard Java regexp
+ * @return this object
+ */
+ public ValidatingObjectInputStream reject(Pattern pattern) {
+ rejectMatchers.add(new RegexpClassNameMatcher(pattern));
+ return this;
+ }
+
+ /**
+ * Accept class names where the supplied ClassNameMatcher matches for
+ * deserialization, unless they are otherwise rejected.
+ *
+ * @param m the matcher to use
+ * @return this object
+ */
+ public ValidatingObjectInputStream accept(ClassNameMatcher m) {
+ acceptMatchers.add(m);
+ return this;
+ }
+
+ /**
+ * Reject class names where the supplied ClassNameMatcher matches for
+ * deserialization, even if they are otherwise accepted.
+ *
+ * @param m the matcher to use
+ * @return this object
+ */
+ public ValidatingObjectInputStream reject(ClassNameMatcher m) {
+ rejectMatchers.add(m);
+ return this;
+ }
+}
\ No newline at end of file
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/WildcardClassNameMatcher.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/WildcardClassNameMatcher.java"
new file mode 100644
index 0000000000000000000000000000000000000000..98a1fc7bace81562eb49085cf206e42bd3dde6aa
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/WildcardClassNameMatcher.java"
@@ -0,0 +1,47 @@
+/*
+ * 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 org.apache.commons.io.serialization;
+
+import org.apache.commons.io.FilenameUtils;
+
+/**
+ * A {@link ClassNameMatcher} that uses simplified regular expressions
+ * provided by {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String) FilenameUtils.wildcardMatch}
+ *
+ * This object is immutable and thread-safe.
+ *
+ */
+final class WildcardClassNameMatcher implements ClassNameMatcher {
+
+ private final String pattern;
+
+ /**
+ * Constructs an object based on the specified simplified regular expression.
+ *
+ * @param pattern a {@link FilenameUtils#wildcardMatch} pattern.
+ */
+ public WildcardClassNameMatcher(String pattern) {
+ this.pattern = pattern;
+ }
+
+ @Override
+ public boolean matches(String className) {
+ return FilenameUtils.wildcardMatch(className, pattern);
+ }
+}
\ No newline at end of file
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/package.html" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/package.html"
new file mode 100644
index 0000000000000000000000000000000000000000..271802e4daeac7706a86e072e317870fc4ea2c51
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/main/java/org/apache/commons/io/serialization/package.html"
@@ -0,0 +1,24 @@
+
+
+
+
+
+This package provides a framework for controlling the deserialization of classes.
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/media/io-logo-white.xcf" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/media/io-logo-white.xcf"
new file mode 100644
index 0000000000000000000000000000000000000000..a3c899b544aef363d6ff27150b8d3a0480a63268
Binary files /dev/null and "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/media/io-logo-white.xcf" differ
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/media/logo.gif" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/media/logo.gif"
new file mode 100644
index 0000000000000000000000000000000000000000..314441b415c5059cb2c0082efa683d798250c565
Binary files /dev/null and "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/media/logo.gif" differ
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/resources/download_io.cgi" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/resources/download_io.cgi"
new file mode 100644
index 0000000000000000000000000000000000000000..495cde12dc8febbe45696b96fb29c372be24fa0b
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/resources/download_io.cgi"
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Just call the standard mirrors.cgi script. It will use download.html
+# as the input template.
+exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $*
\ No newline at end of file
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/resources/images/io-logo-white.png" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/resources/images/io-logo-white.png"
new file mode 100644
index 0000000000000000000000000000000000000000..75be7af462d68915926b292656fd475760aa7739
Binary files /dev/null and "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/resources/images/io-logo-white.png" differ
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/site.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/site.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..84ec68c86bf1942df8eba1af7e465f1c077ae1e7
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/site.xml"
@@ -0,0 +1,49 @@
+
+
+
+
+ Commons IO
+ /images/io-logo-white.png
+ /index.html
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/bestpractices.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/bestpractices.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..a4382df6d3e20125bac49c153f7f02139733d63a
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/bestpractices.xml"
@@ -0,0 +1,135 @@
+
+
+
+
+ Best practices
+ Commons Documentation Team
+
+
+
+
+
+ This document presents a number of 'best practices' in the IO area.
+
+
+
+
+
+
+ Often, you have to deal with files and filenames. There are many
+ things that can go wrong:
+
+
+ A class works in Unix but doesn't on Windows (or vice versa)
+ Invalid filenames due to double or missing path separators
+ UNC filenames (on Windows) don't work with my home-grown filename utility function
+ etc. etc.
+
+
+ These are good reasons not to work with filenames as Strings.
+ Using java.io.File instead handles many of the above cases nicely.
+ Thus, our best practice recommendation is to use java.io.File
+ instead of String for filenames to avoid platform dependencies.
+
+
+
+ Version 1.1 of commons-io now includes a dedicated filename
+ handling class - FilenameUtils .
+ This does handle many of these filename issues, however we still
+ recommend, wherever possible, that you use java.io.File objects.
+
+
+
+ Let's look at an example.
+
+
+ public static String getExtension(String filename) {
+ int index = filename.lastIndexOf('.');
+ if (index == -1) {
+ return "";
+ } else {
+ return filename.substring(index + 1);
+ }
+ }
+
+ Easy enough? Right, but what happens if someone passes in a full path
+ instead of only a filename? Consider the following, perfectly legal path:
+ "C:\Temp\documentation.new\README".
+ The method as defined above would return "new\README" - definitely
+ not what you wanted.
+
+
+ Please use java.io.File for filenames instead of Strings.
+ The functionality that the class provides is well tested.
+ In FileUtils you will find other useful utility functions
+ around java.io.File.
+
+
+ Instead of:
+
+
+ String tmpdir = "/var/tmp";
+ String tmpfile = tmpdir + System.getProperty("file.separator") + "test.tmp";
+ InputStream in = new java.io.FileInputStream(tmpfile);
+
+ ...write:
+
+
+ File tmpdir = new File("/var/tmp");
+ File tmpfile = new File(tmpdir, "test.tmp");
+ InputStream in = new java.io.FileInputStream(tmpfile);
+
+
+
+
+
+ IO performance depends a lot from the buffering strategy. Usually, it's
+ quite fast to read packets with the size of 512 or 1024 bytes because
+ these sizes match well with the packet sizes used on harddisks in
+ file systems or file system caches. But as soon as you have to read only
+ a few bytes and that many times performance drops significantly.
+
+
+ Make sure you're properly buffering streams when reading or writing
+ streams, especially when working with files. Just decorate your
+ FileInputStream with a BufferedInputStream:
+
+
+ InputStream in = new java.io.FileInputStream(myfile);
+ try {
+ in = new java.io.BufferedInputStream(in);
+
+ in.read(.....
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+
+ Pay attention that you're not buffering an already buffered stream. Some
+ components like XML parsers may do their own buffering so decorating
+ the InputStream you pass to the XML parser does nothing but slowing down
+ your code. If you use our CopyUtils or IOUtils you don't need to
+ additionally buffer the streams you use as the code in there already
+ buffers the copy process. Always check the Javadocs for information.
+ Another case where buffering is unnecessary is when you write to a
+ ByteArrayOutputStream since you're writing to memory only.
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/building.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/building.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..eed872ea9988efbd6f3f76aed1ee58133958fd47
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/building.xml"
@@ -0,0 +1,79 @@
+
+
+
+
+ Building
+ Commons Documentation Team
+
+
+
+
+
+
+ The following Maven commands can be used to build io:
+
+
+ mvn clean - clean up
+ mvn test - compile and run the unit tests
+ mvn site - create io documentation
+ mvn package - build the jar
+ mvn package -Prc - Create the source and binary distributions
+
+
+
+
+
+ Note:
+
+ Dependencies are automatically downloaded if not specified explicitly in
+ a build.properties file.
+
+
+
+ The following Ant commands can be used to build io:
+
+
+ ant clean - clean up
+ ant test - compile and run the unit tests
+ ant javadoc - create javadocs
+ ant jar - build the jar
+ ant dist - Create the source and binary distributions
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/description.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/description.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..df0d55c7a50a792c8cc28ac296636444c68c1bbc
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/description.xml"
@@ -0,0 +1,259 @@
+
+
+
+
+ User guide
+ Commons Documentation Team
+
+
+
+
+
+
+
+
+ IOUtils
+ contains utility methods dealing with reading, writing and copying.
+ The methods work on InputStream, OutputStream, Reader and Writer.
+
+
+ As an example, consider the task of reading bytes
+ from a URL, and printing them. This would typically done like this:
+
+
+
+ InputStream in = new URL( "http://commons.apache.org" ).openStream();
+ try {
+ InputStreamReader inR = new InputStreamReader( in );
+ BufferedReader buf = new BufferedReader( inR );
+ String line;
+ while ( ( line = buf.readLine() ) != null ) {
+ System.out.println( line );
+ }
+ } finally {
+ in.close();
+ }
+
+
+ With the IOUtils class, that could be done with:
+
+
+
+ InputStream in = new URL( "http://commons.apache.org" ).openStream();
+ try {
+ System.out.println( IOUtils.toString( in ) );
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+
+
+ In certain application domains, such IO operations are
+ common, and this class can save a great deal of time. And you can
+ rely on well-tested code.
+
+
+ For utility code such as this, flexibility and speed are of primary importance.
+ However you should also understand the limitations of this approach.
+ Using the above technique to read a 1GB file would result in an
+ attempt to create a 1GB String object!
+
+
+
+
+
+
+ The FileUtils
+ class contains utility methods for working with File objects.
+ These include reading, writing, copying and comparing files.
+
+
+ For example to read an entire file line by line you could use:
+
+
+ File file = new File("/commons/io/project.properties");
+ List lines = FileUtils.readLines(file, "UTF-8");
+
+
+
+
+ The FilenameUtils
+ class contains utility methods for working with filenames without
+ using File objects. The class aims to be consistent
+ between Unix and Windows, to aid transitions between these
+ environments (such as moving from development to production).
+
+
+ For example to normalize a filename removing double dot segments:
+
+
+ String filename = "C:/commons/io/../lang/project.xml";
+ String normalized = FilenameUtils.normalize(filename);
+ // result is "C:/commons/lang/project.xml"
+
+
+
+
+ The FileSystemUtils
+ class contains
+ utility methods for working with the file system
+ to access functionality not supported by the JDK.
+ Currently, the only method is to get the free space on a drive.
+ Note that this uses the command line, not native code.
+
+
+ For example to find the free space on a drive:
+
+
+ long freeSpace = FileSystemUtils.freeSpace("C:/");
+
+
+
+
+
+
+ Different computer architectures adopt different
+ conventions for byte ordering. In so-called
+ "Little Endian" architectures (eg Intel), the low-order
+ byte is stored in memory at the lowest address, and
+ subsequent bytes at higher addresses. For "Big Endian"
+ architectures (eg Motorola), the situation is reversed.
+
+
+
+ There are two classes in this package of relevance:
+
+
+
+
+ The EndianUtils
+ class contains static methods for swapping the Endian-ness
+ of Java primitives and streams.
+
+
+
+ The SwappedDataInputStream
+ class is an implementation of the DataInput interface. With
+ this, one can read data from files of non-native Endian-ness.
+
+
+
+
+ For more information, see
+ http://www.cs.umass.edu/~verts/cs32/endian.html
+
+
+
+
+
+
+ The org.apache.commons.io.LineIterator class
+ provides a flexible way for working with a line-based file.
+ An instance can be created directly, or via factory methods on
+ FileUtils or IOUtils.
+ The recommended usage pattern is:
+
+
+ LineIterator it = FileUtils.lineIterator(file, "UTF-8");
+ try {
+ while (it.hasNext()) {
+ String line = it.nextLine();
+ /// do something with line
+ }
+ } finally {
+ LineIterator.closeQuietly(iterator);
+ }
+
+
+
+
+ The org.apache.commons.io.filefilter
+ package defines an interface
+ (IOFileFilter )
+ that combines both java.io.FileFilter and
+ java.io.FilenameFilter. Besides
+ that the package offers a series of ready-to-use
+ implementations of the IOFileFilter
+ interface including
+ implementation that allow you to combine other such filters.
+
+ These filters can be used to list files or in FileDialog, for example.
+
+
+ See the
+ filefilter
+ package javadoc for more details.
+
+
+
+
+
+ The org.apache.commons.io.comparator
+ package provides a number of java.util.Comparator
+ implementations for java.io.File.
+
+ These comparators can be used to sort lists and arrays of files, for example.
+
+
+ See the
+ comparator
+ package javadoc for more details.
+
+
+
+
+
+ The org.apache.commons.io.input and
+ org.apache.commons.io.output packages
+ contain various useful implementations of streams.
+ These include:
+
+ Null output stream - that silently absorbs all data sent to it
+ Tee output stream - that sends output data to two streams instead of one
+ Byte array output stream - that is a faster version of the JDK class
+ Counting streams - that count the number of bytes passed
+ Proxy streams - that delegate to the correct method in the proxy
+ Lockable writer - that provides synchronization of writes using a lock file
+
+
+
+ See the
+ input or
+ output
+ package javadoc for more details.
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/download_io.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/download_io.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..bbb25653f9270b916c948e82df2554ba1f0a5409
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/download_io.xml"
@@ -0,0 +1,138 @@
+
+
+
+
+
+ Download Apache Commons IO
+ Commons Documentation Team
+
+
+
+
+
+ We recommend you use a mirror to download our release
+ builds, but you must verify the integrity of
+ the downloaded files using signatures downloaded from our main
+ distribution directories. Recent releases (48 hours) may not yet
+ be available from the mirrors.
+
+
+
+ You are currently using [preferred] . If you
+ encounter a problem with this mirror, please select another
+ mirror. If all mirrors are failing, there are backup
+ mirrors (at the end of the mirrors list) that should be
+ available.
+
+ [if-any logo] [end]
+
+
+
+
+
+ The KEYS
+ link links to the code signing keys used to sign the product.
+ The PGP link downloads the OpenPGP compatible signature from our main site.
+ The MD5 link downloads the checksum from the main site.
+
+
+
+
+
+
+ Older releases can be obtained from the archives.
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/index.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/index.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..7a1f16009a688f8e6d3887497cf2507e825b1c94
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/index.xml"
@@ -0,0 +1,109 @@
+
+
+
+
+ Commons IO Overview
+ Commons Documentation Team
+
+
+
+
+
+Commons IO is a library of utilities to assist with developing IO functionality.
+
+
+There are six main areas included:
+
+Utility classes
+ - with static methods to perform common tasks
+Input
+ - useful Input Stream and Reader implementations
+Output
+ - useful Output Stream and Writer implementations
+Filters
+ - various implementations of file filters
+Comparators
+ - various implementations of java.util.Comparator for files
+File Monitor
+ - a component for monitoring file system events
+
+
+
+
+
+
+
+
+The commons mailing lists act as the main support forum.
+The user list is suitable for most library usage queries.
+The dev list is intended for the development discussion.
+Please remember that the lists are shared between all commons components,
+so prefix your email by [io].
+
+
+Issues may be reported via ASF JIRA .
+Please read the instructions carefully to submit a useful bug report or enhancement request.
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/issue-tracking.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/issue-tracking.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..9e059440ed57d6039c21e819504613e405f9dc06
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/issue-tracking.xml"
@@ -0,0 +1,102 @@
+
+
+
+
+
+ Commons IO Issue tracking
+ Commons Documentation Team
+
+
+
+
+
+
+ Please also remember these points:
+
+ the more information you provide, the better we can help you
+ test cases are vital, particularly for any proposed enhancements
+ the developers of Commons IO are all unpaid volunteers
+
+
+
+
+ For more information on subversion and creating patches see the
+ Apache Contributors Guide .
+
+
+
+ You may also find these links useful:
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/mail-lists.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/mail-lists.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..0e375acae92863128e811408cdd5278dec3edef9
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/mail-lists.xml"
@@ -0,0 +1,202 @@
+
+
+
+
+
+ Commons IO Mailing Lists
+ Commons Documentation Team
+
+
+
+
+
+ Commons IO shares mailing lists with all the other
+ Commons Components .
+ To make it easier for people to only read messages related to components they are interested in,
+ the convention in Commons is to prefix the subject line of messages with the component's name,
+ for example:
+
+ [io] Problem with the ...
+
+
+
+ Questions related to the usage of Commons IO should be posted to the
+ User List .
+
+ The Developer List
+ is for questions and discussion related to the development of Commons IO.
+
+ Please do not cross-post; developers are also subscribed to the user list.
+
+
+ Note: please don't send patches or attachments to any of the mailing lists.
+ Patches are best handled via the Issue Tracking system.
+ Otherwise, please upload the file to a public server and include the URL in the mail.
+
+
+
+
+
+ Please prefix the subject line of any messages for Commons IO
+ with [io] - thanks!
+
+
+
+
+
+
+
+
+
+ Other mailing lists which you may find useful include:
+
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/proposal.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/proposal.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..ac20c4d22b1b50e4d39fc164c6924da230b026bd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/proposal.xml"
@@ -0,0 +1,88 @@
+
+
+
+
+
+ Proposal
+ Commons Documentation Team
+
+
+
+
+
+
+
+
+
+
+Many software projects have a need to perform I/O in various ways, and
+the JDK class libraries provide a lot of functionality, but sometimes you
+need just a little bit more. The io package seeks to encapsulate some of
+the most popular i/o base classes into one easy to use package.
+
+
+
+
+This proposal is to create a package of Java utility classes for various
+types of i/o related activity.
+
+
+
+
+IO relies only on standard JDK 1.2 (or later) APIs for production
+deployment. It utilizes the JUnit unit testing framework for developing
+and executing unit tests, but this is of interest only to developers of the
+component. IO will be a dependency for several existing components in the
+open source world.
+
+No external configuration files are utilized.
+
+
+
+
+The original Java classes are splashed around various Apache subprojects.
+ We intend to seek them out and integrate them.
+
+The proposed package name for the new component is org.apache.commons.io.
+
+
+
+
+
+ CVS Repository - New directory io in the jakarta-commons
+CVS repository.
+ Mailing List - Discussions will take place on the general dev@commons.apache.org
+mailing list. To help list subscribers identify messages of interest,
+it is suggested that the message subject of messages about this component
+be prefixed with [IO].
+ Bugzilla - New component "IO" under the "Commons" product category,
+with appropriate version identifiers as needed.
+ Jyve FAQ - New category "commons-io" (when available).
+
+
+
+
+
+
+The initial committers on the IO component shall be Scott Sanders and
+Nicola Ken Barozzi and Henri Yandell
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/tasks.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/tasks.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..76919fd3e88bc5f6b0674fd2010306f177149ce7
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/tasks.xml"
@@ -0,0 +1,39 @@
+
+
+
+
+ Tasks
+ Commons Documentation Team
+
+
+
+
+ The following are some of the proposed ideas and tasks for commons-io:
+
+
+ A proper user guide
+ A URLUtils class that has many of the FileUtils operations, but for a URL
+ FilePoller for telling when a file changes. Look in Tomcat, or GenJava[bayard] (One implemented in bugzilla awaiting investigation)
+ A "hot folder" handler which triggers an action when a new file has been uploaded to an FTP directory, for example.
+ JoinReader/ConcatReader. One in GenJava, one submitted to Bayard
+ FormattedWriter, when it writes out values it uses Format objects to output them.
+ FixedWidthReader. Reads in files with a known width, ie) mainframe like.
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_1.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_1.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..1b0e725963e6d547bfa3203c46be0273ee11ffea
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_1.xml"
@@ -0,0 +1,207 @@
+
+
+
+
+ Upgrade from 1.0 to 1.1
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 1.0 to version 1.1.
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+and endian transformation classes.
+
+
+Incompatible changes from 1.0
+-----------------------------
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes, except:
+- FileUtils.writeStringToFile()
+ A null encoding previously used 'ISO-8859-1', now it uses the platform default
+ Generally this will make no difference
+
+- LockableFileWriter
+ Improved validation and now create directories if necesssary
+
+plus these bug fixes may affect you semantically:
+- FileUtils.touch() (Bug fix 29821)
+ Now creates the file if it did not previously exist
+
+- FileUtils.toFile(URL) (Bug fix 32575)
+ Now handles escape syntax such as %20
+
+- FileUtils.sizeOfDirectory() (Bug fix 36801)
+ May now return a size of 0 if the directory is security restricted
+
+
+Deprecations from 1.0
+---------------------
+- CopyUtils has been deprecated.
+ Its methods have been moved to IOUtils.
+ The new IOUtils methods handle nulls better, and have clearer names.
+
+- IOUtils.toByteArray(String) - Use {@link String#getBytes()}
+- IOUtils.toString(byte[]) - Use {@link String#String(byte[])}
+- IOUtils.toString(byte[],String) - Use {@link String#String(byte[],String)}
+
+
+Bug fixes from 1.0
+------------------
+- FileUtils - touch() [29821]
+ Now creates the file if it did not previously exist
+
+- FileUtils - toFile(URL) [32575]
+ Now handles escape syntax such as %20
+
+- FileFilterUtils - makeCVSAware(IOFileFilter) [33023]
+ Fixed bug that caused method to be completely broken
+
+- CountingInputStream [33336]
+ Fixed bug that caused the count to reduce by one at the end of the stream
+
+- CountingInputStream - skip(long) [34311]
+ Bytes from calls to this method were not previously counted
+
+- NullOutputStream [33481]
+ Remove unnecessary synchronization
+
+- AbstractFileFilter - accept(File, String) [30992]
+ Fixed broken implementation
+
+- FileUtils [36801]
+ Previously threw NPE when listing files in a security restricted directory
+ Now throw IOException with a better message
+
+- FileUtils - writeStringToFile()
+ Null encoding now correctly uses the platform default
+
+
+Enhancements from 1.0
+---------------------
+- FilenameUtils - new class [33303,29351]
+ A static utility class for working with filenames
+ Seeks to ease the pain of developing on Windows and deploying on Unix
+
+- FileSystemUtils - new class [32982,36325]
+ A static utility class for working with file systems
+ Provides one method at present, to get the free space on the filing system
+
+- IOUtils - new public constants
+ Constants for directory and line separators on Windows and Unix
+
+- IOUtils - toByteArray(Reader,encoding)
+ Handles encodings when reading to a byte array
+
+- IOUtils - toCharArray(InputStream) [28979]
+ - toCharArray(InputStream,encoding)
+ - toCharArray(Reader)
+ Reads a stream/reader into a charatcter array
+
+- IOUtils - readLines(InputStream) [36214]
+ - readLines(InputStream,encoding)
+ - readLines(Reader)
+ Reads a stream/reader line by line into a List of Strings
+
+- IOUtils - toInputStream(String) [32958]
+ - toInputStream(String,encoding)
+ Creates an input stream that uses the string as a source of data
+
+- IOUtils - writeLines(Collection,lineEnding,OutputStream) [36214]
+ - writeLines(Collection,lineEnding,OutputStream,encoding)
+ - writeLines(Collection,lineEnding,Writer)
+ Writes a collection to a stream/writer line by line
+
+- IOUtils - write(...)
+ Write data to a stream/writer (moved from CopyUtils with better null handling)
+
+- IOUtils - copy(...)
+ Copy data between streams (moved from CopyUtils with better null handling)
+
+- IOUtils - contentEquals(Reader,Reader)
+ Method to compare the contents of two readers
+
+- FileUtils - toFiles(URL[])
+ Converts an array of URLs to an array of Files
+
+- FileUtils - copyDirectory() [32944]
+ New methods to copy a directory
+
+- FileUtils - readFileToByteArray(File)
+ Reads an entire file into a byte array
+
+- FileUtils - writeByteArrayToFile(File,byte[])
+ Writes a byte array to a file
+
+- FileUtils - readLines(File,encoding) [36214]
+ Reads a file line by line into a List of Strings
+
+- FileUtils - writeLines(File,encoding,List)
+ writeLines(File,encoding,List,lineEnding)
+ Writes a collection to a file line by line
+
+- FileUtils - EMPTY_FILE_ARRAY
+ Constant for an empty array of File objects
+
+- ConditionalFileFilter - new interface [30705]
+ Defines the behaviour of list based filters
+
+- AndFileFilter, OrFileFilter [30705]
+ Now support a list of filters to and/or
+
+- WildcardFilter [31115]
+ New filter that can match using wildcard file names
+
+- FileFilterUtils - makeSVNAware(IOFileFilter)
+ New method, like makeCVSAware, that ignores Subversion source control directories
+
+- ClassLoaderObjectInputStream
+ An ObjectInputStream that supports a ClassLoader
+
+- CountingInputStream,CountingOutputStream - resetCount() [28976]
+ Adds the ability to reset the count part way through reading/writing the stream
+
+- DeferredFileOutputStream - writeTo(OutputStream) [34173]
+ New method to allow current contents to be written to a stream
+
+- DeferredFileOutputStream [34142]
+ Performance optimizations avoiding double buffering
+
+- LockableFileWriter - encoding support [36825]
+ Add support for character encodings to LockableFileWriter
+ Improve the validation
+ Create directories if necesssary
+
+- IOUtils and EndianUtils are no longer final [28978]
+ Allows developers to have subclasses if desired
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_2.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_2.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..67b45d3a1bef5e843564b3c4a779df2a67ece721
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_2.xml"
@@ -0,0 +1,90 @@
+
+
+
+
+ Upgrade from 1.1 to 1.2
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 1.1 to version 1.2.
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+and endian transformation classes.
+
+
+Compatibility with 1.1
+----------------------
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes
+
+
+Deprecations from 1.1
+---------------------
+
+
+Bug fixes from 1.1
+------------------
+- FileSystemUtils.freeSpace(drive)
+ Fix to allow Windows based command to function in French locale
+
+- FileUtils.read*
+ Increase certainty that files are closed in case of error
+
+- LockableFileWriter
+ Locking mechanism was broken and only provided limited protection [38942]
+ File deletion and locking in case of constructor error was broken
+
+
+Enhancements from 1.1
+---------------------
+- AgeFileFilter/SizeFileFilter
+ New file filters that compares against the age and size of the file
+
+- FileSystemUtils.freeSpaceKb(drive)
+ New method that unifies result to be in kilobytes [38574]
+
+- FileUtils.contentEquals(File,File)
+ Performance improved by adding length and file location checking
+
+- FileUtils.iterateFiles
+ Two new method to provide direct access to iterators over files
+
+- FileUtils.lineIterator
+ IOUtils.lineIterator
+ New methods to provide an iterator over the lines in a file [38083]
+
+- FileUtils.copyDirectoryToDirectory
+ New method to copy a directory to within another directory [36315]
+
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..a243a3e1e2f41409bf7516dfa1a09eefb5493054
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3.xml"
@@ -0,0 +1,228 @@
+
+
+
+
+ Upgrade from 1.2 to 1.3
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 1.2 to version 1.3.
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+and endian transformation classes.
+
+
+Compatibility with 1.2
+----------------------
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes
+ Check the bug fixes section for semantic bug fixes
+
+
+Deprecations from 1.2
+---------------------
+- WildcardFilter deprecated, replaced by WildcardFileFilter
+ - old class only accepted files, thus had a confusing dual purpose
+
+- FileSystemUtils.freeSpace deprecated, replaced by freeSpaceKb
+ - freeSpace returns a result that varies by operating system and
+ thus isn't that useful
+ - freeSpaceKb returns much better and more consistent results
+ - freeSpaceKb existed in v1.2, so this is a gentle cutover
+
+
+Bug fixes from 1.2
+------------------
+- LineIterator now implements Iterator
+ - It was always supposed to...
+
+- FileSystemUtils.freeSpace/freeSpaceKb [IO-83]
+ - These should now work on AIX and HP-UX
+
+- FileSystemUtils.freeSpace/freeSpaceKb [IO-90]
+ - Avoid infinite looping in Windows
+ - Catch more errors with nice messages
+
+- FileSystemUtils.freeSpace [IO-91]
+ - This is now documented not to work on SunOS 5
+
+- FileSystemUtils [IO-93]
+ - Fixed resource leak leading to 'Too many open files' error
+ - Previously did not destroy Process instances (as JDK Javadoc is so poor)
+ - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4801027
+
+- FileUtils.touch [IO-100]
+ - The touch method previously gave no indication when the file could not
+ be touched successfully (such as due to access restrictions) - it now
+ throws an IOException if the last modified date cannot be changed
+
+- FileCleaner
+ - This now handles the situation where an error occurs when deleting the file
+
+- IOUtils.copy [IO-84]
+ - Copy methods could return inaccurate byte/char count for large streams
+ - The copy(InputStream, OutputStream) method now returns -1 if the count is greater than an int
+ - The copy(Reader, Writer) method now throws now returns -1 if the count is greater than an int
+ - Added a new copyLarge(InputStream, OutputStream) method that returns a long
+ - Added a new copyLarge(Reader, Writer) method that returns a long
+
+- CountingInputStream/CountingOutputStream [IO-84]
+ - Methods were declared as int thus the count was innacurate for large streams
+ - new long based methods getByteCount()/resetByteCount() added
+ - existing methods changed to throw an exception if the count is greater than an int
+
+- FileBasedTestCase
+ - Fixed bug in compare content methods identified by GNU classpath
+
+- EndianUtils.writeSwappedLong(byte[], int) [IO-101]
+ - An int overrun in the bit shifting when it should have been a long
+
+- EndianUtils.writeSwappedLong(InputStream) [IO-102]
+ - The return of input.read(byte[]) was not being checked to ensure all 8 bytes were read
+
+Enhancements from 1.2
+---------------------
+- DirectoryWalker [IO-86]
+ - New class designed for subclassing to walk through a set of files.
+ DirectoryWalker provides the walk of the directories, filtering of
+ directories and files, and cancellation support. The subclass must provide
+ the specific behaviour, such as text searching or image processing.
+
+- IOCase
+ - New class/enumeration for case-sensitivity control
+
+- FilenameUtils
+ - New methods to handle case-sensitivity
+ - wildcardMatch - new method that has IOCase as a parameter
+ - equals - new method that has IOCase as a parameter
+
+- FileUtils [IO-108] - new default encoding methods for:
+ - readFileToString(File)
+ - readLines(File)
+ - lineIterator(File)
+ - writeStringToFile(File, String)
+ - writeLines(File, Collection)
+ - writeLines(File, Collection, String)
+
+- FileUtils.openOutputStream [IO-107]
+ - new method to open a FileOutputStream, creating parent directories if required
+- FileUtils.touch
+- FileUtils.copyURLToFile
+- FileUtils.writeStringToFile
+- FileUtils.writeByteArrayToFile
+- FileUtils.writeLines
+ - enhanced to create parent directories if required
+- FileUtils.openInputStream [IO-107]
+ - new method to open a FileInputStream, providing better error messages than the JDK
+
+- FileUtils.isFileOlder
+ - new methods to check if a file is older (i.e. isFileOlder()) - counterparts
+ to the existing isFileNewer() methods.
+
+- FileUtils.checksum, FileUtils.checksumCRC32
+ - new methods to create a checksum of a file
+
+- FileUtils.copyFileToDirectory [IO-104]
+ - new variant that optionally retains the file date
+
+- FileDeleteStrategy
+- FileCleaner [IO-56,IO-70]
+ - FileDeleteStrategy is a strategy for handling file deletion
+ - This can be used as a calback in FileCleaner
+ - Together these allow FileCleaner to do a forceDelete to kill directories
+
+- FileCleaner.exitWhenFinished [IO-99]
+ - A new method that allows the internal cleaner thread to be cleanly terminated
+
+- WildcardFileFilter
+ - Replacement for WildcardFilter
+ - Accepts both files and directories
+ - Ability to control case-sensitivity
+
+- NameFileFilter
+ - Ability to control case-sensitivity
+
+- FileFileFilter
+ - New IOFileFilter implementation
+ - Accepts files where File.isFile() is true
+ - In other words it filters out directories
+ - Singleton instance provided (FILE)
+
+- CanReadFileFilter
+ - New IOFileFilter implementation
+ - Accepts files where File.canRead() is true
+ - Singleton instances provided (CAN_READ/CANNOT_READ/READ_ONLY)
+
+- CanWriteFileFilter
+ - New IOFileFilter implementation
+ - Accepts files where File.canWrite() is true
+ - Singleton instances provided (CAN_WRITE/CANNOT_WRITE)
+
+- HiddenFileFilter
+ - New IOFileFilter implementation
+ - Accepts files where File.isHidden() is true
+ - Singleton instances provided (HIDDEN/VISIBLE)
+
+- EmptyFileFilter
+ - New IOFileFilter implementation
+ - Accepts files or directories that are empty
+ - Singleton instances provided (EMPTY/NOT_EMPTY)
+
+- TrueFileFilter/FalseFileFilter/DirectoryFileFilter
+ - New singleton instance constants (TRUE/FALSE/DIRECTORY)
+ - The new constants are more JDK 1.5 friendly with regards to static imports
+ (whereas if everything uses INSTANCE, then they just clash)
+ - The old INSTANCE constants are still present and have not been deprecated
+
+- FileFilterUtils.sizeRangeFileFilter
+ - new sizeRangeFileFilter(long minimumSize, long maximumSize) method which
+ creates a filter that accepts files within the specified size range.
+
+- FileFilterUtils.makeDirectoryOnly/makeFileOnly
+ - two new methods that decorate a file filter to make it apply to
+ directories only or files only
+
+- NullWriter
+ - New writer that acts as a sink for all data, as per /dev/null
+
+- NullInputStream
+ - New input stream that emulates a stream of a specified size
+
+- NullReader
+ - New reader that emulates a reader of a specified size
+
+- ByteArrayOutputStream [IO-97]
+ - Performance enhancements
+
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3_1.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3_1.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..baec5c11566d02b6905979848adef01705456dc0
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3_1.xml"
@@ -0,0 +1,60 @@
+
+
+
+
+ Upgrade from 1.3 to 1.3.1
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 1.3 to version 1.3.1.
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+and endian transformation classes.
+
+
+Compatibility with 1.3
+----------------------
+Binary compatible - No
+ See [IO-113]
+
+Source compatible - No
+ See [IO-113]
+
+Semantic compatible - Yes
+
+
+Bug fixes from 1.3
+------------------
+
+- FileUtils
+ - NPE in openOutputStream(File) when file has no parent in path [IO-112]
+ - readFileToString(File) is not static [IO-113]
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3_2.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3_2.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..4baebea60ab12af71b11daa1904ab3d85b8d6ac1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_3_2.xml"
@@ -0,0 +1,87 @@
+
+
+
+
+ Upgrade from 1.3, or 1.3.1, to 1.3.2
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 1.3, or 1.3.1, to version 1.3.2.
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+and endian transformation classes.
+
+
+Compatibility with 1.3.1
+------------------------
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes
+ Check the bug fixes section for semantic bug fixes
+
+
+Compatibility with 1.3
+----------------------
+Binary compatible - No
+ See [IO-113]
+
+Source compatible - No
+ See [IO-113]
+
+Semantic compatible - Yes
+
+
+Enhancements since 1.3.1
+------------------------
+
+- Created the FileCleaningTracker, basically a non-static version of the
+ FileCleaner, which can be controlled by the user. [IO-116]
+- The FileCleaner is deprecated. (For reasons of compatibility, the
+ deprecation warnings are hidden within the 1.3 branch. They'll be
+ visible, as of version 1.4.)
+
+
+Bug fixes from 1.3.1
+--------------------
+
+- Some tests, which are implicitly assuming a Unix-like file system, are
+ now skipped on Windows. [IO-115]
+
+
+Bug fixes from 1.3
+------------------
+
+- FileUtils
+ - NPE in openOutputStream(File) when file has no parent in path [IO-112]
+ - readFileToString(File) is not static [IO-113]
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_4.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_4.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..7056de7a44093d9da6671da78e9b8810062ae1e1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto1_4.xml"
@@ -0,0 +1,142 @@
+
+
+
+
+ Upgrade from 1.3.2 to 1.4
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 1.3.2 to version 1.4.
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+file comparators and endian transformation classes.
+
+
+Compatibility with 1.3.2
+------------------------
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes
+ Check the bug fixes section for semantic bug fixes
+
+Commons IO 1.4 introduces four new implementations which depend on JDK 1.4 features
+(CharSequenceReader, FileWriterWithEncoding, IOExceptionWithCause and RegexFileFilter).
+It has been built with the JDK source and target options set to JDK 1.3 and, except for
+those implementations, can be used with JDK 1.3 (see IO IO-127).
+
+
+Deprecations from 1.3.2
+-----------------------
+- FileCleaner deprecated in favour of FileCleaningTracker [see IO-116]
+
+
+Bug fixes from 1.3.2
+--------------------
+- FileUtils
+ - forceDelete of orphaned Softlinks does not work [IO-147]
+ - Infinite loop on FileUtils.copyDirectory when the destination directory is within
+ the source directory [IO-141]
+
+- HexDump
+ - HexDump's use of static StringBuffers isn't thread-safe [IO-136]
+
+
+Enhancements from 1.3.2
+-----------------------
+- FileUtils
+ - Add a deleteQuietly method [IO-135]
+ - Add a copyDirectory() method that makes use of FileFilter [IO-105]
+ - Add moveDirectory() and moveFile() methods [IO-77]
+
+- FilenameUtils
+ - Add file name extension separator constants[IO-149]
+
+- IOExceptionWithCause [IO-148]
+ - Add a new IOException implementation with constructors which take a cause
+
+- TeeInputStream [IO-129]
+ - Add new Tee input stream implementation
+
+- FileWriterWithEncoding [IO-153]
+ - Add new File Writer implementation that accepts an encoding
+
+- CharSequenceReader [IO-138]
+ - Add new Reader implementation that handles any CharSequence (String,
+ StringBuffer, StringBuilder or CharBuffer)
+
+- ThesholdingOuputStream [IO-121]
+ - Add a reset() method which sets the count of the bytes written back to zero.
+
+- DeferredFileOutputStream [IO-130]
+ - Add support for temporary files
+
+- ByteArrayOutputStream
+ - Add a new write(InputStream) method [IO-152]
+
+- New Closed Input/Output stream implementations [IO-122]
+ - AutoCloseInputStream - automatically closes and discards the underlying input stream
+ - ClosedInputStream - returns -1 for any read attempts
+ - ClosedOutputStream - throws an IOException for any write attempts
+ - CloseShieldInputStream - prevents the underlying input stream from being closed.
+ - CloseShieldOutputStream - prevents the underlying output stream from being closed.
+
+- Add Singleton Constants to several stream classes [IO-143]
+
+- PrefixFileFilter [IO-126]
+ - Add faciltiy to specify case sensitivity on prefix matching
+
+- SuffixFileFilter [IO-126]
+ - Add faciltiy to specify case sensitivity on suffix matching
+
+- RegexFileFilter [IO-74]
+ - Add new regular expression file filter implementation
+
+- Make IOFileFilter implementations Serializable [IO-131]
+
+- Improve IOFileFilter toString() methods [IO-120]
+
+- Make fields final so classes are immutable/threadsafe [IO-133]
+ - changes to Age, Delegate, Name, Not, Prefix, Regex, Size, Suffix and Wildcard IOFileFilter
+ implementations.
+
+- IOCase
+ - Add a compare method to IOCase [IO-144]
+
+- Add a package of java.util.Comparator implementations for files [IO-145]
+ - DefaultFileComparator - compare files using the default File.compareTo(File) method.
+ - ExtensionFileComparator - compares files using file name extensions.
+ - LastModifiedFileComparator - compares files using the last modified date/time.
+ - NameFileComparator - compares files using file names.
+ - PathFileComparator - compares files using file paths.
+ - SizeFileComparator - compares files using file sizes.
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_0.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_0.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..3a9dd0aad462f8f45563d762a7db6969cf395386
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_0.xml"
@@ -0,0 +1,157 @@
+
+
+
+
+ Upgrade from 1.4 to 2.0
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 1.4 to version 2.0.
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+file comparators and endian transformation classes.
+
+
+Compatibility with 1.4
+----------------------
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes
+ Check the bug fixes section for semantic bug fixes
+
+Commons IO 2.0 requires a minimum of JDK 1.5
+ (Commons IO 1.4 had a minimum of JDK 1.3)
+
+
+Deprecations from 1.4
+---------------------
+
+- IOUtils
+ - write(StringBuffer, Writer) in favour of write(CharSequence, Writer)
+ - write(StringBuffer, OutputStream) in favour of write(CharSequence, OutputStream)
+ - write(StringBuffer, OutputStream, String) in favour of write(CharSequence, OutputStream, String)
+
+- FileFilterUtils
+ - andFileFilter(IOFileFilter, IOFileFilter) in favour of and(IOFileFilter...)
+ - orFileFilter(IOFileFilter, IOFileFilter) in favour of or(IOFileFilter...)
+
+
+Enhancements from 1.4
+---------------------
+
+ * [IO-140] Move minimum Java requirement from JDK 1.3 to JDK 1.5
+ - use Generics
+ - add new CharSequence write() flavour methods to IOUtils and FileUtils
+ - replace StringBuffer with StringBuilder, where appropriate
+ - add new Reader/Writer methods to ProxyReader and ProxyWriter
+ - Annotate with @Override and @Deprecated
+
+ * [IO-178] New BOMInputStream and ByteOrderMark implementations - to detect and optionally exclude an initial Byte Order mark (BOM)
+ * [IO-197] New BoundedInputStream (copied from from Apache JackRabbit)
+ * [IO-193] New Broken Input and Output streams
+ * [IO-132] New File Listener/Monitor facility
+ * [IO-158] New ReaderInputStream and WriterOutputStream implementations
+ * [IO-139] New StringBuilder Writer implementation
+ * [IO-192] New Tagged Input and Output streams
+ * [IO-177] New Tailer class - simple implementation of the Unix "tail -f" functionality
+ * [IO-162] New XML Stream Reader/Writer implementations (from ROME via plexus-utils)
+
+ * [IO-142] Comparators - add facility to sort file lists/arrays
+ * [IO-186] Comparators - new Composite and Directory File Comparator implementations
+ * [IO-176] DirectoryWalker - add filterDirectoryContents() callback method for filtering directory contents
+ * [IO-210] FileFilter - new Magic Number FileFilter
+ * [IO-221] FileFilterUtils - add methods for suffix and prefix filters which take an IOCase object
+ * [IO-232] FileFilterUtils - add method for name filters which take an IOCase object
+ * [IO-229] FileFilterUtils - add varargs and() and or() methods
+ * [IO-198] FileFilterUtils - add ability to apply file filters to collections and arrays
+ * [IO-156] FilenameUtils - add normalize() and normalizeNoEndSeparator() methods which allow the separator character to be specified
+ * [IO-194] FileSystemUtils - add freeSpaceKb() method with no input arguments
+ * [IO-185] FileSystemUtils - add freeSpaceKb() methods that take a timeout parameter - fixes freeSpaceWindows() blocks
+ * [IO-155] FileUtils - use NIO to copy files
+ * [IO-168] FileUtils - add new isSymlink() method
+ * [IO-219] FileUtils - throw FileExistsException when moving a file or directory if the destination already exists
+ * [IO-234] FileUtils - add Methods for retrieving System User/Temp directories/paths
+ * [IO-208] FileUtils - add timeout (connection and read) support for copyURLToFile() method
+ * [IO-238] FileUtils - add sizeOf(File) method
+ * [IO-181] LineIterator now implements Iterable
+ * [IO-224] IOUtils - add closeQuietly(Closeable) and closeQuietly(Socket) methods
+ * [IO-203] IOUtils - add skipFully() method for InputStreams
+ * [IO-137] IOUtils and ByteArrayOutputStream - add toBufferedInputStream() method to avoid unnecessary array allocation/copy
+ * [IO-195] Proxy streams/Reader/Writer - provide exception handling methods
+ * [IO-211] Proxy Input/Output streams - add pre/post processing support
+ * [IO-242] Proxy Reader/Writer - add pre/post processing support
+
+
+Bug fixes from 1.4
+------------------
+ * [IO-214] ByteArrayOutputStream - fix inconsistent synchronization of fields
+ * [IO-201] Counting Input/Output streams - fix inconsistent synchronization
+ * [IO-159] FileCleaningTracker - fix remove() never returns null
+ * [IO-220] FileCleaningTracker - fix Vector performs badly under load
+ * [IO-167] FilenameUtils - fix case-insensitive string handling in FilenameUtils and FilesystemUtils
+ * [IO-179] FilenameUtils - fix StringIndexOutOfBounds exception in getPathNoEndSeparator()
+ * [IO-248] FilenameUtils - fix getFullPathNoEndSeparator() returns empty while path is a one level directory
+ * [IO-246] FilenameUtils - fix wildcardMatch gives incorrect results
+ * [IO-187] FileSystemUtils - fix freeSpaceKb() doesn't work with relative paths on Linux
+ * [IO-160] FileSystemUtils - fix freeSpace() fails on solaris
+ * [IO-209] FileSystemUtils - fix freeSpaceKb() fails to return correct size for a windows mount point
+ * [IO-163] FileUtils - fix toURLs() using deprecated method of conversion to URL
+ * [IO-168] FileUtils - fix Symbolic links followed when deleting directory
+ * [IO-231] FileUtils - fix wrong exception message generated in isFileNewer() method
+ * [IO-207] FileUtils - fix race condition in forceMkdir() method
+ * [IO-217] FileUtils - fix copyDirectoryToDirectory() makes infinite loops
+ * [IO-166] FileUtils - fix URL decoding in toFile(URL)
+ * [IO-190] FileUtils - fix copyDirectory not preserving lastmodified date on sub-directories
+ * [IO-240] FileFilterUtils - ensure cvsFilter and svnFilter are only created once.
+ * [IO-175] IOUtils - fix copyFile() issues with very large files
+ * [IO-191] Improvements from static analysis
+ * [IO-216] LockableFileWriter - delete files quietly when an exception is thrown during initialization
+ * [IO-243] SwappedDataInputStream - fix readBoolean is inverted
+ * [IO-235] Tests - remove unused YellOnFlushAndCloseOutputStream from CopyUtilsTest
+ * [IO-161] Tests - fix FileCleaningTrackerTestCase hanging
+
+
+Documentation changes from 1.4
+------------------------------
+ * [IO-183 FilenameUtils.getExtension() method documentation improvements
+ * [IO-226 FileUtils.byteCountToDisplaySize() documentation corrections
+ * [IO-205 FileUtils.forceMkdir() documentation improvements
+ * [IO-215 FileUtils copy file/directory improve documentation regarding preserving the last modified date
+ * [IO-189 HexDump.dump() method documentation improvements
+ * [IO-171 IOCase document that it assumes there are only two OSes: Windows and Unix
+ * [IO-223 IOUtils.copy() documentation corrections
+ * [IO-247 IOUtils.closeQuietly() improve documentation with examples
+ * [IO-202 NotFileFilter documentation corrections
+ * [IO-206 ProxyInputStream - fix misleading parameter names
+ * [IO-212 ProxyInputStream.skip() documentation corrections
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_0_1.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_0_1.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..5f6f53eaa839c422094dcd16067186831b0c1caa
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_0_1.xml"
@@ -0,0 +1,67 @@
+
+
+
+
+ Upgrade from 2.0 to 2.0.1
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 2.0 to version 2.0.1
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+file comparators and endian transformation classes.
+
+
+Compatibility with 2.0 and 1.4
+------------------------------
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes
+ Check the bug fixes section for semantic bug fixes
+
+Commons IO 2.0.1 requires a minimum of JDK 1.5
+ (Commons IO 1.4 had a minimum of JDK 1.3)
+
+
+Enhancements from 2.0
+---------------------
+
+ * [IO-256] - Provide thread factory for FileAlternationMonitor
+
+
+Bug fixes from 2.0
+------------------
+
+ * [IO-257] - BOMInputStream.read(byte[]) can return 0 which it should not
+ * [IO-258] - XmlStreamReader consumes the stream during encoding detection
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_1.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_1.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..f1f75b56c8ea4366e4bae7755ddc94b15a20ba81
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_1.xml"
@@ -0,0 +1,82 @@
+
+
+
+
+ Upgrade from 2.0.1 to 2.1
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 2.0.1 to version 2.1
+
+Commons IO is a package of Java utility classes for java.io's hierarchy.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+file comparators and endian transformation classes.
+
+Compatibility with 2.0.1 and 1.4
+--------------------------------
+
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes
+ Check the bug fixes section for semantic bug fixes
+
+Commons IO 2.1 requires a minimum of JDK 1.5
+ (Commons IO 1.4 had a minimum of JDK 1.3)
+
+
+New features since 2.0.1
+------------------------
+
+o Use standard Maven directory layout Issue: IO-285. Thanks to ggregory.
+o Add IOUtils API toString for URL and URI to get contents Issue: IO-284. Thanks to ggregory.
+o Add API FileUtils.copyFile(File input, OutputStream output) Issue: IO-282. Thanks to ggregory.
+o FileAlterationObserver has no getter for FileFilter Issue: IO-262.
+o Add FileUtils.getFile API with varargs parameter Issue: IO-261.
+o Add new APPEND parameter for writing string into files Issue: IO-182.
+o Add new read method "toByteArray" to handle InputStream with known size. Issue: IO-251. Thanks to Marco Albini.
+
+Fixed Bugs since 2.0.1
+----------------------
+
+o Dubious use of mkdirs() return code Issue: IO-280. Thanks to sebb.
+o ReaderInputStream enters infinite loop when it encounters an unmappable character Issue: IO-277.
+o FileUtils.moveFile() JavaDoc should specify FileExistsException thrown Issue: IO-264.
+o ClassLoaderObjectInputStream does not handle Proxy classes Issue: IO-260.
+o Tailer returning partial lines when reaching EOF before EOL Issue: IO-274. Thanks to Frank Grimes.
+o FileUtils.copyFile() throws IOException when copying large files to a shared directory (on Windows) Issue: IO-266. Thanks to Igor Smereka.
+o FileSystemUtils.freeSpaceKb throws exception for Windows volumes with no visible files.
+ Improve coverage by also looking for hidden files. Issue: IO-263. Thanks to Gil Adam.
+
+Changes since 2.0.1
+-------------------
+o FileAlterationMonitor.stop(boolean allowIntervalToFinish) Issue: IO-259.
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_2.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_2.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..45497e6932f504a351eebe891977cad0babcf0f2
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_2.xml"
@@ -0,0 +1,82 @@
+
+
+
+
+ Upgrade from 2.1 to 2.2
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 2.1 to version 2.2
+
+Commons IO is a package of Java utility classes like java.io.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters,
+file comparators, endian transformation classes, and much more.
+
+==============================================================================
+Commons IO Package Version 2.2
+==============================================================================
+
+Changes in this version include:
+
+New features:
+o IO-305: New copyLarge() method in IOUtils that takes additional offset, length arguments Thanks to Manoj Mokashi.
+o IO-287: Use terabyte (TB) , petabyte (PB) and exabyte (EB) in FileUtils.byteCountToDisplaySize(long size) Thanks to Ron Kuris, Gary Gregory.
+o IO-173: FileUtils.listFiles() doesn't return directories Thanks to Marcos Vinícius da Silva.
+o IO-297: CharSequenceInputStream to efficiently stream content of a CharSequence Thanks to Oleg Kalnichevski.
+o IO-304: The second constructor of Tailer class does not pass 'delay' to the third one Thanks to liangly.
+o IO-303: TeeOutputStream does not call branch.close() when main.close() throws an exception Thanks to fabian.barney.
+o IO-302: ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times Thanks to jsteuerwald, detinho.
+o IO-301: Add IOUtils.closeQuietly(Selector) necessary Thanks to kaykay.unique.
+o IO-292: IOUtils.closeQuietly() should take a ServerSocket as a parameter Thanks to sebb.
+o IO-290: Add read/readFully methods to IOUtils Thanks to sebb.
+o IO-288: Supply a ReversedLinesFileReader Thanks to Georg Henzler.
+o IO-291: Add new function FileUtils.directoryContains. Thanks to ggregory.
+o IO-275: FileUtils.contentEquals and IOUtils.contentEquals - Add option to ignore "line endings"
+ Added contentEqualsIgnoreEOL methods to both classes Thanks to CJ Aspromgos.
+
+Fixed Bugs:
+o IO-300: FileUtils.moveDirectoryToDirectory removes source directory if destination is a subdirectory
+o IO-307: ReaderInputStream#read(byte[] b, int off, int len) should check for valid parameters
+o IO-306: ReaderInputStream#read(byte[] b, int off, int len) should always return 0 for length == 0
+o IO-276: "FileUtils#deleteDirectoryOnExit(File)" does not work Thanks to nkami.
+o IO-273: BoundedInputStream.read() treats max differently from BoundedInputStream.read(byte[]...) Thanks to sebb.
+o IO-298: Various methods of class 'org.apache.commons.io.FileUtils' incorrectly suppress 'java.io.IOException' Thanks to Christian Schulte.
+
+Changes:
+o IO-296: ReaderInputStream optimization: more efficient reading of small chunks of data Thanks to Oleg Kalnichevski.
+
+Compatibility with 2.1 and 1.4:
+Binary compatible: Yes
+Source compatible: Yes
+Semantic compatible: Yes. Check the bug fixes section for semantic bug fixes
+
+Commons IO 2.2 requires a minimum of JDK 1.5.
+Commons IO 1.4 requires a minimum of JDK 1.3.
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_3.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_3.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..56a4948208ac745f716a0b0b074a94415f800d3c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_3.xml"
@@ -0,0 +1,61 @@
+
+
+
+
+ Upgrade from 2.2 to 2.3
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 2.2 to version 2.3
+
+Commons IO is a package of Java utility classes like java.io.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+The Commons IO library contains utility classes, stream implementations, file filters,
+file comparators, endian transformation classes, and much more.
+
+==============================================================================
+Apache Commons IO Version 2.3-SNAPSHOT
+==============================================================================
+
+Changes in this version include:
+
+New features:
+o IO-322: Add and use class Charsets. Thanks to ggregory.
+o IO-321: ByteOrderMark UTF_32LE is incorrect. Thanks to ggregory.
+o IO-318: Add Charset sister APIs to method that take a String charset name. Thanks to ggregory.
+
+Compatibility with 2.2 and 1.4:
+Binary compatible: Yes.
+Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
+Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
+
+Commons IO 2.3 requires JDK 1.6 or later.
+Commons IO 2.2 requires JDK 1.5 or later.
+Commons IO 1.4 requires JDK 1.3 or later.
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_4.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_4.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..9f46468265193a825eecc39f78f952dad18ccf78
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_4.xml"
@@ -0,0 +1,81 @@
+
+
+
+
+ Upgrade from 2.3 to 2.4
+ Commons Documentation Team
+
+
+
+
+
+These are the release notes and advice for upgrading Commons-IO from
+version 2.3 to version 2.4
+
+Commons IO is a package of Java utility classes like java.io.
+Classes in this package are considered to be so standard and of such high
+reuse as to justify existence in java.io.
+
+The Commons IO library contains utility classes, stream implementations, file filters,
+file comparators, endian transformation classes, and much more.
+
+==============================================================================
+Apache Commons IO Version 2.4-SNAPSHOT
+==============================================================================
+
+Changes in this version include:
+
+New features:
+o IO-269: Tailer locks file from deletion/rename on Windows. Thanks to sebb.
+o IO-333: Export OSGi packages at version 1.x in addition to 2.x. Thanks to fmeschbe.
+o IO-320: Add XmlStreamReader support for UTF-32. Thanks to ggregory.
+o IO-331: BOMInputStream wrongly detects UTF-32LE_BOM files as UTF-16LE_BOM files in method getBOM(). Thanks to ggregory.
+o IO-327: Add byteCountToDisplaySize(BigInteger). Thanks to ggregory.
+o IO-326: Add new FileUtils.sizeOf[Directory] APIs to return BigInteger. Thanks to ggregory.
+o IO-325: Add IOUtils.toByteArray methods to work with URL and URI. Thanks to raviprak.
+o IO-324: Add missing Charset sister APIs to method that take a String charset name. Thanks to raviprak.
+
+Fixed Bugs:
+o IO-279: Tailer erroneously considers file as new. Thanks to Sergio Bossa, Chris Baron.
+o IO-335: Tailer#readLines - incorrect CR handling.
+o IO-334: FileUtils.toURLs throws NPE for null parameter; document the behavior.
+o IO-332: Improve tailer's reading performance. Thanks to liangly.
+o IO-279: Improve Tailer performance with buffered reads (see IO-332).
+o IO-329: FileUtils.writeLines uses unbuffered IO. Thanks to tivv.
+o IO-319: FileUtils.sizeOfDirectory follows symbolic links. Thanks to raviprak.
+
+Compatibility with 2.3:
+Binary compatible: Yes.
+Source compatible: Yes.
+Semantic compatible: Yes.
+
+Compatibility with 2.2 and 1.4:
+Binary compatible: Yes.
+Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
+Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
+
+Commons IO 2.4 requires JDK 1.6 or later.
+Commons IO 2.3 requires JDK 1.6 or later.
+Commons IO 2.2 requires JDK 1.5 or later.
+Commons IO 1.4 requires JDK 1.3 or later.
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_5.xml" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_5.xml"
new file mode 100644
index 0000000000000000000000000000000000000000..a706c04b686637b56b34fd42c21b58bcb513d381
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/site/xdoc/upgradeto2_5.xml"
@@ -0,0 +1,84 @@
+
+
+
+
+ Upgrade from 2.4 to 2.5
+ Commons Documentation Team
+
+
+
+
+
+ These are the release notes and advice for upgrading Commons-IO from
+ version 2.4 to version 2.5
+
+ Commons IO is a package of Java utility classes like java.io.
+ Classes in this package are considered to be so standard and of such high
+ reuse as to justify existence in java.io.
+
+ The Commons IO library contains utility classes, stream implementations, file filters,
+ file comparators, endian transformation classes, and much more.
+
+ ==============================================================================
+ Apache Commons IO Version 2.4-SNAPSHOT
+ ==============================================================================
+
+ Changes in this version include:
+
+ New features:
+ o IO-269: Tailer locks file from deletion/rename on Windows. Thanks to sebb.
+ o IO-333: Export OSGi packages at version 1.x in addition to 2.x. Thanks to fmeschbe.
+ o IO-320: Add XmlStreamReader support for UTF-32. Thanks to ggregory.
+ o IO-331: BOMInputStream wrongly detects UTF-32LE_BOM files as UTF-16LE_BOM files in method
+ getBOM(). Thanks to ggregory.
+ o IO-327: Add byteCountToDisplaySize(BigInteger). Thanks to ggregory.
+ o IO-326: Add new FileUtils.sizeOf[Directory] APIs to return BigInteger. Thanks to ggregory.
+ o IO-325: Add IOUtils.toByteArray methods to work with URL and URI. Thanks to raviprak.
+ o IO-324: Add missing Charset sister APIs to method that take a String charset name. Thanks to
+ raviprak.
+
+ Fixed Bugs:
+ o IO-279: Tailer erroneously considers file as new. Thanks to Sergio Bossa, Chris Baron.
+ o IO-335: Tailer#readLines - incorrect CR handling.
+ o IO-334: FileUtils.toURLs throws NPE for null parameter; document the behavior.
+ o IO-332: Improve tailer's reading performance. Thanks to liangly.
+ o IO-279: Improve Tailer performance with buffered reads (see IO-332).
+ o IO-329: FileUtils.writeLines uses unbuffered IO. Thanks to tivv.
+ o IO-319: FileUtils.sizeOfDirectory follows symbolic links. Thanks to raviprak.
+
+ Compatibility with 2.3:
+ Binary compatible: Yes.
+ Source compatible: Yes.
+ Semantic compatible: Yes.
+
+ Compatibility with 2.2 and 1.4:
+ Binary compatible: Yes.
+ Source compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
+ Semantic compatible: No, see the rare case in https://issues.apache.org/jira/browse/IO-318.
+
+ Commons IO 2.5 requires JDK 1.6 or later.
+ Commons IO 2.4 requires JDK 1.6 or later.
+ Commons IO 2.3 requires JDK 1.6 or later.
+ Commons IO 2.2 requires JDK 1.5 or later.
+ Commons IO 1.4 requires JDK 1.3 or later.
+
+
+
+
+
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..92fdc22899acee2bc31e25790ae7bdabf4a764fa
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java"
@@ -0,0 +1,147 @@
+/*
+ * 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 org.apache.commons.io;
+
+
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Test for {@link ByteOrderMark}.
+ *
+ * @version $Id: ByteOrderMarkTestCase.java 1718944 2015-12-09 19:50:30Z krosenvold $
+ */
+public class ByteOrderMarkTestCase {
+
+ private static final ByteOrderMark TEST_BOM_1 = new ByteOrderMark("test1", 1);
+ private static final ByteOrderMark TEST_BOM_2 = new ByteOrderMark("test2", 1, 2);
+ private static final ByteOrderMark TEST_BOM_3 = new ByteOrderMark("test3", 1, 2, 3);
+
+ /** Test {@link ByteOrderMark#getCharsetName()} */
+ @Test
+ public void charsetName() {
+ assertEquals("test1 name", "test1", TEST_BOM_1.getCharsetName());
+ assertEquals("test2 name", "test2", TEST_BOM_2.getCharsetName());
+ assertEquals("test3 name", "test3", TEST_BOM_3.getCharsetName());
+ }
+
+ /** Tests that {@link ByteOrderMark#getCharsetName()} can be loaded as a {@link java.nio.charset.Charset} as advertised. */
+ @Test
+ public void constantCharsetNames() {
+ assertNotNull(Charset.forName(ByteOrderMark.UTF_8.getCharsetName()));
+ assertNotNull(Charset.forName(ByteOrderMark.UTF_16BE.getCharsetName()));
+ assertNotNull(Charset.forName(ByteOrderMark.UTF_16LE.getCharsetName()));
+ assertNotNull(Charset.forName(ByteOrderMark.UTF_32BE.getCharsetName()));
+ assertNotNull(Charset.forName(ByteOrderMark.UTF_32LE.getCharsetName()));
+ }
+
+ /** Test {@link ByteOrderMark#length()} */
+ @Test
+ public void testLength() { assertEquals("test1 length", 1, TEST_BOM_1.length());
+ assertEquals("test2 length", 2, TEST_BOM_2.length());
+ assertEquals("test3 length", 3, TEST_BOM_3.length());
+ }
+
+ /** Test {@link ByteOrderMark#get(int)} */
+ @Test
+ public void get() {
+ assertEquals("test1 get(0)", 1, TEST_BOM_1.get(0));
+ assertEquals("test2 get(0)", 1, TEST_BOM_2.get(0));
+ assertEquals("test2 get(1)", 2, TEST_BOM_2.get(1));
+ assertEquals("test3 get(0)", 1, TEST_BOM_3.get(0));
+ assertEquals("test3 get(1)", 2, TEST_BOM_3.get(1));
+ assertEquals("test3 get(2)", 3, TEST_BOM_3.get(2));
+ }
+
+ /** Test {@link ByteOrderMark#getBytes()} */
+ @Test
+ public void getBytes() {
+ assertTrue("test1 bytes", Arrays.equals(TEST_BOM_1.getBytes(), new byte[] {(byte)1}));
+ assertTrue("test1 bytes", Arrays.equals(TEST_BOM_2.getBytes(), new byte[] {(byte)1, (byte)2}));
+ assertTrue("test1 bytes", Arrays.equals(TEST_BOM_3.getBytes(), new byte[] {(byte)1, (byte)2, (byte)3}));
+ }
+
+ /** Test {@link ByteOrderMark#equals(Object)} */
+ @SuppressWarnings("EqualsWithItself")
+ @Test
+ public void testEquals() {
+ assertTrue("test1 equals", TEST_BOM_1.equals(TEST_BOM_1));
+ assertTrue("test2 equals", TEST_BOM_2.equals(TEST_BOM_2));
+ assertTrue("test3 equals", TEST_BOM_3.equals(TEST_BOM_3));
+
+ assertFalse("Object not equal", TEST_BOM_1.equals(new Object()));
+ assertFalse("test1-1 not equal", TEST_BOM_1.equals(new ByteOrderMark("1a", 2)));
+ assertFalse("test1-2 not test2", TEST_BOM_1.equals(new ByteOrderMark("1b", 1, 2)));
+ assertFalse("test2 not equal", TEST_BOM_2.equals(new ByteOrderMark("2", 1, 1)));
+ assertFalse("test3 not equal", TEST_BOM_3.equals(new ByteOrderMark("3", 1, 2, 4)));
+ }
+
+ /** Test {@link ByteOrderMark#hashCode()} */
+ @Test
+ public void testHashCode() {
+ final int bomClassHash = ByteOrderMark.class.hashCode();
+ assertEquals("hash test1 ", bomClassHash + 1, TEST_BOM_1.hashCode());
+ assertEquals("hash test2 ", bomClassHash + 3, TEST_BOM_2.hashCode());
+ assertEquals("hash test3 ", bomClassHash + 6, TEST_BOM_3.hashCode());
+ }
+
+ /** Test Erros */
+ @Test
+ public void errors() {
+ try {
+ new ByteOrderMark(null, 1,2,3);
+ fail("null charset name, expected IllegalArgumentException");
+ } catch (final IllegalArgumentException e) {
+ // expected
+ }
+ try {
+ new ByteOrderMark("", 1,2,3);
+ fail("no charset name, expected IllegalArgumentException");
+ } catch (final IllegalArgumentException e) {
+ // expected
+ }
+ try {
+ new ByteOrderMark("a", (int[])null);
+ fail("null bytes, expected IllegalArgumentException");
+ } catch (final IllegalArgumentException e) {
+ // expected
+ }
+ try {
+ new ByteOrderMark("b");
+ fail("empty bytes, expected IllegalArgumentException");
+ } catch (final IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /** Test {@link ByteOrderMark#toString()} */
+ @Test
+ public void testToString() {
+ assertEquals("test1 ", "ByteOrderMark[test1: 0x1]", TEST_BOM_1.toString());
+ assertEquals("test2 ", "ByteOrderMark[test2: 0x1,0x2]", TEST_BOM_2.toString());
+ assertEquals("test3 ", "ByteOrderMark[test3: 0x1,0x2,0x3]", TEST_BOM_3.toString());
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/CharsetsTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/CharsetsTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..9f50dd043b0ad5eeb83b2ed9e543714c7c2a8cf2
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/CharsetsTestCase.java"
@@ -0,0 +1,90 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.nio.charset.Charset;
+import java.util.SortedMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests {@link Charsets}.
+ *
+ * @version $Id: CharEncodingTest.java 1298985 2012-03-09 19:12:49Z ggregory $
+ */
+public class CharsetsTestCase {
+
+ @Test
+ public void testRequiredCharsets() {
+ final SortedMap requiredCharsets = Charsets.requiredCharsets();
+ // test for what we expect to be there as of Java 6
+ // Make sure the object at the given key is the right one
+ Assert.assertEquals(requiredCharsets.get("US-ASCII").name(), "US-ASCII");
+ Assert.assertEquals(requiredCharsets.get("ISO-8859-1").name(), "ISO-8859-1");
+ Assert.assertEquals(requiredCharsets.get("UTF-8").name(), "UTF-8");
+ Assert.assertEquals(requiredCharsets.get("UTF-16").name(), "UTF-16");
+ Assert.assertEquals(requiredCharsets.get("UTF-16BE").name(), "UTF-16BE");
+ Assert.assertEquals(requiredCharsets.get("UTF-16LE").name(), "UTF-16LE");
+ }
+
+ @Test
+ @SuppressWarnings("deprecation") // unavoidable until Java 7
+ public void testIso8859_1() {
+ Assert.assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name());
+ }
+
+ @Test
+ public void testToCharset() {
+ Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null));
+ Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null));
+ Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset()));
+ Assert.assertEquals(Charset.forName("UTF-8"), Charsets.toCharset(Charset.forName("UTF-8")));
+ }
+
+ @Test
+ @SuppressWarnings("deprecation") // unavoidable until Java 7
+ public void testUsAscii() {
+ Assert.assertEquals("US-ASCII", Charsets.US_ASCII.name());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation") // unavoidable until Java 7
+ public void testUtf16() {
+ Assert.assertEquals("UTF-16", Charsets.UTF_16.name());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation") // unavoidable until Java 7
+ public void testUtf16Be() {
+ Assert.assertEquals("UTF-16BE", Charsets.UTF_16BE.name());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation") // unavoidable until Java 7
+ public void testUtf16Le() {
+ Assert.assertEquals("UTF-16LE", Charsets.UTF_16LE.name());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation") // unavoidable until Java 7
+ public void testUtf8() {
+ Assert.assertEquals("UTF-8", Charsets.UTF_8.name());
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/CopyUtilsTest.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/CopyUtilsTest.java"
new file mode 100644
index 0000000000000000000000000000000000000000..7b6add92e4c775043f4051c4f4c510c2fc191758
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/CopyUtilsTest.java"
@@ -0,0 +1,225 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Arrays;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.apache.commons.io.testtools.TestUtils;
+import org.apache.commons.io.testtools.YellOnCloseInputStream;
+import org.apache.commons.io.testtools.YellOnFlushAndCloseOutputStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+@SuppressWarnings("deprecation") // these are test cases for the deprecated CopyUtils
+
+/**
+ * JUnit tests for CopyUtils.
+ *
+ * @version $Id: CopyUtilsTest.java 1718944 2015-12-09 19:50:30Z krosenvold $
+ * @see CopyUtils
+ */
+public class CopyUtilsTest extends FileBasedTestCase {
+
+ /*
+ * NOTE this is not particularly beautiful code. A better way to check for
+ * flush and close status would be to implement "trojan horse" wrapper
+ * implementations of the various stream classes, which set a flag when
+ * relevant methods are called. (JT)
+ */
+
+ private static final int FILE_SIZE = 1024 * 4 + 1;
+
+
+ private final byte[] inData = TestUtils.generateTestData((long) FILE_SIZE);
+
+ // ----------------------------------------------------------------
+ // Tests
+ // ----------------------------------------------------------------
+
+ @Test
+ public void testCtor() {
+ new CopyUtils();
+ // Nothing to assert, the constructor is public and does not blow up.
+ }
+
+ @Test
+ public void copy_byteArrayToOutputStream() throws Exception {
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
+
+ CopyUtils.copy(inData, out);
+
+ assertEquals("Sizes differ", inData.length, baout.size());
+ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
+ }
+
+ @Test
+ public void copy_byteArrayToWriter() throws Exception {
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
+ final Writer writer = new java.io.OutputStreamWriter(out, "US-ASCII");
+
+ CopyUtils.copy(inData, writer);
+ writer.flush();
+
+ assertEquals("Sizes differ", inData.length, baout.size());
+ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
+ }
+
+ @Test
+ public void testCopy_byteArrayToWriterWithEncoding() throws Exception {
+ final String inDataStr = "data";
+ final String charsetName = "UTF-8";
+ final StringWriter writer = new StringWriter();
+ CopyUtils.copy(inDataStr.getBytes(charsetName), writer, charsetName);
+ assertEquals(inDataStr, writer.toString());
+ }
+
+ @SuppressWarnings("resource") // 'in' is deliberately not closed
+ @Test
+ public void testCopy_inputStreamToOutputStream() throws Exception {
+ InputStream in = new ByteArrayInputStream(inData);
+ in = new YellOnCloseInputStream(in);
+
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
+
+ final int count = CopyUtils.copy(in, out);
+
+ assertEquals("Not all bytes were read", 0, in.available());
+ assertEquals("Sizes differ", inData.length, baout.size());
+ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
+ assertEquals(inData.length, count);
+ }
+
+ @SuppressWarnings("resource") // 'in' is deliberately not closed
+ @Test
+ public void copy_inputStreamToWriter() throws Exception {
+ InputStream in = new ByteArrayInputStream(inData);
+ in = new YellOnCloseInputStream(in);
+
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
+ final Writer writer = new java.io.OutputStreamWriter(out, "US-ASCII");
+
+ CopyUtils.copy(in, writer);
+ writer.flush();
+
+ assertEquals("Not all bytes were read", 0, in.available());
+ assertEquals("Sizes differ", inData.length, baout.size());
+ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
+ }
+
+ @Test
+ public void copy_inputStreamToWriterWithEncoding() throws Exception {
+ final String inDataStr = "data";
+ final String charsetName = "UTF-8";
+ final StringWriter writer = new StringWriter();
+ CopyUtils.copy(new ByteArrayInputStream(inDataStr.getBytes(charsetName)), writer, charsetName);
+ assertEquals(inDataStr, writer.toString());
+ }
+
+ @SuppressWarnings("resource") // 'in' is deliberately not closed
+ @Test
+ public void testCopy_readerToOutputStream() throws Exception {
+ InputStream in = new ByteArrayInputStream(inData);
+ in = new YellOnCloseInputStream(in);
+ final Reader reader = new java.io.InputStreamReader(in, "US-ASCII");
+
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
+
+ CopyUtils.copy(reader, out);
+ //Note: this method *does* flush. It is equivalent to:
+ // OutputStreamWriter _out = new OutputStreamWriter(fout);
+ // IOUtils.copy( fin, _out, 4096 ); // copy( Reader, Writer, int );
+ // _out.flush();
+ // out = fout;
+
+ // Note: rely on the method to flush
+ assertEquals("Sizes differ", inData.length, baout.size());
+ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
+ }
+
+ @SuppressWarnings("resource") // 'in' is deliberately not closed
+ @Test
+ public void copy_readerToWriter() throws Exception {
+ InputStream in = new ByteArrayInputStream(inData);
+ in = new YellOnCloseInputStream(in);
+ final Reader reader = new java.io.InputStreamReader(in, "US-ASCII");
+
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
+ final Writer writer = new java.io.OutputStreamWriter(out, "US-ASCII");
+
+ final int count = CopyUtils.copy(reader, writer);
+ writer.flush();
+ assertEquals(
+ "The number of characters returned by copy is wrong",
+ inData.length,
+ count);
+ assertEquals("Sizes differ", inData.length, baout.size());
+ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
+ }
+
+ @Test
+ public void copy_stringToOutputStream() throws Exception {
+ final String str = new String(inData, "US-ASCII");
+
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
+
+ CopyUtils.copy(str, out);
+ //Note: this method *does* flush. It is equivalent to:
+ // OutputStreamWriter _out = new OutputStreamWriter(fout);
+ // IOUtils.copy( str, _out, 4096 ); // copy( Reader, Writer, int );
+ // _out.flush();
+ // out = fout;
+ // note: we don't flush here; this IOUtils method does it for us
+
+ assertEquals("Sizes differ", inData.length, baout.size());
+ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
+ }
+
+ @Test
+ public void copy_stringToWriter() throws Exception {
+ final String str = new String(inData, "US-ASCII");
+
+ final ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
+ final Writer writer = new java.io.OutputStreamWriter(out, "US-ASCII");
+
+ CopyUtils.copy(str, writer);
+ writer.flush();
+
+ assertEquals("Sizes differ", inData.length, baout.size());
+ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
+ }
+
+} // CopyUtilsTest
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DemuxTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DemuxTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..1eb11e5d205986a4048db05b9350ed3f07aa9b4b
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DemuxTestCase.java"
@@ -0,0 +1,210 @@
+/*
+ * 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 org.apache.commons.io;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Random;
+
+import org.apache.commons.io.input.DemuxInputStream;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.io.output.DemuxOutputStream;
+import org.apache.commons.io.testtools.TestUtils;
+import org.junit.Test;
+
+/**
+ * Basic unit tests for the multiplexing streams.
+ */
+public class DemuxTestCase {
+ private static final String T1 = "Thread1";
+ private static final String T2 = "Thread2";
+ private static final String T3 = "Thread3";
+ private static final String T4 = "Thread4";
+
+ private static final String DATA1 = "Data for thread1";
+ private static final String DATA2 = "Data for thread2";
+ private static final String DATA3 = "Data for thread3";
+ private static final String DATA4 = "Data for thread4";
+
+ private static final Random c_random = new Random();
+ private final HashMap m_outputMap = new HashMap();
+ private final HashMap m_threadMap = new HashMap();
+
+ @SuppressWarnings("deprecation") // unavoidable until Java 7
+ private String getOutput(final String threadName) {
+ final ByteArrayOutputStream output =
+ m_outputMap.get(threadName);
+ assertNotNull("getOutput()", output);
+
+ return output.toString(Charsets.UTF_8);
+ }
+
+ private String getInput(final String threadName) {
+ final ReaderThread thread = (ReaderThread) m_threadMap.get(threadName);
+ assertNotNull("getInput()", thread);
+
+ return thread.getData();
+ }
+
+ private void doStart()
+ throws Exception {
+ for (String name : m_threadMap.keySet()) {
+ final Thread thread = m_threadMap.get(name);
+ thread.start();
+ }
+ }
+
+ private void doJoin()
+ throws Exception {
+ for (String name : m_threadMap.keySet()) {
+ final Thread thread = m_threadMap.get(name);
+ thread.join();
+ }
+ }
+
+ private void startWriter(final String name,
+ final String data,
+ final DemuxOutputStream demux)
+ throws Exception {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ m_outputMap.put(name, output);
+ final WriterThread thread =
+ new WriterThread(name, data, output, demux);
+ m_threadMap.put(name, thread);
+ }
+
+ private void startReader(final String name,
+ final String data,
+ final DemuxInputStream demux)
+ throws Exception {
+ final ByteArrayInputStream input = new ByteArrayInputStream(data.getBytes());
+ final ReaderThread thread = new ReaderThread(name, input, demux);
+ m_threadMap.put(name, thread);
+ }
+
+ @Test
+ public void testOutputStream()
+ throws Exception {
+ final DemuxOutputStream output = new DemuxOutputStream();
+ startWriter(T1, DATA1, output);
+ startWriter(T2, DATA2, output);
+ startWriter(T3, DATA3, output);
+ startWriter(T4, DATA4, output);
+
+ doStart();
+ doJoin();
+
+ assertEquals("Data1", DATA1, getOutput(T1));
+ assertEquals("Data2", DATA2, getOutput(T2));
+ assertEquals("Data3", DATA3, getOutput(T3));
+ assertEquals("Data4", DATA4, getOutput(T4));
+ }
+
+ @Test
+ public void testInputStream()
+ throws Exception {
+ final DemuxInputStream input = new DemuxInputStream();
+ startReader(T1, DATA1, input);
+ startReader(T2, DATA2, input);
+ startReader(T3, DATA3, input);
+ startReader(T4, DATA4, input);
+
+ doStart();
+ doJoin();
+
+ assertEquals("Data1", DATA1, getInput(T1));
+ assertEquals("Data2", DATA2, getInput(T2));
+ assertEquals("Data3", DATA3, getInput(T3));
+ assertEquals("Data4", DATA4, getInput(T4));
+ }
+
+ private static class ReaderThread
+ extends Thread {
+ private final StringBuffer m_buffer = new StringBuffer();
+ private final InputStream m_input;
+ private final DemuxInputStream m_demux;
+
+ ReaderThread(final String name,
+ final InputStream input,
+ final DemuxInputStream demux) {
+ super(name);
+ m_input = input;
+ m_demux = demux;
+ }
+
+ public String getData() {
+ return m_buffer.toString();
+ }
+
+ @Override
+ public void run() {
+ m_demux.bindStream(m_input);
+
+ try {
+ int ch = m_demux.read();
+ while (-1 != ch) {
+ //System.out.println( "Reading: " + (char)ch );
+ m_buffer.append((char) ch);
+
+ final int sleepTime = Math.abs(c_random.nextInt() % 10);
+ TestUtils.sleep(sleepTime);
+ ch = m_demux.read();
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static class WriterThread
+ extends Thread {
+ private final byte[] m_data;
+ private final OutputStream m_output;
+ private final DemuxOutputStream m_demux;
+
+ WriterThread(final String name,
+ final String data,
+ final OutputStream output,
+ final DemuxOutputStream demux) {
+ super(name);
+ m_output = output;
+ m_demux = demux;
+ m_data = data.getBytes();
+ }
+
+ @Override
+ public void run() {
+ m_demux.bindStream(m_output);
+ for (final byte element : m_data) {
+ try {
+ //System.out.println( "Writing: " + (char)m_data[ i ] );
+ m_demux.write(element);
+ final int sleepTime = Math.abs(c_random.nextInt() % 10);
+ TestUtils.sleep(sleepTime);
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
+
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..df3a187868be0fe27797dd06bc0c76d1c81697bd
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java"
@@ -0,0 +1,571 @@
+/*
+ * 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 org.apache.commons.io;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NameFileFilter;
+import org.apache.commons.io.filefilter.OrFileFilter;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This is used to test DirectoryWalker for correctness.
+ *
+ * @version $Id: DirectoryWalkerTestCase.java 1686260 2015-06-18 15:57:56Z krosenvold $
+ * @see DirectoryWalker
+ *
+ */
+public class DirectoryWalkerTestCase {
+
+ // Directories
+ private static final File current = new File(".");
+ private static final File javaDir = new File("src/main/java");
+ private static final File orgDir = new File(javaDir, "org");
+ private static final File apacheDir = new File(orgDir, "apache");
+ private static final File commonsDir = new File(apacheDir, "commons");
+ private static final File ioDir = new File(commonsDir, "io");
+ private static final File outputDir = new File(ioDir, "output");
+ private static final File[] dirs = new File[] {orgDir, apacheDir, commonsDir, ioDir, outputDir};
+
+ // Files
+ private static final File filenameUtils = new File(ioDir, "FilenameUtils.java");
+ private static final File ioUtils = new File(ioDir, "IOUtils.java");
+ private static final File proxyWriter = new File(outputDir, "ProxyWriter.java");
+ private static final File nullStream = new File(outputDir, "NullOutputStream.java");
+ private static final File[] ioFiles = new File[] {filenameUtils, ioUtils};
+ private static final File[] outputFiles = new File[] {proxyWriter, nullStream};
+
+ // Filters
+ private static final IOFileFilter dirsFilter = createNameFilter(dirs);
+ private static final IOFileFilter iofilesFilter = createNameFilter(ioFiles);
+ private static final IOFileFilter outputFilesFilter = createNameFilter(outputFiles);
+ private static final IOFileFilter ioDirAndFilesFilter = new OrFileFilter(dirsFilter, iofilesFilter);
+ private static final IOFileFilter dirsAndFilesFilter = new OrFileFilter(ioDirAndFilesFilter, outputFilesFilter);
+
+ // Filter to exclude SVN files
+ private static final IOFileFilter NOT_SVN = FileFilterUtils.makeSVNAware(null);
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Test Filtering
+ */
+ @Test
+ public void testFilter() {
+ final List results = new TestFileFinder(dirsAndFilesFilter, -1).find(javaDir);
+ assertEquals("Result Size", 1 + dirs.length + ioFiles.length + outputFiles.length, results.size());
+ assertTrue("Start Dir", results.contains(javaDir));
+ checkContainsFiles("Dir", dirs, results);
+ checkContainsFiles("IO File", ioFiles, results);
+ checkContainsFiles("Output File", outputFiles, results);
+ }
+
+ /**
+ * Test Filtering and limit to depth 0
+ */
+ @Test
+ public void testFilterAndLimitA() {
+ final List results = new TestFileFinder(NOT_SVN, 0).find(javaDir);
+ assertEquals("[A] Result Size", 1, results.size());
+ assertTrue("[A] Start Dir", results.contains(javaDir));
+ }
+
+ /**
+ * Test Filtering and limit to depth 1
+ */
+ @Test
+ public void testFilterAndLimitB() {
+ final List results = new TestFileFinder(NOT_SVN, 1).find(javaDir);
+ assertEquals("[B] Result Size", 2, results.size());
+ assertTrue("[B] Start Dir", results.contains(javaDir));
+ assertTrue("[B] Org Dir", results.contains(orgDir));
+ }
+
+ /**
+ * Test Filtering and limit to depth 3
+ */
+ @Test
+ public void testFilterAndLimitC() {
+ final List results = new TestFileFinder(NOT_SVN, 3).find(javaDir);
+ assertEquals("[C] Result Size", 4, results.size());
+ assertTrue("[C] Start Dir", results.contains(javaDir));
+ assertTrue("[C] Org Dir", results.contains(orgDir));
+ assertTrue("[C] Apache Dir", results.contains(apacheDir));
+ assertTrue("[C] Commons Dir", results.contains(commonsDir));
+ }
+
+ /**
+ * Test Filtering and limit to depth 5
+ */
+ @Test
+ public void testFilterAndLimitD() {
+ final List results = new TestFileFinder(dirsAndFilesFilter, 5).find(javaDir);
+ assertEquals("[D] Result Size", 1 + dirs.length + ioFiles.length, results.size());
+ assertTrue("[D] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[D] Dir", dirs, results);
+ checkContainsFiles("[D] File", ioFiles, results);
+ }
+
+ /**
+ * Test separate dir and file filters
+ */
+ @Test
+ public void testFilterDirAndFile1() {
+ final List results = new TestFileFinder(dirsFilter, iofilesFilter, -1).find(javaDir);
+ assertEquals("[DirAndFile1] Result Size", 1 + dirs.length + ioFiles.length, results.size());
+ assertTrue("[DirAndFile1] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[DirAndFile1] Dir", dirs, results);
+ checkContainsFiles("[DirAndFile1] File", ioFiles, results);
+ }
+
+ /**
+ * Test separate dir and file filters
+ */
+ @Test
+ public void testFilterDirAndFile2() {
+ final List results = new TestFileFinder(null, null, -1).find(javaDir);
+ assertTrue("[DirAndFile2] Result Size", results.size() > 1 + dirs.length + ioFiles.length);
+ assertTrue("[DirAndFile2] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[DirAndFile2] Dir", dirs, results);
+ checkContainsFiles("[DirAndFile2] File", ioFiles, results);
+ }
+
+ /**
+ * Test separate dir and file filters
+ */
+ @Test
+ public void testFilterDirAndFile3() {
+ final List results = new TestFileFinder(dirsFilter, null, -1).find(javaDir);
+ final List resultDirs = directoriesOnly(results);
+ assertEquals("[DirAndFile3] Result Size", 1 + dirs.length, resultDirs.size());
+ assertTrue("[DirAndFile3] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[DirAndFile3] Dir", dirs, resultDirs);
+ }
+
+ /**
+ * Test separate dir and file filters
+ */
+ @Test
+ public void testFilterDirAndFile4() {
+ final List results = new TestFileFinder(null, iofilesFilter, -1).find(javaDir);
+ final List resultFiles = filesOnly(results);
+ assertEquals("[DirAndFile4] Result Size", ioFiles.length, resultFiles.size());
+ assertTrue("[DirAndFile4] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[DirAndFile4] File", ioFiles, resultFiles);
+ }
+
+ /**
+ * Test Limiting to current directory
+ */
+ @Test
+ public void testLimitToCurrent() {
+ final List results = new TestFileFinder(null, 0).find(current);
+ assertEquals("Result Size", 1, results.size());
+ assertTrue("Current Dir", results.contains(new File(".")));
+ }
+
+ /**
+ * test an invalid start directory
+ */
+ @Test
+ public void testMissingStartDirectory() {
+
+ // TODO is this what we want with invalid directory?
+ final File invalidDir = new File("invalid-dir");
+ final List results = new TestFileFinder(null, -1).find(invalidDir);
+ assertEquals("Result Size", 1, results.size());
+ assertTrue("Current Dir", results.contains(invalidDir));
+
+ try {
+ new TestFileFinder(null, -1).find(null);
+ fail("Null start directory didn't throw Exception");
+ } catch (final NullPointerException ignore) {
+ // expected result
+ }
+ }
+
+ /**
+ * test an invalid start directory
+ */
+ @Test
+ public void testHandleStartDirectoryFalse() {
+
+ final List results = new TestFalseFileFinder(null, -1).find(current);
+ assertEquals("Result Size", 0, results.size());
+
+ }
+
+ // ------------ Convenience Test Methods ------------------------------------
+
+ /**
+ * Check the files in the array are in the results list.
+ */
+ private void checkContainsFiles(final String prefix, final File[] files, final Collection results) {
+ for (int i = 0; i < files.length; i++) {
+ assertTrue(prefix + "["+i+"] " + files[i], results.contains(files[i]));
+ }
+ }
+
+ private void checkContainsString(final String prefix, final File[] files, final Collection results) {
+ for (int i = 0; i < files.length; i++) {
+ assertTrue(prefix + "["+i+"] " + files[i], results.contains(files[i].toString()));
+ }
+ }
+
+ /**
+ * Extract the directories.
+ */
+ private List directoriesOnly(final Collection results) {
+ final List list = new ArrayList(results.size());
+ for (final File file : results) {
+ if (file.isDirectory()) {
+ list.add(file);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Extract the files.
+ */
+ private List filesOnly(final Collection results) {
+ final List list = new ArrayList(results.size());
+ for (final File file : results) {
+ if (file.isFile()) {
+ list.add(file);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Create an name filter containg the names of the files
+ * in the array.
+ */
+ private static IOFileFilter createNameFilter(final File[] files) {
+ final String[] names = new String[files.length];
+ for (int i = 0; i < files.length; i++) {
+ names[i] = files[i].getName();
+ }
+ return new NameFileFilter(names);
+ }
+
+ /**
+ * Test Cancel
+ */
+ @Test
+ public void testCancel() {
+ String cancelName = null;
+
+ // Cancel on a file
+ try {
+ cancelName = "DirectoryWalker.java";
+ new TestCancelWalker(cancelName, false).find(javaDir);
+ fail("CancelException not thrown for '" + cancelName + "'");
+ } catch (final DirectoryWalker.CancelException cancel) {
+ assertEquals("File: " + cancelName, cancelName, cancel.getFile().getName());
+ assertEquals("Depth: " + cancelName, 5, cancel.getDepth());
+ } catch(final IOException ex) {
+ fail("IOException: " + cancelName + " " + ex);
+ }
+
+ // Cancel on a directory
+ try {
+ cancelName = "commons";
+ new TestCancelWalker(cancelName, false).find(javaDir);
+ fail("CancelException not thrown for '" + cancelName + "'");
+ } catch (final DirectoryWalker.CancelException cancel) {
+ assertEquals("File: " + cancelName, cancelName, cancel.getFile().getName());
+ assertEquals("Depth: " + cancelName, 3, cancel.getDepth());
+ } catch(final IOException ex) {
+ fail("IOException: " + cancelName + " " + ex);
+ }
+
+ // Suppress CancelException (use same file name as preceding test)
+ try {
+ final List results = new TestCancelWalker(cancelName, true).find(javaDir);
+ final File lastFile = results.get(results.size() - 1);
+ assertEquals("Suppress: " + cancelName, cancelName, lastFile.getName());
+ } catch(final IOException ex) {
+ fail("Suppress threw " + ex);
+ }
+
+ }
+
+ /**
+ * Test Cancel
+ */
+ @Test
+ public void testMultiThreadCancel() {
+ String cancelName = "DirectoryWalker.java";
+ TestMultiThreadCancelWalker walker = new TestMultiThreadCancelWalker(cancelName, false);
+ // Cancel on a file
+ try {
+ walker.find(javaDir);
+ fail("CancelException not thrown for '" + cancelName + "'");
+ } catch (final DirectoryWalker.CancelException cancel) {
+ final File last = walker.results.get(walker.results.size() - 1);
+ assertEquals(cancelName, last.getName());
+ assertEquals("Depth: " + cancelName, 5, cancel.getDepth());
+ } catch(final IOException ex) {
+ fail("IOException: " + cancelName + " " + ex);
+ }
+
+ // Cancel on a directory
+ try {
+ cancelName = "commons";
+ walker = new TestMultiThreadCancelWalker(cancelName, false);
+ walker.find(javaDir);
+ fail("CancelException not thrown for '" + cancelName + "'");
+ } catch (final DirectoryWalker.CancelException cancel) {
+ assertEquals("File: " + cancelName, cancelName, cancel.getFile().getName());
+ assertEquals("Depth: " + cancelName, 3, cancel.getDepth());
+ } catch(final IOException ex) {
+ fail("IOException: " + cancelName + " " + ex);
+ }
+
+ // Suppress CancelException (use same file name as preceding test)
+ try {
+ walker = new TestMultiThreadCancelWalker(cancelName, true);
+ final List results = walker.find(javaDir);
+ final File lastFile = results.get(results.size() - 1);
+ assertEquals("Suppress: " + cancelName, cancelName, lastFile.getName());
+ } catch(final IOException ex) {
+ fail("Suppress threw " + ex);
+ }
+
+ }
+
+ /**
+ * Test Filtering
+ */
+ @Test
+ public void testFilterString() {
+ final List results = new TestFileFinderString(dirsAndFilesFilter, -1).find(javaDir);
+ assertEquals("Result Size", outputFiles.length + ioFiles.length, results.size());
+ checkContainsString("IO File", ioFiles, results);
+ checkContainsString("Output File", outputFiles, results);
+ }
+
+ // ------------ Test DirectoryWalker implementation --------------------------
+
+ /**
+ * Test DirectoryWalker implementation that finds files in a directory hierarchy
+ * applying a file filter.
+ */
+ private static class TestFileFinder extends DirectoryWalker {
+
+ protected TestFileFinder(final FileFilter filter, final int depthLimit) {
+ super(filter, depthLimit);
+ }
+
+ protected TestFileFinder(final IOFileFilter dirFilter, final IOFileFilter fileFilter, final int depthLimit) {
+ super(dirFilter, fileFilter, depthLimit);
+ }
+
+ /** find files. */
+ protected List find(final File startDirectory) {
+ final List results = new ArrayList();
+ try {
+ walk(startDirectory, results);
+ } catch(final IOException ex) {
+ Assert.fail(ex.toString());
+ }
+ return results;
+ }
+
+ /** Handles a directory end by adding the File to the result set. */
+ @Override
+ protected void handleDirectoryEnd(final File directory, final int depth, final Collection results) {
+ results.add(directory);
+ }
+
+ /** Handles a file by adding the File to the result set. */
+ @Override
+ protected void handleFile(final File file, final int depth, final Collection results) {
+ results.add(file);
+ }
+ }
+
+ // ------------ Test DirectoryWalker implementation --------------------------
+
+ /**
+ * Test DirectoryWalker implementation that always returns false
+ * from handleDirectoryStart()
+ */
+ private static class TestFalseFileFinder extends TestFileFinder {
+
+ protected TestFalseFileFinder(final FileFilter filter, final int depthLimit) {
+ super(filter, depthLimit);
+ }
+
+ /** Always returns false. */
+ @Override
+ protected boolean handleDirectory(final File directory, final int depth, final Collection results) {
+ return false;
+ }
+ }
+
+ // ------------ Test DirectoryWalker implementation --------------------------
+
+ /**
+ * Test DirectoryWalker implementation that finds files in a directory hierarchy
+ * applying a file filter.
+ */
+ static class TestCancelWalker extends DirectoryWalker {
+ private final String cancelFileName;
+ private final boolean suppressCancel;
+
+ TestCancelWalker(final String cancelFileName,final boolean suppressCancel) {
+ super();
+ this.cancelFileName = cancelFileName;
+ this.suppressCancel = suppressCancel;
+ }
+
+ /** find files. */
+ protected List find(final File startDirectory) throws IOException {
+ final List results = new ArrayList();
+ walk(startDirectory, results);
+ return results;
+ }
+
+ /** Handles a directory end by adding the File to the result set. */
+ @Override
+ protected void handleDirectoryEnd(final File directory, final int depth, final Collection results) throws IOException {
+ results.add(directory);
+ if (cancelFileName.equals(directory.getName())) {
+ throw new CancelException(directory, depth);
+ }
+ }
+
+ /** Handles a file by adding the File to the result set. */
+ @Override
+ protected void handleFile(final File file, final int depth, final Collection results) throws IOException {
+ results.add(file);
+ if (cancelFileName.equals(file.getName())) {
+ throw new CancelException(file, depth);
+ }
+ }
+
+ /** Handles Cancel. */
+ @Override
+ protected void handleCancelled(final File startDirectory, final Collection results,
+ final CancelException cancel) throws IOException {
+ if (!suppressCancel) {
+ super.handleCancelled(startDirectory, results, cancel);
+ }
+ }
+ }
+
+ /**
+ * Test DirectoryWalker implementation that finds files in a directory hierarchy
+ * applying a file filter.
+ */
+ static class TestMultiThreadCancelWalker extends DirectoryWalker {
+ private final String cancelFileName;
+ private final boolean suppressCancel;
+ private boolean cancelled;
+ public List results;
+
+ TestMultiThreadCancelWalker(final String cancelFileName, final boolean suppressCancel) {
+ super();
+ this.cancelFileName = cancelFileName;
+ this.suppressCancel = suppressCancel;
+ }
+
+ /** find files. */
+ protected List find(final File startDirectory) throws IOException {
+ results = new ArrayList();
+ walk(startDirectory, results);
+ return results;
+ }
+
+ /** Handles a directory end by adding the File to the result set. */
+ @Override
+ protected void handleDirectoryEnd(final File directory, final int depth, final Collection results) throws IOException {
+ results.add(directory);
+ assertFalse(cancelled);
+ if (cancelFileName.equals(directory.getName())) {
+ cancelled = true;
+ }
+ }
+
+ /** Handles a file by adding the File to the result set. */
+ @Override
+ protected void handleFile(final File file, final int depth, final Collection results) throws IOException {
+ results.add(file);
+ assertFalse(cancelled);
+ if (cancelFileName.equals(file.getName())) {
+ cancelled = true;
+ }
+ }
+
+ /** Handles Cancelled. */
+ @Override
+ protected boolean handleIsCancelled(final File file, final int depth, final Collection results) throws IOException {
+ return cancelled;
+ }
+
+ /** Handles Cancel. */
+ @Override
+ protected void handleCancelled(final File startDirectory, final Collection results,
+ final CancelException cancel) throws IOException {
+ if (!suppressCancel) {
+ super.handleCancelled(startDirectory, results, cancel);
+ }
+ }
+ }
+
+ /**
+ * Test DirectoryWalker implementation that finds files in a directory hierarchy
+ * applying a file filter.
+ */
+ private static class TestFileFinderString extends DirectoryWalker {
+
+ protected TestFileFinderString(final FileFilter filter, final int depthLimit) {
+ super(filter, depthLimit);
+ }
+
+ /** find files. */
+ protected List find(final File startDirectory) {
+ final List results = new ArrayList();
+ try {
+ walk(startDirectory, results);
+ } catch(final IOException ex) {
+ Assert.fail(ex.toString());
+ }
+ return results;
+ }
+
+ /** Handles a file by adding the File to the result set. */
+ @Override
+ protected void handleFile(final File file, final int depth, final Collection results) {
+ results.add(file.toString());
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java"
new file mode 100644
index 0000000000000000000000000000000000000000..b633f5a2dbe09a00b8bf8a55134bca726fb3972c
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java"
@@ -0,0 +1,554 @@
+/*
+ * 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 org.apache.commons.io;
+
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NameFileFilter;
+import org.apache.commons.io.filefilter.OrFileFilter;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * This is used to test DirectoryWalker for correctness when using Java4 (i.e. no generics).
+ *
+ * @version $Id: DirectoryWalkerTestCaseJava4.java 1718944 2015-12-09 19:50:30Z krosenvold $
+ * @see DirectoryWalker
+ */
+@SuppressWarnings({"unchecked", "rawtypes"}) // Java4
+public class DirectoryWalkerTestCaseJava4 {
+
+ // Directories
+ private static final File current = new File(".");
+ private static final File javaDir = new File("src/main/java");
+ private static final File orgDir = new File(javaDir, "org");
+ private static final File apacheDir = new File(orgDir, "apache");
+ private static final File commonsDir = new File(apacheDir, "commons");
+ private static final File ioDir = new File(commonsDir, "io");
+ private static final File outputDir = new File(ioDir, "output");
+ private static final File[] dirs = new File[]{orgDir, apacheDir, commonsDir, ioDir, outputDir};
+
+ // Files
+ private static final File filenameUtils = new File(ioDir, "FilenameUtils.java");
+ private static final File ioUtils = new File(ioDir, "IOUtils.java");
+ private static final File proxyWriter = new File(outputDir, "ProxyWriter.java");
+ private static final File nullStream = new File(outputDir, "NullOutputStream.java");
+ private static final File[] ioFiles = new File[]{filenameUtils, ioUtils};
+ private static final File[] outputFiles = new File[]{proxyWriter, nullStream};
+
+ // Filters
+ private static final IOFileFilter dirsFilter = createNameFilter(dirs);
+ private static final IOFileFilter iofilesFilter = createNameFilter(ioFiles);
+ private static final IOFileFilter outputFilesFilter = createNameFilter(outputFiles);
+ private static final IOFileFilter ioDirAndFilesFilter = new OrFileFilter(dirsFilter, iofilesFilter);
+ private static final IOFileFilter dirsAndFilesFilter = new OrFileFilter(ioDirAndFilesFilter, outputFilesFilter);
+
+ // Filter to exclude SVN files
+ private static final IOFileFilter NOT_SVN = FileFilterUtils.makeSVNAware(null);
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Test Filtering
+ */
+ @Test
+ public void testFilter() {
+ final List results = new TestFileFinder(dirsAndFilesFilter, -1).find(javaDir);
+ assertEquals("Result Size", 1 + dirs.length + ioFiles.length + outputFiles.length, results.size());
+ assertTrue("Start Dir", results.contains(javaDir));
+ checkContainsFiles("Dir", dirs, results);
+ checkContainsFiles("IO File", ioFiles, results);
+ checkContainsFiles("Output File", outputFiles, results);
+ }
+
+ /**
+ * Test Filtering and limit to depth 0
+ */
+ @Test
+ public void testFilterAndLimitA() {
+ final List results = new TestFileFinder(NOT_SVN, 0).find(javaDir);
+ assertEquals("[A] Result Size", 1, results.size());
+ assertTrue("[A] Start Dir", results.contains(javaDir));
+ }
+
+ /**
+ * Test Filtering and limit to depth 1
+ */
+ @Test
+ public void testFilterAndLimitB() {
+ final List results = new TestFileFinder(NOT_SVN, 1).find(javaDir);
+ assertEquals("[B] Result Size", 2, results.size());
+ assertTrue("[B] Start Dir", results.contains(javaDir));
+ assertTrue("[B] Org Dir", results.contains(orgDir));
+ }
+
+ /**
+ * Test Filtering and limit to depth 3
+ */
+ @Test
+ public void testFilterAndLimitC() {
+ final List results = new TestFileFinder(NOT_SVN, 3).find(javaDir);
+ assertEquals("[C] Result Size", 4, results.size());
+ assertTrue("[C] Start Dir", results.contains(javaDir));
+ assertTrue("[C] Org Dir", results.contains(orgDir));
+ assertTrue("[C] Apache Dir", results.contains(apacheDir));
+ assertTrue("[C] Commons Dir", results.contains(commonsDir));
+ }
+
+ /**
+ * Test Filtering and limit to depth 5
+ */
+ @Test
+ public void testFilterAndLimitD() {
+ final List results = new TestFileFinder(dirsAndFilesFilter, 5).find(javaDir);
+ assertEquals("[D] Result Size", 1 + dirs.length + ioFiles.length, results.size());
+ assertTrue("[D] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[D] Dir", dirs, results);
+ checkContainsFiles("[D] File", ioFiles, results);
+ }
+
+ /**
+ * Test separate dir and file filters
+ */
+ @Test
+ public void testFilterDirAndFile1() {
+ final List results = new TestFileFinder(dirsFilter, iofilesFilter, -1).find(javaDir);
+ assertEquals("[DirAndFile1] Result Size", 1 + dirs.length + ioFiles.length, results.size());
+ assertTrue("[DirAndFile1] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[DirAndFile1] Dir", dirs, results);
+ checkContainsFiles("[DirAndFile1] File", ioFiles, results);
+ }
+
+ /**
+ * Test separate dir and file filters
+ */
+ @Test
+ public void testFilterDirAndFile2() {
+ final List results = new TestFileFinder(null, null, -1).find(javaDir);
+ assertTrue("[DirAndFile2] Result Size", results.size() > 1 + dirs.length + ioFiles.length);
+ assertTrue("[DirAndFile2] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[DirAndFile2] Dir", dirs, results);
+ checkContainsFiles("[DirAndFile2] File", ioFiles, results);
+ }
+
+ /**
+ * Test separate dir and file filters
+ */
+ @Test
+ public void testFilterDirAndFile3() {
+ final List results = new TestFileFinder(dirsFilter, null, -1).find(javaDir);
+ final List resultDirs = directoriesOnly(results);
+ assertEquals("[DirAndFile3] Result Size", 1 + dirs.length, resultDirs.size());
+ assertTrue("[DirAndFile3] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[DirAndFile3] Dir", dirs, resultDirs);
+ }
+
+ /**
+ * Test separate dir and file filters
+ */
+ @Test
+ public void testFilterDirAndFile4() {
+ final List results = new TestFileFinder(null, iofilesFilter, -1).find(javaDir);
+ final List resultFiles = filesOnly(results);
+ assertEquals("[DirAndFile4] Result Size", ioFiles.length, resultFiles.size());
+ assertTrue("[DirAndFile4] Start Dir", results.contains(javaDir));
+ checkContainsFiles("[DirAndFile4] File", ioFiles, resultFiles);
+ }
+
+ /**
+ * Test Limiting to current directory
+ */
+ @Test
+ public void testLimitToCurrent() {
+ final List results = new TestFileFinder(null, 0).find(current);
+ assertEquals("Result Size", 1, results.size());
+ assertTrue("Current Dir", results.contains(new File(".")));
+ }
+
+ /**
+ * test an invalid start directory
+ */
+ @Test
+ public void testMissingStartDirectory() {
+
+ // TODO is this what we want with invalid directory?
+ final File invalidDir = new File("invalid-dir");
+ final List results = new TestFileFinder(null, -1).find(invalidDir);
+ assertEquals("Result Size", 1, results.size());
+ assertTrue("Current Dir", results.contains(invalidDir));
+
+ try {
+ new TestFileFinder(null, -1).find(null);
+ fail("Null start directory didn't throw Exception");
+ } catch (final NullPointerException ignore) {
+ // expected result
+ }
+ }
+
+ /**
+ * test an invalid start directory
+ */
+ @Test
+ public void testHandleStartDirectoryFalse() {
+
+ final List results = new TestFalseFileFinder(null, -1).find(current);
+ assertEquals("Result Size", 0, results.size());
+
+ }
+
+ // ------------ Convenience Test Methods ------------------------------------
+
+ /**
+ * Check the files in the array are in the results list.
+ */
+ private void checkContainsFiles(final String prefix, final File[] files, final Collection results) {
+ for (int i = 0; i < files.length; i++) {
+ assertTrue(prefix + "[" + i + "] " + files[i], results.contains(files[i]));
+ }
+ }
+
+ /**
+ * Extract the directories.
+ */
+ private List directoriesOnly(final Collection results) {
+ final List list = new ArrayList(results.size());
+ for (File file : results) {
+ if (file.isDirectory()) {
+ list.add(file);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Extract the files.
+ */
+ private List filesOnly(final Collection results) {
+ final List list = new ArrayList(results.size());
+ for (File file : results) {
+ if (file.isFile()) {
+ list.add(file);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Create an name filter containg the names of the files
+ * in the array.
+ */
+ private static IOFileFilter createNameFilter(final File[] files) {
+ final String[] names = new String[files.length];
+ for (int i = 0; i < files.length; i++) {
+ names[i] = files[i].getName();
+ }
+ return new NameFileFilter(names);
+ }
+
+ /**
+ * Test Cancel
+ */
+ @Test
+ public void testCancel() {
+ String cancelName = null;
+
+ // Cancel on a file
+ try {
+ cancelName = "DirectoryWalker.java";
+ new TestCancelWalker(cancelName, false).find(javaDir);
+ fail("CancelException not thrown for '" + cancelName + "'");
+ } catch (final DirectoryWalker.CancelException cancel) {
+ assertEquals("File: " + cancelName, cancelName, cancel.getFile().getName());
+ assertEquals("Depth: " + cancelName, 5, cancel.getDepth());
+ } catch (final IOException ex) {
+ fail("IOException: " + cancelName + " " + ex);
+ }
+
+ // Cancel on a directory
+ try {
+ cancelName = "commons";
+ new TestCancelWalker(cancelName, false).find(javaDir);
+ fail("CancelException not thrown for '" + cancelName + "'");
+ } catch (final DirectoryWalker.CancelException cancel) {
+ assertEquals("File: " + cancelName, cancelName, cancel.getFile().getName());
+ assertEquals("Depth: " + cancelName, 3, cancel.getDepth());
+ } catch (final IOException ex) {
+ fail("IOException: " + cancelName + " " + ex);
+ }
+
+ // Suppress CancelException (use same file name as preceding test)
+ try {
+ final List results = new TestCancelWalker(cancelName, true).find(javaDir);
+ final File lastFile = (File) results.get(results.size() - 1);
+ assertEquals("Suppress: " + cancelName, cancelName, lastFile.getName());
+ } catch (final IOException ex) {
+ fail("Suppress threw " + ex);
+ }
+
+ }
+
+ /**
+ * Test Cancel
+ */
+ @Test
+ public void testMultiThreadCancel() {
+ String cancelName = "DirectoryWalker.java";
+ TestMultiThreadCancelWalker walker = new TestMultiThreadCancelWalker(cancelName, false);
+ // Cancel on a file
+ try {
+ walker.find(javaDir);
+ fail("CancelException not thrown for '" + cancelName + "'");
+ } catch (final DirectoryWalker.CancelException cancel) {
+ final File last = (File) walker.results.get(walker.results.size() - 1);
+ assertEquals(cancelName, last.getName());
+ assertEquals("Depth: " + cancelName, 5, cancel.getDepth());
+ } catch (final IOException ex) {
+ fail("IOException: " + cancelName + " " + ex);
+ }
+
+ // Cancel on a directory
+ try {
+ cancelName = "commons";
+ walker = new TestMultiThreadCancelWalker(cancelName, false);
+ walker.find(javaDir);
+ fail("CancelException not thrown for '" + cancelName + "'");
+ } catch (final DirectoryWalker.CancelException cancel) {
+ assertEquals("File: " + cancelName, cancelName, cancel.getFile().getName());
+ assertEquals("Depth: " + cancelName, 3, cancel.getDepth());
+ } catch (final IOException ex) {
+ fail("IOException: " + cancelName + " " + ex);
+ }
+
+ // Suppress CancelException (use same file name as preceding test)
+ try {
+ walker = new TestMultiThreadCancelWalker(cancelName, true);
+ final List results = walker.find(javaDir);
+ final File lastFile = (File) results.get(results.size() - 1);
+ assertEquals("Suppress: " + cancelName, cancelName, lastFile.getName());
+ } catch (final IOException ex) {
+ fail("Suppress threw " + ex);
+ }
+
+ }
+
+ // ------------ Test DirectoryWalker implementation --------------------------
+
+ /**
+ * Test DirectoryWalker implementation that finds files in a directory hierarchy
+ * applying a file filter.
+ */
+ private static class TestFileFinder extends DirectoryWalker {
+
+ protected TestFileFinder(final FileFilter filter, final int depthLimit) {
+ super(filter, depthLimit);
+ }
+
+ protected TestFileFinder(final IOFileFilter dirFilter, final IOFileFilter fileFilter, final int depthLimit) {
+ super(dirFilter, fileFilter, depthLimit);
+ }
+
+ /**
+ * find files.
+ */
+ protected List find(final File startDirectory) {
+ final List results = new ArrayList();
+ try {
+ walk(startDirectory, results);
+ } catch (final IOException ex) {
+ fail(ex.toString());
+ }
+ return results;
+ }
+
+ /**
+ * Handles a directory end by adding the File to the result set.
+ */
+ @Override
+ protected void handleDirectoryEnd(final File directory, final int depth, final Collection results) {
+ results.add(directory);
+ }
+
+ /**
+ * Handles a file by adding the File to the result set.
+ */
+ @Override
+ protected void handleFile(final File file, final int depth, final Collection results) {
+ results.add(file);
+ }
+ }
+
+ // ------------ Test DirectoryWalker implementation --------------------------
+
+ /**
+ * Test DirectoryWalker implementation that always returns false
+ * from handleDirectoryStart()
+ */
+ private static class TestFalseFileFinder extends TestFileFinder {
+
+ protected TestFalseFileFinder(final FileFilter filter, final int depthLimit) {
+ super(filter, depthLimit);
+ }
+
+ /**
+ * Always returns false.
+ */
+ @Override
+ protected boolean handleDirectory(final File directory, final int depth, final Collection results) {
+ return false;
+ }
+ }
+
+ // ------------ Test DirectoryWalker implementation --------------------------
+
+ /**
+ * Test DirectoryWalker implementation that finds files in a directory hierarchy
+ * applying a file filter.
+ */
+ static class TestCancelWalker extends DirectoryWalker {
+ private final String cancelFileName;
+ private final boolean suppressCancel;
+
+ TestCancelWalker(final String cancelFileName, final boolean suppressCancel) {
+ super();
+ this.cancelFileName = cancelFileName;
+ this.suppressCancel = suppressCancel;
+ }
+
+ /**
+ * find files.
+ */
+ protected List find(final File startDirectory) throws IOException {
+ final List results = new ArrayList();
+ walk(startDirectory, results);
+ return results;
+ }
+
+ /**
+ * Handles a directory end by adding the File to the result set.
+ */
+ @Override
+ protected void handleDirectoryEnd(final File directory, final int depth, final Collection results) throws IOException {
+ results.add(directory);
+ if (cancelFileName.equals(directory.getName())) {
+ throw new CancelException(directory, depth);
+ }
+ }
+
+ /**
+ * Handles a file by adding the File to the result set.
+ */
+ @Override
+ protected void handleFile(final File file, final int depth, final Collection results) throws IOException {
+ results.add(file);
+ if (cancelFileName.equals(file.getName())) {
+ throw new CancelException(file, depth);
+ }
+ }
+
+ /**
+ * Handles Cancel.
+ */
+ @Override
+ protected void handleCancelled(final File startDirectory, final Collection results,
+ final CancelException cancel) throws IOException {
+ if (!suppressCancel) {
+ super.handleCancelled(startDirectory, results, cancel);
+ }
+ }
+ }
+
+ /**
+ * Test DirectoryWalker implementation that finds files in a directory hierarchy
+ * applying a file filter.
+ */
+ static class TestMultiThreadCancelWalker extends DirectoryWalker {
+ private final String cancelFileName;
+ private final boolean suppressCancel;
+ private boolean cancelled;
+ public List results;
+
+ TestMultiThreadCancelWalker(final String cancelFileName, final boolean suppressCancel) {
+ super();
+ this.cancelFileName = cancelFileName;
+ this.suppressCancel = suppressCancel;
+ }
+
+ /**
+ * find files.
+ */
+ protected List find(final File startDirectory) throws IOException {
+ results = new ArrayList();
+ walk(startDirectory, results);
+ return results;
+ }
+
+ /**
+ * Handles a directory end by adding the File to the result set.
+ */
+ @Override
+ protected void handleDirectoryEnd(final File directory, final int depth, final Collection results) throws IOException {
+ results.add(directory);
+ assertFalse(cancelled);
+ if (cancelFileName.equals(directory.getName())) {
+ cancelled = true;
+ }
+ }
+
+ /**
+ * Handles a file by adding the File to the result set.
+ */
+ @Override
+ protected void handleFile(final File file, final int depth, final Collection results) throws IOException {
+ results.add(file);
+ assertFalse(cancelled);
+ if (cancelFileName.equals(file.getName())) {
+ cancelled = true;
+ }
+ }
+
+ /**
+ * Handles Cancelled.
+ */
+ @Override
+ protected boolean handleIsCancelled(final File file, final int depth, final Collection results) throws IOException {
+ return cancelled;
+ }
+
+ /**
+ * Handles Cancel.
+ */
+ @Override
+ protected void handleCancelled(final File startDirectory, final Collection results,
+ final CancelException cancel) throws IOException {
+ if (!suppressCancel) {
+ super.handleCancelled(startDirectory, results, cancel);
+ }
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/EndianUtilsTest.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/EndianUtilsTest.java"
new file mode 100644
index 0000000000000000000000000000000000000000..0c884a57927fc7e36c12bb2e976eb684c7d3f3b5
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/EndianUtilsTest.java"
@@ -0,0 +1,316 @@
+/*
+ * 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 org.apache.commons.io;
+
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * @version $Id: EndianUtilsTest.java 1718944 2015-12-09 19:50:30Z krosenvold $
+ */
+public class EndianUtilsTest {
+
+ @Test
+ public void testCtor() {
+ new EndianUtils();
+ // Constructor does not blow up.
+ }
+
+ @Test
+ public void testEOFException() throws IOException {
+ final ByteArrayInputStream input = new ByteArrayInputStream(new byte[] {});
+ try {
+ EndianUtils.readSwappedDouble(input);
+ fail("Expected EOFException");
+ } catch (final EOFException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testSwapShort() {
+ assertEquals( (short) 0, EndianUtils.swapShort( (short) 0 ) );
+ assertEquals( (short) 0x0201, EndianUtils.swapShort( (short) 0x0102 ) );
+ assertEquals( (short) 0xffff, EndianUtils.swapShort( (short) 0xffff ) );
+ assertEquals( (short) 0x0102, EndianUtils.swapShort( (short) 0x0201 ) );
+ }
+
+ @Test
+ public void testSwapInteger() {
+ assertEquals( 0, EndianUtils.swapInteger( 0 ) );
+ assertEquals( 0x04030201, EndianUtils.swapInteger( 0x01020304 ) );
+ assertEquals( 0x01000000, EndianUtils.swapInteger( 0x00000001 ) );
+ assertEquals( 0x00000001, EndianUtils.swapInteger( 0x01000000 ) );
+ assertEquals( 0x11111111, EndianUtils.swapInteger( 0x11111111 ) );
+ assertEquals( 0xabcdef10, EndianUtils.swapInteger( 0x10efcdab ) );
+ assertEquals( 0xab, EndianUtils.swapInteger( 0xab000000 ) );
+ }
+
+ @Test
+ public void testSwapLong() {
+ assertEquals( 0, EndianUtils.swapLong( 0 ) );
+ assertEquals( 0x0807060504030201L, EndianUtils.swapLong( 0x0102030405060708L ) );
+ assertEquals( 0xffffffffffffffffL, EndianUtils.swapLong( 0xffffffffffffffffL ) );
+ assertEquals( 0xab, EndianUtils.swapLong( 0xab00000000000000L ) );
+ }
+
+ @Test
+ public void testSwapFloat() {
+ assertEquals( 0.0f, EndianUtils.swapFloat( 0.0f ), 0.0 );
+ final float f1 = Float.intBitsToFloat( 0x01020304 );
+ final float f2 = Float.intBitsToFloat( 0x04030201 );
+ assertEquals( f2, EndianUtils.swapFloat( f1 ), 0.0 );
+ }
+
+ @Test
+ public void testSwapDouble() {
+ assertEquals( 0.0, EndianUtils.swapDouble( 0.0 ), 0.0 );
+ final double d1 = Double.longBitsToDouble( 0x0102030405060708L );
+ final double d2 = Double.longBitsToDouble( 0x0807060504030201L );
+ assertEquals( d2, EndianUtils.swapDouble( d1 ), 0.0 );
+ }
+
+ /**
+ * Tests all swapXxxx methods for symmetry when going from one endian
+ * to another and back again.
+ */
+ @Test
+ public void testSymmetry() {
+ assertEquals( (short) 0x0102, EndianUtils.swapShort( EndianUtils.swapShort( (short) 0x0102 ) ) );
+ assertEquals( 0x01020304, EndianUtils.swapInteger( EndianUtils.swapInteger( 0x01020304 ) ) );
+ assertEquals( 0x0102030405060708L, EndianUtils.swapLong( EndianUtils.swapLong( 0x0102030405060708L ) ) );
+ final float f1 = Float.intBitsToFloat( 0x01020304 );
+ assertEquals( f1, EndianUtils.swapFloat( EndianUtils.swapFloat( f1 ) ), 0.0 );
+ final double d1 = Double.longBitsToDouble( 0x0102030405060708L );
+ assertEquals( d1, EndianUtils.swapDouble( EndianUtils.swapDouble( d1 ) ), 0.0 );
+ }
+
+ @Test
+ public void testReadSwappedShort() throws IOException {
+ final byte[] bytes = new byte[] { 0x02, 0x01 };
+ assertEquals( 0x0102, EndianUtils.readSwappedShort( bytes, 0 ) );
+
+ final ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+ assertEquals( 0x0102, EndianUtils.readSwappedShort( input ) );
+ }
+
+ @Test
+ public void testWriteSwappedShort() throws IOException {
+ byte[] bytes = new byte[2];
+ EndianUtils.writeSwappedShort( bytes, 0, (short) 0x0102 );
+ assertEquals( 0x02, bytes[0] );
+ assertEquals( 0x01, bytes[1] );
+
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(2);
+ EndianUtils.writeSwappedShort( baos, (short) 0x0102 );
+ bytes = baos.toByteArray();
+ assertEquals( 0x02, bytes[0] );
+ assertEquals( 0x01, bytes[1] );
+ }
+
+ @Test
+ public void testReadSwappedUnsignedShort() throws IOException {
+ final byte[] bytes = new byte[] { 0x02, 0x01 };
+ assertEquals( 0x00000102, EndianUtils.readSwappedUnsignedShort( bytes, 0 ) );
+
+ final ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+ assertEquals( 0x00000102, EndianUtils.readSwappedUnsignedShort( input ) );
+ }
+
+ @Test
+ public void testReadSwappedInteger() throws IOException {
+ final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 };
+ assertEquals( 0x01020304, EndianUtils.readSwappedInteger( bytes, 0 ) );
+
+ final ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+ assertEquals( 0x01020304, EndianUtils.readSwappedInteger( input ) );
+ }
+
+ @Test
+ public void testWriteSwappedInteger() throws IOException {
+ byte[] bytes = new byte[4];
+ EndianUtils.writeSwappedInteger( bytes, 0, 0x01020304 );
+ assertEquals( 0x04, bytes[0] );
+ assertEquals( 0x03, bytes[1] );
+ assertEquals( 0x02, bytes[2] );
+ assertEquals( 0x01, bytes[3] );
+
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(4);
+ EndianUtils.writeSwappedInteger( baos, 0x01020304 );
+ bytes = baos.toByteArray();
+ assertEquals( 0x04, bytes[0] );
+ assertEquals( 0x03, bytes[1] );
+ assertEquals( 0x02, bytes[2] );
+ assertEquals( 0x01, bytes[3] );
+ }
+
+ @Test
+ public void testReadSwappedUnsignedInteger() throws IOException {
+ final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 };
+ assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( bytes, 0 ) );
+
+ final ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+ assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( input ) );
+ }
+
+ @Test
+ public void testReadSwappedLong() throws IOException {
+ final byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
+ assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( bytes, 0 ) );
+
+ final ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+ assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( input ) );
+ }
+
+ @Test
+ public void testWriteSwappedLong() throws IOException {
+ byte[] bytes = new byte[8];
+ EndianUtils.writeSwappedLong( bytes, 0, 0x0102030405060708L );
+ assertEquals( 0x08, bytes[0] );
+ assertEquals( 0x07, bytes[1] );
+ assertEquals( 0x06, bytes[2] );
+ assertEquals( 0x05, bytes[3] );
+ assertEquals( 0x04, bytes[4] );
+ assertEquals( 0x03, bytes[5] );
+ assertEquals( 0x02, bytes[6] );
+ assertEquals( 0x01, bytes[7] );
+
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(8);
+ EndianUtils.writeSwappedLong( baos, 0x0102030405060708L );
+ bytes = baos.toByteArray();
+ assertEquals( 0x08, bytes[0] );
+ assertEquals( 0x07, bytes[1] );
+ assertEquals( 0x06, bytes[2] );
+ assertEquals( 0x05, bytes[3] );
+ assertEquals( 0x04, bytes[4] );
+ assertEquals( 0x03, bytes[5] );
+ assertEquals( 0x02, bytes[6] );
+ assertEquals( 0x01, bytes[7] );
+ }
+
+ @Test
+ public void testReadSwappedFloat() throws IOException {
+ final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 };
+ final float f1 = Float.intBitsToFloat( 0x01020304 );
+ final float f2 = EndianUtils.readSwappedFloat( bytes, 0 );
+ assertEquals( f1, f2, 0.0 );
+
+ final ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+ assertEquals( f1, EndianUtils.readSwappedFloat( input ), 0.0 );
+ }
+
+ @Test
+ public void testWriteSwappedFloat() throws IOException {
+ byte[] bytes = new byte[4];
+ final float f1 = Float.intBitsToFloat( 0x01020304 );
+ EndianUtils.writeSwappedFloat( bytes, 0, f1 );
+ assertEquals( 0x04, bytes[0] );
+ assertEquals( 0x03, bytes[1] );
+ assertEquals( 0x02, bytes[2] );
+ assertEquals( 0x01, bytes[3] );
+
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(4);
+ EndianUtils.writeSwappedFloat( baos, f1 );
+ bytes = baos.toByteArray();
+ assertEquals( 0x04, bytes[0] );
+ assertEquals( 0x03, bytes[1] );
+ assertEquals( 0x02, bytes[2] );
+ assertEquals( 0x01, bytes[3] );
+ }
+
+ @Test
+ public void testReadSwappedDouble() throws IOException {
+ final byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
+ final double d1 = Double.longBitsToDouble( 0x0102030405060708L );
+ final double d2 = EndianUtils.readSwappedDouble( bytes, 0 );
+ assertEquals( d1, d2, 0.0 );
+
+ final ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+ assertEquals( d1, EndianUtils.readSwappedDouble( input ), 0.0 );
+ }
+
+ @Test
+ public void testWriteSwappedDouble() throws IOException {
+ byte[] bytes = new byte[8];
+ final double d1 = Double.longBitsToDouble( 0x0102030405060708L );
+ EndianUtils.writeSwappedDouble( bytes, 0, d1 );
+ assertEquals( 0x08, bytes[0] );
+ assertEquals( 0x07, bytes[1] );
+ assertEquals( 0x06, bytes[2] );
+ assertEquals( 0x05, bytes[3] );
+ assertEquals( 0x04, bytes[4] );
+ assertEquals( 0x03, bytes[5] );
+ assertEquals( 0x02, bytes[6] );
+ assertEquals( 0x01, bytes[7] );
+
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(8);
+ EndianUtils.writeSwappedDouble( baos, d1 );
+ bytes = baos.toByteArray();
+ assertEquals( 0x08, bytes[0] );
+ assertEquals( 0x07, bytes[1] );
+ assertEquals( 0x06, bytes[2] );
+ assertEquals( 0x05, bytes[3] );
+ assertEquals( 0x04, bytes[4] );
+ assertEquals( 0x03, bytes[5] );
+ assertEquals( 0x02, bytes[6] );
+ assertEquals( 0x01, bytes[7] );
+ }
+
+ // tests #IO-101
+ @Test
+ public void testSymmetryOfLong() {
+
+ final double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
+ for (final double test : tests) {
+
+ // testing the real problem
+ byte[] buffer = new byte[8];
+ final long ln1 = Double.doubleToLongBits( test );
+ EndianUtils.writeSwappedLong(buffer, 0, ln1);
+ final long ln2 = EndianUtils.readSwappedLong(buffer, 0);
+ assertEquals( ln1, ln2 );
+
+ // testing the bug report
+ buffer = new byte[8];
+ EndianUtils.writeSwappedDouble(buffer, 0, test);
+ final double val = EndianUtils.readSwappedDouble(buffer, 0);
+ assertEquals( test, val, 0 );
+ }
+ }
+
+ // tests #IO-117
+ @Test
+ public void testUnsignedOverrun() throws Exception {
+ final byte[] target = new byte[] { 0, 0, 0, (byte)0x80 };
+ final long expected = 0x80000000L;
+
+ long actual = EndianUtils.readSwappedUnsignedInteger(target, 0);
+ assertEquals("readSwappedUnsignedInteger(byte[], int) was incorrect", expected, actual);
+
+ final ByteArrayInputStream in = new ByteArrayInputStream(target);
+ actual = EndianUtils.readSwappedUnsignedInteger(in);
+ assertEquals("readSwappedUnsignedInteger(InputStream) was incorrect", expected, actual);
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileCleanerTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileCleanerTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..b809eaead4ea0049f9df851a03d7ba1bd60dbd6d
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileCleanerTestCase.java"
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.commons.io;
+
+@SuppressWarnings("deprecation") // testing deprecated class
+/**
+ * This is used to test FileCleaner for correctness.
+ *
+ * @version $Id: FileCleanerTestCase.java 1718944 2015-12-09 19:50:30Z krosenvold $
+
+ * @see FileCleaner
+ */
+public class FileCleanerTestCase extends FileCleaningTrackerTestCase {
+ @Override
+ protected FileCleaningTracker newInstance() {
+ return FileCleaner.getInstance();
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..4fa71c80188108c320ca39b74b1a3e219a216ef1
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java"
@@ -0,0 +1,346 @@
+/*
+ * 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 org.apache.commons.io;
+
+import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.apache.commons.io.testtools.TestUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.*;
+import java.lang.ref.ReferenceQueue;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * This is used to test {@link FileCleaningTracker} for correctness.
+ *
+ * @version $Id: FileCleaningTrackerTestCase.java 1718945 2015-12-09 19:51:14Z krosenvold $
+ * @see FileCleaningTracker
+ */
+public class FileCleaningTrackerTestCase extends FileBasedTestCase {
+ protected FileCleaningTracker newInstance() {
+ return new FileCleaningTracker();
+ }
+
+ private File testFile;
+ private FileCleaningTracker theInstance;
+
+ public FileCleaningTrackerTestCase() {
+ testFile = new File(getTestDirectory(), "file-test.txt");
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ theInstance = newInstance();
+ getTestDirectory();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ FileUtils.deleteDirectory(getTestDirectory());
+
+ // reset file cleaner class, so as not to break other tests
+
+ /**
+ * The following block of code can possibly be removed when the
+ * deprecated {@link FileCleaner} is gone. The question is, whether
+ * we want to support reuse of {@link FileCleaningTracker} instances,
+ * which we should, IMO, not.
+ */
+ {
+ theInstance.q = new ReferenceQueue();
+ theInstance.trackers.clear();
+ theInstance.deleteFailures.clear();
+ theInstance.exitWhenFinished = false;
+ theInstance.reaper = null;
+ }
+
+ theInstance = null;
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testFileCleanerFile() throws Exception {
+ final String path = testFile.getPath();
+
+ assertFalse(testFile.exists());
+ RandomAccessFile r = new RandomAccessFile(testFile, "rw");
+ assertTrue(testFile.exists());
+
+ assertEquals(0, theInstance.getTrackCount());
+ theInstance.track(path, r);
+ assertEquals(1, theInstance.getTrackCount());
+
+ r.close();
+ testFile = null;
+ r = null;
+
+ waitUntilTrackCount();
+ pauseForDeleteToComplete(new File(path));
+
+ assertEquals(0, theInstance.getTrackCount());
+ assertEquals(showFailures(), false, new File(path).exists());
+ }
+
+ @Test
+ public void testFileCleanerDirectory() throws Exception {
+ TestUtils.createFile(testFile, 100);
+ assertTrue(testFile.exists());
+ assertTrue(getTestDirectory().exists());
+
+ Object obj = new Object();
+ assertEquals(0, theInstance.getTrackCount());
+ theInstance.track(getTestDirectory(), obj);
+ assertEquals(1, theInstance.getTrackCount());
+
+ obj = null;
+
+ waitUntilTrackCount();
+
+ assertEquals(0, theInstance.getTrackCount());
+ assertTrue(testFile.exists()); // not deleted, as dir not empty
+ assertTrue(testFile.getParentFile().exists()); // not deleted, as dir not empty
+ }
+
+ @Test
+ public void testFileCleanerDirectory_NullStrategy() throws Exception {
+ TestUtils.createFile(testFile, 100);
+ assertTrue(testFile.exists());
+ assertTrue(getTestDirectory().exists());
+
+ Object obj = new Object();
+ assertEquals(0, theInstance.getTrackCount());
+ theInstance.track(getTestDirectory(), obj, null);
+ assertEquals(1, theInstance.getTrackCount());
+
+ obj = null;
+
+ waitUntilTrackCount();
+
+ assertEquals(0, theInstance.getTrackCount());
+ assertTrue(testFile.exists()); // not deleted, as dir not empty
+ assertTrue(testFile.getParentFile().exists()); // not deleted, as dir not empty
+ }
+
+ @Test
+ public void testFileCleanerDirectory_ForceStrategy() throws Exception {
+ if (!testFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + testFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(testFile));
+ try {
+ TestUtils.generateTestData(output, (long) 100);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
+ assertTrue(testFile.exists());
+ assertTrue(getTestDirectory().exists());
+
+ Object obj = new Object();
+ assertEquals(0, theInstance.getTrackCount());
+ theInstance.track(getTestDirectory(), obj, FileDeleteStrategy.FORCE);
+ assertEquals(1, theInstance.getTrackCount());
+
+ obj = null;
+
+ waitUntilTrackCount();
+ pauseForDeleteToComplete(testFile.getParentFile());
+
+ assertEquals(0, theInstance.getTrackCount());
+ assertEquals(showFailures(), false, new File(testFile.getPath()).exists());
+ assertEquals(showFailures(), false, testFile.getParentFile().exists());
+ }
+
+ @Test
+ public void testFileCleanerNull() throws Exception {
+ try {
+ theInstance.track((File) null, new Object());
+ fail();
+ } catch (final NullPointerException ex) {
+ // expected
+ }
+ try {
+ theInstance.track((File) null, new Object(), FileDeleteStrategy.NORMAL);
+ fail();
+ } catch (final NullPointerException ex) {
+ // expected
+ }
+ try {
+ theInstance.track((String) null, new Object());
+ fail();
+ } catch (final NullPointerException ex) {
+ // expected
+ }
+ try {
+ theInstance.track((String) null, new Object(), FileDeleteStrategy.NORMAL);
+ fail();
+ } catch (final NullPointerException ex) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testFileCleanerExitWhenFinishedFirst() throws Exception {
+ assertFalse(theInstance.exitWhenFinished);
+ theInstance.exitWhenFinished();
+ assertTrue(theInstance.exitWhenFinished);
+ assertEquals(null, theInstance.reaper);
+
+ waitUntilTrackCount();
+
+ assertEquals(0, theInstance.getTrackCount());
+ assertTrue(theInstance.exitWhenFinished);
+ assertEquals(null, theInstance.reaper);
+ }
+
+ @Test
+ public void testFileCleanerExitWhenFinished_NoTrackAfter() throws Exception {
+ assertFalse(theInstance.exitWhenFinished);
+ theInstance.exitWhenFinished();
+ assertTrue(theInstance.exitWhenFinished);
+ assertEquals(null, theInstance.reaper);
+
+ final String path = testFile.getPath();
+ final Object marker = new Object();
+ try {
+ theInstance.track(path, marker);
+ fail();
+ } catch (final IllegalStateException ex) {
+ // expected
+ }
+ assertTrue(theInstance.exitWhenFinished);
+ assertEquals(null, theInstance.reaper);
+ }
+
+ @Test
+ public void testFileCleanerExitWhenFinished1() throws Exception {
+ final String path = testFile.getPath();
+
+ assertEquals("1-testFile exists", false, testFile.exists());
+ RandomAccessFile r = new RandomAccessFile(testFile, "rw");
+ assertEquals("2-testFile exists", true, testFile.exists());
+
+ assertEquals("3-Track Count", 0, theInstance.getTrackCount());
+ theInstance.track(path, r);
+ assertEquals("4-Track Count", 1, theInstance.getTrackCount());
+ assertEquals("5-exitWhenFinished", false, theInstance.exitWhenFinished);
+ assertEquals("6-reaper.isAlive", true, theInstance.reaper.isAlive());
+
+ assertEquals("7-exitWhenFinished", false, theInstance.exitWhenFinished);
+ theInstance.exitWhenFinished();
+ assertEquals("8-exitWhenFinished", true, theInstance.exitWhenFinished);
+ assertEquals("9-reaper.isAlive", true, theInstance.reaper.isAlive());
+
+ r.close();
+ testFile = null;
+ r = null;
+
+ waitUntilTrackCount();
+ pauseForDeleteToComplete(new File(path));
+
+ assertEquals("10-Track Count", 0, theInstance.getTrackCount());
+ assertEquals("11-testFile exists " + showFailures(), false, new File(path).exists());
+ assertEquals("12-exitWhenFinished", true, theInstance.exitWhenFinished);
+ assertEquals("13-reaper.isAlive", false, theInstance.reaper.isAlive());
+ }
+
+ @Test
+ public void testFileCleanerExitWhenFinished2() throws Exception {
+ final String path = testFile.getPath();
+
+ assertFalse(testFile.exists());
+ RandomAccessFile r = new RandomAccessFile(testFile, "rw");
+ assertTrue(testFile.exists());
+
+ assertEquals(0, theInstance.getTrackCount());
+ theInstance.track(path, r);
+ assertEquals(1, theInstance.getTrackCount());
+ assertFalse(theInstance.exitWhenFinished);
+ assertTrue(theInstance.reaper.isAlive());
+
+ r.close();
+ testFile = null;
+ r = null;
+
+ waitUntilTrackCount();
+ pauseForDeleteToComplete(new File(path));
+
+ assertEquals(0, theInstance.getTrackCount());
+ assertEquals(showFailures(), false, new File(path).exists());
+ assertFalse(theInstance.exitWhenFinished);
+ assertTrue(theInstance.reaper.isAlive());
+
+ assertFalse(theInstance.exitWhenFinished);
+ theInstance.exitWhenFinished();
+ for (int i = 0; i < 20 && theInstance.reaper.isAlive(); i++) {
+ TestUtils.sleep(500L); // allow reaper thread to die
+ }
+ assertTrue(theInstance.exitWhenFinished);
+ assertFalse(theInstance.reaper.isAlive());
+ }
+
+ //-----------------------------------------------------------------------
+ private void pauseForDeleteToComplete(File file) {
+ int count = 0;
+ while(file.exists() && count++ < 40) {
+ try {
+ TestUtils.sleep(500L);
+ } catch (final InterruptedException ignore) {
+ }
+ file = new File(file.getPath());
+ }
+ }
+ private String showFailures() throws Exception {
+ if (theInstance.deleteFailures.size() == 1) {
+ return "[Delete Failed: " + theInstance.deleteFailures.get(0) + "]";
+ } else {
+ return "[Delete Failures: " + theInstance.deleteFailures.size() + "]";
+ }
+ }
+
+ private void waitUntilTrackCount() throws Exception {
+ System.gc();
+ TestUtils.sleep(500);
+ int count = 0;
+ while(theInstance.getTrackCount() != 0 && count++ < 5) {
+ List list = new ArrayList();
+ try {
+ long i = 0;
+ while (theInstance.getTrackCount() != 0) {
+ list.add("A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String " + (i++));
+ }
+ } catch (final Throwable ignored) {
+ }
+ list = null;
+ System.gc();
+ TestUtils.sleep(1000);
+ }
+ if (theInstance.getTrackCount() != 0) {
+ throw new IllegalStateException("Your JVM is not releasing References, try running the testcase with less memory (-Xmx)");
+ }
+
+ }
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileDeleteStrategyTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileDeleteStrategyTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..f92d6c57cb40f2216f2c9092f2ac82f95b354db7
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileDeleteStrategyTestCase.java"
@@ -0,0 +1,165 @@
+/*
+ * 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 org.apache.commons.io;
+
+import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.apache.commons.io.testtools.TestUtils;
+import org.junit.Test;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Test for FileDeleteStrategy.
+ *
+ * @version $Id: FileDeleteStrategyTestCase.java 1718944 2015-12-09 19:50:30Z krosenvold $
+ * @see FileDeleteStrategy
+ */
+public class FileDeleteStrategyTestCase extends FileBasedTestCase {
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testDeleteNormal() throws Exception {
+ final File baseDir = getTestDirectory();
+ final File subDir = new File(baseDir, "test");
+ assertTrue(subDir.mkdir());
+ final File subFile = new File(subDir, "a.txt");
+ if (!subFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + subFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(subFile));
+ try {
+ TestUtils.generateTestData(output, (long) 16);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
+
+ assertTrue(subDir.exists());
+ assertTrue(subFile.exists());
+ // delete dir
+ try {
+ FileDeleteStrategy.NORMAL.delete(subDir);
+ fail();
+ } catch (final IOException ex) {
+ // expected
+ }
+ assertTrue(subDir.exists());
+ assertTrue(subFile.exists());
+ // delete file
+ FileDeleteStrategy.NORMAL.delete(subFile);
+ assertTrue(subDir.exists());
+ assertFalse(subFile.exists());
+ // delete dir
+ FileDeleteStrategy.NORMAL.delete(subDir);
+ assertFalse(subDir.exists());
+ // delete dir
+ FileDeleteStrategy.NORMAL.delete(subDir); // no error
+ assertFalse(subDir.exists());
+ }
+
+ @Test
+ public void testDeleteQuietlyNormal() throws Exception {
+ final File baseDir = getTestDirectory();
+ final File subDir = new File(baseDir, "test");
+ assertTrue(subDir.mkdir());
+ final File subFile = new File(subDir, "a.txt");
+ if (!subFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + subFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(subFile));
+ try {
+ TestUtils.generateTestData(output, (long) 16);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
+
+ assertTrue(subDir.exists());
+ assertTrue(subFile.exists());
+ // delete dir
+ assertFalse(FileDeleteStrategy.NORMAL.deleteQuietly(subDir));
+ assertTrue(subDir.exists());
+ assertTrue(subFile.exists());
+ // delete file
+ assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(subFile));
+ assertTrue(subDir.exists());
+ assertFalse(subFile.exists());
+ // delete dir
+ assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(subDir));
+ assertFalse(subDir.exists());
+ // delete dir
+ assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(subDir)); // no error
+ assertFalse(subDir.exists());
+ }
+
+ @Test
+ public void testDeleteForce() throws Exception {
+ final File baseDir = getTestDirectory();
+ final File subDir = new File(baseDir, "test");
+ assertTrue(subDir.mkdir());
+ final File subFile = new File(subDir, "a.txt");
+ if (!subFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + subFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(subFile));
+ try {
+ TestUtils.generateTestData(output, (long) 16);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
+
+ assertTrue(subDir.exists());
+ assertTrue(subFile.exists());
+ // delete dir
+ FileDeleteStrategy.FORCE.delete(subDir);
+ assertFalse(subDir.exists());
+ assertFalse(subFile.exists());
+ // delete dir
+ FileDeleteStrategy.FORCE.delete(subDir); // no error
+ assertFalse(subDir.exists());
+ }
+
+ @Test
+ public void testDeleteNull() throws Exception {
+ try {
+ FileDeleteStrategy.NORMAL.delete(null);
+ fail();
+ } catch (final NullPointerException ex) {
+ // expected
+ }
+ assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(null));
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals("FileDeleteStrategy[Normal]", FileDeleteStrategy.NORMAL.toString());
+ assertEquals("FileDeleteStrategy[Force]", FileDeleteStrategy.FORCE.toString());
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ebacff5099717e744b812535243ad9fcc9022bd2
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java"
@@ -0,0 +1,584 @@
+/*
+ * 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 org.apache.commons.io;
+
+import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.*;
+import java.util.Locale;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * This is used to test FileSystemUtils.
+ *
+ * @version $Id: FileSystemUtilsTestCase.java 1718944 2015-12-09 19:50:30Z krosenvold $
+ */
+public class FileSystemUtilsTestCase extends FileBasedTestCase {
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testGetFreeSpace_String() throws Exception {
+ // test coverage, as we can't check value
+ if (File.separatorChar == '/') {
+ // have to figure out unix block size
+ final String[] cmd;
+ String osName = System.getProperty("os.name");
+ osName = osName.toLowerCase(Locale.ENGLISH);
+
+ if (osName.contains("hp-ux") || osName.contains("aix")) {
+ cmd = new String[]{"df", "-P", "/"};
+ } else if (osName.contains("sunos") || osName.contains("sun os")
+ || osName.contains("solaris")) {
+ cmd = new String[]{"/usr/xpg4/bin/df", "-P", "/"};
+ } else {
+ cmd = new String[]{"df", "/"};
+ }
+ final Process proc = Runtime.getRuntime().exec(cmd);
+ boolean kilobyteBlock = true;
+ BufferedReader r = null;
+ try {
+ r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ final String line = r.readLine();
+ Assert.assertNotNull("Unexpected null line", line);
+ if (line.contains("512")) {
+ kilobyteBlock = false;
+ }
+ } finally {
+ IOUtils.closeQuietly(r);
+ }
+
+ // now perform the test
+ @SuppressWarnings("deprecation")
+ final
+ long free = FileSystemUtils.freeSpace("/");
+ final long kb = FileSystemUtils.freeSpaceKb("/");
+ if (kilobyteBlock) {
+ assertEquals(free, kb, 256d);
+ } else {
+ assertEquals(free / 2d, kb, 256d);
+ }
+ } else {
+ @SuppressWarnings("deprecation")
+ final
+ long bytes = FileSystemUtils.freeSpace("");
+ final long kb = FileSystemUtils.freeSpaceKb("");
+ assertEquals((double) bytes / 1024, kb, 256d);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testGetFreeSpaceOS_String_NullPath() throws Exception {
+ final FileSystemUtils fsu = new FileSystemUtils();
+ try {
+ fsu.freeSpaceOS(null, 1, false, -1);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+ try {
+ fsu.freeSpaceOS(null, 1, true, -1);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+ }
+
+ @Test
+ public void testGetFreeSpaceOS_String_InitError() throws Exception {
+ final FileSystemUtils fsu = new FileSystemUtils();
+ try {
+ fsu.freeSpaceOS("", -1, false, -1);
+ fail();
+ } catch (final IllegalStateException ignore) {
+ }
+ try {
+ fsu.freeSpaceOS("", -1, true, -1);
+ fail();
+ } catch (final IllegalStateException ignore) {
+ }
+ }
+
+ @Test
+ public void testGetFreeSpaceOS_String_Other() throws Exception {
+ final FileSystemUtils fsu = new FileSystemUtils();
+ try {
+ fsu.freeSpaceOS("", 0, false, -1);
+ fail();
+ } catch (final IllegalStateException ignore) {
+ }
+ try {
+ fsu.freeSpaceOS("", 0, true, -1);
+ fail();
+ } catch (final IllegalStateException ignore) {
+ }
+ }
+
+ @Test
+ public void testGetFreeSpaceOS_String_Windows() throws Exception {
+ final FileSystemUtils fsu = new FileSystemUtils() {
+ @Override
+ protected long freeSpaceWindows(final String path, final long timeout) throws IOException {
+ return 12345L;
+ }
+ };
+ assertEquals(12345L, fsu.freeSpaceOS("", 1, false, -1));
+ assertEquals(12345L / 1024, fsu.freeSpaceOS("", 1, true, -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceOS_String_Unix() throws Exception {
+ final FileSystemUtils fsu = new FileSystemUtils() {
+ @Override
+ protected long freeSpaceUnix(final String path, final boolean kb, final boolean posix, final long timeout) throws IOException {
+ return kb ? 12345L : 54321;
+ }
+ };
+ assertEquals(54321L, fsu.freeSpaceOS("", 2, false, -1));
+ assertEquals(12345L, fsu.freeSpaceOS("", 2, true, -1));
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testGetFreeSpaceWindows_String_ParseCommaFormatBytes() throws Exception {
+ // this is the format of response when calling dir /c
+ // we have now switched to dir /-c, so we should never get this
+ final String lines =
+ " Volume in drive C is HDD\n" +
+ " Volume Serial Number is XXXX-YYYY\n" +
+ "\n" +
+ " Directory of C:\\Documents and Settings\\Xxxx\n" +
+ "\n" +
+ "19/08/2005 22:43 .\n" +
+ "19/08/2005 22:43 ..\n" +
+ "11/08/2005 01:07 81 build.properties\n" +
+ "17/08/2005 21:44 Desktop\n" +
+ " 7 File(s) 180,260 bytes\n" +
+ " 10 Dir(s) 41,411,551,232 bytes free";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ assertEquals(41411551232L, fsu.freeSpaceWindows("", -1));
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testGetFreeSpaceWindows_String_EmptyPath() throws Exception {
+ final String lines =
+ " Volume in drive C is HDD\n" +
+ " Volume Serial Number is XXXX-YYYY\n" +
+ "\n" +
+ " Directory of C:\\Documents and Settings\\Xxxx\n" +
+ "\n" +
+ "19/08/2005 22:43 .\n" +
+ "19/08/2005 22:43 ..\n" +
+ "11/08/2005 01:07 81 build.properties\n" +
+ "17/08/2005 21:44 Desktop\n" +
+ " 7 File(s) 180260 bytes\n" +
+ " 10 Dir(s) 41411551232 bytes free";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /a /-c ");
+ assertEquals(41411551232L, fsu.freeSpaceWindows("", -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceWindows_String_NormalResponse() throws Exception {
+ final String lines =
+ " Volume in drive C is HDD\n" +
+ " Volume Serial Number is XXXX-YYYY\n" +
+ "\n" +
+ " Directory of C:\\Documents and Settings\\Xxxx\n" +
+ "\n" +
+ "19/08/2005 22:43 .\n" +
+ "19/08/2005 22:43 ..\n" +
+ "11/08/2005 01:07 81 build.properties\n" +
+ "17/08/2005 21:44 Desktop\n" +
+ " 7 File(s) 180260 bytes\n" +
+ " 10 Dir(s) 41411551232 bytes free";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /a /-c \"C:\"");
+ assertEquals(41411551232L, fsu.freeSpaceWindows("C:", -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceWindows_String_StripDrive() throws Exception {
+ final String lines =
+ " Volume in drive C is HDD\n" +
+ " Volume Serial Number is XXXX-YYYY\n" +
+ "\n" +
+ " Directory of C:\\Documents and Settings\\Xxxx\n" +
+ "\n" +
+ "19/08/2005 22:43 .\n" +
+ "19/08/2005 22:43 ..\n" +
+ "11/08/2005 01:07 81 build.properties\n" +
+ "17/08/2005 21:44 Desktop\n" +
+ " 7 File(s) 180260 bytes\n" +
+ " 10 Dir(s) 41411551232 bytes free";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /a /-c \"C:\\somedir\"");
+ assertEquals(41411551232L, fsu.freeSpaceWindows("C:\\somedir", -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceWindows_String_quoted() throws Exception {
+ final String lines =
+ " Volume in drive C is HDD\n" +
+ " Volume Serial Number is XXXX-YYYY\n" +
+ "\n" +
+ " Directory of C:\\Documents and Settings\\Xxxx\n" +
+ "\n" +
+ "19/08/2005 22:43 .\n" +
+ "19/08/2005 22:43 ..\n" +
+ "11/08/2005 01:07 81 build.properties\n" +
+ "17/08/2005 21:44 Desktop\n" +
+ " 7 File(s) 180260 bytes\n" +
+ " 10 Dir(s) 41411551232 bytes free";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /a /-c \"C:\\somedir\"");
+ assertEquals(41411551232L, fsu.freeSpaceWindows("\"C:\\somedir\"", -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceWindows_String_EmptyResponse() throws Exception {
+ final String lines = "";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ try {
+ fsu.freeSpaceWindows("C:", -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ }
+
+ @Test(expected = IOException.class)
+ public void testGetFreeSpaceWindows_String_EmptyMultiLineResponse() throws Exception {
+ final String lines = "\n\n";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ fsu.freeSpaceWindows("C:", -1);
+ }
+
+ @Test(expected = IOException.class)
+ public void testGetFreeSpaceWindows_String_InvalidTextResponse() throws Exception {
+ final String lines = "BlueScreenOfDeath";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ fsu.freeSpaceWindows("C:", -1);
+ }
+
+ @Test(expected = IOException.class)
+ public void testGetFreeSpaceWindows_String_NoSuchDirectoryResponse() throws Exception {
+ final String lines =
+ " Volume in drive C is HDD\n" +
+ " Volume Serial Number is XXXX-YYYY\n" +
+ "\n" +
+ " Directory of C:\\Documents and Settings\\empty" +
+ "\n";
+ final FileSystemUtils fsu = new MockFileSystemUtils(1, lines);
+ fsu.freeSpaceWindows("C:", -1);
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testGetFreeSpaceUnix_String_EmptyPath() throws Exception {
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ "xxx:/home/users/s 14428928 12956424 1472504 90% /home/users/s";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ try {
+ fsu.freeSpaceUnix("", false, false, -1);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("", true, false, -1);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("", true, true, -1);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("", false, true, -1);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_NormalResponseLinux() throws Exception {
+ // from Sourceforge 'GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)'
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ "/dev/xxx 497944 308528 189416 62% /";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ assertEquals(189416L, fsu.freeSpaceUnix("/", false, false, -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_NormalResponseFreeBSD() throws Exception {
+ // from Apache 'FreeBSD 6.1-RELEASE (SMP-turbo)'
+ final String lines =
+ "Filesystem 1K-blocks Used Avail Capacity Mounted on\n" +
+ "/dev/xxxxxx 128990 102902 15770 87% /";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ assertEquals(15770L, fsu.freeSpaceUnix("/", false, false, -1));
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testGetFreeSpaceUnix_String_NormalResponseKbLinux() throws Exception {
+ // from Sourceforge 'GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)'
+ // df, df -k and df -kP are all identical
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ "/dev/xxx 497944 308528 189416 62% /";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ assertEquals(189416L, fsu.freeSpaceUnix("/", true, false, -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_NormalResponseKbFreeBSD() throws Exception {
+ // from Apache 'FreeBSD 6.1-RELEASE (SMP-turbo)'
+ // df and df -k are identical, but df -kP uses 512 blocks (not relevant as not used)
+ final String lines =
+ "Filesystem 1K-blocks Used Avail Capacity Mounted on\n" +
+ "/dev/xxxxxx 128990 102902 15770 87% /";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ assertEquals(15770L, fsu.freeSpaceUnix("/", true, false, -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_NormalResponseKbSolaris() throws Exception {
+ // from IO-91 - ' SunOS et 5.10 Generic_118822-25 sun4u sparc SUNW,Ultra-4'
+ // non-kb response does not contain free space - see IO-91
+ final String lines =
+ "Filesystem kbytes used avail capacity Mounted on\n" +
+ "/dev/dsk/x0x0x0x0 1350955 815754 481163 63%";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ assertEquals(481163L, fsu.freeSpaceUnix("/dev/dsk/x0x0x0x0", true, false, -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_LongResponse() throws Exception {
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ "xxx-yyyyyyy-zzz:/home/users/s\n" +
+ " 14428928 12956424 1472504 90% /home/users/s";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ assertEquals(1472504L, fsu.freeSpaceUnix("/home/users/s", false, false, -1));
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_LongResponseKb() throws Exception {
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ "xxx-yyyyyyy-zzz:/home/users/s\n" +
+ " 14428928 12956424 1472504 90% /home/users/s";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ assertEquals(1472504L, fsu.freeSpaceUnix("/home/users/s", true, false, -1));
+ }
+ @Test
+
+ public void testGetFreeSpaceUnix_String_EmptyResponse() throws Exception {
+ final String lines = "";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_InvalidResponse1() throws Exception {
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ " 14428928 12956424 100";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_InvalidResponse2() throws Exception {
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ "xxx:/home/users/s 14428928 12956424 nnnnnnn 90% /home/users/s";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_InvalidResponse3() throws Exception {
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ "xxx:/home/users/s 14428928 12956424 -1 90% /home/users/s";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ }
+
+ @Test
+ public void testGetFreeSpaceUnix_String_InvalidResponse4() throws Exception {
+ final String lines =
+ "Filesystem 1K-blocks Used Available Use% Mounted on\n" +
+ "xxx-yyyyyyy-zzz:/home/users/s";
+ final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, false, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", false, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ try {
+ fsu.freeSpaceUnix("/home/users/s", true, true, -1);
+ fail();
+ } catch (final IOException ignore) {
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ static class MockFileSystemUtils extends FileSystemUtils {
+ private final int exitCode;
+ private final byte[] bytes;
+ private final String cmd;
+
+ public MockFileSystemUtils(final int exitCode, final String lines) {
+ this(exitCode, lines, null);
+ }
+
+ public MockFileSystemUtils(final int exitCode, final String lines, final String cmd) {
+ this.exitCode = exitCode;
+ this.bytes = lines.getBytes();
+ this.cmd = cmd;
+ }
+
+ @Override
+ Process openProcess(final String[] params) {
+ if (cmd != null) {
+ assertEquals(cmd, params[params.length - 1]);
+ }
+ return new Process() {
+ @Override
+ public InputStream getErrorStream() {
+ return null;
+ }
+
+ @Override
+ public InputStream getInputStream() {
+ return new ByteArrayInputStream(bytes);
+ }
+
+ @Override
+ public OutputStream getOutputStream() {
+ return null;
+ }
+
+ @Override
+ public int waitFor() throws InterruptedException {
+ return exitCode;
+ }
+
+ @Override
+ public int exitValue() {
+ return exitCode;
+ }
+
+ @Override
+ public void destroy() {
+ }
+ };
+ }
+ }
+
+}
diff --git "a/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java" "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java"
new file mode 100644
index 0000000000000000000000000000000000000000..ce54fbef3890290c599faddeb970287c0236adce
--- /dev/null
+++ "b/\345\260\232\347\241\205\350\260\267Java\345\205\245\351\227\250\346\225\231\347\250\213\357\274\214java\347\224\265\345\255\220\344\271\246+Java\351\235\242\350\257\225\347\234\237\351\242\230\357\274\2102023\346\226\260\347\211\210\357\274\211/01_\350\257\276\344\273\266\344\270\216\347\224\265\345\255\220\346\225\231\346\235\220/\345\260\232\347\241\205\350\260\267_\347\254\25415\347\253\240_File\347\261\273\344\270\216IO\346\265\201/03-apache-common\345\214\205/commons-io-2.5-src/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java"
@@ -0,0 +1,161 @@
+/*
+ * 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 org.apache.commons.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Test cases for FileUtils.cleanDirectory() method.
+ *
+ * @version $Id: FileUtilsCleanDirectoryTestCase.java 1718944 2015-12-09 19:50:30Z krosenvold $
+ */
+public class FileUtilsCleanDirectoryTestCase extends FileBasedTestCase {
+ final File top = getLocalTestDirectory();
+
+ private File getLocalTestDirectory() {
+ return new File(getTestDirectory(), "list-files");
+ }
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Before
+ public void setUp() throws Exception {
+ top.mkdirs();
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @After
+ public void tearDown() throws Exception {
+ chmod(top, 775, true);
+ FileUtils.deleteDirectory(top);
+ }
+
+ //-----------------------------------------------------------------------
+ @Test
+ public void testCleanEmpty() throws Exception {
+ assertEquals(0, top.list().length);
+
+ FileUtils.cleanDirectory(top);
+
+ assertEquals(0, top.list().length);
+ }
+
+ @Test
+ public void testDeletesRegular() throws Exception {
+ FileUtils.touch(new File(top, "regular"));
+ FileUtils.touch(new File(top, ".hidden"));
+
+ assertEquals(2, top.list().length);
+
+ FileUtils.cleanDirectory(top);
+
+ assertEquals(0, top.list().length);
+ }
+
+ @Test
+ public void testDeletesNested() throws Exception {
+ final File nested = new File(top, "nested");
+
+ assertTrue(nested.mkdirs());
+
+ FileUtils.touch(new File(nested, "file"));
+
+ assertEquals(1, top.list().length);
+
+ FileUtils.cleanDirectory(top);
+
+ assertEquals(0, top.list().length);
+ }
+
+ @Test
+ public void testThrowsOnNullList() throws Exception {
+ if (System.getProperty("os.name").startsWith("Win") || !chmod(top, 0, false)) {
+ // test wont work if we can't restrict permissions on the
+ // directory, so skip it.
+ return;
+ }
+
+ try {
+ FileUtils.cleanDirectory(top);
+ fail("expected IOException");
+ } catch (final IOException e) {
+ assertEquals("Failed to list contents of " +
+ top.getAbsolutePath(), e.getMessage());
+ }
+ }
+
+ @Test
+ public void testThrowsOnCannotDeleteFile() throws Exception {
+ final File file = new File(top, "restricted");
+ FileUtils.touch(file);
+
+ if (System.getProperty("os.name").startsWith("Win") || !chmod(top, 500, false)) {
+ // test wont work if we can't restrict permissions on the
+ // directory, so skip it.
+ return;
+ }
+
+ try {
+ FileUtils.cleanDirectory(top);
+ fail("expected IOException");
+ } catch (final IOException e) {
+ assertEquals("Unable to delete file: " +
+ file.getAbsolutePath(), e.getMessage());
+ }
+ }
+
+ private boolean chmod(final File file, final int mode, final boolean recurse)
+ throws InterruptedException {
+ // TODO: Refactor this to FileSystemUtils
+ final List