org.openadaptor.adaptor.bridge
Class Utf8Converter
java.lang.Object
org.openadaptor.adaptor.bridge.Utf8Converter
public final class Utf8Converter
- extends java.lang.Object
This class contains static methods for decoding arrays of characters into
arrays of utf-8 bytes, and vice versa. The API is aimed at java.io.*
classes which read and write byte arrays, and are using a byte (or char)
buffer to do buffering and encoding/decoding at the same time.
- Author:
- tim
Method Summary |
static int |
bytesToChars(byte[] from,
int[] offlen,
char[] to,
int cnext)
|
static int |
bytesToChars(byte[] from,
int[] bofflen,
char[] to,
int[] cofflen)
|
static int |
charsToBytes(char[] from,
int[] posnum,
byte[] to,
int offset)
Note:Tuned for speed; if you pass any dodgy parameters,
runtime exceptions will be thrown, and the from/to arrays will
be left in an indeterminate state. |
static void |
main(java.lang.String[] args)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Utf8Converter
public Utf8Converter()
charsToBytes
public static int charsToBytes(char[] from,
int[] posnum,
byte[] to,
int offset)
- Note:Tuned for speed; if you pass any dodgy parameters,
runtime exceptions will be thrown, and the from/to arrays will
be left in an indeterminate state.
- Parameters:
from
- array of characters for conversionposnum
- posnum[0] contains index of first character for
conversion, posnum[1] contains the number of characters to be converted.
When the method returns, posnum[0] will contain the index of the next
unconverted character (or -1 if all have been converted) and posnum[1]
will contain the number of characters left unconverted.to
- byte array to hold converted UTF-8 format bytes.offset
- index of slot to contain first converted byte.
- Returns:
- index of next empty slot in the byte array.
bytesToChars
public static int bytesToChars(byte[] from,
int[] offlen,
char[] to,
int cnext)
throws java.io.IOException
- Parameters:
from
- Byte array from which to read UTF-8 bytesofflen
- Array of two ints containing the offset and length of the
byte array slice to decode. Values in the array are updated.to
- Char array into which decoded characters are written.cnext
-
- Throws:
java.io.IOException
bytesToChars
public static int bytesToChars(byte[] from,
int[] bofflen,
char[] to,
int[] cofflen)
throws java.io.IOException
- Parameters:
from
- Byte array from which to read UTF-8 bytesbofflen
- Array of two ints containing the offset and length of the
byte array slice to decode. Values in the array are updated.to
- Char array into which decoded characters are written.cofflen
-
- Throws:
java.io.IOException
main
public static void main(java.lang.String[] args)