public static ByteArrayOutputStream readAll(InputStream instream, long maxSize)
      throws IOException {
    ByteArrayOutputStream outstream = new ByteArrayOutputStream(4096);

    readAndWrite(instream, maxSize, outstream);

    outstream.close();
    return outstream;
  }