Skip to content

Commit 0986e79

Browse files
committed
<action issue="IO-437" dev="ggregory" type="add">
Make IOUtils.EOF public and reuse it in various classes. </action> git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1586350 13f79535-47bb-0310-9956-ffa450edef68
1 parent bdd4555 commit 0986e79

17 files changed

Lines changed: 69 additions & 36 deletions

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ The <action> type attribute can be add,update,fix,remove.
188188
<action issue="IO-436" dev="ggregory" type="fix" due-to="christoph.schneegans">
189189
Improper JavaDoc comment for FilenameUtils.indexOfExtension.
190190
</action>
191+
<action issue="IO-437" dev="ggregory" type="add">
192+
Make IOUtils.EOF public and reuse it in various classes.
193+
</action>
191194
</release>
192195
<!-- The release date is the date RC is cut -->
193196
<release version="2.4" date="2012-06-12" description="New features and bug fixes.">

src/main/java/org/apache/commons/io/EndianUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.commons.io;
1818

19+
import static org.apache.commons.io.IOUtils.EOF;
20+
1921
import java.io.EOFException;
2022
import java.io.IOException;
2123
import java.io.InputStream;
@@ -479,7 +481,7 @@ private static int read(final InputStream input)
479481
{
480482
final int value = input.read();
481483

482-
if( -1 == value ) {
484+
if( EOF == value ) {
483485
throw new EOFException( "Unexpected EOF reached" );
484486
}
485487

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.commons.io.input;
1818

19+
import static org.apache.commons.io.IOUtils.EOF;
20+
1921
import java.io.IOException;
2022
import java.io.InputStream;
2123

@@ -73,7 +75,7 @@ public void close() throws IOException {
7375
*/
7476
@Override
7577
protected void afterRead(final int n) throws IOException {
76-
if (n == -1) {
78+
if (n == EOF) {
7779
close();
7880
}
7981
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.commons.io.input;
1919

20+
import static org.apache.commons.io.IOUtils.EOF;
21+
2022
import java.io.IOException;
2123
import java.io.InputStream;
2224
import java.nio.ByteBuffer;
@@ -39,8 +41,6 @@ public class CharSequenceInputStream extends InputStream {
3941

4042
private static final int BUFFER_SIZE = 2048;
4143

42-
private static final int EOS = -1;
43-
4444
private static final int NO_MARK = -1;
4545

4646
private final CharsetEncoder encoder;
@@ -139,7 +139,7 @@ public int read(final byte[] b, int off, int len) throws IOException {
139139
return 0; // must return 0 for zero length read
140140
}
141141
if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) {
142-
return EOS;
142+
return EOF;
143143
}
144144
int bytesRead = 0;
145145
while (len > 0) {
@@ -156,7 +156,7 @@ public int read(final byte[] b, int off, int len) throws IOException {
156156
}
157157
}
158158
}
159-
return bytesRead == 0 && !this.cbuf.hasRemaining() ? EOS : bytesRead;
159+
return bytesRead == 0 && !this.cbuf.hasRemaining() ? EOF : bytesRead;
160160
}
161161

162162
@Override
@@ -167,7 +167,7 @@ public int read() throws IOException {
167167
} else {
168168
fillBuffer();
169169
if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) {
170-
return EOS;
170+
return EOF;
171171
}
172172
}
173173
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.commons.io.input;
1818

19+
import static org.apache.commons.io.IOUtils.EOF;
20+
1921
import java.io.Reader;
2022
import java.io.Serializable;
2123

@@ -81,7 +83,7 @@ public boolean markSupported() {
8183
@Override
8284
public int read() {
8385
if (idx >= charSequence.length()) {
84-
return -1;
86+
return EOF;
8587
} else {
8688
return charSequence.charAt(idx++);
8789
}
@@ -99,7 +101,7 @@ public int read() {
99101
@Override
100102
public int read(final char[] array, final int offset, final int length) {
101103
if (idx >= charSequence.length()) {
102-
return -1;
104+
return EOF;
103105
}
104106
if (array == null) {
105107
throw new NullPointerException("Character array is missing");
@@ -111,7 +113,7 @@ public int read(final char[] array, final int offset, final int length) {
111113
int count = 0;
112114
for (int i = 0; i < length; i++) {
113115
final int c = read();
114-
if (c == -1) {
116+
if (c == EOF) {
115117
return count;
116118
}
117119
array[offset + i] = (char)c;
@@ -142,7 +144,7 @@ public long skip(final long n) {
142144
"Number of characters to skip is less than zero: " + n);
143145
}
144146
if (idx >= charSequence.length()) {
145-
return -1;
147+
return EOF;
146148
}
147149
final int dest = (int)Math.min(charSequence.length(), idx + n);
148150
final int count = dest - idx;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
*/
1717
package org.apache.commons.io.input;
1818

19+
import static org.apache.commons.io.IOUtils.EOF;
20+
1921
import java.io.InputStream;
2022

2123
/**
22-
* Closed input stream. This stream returns -1 to all attempts to read
24+
* Closed input stream. This stream returns EOF to all attempts to read
2325
* something from the stream.
2426
* <p>
2527
* Typically uses of this class include testing for corner cases in methods
@@ -43,7 +45,7 @@ public class ClosedInputStream extends InputStream {
4345
*/
4446
@Override
4547
public int read() {
46-
return -1;
48+
return EOF;
4749
}
4850

4951
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.commons.io.input;
1818

19+
import static org.apache.commons.io.IOUtils.EOF;
20+
1921
import java.io.IOException;
2022
import java.io.InputStream;
2123

@@ -68,7 +70,7 @@ public synchronized long skip(final long length) throws IOException {
6870
*/
6971
@Override
7072
protected synchronized void afterRead(final int n) {
71-
if (n != -1) {
73+
if (n != EOF) {
7274
this.count += n;
7375
}
7476
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.commons.io.input;
1818

19+
import static org.apache.commons.io.IOUtils.EOF;
20+
1921
import java.io.IOException;
2022
import java.io.InputStream;
2123

@@ -76,7 +78,7 @@ public int read()
7678
}
7779
else
7880
{
79-
return -1;
81+
return EOF;
8082
}
8183
}
8284
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.commons.io.input;
1818

19+
import static org.apache.commons.io.IOUtils.EOF;
20+
1921
import java.io.EOFException;
2022
import java.io.IOException;
2123
import java.io.InputStream;
@@ -332,7 +334,7 @@ private int doEndOfFile() throws EOFException {
332334
if (throwEofException) {
333335
throw new EOFException();
334336
}
335-
return -1;
337+
return EOF;
336338
}
337339

338340
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.commons.io.input;
1818

19+
import static org.apache.commons.io.IOUtils.EOF;
20+
1921
import java.io.EOFException;
2022
import java.io.IOException;
2123
import java.io.Reader;
@@ -315,7 +317,7 @@ private int doEndOfFile() throws EOFException {
315317
if (throwEofException) {
316318
throw new EOFException();
317319
}
318-
return -1;
320+
return EOF;
319321
}
320322

321323
}

0 commit comments

Comments
 (0)