Skip to content

Commit b85b9a3

Browse files
committed
Internal clean ups to more easily compare these two very similar classes
1 parent 6a9cb38 commit b85b9a3

2 files changed

Lines changed: 34 additions & 32 deletions

File tree

src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
*/
3131
public class UnixLineEndingInputStream extends InputStream {
3232

33-
private boolean atSlashLf;
33+
private boolean atEos;
3434

3535
private boolean atSlashCr;
3636

37-
private boolean atEos;
37+
private boolean atSlashLf;
3838

39-
private final InputStream target;
39+
private final InputStream in;
4040

41-
private final boolean ensureLineFeedAtEndOfFile;
41+
private final boolean lineFeedAtEndOfFile;
4242

4343
/**
4444
* Creates an input stream that filters another stream
@@ -47,8 +47,8 @@ public class UnixLineEndingInputStream extends InputStream {
4747
* @param ensureLineFeedAtEndOfFile true to ensure that the file ends with LF
4848
*/
4949
public UnixLineEndingInputStream(final InputStream inputStream, final boolean ensureLineFeedAtEndOfFile) {
50-
this.target = inputStream;
51-
this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
50+
this.in = inputStream;
51+
this.lineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
5252
}
5353

5454
/**
@@ -58,7 +58,7 @@ public UnixLineEndingInputStream(final InputStream inputStream, final boolean en
5858
@Override
5959
public void close() throws IOException {
6060
super.close();
61-
target.close();
61+
in.close();
6262
}
6363

6464
/**
@@ -68,7 +68,7 @@ public void close() throws IOException {
6868
* @return The next char to output to the stream.
6969
*/
7070
private int handleEos(final boolean previousWasSlashCr) {
71-
if (previousWasSlashCr || !ensureLineFeedAtEndOfFile) {
71+
if (previousWasSlashCr || !lineFeedAtEndOfFile) {
7272
return EOF;
7373
}
7474
if (!atSlashLf) {
@@ -116,13 +116,13 @@ public int read() throws IOException {
116116
* @throws IOException upon error
117117
*/
118118
private int readWithUpdate() throws IOException {
119-
final int target = this.target.read();
119+
final int target = this.in.read();
120120
atEos = target == EOF;
121121
if (atEos) {
122122
return target;
123123
}
124-
atSlashLf = target == LF;
125124
atSlashCr = target == CR;
125+
atSlashLf = target == LF;
126126
return target;
127127
}
128128
}

src/main/java/org/apache/commons/io/input/WindowsLineEndingInputStream.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
*/
3131
public class WindowsLineEndingInputStream extends InputStream {
3232

33-
private boolean atSlashCr;
33+
private boolean atEos;
3434

35-
private boolean atSlashN;
35+
private boolean atSlashCr;
3636

37-
private boolean injectSlashN;
37+
private boolean atSlashLf;
3838

39-
private boolean atEos;
39+
private final InputStream in;
4040

41-
private final InputStream target;
41+
private boolean injectSlashLf;
4242

43-
private final boolean ensureLineFeedAtEndOfFile;
43+
private final boolean lineFeedAtEndOfFile;
4444

4545
/**
4646
* Creates an input stream that filters another stream
@@ -49,35 +49,37 @@ public class WindowsLineEndingInputStream extends InputStream {
4949
* @param ensureLineFeedAtEndOfFile true to ensure that the file ends with CRLF
5050
*/
5151
public WindowsLineEndingInputStream(final InputStream in, final boolean ensureLineFeedAtEndOfFile) {
52-
this.target = in;
53-
this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
52+
this.in = in;
53+
this.lineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
5454
}
5555

5656
/**
5757
* Closes the stream. Also closes the underlying stream.
58+
*
5859
* @throws IOException upon error
5960
*/
6061
@Override
6162
public void close() throws IOException {
6263
super.close();
63-
target.close();
64+
in.close();
6465
}
6566

6667
/**
67-
* Handles the EOF-handling at the end of the stream
68+
* Handles the end of stream condition.
69+
*
6870
* @return The next char to output to the stream
6971
*/
70-
private int eofGame() {
71-
if (!ensureLineFeedAtEndOfFile) {
72+
private int handleEos() {
73+
if (!lineFeedAtEndOfFile) {
7274
return EOF;
7375
}
74-
if (!atSlashN && !atSlashCr) {
76+
if (!atSlashLf && !atSlashCr) {
7577
atSlashCr = true;
7678
return CR;
7779
}
78-
if (!atSlashN) {
80+
if (!atSlashLf) {
7981
atSlashCr = false;
80-
atSlashN = true;
82+
atSlashLf = true;
8183
return LF;
8284
}
8385
return EOF;
@@ -97,19 +99,19 @@ public synchronized void mark(final int readlimit) {
9799
@Override
98100
public int read() throws IOException {
99101
if (atEos) {
100-
return eofGame();
102+
return handleEos();
101103
}
102-
if (injectSlashN) {
103-
injectSlashN = false;
104+
if (injectSlashLf) {
105+
injectSlashLf = false;
104106
return LF;
105107
}
106108
final boolean prevWasSlashR = atSlashCr;
107109
final int target = readWithUpdate();
108110
if (atEos) {
109-
return eofGame();
111+
return handleEos();
110112
}
111113
if (target == LF && !prevWasSlashR) {
112-
injectSlashN = true;
114+
injectSlashLf = true;
113115
return CR;
114116
}
115117
return target;
@@ -121,13 +123,13 @@ public int read() throws IOException {
121123
* @throws IOException upon error
122124
*/
123125
private int readWithUpdate() throws IOException {
124-
final int target = this.target.read();
126+
final int target = this.in.read();
125127
atEos = target == EOF;
126128
if (atEos) {
127129
return target;
128130
}
129131
atSlashCr = target == CR;
130-
atSlashN = target == LF;
132+
atSlashLf = target == LF;
131133
return target;
132134
}
133135
}

0 commit comments

Comments
 (0)