|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.moesol.bindings.NativeStructure
public class NativeStructure
Wraps the bytes of a native structure with a java class that allows easier access to the java compatible values of structure fields at given offsets. A union is treated in the same way as a structure, but the offsets to the fields may be the same. For example, the may all be at zero. Nested structures are supported by creating slices. Since the slices refer to the same underlying bytes when a nested structure is changed through the java wrapper so is the outer structure. However, primitive arrays are copied.
Constructor Summary | |
---|---|
protected |
NativeStructure(byte[] bytes)
|
protected |
NativeStructure(ByteBuffer bb)
|
Method Summary | |
---|---|
ByteBuffer |
_getByteBuffer()
JUnit support |
byte[] |
_getStructureBytes()
JNI support |
void |
clearRecord()
NativeStructures that contain fields of type BSTR, VARIANT, SAFEARRAY, or COM Interface must call clearRecord or native resources will be leaked. |
int |
compareTo(Object other)
Compares this native structure to another. |
boolean |
equals(Object other)
Tells whether or not this structure is equal to another structure. |
protected void |
freeLpwstr(int offset)
|
protected byte[] |
getArray(int offset,
int buflen)
Gets a copy of the array. |
protected boolean |
getBool(int offset)
|
protected boolean[] |
getBOOLArray(int offset)
|
protected String |
getBstr(int offset)
|
protected String[] |
getBSTRArray(int offset)
|
protected String[] |
getBstrArray(int offset,
int count)
|
protected byte |
getByte(int offset)
|
protected short[] |
getBYTEArray(int offset)
|
protected byte[] |
getByteArray(int offset,
int buflen)
Gets a copy of the array. |
ByteBuffer |
getByteBuffer()
Gets the byte buffer used as this structures underlying storage. |
static int |
getByteSize()
|
protected String |
getByteString(int offset,
int buflen)
|
protected Date |
getDate(int offset)
|
protected double |
getDouble(int offset)
|
protected double[] |
getDOUBLEArray(int offset)
|
protected double[] |
getDoubleArray(int offset,
int count)
|
static int |
getDoubleSize()
|
protected float |
getFloat(int offset)
|
protected float[] |
getFLOATArray(int offset)
|
protected float[] |
getFloatArray(int offset,
int count)
|
static int |
getFloatSize()
|
protected int |
getInt(int offset)
|
protected int[] |
getINTArray(int offset)
|
protected int[] |
getIntArray(int offset,
int count)
|
protected void |
getInterface(int offset,
Object[] out)
|
static int |
getIntSize()
|
protected long |
getLong(int offset)
|
protected int[] |
getLONGArray(int offset)
|
static int |
getLongSize()
Number of bytes in a C/C++ 32 bit long. |
protected String |
getLpwstr(int offset)
|
protected int[] |
getPtrInt(int offset,
int numIndirect)
|
protected short[] |
getPtrShort(int offset,
int numPointers)
|
protected String |
getPtrShortString(int offset,
int numPointers)
|
protected ByteBuffer |
getPtrStruct(int offset,
int size,
int numIndirect)
|
protected short[] |
getPtrUnsignedByte(int offset,
int numIndirect)
|
protected char[] |
getPtrUnsignedShort(int offset,
int numIndirect)
|
protected Object[] |
getPtrVariant(int offset,
int numIndirect)
|
protected ByteBuffer |
getPtrvoid(int offset,
int numIndirect)
|
protected ByteBuffer |
getRemaining(int offset)
Gets a slice of the byte buffer that is all bytes after offset. |
protected int |
getSCODE(int offset)
|
protected short |
getShort(int offset)
|
protected short[] |
getSHORTArray(int offset)
|
protected short[] |
getShortArray(int offset,
int count)
|
static int |
getShortSize()
|
protected ByteBuffer |
getSlice(int offset,
int length)
Gets a slice of the array. |
protected ByteBuffer |
getSlice(int offset,
long length)
Pass along a ULONG to getSlice as an int |
protected String |
getString(int offset,
int buflen)
Superceded by getByteString |
protected void |
getStruct(int offset,
int length,
NativeStructure s)
Copy the sub-structure into s |
protected void |
getStruct(int offset,
int length,
NativeStructure[] v)
|
protected void |
getStructArray(int offset,
int size,
int count,
NativeStructure[] v)
Copy the array sub-structures into v. |
protected long[] |
getUINTArray(int offset)
|
protected short |
getUnsignedByte(int offset)
|
protected short[] |
getUnsignedByteArray(int offset,
int count)
Gets a copy of the array. |
static int |
getUnsignedByteSize()
|
protected long |
getUnsignedInt(int offset)
|
protected long[] |
getUnsignedIntArray(int offset,
int count)
Gets a copy of the array. |
static int |
getUnsignedIntSize()
|
protected BigInteger |
getUnsignedLongLong(int offset)
|
static int |
getUnsignedLongSize()
|
protected char |
getUnsignedShort(int offset)
|
protected char[] |
getUnsignedShortArray(int offset,
int count)
Gets a copy of the array. |
static int |
getUnsignedShortSize()
|
protected char[] |
getUSHORTArray(int offset)
|
protected Object |
getVariant(int offset)
|
protected Object[] |
getVARIANTArray(int offset)
|
int |
hashCode()
Computes the hash of the bytes of this native structure. |
ByteOrder |
order()
Get the byte order for this structure. |
void |
order(ByteOrder bo)
Allow the native order to be overriden for byte swapped files. |
protected void |
putArray(int offset,
int buflen,
byte[] v)
Copies v into this structure. |
protected void |
putBool(int offset,
boolean v)
|
protected void |
putBOOLArray(int offset,
boolean[] bytes)
|
protected void |
putBstr(int offset,
String v)
|
protected void |
putBstrArray(int offset,
int count,
String[] v)
|
protected void |
putBSTRArray(int offset,
String[] bytes)
|
protected void |
putByte(int offset,
byte v)
|
protected void |
putByteArray(int offset,
int buflen,
byte[] v)
|
protected void |
putBYTEArray(int offset,
short[] bytes)
|
protected void |
putByteString(int offset,
int buflen,
String v)
|
protected void |
putDate(int offset,
Date v)
|
protected void |
putDouble(int offset,
double v)
|
protected void |
putDOUBLEArray(int offset,
double[] bytes)
|
protected void |
putDoubleArray(int offset,
int count,
double[] v)
|
protected void |
putFloat(int offset,
float v)
|
protected void |
putFLOATArray(int offset,
float[] bytes)
|
protected void |
putFloatArray(int offset,
int count,
float[] v)
|
protected void |
putInt(int offset,
int v)
|
protected void |
putINTArray(int offset,
int[] bytes)
|
protected void |
putIntArray(int offset,
int count,
int[] v)
|
protected void |
putInterface(int offset,
IUnknown unk)
|
protected void |
putLong(int offset,
long v)
|
protected void |
putLONGArray(int offset,
int[] bytes)
|
protected void |
putLpwstr(int offset,
String v)
|
protected void |
putPtrInt(int offset,
int numIndirect,
int[] v)
|
protected void |
putPtrShort(int offset,
int numPointers,
short[] v)
|
protected void |
putPtrShortString(int offet,
int numPointers,
String v)
|
protected void |
putPtrStruct(int offset,
int size,
int numIndirect,
NativeStructure[] v)
|
protected void |
putPtrUnsignedByte(int offset,
int numIndirect,
short[] v)
|
protected void |
putPtrUnsignedShort(int offset,
int numIndirect,
char[] v)
|
protected void |
putPtrVariant(int offset,
int numIndirect,
Object[] v)
|
protected void |
putPtrvoid(int offset,
int numIndirect,
ByteBuffer v)
|
protected void |
putSCODE(int offset,
int v)
|
protected void |
putShort(int offset,
short v)
|
protected void |
putShortArray(int offset,
int count,
short[] v)
|
protected void |
putSHORTArray(int offset,
short[] bytes)
|
protected void |
putString(int offset,
int buflen,
String v)
Superceded by putByteString |
protected void |
putStruct(int offset,
int length,
NativeStructure s)
Copy s into a sub-structure of this. |
protected void |
putStruct(int offset,
int length,
NativeStructure[] v)
|
protected void |
putStructArray(int offset,
int size,
int count,
NativeStructure[] v)
Copy v into this structure |
protected void |
putUINTArray(int offset,
long[] bytes)
|
protected void |
putUnsignedByte(int offset,
short v)
|
protected void |
putUnsignedByteArray(int offset,
int count,
short[] v)
Copies the array into this struct in native byte order and packing. |
protected void |
putUnsignedInt(int offset,
long v)
|
protected void |
putUnsignedIntArray(int offset,
int count,
long[] v)
Copies the array into this struct in native byte order and packing. |
protected void |
putUnsignedLongLong(int offset,
BigInteger v)
|
protected void |
putUnsignedShort(int offset,
char v)
|
protected void |
putUnsignedShortArray(int offset,
int count,
char[] v)
Copies the array into this struct in native byte order and packing. |
protected void |
putUSHORTArray(int offset,
char[] bytes)
|
protected void |
putVariant(int offset,
Object v)
|
protected void |
putVARIANTArray(int offset,
Object[] bytes)
|
static String |
stringFromC(byte[] s)
Turn an array of bytes that is a C '\0' terminated string into a java string. |
static String |
stringFromC(byte[] s,
int offset,
int length)
Turn an array of bytes that is a C '\0' terminated string into a java string. |
void |
zero()
Fill the structure with zeros |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected NativeStructure(byte[] bytes)
protected NativeStructure(ByteBuffer bb)
Method Detail |
---|
public void order(ByteOrder bo)
bo
- The new byte order.public ByteOrder order()
public void zero()
protected void putLong(int offset, long v)
protected long getLong(int offset)
protected void putUnsignedLongLong(int offset, BigInteger v)
protected BigInteger getUnsignedLongLong(int offset)
protected void putSCODE(int offset, int v)
protected int getSCODE(int offset)
protected void putInt(int offset, int v)
protected int getInt(int offset)
protected void putUnsignedInt(int offset, long v)
protected long getUnsignedInt(int offset)
protected void putBool(int offset, boolean v)
protected boolean getBool(int offset)
protected void putShort(int offset, short v)
protected short getShort(int offset)
protected void putUnsignedShort(int offset, char v)
protected char getUnsignedShort(int offset)
protected void putByte(int offset, byte v)
protected byte getByte(int offset)
protected void putUnsignedByte(int offset, short v)
protected short getUnsignedByte(int offset)
protected void putDouble(int offset, double v)
protected double getDouble(int offset)
protected void putFloat(int offset, float v)
protected float getFloat(int offset)
protected void putString(int offset, int buflen, String v)
protected String getString(int offset, int buflen)
protected void putByteString(int offset, int buflen, String v)
protected String getByteString(int offset, int buflen)
public static String stringFromC(byte[] s)
public static String stringFromC(byte[] s, int offset, int length)
s
- offset
- length
-
protected void putArray(int offset, int buflen, byte[] v)
offset
- buflen
- v
- protected byte[] getArray(int offset, int buflen)
offset
- buflen
-
protected void putByteArray(int offset, int buflen, byte[] v)
protected byte[] getByteArray(int offset, int buflen)
offset
- buflen
-
protected void putUnsignedIntArray(int offset, int count, long[] v)
offset
- count
- v
- protected long[] getUnsignedIntArray(int offset, int count)
offset
- count
-
protected void putShortArray(int offset, int count, short[] v)
protected short[] getShortArray(int offset, int count)
protected void putIntArray(int offset, int count, int[] v)
protected int[] getIntArray(int offset, int count)
protected void putFloatArray(int offset, int count, float[] v)
protected float[] getFloatArray(int offset, int count)
protected void putDoubleArray(int offset, int count, double[] v)
protected double[] getDoubleArray(int offset, int count)
protected void putBstrArray(int offset, int count, String[] v)
protected String[] getBstrArray(int offset, int count)
protected void putUnsignedShortArray(int offset, int count, char[] v)
offset
- count
- v
- protected char[] getUnsignedShortArray(int offset, int count)
offset
- count
-
protected void putUnsignedByteArray(int offset, int count, short[] v)
offset
- count
- v
- protected short[] getUnsignedByteArray(int offset, int count)
offset
- count
-
protected ByteBuffer getRemaining(int offset)
offset
-
protected ByteBuffer getSlice(int offset, int length)
offset
- start offset of slicelength
- length of slice
protected ByteBuffer getSlice(int offset, long length)
offset
- length
- protected void putStruct(int offset, int length, NativeStructure s)
offset
- length
- s
- protected void getStruct(int offset, int length, NativeStructure s)
offset
- length
- s
- protected void putStruct(int offset, int length, NativeStructure[] v)
protected void getStruct(int offset, int length, NativeStructure[] v)
protected void putInterface(int offset, IUnknown unk)
protected void getInterface(int offset, Object[] out)
protected void putVariant(int offset, Object v)
protected Object getVariant(int offset)
protected void putPtrVariant(int offset, int numIndirect, Object[] v)
protected Object[] getPtrVariant(int offset, int numIndirect)
protected void putPtrStruct(int offset, int size, int numIndirect, NativeStructure[] v)
protected ByteBuffer getPtrStruct(int offset, int size, int numIndirect)
protected void putPtrInt(int offset, int numIndirect, int[] v)
protected int[] getPtrInt(int offset, int numIndirect)
protected void putPtrUnsignedByte(int offset, int numIndirect, short[] v)
protected short[] getPtrUnsignedByte(int offset, int numIndirect)
protected void putPtrUnsignedShort(int offset, int numIndirect, char[] v)
protected char[] getPtrUnsignedShort(int offset, int numIndirect)
protected void putPtrvoid(int offset, int numIndirect, ByteBuffer v)
protected ByteBuffer getPtrvoid(int offset, int numIndirect)
protected void putBstr(int offset, String v)
protected String getBstr(int offset)
protected void putDate(int offset, Date v)
protected Date getDate(int offset)
protected void putLpwstr(int offset, String v)
protected String getLpwstr(int offset)
protected void freeLpwstr(int offset)
protected void putPtrShort(int offset, int numPointers, short[] v)
protected short[] getPtrShort(int offset, int numPointers)
protected void putPtrShortString(int offet, int numPointers, String v)
protected String getPtrShortString(int offset, int numPointers)
protected void putSHORTArray(int offset, short[] bytes)
protected short[] getSHORTArray(int offset)
protected void putBYTEArray(int offset, short[] bytes)
protected short[] getBYTEArray(int offset)
protected void putUSHORTArray(int offset, char[] bytes)
protected char[] getUSHORTArray(int offset)
protected void putBSTRArray(int offset, String[] bytes)
protected String[] getBSTRArray(int offset)
protected void putBOOLArray(int offset, boolean[] bytes)
protected boolean[] getBOOLArray(int offset)
protected void putLONGArray(int offset, int[] bytes)
protected int[] getLONGArray(int offset)
protected void putUINTArray(int offset, long[] bytes)
protected long[] getUINTArray(int offset)
protected void putDOUBLEArray(int offset, double[] bytes)
protected double[] getDOUBLEArray(int offset)
protected void putFLOATArray(int offset, float[] bytes)
protected float[] getFLOATArray(int offset)
protected void putINTArray(int offset, int[] bytes)
protected int[] getINTArray(int offset)
protected void putVARIANTArray(int offset, Object[] bytes)
protected Object[] getVARIANTArray(int offset)
public void clearRecord()
protected void putStructArray(int offset, int size, int count, NativeStructure[] v)
offset
- size
- count
- v
- protected void getStructArray(int offset, int size, int count, NativeStructure[] v)
offset
- size
- count
- v
- public byte[] _getStructureBytes()
public ByteBuffer _getByteBuffer()
public boolean equals(Object other)
equals
in class Object
public int compareTo(Object other)
compareTo
in interface Comparable
other
-
ClassCastException
- if native structures are not of
the same type.public ByteBuffer getByteBuffer()
public int hashCode()
hashCode
in class Object
public static int getByteSize()
public static int getUnsignedByteSize()
public static int getShortSize()
public static int getUnsignedShortSize()
public static int getIntSize()
public static int getUnsignedIntSize()
public static int getLongSize()
public static int getUnsignedLongSize()
public static int getFloatSize()
public static int getDoubleSize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |