commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1686747 [3/3] - in /commons/proper/io/trunk/src: main/java/org/apache/commons/io/ main/java/org/apache/commons/io/filefilter/ main/java/org/apache/commons/io/input/ main/java/org/apache/commons/io/monitor/ main/java/org/apache/commons/io/o...
Date Sun, 21 Jun 2015 18:44:50 GMT
Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/Java7Support.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/Java7Support.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/Java7Support.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/Java7Support.java Sun Jun
21 18:44:49 2015
@@ -78,6 +78,11 @@ class Java7Support {
         IS_JAVA7 = isJava7x;
     }
 
+    /**
+     * Invokes java7 isSymbolicLink
+     * @param file The file to check
+     * @return true if the file is a symbolic link
+     */
     public static boolean isSymLink(File file) {
         try {
             Object path = toPath.invoke(file);
@@ -90,6 +95,12 @@ class Java7Support {
         }
     }
 
+    /**
+     * Reads the target of a symbolic link
+     * @param symlink The symlink to read
+     * @return The location the symlink is pointing to
+     * @throws IOException Upon failure
+     */
 
     public static File readSymbolicLink(File symlink)
             throws IOException {
@@ -105,7 +116,13 @@ class Java7Support {
     }
 
 
-    public static boolean exists(File file)
+    /**
+     * Indicates if a symlunk target exists
+     * @param file The symlink file
+     * @return true if the target exists
+     * @throws IOException upon error
+     */
+    private static boolean exists(File file)
             throws IOException {
         try {
             Object path = toPath.invoke(file);
@@ -119,6 +136,13 @@ class Java7Support {
 
     }
 
+    /**
+     * Creates a symbolic link
+     * @param symlink The symlink to create
+     * @param target Where it should point
+     * @return The newly created symlink
+     * @throws IOException upon error
+     */
     public static File createSymbolicLink(File symlink, File target)
             throws IOException {
         try {
@@ -141,7 +165,7 @@ class Java7Support {
      * Performs a nio delete
      *
      * @param file the file to delete
-     * @throws IOException
+     * @throws IOException Upon error
      */
     public static void delete(File file)
             throws IOException {
@@ -155,6 +179,10 @@ class Java7Support {
         }
     }
 
+    /**
+     * Indicates if the current vm has java7 lubrary support
+     * @return true if java7 library support
+     */
     public static boolean isAtLeastJava7() {
         return IS_JAVA7;
     }

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/filefilter/MagicNumberFileFilter.java
Sun Jun 21 18:44:49 2015
@@ -170,7 +170,8 @@ public class MagicNumberFileFilter exten
             throw new IllegalArgumentException("The offset cannot be negative");
         }
 
-        this.magicNumbers = magicNumber.getBytes(Charset.defaultCharset()); // explicitly
uses the platform default charset
+        this.magicNumbers = magicNumber.getBytes(Charset.defaultCharset()); // explicitly
uses the platform default
+                                                                            // charset
         this.byteOffset = offset;
     }
 
@@ -263,7 +264,8 @@ public class MagicNumberFileFilter exten
     public String toString() {
         final StringBuilder builder = new StringBuilder(super.toString());
         builder.append("(");
-        builder.append(new String(magicNumbers, Charset.defaultCharset()));// TODO perhaps
use hex if value is not printable
+        builder.append(new String(magicNumbers, Charset.defaultCharset()));// TODO perhaps
use hex if value is not
+                                                                           // printable
         builder.append(",");
         builder.append(this.byteOffset);
         builder.append(")");

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java
Sun Jun 21 18:44:49 2015
@@ -66,7 +66,8 @@ public class CharSequenceInputStream ext
         // Ensure that buffer is long enough to hold a complete character
         final float maxBytesPerChar = encoder.maxBytesPerChar();
         if (bufferSize < maxBytesPerChar) {
-            throw new IllegalArgumentException("Buffer size " + bufferSize + " is less than
maxBytesPerChar " + maxBytesPerChar);
+            throw new IllegalArgumentException("Buffer size " + bufferSize + " is less than
maxBytesPerChar " +
+                    maxBytesPerChar);
         }
         this.bbuf = ByteBuffer.allocate(bufferSize);
         this.bbuf.flip();
@@ -233,9 +234,10 @@ public class CharSequenceInputStream ext
          * Since the bbuf is re-used, in general it's necessary to re-encode the data.
          *
          * It should be possible to apply some optimisations however:
-         * + use mark/reset on the cbuf and bbuf. This would only work if the buffer had
not been (re)filled since the mark.
-         * The code would have to catch InvalidMarkException - does not seem possible to
check if mark is valid otherwise.
-         * + Try saving the state of the cbuf before each fillBuffer; it might be possible
to restart from there.
+         * + use mark/reset on the cbuf and bbuf. This would only work if the buffer had
not been (re)filled since
+         * the mark. The code would have to catch InvalidMarkException - does not seem possible
to check if mark is
+         * valid otherwise. + Try saving the state of the cbuf before each fillBuffer; it
might be possible to
+         * restart from there.
          */
         if (this.mark_cbuf != NO_MARK) {
             // if cbuf is at 0, we have not started reading anything, so skip re-encoding
@@ -251,7 +253,8 @@ public class CharSequenceInputStream ext
                 }
             }
             if (this.cbuf.position() != this.mark_cbuf) {
-                throw new IllegalStateException("Unexpected CharBuffer postion: actual="+cbuf.position()
+ " expected=" + this.mark_cbuf);
+                throw new IllegalStateException("Unexpected CharBuffer postion: actual="
+ cbuf.position() + " " +
+                        "expected=" + this.mark_cbuf);
             }
             this.bbuf.position(this.mark_bbuf);
             this.mark_cbuf = NO_MARK;

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
Sun Jun 21 18:44:49 2015
@@ -23,7 +23,6 @@ import java.io.RandomAccessFile;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
-import java.nio.charset.UnsupportedCharsetException;
 
 import org.apache.commons.io.Charsets;
 
@@ -121,7 +120,8 @@ public class ReversedLinesFileReader imp
             // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte
can never be a newline byte
             // http://en.wikipedia.org/wiki/UTF-8
             byteDecrement = 1;
-        } else if(charset == Charset.forName("Shift_JIS") || // Same as for UTF-8 http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
+        } else if(charset == Charset.forName("Shift_JIS") || // Same as for UTF-8
+                                      // http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
                 charset == Charset.forName("windows-31j") || // Windows code page 932 (Japanese)
                 charset == Charset.forName("x-windows-949") || // Windows code page 949 (Korean)
                 charset == Charset.forName("gbk") || // Windows code page 936 (Simplified
Chinese)
@@ -132,9 +132,11 @@ public class ReversedLinesFileReader imp
             // however byte order has to be specified
             byteDecrement = 2;
         } else if (charset == Charsets.UTF_16) {
-            throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte
order (use UTF-16BE or UTF-16LE)");
+            throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte
order (use UTF-16BE or " +
+                    "UTF-16LE)");
         } else {
-            throw new UnsupportedEncodingException("Encoding " + encoding + " is not supported
yet (feel free to submit a patch)");
+            throw new UnsupportedEncodingException("Encoding " + encoding + " is not supported
yet (feel free to " +
+                    "submit a patch)");
         }
         // NOTE: The new line sequences are matched in the order given, so it is important
that \r\n is BEFORE \n
         newLineSequences = new byte[][] { "\r\n".getBytes(encoding), "\n".getBytes(encoding),
"\r".getBytes(encoding) };
@@ -153,9 +155,8 @@ public class ReversedLinesFileReader imp
      * @param encoding
      *            the encoding of the file
      * @throws IOException  if an I/O error occurs
-     * @throws UnsupportedCharsetException
-     *             thrown instead of {@link UnsupportedEncodingException} in version 2.2
if the encoding is not
-     *             supported.
+     * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link UnsupportedEncodingException}
in
+     * version 2.2 if the encoding is not supported.
      */
     public ReversedLinesFileReader(final File file, final int blockSize, final String encoding)
throws IOException {
         this(file, blockSize, Charsets.toCharset(encoding));

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java Sun Jun
21 18:44:49 2015
@@ -207,7 +207,8 @@ public class Tailer implements Runnable
      * @param end Set to true to tail from the end of the file, false to tail from the beginning
of the file.
      * @param reOpen if true, close and reopen the file between reading chunks
      */
-    public Tailer(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final boolean reOpen) {
+    public Tailer(final File file, final TailerListener listener, final long delayMillis,
final boolean end,
+                  final boolean reOpen) {
         this(file, listener, delayMillis, end, reOpen, DEFAULT_BUFSIZE);
     }
 
@@ -219,7 +220,8 @@ public class Tailer implements Runnable
      * @param end Set to true to tail from the end of the file, false to tail from the beginning
of the file.
      * @param bufSize Buffer size
      */
-    public Tailer(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final int bufSize) {
+    public Tailer(final File file, final TailerListener listener, final long delayMillis,
final boolean end,
+                  final int bufSize) {
         this(file, listener, delayMillis, end, false, bufSize);
     }
 
@@ -232,7 +234,8 @@ public class Tailer implements Runnable
      * @param reOpen if true, close and reopen the file between reading chunks
      * @param bufSize Buffer size
      */
-    public Tailer(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final boolean reOpen, final int bufSize) {
+    public Tailer(final File file, final TailerListener listener, final long delayMillis,
final boolean end,
+                  final boolean reOpen, final int bufSize) {
         this(file, DEFAULT_CHARSET, listener, delayMillis, end, reOpen, bufSize);
     }
 
@@ -246,7 +249,8 @@ public class Tailer implements Runnable
      * @param reOpen if true, close and reopen the file between reading chunks
      * @param bufSize Buffer size
      */
-    public Tailer(final File file, final Charset cset, final TailerListener listener, final
long delayMillis, final boolean end, final boolean reOpen
+    public Tailer(final File file, final Charset cset, final TailerListener listener, final
long delayMillis,
+                  final boolean end, final boolean reOpen
             , final int bufSize) {
         this.file = file;
         this.delayMillis = delayMillis;
@@ -271,7 +275,8 @@ public class Tailer implements Runnable
      * @param bufSize buffer size.
      * @return The new tailer
      */
-    public static Tailer create(final File file, final TailerListener listener, final long
delayMillis, final boolean end, final int bufSize) {
+    public static Tailer create(final File file, final TailerListener listener, final long
delayMillis,
+                                final boolean end, final int bufSize) {
         return create(file, listener, delayMillis, end, false, bufSize);
     }
 
@@ -286,7 +291,8 @@ public class Tailer implements Runnable
      * @param bufSize buffer size.
      * @return The new tailer
      */
-    public static Tailer create(final File file, final TailerListener listener, final long
delayMillis, final boolean end, final boolean reOpen,
+    public static Tailer create(final File file, final TailerListener listener, final long
delayMillis,
+                                final boolean end, final boolean reOpen,
             final int bufSize) {
         return create(file, DEFAULT_CHARSET, listener, delayMillis, end, reOpen, bufSize);
     }
@@ -303,7 +309,8 @@ public class Tailer implements Runnable
      * @param bufSize buffer size.
      * @return The new tailer
      */
-    public static Tailer create(final File file, final Charset charset, final TailerListener
listener, final long delayMillis, final boolean end, final boolean reOpen
+    public static Tailer create(final File file, final Charset charset, final TailerListener
listener,
+                                final long delayMillis, final boolean end, final boolean
reOpen
             ,final int bufSize) {
         final Tailer tailer = new Tailer(file, charset, listener, delayMillis, end, reOpen,
bufSize);
         final Thread thread = new Thread(tailer);
@@ -321,7 +328,8 @@ public class Tailer implements Runnable
      * @param end Set to true to tail from the end of the file, false to tail from the beginning
of the file.
      * @return The new tailer
      */
-    public static Tailer create(final File file, final TailerListener listener, final long
delayMillis, final boolean end) {
+    public static Tailer create(final File file, final TailerListener listener, final long
delayMillis,
+                                final boolean end) {
         return create(file, listener, delayMillis, end, DEFAULT_BUFSIZE);
     }
 
@@ -335,7 +343,8 @@ public class Tailer implements Runnable
      * @param reOpen whether to close/reopen the file between chunks
      * @return The new tailer
      */
-    public static Tailer create(final File file, final TailerListener listener, final long
delayMillis, final boolean end, final boolean reOpen) {
+    public static Tailer create(final File file, final TailerListener listener, final long
delayMillis,
+                                final boolean end, final boolean reOpen) {
         return create(file, listener, delayMillis, end, reOpen, DEFAULT_BUFSIZE);
     }
 
@@ -481,6 +490,10 @@ public class Tailer implements Runnable
         }
     }
 
+    /**
+     * Stops the tailer with an exception
+     * @param e The exception to send to listener
+     */
     private void stop(final Exception e) {
         listener.handle(e);
         stop();
@@ -536,6 +549,9 @@ public class Tailer implements Runnable
         }
         IOUtils.closeQuietly(lineBuf); // not strictly necessary
         reader.seek(rePos); // Ensure we can re-read if necessary
+
+        listener.endOfFileReached();
+
         return rePos;
     }
 

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/TailerListener.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/TailerListener.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/TailerListener.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/TailerListener.java
Sun Jun 21 18:44:49 2015
@@ -64,4 +64,10 @@ public interface TailerListener {
      */
     void handle(Exception ex);
 
+    /**
+     * Called each time the Tailer reaches the end of the file.
+     * <p>
+     * <b>Note:</b> this is called from the tailer thread.
+     */
+    void endOfFileReached();
 }

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/TailerListenerAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/TailerListenerAdapter.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/TailerListenerAdapter.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/TailerListenerAdapter.java
Sun Jun 21 18:44:49 2015
@@ -61,4 +61,9 @@ public class TailerListenerAdapter imple
     public void handle(final Exception ex) {
     }
 
+    /**
+     * Called each time the Tailer reaches the end of the file.
+     */
+    public void endOfFileReached() {
+    }
 }

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
Sun Jun 21 18:44:49 2015
@@ -48,6 +48,11 @@ public class UnixLineEndingInputStream e
         this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
     }
 
+    /**
+     * Reads the next item from the target, updating internal flags in the process
+     * @return the next int read from the target stream
+     * @throws IOException upon error
+     */
     private int readWithUpdate() throws IOException {
         final int target = this.target.read();
         eofSeen = target == -1;
@@ -86,6 +91,11 @@ public class UnixLineEndingInputStream e
         }
     }
 
+    /**
+     * Handles the eof-handling at the end of the stream
+     * @param previousWasSlashR Indicates if the last seen was a \r
+     * @return The next char to output to the stream
+     */
     private int eofGame(boolean previousWasSlashR) {
         if ( previousWasSlashR || !ensureLineFeedAtEndOfFile ) {
             return -1;
@@ -100,6 +110,7 @@ public class UnixLineEndingInputStream e
 
     /**
      * Closes the stream. Also closes the underlying stream.
+     * @throws IOException upon error
      */
     @Override
     public void close() throws IOException {

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
Sun Jun 21 18:44:49 2015
@@ -21,6 +21,8 @@ import java.io.InputStream;
 
 /**
  * A filtering input stream that ensures the content will have windows line endings, CRLF.
+ *
+ * @since 2.5
  */
 public class WindowsLineEndingInputStream  extends InputStream {
 
@@ -47,6 +49,11 @@ public class WindowsLineEndingInputStrea
         this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
     }
 
+    /**
+     * Reads the next item from the target, updating internal flags in the process
+     * @return the next int read from the target stream
+     * @throws IOException upon error
+     */
     private int readWithUpdate() throws IOException {
         final int target = this.target.read();
         eofSeen = target == -1;
@@ -85,6 +92,11 @@ public class WindowsLineEndingInputStrea
         }
     }
 
+    /**
+     * Handles the eof-handling at the end of the stream
+     * @return The next char to output to the stream
+     */
+
     private int eofGame() {
         if ( !ensureLineFeedAtEndOfFile ) {
             return -1;
@@ -104,6 +116,7 @@ public class WindowsLineEndingInputStrea
 
     /**
      * Closes the stream. Also closes the underlying stream.
+     * @throws IOException upon error
      */
     @Override
     public void close() throws IOException {

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/XmlStreamReader.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/XmlStreamReader.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/XmlStreamReader.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/XmlStreamReader.java
Sun Jun 21 18:44:49 2015
@@ -212,7 +212,8 @@ public class XmlStreamReader extends Rea
      * @throws XmlStreamReaderException thrown if the charset encoding could not
      *         be determined according to the specs.
      */
-    public XmlStreamReader(final InputStream is, final boolean lenient, final String defaultEncoding)
throws IOException {
+    public XmlStreamReader(final InputStream is, final boolean lenient, final String defaultEncoding)
+            throws IOException {
         this.defaultEncoding = defaultEncoding;
         final BOMInputStream bom = new BOMInputStream(new BufferedInputStream(is, BUFFER_SIZE),
false, BOMS);
         final BOMInputStream pis = new BOMInputStream(bom, true, XML_GUESS_BYTES);

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationObserver.java
Sun Jun 21 18:44:49 2015
@@ -154,7 +154,8 @@ public class FileAlterationObserver impl
      * @param fileFilter The file filter or null if none
      * @param caseSensitivity  what case sensitivity to use comparing file names, null means
system sensitive
      */
-    public FileAlterationObserver(final String directoryName, final FileFilter fileFilter,
final IOCase caseSensitivity) {
+    public FileAlterationObserver(final String directoryName, final FileFilter fileFilter,
+                                  final IOCase caseSensitivity) {
         this(new File(directoryName), fileFilter, caseSensitivity);
     }
 
@@ -197,7 +198,8 @@ public class FileAlterationObserver impl
      * @param fileFilter The file filter or null if none
      * @param caseSensitivity  what case sensitivity to use comparing file names, null means
system sensitive
      */
-    protected FileAlterationObserver(final FileEntry rootEntry, final FileFilter fileFilter,
final IOCase caseSensitivity) {
+    protected FileAlterationObserver(final FileEntry rootEntry, final FileFilter fileFilter,
+                                     final IOCase caseSensitivity) {
         if (rootEntry == null) {
             throw new IllegalArgumentException("Root entry is missing");
         }
@@ -359,6 +361,12 @@ public class FileAlterationObserver impl
         return entry;
     }
 
+    /**
+     * List the files
+     * @param file The file to list files for
+     * @param entry the parent entry
+     * @return The child files
+     */
     private FileEntry[] doListFiles(File file, FileEntry entry) {
         final File[] files = listFiles(file);
         final FileEntry[] children = files.length > 0 ? new FileEntry[files.length] :
FileEntry.EMPTY_ENTRIES;

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/AppendableOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/AppendableOutputStream.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/AppendableOutputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/AppendableOutputStream.java
Sun Jun 21 18:44:49 2015
@@ -46,6 +46,7 @@ public class AppendableOutputStream <T e
      * Write a character to the underlying appendable.
      *
      * @param b the character to write
+     * @throws IOException upon error
      */
     @Override
     public void write(int b) throws IOException {

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java
Sun Jun 21 18:44:49 2015
@@ -65,6 +65,12 @@ public class ChunkedOutputStream extends
 
     /**
      * Writes the data buffer in chunks to the underlying stream
+     *
+     * @param data the data to write
+     * @param srcOffset the offset
+     * @param length the length of data to write
+     *
+     * @throws IOException if an I/O error occurs.
      */
     @Override
     public void write(byte[] data, int srcOffset, int length) throws IOException {

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/ChunkedWriter.java
Sun Jun 21 18:44:49 2015
@@ -64,6 +64,11 @@ public class ChunkedWriter extends Filte
 
     /**
      * writes the data buffer in chunks to the underlying writer
+     * @param data The data
+     * @param srcOffset the offset
+     * @param length the number of bytes to write
+     *
+     * @throws IOException upon error
      */
     @Override
     public void write(char[] data, int srcOffset, int length) throws IOException {

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/DeferredFileOutputStream.java
Sun Jun 21 18:44:49 2015
@@ -131,7 +131,8 @@ public class DeferredFileOutputStream
      * @param suffix Suffix to use for the temporary file.
      * @param directory Temporary file directory.
      */
-    private DeferredFileOutputStream(final int threshold, final File outputFile, final String
prefix, final String suffix, final File directory) {
+    private DeferredFileOutputStream(final int threshold, final File outputFile, final String
prefix,
+                                     final String suffix, final File directory) {
         super(threshold);
         this.outputFile = outputFile;
 
@@ -176,7 +177,12 @@ public class DeferredFileOutputStream
             outputFile = File.createTempFile(prefix, suffix, directory);
         }
         final FileOutputStream fos = new FileOutputStream(outputFile);
-        memoryOutputStream.writeTo(fos);
+        try {
+            memoryOutputStream.writeTo(fos);
+        } catch (IOException e){
+            fos.close();
+            throw e;
+        }
         currentOutputStream = fos;
         memoryOutputStream = null;
     }

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
Sun Jun 21 18:44:49 2015
@@ -75,7 +75,8 @@ public class FileWriterWithEncoding exte
      * @throws NullPointerException if the file name or encoding is null
      * @throws IOException in case of an I/O error
      */
-    public FileWriterWithEncoding(final String filename, final String encoding, final boolean
append) throws IOException {
+    public FileWriterWithEncoding(final String filename, final String encoding, final boolean
append)
+            throws IOException {
         this(new File(filename), encoding, append);
     }
 
@@ -100,7 +101,8 @@ public class FileWriterWithEncoding exte
      * @throws NullPointerException if the file name or encoding is null
      * @throws IOException in case of an I/O error
      */
-    public FileWriterWithEncoding(final String filename, final Charset encoding, final boolean
append) throws IOException {
+    public FileWriterWithEncoding(final String filename, final Charset encoding, final boolean
append)
+            throws IOException {
         this(new File(filename), encoding, append);
     }
 
@@ -125,7 +127,8 @@ public class FileWriterWithEncoding exte
      * @throws NullPointerException if the file name or encoding is null
      * @throws IOException in case of an I/O error
      */
-    public FileWriterWithEncoding(final String filename, final CharsetEncoder encoding, final
boolean append) throws IOException {
+    public FileWriterWithEncoding(final String filename, final CharsetEncoder encoding, final
boolean append)
+            throws IOException {
         this(new File(filename), encoding, append);
     }
 
@@ -202,7 +205,8 @@ public class FileWriterWithEncoding exte
      * @throws NullPointerException if the file or encoding is null
      * @throws IOException in case of an I/O error
      */
-    public FileWriterWithEncoding(final File file, final CharsetEncoder encoding, final boolean
append) throws IOException {
+    public FileWriterWithEncoding(final File file, final CharsetEncoder encoding, final boolean
append)
+            throws IOException {
         super();
         this.out = initWriter(file, encoding, append);
     }

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/LockableFileWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/LockableFileWriter.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/LockableFileWriter.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/LockableFileWriter.java
Sun Jun 21 18:44:49 2015
@@ -21,10 +21,8 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.nio.charset.Charset;
-import java.nio.charset.UnsupportedCharsetException;
 
 import org.apache.commons.io.Charsets;
 import org.apache.commons.io.FileUtils;
@@ -158,8 +156,8 @@ public class LockableFileWriter extends
      * @param encoding  the encoding to use, null means platform default
      * @throws NullPointerException if the file is null
      * @throws IOException in case of an I/O error
-     * @throws UnsupportedCharsetException
-     *             thrown instead of {@link UnsupportedEncodingException} in version 2.2
if the encoding is not
+     * @throws java.nio.charset.UnsupportedCharsetException
+     *             thrown instead of {@link java.io.UnsupportedEncodingException} in version
2.2 if the encoding is not
      *             supported.
      */
     public LockableFileWriter(final File file, final String encoding) throws IOException
{
@@ -214,8 +212,8 @@ public class LockableFileWriter extends
      * @param lockDir  the directory in which the lock file should be held
      * @throws NullPointerException if the file is null
      * @throws IOException in case of an I/O error
-     * @throws UnsupportedCharsetException
-     *             thrown instead of {@link UnsupportedEncodingException} in version 2.2
if the encoding is not
+     * @throws java.nio.charset.UnsupportedCharsetException
+     *             thrown instead of {@link java.io.UnsupportedEncodingException} in version
2.2 if the encoding is not
      *             supported.
      */
     public LockableFileWriter(final File file, final String encoding, final boolean append,

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/WriterOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/WriterOutputStream.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/WriterOutputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/output/WriterOutputStream.java
Sun Jun 21 18:44:49 2015
@@ -117,7 +117,8 @@ public class WriterOutputStream extends
      *                         {@link #flush()} or {@link #close()} is called.
      * @since 2.1
      */
-    public WriterOutputStream(final Writer writer, final CharsetDecoder decoder, final int
bufferSize, final boolean writeImmediately) {
+    public WriterOutputStream(final Writer writer, final CharsetDecoder decoder, final int
bufferSize,
+                              final boolean writeImmediately) {
         this.writer = writer;
         this.decoder = decoder;
         this.writeImmediately = writeImmediately;
@@ -136,7 +137,8 @@ public class WriterOutputStream extends
      *                         output buffer will only be flushed when it overflows or when
      *                         {@link #flush()} or {@link #close()} is called.
      */
-    public WriterOutputStream(final Writer writer, final Charset charset, final int bufferSize,
final boolean writeImmediately) {
+    public WriterOutputStream(final Writer writer, final Charset charset, final int bufferSize,
+                              final boolean writeImmediately) {
         this(writer,
              charset.newDecoder()
                     .onMalformedInput(CodingErrorAction.REPLACE)
@@ -170,7 +172,8 @@ public class WriterOutputStream extends
      *                         output buffer will only be flushed when it overflows or when
      *                         {@link #flush()} or {@link #close()} is called.
      */
-    public WriterOutputStream(final Writer writer, final String charsetName, final int bufferSize,
final boolean writeImmediately) {
+    public WriterOutputStream(final Writer writer, final String charsetName, final int bufferSize,
+                              final boolean writeImmediately) {
         this(writer, Charset.forName(charsetName), bufferSize, writeImmediately);
     }
 

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java?rev=1686747&r1=1686746&r2=1686747&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java Sun
Jun 21 18:44:49 2015
@@ -262,6 +262,34 @@ public class TailerTest extends FileBase
         assertEquals("fileRotated should be be called", 1 , listener.rotated);
     }
 
+    public void testTailerEndOfFileReached() throws Exception {
+        // Create & start the Tailer
+        final long delayMillis = 50;
+        final long testDelayMillis = delayMillis * 10;
+        final File file = new File(getTestDirectory(), "tailer1-test.txt");
+        createFile(file, 0);
+        final TestTailerListener listener = new TestTailerListener();
+        final String osname = System.getProperty("os.name");
+        final boolean isWindows = osname.startsWith("Windows");
+        tailer = new Tailer(file, listener, delayMillis, false, isWindows);
+        final Thread thread = new Thread(tailer);
+        thread.start();
+
+        // write a few lines
+        write(file, "line1", "line2", "line3");
+        Thread.sleep(testDelayMillis);
+
+        // write a few lines
+        write(file, "line4", "line5", "line6");
+        Thread.sleep(testDelayMillis);
+
+        // write a few lines
+        write(file, "line7", "line8", "line9");
+        Thread.sleep(testDelayMillis);
+
+        assertEquals("end of file reached 3 times", 3, listener.reachedEndOfFile);
+    }
+
     @Override
     protected void createFile(final File file, final long size)
         throws IOException {
@@ -328,6 +356,7 @@ public class TailerTest extends FileBase
         assertEquals("Expected init to be called", 1 , listener.initialised);
         assertTrue("fileNotFound should be called", listener.notFound > 0);
         assertEquals("fileRotated should be not be called", 0 , listener.rotated);
+        assertEquals("end of file never reached", 0, listener.reachedEndOfFile);
     }
 
     /*
@@ -353,6 +382,7 @@ public class TailerTest extends FileBase
         assertEquals("Expected init to be called", 1, listener.initialised);
         assertTrue("fileNotFound should be called", listener.notFound > 0);
         assertEquals("fileRotated should be not be called", 0, listener.rotated);
+        assertEquals("end of file never reached", 0, listener.reachedEndOfFile);
     }
 
     public void testStopWithNoFileUsingExecutor() throws Exception {
@@ -372,6 +402,7 @@ public class TailerTest extends FileBase
         assertEquals("Expected init to be called", 1 , listener.initialised);
         assertTrue("fileNotFound should be called", listener.notFound > 0);
         assertEquals("fileRotated should be not be called", 0 , listener.rotated);
+        assertEquals("end of file never reached", 0, listener.reachedEndOfFile);
     }
 
     public void testIO335() throws Exception { // test CR behaviour
@@ -418,6 +449,8 @@ public class TailerTest extends FileBase
 
         volatile int initialised = 0;
 
+        volatile int reachedEndOfFile = 0;
+
         public void handle(final String line) {
             lines.add(line);
         }
@@ -445,5 +478,9 @@ public class TailerTest extends FileBase
         public void fileRotated() {
             rotated++; // not atomic, but OK because only updated here.
         }
+
+        public void endOfFileReached() {
+            reachedEndOfFile++; // not atomic, but OK because only updated here.
+        }
     }
 }



Mime
View raw message