aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
diff options
context:
space:
mode:
authorKristian Rosenvold <krosenvold@apache.org>2015-04-14 16:10:27 +0000
committerKristian Rosenvold <krosenvold@apache.org>2015-04-14 16:10:27 +0000
commit071dbe7c211380bd4bed252c9b7a767279d112bc (patch)
treeaf8f11239681fb8b1b1e7609f871e87a7040fd02 /src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
parentc0eb48f7e83987c5ed112b82f0d651aff5149ae4 (diff)
downloadapache-commons-io-071dbe7c211380bd4bed252c9b7a767279d112bc.tar.gz
MASSEMBLY-753 CR only handling. Unreleased code so no separate issue for commons
According to http://en.wikipedia.org/wiki/Newline#Representations we're probably be talking about files originating on old v9 MacOS'es or a Commodore 64 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1673459 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java')
-rw-r--r--src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java22
1 files changed, 16 insertions, 6 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 a34647ac..6aa234de 100644
--- a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
@@ -29,6 +29,8 @@ public class UnixLineEndingInputStream extends InputStream {
private boolean slashNSeen = false;
+ private boolean slashRSeen = false;
+
private boolean eofSeen = false;
private final InputStream target;
@@ -53,6 +55,7 @@ public class UnixLineEndingInputStream extends InputStream {
return target;
}
slashNSeen = target == '\n';
+ slashRSeen = target == '\r';
return target;
}
@@ -62,23 +65,30 @@ public class UnixLineEndingInputStream extends InputStream {
@Override
public int read() throws IOException {
+ boolean previousWasSlashR = slashRSeen;
if ( eofSeen ) {
- return eofGame();
+ return eofGame(previousWasSlashR);
}
else {
int target = readWithUpdate();
if ( eofSeen ) {
- return eofGame();
+ return eofGame(previousWasSlashR);
+ }
+ if (slashRSeen)
+ {
+ return '\n';
}
- if ( target == '\r' ) {
- target = readWithUpdate();
+
+ if ( previousWasSlashR && slashNSeen){
+ return read();
}
+
return target;
}
}
- private int eofGame() {
- if ( !ensureLineFeedAtEndOfFile ) {
+ private int eofGame(boolean previousWasSlashR) {
+ if ( previousWasSlashR || !ensureLineFeedAtEndOfFile ) {
return -1;
}
if ( !slashNSeen ) {