public static void writeBytes(byte[] from, int length, OutputStream to) throws IOException {
    int offset = 0;
    while (offset < length) {
      int chunkSize = Math.min(BUFFER_SIZE, length - offset);
      to.write(from, offset, chunkSize);
      offset += chunkSize;
    }
  }
public static void writeBytes(byte[] from, int length, OutputStream to)