Javolution 6.0.0 java
javolution.io.Struct.UTF8String Class Reference
Inheritance diagram for javolution.io.Struct.UTF8String:
[legend]
Collaboration diagram for javolution.io.Struct.UTF8String:
[legend]

Public Member Functions

 UTF8String (int length)
 
void set (String string)
 
String get ()
 
String toString ()
 
final Struct struct ()
 
final int offset ()
 
final int bitIndex ()
 
final int bitLength ()
 

Package Functions

final int get (int wordSize, int word)
 
final long get (int wordSize, long word)
 
final int set (int value, int wordSize, int word)
 
final long set (long value, int wordSize, long word)
 

Private Attributes

final UTF8ByteBufferWriter _writer = new UTF8ByteBufferWriter()
 
final UTF8ByteBufferReader _reader = new UTF8ByteBufferReader()
 
final int _length
 
final int _offset
 
final int _bitIndex
 
final int _bitLength
 

Detailed Description

This class represents a UTF-8 character string, null terminated (for C/C++ compatibility)

Definition at line 1062 of file Struct.java.

Constructor & Destructor Documentation

◆ UTF8String()

javolution.io.Struct.UTF8String.UTF8String ( int  length)

Definition at line 1068 of file Struct.java.

1068  {
1069  super(length << 3, 1);
1070  _length = length; // Takes into account 0 terminator.
1071  }

References javolution.io.Struct.UTF8String._length.

Member Function Documentation

◆ bitIndex()

final int javolution.io.Struct.Member.bitIndex ( )
inherited

Holds the bit offset of this member (if any). The actual position of the bits data depends upon the endianess and the word size.

Definition at line 998 of file Struct.java.

998  {
999  return _bitIndex;
1000  }

References javolution.io.Struct.Member._bitIndex.

Referenced by javolution.io.Struct.Member.get(), javolution.io.Struct.BitField.longValue(), javolution.io.Struct.Member.set(), and javolution.io.Struct.BitField.set().

Here is the caller graph for this function:

◆ bitLength()

◆ get() [1/3]

String javolution.io.Struct.UTF8String.get ( )

Definition at line 1096 of file Struct.java.

1096  {
1097  final ByteBuffer buffer = getByteBuffer();
1098  synchronized (buffer) {
1099  TextBuilder tmp = new TextBuilder();
1100  try {
1101  int index = getByteBufferPosition() + offset();
1102  buffer.position(index);
1103  _reader.setInput(buffer);
1104  for (int i = 0; i < _length; i++) {
1105  char c = (char) _reader.read();
1106  if (c == 0) { // Null terminator.
1107  return tmp.toString();
1108  } else {
1109  tmp.append(c);
1110  }
1111  }
1112  return tmp.toString();
1113  } catch (IOException e) { // Should never happen.
1114  throw new Error(e.getMessage());
1115  } finally {
1116  _reader.reset();
1117  }
1118  }
1119  }

References javolution.io.Struct.UTF8String._length, javolution.io.Struct.UTF8String._reader, javolution.text.TextBuilder.append(), javolution.io.Struct.getByteBuffer(), javolution.io.Struct.getByteBufferPosition(), javolution.io.Struct.Member.offset(), javolution.io.UTF8ByteBufferReader.read(), javolution.io.UTF8ByteBufferReader.reset(), javolution.io.UTF8ByteBufferReader.setInput(), and javolution.text.TextBuilder.toString().

Here is the call graph for this function:

◆ get() [2/3]

final int javolution.io.Struct.Member.get ( int  wordSize,
int  word 
)
packageinherited

Definition at line 1013 of file Struct.java.

1013  {
1014  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1015  - bitIndex() - bitLength()
1016  : bitIndex();
1017  word >>= shift;
1018  int mask = 0xFFFFFFFF >>> (32 - bitLength());
1019  return word & mask;
1020  }

References javolution.io.Struct.Member.bitIndex(), javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.byteOrder().

Here is the call graph for this function:

◆ get() [3/3]

final long javolution.io.Struct.Member.get ( int  wordSize,
long  word 
)
packageinherited

Definition at line 1034 of file Struct.java.

1034  {
1035  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1036  - bitIndex() - bitLength()
1037  : bitIndex();
1038  word >>= shift;
1039  long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - bitLength());
1040  return word & mask;
1041  }

References javolution.io.Struct.Member.bitIndex(), javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.byteOrder().

Here is the call graph for this function:

◆ offset()

final int javolution.io.Struct.Member.offset ( )
inherited

Returns the byte offset of this member in its struct. Equivalent to C/C++ offsetof(struct(), this)

Returns
the offset of this member in the Struct.

Definition at line 989 of file Struct.java.

989  {
990  return _offset;
991  }

References javolution.io.Struct.Member._offset.

Referenced by javolution.io.Struct.UTF8String.get(), javolution.io.Struct.Bool.get(), javolution.io.Struct.Signed8.get(), javolution.io.Struct.Unsigned8.get(), javolution.io.Struct.Signed16.get(), javolution.io.Struct.Unsigned16.get(), javolution.io.Struct.Signed32.get(), javolution.io.Struct.Unsigned32.get(), javolution.io.Struct.Signed64.get(), javolution.io.Struct.Float32.get(), javolution.io.Struct.Float64.get(), javolution.io.Struct.Enum8< T extends Enum< T >.get(), javolution.io.Struct.Enum16< T extends Enum< T >.get(), javolution.io.Struct.Enum32< T extends Enum< T >.get(), javolution.io.Struct.Enum64< T extends Enum< T >.get(), javolution.io.Struct.Reference32< S extends Struct >.isUpToDate(), javolution.io.Struct.Reference64< S extends Struct >.isUpToDate(), javolution.io.Struct.BitField.longValue(), javolution.io.Struct.UTF8String.set(), javolution.io.Struct.Bool.set(), javolution.io.Struct.Signed8.set(), javolution.io.Struct.Unsigned8.set(), javolution.io.Struct.Signed16.set(), javolution.io.Struct.Unsigned16.set(), javolution.io.Struct.Signed32.set(), javolution.io.Struct.Unsigned32.set(), javolution.io.Struct.Signed64.set(), javolution.io.Struct.BitField.set(), javolution.io.Struct.Float32.set(), javolution.io.Struct.Float64.set(), javolution.io.Struct.Reference32< S extends Struct >.set(), javolution.io.Struct.Reference64< S extends Struct >.set(), javolution.io.Struct.Enum8< T extends Enum< T >.set(), javolution.io.Struct.Enum16< T extends Enum< T >.set(), javolution.io.Struct.Enum32< T extends Enum< T >.set(), javolution.io.Struct.Enum64< T extends Enum< T >.set(), javolution.io.Struct.Reference32< S extends Struct >.value(), and javolution.io.Struct.Reference64< S extends Struct >.value().

Here is the caller graph for this function:

◆ set() [1/3]

final int javolution.io.Struct.Member.set ( int  value,
int  wordSize,
int  word 
)
packageinherited

Definition at line 1023 of file Struct.java.

1023  {
1024  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1025  - bitIndex() - bitLength()
1026  : bitIndex();
1027  int mask = 0xFFFFFFFF >>> (32 - bitLength());
1028  mask <<= shift;
1029  value <<= shift;
1030  return (word & ~mask) | (value & mask);
1031  }

References javolution.io.Struct.Member.bitIndex(), javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.byteOrder().

Here is the call graph for this function:

◆ set() [2/3]

final long javolution.io.Struct.Member.set ( long  value,
int  wordSize,
long  word 
)
packageinherited

Definition at line 1044 of file Struct.java.

1044  {
1045  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1046  - bitIndex() - bitLength()
1047  : bitIndex();
1048  long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - bitLength());
1049  mask <<= shift;
1050  value <<= shift;
1051  return (word & ~mask) | (value & mask);
1052  }

References javolution.io.Struct.Member.bitIndex(), javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.byteOrder().

Here is the call graph for this function:

◆ set() [3/3]

void javolution.io.Struct.UTF8String.set ( String  string)

Definition at line 1073 of file Struct.java.

1073  {
1074  final ByteBuffer buffer = getByteBuffer();
1075  synchronized (buffer) {
1076  try {
1077  int index = getByteBufferPosition() + offset();
1078  buffer.position(index);
1079  _writer.setOutput(buffer);
1080  if (string.length() < _length) {
1081  _writer.write(string);
1082  _writer.write(0); // Marks end of string.
1083  } else if (string.length() > _length) { // Truncates.
1084  _writer.write(string.substring(0, _length));
1085  } else { // Exact same length.
1086  _writer.write(string);
1087  }
1088  } catch (IOException e) { // Should never happen.
1089  throw new Error(e.getMessage());
1090  } finally {
1091  _writer.reset();
1092  }
1093  }
1094  }

References javolution.io.Struct.UTF8String._length, javolution.io.Struct.UTF8String._writer, javolution.io.Struct.getByteBuffer(), javolution.io.Struct.getByteBufferPosition(), javolution.io.Struct.Member.offset(), javolution.io.UTF8ByteBufferWriter.reset(), javolution.io.UTF8ByteBufferWriter.setOutput(), and javolution.io.UTF8ByteBufferWriter.write().

Here is the call graph for this function:

◆ struct()

final Struct javolution.io.Struct.Member.struct ( )
inherited

Returns the outer struct container.

Returns
the outer struct.

Definition at line 979 of file Struct.java.

979  {
980  return Struct.this;
981  }

◆ toString()

String javolution.io.Struct.UTF8String.toString ( )

Definition at line 1121 of file Struct.java.

1121  {
1122  return this.get();
1123  }

Member Data Documentation

◆ _bitIndex

final int javolution.io.Struct.Member._bitIndex
privateinherited

Holds the relative bit offset of this member to its struct offset.

Definition at line 903 of file Struct.java.

Referenced by javolution.io.Struct.Member.bitIndex(), and javolution.io.Struct.Member.Member().

◆ _bitLength

final int javolution.io.Struct.Member._bitLength
privateinherited

Holds the bit length of this member.

Definition at line 907 of file Struct.java.

Referenced by javolution.io.Struct.Member.bitLength(), and javolution.io.Struct.Member.Member().

◆ _length

final int javolution.io.Struct.UTF8String._length
private

◆ _offset

final int javolution.io.Struct.Member._offset
privateinherited

Holds the relative offset (in bytes) of this member within its struct.

Definition at line 899 of file Struct.java.

Referenced by javolution.io.Struct.Member.Member(), and javolution.io.Struct.Member.offset().

◆ _reader

final UTF8ByteBufferReader javolution.io.Struct.UTF8String._reader = new UTF8ByteBufferReader()
private

Definition at line 1065 of file Struct.java.

Referenced by javolution.io.Struct.UTF8String.get().

◆ _writer

final UTF8ByteBufferWriter javolution.io.Struct.UTF8String._writer = new UTF8ByteBufferWriter()
private

Definition at line 1064 of file Struct.java.

Referenced by javolution.io.Struct.UTF8String.set().


The documentation for this class was generated from the following file:
javolution.io.Struct.UTF8String._reader
final UTF8ByteBufferReader _reader
Definition: Struct.java:1065
javolution.io.UTF8ByteBufferWriter.reset
void reset()
Definition: UTF8ByteBufferWriter.java:212
javolution.io.UTF8ByteBufferWriter.setOutput
UTF8ByteBufferWriter setOutput(ByteBuffer byteBuffer)
Definition: UTF8ByteBufferWriter.java:57
javolution.io.UTF8ByteBufferWriter.write
void write(char c)
Definition: UTF8ByteBufferWriter.java:72
javolution.io.Struct.Member._offset
final int _offset
Definition: Struct.java:899
javolution.io.UTF8ByteBufferReader.reset
void reset()
Definition: UTF8ByteBufferReader.java:254
javolution.io.Struct.Member._bitLength
final int _bitLength
Definition: Struct.java:907
javolution.io.Struct.Struct
Struct()
Definition: Struct.java:214
javolution.io.UTF8ByteBufferReader.read
int read()
Definition: UTF8ByteBufferReader.java:102
javolution.io.UTF8ByteBufferReader.setInput
UTF8ByteBufferReader setInput(ByteBuffer byteBuffer)
Definition: UTF8ByteBufferReader.java:60
javolution.io.Struct.Member.offset
final int offset()
Definition: Struct.java:989
javolution.io.Struct.Member._bitIndex
final int _bitIndex
Definition: Struct.java:903
javolution.io.Struct.UTF8String._length
final int _length
Definition: Struct.java:1066
javolution.io.Struct.getByteBufferPosition
final int getByteBufferPosition()
Definition: Struct.java:312
javolution.io.Struct.UTF8String._writer
final UTF8ByteBufferWriter _writer
Definition: Struct.java:1064
javolution.io.Struct.byteOrder
ByteOrder byteOrder()
Definition: Struct.java:480
javolution.io.Struct.Member.bitIndex
final int bitIndex()
Definition: Struct.java:998
javolution.io.Struct.Member.bitLength
final int bitLength()
Definition: Struct.java:1008
javolution.io.Struct.getByteBuffer
final ByteBuffer getByteBuffer()
Definition: Struct.java:254