content: package com.chaitin.xray.utils;
  
  import java.io.*;
  import java.nio.charset.StandardCharsets;
  
  public class IOUtil {
  
      @SuppressWarnings("unused")
      public static byte[] readBytesFromIs(InputStream is) {
          try {
              ByteArrayOutputStream buffer = new ByteArrayOutputStream();
              int nRead;
              byte[] data = new byte[16384];
              while ((nRead = is.read(data, 0, data.length)) != -1) {
                  buffer.write(data, 0, nRead);
              }
              return buffer.toByteArray();
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  
      public static String readStringFromIs(InputStream stream) {
          try {
              int bufferSize = 1024;
              char[] buffer = new char[bufferSize];
              StringBuilder out = new StringBuilder();
              Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8);
              for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) {
                  out.append(buffer, 0, numRead);
              }
              return out.toString();
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  }
  