Package org.apache.abdera.i18n.text.io
Class PipeChannel
- java.lang.Object
-
- org.apache.abdera.i18n.text.io.PipeChannel
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.Appendable,java.lang.AutoCloseable,java.lang.Readable,java.nio.channels.Channel,java.nio.channels.ReadableByteChannel,java.nio.channels.WritableByteChannel
public class PipeChannel extends java.lang.Object implements java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel, java.lang.Appendable, java.lang.Readable, java.io.CloseableImplements a buffer that provides a slightly more efficient way of writing, and then reading a stream of bytes. To use: PipeChannel pipe = new PipeChannel(); byte[] bytes = {'a','b','c','d'}; pipe.write(bytes); pipe.close(); InputStream in = pipe.getInputStream(); int i = -1; while ((i = in.read()) != -1) {...} By default, closing 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
-
-
Constructor Summary
Constructors Constructor Description PipeChannel()PipeChannel(java.lang.String charset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Appendableappend(char c)java.lang.Appendableappend(char c, java.lang.String charset)java.lang.Appendableappend(java.lang.CharSequence csq)java.lang.Appendableappend(java.lang.CharSequence csq, int start, int end)java.lang.Appendableappend(java.lang.CharSequence csq, int start, int end, java.lang.String charset)java.lang.Appendableappend(java.lang.CharSequence csq, java.lang.String charset)voidclose()If the pipe is writable, this will close the input and switch to readable mode If the pipe is readable, this will close the output and reset the pipejava.io.InputStreamgetInputStream()Get an inputstream that can read from this pipe.CodepointIteratorgetIterator()Get a CodepointIterator that can iterate over unicode codepoints in this pipe.CodepointIteratorgetIterator(java.lang.String charset)Get a CodepointIterator that can iterate over unicode codepoints in this pipe.java.io.OutputStreamgetOutputStream()Get an outputstream that can write to this pipe.java.io.ReadergetReader()Get a reader that can reader from this pipe.java.io.ReadergetReader(java.lang.String charset)Get a reader that can reader from this pipe.java.io.WritergetWriter()Get a writer that can write to this pipe.java.io.WritergetWriter(java.lang.String charset)Get a writer that can write to this pipe.booleanisOpen()True if the pipe is openbooleanisReadable()True if this pipe is readablebooleanisWritable()True if this pipe is writableintread(byte[] dst)Read from the pipe.intread(byte[] dst, int offset, int length)Read from the pipe.intread(java.nio.ByteBuffer dst)Read from the pipe.intread(java.nio.CharBuffer cb)intread(java.nio.CharBuffer cb, java.lang.String charset)voidreset()Reset the pipe.intwrite(byte[] src)Write to the pipeintwrite(byte[] src, int offset, int len)Write to the pipeintwrite(java.nio.ByteBuffer src)Write to the pipe
-
-
-
Method Detail
-
getInputStream
public java.io.InputStream getInputStream()
Get an inputstream that can read from this pipe. The Pipe must be readable
-
getOutputStream
public java.io.OutputStream getOutputStream()
Get an outputstream that can write to this pipe. The Pipe must be writable
-
getWriter
public java.io.Writer getWriter()
Get a writer that can write to this pipe. The pipe must be writable
-
getWriter
public java.io.Writer getWriter(java.lang.String charset)
Get a writer that can write to this pipe. The pipe must be writable
-
getReader
public java.io.Reader getReader(java.lang.String charset)
Get a reader that can reader from this pipe. The pipe must be readable
-
getReader
public java.io.Reader getReader()
Get a reader that can reader from this pipe. The pipe must be readable
-
getIterator
public CodepointIterator getIterator()
Get a CodepointIterator that can iterate over unicode codepoints in this pipe. The pipe must be readable
-
getIterator
public CodepointIterator getIterator(java.lang.String charset)
Get a CodepointIterator that can iterate over unicode codepoints in this pipe. The pipe must be readable
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOExceptionRead from the pipe.- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Throws:
java.io.IOException
-
read
public int read(byte[] dst) throws java.io.IOExceptionRead from the pipe.- Throws:
java.io.IOException
-
read
public int read(byte[] dst, int offset, int length) throws java.io.IOExceptionRead from the pipe.- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
True if the pipe is open- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOExceptionWrite to the pipe- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Throws:
java.io.IOException
-
write
public int write(byte[] src) throws java.io.IOExceptionWrite to the pipe- Throws:
java.io.IOException
-
write
public int write(byte[] src, int offset, int len) throws java.io.IOExceptionWrite to the pipe- Throws:
java.io.IOException
-
isReadable
public boolean isReadable()
True if this pipe is readable
-
isWritable
public boolean isWritable()
True if this pipe is writable
-
close
public void close() throws java.io.IOExceptionIf the pipe is writable, this will close the input and switch to readable mode If the pipe is readable, this will close the output and reset the pipe- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
reset
public void reset()
Reset the pipe. Switches the pipe to writable mode
-
append
public java.lang.Appendable append(java.lang.CharSequence csq) throws java.io.IOException- Specified by:
appendin interfacejava.lang.Appendable- Throws:
java.io.IOException
-
append
public java.lang.Appendable append(char c) throws java.io.IOException- Specified by:
appendin interfacejava.lang.Appendable- Throws:
java.io.IOException
-
append
public java.lang.Appendable append(java.lang.CharSequence csq, int start, int end) throws java.io.IOException- Specified by:
appendin interfacejava.lang.Appendable- Throws:
java.io.IOException
-
append
public java.lang.Appendable append(java.lang.CharSequence csq, java.lang.String charset) throws java.io.IOException- Throws:
java.io.IOException
-
append
public java.lang.Appendable append(char c, java.lang.String charset) throws java.io.IOException- Throws:
java.io.IOException
-
append
public java.lang.Appendable append(java.lang.CharSequence csq, int start, int end, java.lang.String charset) throws java.io.IOException- Throws:
java.io.IOException
-
read
public int read(java.nio.CharBuffer cb) throws java.io.IOException- Specified by:
readin interfacejava.lang.Readable- Throws:
java.io.IOException
-
read
public int read(java.nio.CharBuffer cb, java.lang.String charset) throws java.io.IOException- Throws:
java.io.IOException
-
-