com.go.trove.io
Class FastCharToByteBuffer

java.lang.Object
  |
  +--com.go.trove.io.FastCharToByteBuffer
All Implemented Interfaces:
ByteBuffer, ByteData, CharToByteBuffer, java.io.Serializable

public class FastCharToByteBuffer
extends java.lang.Object
implements CharToByteBuffer, java.io.Serializable

A CharToByteBuffer implementation that converts ISO-8859-1 encoded characters faster. To force fast conversion, construct FastCharToByteBuffer with ISO-8859-1 as the default encoding.

Version:
1 , 01/06/14
Author:
Brian S O'Neill
See Also:
Serialized Form

Constructor Summary
FastCharToByteBuffer(ByteBuffer buffer)
           
FastCharToByteBuffer(ByteBuffer buffer, java.lang.String defaultEncoding)
           
 
Method Summary
 void addCaptureBuffer(ByteBuffer buffer)
          Add a ByteBuffer that will receive a copy of all the data appended to this ByteBuffer.
 void append(byte b)
          Add one byte to the end of this buffer.
 void append(byte[] bytes)
          Copy the given bytes to the end of this buffer.
 void append(byte[] bytes, int offset, int length)
          Copy the given bytes to the end of this buffer, starting at the offset, using the length provided.
 void append(char c)
          Add one character to the end of this buffer.
 void append(char[] chars)
          Copy the given characters to the end of this buffer.
 void append(char[] chars, int offset, int length)
          Copy the given characters to the end of this buffer, starting at the offset, using the length provided.
 void append(java.lang.String str)
          Copy the given String to the end of this buffer.
 void append(java.lang.String str, int offset, int length)
          Copy the given String to the end of this buffer, starting at the offset, using the length provided.
 void appendSurrogate(ByteData s)
          Append ByteData that will not be touched until this ByteBuffer needs to calculate its byte count, or it needs to write out.
 void drain()
          Force any buffered characters to be immediately converted to bytes.
 long getBaseByteCount()
          Returns the base byte count, which excludes surrogates.
 long getByteCount()
          Return the amount of bytes that will be written by the writeTo method.
 java.lang.String getEncoding()
          Returns the current encoding that is being used to convert characters to bytes or null if no encoding has been set yet.
 void removeCaptureBuffer(ByteBuffer buffer)
          Remove a capture buffer that was previously added by addCaptureBuffer.
 void reset()
          Reset any transient data stored in this ByteData.
 void setEncoding(java.lang.String enc)
          Set the encoding for converting characters to bytes.
 void writeTo(java.io.OutputStream out)
          Writes all the bytes to the given OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FastCharToByteBuffer

public FastCharToByteBuffer(ByteBuffer buffer)
Parameters:
buffer - Buffer that receives the characters converted to bytes.

FastCharToByteBuffer

public FastCharToByteBuffer(ByteBuffer buffer,
                            java.lang.String defaultEncoding)
Parameters:
buffer - Buffer that receives the characters converted to bytes.
defaultEncoding - Default character encoding to use if setEncoding is not called.
Method Detail

setEncoding

public void setEncoding(java.lang.String enc)
                 throws java.io.IOException
Description copied from interface: CharToByteBuffer
Set the encoding for converting characters to bytes. Calling getEncoding will return the canonical encoding name and may differ from the encoding name provided to this method.
Specified by:
setEncoding in interface CharToByteBuffer

getEncoding

public java.lang.String getEncoding()
                             throws java.io.IOException
Description copied from interface: CharToByteBuffer
Returns the current encoding that is being used to convert characters to bytes or null if no encoding has been set yet. The encoding name that is returned is canonical and may differ from the name passed into setEncoding.
Specified by:
getEncoding in interface CharToByteBuffer

getBaseByteCount

public long getBaseByteCount()
                      throws java.io.IOException
Description copied from interface: ByteBuffer
Returns the base byte count, which excludes surrogates.
Specified by:
getBaseByteCount in interface ByteBuffer

getByteCount

public long getByteCount()
                  throws java.io.IOException
Description copied from interface: ByteData
Return the amount of bytes that will be written by the writeTo method.
Specified by:
getByteCount in interface ByteData

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Description copied from interface: ByteData
Writes all the bytes to the given OutputStream.
Specified by:
writeTo in interface ByteData

append

public void append(byte b)
            throws java.io.IOException
Description copied from interface: ByteBuffer
Add one byte to the end of this buffer.
Specified by:
append in interface ByteBuffer

append

public void append(byte[] bytes)
            throws java.io.IOException
Description copied from interface: ByteBuffer
Copy the given bytes to the end of this buffer.
Specified by:
append in interface ByteBuffer

append

public void append(byte[] bytes,
                   int offset,
                   int length)
            throws java.io.IOException
Description copied from interface: ByteBuffer
Copy the given bytes to the end of this buffer, starting at the offset, using the length provided.
Specified by:
append in interface ByteBuffer

appendSurrogate

public void appendSurrogate(ByteData s)
                     throws java.io.IOException
Description copied from interface: ByteBuffer
Append ByteData that will not be touched until this ByteBuffer needs to calculate its byte count, or it needs to write out. A null surrogate is not appended.
Specified by:
appendSurrogate in interface ByteBuffer

addCaptureBuffer

public void addCaptureBuffer(ByteBuffer buffer)
                      throws java.io.IOException
Description copied from interface: ByteBuffer
Add a ByteBuffer that will receive a copy of all the data appended to this ByteBuffer.
Specified by:
addCaptureBuffer in interface ByteBuffer

removeCaptureBuffer

public void removeCaptureBuffer(ByteBuffer buffer)
                         throws java.io.IOException
Description copied from interface: ByteBuffer
Remove a capture buffer that was previously added by addCaptureBuffer.
Specified by:
removeCaptureBuffer in interface ByteBuffer

append

public void append(char c)
            throws java.io.IOException
Description copied from interface: CharToByteBuffer
Add one character to the end of this buffer.
Specified by:
append in interface CharToByteBuffer

append

public void append(char[] chars)
            throws java.io.IOException
Description copied from interface: CharToByteBuffer
Copy the given characters to the end of this buffer.
Specified by:
append in interface CharToByteBuffer

append

public void append(char[] chars,
                   int offset,
                   int length)
            throws java.io.IOException
Description copied from interface: CharToByteBuffer
Copy the given characters to the end of this buffer, starting at the offset, using the length provided.
Specified by:
append in interface CharToByteBuffer

append

public void append(java.lang.String str)
            throws java.io.IOException
Description copied from interface: CharToByteBuffer
Copy the given String to the end of this buffer.
Specified by:
append in interface CharToByteBuffer

append

public void append(java.lang.String str,
                   int offset,
                   int length)
            throws java.io.IOException
Description copied from interface: CharToByteBuffer
Copy the given String to the end of this buffer, starting at the offset, using the length provided.
Specified by:
append in interface CharToByteBuffer

reset

public void reset()
           throws java.io.IOException
Description copied from interface: ByteData
Reset any transient data stored in this ByteData. A call to getByteCount or writeTo will force this data to be restored.
Specified by:
reset in interface ByteData

drain

public void drain()
           throws java.io.IOException
Description copied from interface: CharToByteBuffer
Force any buffered characters to be immediately converted to bytes.
Specified by:
drain in interface CharToByteBuffer