org.hd.d.pg2k.svrCore
Class WrappedByteArrayCharSequence

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.WrappedByteArrayCharSequence
All Implemented Interfaces:
java.lang.CharSequence, TextUtils.CharSequence8Bit

public final class WrappedByteArrayCharSequence
extends java.lang.Object
implements TextUtils.CharSequence8Bit

Lightweight CharSequence that wraps a portion of an underlying byte array. The underlying bytes cannot be altered via this interface, but changes to the underlying bytes may be visible through this wrapper (subject to the JMM, if different threads are involved), ie this is mutable and thus not thread-safe without external synchronisation.


Field Summary
private  int length
          Length of exposed fragment, non-negative.
private  int offset
          Offset into underlying buffer, non-negative.
private  byte[] text
          Underlying 8-bit text; never null.
 
Constructor Summary
WrappedByteArrayCharSequence(byte[] text, int offset, int length)
          Expose portion of byte array from offset of specified length.
 
Method Summary
 byte byteAt(int index)
          Returns byte value at given index.
 char charAt(int index)
           
 int length()
           
 java.lang.CharSequence subSequence(int start, int end)
           
 byte[] toByteArray()
          Return private copy (8-bit) text with each byte corresponding to one char; never null.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

text

private final byte[] text
Underlying 8-bit text; never null.


length

private final int length
Length of exposed fragment, non-negative.


offset

private final int offset
Offset into underlying buffer, non-negative.

Constructor Detail

WrappedByteArrayCharSequence

public WrappedByteArrayCharSequence(byte[] text,
                                    int offset,
                                    int length)
Expose portion of byte array from offset of specified length.

Method Detail

length

public int length()
Specified by:
length in interface java.lang.CharSequence

byteAt

public byte byteAt(int index)
Description copied from interface: TextUtils.CharSequence8Bit
Returns byte value at given index. Like charAt(), but avoids explicit conversion to char.

Specified by:
byteAt in interface TextUtils.CharSequence8Bit

charAt

public char charAt(int index)
Specified by:
charAt in interface java.lang.CharSequence

subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
Specified by:
subSequence in interface java.lang.CharSequence

toString

public java.lang.String toString()
Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object

toByteArray

public byte[] toByteArray()
Return private copy (8-bit) text with each byte corresponding to one char; never null. May be far more efficient than converting via a String if the aim is to write directly to a file for example.

Specified by:
toByteArray in interface TextUtils.CharSequence8Bit

DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.