private void skip(long length) throws IOException { seek(tell()+length); }
/** Seek to the named value. */ public void seek(T v) throws IOException { if (!column.metaData.hasIndexValues()) throw new TrevniRuntimeException ("Column does not have value index: " +column.metaData.getName()); if (previous == null // not in current block? || previous.compareTo(v) > 0 || (block != column.blockCount()-1 && column.firstValues[block+1].compareTo(v) <= 0)) startBlock(column.findBlock(v)); // seek to block start while (hasNext()) { // scan block long savedPosition = values.tell(); T savedPrevious = previous; if (next().compareTo(v) >= 0) { values.seek(savedPosition); previous = savedPrevious; row--; return; } } }
@Test public void testEmpty() throws Exception { OutputBuffer out = new OutputBuffer(); ByteArrayOutputStream temp = new ByteArrayOutputStream(); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); Assert.assertEquals(0, in.tell()); Assert.assertEquals(0, in.length()); }
public void ensureBlocksRead() throws IOException { if (blocks != null) return; // read block descriptors InputBuffer in = new InputBuffer(file, start); int blockCount = in.readFixed32(); BlockDescriptor[] blocks = new BlockDescriptor[blockCount]; if (metaData.hasIndexValues()) firstValues = (T[])new Comparable[blockCount]; for (int i = 0; i < blockCount; i++) { blocks[i] = BlockDescriptor.read(in); if (metaData.hasIndexValues()) firstValues[i] = in.readValue(metaData.getType()); } dataStart = in.tell(); // compute blockStarts and firstRows Checksum checksum = Checksum.get(metaData); blockStarts = new long[blocks.length]; firstRows = new long[blocks.length]; long startPosition = dataStart; long row = 0; for (int i = 0; i < blockCount; i++) { BlockDescriptor b = blocks[i]; blockStarts[i] = startPosition; firstRows[i] = row; startPosition += b.compressedSize + checksum.size(); row += b.rowCount; } this.blocks = blocks; }
@Test public void testInitPos() throws Exception { long sentinel = Long.MAX_VALUE; OutputBuffer out = new OutputBuffer(); out.writeValue(Integer.MAX_VALUE, ValueType.INT); out.writeLong(sentinel); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); in.readInt(); long pos = in.tell(); in = new InputBuffer(new InputBytes(out.toByteArray()), pos); Assert.assertEquals(sentinel, in.readLong()); } }
private void skip(long length) throws IOException { seek(tell()+length); }
/** Seek to the named value. */ public void seek(T v) throws IOException { if (!column.metaData.hasIndexValues()) throw new TrevniRuntimeException ("Column does not have value index: " +column.metaData.getName()); if (previous == null // not in current block? || previous.compareTo(v) > 0 || (block != column.blockCount()-1 && column.firstValues[block+1].compareTo(v) <= 0)) startBlock(column.findBlock(v)); // seek to block start while (hasNext()) { // scan block long savedPosition = values.tell(); T savedPrevious = previous; if (next().compareTo(v) >= 0) { values.seek(savedPosition); previous = savedPrevious; row--; return; } } }
@Test public void testEmpty() throws Exception { OutputBuffer out = new OutputBuffer(); ByteArrayOutputStream temp = new ByteArrayOutputStream(); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); Assert.assertEquals(0, in.tell()); Assert.assertEquals(0, in.length()); }
public void ensureBlocksRead() throws IOException { if (blocks != null) return; // read block descriptors InputBuffer in = new InputBuffer(file, start); int blockCount = in.readFixed32(); BlockDescriptor[] blocks = new BlockDescriptor[blockCount]; if (metaData.hasIndexValues()) firstValues = (T[])new Comparable[blockCount]; for (int i = 0; i < blockCount; i++) { blocks[i] = BlockDescriptor.read(in); if (metaData.hasIndexValues()) firstValues[i] = in.<T>readValue(metaData.getType()); } dataStart = in.tell(); // compute blockStarts and firstRows Checksum checksum = Checksum.get(metaData); blockStarts = new long[blocks.length]; firstRows = new long[blocks.length]; long startPosition = dataStart; long row = 0; for (int i = 0; i < blockCount; i++) { BlockDescriptor b = blocks[i]; blockStarts[i] = startPosition; firstRows[i] = row; startPosition += b.compressedSize + checksum.size(); row += b.rowCount; } this.blocks = blocks; }