@Override public int read() throws IOException { if (nonBlockingEnabled) return read(0L, false); return in.read (); }
/** * Attempts to read a character from the input stream for a specific * period of time. * @param timeout The amount of time to wait for the character * @return The character read, -1 if EOF is reached, or -2 if the * read timed out. */ public int read(long timeout) throws IOException { if (!nonBlockingEnabled || isShutdown) { throw new UnsupportedOperationException ("read() with timeout " + "cannot be called as non-blocking operation is disabled"); } return read(timeout, false); }
/** * Peeks to see if there is a byte waiting in the input stream without * actually consuming the byte. * * @param timeout The amount of time to wait, 0 == forever * @return -1 on eof, -2 if the timeout expired with no available input * or the character that was read (without consuming it). */ public int peek(long timeout) throws IOException { if (!nonBlockingEnabled || isShutdown) { throw new UnsupportedOperationException ("peek() " + "cannot be called as non-blocking operation is disabled"); } return read(timeout, true); }
/** * This version of read() is very specific to jline's purposes, it * will always always return a single byte at a time, rather than filling * the entire buffer. */ @Override public int read (byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } int c; if (nonBlockingEnabled) c = this.read(0L); else c = in.read(); if (c == -1) { return -1; } b[off] = (byte)c; return 1; }
/** * Attempts to read a character from the input stream for a specific * period of time. * @param timeout The amount of time to wait for the character * @return The character read, -1 if EOF is reached, or -2 if the * read timed out. */ public int read(long timeout) throws IOException { if (!nonBlockingEnabled || isShutdown) { throw new UnsupportedOperationException ("read() with timeout " + "cannot be called as non-blocking operation is disabled"); } return read(timeout, false); }
@Override public int read() throws IOException { if (nonBlockingEnabled) return read(0L, false); return in.read (); }
/** * Peeks to see if there is a byte waiting in the input stream without * actually consuming the byte. * * @param timeout The amount of time to wait, 0 == forever * @return -1 on eof, -2 if the timeout expired with no available input * or the character that was read (without consuming it). */ public int peek(long timeout) throws IOException { if (!nonBlockingEnabled || isShutdown) { throw new UnsupportedOperationException ("peek() " + "cannot be called as non-blocking operation is disabled"); } return read(timeout, true); }
/** * This version of read() is very specific to jline's purposes, it * will always always return a single byte at a time, rather than filling * the entire buffer. */ @Override public int read (byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } int c; if (nonBlockingEnabled) c = this.read(0L); else c = in.read(); if (c == -1) { return -1; } b[off] = (byte)c; return 1; }