@Override public void close() throws IOException { source.close(); }
@Override public void close() throws IOException { closed = true; if (delegate != null) { delegate.close(); } else { source.close(); } } }
@Override public void close() throws IOException { source.close(); }
@Override public void close() throws IOException { closed = true; if (delegate != null) { delegate.close(); } else { source.close(); } } }
@Override public void close() throws IOException { peeked = PEEKED_NONE; scopes[0] = JsonScope.CLOSED; stackSize = 1; buffer.clear(); source.close(); }
@Override public void close() throws IOException { if (!cacheRequestClosed && !discard(this, HttpCodec.DISCARD_STREAM_TIMEOUT_MILLIS, MILLISECONDS)) { cacheRequestClosed = true; cacheRequest.abort(); } source.close(); } };
public static void close(Response response, ANRequest request) { if (request.getResponseAs() != ResponseType.OK_HTTP_RESPONSE && response != null && response.body() != null && response.body().source() != null) { try { response.body().source().close(); } catch (Exception ignore) { } } } }
@Override public void close() throws IOException { peeked = PEEKED_NONE; stack[0] = JsonScope.CLOSED; stackSize = 1; buffer.clear(); source.close(); }
@Override public void close() throws IOException { if (!cacheRequestClosed && !discard(this, HttpCodec.DISCARD_STREAM_TIMEOUT_MILLIS, MILLISECONDS)) { cacheRequestClosed = true; cacheRequest.abort(); } source.close(); } };
private void load(KeyStore ks, ObservableEmitter<char[]> emitter) throws Exception { BufferedSource source=Okio.buffer(Okio.source(encryptedFile)); byte[] iv=source.readByteArray(BLOCK_SIZE); byte[] encrypted=source.readByteArray(); source.close(); SecretKey secretKey=(SecretKey)ks.getKey(keyName, null); Cipher cipher=Cipher.getInstance("AES/CBC/PKCS7Padding"); cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv)); byte[] decrypted=cipher.doFinal(encrypted); char[] passphrase=toChars(decrypted); emitter.onNext(passphrase); } }
static EncryptionResult load(File f) throws Exception { BufferedSource source=Okio.buffer(Okio.source(f)); byte[] iv=source.readByteArray(BLOCK_SIZE); byte[] encrypted=source.readByteArray(); source.close(); return new EncryptionResult(iv, encrypted); }
@Test public void sourceIsOpen() throws Exception { BufferedSource source = Okio.buffer((Source) new Buffer()); assertTrue(source.isOpen()); source.close(); assertFalse(source.isOpen()); }
@Test public void writableChannelNioFile() throws Exception { File file = temporaryFolder.newFile(); FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.WRITE); testWritableByteChannel(fileChannel); BufferedSource emitted = Okio.buffer(Okio.source(file)); assertEquals("defghijklmnopqrstuvw", emitted.readUtf8()); emitted.close(); }
@Test public void closeThenRead() throws Exception { SourceMarker marker = new SourceMarker(new Buffer().writeUtf8("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); BufferedSource source = marker.source(); source.close(); try { source.readUtf8(3); fail(); } catch (IllegalStateException expected) { assertThat(expected).hasMessage("closed"); } }
@Test public void closeThenMark() throws Exception { SourceMarker marker = new SourceMarker(new Buffer().writeUtf8("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); BufferedSource source = marker.source(); source.close(); try { marker.mark(5); fail(); } catch (IllegalStateException expected) { assertThat(expected).hasMessage("closed"); } }
@Test public void closeThenReset() throws Exception { SourceMarker marker = new SourceMarker(new Buffer().writeUtf8("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); BufferedSource source = marker.source(); long pos0 = marker.mark(5); source.close(); try { marker.reset(pos0); fail(); } catch (IllegalStateException expected) { assertThat(expected).hasMessage("closed"); } }
@Test public void readWritePath() throws Exception { Path path = temporaryFolder.newFile().toPath(); BufferedSink sink = Okio.buffer(Okio.sink(path)); sink.writeUtf8("Hello, java.nio file!"); sink.close(); assertTrue(Files.exists(path)); assertEquals(21, Files.size(path)); BufferedSource source = Okio.buffer(Okio.source(path)); assertEquals("Hello, java.nio file!", source.readUtf8()); source.close(); }
@Test public void readWriteFile() throws Exception { File file = temporaryFolder.newFile(); BufferedSink sink = Okio.buffer(Okio.sink(file)); sink.writeUtf8("Hello, java.io file!"); sink.close(); assertTrue(file.exists()); assertEquals(20, file.length()); BufferedSource source = Okio.buffer(Okio.source(file)); assertEquals("Hello, java.io file!", source.readUtf8()); source.close(); }
@Test public void appendFile() throws Exception { File file = temporaryFolder.newFile(); BufferedSink sink = Okio.buffer(Okio.appendingSink(file)); sink.writeUtf8("Hello, "); sink.close(); assertTrue(file.exists()); assertEquals(7, file.length()); sink = Okio.buffer(Okio.appendingSink(file)); sink.writeUtf8("java.io file!"); sink.close(); assertEquals(20, file.length()); BufferedSource source = Okio.buffer(Okio.source(file)); assertEquals("Hello, java.io file!", source.readUtf8()); source.close(); }
@Test public void removingElementDoesNotZeroData() throws IOException { QueueFile queueFile = newQueueFile(false); queueFile.add(values[4]); queueFile.remove(); queueFile.close(); BufferedSource source = Okio.buffer(Okio.source(file)); source.skip(headerLength); source.skip(Element.HEADER_LENGTH); assertThat(source.readByteString(4).hex()).isEqualTo("04030201"); source.close(); }