public void run() { synchronized (DiskLruCache.this) { if (!initialized | closed) { return; // Nothing to do } try { trimToSize(); } catch (IOException ignored) { mostRecentTrimFailed = true; } try { if (journalRebuildRequired()) { rebuildJournal(); redundantOpCount = 0; } } catch (IOException e) { mostRecentRebuildFailed = true; journalWriter = Okio.buffer(Okio.blackhole()); } } } };
public void run() { synchronized (DiskLruCache.this) { if (!initialized | closed) { return; // Nothing to do } try { trimToSize(); } catch (IOException ignored) { mostRecentTrimFailed = true; } try { if (journalRebuildRequired()) { rebuildJournal(); redundantOpCount = 0; } } catch (IOException e) { mostRecentRebuildFailed = true; journalWriter = Okio.buffer(Okio.blackhole()); } } } };
try (HashingSource hashingSource = HashingSource.sha256(Okio.source(file)); BufferedSource source = Okio.buffer(hashingSource)) { source.readAll(Okio.blackhole()); System.out.println(" sha256: " + hashingSource.hash().hex()); try (HashingSink hashingSink = HashingSink.sha256(Okio.blackhole()); BufferedSink sink = Okio.buffer(hashingSink); Source source = Okio.source(file)) {
private void exhaustStream(InputStream inputStream) throws IOException { Okio.buffer(Okio.source(inputStream)).readAll(Okio.blackhole()); }
@Test public void blackhole() throws Exception { Buffer data = new Buffer(); data.writeUtf8("blackhole"); Sink blackhole = Okio.blackhole(); blackhole.write(data, 5); assertEquals("hole", data.readUtf8()); } }
@Test public void gzipSink() throws Exception { Pipe pipe = new Pipe(1024 * 1024); GzipSink gzipSink = new GzipSink(pipe.sink()); // Disable compression to speed up a slow test. Improved from 141s to 35s on one machine. gzipSink.deflater().setLevel(Deflater.NO_COMPRESSION); Future<Long> future = readAllAndCloseAsync(randomSource(FOUR_GIB_PLUS_ONE), gzipSink); HashingSink hashingSink = HashingSink.sha256(Okio.blackhole()); GZIPInputStream gzipIn = new GZIPInputStream(Okio.buffer(pipe.source()).inputStream()); readAllAndClose(Okio.source(gzipIn), hashingSink); assertEquals(FOUR_GIB_PLUS_ONE, (long) future.get()); assertEquals(SHA256_RANDOM_FOUR_GIB_PLUS_1, hashingSink.hash()); }
@Test public void test() throws Exception { Pipe pipe = new Pipe(1024 * 1024); Future<Long> future = readAllAndCloseAsync(randomSource(FOUR_GIB_PLUS_ONE), pipe.sink()); HashingSink hashingSink = HashingSink.sha256(Okio.blackhole()); readAllAndClose(pipe.source(), hashingSink); assertEquals(FOUR_GIB_PLUS_ONE, (long) future.get()); assertEquals(SHA256_RANDOM_FOUR_GIB_PLUS_1, hashingSink.hash()); }
@Test public void gzipSource() throws Exception { Pipe pipe = new Pipe(1024 * 1024); OutputStream gzipOut = new GZIPOutputStream(Okio.buffer(pipe.sink()).outputStream()) { { // Disable compression to speed up a slow test. Improved from 141s to 33s on one machine. def.setLevel(Deflater.NO_COMPRESSION); } }; Future<Long> future = readAllAndCloseAsync( randomSource(FOUR_GIB_PLUS_ONE), Okio.sink(gzipOut)); HashingSink hashingSink = HashingSink.sha256(Okio.blackhole()); GzipSource gzipSource = new GzipSource(pipe.source()); readAllAndClose(gzipSource, hashingSink); assertEquals(FOUR_GIB_PLUS_ONE, (long) future.get()); assertEquals(SHA256_RANDOM_FOUR_GIB_PLUS_1, hashingSink.hash()); }
@Test public void peekSegmentThenInvalid() throws IOException { sink.writeUtf8("abc"); sink.writeUtf8(repeat('d', 2 * SEGMENT_SIZE)); sink.emit(); assertEquals("abc", source.readUtf8(3)); // Peek a little data and skip the rest of the upstream source BufferedSource peek = source.peek(); assertEquals("ddd", peek.readUtf8(3)); source.readAll(Okio.blackhole()); // Skip the rest of the buffered data peek.skip(SEGMENT_SIZE - 3); try { peek.readByte(); fail(); } catch (IllegalStateException e) { assertEquals("Peek source is invalid because upstream source was used", e.getMessage()); } }
public void run() { synchronized (DiskLruCache.this) { if (!initialized | closed) { return; // Nothing to do } try { trimToSize(); } catch (IOException ignored) { mostRecentTrimFailed = true; } try { if (journalRebuildRequired()) { rebuildJournal(); redundantOpCount = 0; } } catch (IOException e) { mostRecentRebuildFailed = true; journalWriter = Okio.buffer(Okio.blackhole()); } } } };
public void run() { synchronized (DiskLruCache.this) { if (!initialized | closed) { return; // Nothing to do } try { trimToSize(); } catch (IOException ignored) { mostRecentTrimFailed = true; } try { if (journalRebuildRequired()) { rebuildJournal(); redundantOpCount = 0; } } catch (IOException e) { mostRecentRebuildFailed = true; journalWriter = Okio.buffer(Okio.blackhole()); } } } };