本文整理汇总了Java中org.apache.calcite.avatica.AvaticaUtils.readFullyToBytes方法的典型用法代码示例。如果您正苦于以下问题:Java AvaticaUtils.readFullyToBytes方法的具体用法?Java AvaticaUtils.readFullyToBytes怎么用?Java AvaticaUtils.readFullyToBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.avatica.AvaticaUtils
的用法示例。
在下文中一共展示了AvaticaUtils.readFullyToBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMalformedRequest
import org.apache.calcite.avatica.AvaticaUtils; //导入方法依赖的package包/类
@Test public void testMalformedRequest() throws Exception {
URL url = new URL("http://localhost:" + this.port);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
// Write some garbage data
wr.write(new byte[] {0, 1, 2, 3, 4, 5, 6, 7});
wr.flush();
wr.close();
}
final int responseCode = conn.getResponseCode();
assertEquals(500, responseCode);
final InputStream inputStream = conn.getErrorStream();
byte[] responseBytes = AvaticaUtils.readFullyToBytes(inputStream);
ErrorResponse response;
switch (this.serialization) {
case JSON:
response = JsonService.MAPPER.readValue(responseBytes, ErrorResponse.class);
assertTrue("Unexpected error message: " + response.errorMessage,
response.errorMessage.contains("Illegal character"));
break;
case PROTOBUF:
ProtobufTranslation pbTranslation = new ProtobufTranslationImpl();
Response genericResp = pbTranslation.parseResponse(responseBytes);
assertTrue("Response was not an ErrorResponse, but was " + genericResp.getClass(),
genericResp instanceof ErrorResponse);
response = (ErrorResponse) genericResp;
assertTrue("Unexpected error message: " + response.errorMessage,
response.errorMessage.contains("contained an invalid tag"));
break;
default:
fail("Unhandled serialization " + this.serialization);
throw new RuntimeException();
}
}
示例2: send
import org.apache.calcite.avatica.AvaticaUtils; //导入方法依赖的package包/类
public byte[] send(byte[] request) {
// TODO back-off policy?
while (true) {
try {
final HttpURLConnection connection = openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
wr.write(request);
wr.flush();
wr.close();
}
final int responseCode = connection.getResponseCode();
final InputStream inputStream;
if (responseCode == HttpURLConnection.HTTP_UNAVAILABLE) {
// Could be sitting behind a load-balancer, try again.
continue;
} else if (responseCode != HttpURLConnection.HTTP_OK) {
inputStream = connection.getErrorStream();
if (inputStream == null) {
// HTTP Transport exception that resulted in no content coming back
throw new RuntimeException("Failed to read data from the server: HTTP/" + responseCode);
}
} else {
inputStream = connection.getInputStream();
}
return AvaticaUtils.readFullyToBytes(inputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
示例3: traceResponse
import org.apache.calcite.avatica.AvaticaUtils; //导入方法依赖的package包/类
private InputStream traceResponse(InputStream in) {
if (CalcitePrepareImpl.DEBUG) {
try {
final byte[] bytes = AvaticaUtils.readFullyToBytes(in);
in.close();
System.out.println("Response: "
+ new String(bytes, StandardCharsets.UTF_8));
in = new ByteArrayInputStream(bytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return in;
}