com.dalsemi.io
Class CharToByteUTF8
java.lang.Object
|
+--com.dalsemi.io.CharToByteConverter
|
+--com.dalsemi.io.CharToByteUTF8
- public class CharToByteUTF8
- extends CharToByteConverter
12-8-00 KLA - added useModifiedUTF8 to do the wierd Java-UTF8, where the value 0
is encoded as 2 bytes, rather than 1. this allows java.io.RandomAccessFile
and java.io.DataOutputStream to use this class.
Method Summary |
int |
convert(char[] src,
int srcStart,
int srcEnd,
byte[] dst,
int dstStart,
int dstEnd)
Converts the specified char array into a byte array based on
this CharToByteConverter 's encoding scheme. |
int |
flush(byte[] buff,
int start,
int length)
Tells the CharToByteConverter to convert
any unconverted data it has internally stored. |
int |
getMaxByteCount(char[] forThis,
int start,
int end)
Returns the number of bytes that the specified character
sequence will require for encoding. |
String |
getName()
Returns the name of this encoding scheme. |
void |
useModifiedUTF8(boolean useMod)
|
static int |
write(String str,
DataOutput writer)
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
CharToByteUTF8
public CharToByteUTF8()
getMaxByteCount
public int getMaxByteCount(char[] forThis,
int start,
int end)
- Description copied from class: CharToByteConverter
- Returns the number of bytes that the specified character
sequence will require for encoding. For instance, in UTF8
encoding, a character can be encoded as one, two, or three
bytes. This method should always be called before the
convert()
method. The value returned may not be the actual
number of converted bytes that will be produced due to
conversion errors, but it will be the maximum that will be
produced.
- Overrides:
- getMaxByteCount in class CharToByteConverter
- Tags copied from class: CharToByteConverter
- Parameters:
forThis
- contains the character sequence that will be encoded
to determine the number of bytes requiredstart
- offset into the character array to begin processingend
- ending offset in the character array to end processing.
The number of processed characters will then be (end-start)
.- Returns:
- The number of bytes required to encode the specified character sequence.
- See Also:
CharToByteConverter.convert(char[],int,int,byte[],int,int)
convert
public int convert(char[] src,
int srcStart,
int srcEnd,
byte[] dst,
int dstStart,
int dstEnd)
throws CharConversionException
- Description copied from class: CharToByteConverter
- Converts the specified
char
array into a byte
array based on
this CharToByteConverter
's encoding scheme. getMaxByteCount()
should
always be called first to find out how much room is required in the
destination byte array.
- Overrides:
- convert in class CharToByteConverter
- Tags copied from class: CharToByteConverter
- Parameters:
src
- the same character array passed to getMaxByteCount()
srcStart
- the same starting offset as passed to getMaxByteCount()
srcEnd
- the same ending offset as passed to getMaxByteCount()
dst
- the destination byte
arraydstStart
- offset to begin storing converted characters in the
destination arraydstEnd
- the ending location for storing converted characters into the
destination array. This argument may usually be ignored, as
the algorithm may choose to continue converting characters until
finished.- Returns:
- number of bytes created and stored from this character sequence
- Throws:
- CharConversionException - If an illegal character is encountered that cannot be converted
- See Also:
CharToByteConverter.getMaxByteCount(char[],int,int)
,
CharToByteConverter.flush(byte[],int,int)
flush
public int flush(byte[] buff,
int start,
int length)
- Description copied from class: CharToByteConverter
- Tells the
CharToByteConverter
to convert
any unconverted data it has internally stored.
Some CharToByteConverter
's will store state between
calls to convert()
. Since the converter may be left in
an unknown state, the converter should be flushed to
notify it that no more input will be received. The converter
can handle any unfinished conversions before its output is
used.
- Overrides:
- flush in class CharToByteConverter
- Tags copied from class: CharToByteConverter
- Parameters:
buff
- the destination byte arraystart
- the next available offset into the destination arrayend
- offset in the destination array to stop placing data
(may be ignored by some algorithms)- Returns:
- number of bytes that were stored in the destination array
from this call to flush().
- Throws:
- CharConversionException - if an illegal character is encountered that cannot be converted.
- See Also:
CharToByteConverter.convert(char[],int,int,byte[],int,int)
getName
public String getName()
- Description copied from class: CharToByteConverter
- Returns the name of this encoding scheme. For example, "UTF8".
- Overrides:
- getName in class CharToByteConverter
- Tags copied from class: CharToByteConverter
- Returns:
- the name of this encoding scheme
useModifiedUTF8
public void useModifiedUTF8(boolean useMod)
write
public static int write(String str,
DataOutput writer)
throws IOException