public MemoryRandomAccessDataInput(final @WillNotClose Memory memory) { dataInput = new MemoryDataInput(memory); }
public MemoryRandomAccessDataInput(final @WillNotClose Memory memory) { dataInput = new MemoryDataInput(memory); }
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 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 V get(@Nonnull final K key) throws IOException { if (dataMemory == null) { throw new IOException("table has been closed!"); } final long offset = getOffset(key); if (offset < 0) { filteredCount.incrementAndGet(); return null; } final MemoryDataInput in = new MemoryDataInput(dataMemory); in.seek(offset); final TableConfig<K, V> config = meta.getConfig(); final K extractedKey = config.readKey(in); final V value = config.readValue(in); if (config.getKeyValidator() != null) { final V result = config.getKeyValidator().validate(key, extractedKey, value); if (result == null) { missingCount.incrementAndGet(); } else { retrievedCount.incrementAndGet(); } return result; } retrievedCount.incrementAndGet(); return value; }
@Override public E get(long address) throws IOException { final long blockAddress = (address>>>shift)&padMask; final Option<BlockCacheEntry> blockOption = blockCache.get(blockAddress).get(); if (blockOption.isNone()) throw new IOException("illegal address "+address+" in file "+file); final BlockCacheEntry block = blockOption.some(); final int recordIndex = (int) (address&mask); if (recordIndex >= block.size()) { throw new IOException("there are only "+block.size()+" in block at address "+blockAddress+", seek request is for record number "+recordIndex); } return serializer.read(new MemoryDataInput(block.get(recordIndex))); }
@Override public E get(long address) throws IOException { final long blockAddress = (address>>>shift)&padMask; final Option<BlockCacheEntry> blockOption = blockCache.get(blockAddress).get(); if (blockOption.isNone()) throw new IOException("illegal address "+address+" in file "+file); final BlockCacheEntry block = blockOption.some(); final int recordIndex = (int) (address&mask); if (recordIndex >= block.size()) { throw new IOException("there are only "+block.size()+" in block at address "+blockAddress+", seek request is for record number "+recordIndex); } return serializer.read(new MemoryDataInput(block.get(recordIndex))); }
public V get(@Nonnull final Object o) { try { final K key = (K) o; final long offset = getOffset(key); if (offset < 0) { return null; } final MemoryDataInput in = new MemoryDataInput(dataMemory); in.seek(offset); final TableConfig<K, V> config = meta.getConfig(); final K extractedKey = config.readKey(in); final V value = config.readValue(in); if (config.getKeyValidator() != null) { final V result = config.getKeyValidator().validate(key, extractedKey, value); return result; } return value; } catch (final IOException e) { throw new RuntimeException("corrupt serialized data in MphMap", e); } }
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");
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); }
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); }