com.jniwrapper
Class ZeroTerminatedString

java.lang.Object
  |
  +--com.jniwrapper.Parameter
        |
        +--com.jniwrapper.ZeroTerminatedString
All Implemented Interfaces:
StringParameter
Direct Known Subclasses:
AnsiString, WideString

public abstract class ZeroTerminatedString
extends Parameter
implements StringParameter

Base class for all types of zero-terminated strings.

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


Constructor Summary
protected ZeroTerminatedString(byte[] bytes, int lenBytes, int charLength)
          Constructs string with specified value, maximum length and characted type (1-byte or 2-byte)
protected ZeroTerminatedString(java.lang.String s, int len, int charLength)
          Deprecated. strings created using this constructor may allocate not enough memory to hold len characters in certain encodings.
 
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 parameter length in bytes aligned to default alignment.
protected  int getCharLength()
          Returns character length in bytes
 int getLength()
          Returns length of this string object.
 int getMaxLength()
          Returns maximum length of a string.
protected abstract  int getStrLen(DataBuffer dataBuffer, int startOffset)
           
 java.lang.String getValue()
           
 void pop(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Default implementation, which does nothing as most primitive types do nothing on pop.
 void push(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Writes a parameter to a function stacks
 void read(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Reads this parameter from a specified data source.
 void setValue(java.lang.String value)
           
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, getAlignmentRequirement, getDataBuffer, getDataBufferOffset, indent, read, setDataBuffer, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZeroTerminatedString

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

Parameters:
bytes - string as bytes
lenBytes - maximum string length in bytes
charLength - character lengtin in bytes
Since:
1.2

ZeroTerminatedString

protected ZeroTerminatedString(java.lang.String s,
                               int len,
                               int charLength)
Deprecated. strings created using this constructor may allocate not enough memory to hold len characters in certain encodings.

Constructs string with specified value, maximum length and characted type (1-byte or 2-byte)

Method Detail

getMaxLength

public int getMaxLength()
Returns maximum length of a string. In certain (mostly Asian) encodings some characters are represented by more that 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 avoids this problem.


setValue

public final void setValue(java.lang.String value)
Specified by:
setValue in interface StringParameter

getValue

public final java.lang.String getValue()
Specified by:
getValue in interface StringParameter

getCharLength

protected int getCharLength()
Returns character length in bytes


getStrLen

protected abstract int getStrLen(DataBuffer dataBuffer,
                                 int startOffset)

getLength

public int getLength()
Returns 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 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

push

public void push(DataBuffer stackBuffer,
                 int offset,
                 boolean invokedByCallback)
Description copied from class: Parameter
Writes a parameter to a function stacks

Overrides:
push in class Parameter

pop

public void pop(DataBuffer stackBuffer,
                int offset,
                boolean invokedByCallback)
         throws MemoryAccessViolationException
Description copied from class: Parameter
Default implementation, which does nothing as most primitive types do nothing on pop. Reads a parameter from a function stack.

Overrides:
pop in class Parameter
MemoryAccessViolationException

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
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
MemoryAccessViolationException

toString

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

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 - value to compare this object to
Returns:
true if two objects are equal.

stringToBytes

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

bytesToString

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