@Override public void writeTo(BufferedSink sink) throws IOException { entity.writeTo(sink.outputStream()); } }
@Override public OutputStream getBody() throws IOException { Sink body = okCacheRequest.body(); if (body == null) { return null; } return Okio.buffer(body).outputStream(); } };
@Override public void writeTo(BufferedSink sink) throws IOException { session.exportTo(requestFlowFile, sink.outputStream()); }
@Test public void outputStreamBounds() throws Exception { OutputStream out = sink.outputStream(); try { out.write(new byte[100], 50, 51); fail(); } catch (ArrayIndexOutOfBoundsException expected) { } }
@Test public void inputStreamCloses() throws Exception { BufferedSink sink = Okio.buffer((Sink) new Buffer()); OutputStream out = sink.outputStream(); out.close(); try { sink.writeUtf8("Hi!"); fail(); } catch (IllegalStateException e) { assertEquals("closed", e.getMessage()); } }
@Test public void outputStream() throws Exception { OutputStream out = sink.outputStream(); out.write('a'); out.write(repeat('b', 9998).getBytes(UTF_8)); out.write('c'); out.flush(); assertEquals("a" + repeat('b', 9998) + "c", data.readUtf8()); }
@Test public void gzipSource() throws Exception { Pipe pipe = new Pipe(1024 * 1024); OutputStream gzipOut = new GZIPOutputStream(Okio.buffer(pipe.sink()).outputStream()) { { // Disable compression to speed up a slow test. Improved from 141s to 33s on one machine. def.setLevel(Deflater.NO_COMPRESSION); } }; Future<Long> future = readAllAndCloseAsync( randomSource(FOUR_GIB_PLUS_ONE), Okio.sink(gzipOut)); HashingSink hashingSink = HashingSink.sha256(Okio.blackhole()); GzipSource gzipSource = new GzipSource(pipe.source()); readAllAndClose(gzipSource, hashingSink); assertEquals(FOUR_GIB_PLUS_ONE, (long) future.get()); assertEquals(SHA256_RANDOM_FOUR_GIB_PLUS_1, hashingSink.hash()); }
OutputStream os = bufferedSink.outputStream(); try { os.write('a');
@Override public void writeTo(BufferedSink bufferedSink) throws IOException { parseBody.writeTo(bufferedSink.outputStream()); } }
@Override public void writeTo(BufferedSink sink) throws IOException { Source source = null; try { source = Okio.source(inputStream); OutputStream os = sink.outputStream(); sink.writeAll(source); } catch (IOException e) { throw KubernetesClientException.launderThrowable("Can't instantiate binary build, due to error reading/writing stream. " + "Can be caused if the output stream was closed by the server.", e); } } };
@Override public void writeTo(BufferedSink bufferedSink) throws IOException { JsonMetricsGenerator.generateJsonMetrics(bufferedSink.outputStream(), getMetricsRegistry(), includeVMMetrics, true, clearMetrics, metricTranslator); } }).
@Override public void writeTo(BufferedSink bufferedSink) throws IOException { JsonMetricsGenerator.generateJsonMetrics(bufferedSink.outputStream(), getMetricsRegistry(), includeVMMetrics, true, clearMetrics, metricTranslator); } }).
@Override public void writeTo(BufferedSink sink) throws IOException { try { OutputStream out = sink.outputStream(); writer.write(out); out.flush(); } catch (IOException ioe) { throw ioe; } catch (Exception e) { throw new IOException("Could not send stream to server: " + e.toString(), e); } }
@Override public void writeTo(BufferedSink sink) throws IOException { session.exportTo(requestFlowFile, sink.outputStream()); }
@Override public void writeTo(BufferedSink sink) throws IOException { entity.writeTo(sink.outputStream()); } }
@Override public void writeTo(BufferedSink sink) throws IOException { source.copyTo(sink.outputStream()); }
@Override public OutputStream getBody() throws IOException { Sink body = okCacheRequest.body(); if (body == null) { return null; } return Okio.buffer(body).outputStream(); } };
@Override public final OutputStream getOutputStream() throws IOException { connect(); BufferedSink sink = httpEngine.getBufferedRequestBody(); if (sink == null) { throw new ProtocolException("method does not support a request body: " + method); } else if (httpEngine.hasResponse()) { throw new ProtocolException("cannot write request body after response has been read"); } return sink.outputStream(); }
@Override public final OutputStream getOutputStream() throws IOException { connect(); BufferedSink sink = httpEngine.getBufferedRequestBody(); if (sink == null) { throw new ProtocolException("method does not support a request body: " + method); } else if (httpEngine.hasResponse()) { throw new ProtocolException("cannot write request body after response has been read"); } return sink.outputStream(); }
@Override public final OutputStream getOutputStream() throws IOException { connect(); BufferedSink sink = httpEngine.getBufferedRequestBody(); if (sink == null) { throw new ProtocolException("method does not support a request body: " + method); } else if (httpEngine.hasResponse()) { throw new ProtocolException("cannot write request body after response has been read"); } return sink.outputStream(); }