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; }
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)); // CHECKSTYLE: IGNORE 0 in = new ByteArrayInputStream(bytes); } catch (IOException e) { throw new RuntimeException(e); } } return in; }
/** Reads the contents of an input stream and returns as a string. */ public static byte[] readFullyToBytes(InputStream inputStream) throws IOException { return readFullyToBytes(inputStream, new UnsynchronizedBuffer(1024)); }
/** Reads the contents of an input stream and returns as a string. */ public static byte[] readFullyToBytes(InputStream inputStream) throws IOException { return readFullyToBytes(inputStream, new UnsynchronizedBuffer(1024)); }
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(); } else { inputStream = connection.getInputStream(); } return AvaticaUtils.readFullyToBytes(inputStream); } catch (IOException e) { throw new RuntimeException(e); } } }
inputStream = connection.getInputStream(); return AvaticaUtils.readFullyToBytes(inputStream); } catch (IOException e) { throw new RuntimeException(e);
inputStream = connection.getInputStream(); return AvaticaUtils.readFullyToBytes(inputStream); } catch (IOException e) { throw new RuntimeException(e);
requestBytes = AvaticaUtils.readFullyToBytes(inputStream, buffer); } finally { buffer.reset();
requestBytes = AvaticaUtils.readFullyToBytes(inputStream, buffer); } finally { buffer.reset();
final byte[] bytes = AvaticaUtils.readFullyToBytes(in); System.out.println("Response: " + new String(bytes, StandardCharsets.UTF_8));
final byte[] bytes = AvaticaUtils.readFullyToBytes(in); System.out.println("Response: " + new String(bytes, StandardCharsets.UTF_8)); // CHECKSTYLE: IGNORE 0