Search in sources :

Example 51 with BufferedSink

use of okio.BufferedSink in project okhttp by square.

the class WebSocketWriterTest method serverLargeNonBufferedPayloadWrittenAsMultipleFrames.

@Test
public void serverLargeNonBufferedPayloadWrittenAsMultipleFrames() throws IOException {
    int length = 100_000;
    Buffer bytes = new Buffer().write(binaryData(length));
    BufferedSink sink = Okio.buffer(serverWriter.newMessageSink(OPCODE_TEXT, length));
    Buffer body = bytes.clone();
    sink.write(body.readByteString(20_000));
    sink.write(body.readByteString(20_000));
    sink.write(body.readByteString(20_000));
    sink.write(body.readByteString(20_000));
    sink.write(body.readByteString(20_000));
    sink.close();
    assertData("017e4000");
    assertData(bytes.readByteArray(16_384));
    assertData("007e4000");
    assertData(bytes.readByteArray(16_384));
    assertData("007e6000");
    assertData(bytes.readByteArray(24_576));
    assertData("007e4000");
    assertData(bytes.readByteArray(16_384));
    assertData("007e6000");
    assertData(bytes.readByteArray(24_576));
    assertData("807e06a0");
    assertData(bytes.readByteArray(1_696));
    assertTrue(data.exhausted());
}
Also used : Buffer(okio.Buffer) BufferedSink(okio.BufferedSink) Test(org.junit.Test)

Example 52 with BufferedSink

use of okio.BufferedSink in project wire by square.

the class ServiceGeneratorTest method schema.

private Schema schema(Map<String, String> fileToProto) throws IOException {
    SchemaLoader schemaLoader = new SchemaLoader();
    schemaLoader.addSource(temporaryFolder.getRoot());
    for (Map.Entry<String, String> entry : fileToProto.entrySet()) {
        File file = new File(temporaryFolder.getRoot(), entry.getKey());
        file.getParentFile().mkdirs();
        try (BufferedSink out = Okio.buffer(Okio.sink(file))) {
            out.writeUtf8(entry.getValue());
        }
        schemaLoader.addProto(entry.getKey());
    }
    return schemaLoader.load();
}
Also used : SchemaLoader(com.squareup.wire.schema.SchemaLoader) BufferedSink(okio.BufferedSink) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) File(java.io.File) JavaFile(com.squareup.javapoet.JavaFile)

Example 53 with BufferedSink

use of okio.BufferedSink in project wire by square.

the class ProtoAdapter method encode.

/** Encode {@code value} and write it to {@code stream}. */
public final void encode(OutputStream stream, E value) throws IOException {
    checkNotNull(value, "value == null");
    checkNotNull(stream, "stream == null");
    BufferedSink buffer = Okio.buffer(Okio.sink(stream));
    encode(buffer, value);
    buffer.emit();
}
Also used : BufferedSink(okio.BufferedSink)

Example 54 with BufferedSink

use of okio.BufferedSink in project okhttp by square.

the class WebSocketWriterTest method serverBinaryMessage.

@Test
public void serverBinaryMessage() throws IOException {
    BufferedSink sink = Okio.buffer(serverWriter.newMessageSink(OPCODE_BINARY, -1));
    sink.write(binaryData(50)).flush();
    assertData("0232");
    assertData(binaryData(50));
    sink.write(binaryData(50)).flush();
    assertData("0032");
    assertData(binaryData(50));
    sink.close();
    assertData("8000");
}
Also used : BufferedSink(okio.BufferedSink) Test(org.junit.Test)

Example 55 with BufferedSink

use of okio.BufferedSink in project okhttp by square.

the class WebSocketWriterTest method serverLargeBufferedPayloadWrittenAsOneFrame.

@Test
public void serverLargeBufferedPayloadWrittenAsOneFrame() throws IOException {
    int length = 12345;
    byte[] bytes = binaryData(length);
    RequestBody body = RequestBody.create(null, bytes);
    BufferedSink sink = Okio.buffer(serverWriter.newMessageSink(OPCODE_TEXT, length));
    body.writeTo(sink);
    sink.close();
    assertData("817e");
    assertData(Util.format("%04x", length));
    assertData(bytes);
    assertTrue(data.exhausted());
}
Also used : BufferedSink(okio.BufferedSink) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

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