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); } }
if (isConnectionReset) { startOffset += delegate.getCount(); try { delegate.close(); delegate = new CountingInputStream(objectOpenFunction.open(object, startOffset));
@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()); }
RetryingInputStream( T object, ObjectOpenFunction<T> objectOpenFunction, Predicate<Throwable> retryCondition, int maxRetry ) throws IOException { this.object = object; this.objectOpenFunction = objectOpenFunction; this.retryCondition = retryCondition; this.maxRetry = maxRetry; this.delegate = new CountingInputStream(objectOpenFunction.open(object)); }
public long offset() { return count.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()); }
/** * A CountingInputStream is inserted to read compressed-offsets. * * @param in stream to wrap * @param lookback tolerance of initial mark * @return original stream wrapped in CountingInputStream * @throws IOException */ protected static InputStream countingStream(InputStream in, int lookback) throws IOException { CountingInputStream cin = new CountingInputStream(in); cin.mark(lookback); return cin; }
public void testMarkNotSupported() { counter = new CountingInputStream(new UnmarkableInputStream()); try { counter.reset(); fail(); } catch (IOException expected) { assertThat(expected).hasMessageThat().isEqualTo("Mark not supported"); } }
public long countContent(URL feedurl) { CountingInputStream counter = null; try { HttpURLConnection con = (HttpURLConnection) feedurl.openConnection(); counter = new CountingInputStream(con.getInputStream()); String output = IOUtils.toString(counter); return counter.getByteCount(); } catch (IOException ex) { throw new RuntimeException(ex); } finally { IOUtils.closeQuietly(counter); } }
private byte[] readSignableBytesAgainForLaterValidation(final CountingInputStream bufferedInputStream) throws IOException { final int position = (int)bufferedInputStream.getCount(); bufferedInputStream.reset(); final byte[] bytes = new byte[position]; IOUtils.read(bufferedInputStream, bytes, 0, position); return bytes; } }
@Override public void close() throws IOException { delegate.close(); } }
public long countContent(URL urls) { try { //... CountingInputStream counter = new CountingInputStream(httpResponse.getEntity().getContent()); FileOutputStream os = new FileOutputStream(MEDIA_PATH + "/fileName.mp3"); int read; byte[] buffer = new byte[1028]; while ((read = counter.read(buffer)) != -1) { os.write(buffer, 0, read); publishProgress(counter.getByteCount()/size); } // ... return counter.getByteCount()/size; } catch (IOException ex) { throw new RuntimeException(ex); } }
@Override protected void setUp() throws Exception { super.setUp(); counter = new CountingInputStream(new ByteArrayInputStream(new byte[20])); }
public void resetCRC() { startCrcRange = count.getCount(); crc.resetCrc(); }
@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()); }
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()); }
/** * A CountingInputStream is inserted to read compressed-offsets. * * @param in stream to wrap * @param lookback tolerance of initial mark * @return original stream wrapped in CountingInputStream * @throws IOException */ protected static InputStream countingStream(InputStream in, int lookback) throws IOException { CountingInputStream cin = new CountingInputStream(in); cin.mark(lookback); return cin; }