Warning: session_start(): open(/var/lib/php/sessions/sess_evc4jlrsdu9qv3fhlt0fogvjbe, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
set flag LeanMode.
p {
ByteCountingLineReader r = new(new ByteArrayInputStream(toUtf8("Hello\r\nWorld\n")));
while (!r.ended()) {
long count = r.byteCount();
System.out.println("Line at byte " + count + ": " + r.readLine());
}
r.close();
}
static class ByteCountingLineReader implements Closeable {
InputStream in;
long _byteCount;
int bufferedByte = -1;
boolean ended;
// in should be a buffered stream!
ByteCountingLineReader(InputStream in) {
this.in = in;
}
ByteCountingLineReader(File f) {
in = bufferedInputStream(f);
}
String readLine() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (ended) null;
while true {
int c = read();
if (ended && baos.isEmpty()) null;
if (ended || c == '\n') break;
if (c == '\r') {
c = read();
if (c != '\n' && !ended)
bufferedByte = c;
break;
}
baos.write(c);
}
return fromUtf8(baos.toByteArray());
}
int read() throws IOException {
if (bufferedByte >= 0) {
int b = bufferedByte;
bufferedByte = -1;
return b;
}
int c = in.read();
if (c < 0) ended = true;
++_byteCount;
return c;
}
long byteCount() {
return bufferedByte >= 0 ? _byteCount-1 : _byteCount;
}
public void close() throws IOException {
if (in != null) try {
in.close();
} finally { in = null; }
}
bool ended() { ret ended; }
}