コード例 #1
0
  private static void writeToFile(
      @NotNull File file, @NotNull byte[] text, int off, int len, boolean append)
      throws IOException {
    createParentDirs(file);

    OutputStream stream = new FileOutputStream(file, append);
    try {
      stream.write(text, off, len);
    } finally {
      stream.close();
    }
  }
コード例 #2
0
 public static void copy(
     @NotNull InputStream inputStream, int maxSize, @NotNull OutputStream outputStream)
     throws IOException {
   final byte[] buffer = BUFFER.get();
   int toRead = maxSize;
   while (toRead > 0) {
     int read = inputStream.read(buffer, 0, Math.min(buffer.length, toRead));
     if (read < 0) break;
     toRead -= read;
     outputStream.write(buffer, 0, read);
   }
 }