@Override public void readFully(byte[] buf) { readFully(buf, 0, buf.length); }
@Override public void readPlain(byte[] buf, int off, int len) { readFully(buf, off, len); }
@Override public int readUByte() { checkAvaliable(1); byte[] data = new byte[1]; readFully(data, 0, 1); if (data[0] >= 0) return data[0]; return data[0] + 256; } }
@Override public short readShort() { checkAvaliable(SHORT_SIZE); byte[] data = new byte[SHORT_SIZE]; readFully(data, 0, SHORT_SIZE); return LittleEndian.getShort(data); }
@Override public int readInt() { checkAvaliable(INT_SIZE); byte[] data = new byte[INT_SIZE]; readFully(data, 0, INT_SIZE); return LittleEndian.getInt(data); }
@Override public long readLong() { checkAvaliable(LONG_SIZE); byte[] data = new byte[LONG_SIZE]; readFully(data, 0, LONG_SIZE); return LittleEndian.getLong(data, 0); }
@Override public int readUShort() { checkAvaliable(SHORT_SIZE); byte[] data = new byte[SHORT_SIZE]; readFully(data, 0, SHORT_SIZE); return LittleEndian.getUShort(data); }
@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; }
private static boolean isEqual(DocumentInputStream i1, DocumentInputStream i2) throws IOException { final byte[] buf1 = new byte[4*1024]; final byte[] buf2 = new byte[4*1024]; try { int len; while ((len = i1.read(buf1)) > 0) { i2.readFully(buf2,0,len); for(int i=0;i<len;i++) { if (buf1[i] != buf2[i]) { return false; } } } // is the end of the second file also. return i2.read() < 0; } catch(EOFException | RuntimeException ioe) { return false; } } }
@Override public void readPlain(byte[] buf, int off, int len) { readFully(buf, off, len); }
inp.readFully(ret);
@Override public void readFully(byte[] buf) { readFully(buf, 0, buf.length); }
public void readFully(byte[] buf) { readFully(buf, 0, buf.length); }
@Override public int readUByte() { checkAvaliable(1); byte[] data = new byte[1]; readFully(data, 0, 1); if (data[0] >= 0) return data[0]; return data[0] + 256; } }
@Override public long readLong() { checkAvaliable(LONG_SIZE); byte[] data = new byte[LONG_SIZE]; readFully(data, 0, LONG_SIZE); return LittleEndian.getLong(data, 0); }
@Override public int readInt() { checkAvaliable(INT_SIZE); byte[] data = new byte[INT_SIZE]; readFully(data, 0, INT_SIZE); return LittleEndian.getInt(data); }
@Override public short readShort() { checkAvaliable(SHORT_SIZE); byte[] data = new byte[SHORT_SIZE]; readFully(data, 0, SHORT_SIZE); return LittleEndian.getShort(data); }
@Override public int readUShort() { checkAvaliable(SHORT_SIZE); byte[] data = new byte[SHORT_SIZE]; readFully(data, 0, SHORT_SIZE); return LittleEndian.getUShort(data); }
inp.readFully(contents); embedded = TikaInputStream.get(contents);