@Override public int read() throws IOException { dieIfClosed(); if (atEOD()) { return EOF; } byte[] b = new byte[1]; int result = read(b, 0, 1); if(result >= 0) { if(b[0] < 0) { return b[0]+256; } return b[0]; } return result; }
@Override public int read(byte[] b, int off, int len) throws IOException { dieIfClosed(); if (b == null) { throw new IllegalArgumentException("buffer must not be null"); } if (off < 0 || len < 0 || b.length < off + len) { throw new IndexOutOfBoundsException("can't read past buffer boundaries"); } if (len == 0) { return 0; } if (atEOD()) { return EOF; } int limit = Math.min(remainingBytes(), len); readFully(b, off, limit); return limit; }
@Override public long skip(long n) throws IOException { dieIfClosed(); if (n < 0) { return 0; } long new_offset = _current_offset + n; if (new_offset < _current_offset) { // wrap around in converting a VERY large long to an int new_offset = _document_size; } else if (new_offset > _document_size) { new_offset = _document_size; } long rval = new_offset - _current_offset; // TODO Do this better byte[] skip = IOUtils.safelyAllocate(rval, Integer.MAX_VALUE); readFully(skip); return rval; }
@Override public int read() throws IOException { dieIfClosed(); if (atEOD()) { return EOF; } byte[] b = new byte[1]; int result = read(b, 0, 1); if(result >= 0) { if(b[0] < 0) { return b[0]+256; } return b[0]; } return result; }
@Override public int read(byte[] b, int off, int len) throws IOException { dieIfClosed(); if (b == null) { throw new IllegalArgumentException("buffer must not be null"); } if (off < 0 || len < 0 || b.length < off + len) { throw new IndexOutOfBoundsException("can't read past buffer boundaries"); } if (len == 0) { return 0; } if (atEOD()) { return EOF; } int limit = Math.min(remainingBytes(), len); readFully(b, off, limit); return limit; }
@Override public long skip(long n) throws IOException { dieIfClosed(); if (n < 0) { return 0; } long new_offset = _current_offset + n; if (new_offset < _current_offset) { // wrap around in converting a VERY large long to an int new_offset = _document_size; } else if (new_offset > _document_size) { new_offset = _document_size; } long rval = new_offset - _current_offset; // TODO Do this better byte[] skip = IOUtils.safelyAllocate(rval, Integer.MAX_VALUE); readFully(skip); return rval; }