+ Converting a ByteArrayInputStream to a ReadableByteChannel Joris Van den Bogaert Main.java: import java.nio.channels.*; import java.nio.*; import java.io.*; public class Main { public static void main(String []args) throws Exception { byte[] buffer = "contents of the buffer".getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(buffer); ReadableByteChannel byteChannel = Channels.newChannel(bais); ByteBuffer bb = ByteBuffer.allocate(10); int n; while ((n = byteChannel.read(bb)) > -1) { bb.rewind(); for (int i=0; i<n; i++) { System.out.print((char) bb.get()); } } } }
Converting a ByteArrayInputStream to a ReadableByteChannel
Joris Van den BogaertMain.java: