private String decodeUtf8String(Buffer buffer) { return new String(buffer.content(), UTF_8); }
private static String bytesToString(ByteStream body) { try { return new String(body.aggregate(100000).get().content(), UTF_8); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } }
private static String bytesToString(ByteStream body) throws Exception { return new String(body.aggregate(100000).get().content(), UTF_8); }
@Test(dataProvider = "emptyBodyResponses") public void convertsToStreamingHttpResponseWithEmptyBody(HttpResponse response) throws ExecutionException, InterruptedException { LiveHttpResponse streaming = response.stream(); byte[] result = streaming.body().aggregate(1000) .get() .content(); assertThat(result.length, is(0)); }
@Test public void aggregatesZeroBuffers() throws ExecutionException, InterruptedException { ByteStreamAggregator aggregator = new ByteStreamAggregator(Flux.empty(), 100); Buffer a = aggregator.apply().get(); assertThat(a.size(), is(0)); assertThat(new String(a.content(), UTF_8), is("")); }
@Test public void aggregatesOneBuffer() throws ExecutionException, InterruptedException { ByteStreamAggregator aggregator = new ByteStreamAggregator(Flux.just(new Buffer("x", UTF_8)), 100); Buffer a = aggregator.apply().get(); assertThat(a.size(), is(1)); assertThat(new String(a.content(), UTF_8), is("x")); }
@Test public void aggregatesManyBuffers() throws ExecutionException, InterruptedException { ByteStreamAggregator aggregator = new ByteStreamAggregator(Flux.just( new Buffer("x", UTF_8), new Buffer("y", UTF_8)), 100); Buffer a = aggregator.apply().get(); assertThat(a.size(), is(2)); assertThat(new String(a.content(), UTF_8), is("xy")); }
@Test public void createsFromByteArray() { byte[] bytes = "Created from string".getBytes(UTF_8); ByteStream byteStream = ByteStream.from(bytes); StepVerifier.create(byteStream) .assertNext(buf -> assertEquals("Created from string", new String(buf.content(), UTF_8))) .verifyComplete(); }
@Test public void createsFromString() { ByteStream byteStream = ByteStream.from("Created from string", UTF_8); StepVerifier.create(byteStream) .assertNext(buf -> assertEquals("Created from string", new String(buf.content(), UTF_8))) .verifyComplete(); }