public ExampleRecordCursor(List<ExampleColumnHandle> columnHandles, ByteSource byteSource) { this.columnHandles = columnHandles; fieldToColumnIndex = new int[columnHandles.size()]; for (int i = 0; i < columnHandles.size(); i++) { ExampleColumnHandle columnHandle = columnHandles.get(i); fieldToColumnIndex[i] = columnHandle.getOrdinalPosition(); } try (CountingInputStream input = new CountingInputStream(byteSource.openStream())) { lines = byteSource.asCharSource(UTF_8).readLines().iterator(); totalBytes = input.getCount(); } catch (IOException e) { throw new UncheckedIOException(e); } }
bytesReceived.addAndGet(countingInputStream.getCount());
public void testSkipEOF() throws IOException { assertEquals(20, counter.skip(30)); assertEquals(20, counter.getCount()); assertEquals(0, counter.skip(20)); assertEquals(20, counter.getCount()); // Test reading a single byte while we're in the right state assertEquals(-1, counter.read()); assertEquals(20, counter.getCount()); }
public void testReadArrayRange() throws IOException { assertEquals(3, counter.read(new byte[10], 1, 3)); assertEquals(3, counter.getCount()); }
public void testReadArray() throws IOException { assertEquals(10, counter.read(new byte[10])); assertEquals(10, counter.getCount()); }
public void testSkip() throws IOException { assertEquals(10, counter.skip(10)); assertEquals(10, counter.getCount()); }
@SuppressWarnings("CheckReturnValue") // calling read() to skip a byte public void testMark() throws Exception { assertTrue(counter.markSupported()); assertEquals(10, counter.read(new byte[10])); assertEquals(10, counter.getCount()); counter.mark(5); counter.read(); assertEquals(11, counter.getCount()); counter.reset(); assertEquals(10, counter.getCount()); assertEquals(10, counter.skip(100)); assertEquals(20, counter.getCount()); }
if (isConnectionReset) { startOffset += delegate.getCount(); try { delegate.close();
public long offset() { return count.getCount(); }
@Override public void handle(HttpExchange exchange) throws IOException { CountingInputStream input = new CountingInputStream(exchange.getRequestBody()); CountingOutputStream output = new CountingOutputStream(exchange.getResponseBody()); exchange.setStreams(input, output); Stopwatch stopwatch = latency.start(); try { handleImpl(exchange); } finally { stopwatch.stop(); bytesReceived.increment(input.getCount()); bytesSent.increment(output.getCount()); } }
public void resetCRC() { startCrcRange = count.getCount(); crc.resetCrc(); }
public long getCRC() { endCrcRange = count.getCount(); return crc.getValue(); }
protected final StreamMetadata storeBlocksAndGetHashlessMetadata(@Nullable Transaction tx, long id, InputStream stream) { CountingInputStream countingStream = new CountingInputStream(stream); // Try to store the bytes in the stream and get length try { storeBlocksFromStream(tx, id, countingStream); } catch (IOException e) { long length = countingStream.getCount(); StreamMetadata metadata = StreamMetadata.newBuilder() .setStatus(Status.FAILED) .setLength(length) .setHash(com.google.protobuf.ByteString.EMPTY) .build(); storeMetadataAndIndex(id, metadata); log.error("Could not store stream {}. Failed after {} bytes.", id, length, e); throw Throwables.rewrapAndThrowUncheckedException("Failed to store stream.", e); } long length = countingStream.getCount(); return StreamMetadata.newBuilder() .setStatus(Status.STORED) .setLength(length) .setHash(com.google.protobuf.ByteString.EMPTY) .build(); }
@Override public long getBytesRead() { return countingInputStream.getCount(); }
@Override public long getBytesRead() { if (countingInputStream == null) { return 0; } return countingInputStream.getCount(); }
protected static long positionForRecord(InputStream in) { return (in instanceof GZIPMembersInputStream) ? ((GZIPMembersInputStream)in).getCurrentMemberStart() : ((CountingInputStream)in).getCount(); }
public void sort(InputStream inputStream, OutputStream outputStream) { long begin = System.currentTimeMillis(); CountingInputStream countingInputStream = new CountingInputStream(inputStream); doSort(countingInputStream, outputStream); LogUtils.infoTimeTaken(LOG, begin, countingInputStream.getCount(), "Sorted stream of %d bytes", countingInputStream.getCount()); }