org.apache.abdera.util.io
Class ReadWriteByteChannel
java.lang.Object
org.apache.abdera.util.io.ReadWriteByteChannel
- All Implemented Interfaces:
- java.io.Closeable, java.io.Serializable, java.lang.Cloneable, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel
public class ReadWriteByteChannel
- extends java.lang.Object
- implements java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel, java.lang.Cloneable, java.io.Serializable
Implements a buffer that provides a slightly more efficient way of writing,
and then reading a stream of bytes.
To use:
ReadWriteByteChannel rw = new ReadWriteByteChannel();
OutputStream out = rw.getOutputStream();
out.write(bytes);
out.close();
InputStream in = rw.getInputStream();
int i = -1;
while ((i = in.read()) != -1) {...}
By default, closing the OutputStream will automatically cause it to
flip over to Read mode, locking the buffer from further writes and
setting the read position to 0.
Once the Buffer has been fully read, it must be reset, which sets it
back into write mode and moves the position pointer back to 0;
- See Also:
- Serialized Form
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
position
protected int position
scale
protected int scale
closed
protected boolean closed
buffer
protected byte[] buffer
flipped
protected boolean flipped
flipOnClose
protected boolean flipOnClose
ReadWriteByteChannel
public ReadWriteByteChannel()
ReadWriteByteChannel
public ReadWriteByteChannel(int capacity)
ReadWriteByteChannel
public ReadWriteByteChannel(int capacity,
boolean flipOnClose)
clone
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
- Overrides:
clone
in class java.lang.Object
- Throws:
java.lang.CloneNotSupportedException
getInputStream
public java.io.InputStream getInputStream()
getOutputStream
public java.io.OutputStream getOutputStream()
getWriter
public java.io.Writer getWriter(java.lang.String charset)
getReader
public java.io.Reader getReader(java.lang.String charset)
getBuffer
public byte[] getBuffer()
getIterator
public CodepointIterator getIterator()
getIterator
public CodepointIterator getIterator(java.lang.String charset)
read
public int read(java.nio.ByteBuffer dst)
throws java.io.IOException
- Specified by:
read
in interface java.nio.channels.ReadableByteChannel
- Throws:
java.io.IOException
flip
public void flip()
rewind
public void rewind()
reset
public void reset()
close
public void close()
throws java.io.IOException
- Specified by:
close
in interface java.io.Closeable
- Specified by:
close
in interface java.nio.channels.Channel
- Throws:
java.io.IOException
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interface java.nio.channels.Channel
write
public int write(java.nio.ByteBuffer src)
throws java.io.IOException
- Specified by:
write
in interface java.nio.channels.WritableByteChannel
- Throws:
java.io.IOException
transferTo
public void transferTo(java.nio.channels.WritableByteChannel channel)
throws java.io.IOException
- Throws:
java.io.IOException