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());
}
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();
}
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();
}
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");
}
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());
}
Aggregations