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