use of org.apache.hc.core5.http.io.SessionOutputBuffer in project httpcomponents-core by apache.
the class TestSessionInOutBuffers method testMultibyteCodedReadWriteLongLine.
@Test
public void testMultibyteCodedReadWriteLongLine() throws Exception {
final String s1 = constructString(SWISS_GERMAN_HELLO);
final String s2 = constructString(RUSSIAN_HELLO);
final String s3 = "Like hello and stuff";
final StringBuilder buf = new StringBuilder();
for (int i = 0; i < 1024; i++) {
buf.append(s1).append(s2).append(s3);
}
final String s = buf.toString();
final SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(16, StandardCharsets.UTF_8.newEncoder());
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final CharArrayBuffer chbuffer = new CharArrayBuffer(16);
chbuffer.append(s);
outbuffer.writeLine(chbuffer, outputStream);
outbuffer.flush(outputStream);
final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, StandardCharsets.UTF_8.newDecoder());
final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
chbuffer.clear();
inBuffer.readLine(chbuffer, inputStream);
Assertions.assertEquals(s, chbuffer.toString());
}
use of org.apache.hc.core5.http.io.SessionOutputBuffer in project httpcomponents-core by apache.
the class TestSessionInOutBuffers method testWriteSmallFragmentBuffering.
@Test
public void testWriteSmallFragmentBuffering() throws Exception {
final OutputStream outputStream = Mockito.mock(OutputStream.class);
final SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(new BasicHttpTransportMetrics(), 16, 16, null);
outbuffer.write(1, outputStream);
outbuffer.write(2, outputStream);
outbuffer.write(new byte[] { 1, 2 }, outputStream);
outbuffer.write(new byte[] { 3, 4 }, outputStream);
outbuffer.flush(outputStream);
Mockito.verify(outputStream, Mockito.times(1)).write(ArgumentMatchers.any(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt());
Mockito.verify(outputStream, Mockito.never()).write(ArgumentMatchers.anyInt());
}
use of org.apache.hc.core5.http.io.SessionOutputBuffer in project httpcomponents-core by apache.
the class TestSessionInOutBuffers method testWriteSmallFragmentNoBuffering.
@Test
public void testWriteSmallFragmentNoBuffering() throws Exception {
final OutputStream outputStream = Mockito.mock(OutputStream.class);
final SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(new BasicHttpTransportMetrics(), 16, 0, null);
outbuffer.write(1, outputStream);
outbuffer.write(2, outputStream);
outbuffer.write(new byte[] { 1, 2 }, outputStream);
outbuffer.write(new byte[] { 3, 4 }, outputStream);
Mockito.verify(outputStream, Mockito.times(2)).write(ArgumentMatchers.any(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt());
Mockito.verify(outputStream, Mockito.times(2)).write(ArgumentMatchers.anyInt());
}
use of org.apache.hc.core5.http.io.SessionOutputBuffer in project httpcomponents-core by apache.
the class TestIdentityEncoder method testBasicCoding.
@Test
public void testBasicCoding() throws Exception {
final WritableByteChannelMock channel = new WritableByteChannelMock(64);
final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
final BasicHttpTransportMetrics metrics = new BasicHttpTransportMetrics();
final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics);
Assertions.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
encoder.complete();
Assertions.assertTrue(encoder.isCompleted());
Assertions.assertEquals(5, metrics.getBytesTransferred());
outbuf.flush(channel);
final String s = channel.dump(StandardCharsets.US_ASCII);
Assertions.assertEquals("stuff", s);
Assertions.assertEquals("[identity; completed: true]", encoder.toString());
}
use of org.apache.hc.core5.http.io.SessionOutputBuffer in project httpcomponents-core by apache.
the class TestIdentityEncoder method testInvalidConstructor.
@Test
public void testInvalidConstructor() {
final WritableByteChannelMock channel = new WritableByteChannelMock(64);
final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
Assertions.assertThrows(NullPointerException.class, () -> new IdentityEncoder(null, null, null));
Assertions.assertThrows(NullPointerException.class, () -> new IdentityEncoder(channel, null, null));
Assertions.assertThrows(NullPointerException.class, () -> new IdentityEncoder(channel, outbuf, null));
}
Aggregations