Top Description Fields Constructors Methods
com.ibm.icu.text

public final Class UnicodeDecompressor

extends Object
implements SCSU
Class Inheritance
All Implemented Interfaces
com.ibm.icu.text.SCSU

A decompression engine implementing the Standard Compression Scheme for Unicode (SCSU) as outlined in Unicode Technical Report #6.

USAGE

The static methods on UnicodeDecompressor may be used in a straightforward manner to decompress simple strings:

 byte [] compressed = ... ; // get compressed bytes from somewhere
 String result = UnicodeDecompressor.decompress(compressed);

The static methods have a fairly large memory footprint. For finer-grained control over memory usage, UnicodeDecompressor offers more powerful APIs allowing iterative decompression:

 // Decompress an array "bytes" of length "len" using a buffer of 512 chars
 // to the Writer "out"

 UnicodeDecompressor myDecompressor         = new UnicodeDecompressor();
 final static int    BUFSIZE                = 512;
 char []             charBuffer             = new char [ BUFSIZE ];
 int                 charsWritten           = 0;
 int []              bytesRead              = new int [1];
 int                 totalBytesDecompressed = 0;
 int                 totalCharsWritten      = 0;

 do {
   // do the decompression
   charsWritten = myDecompressor.decompress(bytes, totalBytesDecompressed, 
                                            len, bytesRead,
                                            charBuffer, 0, BUFSIZE);

   // do something with the current set of chars
   out.write(charBuffer, 0, charsWritten);

   // update the no. of bytes decompressed
   totalBytesDecompressed += bytesRead[0];

   // update the no. of chars written
   totalCharsWritten += charsWritten;

 } while(totalBytesDecompressed < len);

 myDecompressor.reset(); // reuse decompressor

Decompression is performed according to the standard set forth in Unicode Technical Report #6

Author
Stephen F. Booth
ICU Status
Stable since ICU 2.4.
See Also
UnicodeCompressor

Field Summary

Modifier and TypeField and Description
private static final int
BUFSIZE

Size of our internal buffer

private byte[]
fBuffer

Internal buffer for saving state

private int
fBufferLength

Number of characters in our internal buffer

private int
fCurrentWindow

Alias to current dynamic window

private int
fMode

Current compression mode

private int[]
fOffsets

Dynamic compression window offsets

Constructor Summary

AccessConstructor and Description
public
UnicodeDecompressor()

Create a UnicodeDecompressor.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

A String containing the decompressed characters.
decompress
(byte[]
The byte array to decompress.
buffer
)

Decompress a byte array into a String.

public static char[]

Returns:

A character array containing the decompressed bytes.
decompress
(byte[]
The byte array to decompress.
buffer
,
int
The start of the byte run to decompress.
start
,
int
The limit of the byte run to decompress.
limit
)

Decompress a byte array into a Unicode character array.

public int

Returns:

The number of Unicode characters written to charBuffer.
decompress
(byte[]
The byte buffer to decompress.
byteBuffer
,
int
The start of the byte run to decompress.
byteBufferStart
,
int
The limit of the byte run to decompress.
byteBufferLimit
,
int[]
A one-element array. If not null, on return the number of bytes read from byteBuffer.
bytesRead
,
char[]
A buffer to receive the decompressed data. This buffer must be at minimum two characters in size.
charBuffer
,
int
The starting offset to which to write decompressed data.
charBufferStart
,
int
The limiting offset for writing decompressed data.
charBufferLimit
)

Decompress a byte array into a Unicode character array.

public void
reset()

Reset the decompressor to its initial state.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFSIZEback to summary
private static final int BUFSIZE

Size of our internal buffer

fBufferback to summary
private byte[] fBuffer

Internal buffer for saving state

fBufferLengthback to summary
private int fBufferLength

Number of characters in our internal buffer

fCurrentWindowback to summary
private int fCurrentWindow

Alias to current dynamic window

fModeback to summary
private int fMode

Current compression mode

fOffsetsback to summary
private int[] fOffsets

Dynamic compression window offsets

Constructor Detail

UnicodeDecompressorback to summary
public UnicodeDecompressor()

Create a UnicodeDecompressor. Sets all windows to their default values.

ICU Status
Stable since ICU 2.4.
See Also
reset

Method Detail

decompressback to summary
public static String decompress(byte[] buffer)

Decompress a byte array into a String.

Parameters
buffer:byte[]

The byte array to decompress.

Returns:String

A String containing the decompressed characters.

ICU Status
Stable since ICU 2.4.
See Also
decompress(byte [], int, int)
decompressback to summary
public static char[] decompress(byte[] buffer, int start, int limit)

Decompress a byte array into a Unicode character array.

Parameters
buffer:byte[]

The byte array to decompress.

start:int

The start of the byte run to decompress.

limit:int

The limit of the byte run to decompress.

Returns:char[]

A character array containing the decompressed bytes.

ICU Status
Stable since ICU 2.4.
See Also
decompress(byte [])
decompressback to summary
public int decompress(byte[] byteBuffer, int byteBufferStart, int byteBufferLimit, int[] bytesRead, char[] charBuffer, int charBufferStart, int charBufferLimit)

Decompress a byte array into a Unicode character array. This function will either completely fill the output buffer, or consume the entire input.

Parameters
byteBuffer:byte[]

The byte buffer to decompress.

byteBufferStart:int

The start of the byte run to decompress.

byteBufferLimit:int

The limit of the byte run to decompress.

bytesRead:int[]

A one-element array. If not null, on return the number of bytes read from byteBuffer.

charBuffer:char[]

A buffer to receive the decompressed data. This buffer must be at minimum two characters in size.

charBufferStart:int

The starting offset to which to write decompressed data.

charBufferLimit:int

The limiting offset for writing decompressed data.

Returns:int

The number of Unicode characters written to charBuffer.

ICU Status
Stable since ICU 2.4.
resetback to summary
public void reset()

Reset the decompressor to its initial state.

ICU Status
Stable since ICU 2.4.