ca.idms.io
Class NativeObject

java.lang.Object
  extended by ca.idms.io.TraceObject
      extended by ca.idms.io.NativeObject
All Implemented Interfaces:
Native, Trace
Direct Known Subclasses:
NativeBase, NativeBuffer

public class NativeObject
extends TraceObject
implements Native

Provides a default implementation of the Native interface. This class reads and writes an array of unconverted bytes, and is used when conversion is not needed. Derived classes can override the readNative(ca.idms.io.NativeDataInputStream) and writeNative(ca.idms.io.NativeDataOutputStream) methods to convert data using the methods provided by the NativeDataInputStream and NativeDataOutputStream classes.

Author:
Dave Ross
See Also:
Native, NativeFormat, TraceObject

Field Summary
protected  byte[] buffer
          Buffer for data in native format.
protected  int length
          Length of data in byte array.
protected  int offset
          Start offset of data in byte array.
 
Fields inherited from class ca.idms.io.TraceObject
exclude, EXCLUDE, FALSE, include, INCLUDE, logWriter, PREFIX, PROPERTIES_FILE, PROPERTIES_KEY, snap, SNAP, SNAP_BYTES, SNAP_NATIVE, SNAP_OBJECT, SNAP_SQL, snapBytes, snapNative, snapObject, snapSql, stub, trace, TRACE, TRACE_FILE, TRACE_LIFE, TRACE_NATIVE, TRACE_PRODUCT, traceLife, traceNative, traceStream, TRUE
 
Constructor Summary
protected NativeObject()
          Creates an uninitialized NativeObject.
  NativeObject(byte[] buf)
          Creates a NativeObject from a byte array.
  NativeObject(byte[] buf, int off, int len)
          Creates an initialized NativeObject.
  NativeObject(int len)
          Creates an initialized NativeObject.
 
Method Summary
protected  java.lang.Object get(java.lang.reflect.Field f)
          Overrides the default get method to allow the default snap method access to the value of a non-public variable.
 byte[] getBuffer()
          Gets the byte array buffer.
 short getClient()
          The default getClient method returns 0.
 int getOffset()
          Gets the byte array offset.
 int length()
          Computes the size of the native form of the object.
 int length(NativeFormat fmt)
          Computes the size of the native form the object.
 boolean readBuffer(NativeDataInputStream in)
          Conditionally reads the buffer from a stream.
 void readNative(NativeDataInputStream in)
          Reads the object from a stream in native format.
 void snap()
          Overrides snap in TraceObject and displays the byte array.
 boolean writeBuffer(NativeDataOutputStream out)
          Conditionally writes the buffer to a stream.
 void writeNative(NativeDataOutputStream out)
          Writes the object to a stream in native format.
 
Methods inherited from class ca.idms.io.TraceObject
finalize, getBoolean, getClasses, getInteger, getProperty, listProperties, message, parseList, print, print, print, println, println, snap, snap, snap, snap, snap, snap, toHex, toHex, toHex, toHex, toHex, toString, trace, trace, trace, trace, trace, trace, traceEntry, unloadProperties
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected byte[] buffer
Buffer for data in native format.


offset

protected int offset
Start offset of data in byte array.


length

protected int length
Length of data in byte array.

Constructor Detail

NativeObject

protected NativeObject()
Creates an uninitialized NativeObject. This is meant to be used as a base class for Native objects that perform data conversion on input and output. The methods in this class can then be used to read and write the object to a stream of bytes with no conversion.


NativeObject

public NativeObject(int len)
Creates an initialized NativeObject. An empty byte array is allocated.

Parameters:
len - length of byte array.

NativeObject

public NativeObject(byte[] buf)
Creates a NativeObject from a byte array.

Parameters:
buf - an existing byte array.

NativeObject

public NativeObject(byte[] buf,
                    int off,
                    int len)
Creates an initialized NativeObject.

The byte array is referenced, not copied. The buffer can be null, which allows a derived class to defer setting the buffer. In this case the derived class is responsible for ensuring the validity of the offset and length.

Parameters:
buf - existing buffer.
off - index of start of data.
len - length of data.
Method Detail

get

protected java.lang.Object get(java.lang.reflect.Field f)
                        throws java.lang.IllegalAccessException
Overrides the default get method to allow the default snap method access to the value of a non-public variable.

Overrides:
get in class TraceObject
Parameters:
f - a Field returned by Class.getDeclaredFields
Returns:
the Object named by f
Throws:
java.lang.IllegalAccessException - should not really happen, but Field.get requires it
See Also:
TraceObject.snap, TraceObject.snap()

snap

public void snap()
Overrides snap in TraceObject and displays the byte array.

Specified by:
snap in interface Trace
Overrides:
snap in class TraceObject
See Also:
TraceObject.get(java.lang.reflect.Field)

getBuffer

public byte[] getBuffer()
Gets the byte array buffer.

Returns:
the underlying byte array.

getOffset

public int getOffset()
Gets the byte array offset.

Returns:
the underlying byte array.

length

public int length()
Computes the size of the native form of the object. Derived classes may override this method to compute an estimated length of the contents of the object when converted to a default format.

Returns:
length of the buffer in bytes.

getClient

public short getClient()
The default getClient method returns 0. Derived classes can override this method to return a specific client type for the Native control block.

Specified by:
getClient in interface Native
Returns:
0

length

public int length(NativeFormat fmt)
Computes the size of the native form the object. Derived classes should override this method to compute the length of the contents of the object when converted according to fmt.

Specified by:
length in interface Native
Parameters:
fmt - describes native data formats, ignored.
Returns:
length of the object in bytes.

readNative

public void readNative(NativeDataInputStream in)
                throws java.io.IOException
Reads the object from a stream in native format. Derived classes should override this method to read from the stream and convert the object.

Specified by:
readNative in interface Native
Parameters:
in - the native buffered input stream.
Throws:
java.io.IOException - if an IO error occurs

writeNative

public void writeNative(NativeDataOutputStream out)
                 throws java.io.IOException
Writes the object to a stream in native format. Derived classes should override this method to convert the object and write to the stream.

Specified by:
writeNative in interface Native
Parameters:
out - the native buffered output stream.
Throws:
java.io.IOException - if an IO error occurs

readBuffer

public boolean readBuffer(NativeDataInputStream in)
                   throws java.io.IOException
Conditionally reads the buffer from a stream. If a buffer is allocated this reads enough bytes from the input stream to fill the buffer. This method allows a derived class to either read bytes directly into the underlying byte array, if present, or to convert the bytes read into objects.

Parameters:
in - the native buffered input stream.
Returns:
true if bytes were read.
Throws:
java.io.IOException - if an IO error occurs

writeBuffer

public boolean writeBuffer(NativeDataOutputStream out)
                    throws java.io.IOException
Conditionally writes the buffer to a stream. If a buffer is allocated this writes it to the output stream. This method allows a derived class to either write bytes directly from the underlying byte array, if present, or to convert and write the contents of its objects.

Parameters:
out - the native buffered output stream.
Returns:
true if bytes were written.
Throws:
java.io.IOException - if an IO error occurs


Copyright © 2009 CA, All rights reserved