### Question:
BufferedIoUtils { public static void readInputStream(InputStream in, int bufSize, Callback<byte[]> callback) throws Exception { int properBufferSize = properBufferSize(bufSize); byte[] buf = new byte[properBufferSize]; BufferedInputStream bin = null; try { bin = new BufferedInputStream(in); int read; while ((read = bin.read(buf)) != -1) { System.out.println(read); callback.on(ArrayUtils.subarray(buf, 0, read)); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { if (bin != null) { try { bin.close(); } catch (IOException e) { e.printStackTrace(); } } } }  static void readInputStream(InputStream in, int bufSize, Callback<byte[]> callback); static void writeInputStreamToFile(InputStream in, int bufSize, File targetFile);  }### Answer:
@Test public void testCallback() { File outFile = new File(SystemUtils.getUserHome(), "tmp/SwiftGantt_0.4.0_release_withdemo.zip"); FileOutputStream fout = null; try { URL url = new URL(path); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); System.out.println("download " + path); InputStream inputStream = httpConn.getInputStream(); fout = new FileOutputStream(outFile); FileOutputStream finalFout = fout; BufferedIoUtils.readInputStream(inputStream, 1024, t -> { System.out.println(t.length); finalFout.write(t); }); System.out.println("complete: " + outFile); } catch (Exception e) { e.printStackTrace(); } finally { if (fout != null) { try { fout.close(); } catch (IOException e) { e.printStackTrace(); } } } }