Import java.io.ioException; import java.io.inputstream; import java.nio.bytebuffer; import java.nio.channels.Readablebytechannel;
Public Class ChannelInputStream Extends InputStream {
Private ReadableBytechannel Channel;
Public ChannelInputStream (ReadableBytechannel Channel) throws IllegalargumentException {if (Channel == Null) {throw new illegalargumentException ("The Readable Byte Channel Is Null);}
THIS.CHANNEL = CHANNEL;
Public int oException {bytebuffer buffer = bytebuffer.allocate (1); int result = channel (buffer); if (Result! = -1) {buffer.flip (); result = (int) buffer. Get (); buffer.clear ();} Return Result;
Public int {(Byte B []) throws ioException {bytebuffer buffer = bytebuffer.allocate (B.LENGTH); int result = channel (buffer); if (result! = -1) {buffer.flip (); buffer .get (b, 0, result); buffer.clear ();} Return Result;}
Public int {byte b [], int offs ooException {bytebuffer buffer = bytebuffer.allocate (b.Length); int result = channel (buffer); if (Result! = -1) {buffer .flip (); buffer.get (b, off, len> result? result: len); buffer.clear ();} return result;}
Public void close () throws oException {channel.close ();}}