private void doWork() throws IOException { CountingInputStream input = null; CountingOutputStream output = null; try { input = new CountingInputStream(s.getInputStream()); output = new CountingOutputStream(s.getOutputStream()); ByteStreams.copy(input, output); Counters.increment("BytesIn", input.getCount()); Counters.increment("BytesOut", output.getCount()); } finally { Closeables.closeQuietly(input); Closeables.closeQuietly(output); } }
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 Throwables.propagate(e); } }
public float percentRead() { return countingInputStream.getCount() / totalBytesToRead; }
public long getRecordOffset() { return streamOffset + inputStream.getCount(); }