use of org.apache.servicecomb.foundation.vertx.stream.BufferInputStream in project java-chassis by ServiceComb.
the class TestStream method testBufferInputStream.
@Test
public void testBufferInputStream() {
ByteBuf obuf = Buffer.buffer(DIRECT_BUFFER_SIZE).getByteBuf();
obuf.writeBytes(("testss").getBytes());
@SuppressWarnings("resource") BufferInputStream oBufferInputStream = new BufferInputStream(obuf);
Assert.assertNotEquals(1234, oBufferInputStream.skip(0));
Assert.assertNotEquals(obuf.readByte(), oBufferInputStream.readByte());
Assert.assertEquals(obuf.readByte() + 1, oBufferInputStream.read());
Assert.assertEquals(obuf.readBoolean(), oBufferInputStream.readBoolean());
Assert.assertEquals(obuf.readerIndex(), oBufferInputStream.getIndex());
Assert.assertEquals(obuf.readableBytes(), oBufferInputStream.available());
Assert.assertNotEquals(null, oBufferInputStream.read(("test").getBytes()));
}
use of org.apache.servicecomb.foundation.vertx.stream.BufferInputStream in project java-chassis by ServiceComb.
the class StandardHttpServletRequestEx method getInputStream.
@Override
public ServletInputStream getInputStream() throws IOException {
if (this.inputStream == null) {
if (cacheRequest) {
byte[] inputBytes = IOUtils.toByteArray(getRequest().getInputStream());
ByteBuf byteBuf = Unpooled.wrappedBuffer(inputBytes);
this.inputStream = new BufferInputStream(byteBuf);
setBodyBuffer(Buffer.buffer(Unpooled.wrappedBuffer(byteBuf)));
} else {
this.inputStream = getRequest().getInputStream();
}
}
return this.inputStream;
}
use of org.apache.servicecomb.foundation.vertx.stream.BufferInputStream in project incubator-servicecomb-java-chassis by apache.
the class StandardHttpServletRequestEx method getInputStream.
@Override
public ServletInputStream getInputStream() throws IOException {
if (this.inputStream == null) {
if (cacheRequest) {
byte[] inputBytes = IOUtils.toByteArray(getRequest().getInputStream());
ByteBuf byteBuf = Unpooled.wrappedBuffer(inputBytes);
this.inputStream = new BufferInputStream(byteBuf);
setBodyBuffer(Buffer.buffer(Unpooled.wrappedBuffer(byteBuf)));
} else {
this.inputStream = getRequest().getInputStream();
}
}
return this.inputStream;
}
use of org.apache.servicecomb.foundation.vertx.stream.BufferInputStream in project java-chassis by ServiceComb.
the class TestStandardHttpServletRequestEx method parameterMap_merge.
@Test
public void parameterMap_merge() throws IOException {
Map<String, String[]> inherited = new HashMap<>();
String[] v1 = new String[] { "v1-1", "v1-2" };
inherited.put("p1", v1);
Buffer buffer = Buffer.buffer("p1=v1-3;p2=v2");
BufferInputStream inputStream = new BufferInputStream(buffer.getByteBuf());
new Expectations() {
{
request.getParameterMap();
result = inherited;
request.getMethod();
result = HttpMethod.PUT;
request.getContentType();
result = MediaType.APPLICATION_FORM_URLENCODED.toUpperCase(Locale.US) + ";abc";
request.getInputStream();
result = inputStream;
}
};
Assert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("p1", "p2"));
Assert.assertThat(requestEx.getParameterValues("p1"), Matchers.arrayContaining("v1-1", "v1-2", "v1-3"));
Assert.assertEquals("v1-1", requestEx.getParameter("p1"));
}
use of org.apache.servicecomb.foundation.vertx.stream.BufferInputStream in project java-chassis by ServiceComb.
the class TestVertxUtils method testgetBytesFastBufferInputStream.
@Test
public void testgetBytesFastBufferInputStream() throws IOException {
byte[] bytes = new byte[] { 1 };
ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
try (BufferInputStream inputStream = new BufferInputStream(byteBuf)) {
byte[] result = VertxUtils.getBytesFast(inputStream);
Assert.assertSame(bytes, result);
}
}
Aggregations