/** {@inheritDoc} */ public int read(final byte[] b, final int off, final int len) throws IOException { return byteInput.read(b, off, len); }
/** {@inheritDoc} */ public int read() throws IOException { return byteInput.read(); }
/** {@inheritDoc} */ public int read(final byte[] b) throws IOException { return byteInput.read(b); }
/** {@inheritDoc} */ public int read() throws IOException { final int limit = this.limit; if (limit == -1) { return -1; } final int position = this.position; final byte[] buffer = this.buffer; if (position == limit) { if ((this.limit = byteInput.read(buffer)) == -1) { this.position = 0; return -1; } else { this.position = 1; return buffer[0] & 0xff; } } else { this.position = position + 1; return buffer[position] & 0xff; } }
@Override public int read(byte[] array, int offset, int length) throws IOException { int readable = readable(length); if (readable > 0) { int i = input.read(array, offset, readable); read += i; return i; } else { throw EXCEPTION; } }
@Override public int read() throws IOException { int readable = readable(1); if (readable > 0) { int b = input.read(); read++; return b; } else { throw EXCEPTION; } }
@Override public int read() throws IOException { int readable = readable(1); if (readable > 0) { int b = input.read(); read++; return b; } else { throw EXCEPTION; } }
@Override public int read(byte[] array, int offset, int length) throws IOException { int readable = readable(length); if (readable > 0) { int i = input.read(array, offset, readable); read += i; return i; } else { throw EXCEPTION; } }
/** * Read bytes from a {@code ByteInput}. Fully fills in {@code len} bytes in the array. * * @param input the input * @param dest the destination * @param offs the offset into the array * @param len the number of bytes * @throws EOFException if the end of file is reached before the array is filled * @throws IOException if an I/O error occurs */ public static void readFully(ByteInput input, byte[] dest, int offs, int len) throws IOException { while (len > 0) { final int r = input.read(dest, offs, len); if (r == -1) { throw new EOFException(); } len -= r; offs += r; } }
/** {@inheritDoc} */ public int read(final byte[] b, final int off, final int len) throws IOException { final int limit = this.limit; if (limit == -1) { return -1; } final int position = this.position; final int remaining = limit - position; // pass through if the buffer is empty if (remaining == 0) { return byteInput.read(b, off, len); } final byte[] buffer = this.buffer; if (len > remaining) { System.arraycopy(buffer, position, b, off, remaining); this.limit = this.position = 0; final int res = byteInput.read(b, off + remaining, len - remaining); return res == -1 ? remaining : res + remaining; } else { System.arraycopy(buffer, position, b, off, len); this.position += len; return len; } }
@Override public int read() throws IOException { int readable = readable(1); if (readable > 0) { int b = input.read(); read++; return b; } else { throw EXCEPTION; } }
@Override public int read(byte[] array, int offset, int length) throws IOException { int readable = readable(length); if (readable > 0) { int i = input.read(array, offset, readable); read += i; return i; } else { throw EXCEPTION; } }
public int read(byte[] array, int offset, int length) throws IOException { int readable = readable(length); if (readable > 0) { int i = input.read(array, offset, readable); read += i; return i; } else { throw EXCEPTION; } }
public int read() throws IOException { int readable = readable(1); if (readable > 0) { int b = input.read(); read++; return b; } else { throw EXCEPTION; } }
private static int readUTFChar(final ByteInput input) throws IOException { final int a = input.read(); if (a < 0) { throw new EOFException(); throw new UTFDataFormatException(INVALID_BYTE); } else if (a < 0xe0) { final int b = input.read(); if (b == -1) { throw new EOFException(); final int b = input.read(); if (b == -1) { throw new EOFException(); throw new UTFDataFormatException(INVALID_BYTE); final int c = input.read(); if (c == -1) { throw new EOFException();
final StringBuilder builder = new StringBuilder(); for (long i = 0; i < len; i ++) { final int a = input.read(); if (a < 0) { throw new EOFException("Expected " + (len - i) + " more bytes"); } else if (a < 0xe0) { if (++i < len) { final int b = input.read(); if (b == -1) { throw new EOFException("Expected " + (len - i) + " more bytes"); final int b = input.read(); if (b == -1) { throw new EOFException("Expected " + (len - i) + " more bytes"); final int c1 = input.read(); if (c1 == -1) { throw new EOFException("Expected " + (len - i) + " more bytes");
/** {@inheritDoc} */ public boolean readBoolean() throws IOException { final int limit = this.limit; if (limit == -1) { throw eofOnRead(); } int position; final byte[] buffer = this.buffer; if ((position = this.position++) == limit) { this.position = 1; if ((this.limit = byteInput.read(buffer)) == -1) { throw eofOnRead(); } return buffer[0] != 0; } this.position = position + 1; return buffer[position] != 0; }
/** {@inheritDoc} */ public byte readByte() throws IOException { final int limit; if ((limit = this.limit) == -1) { throw eofOnRead(); } int position; final byte[] buffer = this.buffer; if ((position = this.position++) == limit) { this.position = 1; if ((this.limit = byteInput.read(buffer)) == -1) { throw eofOnRead(); } return buffer[0]; } this.position = position + 1; return buffer[position]; }
/** * Read an unsigned byte directly. * * @return the unsigned byte * @throws IOException if an error occurs */ protected int readUnsignedByteDirect() throws IOException { final int limit; if ((limit = this.limit) == -1) { throw eofOnRead(); } int position; final byte[] buffer = this.buffer; if ((position = this.position++) == limit) { this.position = 1; if ((this.limit = byteInput.read(buffer)) == -1) { throw eofOnRead(); } return buffer[0] & 0xff; } return buffer[position] & 0xff; }
/** {@inheritDoc} */ public void readFully(final byte[] b, int off, int len) throws IOException { if (limit == -1) { throw eofOnRead(); } final int position = this.position; int remaining = limit - position; if (len > remaining) { if (remaining > 0) { System.arraycopy(buffer, position, b, off, remaining); limit = this.position = 0; off += remaining; len -= remaining; } final ByteInput byteInput = this.byteInput; do { remaining = byteInput.read(b, off, len); if (remaining == -1) { throw eofOnRead(); } off += remaining; len -= remaining; } while (len != 0); } else try { System.arraycopy(buffer, position, b, off, len); this.position = position + len; } catch (NullPointerException e) { throw eofOnRead(); } }