You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/12/12 15:17:34 UTC

[commons-io] branch master updated (b47686a -> fe6e6e9)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git.


    from b47686a  Slightly better Javadoc.
     new a25b144  Formatting.
     new f17997c  Formatting.
     new 6f82a45  Formatting.
     new 76d42c0  Better private ivar name.
     new b2d0756  Remove unused exception from private method signature.
     new fe6e6e9  Fix typo.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/io/input/ReversedLinesFileReader.java  | 35 +++++++++---------
 .../java/org/apache/commons/io/input/Tailer.java   | 41 +++++++++++-----------
 .../io/input/UnixLineEndingInputStream.java        | 21 ++++++-----
 .../io/input/WindowsLineEndingInputStream.java     | 25 +++++++------
 4 files changed, 59 insertions(+), 63 deletions(-)


[commons-io] 06/06: Fix typo.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git

commit fe6e6e9872eb8dd75f8b84cf48d0674f8748e02b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 12 10:17:19 2020 -0500

    Fix typo.
---
 .../java/org/apache/commons/io/input/UnixLineEndingInputStream.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
index 1b92bb8..dc43e30 100644
--- a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
@@ -119,6 +119,6 @@ public class UnixLineEndingInputStream extends InputStream {
      */
     @Override
     public synchronized void mark(final int readlimit) {
-        throw new UnsupportedOperationException("Mark notsupported");
+        throw new UnsupportedOperationException("Mark not supported");
     }
 }


[commons-io] 01/06: Formatting.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git

commit a25b1440bdbcd5854ad3516aa17576140415f8d6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 12 09:52:55 2020 -0500

    Formatting.
---
 .../java/org/apache/commons/io/input/Tailer.java   | 41 +++++++++++-----------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/input/Tailer.java b/src/main/java/org/apache/commons/io/input/Tailer.java
index 6d2ac52..a03f33f 100644
--- a/src/main/java/org/apache/commons/io/input/Tailer.java
+++ b/src/main/java/org/apache/commons/io/input/Tailer.java
@@ -441,7 +441,7 @@ public class Tailer implements Runnable {
                         // Finish scanning the old file and then we'll start with the new one
                         try {
                             readLines(save);
-                        }  catch (final IOException ioe) {
+                        } catch (final IOException ioe) {
                             listener.handle(ioe);
                         }
                         position = 0;
@@ -489,8 +489,7 @@ public class Tailer implements Runnable {
                 if (reader != null) {
                     reader.close();
                 }
-            }
-            catch (final IOException e) {
+            } catch (final IOException e) {
                 listener.handle(e);
             }
             stop();
@@ -520,27 +519,27 @@ public class Tailer implements Runnable {
             while (getRun() && ((num = reader.read(inbuf)) != EOF)) {
                 for (int i = 0; i < num; i++) {
                     final byte ch = inbuf[i];
-                    switch ( ch ) {
-                        case '\n':
-                            seenCR = false; // swallow CR before LF
+                    switch (ch) {
+                    case '\n':
+                        seenCR = false; // swallow CR before LF
+                        listener.handle(new String(lineBuf.toByteArray(), charset));
+                        lineBuf.reset();
+                        rePos = pos + i + 1;
+                        break;
+                    case '\r':
+                        if (seenCR) {
+                            lineBuf.write('\r');
+                        }
+                        seenCR = true;
+                        break;
+                    default:
+                        if (seenCR) {
+                            seenCR = false; // swallow final CR
                             listener.handle(new String(lineBuf.toByteArray(), charset));
                             lineBuf.reset();
                             rePos = pos + i + 1;
-                            break;
-                        case '\r':
-                            if (seenCR) {
-                                lineBuf.write('\r');
-                            }
-                            seenCR = true;
-                            break;
-                        default:
-                            if (seenCR) {
-                                seenCR = false; // swallow final CR
-                                listener.handle(new String(lineBuf.toByteArray(), charset));
-                                lineBuf.reset();
-                                rePos = pos + i + 1;
-                            }
-                            lineBuf.write(ch);
+                        }
+                        lineBuf.write(ch);
                     }
                 }
                 pos = reader.getFilePointer();


[commons-io] 02/06: Formatting.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git

commit f17997c19b67bb07d51124ba751d5fc7f6e892b0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 12 09:58:14 2020 -0500

    Formatting.
---
 .../io/input/WindowsLineEndingInputStream.java     | 23 +++++++++++-----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java b/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
index ccf321e..39964f7 100644
--- a/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
@@ -57,7 +57,7 @@ public class WindowsLineEndingInputStream  extends InputStream {
     private int readWithUpdate() throws IOException {
         final int target = this.target.read();
         eofSeen = target == -1;
-        if ( eofSeen ) {
+        if (eofSeen) {
             return target;
         }
         slashRSeen = target == '\r';
@@ -70,20 +70,19 @@ public class WindowsLineEndingInputStream  extends InputStream {
      */
     @Override
     public int read() throws IOException {
-        if ( eofSeen ) {
+        if (eofSeen) {
             return eofGame();
-        } else if ( injectSlashN ) {
+        } else if (injectSlashN) {
             injectSlashN = false;
             return '\n';
         } else {
             final boolean prevWasSlashR = slashRSeen;
             final int target = readWithUpdate();
-            if ( eofSeen ) {
+            if (eofSeen) {
                 return eofGame();
             }
-            if ( target == '\n' ) {
-                if ( !prevWasSlashR )
-                {
+            if (target == '\n') {
+                if (!prevWasSlashR) {
                     injectSlashN = true;
                     return '\r';
                 }
@@ -98,14 +97,14 @@ public class WindowsLineEndingInputStream  extends InputStream {
      */
 
     private int eofGame() {
-        if ( !ensureLineFeedAtEndOfFile ) {
+        if (!ensureLineFeedAtEndOfFile) {
             return -1;
         }
-        if ( !slashNSeen && !slashRSeen ) {
+        if (!slashNSeen && !slashRSeen) {
             slashRSeen = true;
             return '\r';
         }
-        if ( !slashNSeen ) {
+        if (!slashNSeen) {
             slashRSeen = false;
             slashNSeen = true;
             return '\n';
@@ -127,7 +126,7 @@ public class WindowsLineEndingInputStream  extends InputStream {
      * {@inheritDoc}
      */
     @Override
-    public synchronized void mark( final int readlimit ) {
-        throw new UnsupportedOperationException( "Mark not supported" );
+    public synchronized void mark(final int readlimit) {
+        throw new UnsupportedOperationException("Mark not supported");
     }
 }


[commons-io] 03/06: Formatting.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git

commit 6f82a453f410ffbf03a7a518ba2de48074af7ab8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 12 09:59:04 2020 -0500

    Formatting.
---
 .../commons/io/input/UnixLineEndingInputStream.java | 21 ++++++++++-----------
 .../io/input/WindowsLineEndingInputStream.java      |  2 +-
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
index fba1944..1b92bb8 100644
--- a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
@@ -43,7 +43,7 @@ public class UnixLineEndingInputStream extends InputStream {
      * @param in                        The input stream to wrap
      * @param ensureLineFeedAtEndOfFile true to ensure that the file ends with LF
      */
-    public UnixLineEndingInputStream( final InputStream in, final boolean ensureLineFeedAtEndOfFile ) {
+    public UnixLineEndingInputStream(final InputStream in, final boolean ensureLineFeedAtEndOfFile) {
         this.target = in;
         this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
     }
@@ -56,7 +56,7 @@ public class UnixLineEndingInputStream extends InputStream {
     private int readWithUpdate() throws IOException {
         final int target = this.target.read();
         eofSeen = target == -1;
-        if ( eofSeen ) {
+        if (eofSeen) {
             return target;
         }
         slashNSeen = target == '\n';
@@ -70,19 +70,18 @@ public class UnixLineEndingInputStream extends InputStream {
     @Override
     public int read() throws IOException {
         final boolean previousWasSlashR = slashRSeen;
-        if ( eofSeen ) {
+        if (eofSeen) {
             return eofGame(previousWasSlashR);
         }
         final int target = readWithUpdate();
-        if ( eofSeen ) {
+        if (eofSeen) {
             return eofGame(previousWasSlashR);
         }
-        if (slashRSeen)
-        {
+        if (slashRSeen) {
             return '\n';
         }
 
-        if ( previousWasSlashR && slashNSeen){
+        if (previousWasSlashR && slashNSeen) {
             return read();
         }
 
@@ -95,10 +94,10 @@ public class UnixLineEndingInputStream extends InputStream {
      * @return The next char to output to the stream
      */
     private int eofGame(final boolean previousWasSlashR) {
-        if ( previousWasSlashR || !ensureLineFeedAtEndOfFile ) {
+        if (previousWasSlashR || !ensureLineFeedAtEndOfFile) {
             return -1;
         }
-        if ( !slashNSeen ) {
+        if (!slashNSeen) {
             slashNSeen = true;
             return '\n';
         }
@@ -119,7 +118,7 @@ public class UnixLineEndingInputStream extends InputStream {
      * {@inheritDoc}
      */
     @Override
-    public synchronized void mark( final int readlimit ) {
-        throw new UnsupportedOperationException( "Mark notsupported" );
+    public synchronized void mark(final int readlimit) {
+        throw new UnsupportedOperationException("Mark notsupported");
     }
 }
diff --git a/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java b/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
index 39964f7..2a81251 100644
--- a/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
@@ -44,7 +44,7 @@ public class WindowsLineEndingInputStream  extends InputStream {
      * @param in                        The input stream to wrap
      * @param ensureLineFeedAtEndOfFile true to ensure that the file ends with CRLF
      */
-    public WindowsLineEndingInputStream( final InputStream in, final boolean ensureLineFeedAtEndOfFile ) {
+    public WindowsLineEndingInputStream(final InputStream in, final boolean ensureLineFeedAtEndOfFile) {
         this.target = in;
         this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
     }


[commons-io] 05/06: Remove unused exception from private method signature.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git

commit b2d075642ac1d370cd8fdd8b80d29f1c88ca4757
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 12 10:01:24 2020 -0500

    Remove unused exception from private method signature.
---
 src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
index c4ff400..5d45b6f 100644
--- a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
+++ b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
@@ -122,9 +122,8 @@ public class ReversedLinesFileReader implements Closeable {
          * Reads a line.
          *
          * @return the line or null
-         * @throws IOException if there is an error reading from the file
          */
-        private String readLine() throws IOException {
+        private String readLine() {
 
             String line = null;
             int newLineMatchByteCount;


[commons-io] 04/06: Better private ivar name.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git

commit 76d42c0a20245948546d20c8548674d17f44c7a7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 12 10:00:09 2020 -0500

    Better private ivar name.
---
 .../commons/io/input/ReversedLinesFileReader.java  | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
index 528c7db..c4ff400 100644
--- a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
+++ b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
@@ -152,7 +152,7 @@ public class ReversedLinesFileReader implements Closeable {
                     final byte[] lineData = new byte[lineLengthBytes];
                     System.arraycopy(data, lineStart, lineData, 0, lineLengthBytes);
 
-                    line = new String(lineData, encoding);
+                    line = new String(lineData, charset);
 
                     currentLastBytePos = i - newLineMatchByteCount;
                     break; // found line
@@ -171,7 +171,7 @@ public class ReversedLinesFileReader implements Closeable {
             // --- last file part handling ---
             if (isLastFilePart && leftOver != null) {
                 // there will be no line break anymore, this is the first line of the file
-                line = new String(leftOver, encoding);
+                line = new String(leftOver, charset);
                 leftOver = null;
             }
 
@@ -197,7 +197,7 @@ public class ReversedLinesFileReader implements Closeable {
             // NO 1 was the last FilePart, we're finished
             if (leftOver != null) {
                 throw new IllegalStateException("Unexpected leftover of the last block: leftOverOfThisFilePart="
-                        + new String(leftOver, encoding));
+                        + new String(leftOver, charset));
             }
             return null;
         }
@@ -207,7 +207,7 @@ public class ReversedLinesFileReader implements Closeable {
     private static final int DEFAULT_BLOCK_SIZE = IOUtils.DEFAULT_BUFFER_SIZE;
 
     private final int blockSize;
-    private final Charset encoding;
+    private final Charset charset;
     private final SeekableByteChannel channel;
     private final long totalByteLength;
     private final long totalBlockCount;
@@ -303,32 +303,32 @@ public class ReversedLinesFileReader implements Closeable {
      */
     public ReversedLinesFileReader(final Path file, final int blockSize, final Charset charset) throws IOException {
         this.blockSize = blockSize;
-        this.encoding = Charsets.toCharset(charset);
+        this.charset = Charsets.toCharset(charset);
 
         // --- check & prepare encoding ---
-        final CharsetEncoder charsetEncoder = this.encoding.newEncoder();
+        final CharsetEncoder charsetEncoder = this.charset.newEncoder();
         final float maxBytesPerChar = charsetEncoder.maxBytesPerChar();
         if (maxBytesPerChar == 1f) {
             // all one byte encodings are no problem
             byteDecrement = 1;
-        } else if (this.encoding == StandardCharsets.UTF_8) {
+        } else if (this.charset == StandardCharsets.UTF_8) {
             // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte
             // can never be a newline byte
             // http://en.wikipedia.org/wiki/UTF-8
             byteDecrement = 1;
-        } else if (this.encoding == Charset.forName("Shift_JIS") || // Same as for UTF-8
+        } else if (this.charset == Charset.forName("Shift_JIS") || // Same as for UTF-8
         // http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
-                this.encoding == Charset.forName("windows-31j") || // Windows code page 932 (Japanese)
-                this.encoding == Charset.forName("x-windows-949") || // Windows code page 949 (Korean)
-                this.encoding == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese)
-                this.encoding == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese)
+                this.charset == Charset.forName("windows-31j") || // Windows code page 932 (Japanese)
+                this.charset == Charset.forName("x-windows-949") || // Windows code page 949 (Korean)
+                this.charset == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese)
+                this.charset == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese)
             byteDecrement = 1;
-        } else if (this.encoding == StandardCharsets.UTF_16BE || this.encoding == StandardCharsets.UTF_16LE) {
+        } else if (this.charset == StandardCharsets.UTF_16BE || this.charset == StandardCharsets.UTF_16LE) {
             // UTF-16 new line sequences are not allowed as second tuple of four byte
             // sequences,
             // however byte order has to be specified
             byteDecrement = 2;
-        } else if (this.encoding == StandardCharsets.UTF_16) {
+        } else if (this.charset == StandardCharsets.UTF_16) {
             throw new UnsupportedEncodingException(
                     "For UTF-16, you need to specify the byte order (use UTF-16BE or " + "UTF-16LE)");
         } else {
@@ -338,8 +338,8 @@ public class ReversedLinesFileReader implements Closeable {
 
         // NOTE: The new line sequences are matched in the order given, so it is
         // important that \r\n is BEFORE \n
-        this.newLineSequences = new byte[][] { "\r\n".getBytes(this.encoding), "\n".getBytes(this.encoding),
-                "\r".getBytes(this.encoding) };
+        this.newLineSequences = new byte[][] { "\r\n".getBytes(this.charset), "\n".getBytes(this.charset),
+                "\r".getBytes(this.charset) };
 
         this.avoidNewlineSplitBufferSize = newLineSequences[0].length;