Search in sources :

Example 1 with BufferOutputStream

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()));
}
Also used : BufferOutputStream(org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream) Test(org.junit.Test)

Example 2 with BufferOutputStream

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);
    }
}
Also used : BufferOutputStream(org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream) IOException(java.io.IOException)

Example 3 with BufferOutputStream

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();
    }
}
Also used : BufferOutputStream(org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream)

Example 4 with BufferOutputStream

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();
}
Also used : BufferOutputStream(org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream) Before(org.junit.Before)

Example 5 with 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()));
}
Also used : BufferOutputStream(org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream) Test(org.junit.Test)

Aggregations

BufferOutputStream (org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream)12 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)2 Response (org.apache.servicecomb.swagger.invocation.Response)2 Before (org.junit.Before)2 Test (org.junit.Test)2 LinkedBuffer (io.protostuff.LinkedBuffer)1 ProtobufOutput (io.protostuff.ProtobufOutput)1 Buffer (io.vertx.core.buffer.Buffer)1 IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1