commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r736890 - in /commons/proper/io/trunk/src/java/org/apache/commons/io: ./ comparator/ filefilter/ input/ monitor/ output/
Date Fri, 23 Jan 2009 02:02:23 GMT
Author: niallp
Date: Thu Jan 22 18:02:22 2009
New Revision: 736890

URL: http://svn.apache.org/viewvc?rev=736890&view=rev
Log:
IO-191 - Possible improvements using static analysis - patch from Peter Lawrey

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/AbstractFileComparator.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/CompositeFileComparator.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AndFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/OrFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/input/DemuxInputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullInputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullReader.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemEntry.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemMonitor.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemObserver.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/output/ByteArrayOutputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/output/DeferredFileOutputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/output/DemuxOutputStream.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/output/ThresholdingOutputStream.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/DirectoryWalker.java Thu Jan 22
18:02:22 2009
@@ -359,8 +359,7 @@
                 if (childFiles == null) {
                     handleRestricted(directory, childDepth, results);
                 } else {
-                    for (int i = 0; i < childFiles.length; i++) {
-                        File childFile = childFiles[i];
+                    for (File childFile : childFiles) {
                         if (childFile.isDirectory()) {
                             walk(childFile, childDepth, results);
                         } else {
@@ -585,9 +584,9 @@
         private static final long serialVersionUID = 1347339620135041008L;
         
         /** The file being processed when the exception was thrown. */
-        private File file;
+        private final File file;
         /** The file depth when the exception was thrown. */
-        private int depth = -1;
+        private final int depth;
 
         /**
          * Constructs a <code>CancelException</code> with

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java Thu Jan 22 18:02:22
2009
@@ -258,11 +258,11 @@
             IOFileFilter filter) {
         File[] found = directory.listFiles((FileFilter) filter);
         if (found != null) {
-            for (int i = 0; i < found.length; i++) {
-                if (found[i].isDirectory()) {
-                    innerListFiles(files, found[i], filter);
+            for (File file : found) {
+                if (file.isDirectory()) {
+                    innerListFiles(files, file, filter);
                 } else {
-                    files.add(found[i]);
+                    files.add(file);
                 }
             }
         }
@@ -899,8 +899,8 @@
             File[] srcFiles = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
             if (srcFiles != null && srcFiles.length > 0) {
                 exclusionList = new ArrayList<String>(srcFiles.length);
-                for (int i = 0; i < srcFiles.length; i++) {
-                    File copiedFile = new File(destDir, srcFiles[i].getName());
+                for (File srcFile : srcFiles) {
+                    File copiedFile = new File(destDir, srcFile.getName());
                     exclusionList.add(copiedFile.getCanonicalPath());
                 }
             }
@@ -941,13 +941,13 @@
         if (files == null) {  // null if security restricted
             throw new IOException("Failed to list contents of " + srcDir);
         }
-        for (int i = 0; i < files.length; i++) {
-            File copiedFile = new File(destDir, files[i].getName());
-            if (exclusionList == null || !exclusionList.contains(files[i].getCanonicalPath()))
{
-                if (files[i].isDirectory()) {
-                    doCopyDirectory(files[i], copiedFile, filter, preserveFileDate, exclusionList);
+        for (File file : files) {
+            File copiedFile = new File(destDir, file.getName());
+            if (exclusionList == null || !exclusionList.contains(file.getCanonicalPath()))
{
+                if (file.isDirectory()) {
+                    doCopyDirectory(file, copiedFile, filter, preserveFileDate, exclusionList);
                 } else {
-                    doCopyFile(files[i], copiedFile, preserveFileDate);
+                    doCopyFile(file, copiedFile, preserveFileDate);
                 }
             }
         }
@@ -1029,12 +1029,12 @@
             if (file.isDirectory()) {
                 cleanDirectory(file);
             }
-        } catch (Exception e) {
+        } catch (Exception ignored) {
         }
 
         try {
             return file.delete();
-        } catch (Exception e) {
+        } catch (Exception ignored) {
             return false;
         }
     }
@@ -1062,8 +1062,7 @@
         }
 
         IOException exception = null;
-        for (int i = 0; i < files.length; i++) {
-            File file = files[i];
+        for (File file : files) {
             try {
                 forceDelete(file);
             } catch (IOException ioe) {
@@ -1503,8 +1502,7 @@
         }
 
         IOException exception = null;
-        for (int i = 0; i < files.length; i++) {
-            File file = files[i];
+        for (File file : files) {
             try {
                 forceDeleteOnExit(file);
             } catch (IOException ioe) {
@@ -1570,9 +1568,7 @@
         if (files == null) {  // null if security restricted
             return 0L;
         }
-        for (int i = 0; i < files.length; i++) {
-            File file = files[i];
-
+        for (File file : files) {
             if (file.isDirectory()) {
                 size += sizeOfDirectory(file);
             } else {

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java Thu Jan 22 18:02:22
2009
@@ -19,7 +19,6 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.Stack;
 
 /**
@@ -102,7 +101,7 @@
      * The extension separator String.
      * @since Commons IO 1.4
      */
-    public static final String EXTENSION_SEPARATOR_STR = (new Character(EXTENSION_SEPARATOR)).toString();
+    public static final String EXTENSION_SEPARATOR_STR = Character.toString(EXTENSION_SEPARATOR);
 
     /**
      * The Unix separator character.
@@ -1135,8 +1134,8 @@
             return (indexOfExtension(filename) == -1);
         }
         String fileExt = getExtension(filename);
-        for (int i = 0; i < extensions.length; i++) {
-            if (fileExt.equals(extensions[i])) {
+        for (String extension : extensions) {
+            if (fileExt.equals(extension)) {
                 return true;
             }
         }
@@ -1162,8 +1161,8 @@
             return (indexOfExtension(filename) == -1);
         }
         String fileExt = getExtension(filename);
-        for (Iterator<String> it = extensions.iterator(); it.hasNext();) {
-            if (fileExt.equals(it.next())) {
+        for (String extension : extensions) {
+            if (fileExt.equals(extension)) {
                 return true;
             }
         }
@@ -1323,7 +1322,7 @@
         // used by wildcardMatch
         // package level so a unit test may run on this
         
-        if (text.indexOf("?") == -1 && text.indexOf("*") == -1) {
+        if (text.indexOf('?') == -1 && text.indexOf('*') == -1) {
             return new String[] { text };
         }
 

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/IOUtils.java Thu Jan 22 18:02:22
2009
@@ -32,7 +32,6 @@
 import java.nio.channels.Channel;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
@@ -1042,8 +1041,7 @@
         if (lineEnding == null) {
             lineEnding = LINE_SEPARATOR;
         }
-        for (Iterator<?> it = lines.iterator(); it.hasNext(); ) {
-            Object line = it.next();
+        for (Object line : lines) {
             if (line != null) {
                 output.write(line.toString().getBytes());
             }
@@ -1078,8 +1076,7 @@
             if (lineEnding == null) {
                 lineEnding = LINE_SEPARATOR;
             }
-            for (Iterator<?> it = lines.iterator(); it.hasNext(); ) {
-                Object line = it.next();
+            for (Object line : lines) {
                 if (line != null) {
                     output.write(line.toString().getBytes(encoding));
                 }
@@ -1107,8 +1104,7 @@
         if (lineEnding == null) {
             lineEnding = LINE_SEPARATOR;
         }
-        for (Iterator<?> it = lines.iterator(); it.hasNext(); ) {
-            Object line = it.next();
+        for (Object line : lines) {
             if (line != null) {
                 writer.write(line.toString());
             }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/AbstractFileComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/AbstractFileComparator.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/AbstractFileComparator.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/AbstractFileComparator.java
Thu Jan 22 18:02:22 2009
@@ -33,7 +33,7 @@
     /**
      * Sort an array of files.
      * <p>
-     * This method uses {@link Arrays#sort(File[], Comparator)}
+     * This method uses {@link Arrays#sort(Object[], Comparator)}
      * and returns the original array.
      *
      * @param files The files to sort, may be null

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/CompositeFileComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/CompositeFileComparator.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/CompositeFileComparator.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/comparator/CompositeFileComparator.java
Thu Jan 22 18:02:22 2009
@@ -44,6 +44,7 @@
  */
 public class CompositeFileComparator extends AbstractFileComparator implements Serializable
{
 
+    private static final Comparator[] NO_COMPARATORS = {};
     private final Comparator<File>[] delegates;
 
     /**
@@ -52,10 +53,11 @@
      * @param delegates The delegate file comparators
      */
     public CompositeFileComparator(Comparator<File>... delegates) {
-        int size = (delegates == null ? 0 : delegates.length);
-        this.delegates = new Comparator[size];
-        for (int i = 0; i < size; i++) {
-            this.delegates[i] = delegates[i];
+        if (delegates == null) {
+            this.delegates = NO_COMPARATORS;
+        } else {
+            this.delegates = new Comparator[delegates.length];
+            System.arraycopy(delegates, 0, this.delegates, 0, delegates.length);
         }
     }
 
@@ -65,13 +67,15 @@
      * @param delegates The delegate file comparators
      */
     public CompositeFileComparator(Iterable<Comparator<File>> delegates) {
-        List<Comparator<File>> list = new ArrayList<Comparator<File>>();
-        if (delegates != null) {
+        if (delegates == null) {
+            this.delegates = NO_COMPARATORS;
+        } else {
+            List<Comparator<File>> list = new ArrayList<Comparator<File>>();
             for (Comparator<File> comparator : delegates) {
                 list.add(comparator);
             }
+            this.delegates = list.toArray(new Comparator[list.size()]);
         }
-        this.delegates = list.toArray(new Comparator[list.size()]);
     }
 
     /**
@@ -84,8 +88,8 @@
      */
     public int compare(File file1, File file2) {
         int result = 0;
-        for (int i = 0; i < delegates.length; i++) {
-            result = delegates[i].compare(file1, file2);
+        for (Comparator<File> delegate : delegates) {
+            result = delegate.compare(file1, file2);
             if (result != 0) {
                 break;
             }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AndFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AndFileFilter.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AndFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/AndFileFilter.java Thu
Jan 22 18:02:22 2009
@@ -39,7 +39,7 @@
         implements ConditionalFileFilter, Serializable {
 
     /** The list of file filters. */
-    private List<IOFileFilter> fileFilters;
+    private final List<IOFileFilter> fileFilters;
 
     /**
      * Constructs a new instance of <code>AndFileFilter</code>.
@@ -76,7 +76,7 @@
         if (filter1 == null || filter2 == null) {
             throw new IllegalArgumentException("The filters must not be null");
         }
-        this.fileFilters = new ArrayList<IOFileFilter>();
+        this.fileFilters = new ArrayList<IOFileFilter>(2);
         addFileFilter(filter1);
         addFileFilter(filter2);
     }
@@ -106,7 +106,8 @@
      * {@inheritDoc}
      */
     public void setFileFilters(final List<IOFileFilter> fileFilters) {
-        this.fileFilters = new ArrayList<IOFileFilter>(fileFilters);
+        this.fileFilters.clear();
+        this.fileFilters.addAll(fileFilters);
     }
 
     /**

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/NameFileFilter.java
Thu Jan 22 18:02:22 2009
@@ -144,8 +144,8 @@
     @Override
     public boolean accept(File file) {
         String name = file.getName();
-        for (int i = 0; i < this.names.length; i++) {
-            if (caseSensitivity.checkEquals(name, names[i])) {
+        for (String name2 : this.names) {
+            if (caseSensitivity.checkEquals(name, name2)) {
                 return true;
             }
         }
@@ -161,8 +161,8 @@
      */
     @Override
     public boolean accept(File file, String name) {
-        for (int i = 0; i < names.length; i++) {
-            if (caseSensitivity.checkEquals(name, names[i])) {
+        for (String name2 : names) {
+            if (caseSensitivity.checkEquals(name, name2)) {
                 return true;
             }
         }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/OrFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/OrFileFilter.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/OrFileFilter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/OrFileFilter.java Thu
Jan 22 18:02:22 2009
@@ -39,7 +39,7 @@
         implements ConditionalFileFilter, Serializable {
 
     /** The list of file filters. */
-    private List<IOFileFilter> fileFilters;
+    private final List<IOFileFilter> fileFilters;
 
     /**
      * Constructs a new instance of <code>OrFileFilter</code>.
@@ -76,7 +76,7 @@
         if (filter1 == null || filter2 == null) {
             throw new IllegalArgumentException("The filters must not be null");
         }
-        this.fileFilters = new ArrayList<IOFileFilter>();
+        this.fileFilters = new ArrayList<IOFileFilter>(2);
         addFileFilter(filter1);
         addFileFilter(filter2);
     }
@@ -106,7 +106,8 @@
      * {@inheritDoc}
      */
     public void setFileFilters(final List<IOFileFilter> fileFilters) {
-        this.fileFilters = fileFilters;
+        this.fileFilters.clear();
+        this.fileFilters.addAll(fileFilters);
     }
 
     /**

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/PrefixFileFilter.java
Thu Jan 22 18:02:22 2009
@@ -150,8 +150,8 @@
     @Override
     public boolean accept(File file) {
         String name = file.getName();
-        for (int i = 0; i < this.prefixes.length; i++) {
-            if (caseSensitivity.checkStartsWith(name, prefixes[i])) {
+        for (String prefix : this.prefixes) {
+            if (caseSensitivity.checkStartsWith(name, prefix)) {
                 return true;
             }
         }
@@ -167,8 +167,8 @@
      */
     @Override
     public boolean accept(File file, String name) {
-        for (int i = 0; i < prefixes.length; i++) {
-            if (caseSensitivity.checkStartsWith(name, prefixes[i])) {
+        for (String prefix : prefixes) {
+            if (caseSensitivity.checkStartsWith(name, prefix)) {
                 return true;
             }
         }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
Thu Jan 22 18:02:22 2009
@@ -151,8 +151,8 @@
     @Override
     public boolean accept(File file) {
         String name = file.getName();
-        for (int i = 0; i < this.suffixes.length; i++) {
-            if (caseSensitivity.checkEndsWith(name, suffixes[i])) {
+        for (String suffix : this.suffixes) {
+            if (caseSensitivity.checkEndsWith(name, suffix)) {
                 return true;
             }
         }
@@ -168,8 +168,8 @@
      */
     @Override
     public boolean accept(File file, String name) {
-        for (int i = 0; i < this.suffixes.length; i++) {
-            if (caseSensitivity.checkEndsWith(name, suffixes[i])) {
+        for (String suffix : this.suffixes) {
+            if (caseSensitivity.checkEndsWith(name, suffix)) {
                 return true;
             }
         }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFileFilter.java
Thu Jan 22 18:02:22 2009
@@ -149,8 +149,8 @@
      */
     @Override
     public boolean accept(File dir, String name) {
-        for (int i = 0; i < wildcards.length; i++) {
-            if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
+        for (String wildcard : wildcards) {
+            if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) {
                 return true;
             }
         }
@@ -166,8 +166,8 @@
     @Override
     public boolean accept(File file) {
         String name = file.getName();
-        for (int i = 0; i < wildcards.length; i++) {
-            if (FilenameUtils.wildcardMatch(name, wildcards[i], caseSensitivity)) {
+        for (String wildcard : wildcards) {
+            if (FilenameUtils.wildcardMatch(name, wildcard, caseSensitivity)) {
                 return true;
             }
         }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/WildcardFilter.java
Thu Jan 22 18:02:22 2009
@@ -109,9 +109,9 @@
         if (dir != null && new File(dir, name).isDirectory()) {
             return false;
         }
-        
-        for (int i = 0; i < wildcards.length; i++) {
-            if (FilenameUtils.wildcardMatch(name, wildcards[i])) {
+
+        for (String wildcard : wildcards) {
+            if (FilenameUtils.wildcardMatch(name, wildcard)) {
                 return true;
             }
         }
@@ -130,9 +130,9 @@
         if (file.isDirectory()) {
             return false;
         }
-        
-        for (int i = 0; i < wildcards.length; i++) {
-            if (FilenameUtils.wildcardMatch(file.getName(), wildcards[i])) {
+
+        for (String wildcard : wildcards) {
+            if (FilenameUtils.wildcardMatch(file.getName(), wildcard)) {
                 return true;
             }
         }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java
Thu Jan 22 18:02:22 2009
@@ -35,7 +35,7 @@
 public class ClassLoaderObjectInputStream extends ObjectInputStream {
 
     /** The class loader to use. */
-    private ClassLoader classLoader;
+    private final ClassLoader classLoader;
 
     /**
      * Constructs a new ClassLoaderObjectInputStream.

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/input/DemuxInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/DemuxInputStream.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/input/DemuxInputStream.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/input/DemuxInputStream.java Thu
Jan 22 18:02:22 2009
@@ -29,7 +29,7 @@
 public class DemuxInputStream
     extends InputStream
 {
-    private InheritableThreadLocal<InputStream> m_streams = new InheritableThreadLocal<InputStream>();
+    private final InheritableThreadLocal<InputStream> m_streams = new InheritableThreadLocal<InputStream>();
 
     /**
      * Bind the specified stream to the current thread.

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullInputStream.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullInputStream.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullInputStream.java Thu
Jan 22 18:02:22 2009
@@ -62,13 +62,13 @@
  */
 public class NullInputStream extends InputStream {
 
-    private long size;
+    private final long size;
     private long position;
     private long mark = -1;
     private long readlimit;
     private boolean eof;
-    private boolean throwEofException;
-    private boolean markSupported;
+    private final boolean throwEofException;
+    private final boolean markSupported;
 
     /**
      * Create an {@link InputStream} that emulates a specified size

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullReader.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullReader.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullReader.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/input/NullReader.java Thu Jan 22
18:02:22 2009
@@ -62,13 +62,13 @@
  */
 public class NullReader extends Reader {
 
-    private long size;
+    private final long size;
     private long position;
     private long mark = -1;
     private long readlimit;
     private boolean eof;
-    private boolean throwEofException;
-    private boolean markSupported;
+    private final boolean throwEofException;
+    private final boolean markSupported;
 
     /**
      * Create a {@link Reader} that emulates a specified size

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemEntry.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemEntry.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemEntry.java Thu
Jan 22 18:02:22 2009
@@ -40,7 +40,7 @@
  */
 public class FilesystemEntry implements Serializable {
 
-    private FilesystemEntry parent;
+    private final FilesystemEntry parent;
     private FilesystemEntry[] children;
     private File file;
     private String name;

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemMonitor.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemMonitor.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemMonitor.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemMonitor.java
Thu Jan 22 18:02:22 2009
@@ -24,7 +24,6 @@
  * registered {@link FilesystemObserver} at a specified interval.
  * 
  * @see FilesystemObserver
- * @see FilesystemTimerTask
  * @version $Id$
  * @since Commons IO 2.0
  */
@@ -62,8 +61,8 @@
     public FilesystemMonitor(long interval, FilesystemObserver... observers) {
         this(interval);
         if (observers != null) {
-            for (int i = 0; i < observers.length; i++) {
-                addObserver(observers[i]);
+            for (FilesystemObserver observer : observers) {
+                addObserver(observer);
             }
         }
     }
@@ -125,6 +124,7 @@
         try {
             thread.join(interval);
         } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
         }
         for (FilesystemObserver observer : observers) {
             observer.destroy();
@@ -135,10 +135,7 @@
      * Run.
      */
     public void run() {
-        while (true) {
-            if (!running) {
-                break;
-            }
+        while (running) {
             for (FilesystemObserver observer : observers) {
                 observer.checkAndNotify();
             }
@@ -147,7 +144,7 @@
             }
             try {
                 Thread.sleep(interval);
-            } catch (final InterruptedException e) {
+            } catch (final InterruptedException ignored) {
             }
         }
     }

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemObserver.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemObserver.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemObserver.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/monitor/FilesystemObserver.java
Thu Jan 22 18:02:22 2009
@@ -352,20 +352,20 @@
     private void checkAndNotify(FilesystemEntry parent, FilesystemEntry[] previous, File[]
files) {
         int c = 0;
         FilesystemEntry[] current = files.length > 0 ? new FilesystemEntry[files.length]
: EMPTY_ENTRIES;
-        for (int p = 0; p < previous.length; p++) {
-            while (c < files.length &&  comparator.compare(previous[p].getFile(),
files[c]) > 0) {
+        for (FilesystemEntry entry : previous) {
+            while (c < files.length && comparator.compare(entry.getFile(), files[c])
> 0) {
                 current[c] = createFileEntry(parent, files[c]);
                 doCreate(current[c]);
                 c++;
             }
-            if (c < files.length && comparator.compare(previous[p].getFile(),
files[c]) == 0) {
-                doMatch(previous[p], files[c]);
-                checkAndNotify(previous[p], previous[p].getChildren(), listFiles(files[c]));
-                current[c] = previous[p];
+            if (c < files.length && comparator.compare(entry.getFile(), files[c])
== 0) {
+                doMatch(entry, files[c]);
+                checkAndNotify(entry, entry.getChildren(), listFiles(files[c]));
+                current[c] = entry;
                 c++;
             } else {
-                checkAndNotify(previous[p], previous[p].getChildren(), EMPTY_FILES);
-                doDelete(previous[p]);
+                checkAndNotify(entry, entry.getChildren(), EMPTY_FILES);
+                doDelete(entry);
             }
         }
         for (; c < files.length; c++) {
@@ -408,8 +408,8 @@
             }
         }
         FilesystemEntry[] children = entry.getChildren();
-        for (int i = 0; i < children.length; i++) {
-            doCreate(children[i]);
+        for (FilesystemEntry aChildren : children) {
+            doCreate(aChildren);
         }
     }
 

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/output/ByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/output/ByteArrayOutputStream.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/output/ByteArrayOutputStream.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/output/ByteArrayOutputStream.java
Thu Jan 22 18:02:22 2009
@@ -58,7 +58,7 @@
     private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
 
     /** The list of buffers, which grows and never reduces. */
-    private List<byte[]> buffers = new ArrayList<byte[]>();
+    private final List<byte[]> buffers = new ArrayList<byte[]>();
     /** The index of the current buffer. */
     private int currentBufferIndex;
     /** The total count of bytes in all the filled buffers. */
@@ -241,8 +241,7 @@
      */
     public synchronized void writeTo(OutputStream out) throws IOException {
         int remaining = count;
-        for (int i = 0; i < buffers.size(); i++) {
-            byte[] buf = buffers.get(i);
+        for (byte[] buf : buffers) {
             int c = Math.min(buf.length, remaining);
             out.write(buf, 0, c);
             remaining -= c;
@@ -295,8 +294,7 @@
             return new ClosedInputStream();
         }
         List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
-        for (int i = 0; i < buffers.size(); i++) {
-            byte[] buf = buffers.get(i);
+        for (byte[] buf : buffers) {
             int c = Math.min(buf.length, remaining);
             list.add(new ByteArrayInputStream(buf, 0, c));
             remaining -= c;
@@ -321,8 +319,7 @@
         }
         byte newbuf[] = new byte[remaining];
         int pos = 0;
-        for (int i = 0; i < buffers.size(); i++) {
-            byte[] buf = buffers.get(i);
+        for (byte[] buf : buffers) {
             int c = Math.min(buf.length, remaining);
             System.arraycopy(buf, 0, newbuf, pos, c);
             pos += c;

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/output/CountingOutputStream.java
Thu Jan 22 18:02:22 2009
@@ -31,7 +31,7 @@
 public class CountingOutputStream extends ProxyOutputStream {
 
     /** The count of bytes that have passed. */
-    private long count;
+    private long count = 0;
 
     /**
      * Constructs a new CountingOutputStream.

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/output/DeferredFileOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/output/DeferredFileOutputStream.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/output/DeferredFileOutputStream.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/output/DeferredFileOutputStream.java
Thu Jan 22 18:02:22 2009
@@ -71,17 +71,17 @@
     /**
      * The temporary file prefix.
      */
-    private String prefix;
+    private final String prefix;
 
     /**
      * The temporary file suffix.
      */
-    private String suffix;
+    private final String suffix;
 
     /**
      * The directory to use for temporary files.
      */
-    private File directory;
+    private final File directory;
 
     
     /**
@@ -101,11 +101,7 @@
      */
     public DeferredFileOutputStream(int threshold, File outputFile)
     {
-        super(threshold);
-        this.outputFile = outputFile;
-
-        memoryOutputStream = new ByteArrayOutputStream();
-        currentOutputStream = memoryOutputStream;
+        this(threshold,  outputFile, null, null, null);
     }
 
 
@@ -122,10 +118,28 @@
      */
     public DeferredFileOutputStream(int threshold, String prefix, String suffix, File directory)
     {
-        this(threshold, (File)null);
+        this(threshold,   null, prefix, suffix, directory);
         if (prefix == null) {
             throw new IllegalArgumentException("Temporary file prefix is missing");
         }
+    }
+
+    /**
+     * Constructs an instance of this class which will trigger an event at the
+     * specified threshold, and save data either to a file beyond that point.
+     * 
+     * @param threshold  The number of bytes at which to trigger an event.
+     * @param outputFile The file to which data is saved beyond the threshold.
+     * @param prefix Prefix to use for the temporary file.
+     * @param suffix Suffix to use for the temporary file.
+     * @param directory Temporary file directory.
+     */
+    private DeferredFileOutputStream(int threshold, File outputFile, String prefix, String
suffix, File directory) {
+        super(threshold);
+        this.outputFile = outputFile;
+
+        memoryOutputStream = new ByteArrayOutputStream();
+        currentOutputStream = memoryOutputStream;
         this.prefix = prefix;
         this.suffix = suffix;
         this.directory = directory;

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/output/DemuxOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/output/DemuxOutputStream.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/output/DemuxOutputStream.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/output/DemuxOutputStream.java Thu
Jan 22 18:02:22 2009
@@ -29,7 +29,7 @@
 public class DemuxOutputStream
     extends OutputStream
 {
-    private InheritableThreadLocal<OutputStream> m_streams = new InheritableThreadLocal<OutputStream>();
+    private final InheritableThreadLocal<OutputStream> m_streams = new InheritableThreadLocal<OutputStream>();
 
     /**
      * Bind the specified stream to the current thread.

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/output/ThresholdingOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/output/ThresholdingOutputStream.java?rev=736890&r1=736889&r2=736890&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/output/ThresholdingOutputStream.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/output/ThresholdingOutputStream.java
Thu Jan 22 18:02:22 2009
@@ -48,7 +48,7 @@
     /**
      * The threshold at which the event will be triggered.
      */
-    private int threshold;
+    private final int threshold;
 
 
     /**



Mime
View raw message