org.apache.abdera.i18n.text.io
Class PipeChannel

java.lang.Object
  extended by org.apache.abdera.i18n.text.io.PipeChannel
All Implemented Interfaces:
Closeable, Appendable, Readable, Channel, ReadableByteChannel, WritableByteChannel

public class PipeChannel
extends Object
implements ReadableByteChannel, WritableByteChannel, Appendable, Readable, Closeable

Implements 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


Field Summary
protected  String charset
           
protected  boolean flipped
           
protected  Pipe pipe
           
 
Constructor Summary
PipeChannel()
           
PipeChannel(String charset)
           
 
Method Summary
 Appendable append(char c)
           
 Appendable append(CharSequence csq)
           
 Appendable append(CharSequence csq, int start, int end)
           
 Appendable append(CharSequence csq, int start, int end, String charset)
           
 Appendable append(CharSequence csq, String charset)
           
 Appendable append(char c, String charset)
           
 void close()
          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 pipe
 InputStream getInputStream()
          Get an inputstream that can read from this pipe.
 CodepointIterator getIterator()
          Get a CodepointIterator that can iterate over unicode codepoints in this pipe.
 CodepointIterator getIterator(String charset)
          Get a CodepointIterator that can iterate over unicode codepoints in this pipe.
 OutputStream getOutputStream()
          Get an outputstream that can write to this pipe.
 Reader getReader()
          Get a reader that can reader from this pipe.
 Reader getReader(String charset)
          Get a reader that can reader from this pipe.
 Writer getWriter()
          Get a writer that can write to this pipe.
 Writer getWriter(String charset)
          Get a writer that can write to this pipe.
 boolean isOpen()
          True if the pipe is open
 boolean isReadable()
          True if this pipe is readable
 boolean isWritable()
          True if this pipe is writable
 int read(byte[] dst)
          Read from the pipe.
 int read(byte[] dst, int offset, int length)
          Read from the pipe.
 int read(ByteBuffer dst)
          Read from the pipe.
 int read(CharBuffer cb)
           
 int read(CharBuffer cb, String charset)
           
 void reset()
          Reset the pipe.
 int write(byte[] src)
          Write to the pipe
 int write(byte[] src, int offset, int len)
          Write to the pipe
 int write(ByteBuffer src)
          Write to the pipe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

charset

protected String charset

pipe

protected Pipe pipe

flipped

protected boolean flipped
Constructor Detail

PipeChannel

public PipeChannel()

PipeChannel

public PipeChannel(String charset)
Method Detail

getInputStream

public InputStream getInputStream()
Get an inputstream that can read from this pipe. The Pipe must be readable


getOutputStream

public OutputStream getOutputStream()
Get an outputstream that can write to this pipe. The Pipe must be writable


getWriter

public Writer getWriter()
Get a writer that can write to this pipe. The pipe must be writable


getWriter

public Writer getWriter(String charset)
Get a writer that can write to this pipe. The pipe must be writable


getReader

public Reader getReader(String charset)
Get a reader that can reader from this pipe. The pipe must be readable


getReader

public 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(String charset)
Get a CodepointIterator that can iterate over unicode codepoints in this pipe. The pipe must be readable


read

public int read(ByteBuffer dst)
         throws IOException
Read from the pipe.

Specified by:
read in interface ReadableByteChannel
Throws:
IOException

read

public int read(byte[] dst)
         throws IOException
Read from the pipe.

Throws:
IOException

read

public int read(byte[] dst,
                int offset,
                int length)
         throws IOException
Read from the pipe.

Throws:
IOException

isOpen

public boolean isOpen()
True if the pipe is open

Specified by:
isOpen in interface Channel

write

public int write(ByteBuffer src)
          throws IOException
Write to the pipe

Specified by:
write in interface WritableByteChannel
Throws:
IOException

write

public int write(byte[] src)
          throws IOException
Write to the pipe

Throws:
IOException

write

public int write(byte[] src,
                 int offset,
                 int len)
          throws IOException
Write to the pipe

Throws:
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 IOException
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 pipe

Specified by:
close in interface Closeable
Specified by:
close in interface Channel
Throws:
IOException

reset

public void reset()
Reset the pipe. Switches the pipe to writable mode


append

public Appendable append(CharSequence csq)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Appendable append(char c)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Appendable append(CharSequence csq,
                         int start,
                         int end)
                  throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public Appendable append(CharSequence csq,
                         String charset)
                  throws IOException
Throws:
IOException

append

public Appendable append(char c,
                         String charset)
                  throws IOException
Throws:
IOException

append

public Appendable append(CharSequence csq,
                         int start,
                         int end,
                         String charset)
                  throws IOException
Throws:
IOException

read

public int read(CharBuffer cb)
         throws IOException
Specified by:
read in interface Readable
Throws:
IOException

read

public int read(CharBuffer cb,
                String charset)
         throws IOException
Throws:
IOException


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.