fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. ArrayList<byte[]> buffer = new ArrayList<>(770000);
  13. for(int i = 0; i < 770000; ++i)
  14. {
  15. buffer.add("0000000000000000000000000000000000000000".getBytes());
  16. }
  17.  
  18. final long begin = System.nanoTime();
  19. write(os, buffer);
  20.  
  21. try (OutputStream outputStream = new FileOutputStream("/tmp/bytes.txt")) {
  22. outputStream.write(os.toByteArray());
  23. outputStream.flush();
  24. }
  25.  
  26. final long end = System.nanoTime();
  27. System.out.println((end - begin) / 10000000.0 + "ms");
  28. }
  29.  
  30. public static void write(OutputStream out, ArrayList<byte[]> buffer) throws IOException {
  31. for (byte[] packet: buffer) {
  32. out.write(packet);
  33. }
  34. }
  35. }
Success #stdin #stdout 0.36s 201100KB
stdin
Standard input is empty
stdout
29.7353156ms