in vault-core/src/main/java/org/apache/jackrabbit/vault/util/LineInputStream.java [89:162]
public int read(byte b[], int off, int len) throws IOException {
if (isEof) {
if (spool == null) {
if (state != STATE_INIT) {
spool = lineFeed;
state = STATE_INIT;
} else {
return -1;
}
}
}
int total = 0;
while (total < len) {
if (spool != null) {
b[off+(total++)] = spool[spoolPos++];
if (spoolPos == spool.length) {
spool = null;
spoolPos = 0;
}
} else {
if (pos == end) {
int ret = fillBuffer();
if (ret == 0 && pos == end) {
// in this case we didn't get more, so flush
pos = end = 0;
continue;
} else if (ret == -1) {
break;
}
}
byte c = buffer[pos++];
if (c == 0x0a) {
switch (state) {
case STATE_INIT:
state = STATE_LF;
break;
case STATE_CR:
state = STATE_CRLF;
break;
case STATE_LF:
spool = lineFeed;
break;
case STATE_CRLF:
spool = lineFeed;
state = STATE_LF;
}
} else if (c == 0x0d) {
switch (state) {
case STATE_INIT:
state = STATE_CR;
break;
case STATE_LF:
state = STATE_CRLF;
break;
case STATE_CR:
spool = lineFeed;
break;
case STATE_CRLF:
spool = lineFeed;
state = STATE_CR;
}
} else {
if (state != STATE_INIT) {
spool = lineSpool;
lineSpool[lineSpool.length - 1] = c;
state = STATE_INIT;
} else {
b[off + (total++)] = c;
}
}
}
}
return total;
}