com.jniwrapper
Class ZeroTerminatedString

java.lang.Object
  extended by com.jniwrapper.Parameter
      extended by com.jniwrapper.ZeroTerminatedString
All Implemented Interfaces:
AlignmentAwareParameter, StringParameter
Direct Known Subclasses:
AnsiString, UnicodeString, WideString

public abstract class ZeroTerminatedString
extends Parameter
implements StringParameter, AlignmentAwareParameter

Base class for all types of zero-terminated strings.

NOTE: All string lengths include the terminating zero character unless otherwise noted.


Field Summary
 
Fields inherited from class com.jniwrapper.Parameter
LICENSE_TYPE, V
 
Constructor Summary
protected ZeroTerminatedString(byte[] bytes, int lenBytes, int charLength)
          Constructs a string with specified value, maximum length and characted type (1-byte or 2-byte).
 
Method Summary
protected  Parameter asReturnValue()
          Returns a parameter that represents this one as a return value.
protected abstract  java.lang.String bytesToString(byte[] bytes)
           
 boolean equals(java.lang.Object obj)
          Compares this Parameter object to a given object.
protected  int getAlignedLength()
          Returns a parameter length in bytes aligned to default alignment.
 java.lang.String getDebugInfo()
          Return debug info for JNIWrapper parameter.
 int getFirstMemberSize()
          Should return first member size.
 int getLength()
          Returns the length of this string object.
 int getMaxLength()
          Returns the maximum length of a string.
protected abstract  int getStrLen(DataBuffer dataBuffer, int startOffset)
           
 java.lang.String getValue()
           
 int hashCode()
           
 void read(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Reads this parameter from a specified data source.
 void setValue(java.lang.String value)
          Sets the value for the parameter.
protected abstract  byte[] stringToBytes(java.lang.String value)
           
 java.lang.String toString()
           
 void write(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Writes this parameter to a specified data source.
 
Methods inherited from class com.jniwrapper.Parameter
acceptIOPerformer, clone, dataBufferAssigned, getAlignmentRequirement, getDataBuffer, getDataBufferOffset, indent, pop, push, read, read, setDataBuffer, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZeroTerminatedString

protected ZeroTerminatedString(byte[] bytes,
                               int lenBytes,
                               int charLength)
Constructs a string with specified value, maximum length and characted type (1-byte or 2-byte).

Parameters:
bytes - a string as bytes
lenBytes - the maximum string length in bytes
charLength - the character lengtin in bytes
Since:
1.2
Method Detail

getMaxLength

public int getMaxLength()
Returns the maximum length of a string. In certain (mostly Asian) encodings, some characters are represented by more than one byte even if the charLength is 1. In these cases ANSI string may not be able to hold getMaxLength() characters. Creating a new AnsiString object with the string as a parameter or using WideString eliminates this problem.


setValue

public final void setValue(java.lang.String value)
Description copied from interface: StringParameter
Sets the value for the parameter.

Specified by:
setValue in interface StringParameter
Parameters:
value - the value to set.

getValue

public final java.lang.String getValue()
Specified by:
getValue in interface StringParameter
Returns:
the string value of the parameter.

getStrLen

protected abstract int getStrLen(DataBuffer dataBuffer,
                                 int startOffset)

getLength

public int getLength()
Returns the length of this string object. This value is not necessarily equal to the allowed maximum length of the string. To get the latter, use getMaxLength() method.

Specified by:
getLength in class Parameter

getAlignedLength

protected int getAlignedLength()
Description copied from class: Parameter
Returns a parameter length in bytes aligned to default alignment.

Overrides:
getAlignedLength in class Parameter

asReturnValue

protected Parameter asReturnValue()
Description copied from class: Parameter
Returns a parameter that represents this one as a return value. Implementors may use this as a convenience shortcut for users when implementing such objects as strings or arrays to allow users to specify an object as a return value instead of requiring a pointer to it. For general use the default implementation should suffice.

Overrides:
asReturnValue in class Parameter
Returns:
this

write

public void write(DataBuffer stackBuffer,
                  int offset,
                  boolean invokedByCallback)
           throws MemoryAccessViolationException
Description copied from class: Parameter
Writes this parameter to a specified data source.

Specified by:
write in class Parameter
Throws:
MemoryAccessViolationException

read

public void read(DataBuffer stackBuffer,
                 int offset,
                 boolean invokedByCallback)
          throws MemoryAccessViolationException
Description copied from class: Parameter
Reads this parameter from a specified data source.

Specified by:
read in class Parameter
Throws:
MemoryAccessViolationException

getDebugInfo

public java.lang.String getDebugInfo()
Description copied from class: Parameter
Return debug info for JNIWrapper parameter.

Specified by:
getDebugInfo in class Parameter
Returns:
debug info

equals

public boolean equals(java.lang.Object obj)
Description copied from class: Parameter
Compares this Parameter object to a given object. Two Parameter objects are considered equal if their byte representations are equal and they are of the same type. Subclasses may override this method as appropriate.

Overrides:
equals in class Parameter
Parameters:
obj - a value to compare this object to.
Returns:
true if two objects are equal.

hashCode

public int hashCode()
Overrides:
hashCode in class Parameter

stringToBytes

protected abstract byte[] stringToBytes(java.lang.String value)

bytesToString

protected abstract java.lang.String bytesToString(byte[] bytes)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getFirstMemberSize

public int getFirstMemberSize()
Description copied from interface: AlignmentAwareParameter
Should return first member size. If first member is structure, should return it's first parameter (in recursive manner). Unions should return their full size.

Specified by:
getFirstMemberSize in interface AlignmentAwareParameter
Returns:
first structure member size