public void get(final long index, final int[] ints, final int start, final int length) { for (int i = 0; i < length; i++) { ints[start+i] = buffer.getInt((index+i)*TYPE_SIZE); } }
@Override public int readInt() throws IOException { int ret = memory.getInt(position); position+=4; return ret; }
public int get(final long index) { return buffer.getInt(index*TYPE_SIZE); }
public String getString(final int docId) { final int address = docIdToAddress.getInt(docId << 2); final int firstByte = stringValues.getByte(address)&0xFF; final int length; final int valOffset; if (firstByte == 0xFF) { length = stringValues.getInt(address+1); valOffset = address+5; } else { length = firstByte; valOffset = address+1; } final byte[] bytes = new byte[length]; stringValues.getBytes(valOffset, bytes); return new String(bytes, Charsets.UTF_8); }
public long getHashOffset(final long hash, @Nullable final Memory offsets, @Nullable final Select select) { switch (config.getOffsetStorage()) { case INDEXED: if (offsets == null) { throw new IllegalArgumentException("indexed offsets with null memory"); } final long offset; if (bytesPerOffset == 2) { offset = offsets.getShort(hash * 2L); } else if (bytesPerOffset == 4) { offset = offsets.getInt(hash * 4L); } else { offset = offsets.getLong(hash * 8L); } return offset; case SELECTED: final long rawSelected = select == null ? selectOffsets.select(hash) : select.select(hash); final long selected = rawSelected < 0 ? 0 : rawSelected; return config.decompressOffset(selected, hash); case FIXED: return config.decompressOffset(0L /* unused */, hash); default: throw new IllegalArgumentException("unknown offset storage type: " + config.getOffsetStorage()); } }
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); }