com.jniwrapper
Class AnsiString

java.lang.Object
  extended by com.jniwrapper.Parameter
      extended by com.jniwrapper.ZeroTerminatedString
          extended by com.jniwrapper.AnsiString
All Implemented Interfaces:
AlignmentAwareParameter, StringParameter

public class AnsiString
extends ZeroTerminatedString

Represents a zero-terminated string of an 8-bit (ANSI) character declared in C as char[n], where n is the length of the buffer.

NOTE: Please keep in mind that this class is the memory buffer of specified lenght, but not the pointer. Thereofore when you need to pass this object to a native function call, for example: void foo(char* aString), you can wrap this object to a Pointer or pass this object as is. In second case JNIWrapper will atomatically wrap this string into Pointer for you. For example:

      AnsiString aString = new AnsiString("String value");
      function.invoke(null, aString);
      //or
      function.invoke(null, new Pointer(aString));

 
In case when you need to wrap a structure that contains char[n] member, for example:
  struct a {
      char name[10];
  }
 
You can use the following wrapper:
  public class A extends Structure {
      AnsiString name = new AnsiString(10); // corresponds to char name[10]
      public A() {
          init(new Parameter[] {name});
      }
  }
 
In case if a structure contains a char* member, for example:
  struct a {
      char name*;
  }
 
Then you can use the following wrapper for it:
  public class A extends Structure {
      Pointer name = new Pointer(AnsiString.class); // corresponds to char name*
      public A() {
          init(new Parameter[] {name});
      }
  }
 

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

This class should be used directly only if 8-bit characters are required. Use Str class for working with string values to make your code compatible with both Unicode and non-Unicode platforms.

See Also:
Str, WideString

Field Summary
 
Fields inherited from class com.jniwrapper.Parameter
LICENSE_TYPE, V
 
Constructor Summary
AnsiString()
          Constructs a string with the maximum length of 256 characters.
AnsiString(AnsiString t)
          Constructs a copy of a specified AnsiString object.
AnsiString(byte[] bytes)
          Creates the string from the specifies byte array.
AnsiString(byte[] bytes, int length)
          Creates the string from the specifies byte array.
AnsiString(int maxLen)
          Constructs a string with a specified maximum length.
AnsiString(java.lang.String s)
          Constructs a string with a specified value.
AnsiString(java.lang.String s, int maxLen)
          Constructs a string with a specified value and maximum length.
 
Method Summary
protected  java.lang.String bytesToString(byte[] bytes)
           
 java.lang.Object clone()
           
 int getAlignmentRequirement()
           
 int getFirstMemberSize()
          Should return first member size.
protected  int getStrLen(DataBuffer dataBuffer, int startOffset)
           
protected  byte[] stringToBytes(java.lang.String value)
           
 
Methods inherited from class com.jniwrapper.ZeroTerminatedString
asReturnValue, equals, getAlignedLength, getDebugInfo, getLength, getMaxLength, getValue, hashCode, read, setValue, toString, write
 
Methods inherited from class com.jniwrapper.Parameter
acceptIOPerformer, dataBufferAssigned, 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

AnsiString

public AnsiString()
Constructs a string with the maximum length of 256 characters.


AnsiString

public AnsiString(int maxLen)
Constructs a string with a specified maximum length.


AnsiString

public AnsiString(java.lang.String s)
Constructs a string with a specified value. The maximum length of the string equals the length of the specified value (including terminating zero).


AnsiString

public AnsiString(java.lang.String s,
                  int maxLen)
Constructs a string with a specified value and maximum length.


AnsiString

public AnsiString(byte[] bytes)
Creates the string from the specifies byte array.

Parameters:
bytes - a byte array to create the structure from

AnsiString

public AnsiString(byte[] bytes,
                  int length)
Creates the string from the specifies byte array.

Parameters:
bytes - a byte array to create the structure from
length - specifies the length of the string

AnsiString

public AnsiString(AnsiString t)
Constructs a copy of a specified AnsiString object.

Method Detail

bytesToString

protected java.lang.String bytesToString(byte[] bytes)
Specified by:
bytesToString in class ZeroTerminatedString

stringToBytes

protected byte[] stringToBytes(java.lang.String value)
Specified by:
stringToBytes in class ZeroTerminatedString

clone

public java.lang.Object clone()
Specified by:
clone in class Parameter

getStrLen

protected int getStrLen(DataBuffer dataBuffer,
                        int startOffset)
Specified by:
getStrLen in class ZeroTerminatedString

getAlignmentRequirement

public int getAlignmentRequirement()
Overrides:
getAlignmentRequirement in class Parameter
Returns:
required alignment within a structure or an array

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
Overrides:
getFirstMemberSize in class ZeroTerminatedString
Returns:
first structure member size