Resolve build warnings; part 1
Change-Id: I80ca98ef80a427229ab5feb41568e34b257f32ce
This commit is contained in:
parent
045f91e94f
commit
44de127691
|
@ -1,30 +1,29 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2006 J.T. Beetstra
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package com.beetstra.jutf7;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
@ -35,7 +34,7 @@ import java.util.List;
|
|||
* Charset service-provider class used for both variants of the UTF-7 charset
|
||||
* and the modified-UTF-7 charset.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Jaap Beetstra
|
||||
*/
|
||||
public class CharsetProvider extends java.nio.charset.spi.CharsetProvider {
|
||||
|
@ -55,10 +54,10 @@ public class CharsetProvider extends java.nio.charset.spi.CharsetProvider {
|
|||
private Charset utf7charset = new UTF7Charset(UTF7_NAME, UTF7_ALIASES, false);
|
||||
private Charset utf7oCharset = new UTF7Charset(UTF7_O_NAME, UTF7_O_ALIASES, true);
|
||||
private Charset imap4charset = new ModifiedUTF7Charset(UTF7_M_NAME, UTF7_M_ALIASES);
|
||||
private List charsets;
|
||||
private List<Charset> charsets;
|
||||
|
||||
public CharsetProvider() {
|
||||
charsets = Arrays.asList(new Object[] {
|
||||
charsets = Arrays.asList(new Charset[] {
|
||||
utf7charset, imap4charset, utf7oCharset
|
||||
});
|
||||
}
|
||||
|
@ -66,15 +65,16 @@ public class CharsetProvider extends java.nio.charset.spi.CharsetProvider {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Charset charsetForName(String charsetName) {
|
||||
charsetName = charsetName.toUpperCase();
|
||||
for (Iterator iter = charsets.iterator(); iter.hasNext();) {
|
||||
Charset charset = (Charset)iter.next();
|
||||
for (Iterator<Charset> iter = charsets.iterator(); iter.hasNext();) {
|
||||
Charset charset = iter.next();
|
||||
if (charset.name().equals(charsetName))
|
||||
return charset;
|
||||
}
|
||||
for (Iterator iter = charsets.iterator(); iter.hasNext();) {
|
||||
Charset charset = (Charset)iter.next();
|
||||
for (Iterator<Charset> iter = charsets.iterator(); iter.hasNext();) {
|
||||
Charset charset = iter.next();
|
||||
if (charset.aliases().contains(charsetName))
|
||||
return charset;
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ public class CharsetProvider extends java.nio.charset.spi.CharsetProvider {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Iterator charsets() {
|
||||
@Override
|
||||
public Iterator<Charset> charsets() {
|
||||
return charsets.iterator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -44,11 +44,11 @@ public class FileCleaningTracker {
|
|||
/**
|
||||
* Queue of <code>Tracker</code> instances being watched.
|
||||
*/
|
||||
ReferenceQueue /* Tracker */ q = new ReferenceQueue();
|
||||
ReferenceQueue<Object> /* Tracker */ q = new ReferenceQueue<Object>();
|
||||
/**
|
||||
* Collection of <code>Tracker</code> instances in existence.
|
||||
*/
|
||||
final Collection /* Tracker */ trackers = new Vector(); // synchronized
|
||||
final Collection<Tracker> /* Tracker */ trackers = new Vector<Tracker>(); // synchronized
|
||||
/**
|
||||
* Whether to terminate the thread when the tracking is complete.
|
||||
*/
|
||||
|
@ -121,7 +121,7 @@ public class FileCleaningTracker {
|
|||
|
||||
/**
|
||||
* 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
|
||||
|
@ -196,6 +196,7 @@ public class FileCleaningTracker {
|
|||
* 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) {
|
||||
|
@ -219,7 +220,7 @@ public class FileCleaningTracker {
|
|||
/**
|
||||
* Inner class which acts as the reference for a file pending deletion.
|
||||
*/
|
||||
private static final class Tracker extends PhantomReference {
|
||||
private static final class Tracker extends PhantomReference<Object> {
|
||||
|
||||
/**
|
||||
* The full path to the file being tracked.
|
||||
|
@ -238,7 +239,7 @@ public class FileCleaningTracker {
|
|||
* @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(String path, FileDeleteStrategy deleteStrategy, Object marker, ReferenceQueue queue) {
|
||||
Tracker(String path, FileDeleteStrategy deleteStrategy, Object marker, ReferenceQueue<Object> queue) {
|
||||
super(marker, queue);
|
||||
this.path = path;
|
||||
this.deleteStrategy = (deleteStrategy == null ? FileDeleteStrategy.NORMAL : deleteStrategy);
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -217,19 +217,19 @@ public class FileSystemUtils {
|
|||
if (path.length() > 2 && path.charAt(1) == ':') {
|
||||
path = path.substring(0, 2); // seems to make it work
|
||||
}
|
||||
|
||||
|
||||
// build and run the 'dir' command
|
||||
String[] cmdAttribs = new String[] {"cmd.exe", "/C", "dir /-c " + path};
|
||||
|
||||
|
||||
// read in the output of the command to an ArrayList
|
||||
List lines = performCommand(cmdAttribs, Integer.MAX_VALUE);
|
||||
|
||||
List<String> lines = performCommand(cmdAttribs, Integer.MAX_VALUE);
|
||||
|
||||
// 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--) {
|
||||
String line = (String) lines.get(i);
|
||||
String line = lines.get(i);
|
||||
if (line.length() > 0) {
|
||||
return parseDir(line, path);
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ public class FileSystemUtils {
|
|||
"Command line 'dir /-c' did not return valid info " +
|
||||
"for path '" + path + "'");
|
||||
}
|
||||
|
||||
|
||||
// remove commas and dots in the bytes count
|
||||
StringBuffer buf = new StringBuffer(line.substring(bytesStart, bytesEnd));
|
||||
for (int k = 0; k < buf.length(); k++) {
|
||||
|
@ -316,25 +316,25 @@ public class FileSystemUtils {
|
|||
if (posix) {
|
||||
flags += "P";
|
||||
}
|
||||
String[] cmdAttribs =
|
||||
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)
|
||||
List lines = performCommand(cmdAttribs, 3);
|
||||
List<String> lines = performCommand(cmdAttribs, 3);
|
||||
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);
|
||||
}
|
||||
String line2 = (String) lines.get(1); // the line we're interested in
|
||||
|
||||
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) {
|
||||
String line3 = (String) lines.get(2); // the line may be interested in
|
||||
String line3 = lines.get(2); // the line may be interested in
|
||||
tok = new StringTokenizer(line3, " ");
|
||||
} else {
|
||||
throw new IOException(
|
||||
|
@ -353,7 +353,7 @@ public class FileSystemUtils {
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Parses the bytes from a string.
|
||||
*
|
||||
*
|
||||
* @param freeSpace the free space string
|
||||
* @param path the path
|
||||
* @return the number of bytes
|
||||
|
@ -368,7 +368,7 @@ public class FileSystemUtils {
|
|||
"for path '" + path + "'- check path is valid");
|
||||
}
|
||||
return bytes;
|
||||
|
||||
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new IOException(
|
||||
"Command line 'df' did not return numeric data as expected " +
|
||||
|
@ -385,7 +385,7 @@ public class FileSystemUtils {
|
|||
* @return the parsed data
|
||||
* @throws IOException if an error occurs
|
||||
*/
|
||||
List performCommand(String[] cmdAttribs, int max) throws IOException {
|
||||
List<String> performCommand(String[] cmdAttribs, int max) 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
|
||||
|
@ -393,8 +393,8 @@ public class FileSystemUtils {
|
|||
// http://forum.java.sun.com/thread.jspa?threadID=533029&messageID=2572018
|
||||
// however, its still not perfect as the JDK support is so poor
|
||||
// (see commond-exec or ant for a better multi-threaded multi-os solution)
|
||||
|
||||
List lines = new ArrayList(20);
|
||||
|
||||
List<String> lines = new ArrayList<String>(20);
|
||||
Process proc = null;
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
@ -412,7 +412,7 @@ public class FileSystemUtils {
|
|||
lines.add(line);
|
||||
line = inr.readLine();
|
||||
}
|
||||
|
||||
|
||||
proc.waitFor();
|
||||
if (proc.exitValue() != 0) {
|
||||
// os command problem, throw exception
|
||||
|
@ -427,7 +427,7 @@ public class FileSystemUtils {
|
|||
"for command " + Arrays.asList(cmdAttribs));
|
||||
}
|
||||
return lines;
|
||||
|
||||
|
||||
} catch (InterruptedException ex) {
|
||||
throw new IOException(
|
||||
"Command line threw an InterruptedException '" + ex.getMessage() +
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -117,7 +117,7 @@ public class FileUtils {
|
|||
* 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</code>
|
||||
* @return a new {@link FileInputStream} for the specified file
|
||||
* @throws FileNotFoundException if the file does not exist
|
||||
|
@ -152,7 +152,7 @@ public class FileUtils {
|
|||
* 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</code>
|
||||
* @return a new {@link FileOutputStream} for the specified file
|
||||
* @throws IOException if the file object is a directory
|
||||
|
@ -235,8 +235,8 @@ public class FileUtils {
|
|||
* @param files a Collection containing java.io.File instances
|
||||
* @return an array of java.io.File
|
||||
*/
|
||||
public static File[] convertFileCollectionToFileArray(Collection files) {
|
||||
return (File[]) files.toArray(new File[files.size()]);
|
||||
public static File[] convertFileCollectionToFileArray(Collection<File> files) {
|
||||
return files.toArray(new File[files.size()]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -248,7 +248,7 @@ public class FileUtils {
|
|||
* @param directory the directory to search in.
|
||||
* @param filter the filter to apply to files and directories.
|
||||
*/
|
||||
private static void innerListFiles(Collection files, File directory,
|
||||
private static void innerListFiles(Collection<File> files, File directory,
|
||||
IOFileFilter filter) {
|
||||
File[] found = directory.listFiles((FileFilter) filter);
|
||||
if (found != null) {
|
||||
|
@ -287,7 +287,7 @@ public class FileUtils {
|
|||
* @see org.apache.commons.io.filefilter.FileFilterUtils
|
||||
* @see org.apache.commons.io.filefilter.NameFileFilter
|
||||
*/
|
||||
public static Collection listFiles(
|
||||
public static Collection<File> listFiles(
|
||||
File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {
|
||||
if (!directory.isDirectory()) {
|
||||
throw new IllegalArgumentException(
|
||||
|
@ -311,7 +311,7 @@ public class FileUtils {
|
|||
}
|
||||
|
||||
//Find files
|
||||
Collection files = new java.util.LinkedList();
|
||||
Collection<File> files = new java.util.LinkedList<File>();
|
||||
innerListFiles(files, directory,
|
||||
FileFilterUtils.orFileFilter(effFileFilter, effDirFilter));
|
||||
return files;
|
||||
|
@ -334,7 +334,7 @@ public class FileUtils {
|
|||
* @see org.apache.commons.io.filefilter.NameFileFilter
|
||||
* @since Commons IO 1.2
|
||||
*/
|
||||
public static Iterator iterateFiles(
|
||||
public static Iterator<File> iterateFiles(
|
||||
File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {
|
||||
return listFiles(directory, fileFilter, dirFilter).iterator();
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ public class FileUtils {
|
|||
* @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(
|
||||
public static Collection<File> listFiles(
|
||||
File directory, String[] extensions, boolean recursive) {
|
||||
IOFileFilter filter;
|
||||
if (extensions == null) {
|
||||
|
@ -391,7 +391,7 @@ public class FileUtils {
|
|||
* @return an iterator of java.io.File with the matching files
|
||||
* @since Commons IO 1.2
|
||||
*/
|
||||
public static Iterator iterateFiles(
|
||||
public static Iterator<File> iterateFiles(
|
||||
File directory, String[] extensions, boolean recursive) {
|
||||
return listFiles(directory, extensions, recursive).iterator();
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ public class FileUtils {
|
|||
URL[] urls = new URL[files.length];
|
||||
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
urls[i] = files[i].toURL();
|
||||
urls[i] = files[i].toURI().toURL();
|
||||
}
|
||||
|
||||
return urls;
|
||||
|
@ -594,10 +594,10 @@ public class FileUtils {
|
|||
* 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.
|
||||
*
|
||||
*
|
||||
* @param srcFile an existing file to copy, must not be <code>null</code>
|
||||
* @param destFile the new file, must not be <code>null</code>
|
||||
*
|
||||
*
|
||||
* @throws NullPointerException if source or destination is <code>null</code>
|
||||
* @throws IOException if source or destination is invalid
|
||||
* @throws IOException if an IO error occurs during copying
|
||||
|
@ -655,7 +655,7 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* Internal copy file method.
|
||||
*
|
||||
*
|
||||
* @param srcFile the validated source file, must not be <code>null</code>
|
||||
* @param destFile the validated destination file, must not be <code>null</code>
|
||||
* @param preserveFileDate whether to preserve the file date
|
||||
|
@ -780,7 +780,7 @@ public class FileUtils {
|
|||
* If the destination directory did exist, then this method merges
|
||||
* the source with the destination, with the source taking precedence.
|
||||
*
|
||||
* <h4>Example: Copy directories only</h4>
|
||||
* <h4>Example: Copy directories only</h4>
|
||||
* <pre>
|
||||
* // only copy the directory structure
|
||||
* FileUtils.copyDirectory(srcDir, destDir, DirectoryFileFilter.DIRECTORY);
|
||||
|
@ -824,7 +824,7 @@ public class FileUtils {
|
|||
* If the destination directory did exist, then this method merges
|
||||
* the source with the destination, with the source taking precedence.
|
||||
*
|
||||
* <h4>Example: Copy directories only</h4>
|
||||
* <h4>Example: Copy directories only</h4>
|
||||
* <pre>
|
||||
* // only copy the directory structure
|
||||
* FileUtils.copyDirectory(srcDir, destDir, DirectoryFileFilter.DIRECTORY, false);
|
||||
|
@ -842,7 +842,7 @@ public class FileUtils {
|
|||
* // Copy using the filter
|
||||
* FileUtils.copyDirectory(srcDir, destDir, filter, false);
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param srcDir an existing directory to copy, must not be <code>null</code>
|
||||
* @param destDir the new directory, must not be <code>null</code>
|
||||
* @param filter the filter to apply, null means copy all directories and files
|
||||
|
@ -873,11 +873,11 @@ public class FileUtils {
|
|||
}
|
||||
|
||||
// Cater for destination being directory within the source directory (see IO-141)
|
||||
List exclusionList = null;
|
||||
List<String> exclusionList = null;
|
||||
if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
|
||||
File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
|
||||
if (srcFiles != null && srcFiles.length > 0) {
|
||||
exclusionList = new ArrayList(srcFiles.length);
|
||||
exclusionList = new ArrayList<String>(srcFiles.length);
|
||||
for (int i = 0; i < srcFiles.length; i++) {
|
||||
File copiedFile = new File(destDir, srcFiles[i].getName());
|
||||
exclusionList.add(copiedFile.getCanonicalPath());
|
||||
|
@ -889,7 +889,7 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* Internal copy directory method.
|
||||
*
|
||||
*
|
||||
* @param srcDir the validated source directory, must not be <code>null</code>
|
||||
* @param destDir the validated destination directory, must not be <code>null</code>
|
||||
* @param filter the filter to apply, null means copy all directories and files
|
||||
|
@ -899,7 +899,7 @@ public class FileUtils {
|
|||
* @since Commons IO 1.1
|
||||
*/
|
||||
private static void doCopyDirectory(File srcDir, File destDir, FileFilter filter,
|
||||
boolean preserveFileDate, List exclusionList) throws IOException {
|
||||
boolean preserveFileDate, List<String> exclusionList) throws IOException {
|
||||
if (destDir.exists()) {
|
||||
if (destDir.isDirectory() == false) {
|
||||
throw new IOException("Destination '" + destDir + "' exists but is not a directory");
|
||||
|
@ -964,7 +964,7 @@ public class FileUtils {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Deletes a directory recursively.
|
||||
* Deletes a directory recursively.
|
||||
*
|
||||
* @param directory directory to delete
|
||||
* @throws IOException in case deletion is unsuccessful
|
||||
|
@ -1108,7 +1108,7 @@ public class FileUtils {
|
|||
|
||||
|
||||
/**
|
||||
* Reads the contents of a file into a String using the default encoding for the VM.
|
||||
* 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</code>
|
||||
|
@ -1150,7 +1150,7 @@ public class FileUtils {
|
|||
* @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static List readLines(File file, String encoding) throws IOException {
|
||||
public static List<String> readLines(File file, String encoding) throws IOException {
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = openInputStream(file);
|
||||
|
@ -1169,7 +1169,7 @@ public class FileUtils {
|
|||
* @throws IOException in case of an I/O error
|
||||
* @since Commons IO 1.3
|
||||
*/
|
||||
public static List readLines(File file) throws IOException {
|
||||
public static List<String> readLines(File file) throws IOException {
|
||||
return readLines(file, null);
|
||||
}
|
||||
|
||||
|
@ -1256,7 +1256,7 @@ public class FileUtils {
|
|||
|
||||
/**
|
||||
* 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
|
||||
|
@ -1301,7 +1301,7 @@ public class FileUtils {
|
|||
* @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static void writeLines(File file, String encoding, Collection lines) throws IOException {
|
||||
public static void writeLines(File file, String encoding, Collection<Object> lines) throws IOException {
|
||||
writeLines(file, encoding, lines, null);
|
||||
}
|
||||
|
||||
|
@ -1315,7 +1315,7 @@ public class FileUtils {
|
|||
* @throws IOException in case of an I/O error
|
||||
* @since Commons IO 1.3
|
||||
*/
|
||||
public static void writeLines(File file, Collection lines) throws IOException {
|
||||
public static void writeLines(File file, Collection<Object> lines) throws IOException {
|
||||
writeLines(file, null, lines, null);
|
||||
}
|
||||
|
||||
|
@ -1335,7 +1335,7 @@ public class FileUtils {
|
|||
* @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static void writeLines(File file, String encoding, Collection lines, String lineEnding) throws IOException {
|
||||
public static void writeLines(File file, String encoding, Collection<Object> lines, String lineEnding) throws IOException {
|
||||
OutputStream out = null;
|
||||
try {
|
||||
out = openOutputStream(file);
|
||||
|
@ -1356,7 +1356,7 @@ public class FileUtils {
|
|||
* @throws IOException in case of an I/O error
|
||||
* @since Commons IO 1.3
|
||||
*/
|
||||
public static void writeLines(File file, Collection lines, String lineEnding) throws IOException {
|
||||
public static void writeLines(File file, Collection<Object> lines, String lineEnding) throws IOException {
|
||||
writeLines(file, null, lines, lineEnding);
|
||||
}
|
||||
|
||||
|
@ -1556,7 +1556,7 @@ public class FileUtils {
|
|||
/**
|
||||
* Tests if the specified <code>File</code> is newer than the specified
|
||||
* <code>Date</code>.
|
||||
*
|
||||
*
|
||||
* @param file the <code>File</code> of which the modification date
|
||||
* must be compared, must not be <code>null</code>
|
||||
* @param date the date reference, must not be <code>null</code>
|
||||
|
@ -1623,7 +1623,7 @@ public class FileUtils {
|
|||
/**
|
||||
* Tests if the specified <code>File</code> is older than the specified
|
||||
* <code>Date</code>.
|
||||
*
|
||||
*
|
||||
* @param file the <code>File</code> of which the modification date
|
||||
* must be compared, must not be <code>null</code>
|
||||
* @param date the date reference, must not be <code>null</code>
|
||||
|
@ -1779,7 +1779,7 @@ public class FileUtils {
|
|||
throw new IOException("Destination '" + destDir + "' is not a directory");
|
||||
}
|
||||
moveDirectory(src, new File(destDir, src.getName()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1862,7 +1862,7 @@ public class FileUtils {
|
|||
* 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 destDir the destination directory
|
||||
* @param createDestDir If <code>true</code> create the destination directory,
|
||||
* otherwise if <code>false</code> throw an IOException
|
||||
* @throws NullPointerException if source or destination is <code>null</code>
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -141,7 +141,7 @@ public class FilenameUtils {
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Determines if Windows file system is in use.
|
||||
*
|
||||
*
|
||||
* @return true if the system is Windows
|
||||
*/
|
||||
static boolean isSystemWindows() {
|
||||
|
@ -151,7 +151,7 @@ public class FilenameUtils {
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Checks if the character is a separator.
|
||||
*
|
||||
*
|
||||
* @param ch the character to check
|
||||
* @return true if it is a separator character
|
||||
*/
|
||||
|
@ -269,24 +269,24 @@ public class FilenameUtils {
|
|||
if (prefix < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
char[] array = new char[size + 2]; // +1 for possible extra slash, +2 for arraycopy
|
||||
filename.getChars(0, filename.length(), array, 0);
|
||||
|
||||
|
||||
// fix separators throughout
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i] == OTHER_SEPARATOR) {
|
||||
array[i] = SYSTEM_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add extra separator on the end to simplify code below
|
||||
boolean lastIsDirectory = true;
|
||||
if (array[size - 1] != SYSTEM_SEPARATOR) {
|
||||
array[size++] = SYSTEM_SEPARATOR;
|
||||
lastIsDirectory = false;
|
||||
}
|
||||
|
||||
|
||||
// adjoining slashes
|
||||
for (int i = prefix + 1; i < size; i++) {
|
||||
if (array[i] == SYSTEM_SEPARATOR && array[i - 1] == SYSTEM_SEPARATOR) {
|
||||
|
@ -295,7 +295,7 @@ public class FilenameUtils {
|
|||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// dot slash
|
||||
for (int i = prefix + 1; i < size; i++) {
|
||||
if (array[i] == SYSTEM_SEPARATOR && array[i - 1] == '.' &&
|
||||
|
@ -308,7 +308,7 @@ public class FilenameUtils {
|
|||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// double dot slash
|
||||
outer:
|
||||
for (int i = prefix + 2; i < size; i++) {
|
||||
|
@ -336,7 +336,7 @@ public class FilenameUtils {
|
|||
i = prefix + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (size <= 0) { // should never be less than 0
|
||||
return "";
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ public class FilenameUtils {
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Converts all separators to the Unix separator of forward slash.
|
||||
*
|
||||
*
|
||||
* @param path the path to be changed, null ignored
|
||||
* @return the updated path
|
||||
*/
|
||||
|
@ -429,7 +429,7 @@ public class FilenameUtils {
|
|||
|
||||
/**
|
||||
* Converts all separators to the Windows separator of backslash.
|
||||
*
|
||||
*
|
||||
* @param path the path to be changed, null ignored
|
||||
* @return the updated path
|
||||
*/
|
||||
|
@ -442,7 +442,7 @@ public class FilenameUtils {
|
|||
|
||||
/**
|
||||
* Converts all separators to the system separator.
|
||||
*
|
||||
*
|
||||
* @param path the path to be changed, null ignored
|
||||
* @return the updated path
|
||||
*/
|
||||
|
@ -527,7 +527,7 @@ public class FilenameUtils {
|
|||
return 3;
|
||||
}
|
||||
return -1;
|
||||
|
||||
|
||||
} else if (isSeparator(ch0) && isSeparator(ch1)) {
|
||||
int posUnix = filename.indexOf(UNIX_SEPARATOR, 2);
|
||||
int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2);
|
||||
|
@ -550,7 +550,7 @@ public class FilenameUtils {
|
|||
* The position of the last forward or backslash is returned.
|
||||
* <p>
|
||||
* 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
|
||||
|
@ -572,7 +572,7 @@ public class FilenameUtils {
|
|||
* handle a file in either Unix or Windows format.
|
||||
* <p>
|
||||
* 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
|
||||
|
@ -685,7 +685,7 @@ public class FilenameUtils {
|
|||
|
||||
/**
|
||||
* 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
|
||||
|
@ -766,7 +766,7 @@ public class FilenameUtils {
|
|||
|
||||
/**
|
||||
* Does the work of getting the path.
|
||||
*
|
||||
*
|
||||
* @param filename the filename
|
||||
* @param includeSeparator true to include the end separator
|
||||
* @return the path
|
||||
|
@ -977,7 +977,7 @@ public class FilenameUtils {
|
|||
public static boolean equals(
|
||||
String filename1, String filename2,
|
||||
boolean normalized, IOCase caseSensitivity) {
|
||||
|
||||
|
||||
if (filename1 == null || filename2 == null) {
|
||||
return filename1 == filename2;
|
||||
}
|
||||
|
@ -1056,7 +1056,7 @@ public class FilenameUtils {
|
|||
* @param extensions the extensions to check for, null checks for no extension
|
||||
* @return true if the filename is one of the extensions
|
||||
*/
|
||||
public static boolean isExtension(String filename, Collection extensions) {
|
||||
public static boolean isExtension(String filename, Collection<String> extensions) {
|
||||
if (filename == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1064,7 +1064,7 @@ public class FilenameUtils {
|
|||
return (indexOfExtension(filename) == -1);
|
||||
}
|
||||
String fileExt = getExtension(filename);
|
||||
for (Iterator it = extensions.iterator(); it.hasNext();) {
|
||||
for (Iterator<String> it = extensions.iterator(); it.hasNext();) {
|
||||
if (fileExt.equals(it.next())) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1088,7 +1088,7 @@ public class FilenameUtils {
|
|||
* wildcardMatch("c.txt", "*.???") --> true
|
||||
* wildcardMatch("c.txt", "*.????") --> false
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param filename the filename to match on
|
||||
* @param wildcardMatcher the wildcard string to match against
|
||||
* @return true if the filename matches the wilcard string
|
||||
|
@ -1113,7 +1113,7 @@ public class FilenameUtils {
|
|||
* wildcardMatch("c.txt", "*.???") --> true
|
||||
* wildcardMatch("c.txt", "*.????") --> false
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param filename the filename to match on
|
||||
* @param wildcardMatcher the wildcard string to match against
|
||||
* @return true if the filename matches the wilcard string
|
||||
|
@ -1129,7 +1129,7 @@ public class FilenameUtils {
|
|||
* <p>
|
||||
* The wildcard matcher uses the characters '?' and '*' to represent a
|
||||
* single or multiple wildcard characters.
|
||||
*
|
||||
*
|
||||
* @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
|
||||
|
@ -1152,32 +1152,32 @@ public class FilenameUtils {
|
|||
boolean anyChars = false;
|
||||
int textIdx = 0;
|
||||
int wcsIdx = 0;
|
||||
Stack backtrack = new Stack();
|
||||
|
||||
Stack<int[]> backtrack = new Stack<int[]>();
|
||||
|
||||
// loop around a backtrack stack, to handle complex * matching
|
||||
do {
|
||||
if (backtrack.size() > 0) {
|
||||
int[] array = (int[]) backtrack.pop();
|
||||
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++;
|
||||
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) {
|
||||
|
@ -1198,41 +1198,41 @@ public class FilenameUtils {
|
|||
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.
|
||||
*
|
||||
*
|
||||
* @param text the text to split
|
||||
* @return the tokens, never null
|
||||
*/
|
||||
static String[] splitOnTokens(String text) {
|
||||
// used by wildcardMatch
|
||||
// package level so a unit test may run on this
|
||||
|
||||
|
||||
if (text.indexOf("?") == -1 && text.indexOf("*") == -1) {
|
||||
return new String[] { text };
|
||||
}
|
||||
|
||||
char[] array = text.toCharArray();
|
||||
ArrayList list = new ArrayList();
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i] == '?' || array[i] == '*') {
|
||||
|
@ -1254,7 +1254,7 @@ public class FilenameUtils {
|
|||
list.add(buffer.toString());
|
||||
}
|
||||
|
||||
return (String[]) list.toArray( new String[ list.size() ] );
|
||||
return list.toArray( new String[ list.size() ] );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -207,7 +207,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedInputStream</code>.
|
||||
*
|
||||
*
|
||||
* @param input the <code>InputStream</code> to read from
|
||||
* @return the requested byte array
|
||||
* @throws NullPointerException if the input is null
|
||||
|
@ -225,7 +225,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedReader</code>.
|
||||
*
|
||||
*
|
||||
* @param input the <code>Reader</code> to read from
|
||||
* @return the requested byte array
|
||||
* @throws NullPointerException if the input is null
|
||||
|
@ -246,7 +246,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedReader</code>.
|
||||
*
|
||||
*
|
||||
* @param input the <code>Reader</code> to read from
|
||||
* @param encoding the encoding to use, null means platform default
|
||||
* @return the requested byte array
|
||||
|
@ -266,7 +266,7 @@ public class IOUtils {
|
|||
* using the default character encoding of the platform.
|
||||
* <p>
|
||||
* This is the same as {@link String#getBytes()}.
|
||||
*
|
||||
*
|
||||
* @param input the <code>String</code> to convert
|
||||
* @return the requested byte array
|
||||
* @throws NullPointerException if the input is null
|
||||
|
@ -285,7 +285,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedInputStream</code>.
|
||||
*
|
||||
*
|
||||
* @param is the <code>InputStream</code> to read from
|
||||
* @return the requested character array
|
||||
* @throws NullPointerException if the input is null
|
||||
|
@ -307,7 +307,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedInputStream</code>.
|
||||
*
|
||||
*
|
||||
* @param is the <code>InputStream</code> to read from
|
||||
* @param encoding the encoding to use, null means platform default
|
||||
* @return the requested character array
|
||||
|
@ -327,7 +327,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedReader</code>.
|
||||
*
|
||||
*
|
||||
* @param input the <code>Reader</code> to read from
|
||||
* @return the requested character array
|
||||
* @throws NullPointerException if the input is null
|
||||
|
@ -348,7 +348,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedInputStream</code>.
|
||||
*
|
||||
*
|
||||
* @param input the <code>InputStream</code> to read from
|
||||
* @return the requested String
|
||||
* @throws NullPointerException if the input is null
|
||||
|
@ -369,7 +369,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedInputStream</code>.
|
||||
*
|
||||
*
|
||||
* @param input the <code>InputStream</code> to read from
|
||||
* @param encoding the encoding to use, null means platform default
|
||||
* @return the requested String
|
||||
|
@ -388,7 +388,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedReader</code>.
|
||||
*
|
||||
*
|
||||
* @param input the <code>Reader</code> to read from
|
||||
* @return the requested String
|
||||
* @throws NullPointerException if the input is null
|
||||
|
@ -403,7 +403,7 @@ public class IOUtils {
|
|||
/**
|
||||
* Get the contents of a <code>byte[]</code> 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
|
||||
|
@ -420,7 +420,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* Character encoding names can be found at
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
|
||||
*
|
||||
*
|
||||
* @param input the byte array to read from
|
||||
* @param encoding the encoding to use, null means platform default
|
||||
* @return the requested String
|
||||
|
@ -452,7 +452,7 @@ public class IOUtils {
|
|||
* @throws IOException if an I/O error occurs
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static List readLines(InputStream input) throws IOException {
|
||||
public static List<String> readLines(InputStream input) throws IOException {
|
||||
InputStreamReader reader = new InputStreamReader(input);
|
||||
return readLines(reader);
|
||||
}
|
||||
|
@ -474,7 +474,7 @@ public class IOUtils {
|
|||
* @throws IOException if an I/O error occurs
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static List readLines(InputStream input, String encoding) throws IOException {
|
||||
public static List<String> readLines(InputStream input, String encoding) throws IOException {
|
||||
if (encoding == null) {
|
||||
return readLines(input);
|
||||
} else {
|
||||
|
@ -496,9 +496,9 @@ public class IOUtils {
|
|||
* @throws IOException if an I/O error occurs
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static List readLines(Reader input) throws IOException {
|
||||
public static List<String> readLines(Reader input) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(input);
|
||||
List list = new ArrayList();
|
||||
List<String> list = new ArrayList<String>();
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
list.add(line);
|
||||
|
@ -570,7 +570,7 @@ public class IOUtils {
|
|||
* @throws IOException if an I/O error occurs, such as if the encoding is invalid
|
||||
* @since Commons IO 1.2
|
||||
*/
|
||||
public static LineIterator lineIterator(InputStream input, String encoding)
|
||||
public static LineIterator lineIterator(InputStream input, String encoding)
|
||||
throws IOException {
|
||||
Reader reader = null;
|
||||
if (encoding == null) {
|
||||
|
@ -617,7 +617,7 @@ public class IOUtils {
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Writes bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
|
||||
*
|
||||
*
|
||||
* @param data the byte array to write, do not modify during output,
|
||||
* null ignored
|
||||
* @param output the <code>OutputStream</code> to write to
|
||||
|
@ -637,7 +637,7 @@ public class IOUtils {
|
|||
* using the default character encoding of the platform.
|
||||
* <p>
|
||||
* This method uses {@link String#String(byte[])}.
|
||||
*
|
||||
*
|
||||
* @param data the byte array to write, do not modify during output,
|
||||
* null ignored
|
||||
* @param output the <code>Writer</code> to write to
|
||||
|
@ -659,7 +659,7 @@ public class IOUtils {
|
|||
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
|
||||
* <p>
|
||||
* 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 <code>Writer</code> to write to
|
||||
|
@ -684,7 +684,7 @@ public class IOUtils {
|
|||
/**
|
||||
* Writes chars from a <code>char[]</code> to a <code>Writer</code>
|
||||
* using the default character encoding of the platform.
|
||||
*
|
||||
*
|
||||
* @param data the char array to write, do not modify during output,
|
||||
* null ignored
|
||||
* @param output the <code>Writer</code> to write to
|
||||
|
@ -704,7 +704,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* 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 <code>OutputStream</code> to write to
|
||||
|
@ -728,7 +728,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* 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 <code>OutputStream</code> to write to
|
||||
|
@ -752,7 +752,7 @@ public class IOUtils {
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Writes chars from a <code>String</code> to a <code>Writer</code>.
|
||||
*
|
||||
*
|
||||
* @param data the <code>String</code> to write, null ignored
|
||||
* @param output the <code>Writer</code> to write to
|
||||
* @throws NullPointerException if output is null
|
||||
|
@ -771,7 +771,7 @@ public class IOUtils {
|
|||
* platform.
|
||||
* <p>
|
||||
* This method uses {@link String#getBytes()}.
|
||||
*
|
||||
*
|
||||
* @param data the <code>String</code> to write, null ignored
|
||||
* @param output the <code>OutputStream</code> to write to
|
||||
* @throws NullPointerException if output is null
|
||||
|
@ -793,7 +793,7 @@ public class IOUtils {
|
|||
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
|
||||
* <p>
|
||||
* This method uses {@link String#getBytes(String)}.
|
||||
*
|
||||
*
|
||||
* @param data the <code>String</code> to write, null ignored
|
||||
* @param output the <code>OutputStream</code> to write to
|
||||
* @param encoding the encoding to use, null means platform default
|
||||
|
@ -816,7 +816,7 @@ public class IOUtils {
|
|||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Writes chars from a <code>StringBuffer</code> to a <code>Writer</code>.
|
||||
*
|
||||
*
|
||||
* @param data the <code>StringBuffer</code> to write, null ignored
|
||||
* @param output the <code>Writer</code> to write to
|
||||
* @throws NullPointerException if output is null
|
||||
|
@ -836,7 +836,7 @@ public class IOUtils {
|
|||
* platform.
|
||||
* <p>
|
||||
* This method uses {@link String#getBytes()}.
|
||||
*
|
||||
*
|
||||
* @param data the <code>StringBuffer</code> to write, null ignored
|
||||
* @param output the <code>OutputStream</code> to write to
|
||||
* @throws NullPointerException if output is null
|
||||
|
@ -858,7 +858,7 @@ public class IOUtils {
|
|||
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
|
||||
* <p>
|
||||
* This method uses {@link String#getBytes(String)}.
|
||||
*
|
||||
*
|
||||
* @param data the <code>StringBuffer</code> to write, null ignored
|
||||
* @param output the <code>OutputStream</code> to write to
|
||||
* @param encoding the encoding to use, null means platform default
|
||||
|
@ -891,7 +891,7 @@ public class IOUtils {
|
|||
* @throws IOException if an I/O error occurs
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static void writeLines(Collection lines, String lineEnding,
|
||||
public static void writeLines(Collection<Object> lines, String lineEnding,
|
||||
OutputStream output) throws IOException {
|
||||
if (lines == null) {
|
||||
return;
|
||||
|
@ -899,7 +899,7 @@ public class IOUtils {
|
|||
if (lineEnding == null) {
|
||||
lineEnding = LINE_SEPARATOR;
|
||||
}
|
||||
for (Iterator it = lines.iterator(); it.hasNext(); ) {
|
||||
for (Iterator<Object> it = lines.iterator(); it.hasNext(); ) {
|
||||
Object line = it.next();
|
||||
if (line != null) {
|
||||
output.write(line.toString().getBytes());
|
||||
|
@ -924,7 +924,7 @@ public class IOUtils {
|
|||
* @throws IOException if an I/O error occurs
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static void writeLines(Collection lines, String lineEnding,
|
||||
public static void writeLines(Collection<Object> lines, String lineEnding,
|
||||
OutputStream output, String encoding) throws IOException {
|
||||
if (encoding == null) {
|
||||
writeLines(lines, lineEnding, output);
|
||||
|
@ -935,7 +935,7 @@ public class IOUtils {
|
|||
if (lineEnding == null) {
|
||||
lineEnding = LINE_SEPARATOR;
|
||||
}
|
||||
for (Iterator it = lines.iterator(); it.hasNext(); ) {
|
||||
for (Iterator<Object> it = lines.iterator(); it.hasNext(); ) {
|
||||
Object line = it.next();
|
||||
if (line != null) {
|
||||
output.write(line.toString().getBytes(encoding));
|
||||
|
@ -956,7 +956,7 @@ public class IOUtils {
|
|||
* @throws IOException if an I/O error occurs
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public static void writeLines(Collection lines, String lineEnding,
|
||||
public static void writeLines(Collection<Object> lines, String lineEnding,
|
||||
Writer writer) throws IOException {
|
||||
if (lines == null) {
|
||||
return;
|
||||
|
@ -964,7 +964,7 @@ public class IOUtils {
|
|||
if (lineEnding == null) {
|
||||
lineEnding = LINE_SEPARATOR;
|
||||
}
|
||||
for (Iterator it = lines.iterator(); it.hasNext(); ) {
|
||||
for (Iterator<Object> it = lines.iterator(); it.hasNext(); ) {
|
||||
Object line = it.next();
|
||||
if (line != null) {
|
||||
writer.write(line.toString());
|
||||
|
@ -986,7 +986,7 @@ public class IOUtils {
|
|||
* <code>-1</code> after the copy has completed since the correct
|
||||
* number of bytes cannot be returned as an int. For large streams
|
||||
* use the <code>copyLarge(InputStream, OutputStream)</code> method.
|
||||
*
|
||||
*
|
||||
* @param input the <code>InputStream</code> to read from
|
||||
* @param output the <code>OutputStream</code> to write to
|
||||
* @return the number of bytes copied
|
||||
|
@ -1009,7 +1009,7 @@ public class IOUtils {
|
|||
* <p>
|
||||
* This method buffers the input internally, so there is no need to use a
|
||||
* <code>BufferedInputStream</code>.
|
||||
*
|
||||
*
|
||||
* @param input the <code>InputStream</code> to read from
|
||||
* @param output the <code>OutputStream</code> to write to
|
||||
* @return the number of bytes copied
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -44,25 +44,23 @@ import java.util.Comparator;
|
|||
* @version $Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
|
||||
* @since Commons IO 1.4
|
||||
*/
|
||||
public class DefaultFileComparator implements Comparator, Serializable {
|
||||
public class DefaultFileComparator implements Comparator<File>, Serializable {
|
||||
|
||||
/** Singleton default comparator instance */
|
||||
public static final Comparator DEFAULT_COMPARATOR = new DefaultFileComparator();
|
||||
public static final Comparator<File> DEFAULT_COMPARATOR = new DefaultFileComparator();
|
||||
|
||||
/** Singleton reverse default comparator instance */
|
||||
public static final Comparator DEFAULT_REVERSE = new ReverseComparator(DEFAULT_COMPARATOR);
|
||||
public static final Comparator<File> DEFAULT_REVERSE = new ReverseComparator<File>(DEFAULT_COMPARATOR);
|
||||
|
||||
/**
|
||||
* Compare the two files using the {@link File#compareTo(File)} method.
|
||||
*
|
||||
*
|
||||
* @param obj1 The first file to compare
|
||||
* @param obj2 The second file to compare
|
||||
* @return the result of calling file1's
|
||||
* {@link File#compareTo(File)} with file2 as the parameter.
|
||||
*/
|
||||
public int compare(Object obj1, Object obj2) {
|
||||
File file1 = (File)obj1;
|
||||
File file2 = (File)obj2;
|
||||
public int compare(File file1, File file2) {
|
||||
return file1.compareTo(file2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -51,26 +51,26 @@ import org.apache.commons.io.IOCase;
|
|||
* @version $Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
|
||||
* @since Commons IO 1.4
|
||||
*/
|
||||
public class ExtensionFileComparator implements Comparator, Serializable {
|
||||
public class ExtensionFileComparator implements Comparator<File>, Serializable {
|
||||
|
||||
/** Case-sensitive extension comparator instance (see {@link IOCase#SENSITIVE}) */
|
||||
public static final Comparator EXTENSION_COMPARATOR = new ExtensionFileComparator();
|
||||
public static final Comparator<File> EXTENSION_COMPARATOR = new ExtensionFileComparator();
|
||||
|
||||
/** Reverse case-sensitive extension comparator instance (see {@link IOCase#SENSITIVE}) */
|
||||
public static final Comparator EXTENSION_REVERSE = new ReverseComparator(EXTENSION_COMPARATOR);
|
||||
public static final Comparator<File> EXTENSION_REVERSE = new ReverseComparator<File>(EXTENSION_COMPARATOR);
|
||||
|
||||
/** Case-insensitive extension comparator instance (see {@link IOCase#INSENSITIVE}) */
|
||||
public static final Comparator EXTENSION_INSENSITIVE_COMPARATOR = new ExtensionFileComparator(IOCase.INSENSITIVE);
|
||||
public static final Comparator<File> 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);
|
||||
public static final Comparator<File> EXTENSION_INSENSITIVE_REVERSE
|
||||
= new ReverseComparator<File>(EXTENSION_INSENSITIVE_COMPARATOR);
|
||||
|
||||
/** System sensitive extension comparator instance (see {@link IOCase#SYSTEM}) */
|
||||
public static final Comparator EXTENSION_SYSTEM_COMPARATOR = new ExtensionFileComparator(IOCase.SYSTEM);
|
||||
public static final Comparator<File> 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);
|
||||
public static final Comparator<File> EXTENSION_SYSTEM_REVERSE = new ReverseComparator<File>(EXTENSION_SYSTEM_COMPARATOR);
|
||||
|
||||
/** Whether the comparison is case sensitive. */
|
||||
private final IOCase caseSensitivity;
|
||||
|
@ -93,18 +93,16 @@ public class ExtensionFileComparator implements Comparator, Serializable {
|
|||
|
||||
/**
|
||||
* Compare the extensions of two files the specified case sensitivity.
|
||||
*
|
||||
*
|
||||
* @param obj1 The first file to compare
|
||||
* @param obj2 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(Object obj1, Object obj2) {
|
||||
File file1 = (File)obj1;
|
||||
File file2 = (File)obj2;
|
||||
public int compare(File file1, File file2) {
|
||||
String suffix1 = FilenameUtils.getExtension(file1.getName());
|
||||
String suffix2 = FilenameUtils.getExtension(file2.getName());
|
||||
return caseSensitivity.checkCompareTo(suffix1, suffix2);
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -21,7 +21,7 @@ import java.io.Serializable;
|
|||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Compare the <b>last modified date/time</b> of two files for order
|
||||
* Compare the <b>last modified date/time</b> of two files for order
|
||||
* (see {@link File#lastModified()}).
|
||||
* <p>
|
||||
* This comparator can be used to sort lists or arrays of files
|
||||
|
@ -45,28 +45,26 @@ import java.util.Comparator;
|
|||
* @version $Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
|
||||
* @since Commons IO 1.4
|
||||
*/
|
||||
public class LastModifiedFileComparator implements Comparator, Serializable {
|
||||
public class LastModifiedFileComparator implements Comparator<File>, Serializable {
|
||||
|
||||
/** Last modified comparator instance */
|
||||
public static final Comparator LASTMODIFIED_COMPARATOR = new LastModifiedFileComparator();
|
||||
public static final Comparator<File> LASTMODIFIED_COMPARATOR = new LastModifiedFileComparator();
|
||||
|
||||
/** Reverse last modified comparator instance */
|
||||
public static final Comparator LASTMODIFIED_REVERSE = new ReverseComparator(LASTMODIFIED_COMPARATOR);
|
||||
public static final Comparator<File> LASTMODIFIED_REVERSE = new ReverseComparator<File>(LASTMODIFIED_COMPARATOR);
|
||||
|
||||
/**
|
||||
* Compare the last the last modified date/time of two files.
|
||||
*
|
||||
*
|
||||
* @param obj1 The first file to compare
|
||||
* @param obj2 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(Object obj1, Object obj2) {
|
||||
File file1 = (File)obj1;
|
||||
File file2 = (File)obj2;
|
||||
public int compare(File file1, File file2) {
|
||||
long result = file1.lastModified() - file2.lastModified();
|
||||
if (result < 0) {
|
||||
return -1;
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -49,25 +49,25 @@ import org.apache.commons.io.IOCase;
|
|||
* @version $Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
|
||||
* @since Commons IO 1.4
|
||||
*/
|
||||
public class NameFileComparator implements Comparator, Serializable {
|
||||
public class NameFileComparator implements Comparator<File>, Serializable {
|
||||
|
||||
/** Case-sensitive name comparator instance (see {@link IOCase#SENSITIVE}) */
|
||||
public static final Comparator NAME_COMPARATOR = new NameFileComparator();
|
||||
public static final Comparator<File> NAME_COMPARATOR = new NameFileComparator();
|
||||
|
||||
/** Reverse case-sensitive name comparator instance (see {@link IOCase#SENSITIVE}) */
|
||||
public static final Comparator NAME_REVERSE = new ReverseComparator(NAME_COMPARATOR);
|
||||
public static final Comparator<File> NAME_REVERSE = new ReverseComparator<File>(NAME_COMPARATOR);
|
||||
|
||||
/** Case-insensitive name comparator instance (see {@link IOCase#INSENSITIVE}) */
|
||||
public static final Comparator NAME_INSENSITIVE_COMPARATOR = new NameFileComparator(IOCase.INSENSITIVE);
|
||||
public static final Comparator<File> 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);
|
||||
public static final Comparator<File> NAME_INSENSITIVE_REVERSE = new ReverseComparator<File>(NAME_INSENSITIVE_COMPARATOR);
|
||||
|
||||
/** System sensitive name comparator instance (see {@link IOCase#SYSTEM}) */
|
||||
public static final Comparator NAME_SYSTEM_COMPARATOR = new NameFileComparator(IOCase.SYSTEM);
|
||||
public static final Comparator<File> 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);
|
||||
public static final Comparator<File> NAME_SYSTEM_REVERSE = new ReverseComparator<File>(NAME_SYSTEM_COMPARATOR);
|
||||
|
||||
/** Whether the comparison is case sensitive. */
|
||||
private final IOCase caseSensitivity;
|
||||
|
@ -90,7 +90,7 @@ public class NameFileComparator implements Comparator, Serializable {
|
|||
|
||||
/**
|
||||
* Compare the names of two files with the specified case sensitivity.
|
||||
*
|
||||
*
|
||||
* @param obj1 The first file to compare
|
||||
* @param obj2 The second file to compare
|
||||
* @return a negative value if the first file's name
|
||||
|
@ -98,9 +98,7 @@ public class NameFileComparator implements Comparator, Serializable {
|
|||
* same and a positive value if the first files name
|
||||
* is greater than the second file.
|
||||
*/
|
||||
public int compare(Object obj1, Object obj2) {
|
||||
File file1 = (File)obj1;
|
||||
File file2 = (File)obj2;
|
||||
public int compare(File file1, File file2) {
|
||||
return caseSensitivity.checkCompareTo(file1.getName(), file2.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -49,25 +49,25 @@ import org.apache.commons.io.IOCase;
|
|||
* @version $Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
|
||||
* @since Commons IO 1.4
|
||||
*/
|
||||
public class PathFileComparator implements Comparator, Serializable {
|
||||
public class PathFileComparator implements Comparator<File>, Serializable {
|
||||
|
||||
/** Case-sensitive path comparator instance (see {@link IOCase#SENSITIVE}) */
|
||||
public static final Comparator PATH_COMPARATOR = new PathFileComparator();
|
||||
public static final Comparator<File> PATH_COMPARATOR = new PathFileComparator();
|
||||
|
||||
/** Reverse case-sensitive path comparator instance (see {@link IOCase#SENSITIVE}) */
|
||||
public static final Comparator PATH_REVERSE = new ReverseComparator(PATH_COMPARATOR);
|
||||
public static final Comparator<File> PATH_REVERSE = new ReverseComparator<File>(PATH_COMPARATOR);
|
||||
|
||||
/** Case-insensitive path comparator instance (see {@link IOCase#INSENSITIVE}) */
|
||||
public static final Comparator PATH_INSENSITIVE_COMPARATOR = new PathFileComparator(IOCase.INSENSITIVE);
|
||||
public static final Comparator<File> 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);
|
||||
public static final Comparator<File> PATH_INSENSITIVE_REVERSE = new ReverseComparator<File>(PATH_INSENSITIVE_COMPARATOR);
|
||||
|
||||
/** System sensitive path comparator instance (see {@link IOCase#SYSTEM}) */
|
||||
public static final Comparator PATH_SYSTEM_COMPARATOR = new PathFileComparator(IOCase.SYSTEM);
|
||||
public static final Comparator<File> 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);
|
||||
public static final Comparator<File> PATH_SYSTEM_REVERSE = new ReverseComparator<File>(PATH_SYSTEM_COMPARATOR);
|
||||
|
||||
/** Whether the comparison is case sensitive. */
|
||||
private final IOCase caseSensitivity;
|
||||
|
@ -90,18 +90,16 @@ public class PathFileComparator implements Comparator, Serializable {
|
|||
|
||||
/**
|
||||
* Compare the paths of two files the specified case sensitivity.
|
||||
*
|
||||
*
|
||||
* @param obj1 The first file to compare
|
||||
* @param obj2 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(Object obj1, Object obj2) {
|
||||
File file1 = (File)obj1;
|
||||
File file2 = (File)obj2;
|
||||
public int compare(File file1, File file2) {
|
||||
return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -26,16 +26,16 @@ import java.util.Comparator;
|
|||
* @version $Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
|
||||
* @since Commons IO 1.4
|
||||
*/
|
||||
class ReverseComparator implements Comparator, Serializable {
|
||||
class ReverseComparator<T> implements Comparator<T>, Serializable {
|
||||
|
||||
private final Comparator delegate;
|
||||
private final Comparator<T> delegate;
|
||||
|
||||
/**
|
||||
* Construct an instance with the sepecified delegate {@link Comparator}.
|
||||
*
|
||||
* @param delegate The comparator to delegate to
|
||||
*/
|
||||
public ReverseComparator(Comparator delegate) {
|
||||
public ReverseComparator(Comparator<T> delegate) {
|
||||
if (delegate == null) {
|
||||
throw new IllegalArgumentException("Delegate comparator is missing");
|
||||
}
|
||||
|
@ -44,13 +44,13 @@ class ReverseComparator implements Comparator, Serializable {
|
|||
|
||||
/**
|
||||
* Compare using the delegate Comparator, but reversing the result.
|
||||
*
|
||||
*
|
||||
* @param obj1 The first object to compare
|
||||
* @param obj2 The second object 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(Object obj1, Object obj2) {
|
||||
public int compare(T obj1, T obj2) {
|
||||
return delegate.compare(obj2, obj1); // parameters switched round
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -49,25 +49,25 @@ import org.apache.commons.io.FileUtils;
|
|||
* @version $Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
|
||||
* @since Commons IO 1.4
|
||||
*/
|
||||
public class SizeFileComparator implements Comparator, Serializable {
|
||||
public class SizeFileComparator implements Comparator<File>, Serializable {
|
||||
|
||||
/** Size comparator instance - directories are treated as zero size */
|
||||
public static final Comparator SIZE_COMPARATOR = new SizeFileComparator();
|
||||
public static final Comparator<File> SIZE_COMPARATOR = new SizeFileComparator();
|
||||
|
||||
/** Reverse size comparator instance - directories are treated as zero size */
|
||||
public static final Comparator SIZE_REVERSE = new ReverseComparator(SIZE_COMPARATOR);
|
||||
public static final Comparator<File> SIZE_REVERSE = new ReverseComparator<File>(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);
|
||||
public static final Comparator<File> 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);
|
||||
public static final Comparator<File> SIZE_SUMDIR_REVERSE = new ReverseComparator<File>(SIZE_SUMDIR_COMPARATOR);
|
||||
|
||||
/** Whether the sum of the directory's contents should be calculated. */
|
||||
private final boolean sumDirectoryContents;
|
||||
|
@ -96,18 +96,16 @@ public class SizeFileComparator implements Comparator, Serializable {
|
|||
|
||||
/**
|
||||
* Compare the length of two files.
|
||||
*
|
||||
*
|
||||
* @param obj1 The first file to compare
|
||||
* @param obj2 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(Object obj1, Object obj2) {
|
||||
File file1 = (File)obj1;
|
||||
File file2 = (File)obj2;
|
||||
public int compare(File file1, File file2) {
|
||||
long size1 = 0;
|
||||
if (file1.isDirectory()) {
|
||||
size1 = sumDirectoryContents && file1.exists() ? FileUtils.sizeOfDirectory(file1) : 0;
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -40,7 +40,7 @@ public class AndFileFilter
|
|||
implements ConditionalFileFilter, Serializable {
|
||||
|
||||
/** The list of file filters. */
|
||||
private List fileFilters;
|
||||
private List<IOFileFilter> fileFilters;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of <code>AndFileFilter</code>.
|
||||
|
@ -48,7 +48,7 @@ public class AndFileFilter
|
|||
* @since Commons IO 1.1
|
||||
*/
|
||||
public AndFileFilter() {
|
||||
this.fileFilters = new ArrayList();
|
||||
this.fileFilters = new ArrayList<IOFileFilter>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,11 +58,11 @@ public class AndFileFilter
|
|||
* @param fileFilters a List of IOFileFilter instances, copied, null ignored
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public AndFileFilter(final List fileFilters) {
|
||||
public AndFileFilter(final List<IOFileFilter> fileFilters) {
|
||||
if (fileFilters == null) {
|
||||
this.fileFilters = new ArrayList();
|
||||
this.fileFilters = new ArrayList<IOFileFilter>();
|
||||
} else {
|
||||
this.fileFilters = new ArrayList(fileFilters);
|
||||
this.fileFilters = new ArrayList<IOFileFilter>(fileFilters);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class AndFileFilter
|
|||
if (filter1 == null || filter2 == null) {
|
||||
throw new IllegalArgumentException("The filters must not be null");
|
||||
}
|
||||
this.fileFilters = new ArrayList();
|
||||
this.fileFilters = new ArrayList<IOFileFilter>();
|
||||
addFileFilter(filter1);
|
||||
addFileFilter(filter2);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class AndFileFilter
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List getFileFilters() {
|
||||
public List<IOFileFilter> getFileFilters() {
|
||||
return Collections.unmodifiableList(this.fileFilters);
|
||||
}
|
||||
|
||||
|
@ -106,19 +106,21 @@ public class AndFileFilter
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setFileFilters(final List fileFilters) {
|
||||
this.fileFilters = new ArrayList(fileFilters);
|
||||
@Override
|
||||
public void setFileFilters(final List<IOFileFilter> fileFilters) {
|
||||
this.fileFilters = new ArrayList<IOFileFilter>(fileFilters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(final File file) {
|
||||
if (this.fileFilters.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
for (Iterator iter = this.fileFilters.iterator(); iter.hasNext();) {
|
||||
IOFileFilter fileFilter = (IOFileFilter) iter.next();
|
||||
for (Iterator<IOFileFilter> iter = this.fileFilters.iterator(); iter.hasNext();) {
|
||||
IOFileFilter fileFilter = iter.next();
|
||||
if (!fileFilter.accept(file)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -129,12 +131,13 @@ public class AndFileFilter
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(final File file, final String name) {
|
||||
if (this.fileFilters.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
for (Iterator iter = this.fileFilters.iterator(); iter.hasNext();) {
|
||||
IOFileFilter fileFilter = (IOFileFilter) iter.next();
|
||||
for (Iterator<IOFileFilter> iter = this.fileFilters.iterator(); iter.hasNext();) {
|
||||
IOFileFilter fileFilter = iter.next();
|
||||
if (!fileFilter.accept(file, name)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -147,6 +150,7 @@ public class AndFileFilter
|
|||
*
|
||||
* @return a String representaion
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(super.toString());
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -43,7 +43,7 @@ public interface ConditionalFileFilter {
|
|||
* @return the file filter list
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public List getFileFilters();
|
||||
public List<IOFileFilter> getFileFilters();
|
||||
|
||||
/**
|
||||
* Removes the specified file filter.
|
||||
|
@ -62,6 +62,6 @@ public interface ConditionalFileFilter {
|
|||
* @param fileFilters the list of filters
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public void setFileFilters(List fileFilters);
|
||||
public void setFileFilters(List<IOFileFilter> fileFilters);
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -25,7 +25,7 @@ import org.apache.commons.io.IOCase;
|
|||
/**
|
||||
* Filters filenames for a certain name.
|
||||
* <p>
|
||||
* For example, to print all files and directories in the
|
||||
* For example, to print all files and directories in the
|
||||
* current directory whose name is <code>Test</code>:
|
||||
*
|
||||
* <pre>
|
||||
|
@ -38,14 +38,14 @@ import org.apache.commons.io.IOCase;
|
|||
*
|
||||
* @since Commons IO 1.0
|
||||
* @version $Revision: 606381 $ $Date: 2007-12-22 02:03:16 +0000 (Sat, 22 Dec 2007) $
|
||||
*
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
* @author Federico Barbieri
|
||||
* @author Serge Knystautas
|
||||
* @author Peter Donald
|
||||
*/
|
||||
public class NameFileFilter extends AbstractFileFilter implements Serializable {
|
||||
|
||||
|
||||
/** The filenames to search for */
|
||||
private final String[] names;
|
||||
/** Whether the comparison is case sensitive. */
|
||||
|
@ -53,7 +53,7 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable {
|
|||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -81,7 +81,7 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable {
|
|||
* <p>
|
||||
* 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
|
||||
*/
|
||||
|
@ -94,7 +94,7 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable {
|
|||
* <p>
|
||||
* 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
|
||||
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
|
||||
* @throws IllegalArgumentException if the names array is null
|
||||
|
@ -109,38 +109,39 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable {
|
|||
|
||||
/**
|
||||
* 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(List names) {
|
||||
public NameFileFilter(List<String> 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(List names, IOCase caseSensitivity) {
|
||||
public NameFileFilter(List<String> names, IOCase caseSensitivity) {
|
||||
if (names == null) {
|
||||
throw new IllegalArgumentException("The list of names must not be null");
|
||||
}
|
||||
this.names = (String[]) names.toArray(new String[names.size()]);
|
||||
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(File file) {
|
||||
String name = file.getName();
|
||||
for (int i = 0; i < this.names.length; i++) {
|
||||
|
@ -153,11 +154,12 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable {
|
|||
|
||||
/**
|
||||
* Checks to see if the filename matches.
|
||||
*
|
||||
*
|
||||
* @param file the File directory
|
||||
* @param name the filename
|
||||
* @return true if the filename matches
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
if (caseSensitivity.checkEquals(name, names[i])) {
|
||||
|
@ -172,6 +174,7 @@ public class NameFileFilter extends AbstractFileFilter implements Serializable {
|
|||
*
|
||||
* @return a String representaion
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(super.toString());
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -40,7 +40,7 @@ public class OrFileFilter
|
|||
implements ConditionalFileFilter, Serializable {
|
||||
|
||||
/** The list of file filters. */
|
||||
private List fileFilters;
|
||||
private List<IOFileFilter> fileFilters;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of <code>OrFileFilter</code>.
|
||||
|
@ -48,7 +48,7 @@ public class OrFileFilter
|
|||
* @since Commons IO 1.1
|
||||
*/
|
||||
public OrFileFilter() {
|
||||
this.fileFilters = new ArrayList();
|
||||
this.fileFilters = new ArrayList<IOFileFilter>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,17 +58,17 @@ public class OrFileFilter
|
|||
* @param fileFilters the file filters for this filter, copied, null ignored
|
||||
* @since Commons IO 1.1
|
||||
*/
|
||||
public OrFileFilter(final List fileFilters) {
|
||||
public OrFileFilter(final List<IOFileFilter> fileFilters) {
|
||||
if (fileFilters == null) {
|
||||
this.fileFilters = new ArrayList();
|
||||
this.fileFilters = new ArrayList<IOFileFilter>();
|
||||
} else {
|
||||
this.fileFilters = new ArrayList(fileFilters);
|
||||
this.fileFilters = new ArrayList<IOFileFilter>(fileFilters);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new file filter that ORs the result of two other filters.
|
||||
*
|
||||
*
|
||||
* @param filter1 the first filter, must not be null
|
||||
* @param filter2 the second filter, must not be null
|
||||
* @throws IllegalArgumentException if either filter is null
|
||||
|
@ -77,7 +77,7 @@ public class OrFileFilter
|
|||
if (filter1 == null || filter2 == null) {
|
||||
throw new IllegalArgumentException("The filters must not be null");
|
||||
}
|
||||
this.fileFilters = new ArrayList();
|
||||
this.fileFilters = new ArrayList<IOFileFilter>();
|
||||
addFileFilter(filter1);
|
||||
addFileFilter(filter2);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class OrFileFilter
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public List getFileFilters() {
|
||||
public List<IOFileFilter> getFileFilters() {
|
||||
return Collections.unmodifiableList(this.fileFilters);
|
||||
}
|
||||
|
||||
|
@ -106,16 +106,17 @@ public class OrFileFilter
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setFileFilters(final List fileFilters) {
|
||||
public void setFileFilters(final List<IOFileFilter> fileFilters) {
|
||||
this.fileFilters = fileFilters;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(final File file) {
|
||||
for (Iterator iter = this.fileFilters.iterator(); iter.hasNext();) {
|
||||
IOFileFilter fileFilter = (IOFileFilter) iter.next();
|
||||
for (Iterator<IOFileFilter> iter = this.fileFilters.iterator(); iter.hasNext();) {
|
||||
IOFileFilter fileFilter = iter.next();
|
||||
if (fileFilter.accept(file)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -126,9 +127,10 @@ public class OrFileFilter
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(final File file, final String name) {
|
||||
for (Iterator iter = this.fileFilters.iterator(); iter.hasNext();) {
|
||||
IOFileFilter fileFilter = (IOFileFilter) iter.next();
|
||||
for (Iterator<IOFileFilter> iter = this.fileFilters.iterator(); iter.hasNext();) {
|
||||
IOFileFilter fileFilter = iter.next();
|
||||
if (fileFilter.accept(file, name)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -141,6 +143,7 @@ public class OrFileFilter
|
|||
*
|
||||
* @return a String representaion
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(super.toString());
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -25,7 +25,7 @@ import org.apache.commons.io.IOCase;
|
|||
/**
|
||||
* Filters filenames for a certain prefix.
|
||||
* <p>
|
||||
* For example, to print all files and directories in the
|
||||
* For example, to print all files and directories in the
|
||||
* current directory whose name starts with <code>Test</code>:
|
||||
*
|
||||
* <pre>
|
||||
|
@ -38,14 +38,14 @@ import org.apache.commons.io.IOCase;
|
|||
*
|
||||
* @since Commons IO 1.0
|
||||
* @version $Revision: 606381 $ $Date: 2007-12-22 02:03:16 +0000 (Sat, 22 Dec 2007) $
|
||||
*
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
* @author Federico Barbieri
|
||||
* @author Serge Knystautas
|
||||
* @author Peter Donald
|
||||
*/
|
||||
public class PrefixFileFilter extends AbstractFileFilter implements Serializable {
|
||||
|
||||
|
||||
/** The filename prefixes to search for */
|
||||
private final String[] prefixes;
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
|
|||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -63,9 +63,9 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a new Prefix file filter for a single prefix
|
||||
* 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
|
||||
|
@ -84,7 +84,7 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
|
|||
* <p>
|
||||
* 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
|
||||
*/
|
||||
|
@ -98,7 +98,7 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
|
|||
* <p>
|
||||
* 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
|
||||
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
|
||||
* @throws IllegalArgumentException if the prefix is null
|
||||
|
@ -114,39 +114,40 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
|
|||
|
||||
/**
|
||||
* 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(List prefixes) {
|
||||
public PrefixFileFilter(List<String> 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 Commons IO 1.4
|
||||
*/
|
||||
public PrefixFileFilter(List prefixes, IOCase caseSensitivity) {
|
||||
public PrefixFileFilter(List<String> prefixes, IOCase caseSensitivity) {
|
||||
if (prefixes == null) {
|
||||
throw new IllegalArgumentException("The list of prefixes must not be null");
|
||||
}
|
||||
this.prefixes = (String[]) prefixes.toArray(new String[prefixes.size()]);
|
||||
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(File file) {
|
||||
String name = file.getName();
|
||||
for (int i = 0; i < this.prefixes.length; i++) {
|
||||
|
@ -156,14 +157,15 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
|
|||
}
|
||||
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(File file, String name) {
|
||||
for (int i = 0; i < prefixes.length; i++) {
|
||||
if (caseSensitivity.checkStartsWith(name, prefixes[i])) {
|
||||
|
@ -178,6 +180,7 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
|
|||
*
|
||||
* @return a String representaion
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(super.toString());
|
||||
|
@ -193,5 +196,5 @@ public class PrefixFileFilter extends AbstractFileFilter implements Serializable
|
|||
buffer.append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -26,7 +26,7 @@ import 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.
|
||||
* <p>
|
||||
* For example, to retrieve and print all <code>*.java</code> files
|
||||
* For example, to retrieve and print all <code>*.java</code> files
|
||||
* in the current directory:
|
||||
*
|
||||
* <pre>
|
||||
|
@ -39,14 +39,14 @@ import org.apache.commons.io.IOCase;
|
|||
*
|
||||
* @since Commons IO 1.0
|
||||
* @version $Revision: 606381 $ $Date: 2007-12-22 02:03:16 +0000 (Sat, 22 Dec 2007) $
|
||||
*
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
* @author Federico Barbieri
|
||||
* @author Serge Knystautas
|
||||
* @author Peter Donald
|
||||
*/
|
||||
public class SuffixFileFilter extends AbstractFileFilter implements Serializable {
|
||||
|
||||
|
||||
/** The filename suffixes to search for */
|
||||
private final String[] suffixes;
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
|
|||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -85,7 +85,7 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
|
|||
* <p>
|
||||
* 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
|
||||
*/
|
||||
|
@ -99,7 +99,7 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
|
|||
* <p>
|
||||
* 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
|
||||
* @param caseSensitivity how to handle case sensitivity, null means case-sensitive
|
||||
* @throws IllegalArgumentException if the suffix array is null
|
||||
|
@ -115,39 +115,40 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
|
|||
|
||||
/**
|
||||
* 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(List suffixes) {
|
||||
public SuffixFileFilter(List<String> 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 Commons IO 1.4
|
||||
*/
|
||||
public SuffixFileFilter(List suffixes, IOCase caseSensitivity) {
|
||||
public SuffixFileFilter(List<String> suffixes, IOCase caseSensitivity) {
|
||||
if (suffixes == null) {
|
||||
throw new IllegalArgumentException("The list of suffixes must not be null");
|
||||
}
|
||||
this.suffixes = (String[]) suffixes.toArray(new String[suffixes.size()]);
|
||||
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(File file) {
|
||||
String name = file.getName();
|
||||
for (int i = 0; i < this.suffixes.length; i++) {
|
||||
|
@ -157,14 +158,15 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
|
|||
}
|
||||
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(File file, String name) {
|
||||
for (int i = 0; i < this.suffixes.length; i++) {
|
||||
if (caseSensitivity.checkEndsWith(name, suffixes[i])) {
|
||||
|
@ -179,6 +181,7 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
|
|||
*
|
||||
* @return a String representaion
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(super.toString());
|
||||
|
@ -194,5 +197,5 @@ public class SuffixFileFilter extends AbstractFileFilter implements Serializable
|
|||
buffer.append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -119,7 +119,7 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab
|
|||
* @throws IllegalArgumentException if the pattern list is null
|
||||
* @throws ClassCastException if the list does not contain Strings
|
||||
*/
|
||||
public WildcardFileFilter(List wildcards) {
|
||||
public WildcardFileFilter(List<String> wildcards) {
|
||||
this(wildcards, null);
|
||||
}
|
||||
|
||||
|
@ -131,11 +131,11 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab
|
|||
* @throws IllegalArgumentException if the pattern list is null
|
||||
* @throws ClassCastException if the list does not contain Strings
|
||||
*/
|
||||
public WildcardFileFilter(List wildcards, IOCase caseSensitivity) {
|
||||
public WildcardFileFilter(List<String> wildcards, IOCase caseSensitivity) {
|
||||
if (wildcards == null) {
|
||||
throw new IllegalArgumentException("The wildcard list must not be null");
|
||||
}
|
||||
this.wildcards = (String[]) wildcards.toArray(new String[wildcards.size()]);
|
||||
this.wildcards = wildcards.toArray(new String[wildcards.size()]);
|
||||
this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity);
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,7 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab
|
|||
* @param name the filename
|
||||
* @return true if the filename matches one of the wildcards
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
for (int i = 0; i < wildcards.length; i++) {
|
||||
if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
|
||||
|
@ -162,6 +163,7 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab
|
|||
* @param file the file to check
|
||||
* @return true if the filename matches one of the wildcards
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
String name = file.getName();
|
||||
for (int i = 0; i < wildcards.length; i++) {
|
||||
|
@ -177,6 +179,7 @@ public class WildcardFileFilter extends AbstractFileFilter implements Serializab
|
|||
*
|
||||
* @return a String representaion
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(super.toString());
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package 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.
|
||||
* <p>
|
||||
* This filter selects files, but not directories, based on one or more wildcards
|
||||
* and using case-sensitive comparison.
|
||||
* <p>
|
||||
* 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} for more information.
|
||||
* <p>
|
||||
* For example:
|
||||
* <pre>
|
||||
* 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]);
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Jason Anderson
|
||||
* @version $Revision: 606381 $ $Date: 2007-12-22 02:03:16 +0000 (Sat, 22 Dec 2007) $
|
||||
* @since Commons IO 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.
|
||||
*/
|
||||
public class WildcardFilter extends AbstractFileFilter implements Serializable {
|
||||
|
||||
/** 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(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(String[] wildcards) {
|
||||
if (wildcards == null) {
|
||||
throw new IllegalArgumentException("The wildcard array must not be null");
|
||||
}
|
||||
this.wildcards = wildcards;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(List wildcards) {
|
||||
if (wildcards == null) {
|
||||
throw new IllegalArgumentException("The wildcard list must not be null");
|
||||
}
|
||||
this.wildcards = (String[]) 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
|
||||
*/
|
||||
public boolean accept(File dir, String name) {
|
||||
if (dir != null && new File(dir, name).isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < wildcards.length; i++) {
|
||||
if (FilenameUtils.wildcardMatch(name, wildcards[i])) {
|
||||
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
|
||||
*/
|
||||
public boolean accept(File file) {
|
||||
if (file.isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < wildcards.length; i++) {
|
||||
if (FilenameUtils.wildcardMatch(file.getName(), wildcards[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -29,7 +29,7 @@ import java.io.InputStream;
|
|||
public class DemuxInputStream
|
||||
extends InputStream
|
||||
{
|
||||
private InheritableThreadLocal m_streams = new InheritableThreadLocal();
|
||||
private InheritableThreadLocal<InputStream> m_streams = new InheritableThreadLocal<InputStream>();
|
||||
|
||||
/**
|
||||
* Bind the specified stream to the current thread.
|
||||
|
@ -49,6 +49,7 @@ public class DemuxInputStream
|
|||
*
|
||||
* @throws IOException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
throws IOException
|
||||
{
|
||||
|
@ -65,6 +66,7 @@ public class DemuxInputStream
|
|||
* @return the byte read from stream
|
||||
* @throws IOException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public int read()
|
||||
throws IOException
|
||||
{
|
||||
|
@ -86,6 +88,6 @@ public class DemuxInputStream
|
|||
*/
|
||||
private InputStream getStream()
|
||||
{
|
||||
return (InputStream)m_streams.get();
|
||||
return m_streams.get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.io.output;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -24,10 +24,10 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class implements an output stream in which the data is
|
||||
* written into a byte array. The buffer automatically grows as data
|
||||
* 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.
|
||||
* <p>
|
||||
* <p>
|
||||
* The data can be retrieved using <code>toByteArray()</code> and
|
||||
* <code>toString()</code>.
|
||||
* <p>
|
||||
|
@ -43,7 +43,7 @@ import java.util.List;
|
|||
* 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.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
|
||||
* @author Holger Hoffstatte
|
||||
* @version $Id: ByteArrayOutputStream.java 610010 2008-01-08 14:50:59Z niallp $
|
||||
|
@ -54,7 +54,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
|
||||
/** The list of buffers, which grows and never reduces. */
|
||||
private List buffers = new ArrayList();
|
||||
private List<byte[]> buffers = new ArrayList<byte[]>();
|
||||
/** The index of the current buffer. */
|
||||
private int currentBufferIndex;
|
||||
/** The total count of bytes in all the filled buffers. */
|
||||
|
@ -65,16 +65,16 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
private int count;
|
||||
|
||||
/**
|
||||
* Creates a new byte array output stream. The buffer capacity is
|
||||
* initially 1024 bytes, though its size increases if necessary.
|
||||
* 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.
|
||||
* 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
|
||||
|
@ -88,14 +88,14 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the appropriate <code>byte[]</code> buffer
|
||||
* Return the appropriate <code>byte[]</code> buffer
|
||||
* specified by index.
|
||||
*
|
||||
* @param index the index of the buffer required
|
||||
* @return the buffer
|
||||
*/
|
||||
private byte[] getBuffer(int index) {
|
||||
return (byte[]) buffers.get(index);
|
||||
return buffers.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,7 +108,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
if (currentBufferIndex < buffers.size() - 1) {
|
||||
//Recycling old buffer
|
||||
filledBufferSum += currentBuffer.length;
|
||||
|
||||
|
||||
currentBufferIndex++;
|
||||
currentBuffer = getBuffer(currentBufferIndex);
|
||||
} else {
|
||||
|
@ -119,11 +119,11 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
filledBufferSum = 0;
|
||||
} else {
|
||||
newBufferSize = Math.max(
|
||||
currentBuffer.length << 1,
|
||||
currentBuffer.length << 1,
|
||||
newcount - filledBufferSum);
|
||||
filledBufferSum += currentBuffer.length;
|
||||
}
|
||||
|
||||
|
||||
currentBufferIndex++;
|
||||
currentBuffer = new byte[newBufferSize];
|
||||
buffers.add(currentBuffer);
|
||||
|
@ -136,11 +136,12 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
* @param off The start offset
|
||||
* @param len The number of bytes to write
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) {
|
||||
if ((off < 0)
|
||||
|| (off > b.length)
|
||||
|| (len < 0)
|
||||
|| ((off + len) > b.length)
|
||||
if ((off < 0)
|
||||
|| (off > b.length)
|
||||
|| (len < 0)
|
||||
|| ((off + len) > b.length)
|
||||
|| ((off + len) < 0)) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
} else if (len == 0) {
|
||||
|
@ -167,6 +168,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
* Write a byte to byte array.
|
||||
* @param b the byte to write
|
||||
*/
|
||||
@Override
|
||||
public synchronized void write(int b) {
|
||||
int inBufferPos = count - filledBufferSum;
|
||||
if (inBufferPos == currentBuffer.length) {
|
||||
|
@ -221,6 +223,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
* @throws IOException never (this method should not declare this exception
|
||||
* but it has to now due to backwards compatability)
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
//nop
|
||||
}
|
||||
|
@ -266,7 +269,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
public synchronized byte[] toByteArray() {
|
||||
int remaining = count;
|
||||
if (remaining == 0) {
|
||||
return EMPTY_BYTE_ARRAY;
|
||||
return EMPTY_BYTE_ARRAY;
|
||||
}
|
||||
byte newbuf[] = new byte[remaining];
|
||||
int pos = 0;
|
||||
|
@ -288,6 +291,7 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
* @return the contents of the byte array as a String
|
||||
* @see java.io.ByteArrayOutputStream#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return new String(toByteArray());
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -29,7 +29,7 @@ import java.io.OutputStream;
|
|||
public class DemuxOutputStream
|
||||
extends OutputStream
|
||||
{
|
||||
private InheritableThreadLocal m_streams = new InheritableThreadLocal();
|
||||
private InheritableThreadLocal<OutputStream> m_streams = new InheritableThreadLocal<OutputStream>();
|
||||
|
||||
/**
|
||||
* Bind the specified stream to the current thread.
|
||||
|
@ -49,6 +49,7 @@ public class DemuxOutputStream
|
|||
*
|
||||
* @throws IOException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
throws IOException
|
||||
{
|
||||
|
@ -64,6 +65,7 @@ public class DemuxOutputStream
|
|||
*
|
||||
* @throws IOException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void flush()
|
||||
throws IOException
|
||||
{
|
||||
|
@ -80,6 +82,7 @@ public class DemuxOutputStream
|
|||
* @param ch the byte to write to stream
|
||||
* @throws IOException if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public void write( int ch )
|
||||
throws IOException
|
||||
{
|
||||
|
@ -97,6 +100,6 @@ public class DemuxOutputStream
|
|||
*/
|
||||
private OutputStream getStream()
|
||||
{
|
||||
return (OutputStream)m_streams.get();
|
||||
return m_streams.get();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue