Search in sources :

Example 1 with BufferOutputStream

use of io.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.

the class TestHighwayServerConnection method createBuffer.

protected Buffer createBuffer(WrapSchema schema, Object value) throws Exception {
    Buffer headerBuffer;
    LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
    ProtobufOutput output = new ProtobufOutput(linkedBuffer);
    schema.writeObject(output, value);
    try (BufferOutputStream os = new BufferOutputStream()) {
        LinkedBuffer.writeTo(os, linkedBuffer);
        headerBuffer = os.getBuffer();
    }
    return headerBuffer;
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) Buffer(io.vertx.core.buffer.Buffer) LinkedBuffer(io.protostuff.LinkedBuffer) BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) ProtobufOutput(io.protostuff.ProtobufOutput)

Example 2 with BufferOutputStream

use of io.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.

the class GrpcCodec method encodeRequest.

public static Buffer encodeRequest(Invocation invocation, OperationProtobuf operationProtobuf) throws Exception {
    try (BufferOutputStream os = new BufferOutputStream()) {
        // 写protobuf数据
        LinkedBuffer linkedBuffer = LinkedBuffer.allocate(BUFFER_SIZE);
        ProtobufOutput output = new ProtobufOutput(linkedBuffer);
        operationProtobuf.getRequestSchema().writeObject(output, invocation.getArgs());
        os.write(0);
        // protobuf输出到流
        LinkedBuffer.writeTo(os, linkedBuffer);
        return os.getBuffer();
    }
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) ProtobufOutput(io.protostuff.ProtobufOutput)

Example 3 with BufferOutputStream

use of io.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.

the class TestStandardObjectWriter method setUp.

@Before
public void setUp() throws Exception {
    StandardObjectWriter = new StandardObjectWriter(Mockito.mock(ObjectWriter.class));
    outputStream = new BufferOutputStream();
}
Also used : BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) Before(org.junit.Before)

Example 4 with BufferOutputStream

use of io.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.

the class RestClientRequestImpl method genBodyBuffer.

private void genBodyBuffer() throws Exception {
    request.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    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());
                output.write(value.getBytes(StandardCharsets.UTF_8));
            }
            output.write('&');
        }
        bodyBuffer = output.getBuffer();
    }
}
Also used : BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream)

Example 5 with BufferOutputStream

use of io.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.

the class TestProduce method testProduce.

/**
	 * Test Produce
	 * 
	 * @throws Exception
	 */
@Test
public void testProduce() throws Exception {
    Assert.assertEquals("produce processor mgr", ProduceProcessorManager.INSTANCE.getName());
    Buffer oBuffer = ProduceProcessorManager.DEFAULT_PROCESSOR.encodeResponse("test");
    OutputStream oOutputStream = new BufferOutputStream();
    ProduceProcessorManager.DEFAULT_PROCESSOR.encodeResponse(oOutputStream, "test2");
    JavaType targetType = TypeFactory.defaultInstance().constructType(String.class);
    InputStream oInputStream = new ByteArrayInputStream(("true").getBytes());
    ProduceProcessorManager.DEFAULT_PROCESSOR.decodeResponse(oInputStream, targetType);
    ProduceProcessorManager.PLAIN_PROCESSOR.encodeResponse(new BufferOutputStream(), "test2");
    Assert.assertNotEquals(null, ProduceProcessorManager.PLAIN_PROCESSOR.decodeResponse(oInputStream, targetType));
    oInputStream = new ByteArrayInputStream(("true").getBytes());
    Assert.assertNotEquals(null, ProduceProcessorManager.DEFAULT_PROCESSOR.decodeResponse(oInputStream, targetType));
    ProduceProcessorManager.DEFAULT_PROCESSOR.decodeResponse(oBuffer, targetType);
    Assert.assertEquals(null, ProduceProcessorManager.DEFAULT_PROCESSOR.encodeResponse(null));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) JavaType(com.fasterxml.jackson.databind.JavaType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) Test(org.junit.Test)

Aggregations

BufferOutputStream (io.servicecomb.foundation.vertx.stream.BufferOutputStream)8 LinkedBuffer (io.protostuff.LinkedBuffer)3 ProtobufOutput (io.protostuff.ProtobufOutput)3 Buffer (io.vertx.core.buffer.Buffer)2 Before (org.junit.Before)2 Test (org.junit.Test)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1