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;
}
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();
}
}
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();
}
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();
}
}
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));
}
Aggregations