MultipleTextEncodedStringNullTerminatedpublic class MultipleTextEncodedStringNullTerminated extends AbstractDataType Represents a data type that supports multiple terminated Strings (there may only be one) |
Methods Summary |
---|
public boolean | canBeEncoded()Check the value can be encoded with the specified encoding
for (ListIterator<String> li = ((Values) value).getList().listIterator(); li.hasNext();)
{
TextEncodedStringNullTerminated next = new TextEncodedStringNullTerminated(identifier, frameBody, li.next());
if (!next.canBeEncoded())
{
return false;
}
}
return true;
| public boolean | equals(java.lang.Object obj)
return obj instanceof MultipleTextEncodedStringNullTerminated && super.equals(obj);
| public int | getSize()Returns the size in bytes of this datatype when written to file
return size;
| public void | readByteArray(byte[] arr, int offset)Read Null Terminated Strings from the array starting at offset, continue until unable to find any null terminated
Strings or until reached the end of the array. The offset should be set to byte after the last null terminated
String found.
logger.finer("Reading MultipleTextEncodedStringNullTerminated from array from offset:" + offset);
//Continue until unable to read a null terminated String
while (true)
{
try
{
//Read String
TextEncodedStringNullTerminated next = new TextEncodedStringNullTerminated(identifier, frameBody);
next.readByteArray(arr, offset);
if (next.getSize() == 0)
{
break;
}
else
{
//Add to value
((Values) value).add((String) next.getValue());
//Add to size calculation
size += next.getSize();
//Increment Offset to start of next datatype.
offset += next.getSize();
}
}
catch (InvalidDataTypeException idte)
{
break;
}
if (size == 0)
{
logger.warning("No null terminated Strings found");
throw new InvalidDataTypeException("No null terminated Strings found");
}
}
logger.finer("Read MultipleTextEncodedStringNullTerminated:" + value + " size:" + size);
| public byte[] | writeByteArray()For every String write to bytebuffer
logger.finer("Writing MultipleTextEncodedStringNullTerminated");
int localSize = 0;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try
{
for (ListIterator<String> li = ((Values) value).getList().listIterator(); li.hasNext();)
{
TextEncodedStringNullTerminated next = new TextEncodedStringNullTerminated(identifier, frameBody, li.next());
buffer.write(next.writeByteArray());
localSize += next.getSize();
}
}
catch (IOException ioe)
{
//This should never happen because the write is internal with the JVM it is not to a file
logger.log(Level.SEVERE, "IOException in MultipleTextEncodedStringNullTerminated when writing byte array", ioe);
throw new RuntimeException(ioe);
}
//Update size member variable
size = localSize;
logger.finer("Written MultipleTextEncodedStringNullTerminated");
return buffer.toByteArray();
|
|