@Override public void readFully(final byte[] b, final int off, final int len) throws IOException { dataInput.readFully(b, off, len); }
public void seek(final long position) { dataInput.seek(position); }
@Override public byte readByte() throws IOException { return dataInput.readByte(); }
try { stuffToClose = SharedReference.create((Closeable)buffer); final MemoryDataInput in = new MemoryDataInput(buffer.memory()); if (sizeInBytes < Header.length()) { throw new IOException("file is less than header length bytes"); in.seek(sizeInBytes - Header.length()); in.readFully(headerBytes); final LittleEndianDataInputStream headerStream = new LittleEndianDataInputStream(new ByteArrayInputStream(headerBytes)); final Header header = new HeaderSerializer().read(headerStream);
public MemoryDataInput getMemoryForHash(final long hash) throws IOException { if (dataMemory == null) { throw new IOException("table has been closed!"); } if (hash < 0 || hash >= size()) { return null; } final long offset = getHashOffset(hash); if (offset < 0) { return null; } final MemoryDataInput in = new MemoryDataInput(dataMemory); in.seek(offset); return in; }
public MemoryRandomAccessDataInput(final @WillNotClose Memory memory) { dataInput = new MemoryDataInput(memory); }
@Override public int readUnsignedShort() throws IOException { return readShort()&0xFFFF; }
@Override public boolean readBoolean() throws IOException { return dataInput.readBoolean(); }
@Override public char readChar() throws IOException { return dataInput.readChar(); }
public long position() { return dataInput.position(); }
public long length() { return dataInput.length(); }
private Option<E> readAndCheck(long address, MutableLong nextElementStart) throws IOException { if (address+4 > memory.length()) { throw new ConsistencyException("not enough bytes in file"); } final int length = memory.getInt(address); if (length < 0) { return Option.none(); } if (address+8 > memory.length()) { throw new ConsistencyException("not enough bytes in file"); } if (address+8+length > memory.length()) { throw new ConsistencyException("not enough bytes in file"); } final int checksum = memory.getInt(address+4); MemoryDataInput in = new MemoryDataInput(memory); in.seek(address+8); CRC32 crc32 = new CRC32(); crc32.update(CRC_SEED); byte[] bytes = new byte[length]; in.readFully(bytes); crc32.update(bytes); if ((int)crc32.getValue() != checksum) { throw new ConsistencyException("checksum for record does not match: expected "+checksum+" actual "+(int)crc32.getValue()); } E ret = serializer.read(ByteStreams.newDataInput(bytes)); if (nextElementStart != null) nextElementStart.setValue(address+8+length); return Option.some(ret); }
public MemoryDataInput getMemoryForHash(final long hash) throws IOException { if (dataMemory == null) { throw new IOException("table has been closed!"); } if (hash < 0 || hash >= size()) { return null; } final long offset = getHashOffset(hash); if (offset < 0) { return null; } final MemoryDataInput in = new MemoryDataInput(dataMemory); in.seek(offset); return in; }
public MemoryRandomAccessDataInput(final @WillNotClose Memory memory) { dataInput = new MemoryDataInput(memory); }
@Override public short readShort() throws IOException { return dataInput.readShort(); }
@Override public boolean readBoolean() throws IOException { return dataInput.readBoolean(); }
@Override public char readChar() throws IOException { return dataInput.readChar(); }
public long position() { return dataInput.position(); }
public long length() { return dataInput.length(); }
private Option<E> readAndCheck(long address, MutableLong nextElementStart) throws IOException { if (address+4 > memory.length()) { throw new ConsistencyException("not enough bytes in file"); } final int length = memory.getInt(address); if (length < 0) { return Option.none(); } if (address+8 > memory.length()) { throw new ConsistencyException("not enough bytes in file"); } if (address+8+length > memory.length()) { throw new ConsistencyException("not enough bytes in file"); } final int checksum = memory.getInt(address+4); MemoryDataInput in = new MemoryDataInput(memory); in.seek(address+8); CRC32 crc32 = new CRC32(); crc32.update(CRC_SEED); byte[] bytes = new byte[length]; in.readFully(bytes); crc32.update(bytes); if ((int)crc32.getValue() != checksum) { throw new ConsistencyException("checksum for record does not match: expected "+checksum+" actual "+(int)crc32.getValue()); } E ret = serializer.read(ByteStreams.newDataInput(bytes)); if (nextElementStart != null) nextElementStart.setValue(address+8+length); return Option.some(ret); }