Coggle requires JavaScript to display documents.
public static void dump(InputStream src, OutputStream dest) throws IOException { try(src; dest) { var data = new byte[1024]; var length = 0; while ((length = src.read(data)) != -1) { dest.write(data, 0, length); } } }
public static void dump(ReadableByteChannel src, WritableByteChannel dest) throws IOException { ByteBuffer buffer = ByteBuffer.allocate(1024); try(src; dest) { while(src.read(buffer) != -1) { //將資料從Channel中讀入Buffer buffer.flip(); //flip()方法標記Buffer中讀入資料的所在區塊 dest.write(buffer); //將Buffer資料寫到另一個Channel buffer.clear(); //最後使用clear()清除Buffer中的標記 } } }