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


The following commit(s) were added to refs/heads/master by this push:
     new b85b9a3e Internal clean ups to more easily compare these two very 
similar classes
b85b9a3e is described below

commit b85b9a3e46665b32cf8a09673307ef6579b72ae5
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun May 7 13:47:56 2023 -0400

    Internal clean ups to more easily compare these two very similar classes
---
 .../io/input/UnixLineEndingInputStream.java        | 20 +++++-----
 .../io/input/WindowsLineEndingInputStream.java     | 46 +++++++++++-----------
 2 files changed, 34 insertions(+), 32 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 35a68493..175776f5 100644
--- a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
@@ -30,15 +30,15 @@ import java.io.InputStream;
  */
 public class UnixLineEndingInputStream extends InputStream {
 
-    private boolean atSlashLf;
+    private boolean atEos;
 
     private boolean atSlashCr;
 
-    private boolean atEos;
+    private boolean atSlashLf;
 
-    private final InputStream target;
+    private final InputStream in;
 
-    private final boolean ensureLineFeedAtEndOfFile;
+    private final boolean lineFeedAtEndOfFile;
 
     /**
      * Creates an input stream that filters another stream
@@ -47,8 +47,8 @@ public class UnixLineEndingInputStream extends InputStream {
      * @param ensureLineFeedAtEndOfFile true to ensure that the file ends with 
LF
      */
     public UnixLineEndingInputStream(final InputStream inputStream, final 
boolean ensureLineFeedAtEndOfFile) {
-        this.target = inputStream;
-        this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
+        this.in = inputStream;
+        this.lineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
     }
 
     /**
@@ -58,7 +58,7 @@ public class UnixLineEndingInputStream extends InputStream {
     @Override
     public void close() throws IOException {
         super.close();
-        target.close();
+        in.close();
     }
 
     /**
@@ -68,7 +68,7 @@ public class UnixLineEndingInputStream extends InputStream {
      * @return The next char to output to the stream.
      */
     private int handleEos(final boolean previousWasSlashCr) {
-        if (previousWasSlashCr || !ensureLineFeedAtEndOfFile) {
+        if (previousWasSlashCr || !lineFeedAtEndOfFile) {
             return EOF;
         }
         if (!atSlashLf) {
@@ -116,13 +116,13 @@ public class UnixLineEndingInputStream extends 
InputStream {
      * @throws IOException upon error
      */
     private int readWithUpdate() throws IOException {
-        final int target = this.target.read();
+        final int target = this.in.read();
         atEos = target == EOF;
         if (atEos) {
             return target;
         }
-        atSlashLf = target == LF;
         atSlashCr = target == CR;
+        atSlashLf = target == LF;
         return target;
     }
 }
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 bb9b15f3..ee908e1d 100644
--- 
a/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
+++ 
b/src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java
@@ -30,17 +30,17 @@ import java.io.InputStream;
  */
 public class WindowsLineEndingInputStream  extends InputStream {
 
-    private boolean atSlashCr;
+    private boolean atEos;
 
-    private boolean atSlashN;
+    private boolean atSlashCr;
 
-    private boolean injectSlashN;
+    private boolean atSlashLf;
 
-    private boolean atEos;
+    private final InputStream in;
 
-    private final InputStream target;
+    private boolean injectSlashLf;
 
-    private final boolean ensureLineFeedAtEndOfFile;
+    private final boolean lineFeedAtEndOfFile;
 
     /**
      * Creates an input stream that filters another stream
@@ -49,35 +49,37 @@ public class WindowsLineEndingInputStream  extends 
InputStream {
      * @param ensureLineFeedAtEndOfFile true to ensure that the file ends with 
CRLF
      */
     public WindowsLineEndingInputStream(final InputStream in, final boolean 
ensureLineFeedAtEndOfFile) {
-        this.target = in;
-        this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
+        this.in = in;
+        this.lineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
     }
 
     /**
      * Closes the stream. Also closes the underlying stream.
+     *
      * @throws IOException upon error
      */
     @Override
     public void close() throws IOException {
         super.close();
-        target.close();
+        in.close();
     }
 
     /**
-     * Handles the EOF-handling at the end of the stream
+     * Handles the end of stream condition.
+     *
      * @return The next char to output to the stream
      */
-    private int eofGame() {
-        if (!ensureLineFeedAtEndOfFile) {
+    private int handleEos() {
+        if (!lineFeedAtEndOfFile) {
             return EOF;
         }
-        if (!atSlashN && !atSlashCr) {
+        if (!atSlashLf && !atSlashCr) {
             atSlashCr = true;
             return CR;
         }
-        if (!atSlashN) {
+        if (!atSlashLf) {
             atSlashCr = false;
-            atSlashN = true;
+            atSlashLf = true;
             return LF;
         }
         return EOF;
@@ -97,19 +99,19 @@ public class WindowsLineEndingInputStream  extends 
InputStream {
     @Override
     public int read() throws IOException {
         if (atEos) {
-            return eofGame();
+            return handleEos();
         }
-        if (injectSlashN) {
-            injectSlashN = false;
+        if (injectSlashLf) {
+            injectSlashLf = false;
             return LF;
         }
         final boolean prevWasSlashR = atSlashCr;
         final int target = readWithUpdate();
         if (atEos) {
-            return eofGame();
+            return handleEos();
         }
         if (target == LF && !prevWasSlashR) {
-            injectSlashN = true;
+            injectSlashLf = true;
             return CR;
         }
         return target;
@@ -121,13 +123,13 @@ public class WindowsLineEndingInputStream  extends 
InputStream {
      * @throws IOException upon error
      */
     private int readWithUpdate() throws IOException {
-        final int target = this.target.read();
+        final int target = this.in.read();
         atEos = target == EOF;
         if (atEos) {
             return target;
         }
         atSlashCr = target == CR;
-        atSlashN = target == LF;
+        atSlashLf = target == LF;
         return target;
     }
 }

Reply via email to