ca.idms.io
Class NativeBase

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

public class NativeBase
extends NativeObject

Base class for the implementations of Native objects. Provides additional methods to support reading and writing both converted and byte array formats.

Since:
CA IDMS Server 4.2 OS/390 Edition
Version:
2.00, 11/20/04
Author:
Dave Ross

Field Summary
protected  int options
          Options that control how the object reads and writes native data.
static int READ_BOTH
          Read both bytes and objects from the input buffer.
static int SET_LENGTH
          Set len after writing.
 
Fields inherited from class ca.idms.io.NativeObject
buffer, length, offset
 
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
NativeBase()
          Base constructor.
NativeBase(int len)
          Base constructor to read a byte array from a stream.
 
Method Summary
 int getOptions()
           
 int length(NativeFormat fmt, int nat, int utf, int uni)
          Computes the estimated size of the native form of the object.
 boolean readBuffer(NativeDataInputStream in)
          Conditionally reads bytes from a stream.
 void setOptions(int i)
           
 boolean writeBuffer(NativeDataOutputStream out)
          Conditionally writes bytes to a stream.
 
Methods inherited from class ca.idms.io.NativeObject
get, getBuffer, getClient, getOffset, length, length, readNative, snap, writeNative
 
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

READ_BOTH

public static final int READ_BOTH
Read both bytes and objects from the input buffer. The next read will link to the byte array buffer but inform the caller that it didn't. The caller should then convert the byte array buffer into objects, which positions the input stream properly.

See Also:
Constant Field Values

SET_LENGTH

public static final int SET_LENGTH
Set len after writing. The next read will then link to the byte array buffer instead of converting it to objects.

See Also:
Constant Field Values

options

protected int options
Options that control how the object reads and writes native data.

See Also:
READ_BOTH, SET_LENGTH
Constructor Detail

NativeBase

public NativeBase()
Base constructor.


NativeBase

public NativeBase(int len)
Base constructor to read a byte array from a stream. No buffer is actually allocated.

The readNative method gets the buffer and current offset from the TraceBufferInputStream contained in the input stream. When READ_BOTH is set the readNative method does not advance the current offset in the input stream, allowing the data to also be read as objects.

The writeNative method writes data directly from the input stream's byte array. If data has not been read yet it writes nulls for the absolute value of the length specified to allocate an output buffer.

Parameters:
len - the length of the array.
See Also:
options
Method Detail

length

public int length(NativeFormat fmt,
                  int nat,
                  int utf,
                  int uni)
Computes the estimated size of the native form of the object.

Parameters:
fmt - NativeFormat object or null.
nat - actual native length.
utf - estimated UTF-8 length.
uni - estimated Unicode length.
Returns:
length in bytes.

getOptions

public int getOptions()
Returns:
options in effect

setOptions

public void setOptions(int i)
Parameters:
i - read write options
See Also:
READ_BOTH, SET_LENGTH

readBuffer

public boolean readBuffer(NativeDataInputStream in)
                   throws java.io.IOException
Conditionally reads bytes from a stream. This method extends the base NativeObject readBuffer method to get the buffer and offset from the input stream when buf == null && len != 0 . When len < 0 the input stream position remains unchanged, allowing the data to be read into objects as well as a buffer.

This can be used to read data directly from a TraceBufferInputStream byte array into an output stream.

Overrides:
readBuffer in class NativeObject
Parameters:
in - the native buffered input stream
Returns:
true if bytes were "read".
Throws:
java.io.IOException - if an IO error occurs
See Also:
NativeBase(int), NativeObject.readBuffer(ca.idms.io.NativeDataInputStream)

writeBuffer

public boolean writeBuffer(NativeDataOutputStream out)
                    throws java.io.IOException
Conditionally writes bytes to a stream. This method extends the base NativeObject writeNative(out) method to write an empty array of bytes to the output stream when the underlying buf == null && len != 0 .

This can be used to allocate space in a larger buffer contained in a TraceBufferOutputStream. No buffer remains allocated in this object.

Overrides:
writeBuffer in class NativeObject
Parameters:
out - the native buffered output stream.
Returns:
true if bytes were "written".
Throws:
java.io.IOException - if an IO error occurs
See Also:
NativeBase(int), NativeObject.writeBuffer(ca.idms.io.NativeDataOutputStream)


Copyright © 2009 CA, All rights reserved