Search in sources :

Example 26 with BufferedSink

use of okio.BufferedSink in project okhttp by square.

the class UrlConnectionCacheTest method writeFile.

private void writeFile(File directory, String file, String content) throws IOException {
    BufferedSink sink = Okio.buffer(fileSystem.sink(new File(directory, file)));
    sink.writeUtf8(content);
    sink.close();
}
Also used : BufferedSink(okio.BufferedSink) File(java.io.File)

Example 27 with BufferedSink

use of okio.BufferedSink in project okhttp by square.

the class WebSocketWriterTest method clientTextMessage.

@Test
public void clientTextMessage() throws IOException {
    BufferedSink sink = Okio.buffer(clientWriter.newMessageSink(OPCODE_TEXT, -1));
    sink.writeUtf8("Hel").flush();
    assertData("018360b420bb28d14c");
    sink.writeUtf8("lo").flush();
    assertData("00823851d9d4543e");
    sink.close();
    assertData("80807acb933d");
}
Also used : BufferedSink(okio.BufferedSink) Test(org.junit.Test)

Example 28 with BufferedSink

use of okio.BufferedSink in project okhttp by square.

the class UrlConnectionCacheTest method gzip.

/** Returns a gzipped copy of {@code bytes}. */
public Buffer gzip(String data) throws IOException {
    Buffer result = new Buffer();
    BufferedSink sink = Okio.buffer(new GzipSink(result));
    sink.writeUtf8(data);
    sink.close();
    return result;
}
Also used : Buffer(okio.Buffer) GzipSink(okio.GzipSink) BufferedSink(okio.BufferedSink)

Example 29 with BufferedSink

use of okio.BufferedSink in project tape by square.

the class QueueTestUtils method copyTestFile.

static File copyTestFile(String file) throws IOException {
    File newFile = File.createTempFile(file, "test");
    InputStream in = QueueTestUtils.class.getResourceAsStream(file);
    try (BufferedSink sink = Okio.buffer(Okio.sink(newFile))) {
        sink.writeAll(Okio.source(in));
    }
    assertTrue(newFile.exists());
    return newFile;
}
Also used : InputStream(java.io.InputStream) BufferedSink(okio.BufferedSink) File(java.io.File)

Example 30 with BufferedSink

use of okio.BufferedSink in project Fast-Android-Networking by amitshekhariitbhu.

the class GzipRequestInterceptor method forceContentLength.

private RequestBody forceContentLength(final RequestBody requestBody) throws IOException {
    final Buffer buffer = new Buffer();
    requestBody.writeTo(buffer);
    return new RequestBody() {

        @Override
        public MediaType contentType() {
            return requestBody.contentType();
        }

        @Override
        public long contentLength() {
            return buffer.size();
        }

        @Override
        public void writeTo(BufferedSink sink) throws IOException {
            sink.write(buffer.snapshot());
        }
    };
}
Also used : Buffer(okio.Buffer) BufferedSink(okio.BufferedSink) RequestBody(okhttp3.RequestBody)

Aggregations

BufferedSink (okio.BufferedSink)91 Test (org.junit.Test)31 IOException (java.io.IOException)30 Buffer (okio.Buffer)19 File (java.io.File)15 RequestBody (okhttp3.RequestBody)14 GzipSink (okio.GzipSink)12 Source (okio.Source)11 Response (okhttp3.Response)10 BufferedSource (okio.BufferedSource)10 Request (okhttp3.Request)9 InFrame (okhttp3.internal.http2.MockHttp2Peer.InFrame)9 MediaType (okhttp3.MediaType)7 InterruptedIOException (java.io.InterruptedIOException)6 MockResponse (okhttp3.mockwebserver.MockResponse)5 Sink (okio.Sink)5 InputStream (java.io.InputStream)4 Socket (java.net.Socket)4 OkHttpClient (okhttp3.OkHttpClient)4 Request (com.squareup.okhttp.Request)3