use of org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream in project incubator-servicecomb-java-chassis by apache.
the class TestStream method testBufferOutputStream.
@Test
public void testBufferOutputStream() {
@SuppressWarnings({ "resource" }) BufferOutputStream oBufferOutputStream = new BufferOutputStream();
oBufferOutputStream.writeString("test");
Assert.assertNotEquals(null, oBufferOutputStream.writerIndex());
oBufferOutputStream.write(1);
oBufferOutputStream.write(true);
Assert.assertEquals(true, (1 < oBufferOutputStream.length()));
}
use of org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream in project incubator-servicecomb-java-chassis by apache.
the class RestClientRequestImpl method genBodyForm.
private void genBodyForm(String boundary) {
if (formMap == null) {
return;
}
try {
try (BufferOutputStream output = new BufferOutputStream()) {
for (Entry<String, Object> entry : formMap.entrySet()) {
output.write(bytesOf("\r\n"));
output.write(bytesOf("--" + boundary + "\r\n"));
output.write(bytesOf("Content-Disposition: form-data; name=\"" + entry.getKey() + "\"\r\n\r\n"));
if (entry.getValue() != null) {
String value = RestObjectMapper.INSTANCE.convertToString(entry.getValue());
output.write(value.getBytes(StandardCharsets.UTF_8));
}
}
request.write(output.getBuffer());
}
} catch (Exception e) {
asyncResp.consumerFail(e);
}
}
use of org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream in project incubator-servicecomb-java-chassis by apache.
the class RestClientRequestImpl method genBodyBuffer.
private void genBodyBuffer() throws Exception {
if (bodyBuffer != null) {
return;
}
if (formMap == null) {
return;
}
request.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
try (BufferOutputStream output = new BufferOutputStream()) {
for (Entry<String, Object> entry : formMap.entrySet()) {
output.write(entry.getKey().getBytes(StandardCharsets.UTF_8));
output.write('=');
if (entry.getValue() != null) {
String value = RestObjectMapper.INSTANCE.convertToString(entry.getValue());
value = URLEncoder.encode(value, StandardCharsets.UTF_8.name());
output.write(value.getBytes(StandardCharsets.UTF_8));
}
output.write('&');
}
bodyBuffer = output.getBuffer();
}
}
use of org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream in project incubator-servicecomb-java-chassis by apache.
the class TestStandardObjectWriter method setUp.
@Before
public void setUp() throws Exception {
StandardObjectWriter = new StandardObjectWriter(Mockito.mock(ObjectWriter.class));
outputStream = new BufferOutputStream();
}
use of org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.
the class TestStream method testBufferOutputStream.
@Test
public void testBufferOutputStream() {
@SuppressWarnings({ "resource" }) BufferOutputStream oBufferOutputStream = new BufferOutputStream();
oBufferOutputStream.writeString("test");
Assert.assertNotEquals(null, oBufferOutputStream.writerIndex());
oBufferOutputStream.write(1);
oBufferOutputStream.write(true);
Assert.assertEquals(true, (1 < oBufferOutputStream.length()));
}
Aggregations