CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.io.pof
Class PofBufferReader

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.io.pof.PofHelper
          extended by com.tangosol.io.pof.PofBufferReader
All Implemented Interfaces:
PofConstants, PofReader
Direct Known Subclasses:
PofBufferReader.UserTypeReader

public class PofBufferReader
extends PofHelper
implements PofReader

PofReader implementation that reads POF-encoded data from a BufferInput.

Since:
Coherence 3.2
Author:
cp 2006.07.14

Nested Class Summary
static class PofBufferReader.UserTypeReader
          The UserTypeReader implementation is a contextually-aware PofReader whose purpose is to advance through the properties of a value of a specified user type.
 
Nested classes/interfaces inherited from class com.tangosol.io.pof.PofHelper
PofHelper.ReadableEntrySetMap, PofHelper.WriteableEntrySetMap
 
Field Summary
protected  SparseArray m_arrayRefs
          Lazily-constructed mapping of identities to references.
protected  PofContext m_ctx
          The PofContext to use to realize user data types as Java objects.
protected  ReadBuffer.BufferInput m_in
          The BufferInput containing the POF stream.
 
Fields inherited from class com.tangosol.io.pof.PofHelper
BIGDECIMAL_ZERO, BINARY_EMPTY, BOOLEAN_ARRAY_EMPTY, BYTE_ARRAY_EMPTY, CHAR_ARRAY_EMPTY, COLLECTION_EMPTY, DOUBLE_ARRAY_EMPTY, FLOAT_ARRAY_EMPTY, INT_ARRAY_EMPTY, LONG_ARRAY_EMPTY, OBJECT_ARRAY_EMPTY, SHORT_ARRAY_EMPTY
 
Fields inherited from interface com.tangosol.io.pof.PofConstants
J_BIG_DECIMAL, J_BIG_INTEGER, J_BINARY, J_BOOLEAN, J_BOOLEAN_ARRAY, J_BYTE, J_BYTE_ARRAY, J_CHAR_ARRAY, J_CHARACTER, J_COLLECTION, J_DATE, J_DATETIME, J_DOUBLE, J_DOUBLE_ARRAY, J_FLOAT, J_FLOAT_ARRAY, J_INT_ARRAY, J_INTEGER, J_LONG, J_LONG_ARRAY, J_MAP, J_NULL, J_OBJECT_ARRAY, J_QUAD, J_RAW_DATE, J_RAW_DATETIME, J_RAW_DAY_TIME_INTERVAL, J_RAW_TIME, J_RAW_TIME_INTERVAL, J_RAW_YEAR_MONTH_INTERVAL, J_SHORT, J_SHORT_ARRAY, J_SPARSE_ARRAY, J_STRING, J_TIME, J_TIMESTAMP, J_USER_TYPE, MAX_DECIMAL128_SCALE, MAX_DECIMAL128_UNSCALED, MAX_DECIMAL32_SCALE, MAX_DECIMAL32_UNSCALED, MAX_DECIMAL64_SCALE, MAX_DECIMAL64_UNSCALED, MIN_DECIMAL128_SCALE, MIN_DECIMAL32_SCALE, MIN_DECIMAL64_SCALE, T_ARRAY, T_BOOLEAN, T_CHAR, T_CHAR_STRING, T_COLLECTION, T_DATE, T_DATETIME, T_DAY_TIME_INTERVAL, T_DECIMAL128, T_DECIMAL32, T_DECIMAL64, T_FLOAT128, T_FLOAT32, T_FLOAT64, T_IDENTITY, T_INT128, T_INT16, T_INT32, T_INT64, T_MAP, T_OCTET, T_OCTET_STRING, T_REFERENCE, T_SPARSE_ARRAY, T_TIME, T_TIME_INTERVAL, T_UNIFORM_ARRAY, T_UNIFORM_COLLECTION, T_UNIFORM_KEYS_MAP, T_UNIFORM_MAP, T_UNIFORM_SPARSE_ARRAY, T_YEAR_MONTH_INTERVAL, V_BOOLEAN_FALSE, V_BOOLEAN_TRUE, V_COLLECTION_EMPTY, V_FP_NAN, V_FP_NEG_INFINITY, V_FP_POS_INFINITY, V_INT_0, V_INT_1, V_INT_10, V_INT_11, V_INT_12, V_INT_13, V_INT_14, V_INT_15, V_INT_16, V_INT_17, V_INT_18, V_INT_19, V_INT_2, V_INT_20, V_INT_21, V_INT_22, V_INT_3, V_INT_4, V_INT_5, V_INT_6, V_INT_7, V_INT_8, V_INT_9, V_INT_NEG_1, V_REFERENCE_NULL, V_STRING_ZERO_LENGTH
 
Constructor Summary
protected PofBufferReader()
           
  PofBufferReader(ReadBuffer.BufferInput in, PofContext ctx)
          Construct a POF parser that will pull values from the specified stream
 
Method Summary
protected  boolean advanceTo(int iProp)
          Advance through the POF stream until the specified property is found.
protected  void complete(int iProp)
          Register the completion of the parsing of a value.
protected  SparseArray ensureReferenceRegistry()
          Obtain the registry for identity-reference pairs, creating it if necessary.
protected  PofBufferReader getParentParser()
          If this parser is contextually within a user type, obtain the parser which created this parser in order to parse the user type.
 PofContext getPofContext()
          Return the PofContext object used by this PofReader to deserialize user types from a POF stream.
 int getUserTypeId()
          Determine the user type that is currently being parsed.
 int getVersionId()
          Determine the version identifier of the user type that is currently being parsed.
protected  Object lookupIdentity(int nId)
          Look up the specified identity and return the object to which it refers.
protected  Object readAsObject(int nType)
          Read a POF value as an Object.
protected  Object[] readAsObjectArray(int nType, Object[] ao)
          Read a POF value as an Object array.
 BigDecimal readBigDecimal(int iProp)
          Read a BigDecimal from the POF stream.
 BigInteger readBigInteger(int iProp)
          Read a BigInteger from the POF stream.
 Binary readBinary(int iProp)
          Read a Binary from the POF stream.
 boolean readBoolean(int iProp)
          Read a boolean property from the POF stream.
 boolean[] readBooleanArray(int iProp)
          Read a boolean[] property from the POF stream.
 byte readByte(int iProp)
          Read a byte property from the POF stream.
 byte[] readByteArray(int iProp)
          Read a byte[] property from the POF stream.
 char readChar(int iProp)
          Read a char property from the POF stream.
 char[] readCharArray(int iProp)
          Read a char[] property from the POF stream.
 Collection readCollection(int iProp, Collection coll)
          Read a Collection of object values from the POF stream.
 Date readDate(int iProp)
          Read a java.util.Date from the POF stream.
 double readDouble(int iProp)
          Read a double property from the POF stream.
 double[] readDoubleArray(int iProp)
          Read a double[] property from the POF stream.
 float readFloat(int iProp)
          Read a float property from the POF stream.
 float[] readFloatArray(int iProp)
          Read a float[] property from the POF stream.
 int readInt(int iProp)
          Read a int property from the POF stream.
 int[] readIntArray(int iProp)
          Read a int[] property from the POF stream.
 long readLong(int iProp)
          Read a long property from the POF stream.
 long[] readLongArray(int iProp)
          Read a long[] property from the POF stream.
 LongArray readLongArray(int iProp, LongArray array)
          Read a LongArray of object values.
 Map readMap(int iProp, Map map)
          Read a Map of key/value pairs from the POF stream.
 Object readObject(int iProp)
          Read a property of any type, including a user type, from the POF stream.
 Object[] readObjectArray(int iProp, Object[] ao)
          Read an array of object values.
 RawDate readRawDate(int iProp)
          Read a RawDate from the POF stream.
 RawDateTime readRawDateTime(int iProp)
          Read a RawDateTime from the POF stream.
 RawDayTimeInterval readRawDayTimeInterval(int iProp)
          Read a RawDayTimeInterval from the POF stream.
 RawQuad readRawQuad(int iProp)
          Read a RawQuad from the POF stream.
 RawTime readRawTime(int iProp)
          Read a RawTime from the POF stream.
 RawTimeInterval readRawTimeInterval(int iProp)
          Read a RawTimeInterval from the POF stream.
 RawYearMonthInterval readRawYearMonthInterval(int iProp)
          Read a RawYearMonthInterval from the POF stream.
 Binary readRemainder()
          Read all remaining indexed properties of the current user type from the POF stream.
 short readShort(int iProp)
          Read a short property from the POF stream.
 short[] readShortArray(int iProp)
          Read a short[] property from the POF stream.
 String readString(int iProp)
          Read a String from the POF stream.
protected  void registerIdentity(int nId, Object oValue)
          Register the passed value with the passed identity.
 void setPofContext(PofContext ctx)
          Configure the PofContext object used by this PofReader to deserialize user types from a POF stream.
 
Methods inherited from class com.tangosol.io.pof.PofHelper
calcDecimalSize, checkDate, checkDayTimeInterval, checkDecimalRange, checkElementCount, checkReferenceRange, checkTime, checkTimeInterval, checkTimeZone, checkType, checkYearMonthInterval, convertNumber, convertToDate, decodeTinyInt, encodeTinyInt, formatDate, formatTime, formatTime, getJavaTypeId, getPofTypeId, readAsBigDecimal, readAsBigInteger, readAsChar, readAsDouble, readAsFloat, readAsInt, readAsLong, readAsQuad, readBigDecimal, readBigInteger, readChar, readQuad, readRawDate, readRawTime, resizeArray, skipPackedInts, skipUniformValue, skipValue, writeBigDecimal, writeBigInteger, writeDate, writeTime
 

Field Detail

m_in

protected ReadBuffer.BufferInput m_in
The BufferInput containing the POF stream.


m_ctx

protected PofContext m_ctx
The PofContext to use to realize user data types as Java objects.


m_arrayRefs

protected SparseArray m_arrayRefs
Lazily-constructed mapping of identities to references.

Constructor Detail

PofBufferReader

public PofBufferReader(ReadBuffer.BufferInput in,
                       PofContext ctx)
Construct a POF parser that will pull values from the specified stream

Parameters:
in - a BufferInput object
ctx - the PofContext

PofBufferReader

protected PofBufferReader()
Method Detail

readBoolean

public boolean readBoolean(int iProp)
                    throws IOException
Read a boolean property from the POF stream.

Specified by:
readBoolean in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the boolean property value
Throws:
IOException - if an I/O error occurs

readByte

public byte readByte(int iProp)
              throws IOException
Read a byte property from the POF stream.

Specified by:
readByte in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the byte property value
Throws:
IOException - if an I/O error occurs

readChar

public char readChar(int iProp)
              throws IOException
Read a char property from the POF stream.

Specified by:
readChar in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the char property value
Throws:
IOException - if an I/O error occurs

readShort

public short readShort(int iProp)
                throws IOException
Read a short property from the POF stream.

Specified by:
readShort in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the short property value
Throws:
IOException - if an I/O error occurs

readInt

public int readInt(int iProp)
            throws IOException
Read a int property from the POF stream.

Specified by:
readInt in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the int property value
Throws:
IOException - if an I/O error occurs

readLong

public long readLong(int iProp)
              throws IOException
Read a long property from the POF stream.

Specified by:
readLong in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the long property value
Throws:
IOException - if an I/O error occurs

readFloat

public float readFloat(int iProp)
                throws IOException
Read a float property from the POF stream.

Specified by:
readFloat in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the float property value
Throws:
IOException - if an I/O error occurs

readDouble

public double readDouble(int iProp)
                  throws IOException
Read a double property from the POF stream.

Specified by:
readDouble in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the double property value
Throws:
IOException - if an I/O error occurs

readBooleanArray

public boolean[] readBooleanArray(int iProp)
                           throws IOException
Read a boolean[] property from the POF stream.

Specified by:
readBooleanArray in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the boolean[] property value; may be null
Throws:
IOException - if an I/O error occurs

readByteArray

public byte[] readByteArray(int iProp)
                     throws IOException
Read a byte[] property from the POF stream.

Specified by:
readByteArray in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the byte[] property value; may be null
Throws:
IOException - if an I/O error occurs

readCharArray

public char[] readCharArray(int iProp)
                     throws IOException
Read a char[] property from the POF stream.

Specified by:
readCharArray in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the char[] property value; may be null
Throws:
IOException - if an I/O error occurs

readShortArray

public short[] readShortArray(int iProp)
                       throws IOException
Read a short[] property from the POF stream.

Specified by:
readShortArray in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the short[] property value; may be null
Throws:
IOException - if an I/O error occurs

readIntArray

public int[] readIntArray(int iProp)
                   throws IOException
Read a int[] property from the POF stream.

Specified by:
readIntArray in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the int[] property value; may be null
Throws:
IOException - if an I/O error occurs

readLongArray

public long[] readLongArray(int iProp)
                     throws IOException
Read a long[] property from the POF stream.

Specified by:
readLongArray in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the long[] property value; may be null
Throws:
IOException - if an I/O error occurs

readFloatArray

public float[] readFloatArray(int iProp)
                       throws IOException
Read a float[] property from the POF stream.

Specified by:
readFloatArray in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the float[] property value; may be null
Throws:
IOException - if an I/O error occurs

readDoubleArray

public double[] readDoubleArray(int iProp)
                         throws IOException
Read a double[] property from the POF stream.

Specified by:
readDoubleArray in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the double[] property value; may be null
Throws:
IOException - if an I/O error occurs

readBigInteger

public BigInteger readBigInteger(int iProp)
                          throws IOException
Read a BigInteger from the POF stream.

Specified by:
readBigInteger in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the BigInteger property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readRawQuad

public RawQuad readRawQuad(int iProp)
                    throws IOException
Read a RawQuad from the POF stream.

Specified by:
readRawQuad in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the RawQuad property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readBigDecimal

public BigDecimal readBigDecimal(int iProp)
                          throws IOException
Read a BigDecimal from the POF stream.

Specified by:
readBigDecimal in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the BigDecimal property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readBinary

public Binary readBinary(int iProp)
                  throws IOException
Read a Binary from the POF stream.

Specified by:
readBinary in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the Binary property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readString

public String readString(int iProp)
                  throws IOException
Read a String from the POF stream.

Specified by:
readString in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the String property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readDate

public Date readDate(int iProp)
              throws IOException
Read a java.util.Date from the POF stream.

Specified by:
readDate in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the Date property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readRawDate

public RawDate readRawDate(int iProp)
                    throws IOException
Read a RawDate from the POF stream. The RawDate class contains the raw date information that was carried in the POF stream.

Specified by:
readRawDate in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the RawDate property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readRawTime

public RawTime readRawTime(int iProp)
                    throws IOException
Read a RawTime from the POF stream. The RawTime class contains the raw time information that was carried in the POF stream, including raw timezone information.

Specified by:
readRawTime in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the RawTime property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readRawDateTime

public RawDateTime readRawDateTime(int iProp)
                            throws IOException
Read a RawDateTime from the POF stream. The RawDateTime class contains the raw date and time information that was carried in the POF stream, including raw timezone information.

Specified by:
readRawDateTime in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the RawDateTime property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readRawYearMonthInterval

public RawYearMonthInterval readRawYearMonthInterval(int iProp)
                                              throws IOException
Read a RawYearMonthInterval from the POF stream. The RawYearMonthInterval class contains the raw year-month interval information that was carried in the POF stream.

Specified by:
readRawYearMonthInterval in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the RawYearMonthInterval property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readRawTimeInterval

public RawTimeInterval readRawTimeInterval(int iProp)
                                    throws IOException
Read a RawTimeInterval from the POF stream. The RawTimeInterval class contains the raw time interval information that was carried in the POF stream.

Specified by:
readRawTimeInterval in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the RawTimeInterval property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readRawDayTimeInterval

public RawDayTimeInterval readRawDayTimeInterval(int iProp)
                                          throws IOException
Read a RawDayTimeInterval from the POF stream. The RawDayTimeInterval class contains the raw year-month interval information that was carried in the POF stream.

Specified by:
readRawDayTimeInterval in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the RawDayTimeInterval property value, or null if no value was available in the POF stream
Throws:
IOException - if an I/O error occurs

readObjectArray

public Object[] readObjectArray(int iProp,
                                Object[] ao)
                         throws IOException
Read an array of object values.

Specified by:
readObjectArray in interface PofReader
Parameters:
iProp - the property index to read
ao - the optional array to use to store the values, or to use as a typed template for creating an array to store the values, following the documentation for Collection.toArray()
Returns:
an array of object values, or null if no array is passed and there is no array data in the POF stream
Throws:
IOException - if an I/O error occurs

readLongArray

public LongArray readLongArray(int iProp,
                               LongArray array)
                        throws IOException
Read a LongArray of object values.

Specified by:
readLongArray in interface PofReader
Parameters:
iProp - the property index to read
array - the optional LongArray object to use to store the values
Returns:
a LongArray of object values, or null if no LongArray is passed and there is no array data in the POF stream
Throws:
IOException - if an I/O error occurs

readCollection

public Collection readCollection(int iProp,
                                 Collection coll)
                          throws IOException
Read a Collection of object values from the POF stream.

Specified by:
readCollection in interface PofReader
Parameters:
iProp - the property index to read
coll - the optional Collection to use to store the values
Returns:
a Collection of object values, or null if no Collection is passed and there is no collection data in the POF stream
Throws:
IOException - if an I/O error occurs

readMap

public Map readMap(int iProp,
                   Map map)
            throws IOException
Read a Map of key/value pairs from the POF stream.

Specified by:
readMap in interface PofReader
Parameters:
iProp - the property index to read
map - the optional Map to initialize
Returns:
a Map of key/value pairs object values, or null if no Map is passed and there is no key/value data in the POF stream
Throws:
IOException - if an I/O error occurs

getPofContext

public PofContext getPofContext()
Return the PofContext object used by this PofReader to deserialize user types from a POF stream.

Specified by:
getPofContext in interface PofReader
Returns:
the PofContext object that contains user type meta-data

setPofContext

public void setPofContext(PofContext ctx)
Configure the PofContext object used by this PofReader to deserialize user types from a POF stream.

Note: this is an advanced method that should be used with care. For example, if this method is being used to switch to another PofContext mid-POF stream, it is important to eventually restore the original PofContext. For example:

 PofContext ctxOrig = reader.getPofContext();
 try
     {
     // switch to another PofContext
     PofContext ctxNew = ...;
     reader.setContext(ctxNew);

     // read POF data using the reader
     }
 finally
     {
     // restore the original PofContext
     reader.setPofContext(ctxOrig);
     }
 

Specified by:
setPofContext in interface PofReader
Parameters:
ctx - the new PofContext; must not be null

readObject

public Object readObject(int iProp)
                  throws IOException
Read a property of any type, including a user type, from the POF stream.

Specified by:
readObject in interface PofReader
Parameters:
iProp - the property index to read
Returns:
the Object value; may be null
Throws:
IOException - if an I/O error occurs

getUserTypeId

public int getUserTypeId()
Determine the user type that is currently being parsed.

Specified by:
getUserTypeId in interface PofReader
Returns:
the user type information, or -1 if the PofReader is not currently parsing a user type

getVersionId

public int getVersionId()
Determine the version identifier of the user type that is currently being parsed.

Specified by:
getVersionId in interface PofReader
Returns:
the integer version ID read from the POF stream; always non-negative

readRemainder

public Binary readRemainder()
                     throws IOException
Read all remaining indexed properties of the current user type from the POF stream. As part of reading in a user type, this method must be called by the PofSerializer that is reading the user type, or the read position within the POF stream will be corrupted.

Subsequent calls to the various readXYZ methods of this interface will fail after this method is called.

Specified by:
readRemainder in interface PofReader
Returns:
a Binary object containing zero or more indexed properties in binary POF encoded form
Throws:
IOException - if an I/O error occurs

advanceTo

protected boolean advanceTo(int iProp)
                     throws IOException
Advance through the POF stream until the specified property is found. If the property is found, return true, otherwise return false and advance to the first property that follows the specified property.

Parameters:
iProp - the index of the property to advance to
Returns:
true if the property is found
Throws:
IllegalStateException - if the POF stream has already advanced past the desired property
IOException - if an I/O error occurs

complete

protected void complete(int iProp)
                 throws IOException
Register the completion of the parsing of a value.

Parameters:
iProp - the property index
Throws:
IOException - if an I/O error occurs

getParentParser

protected PofBufferReader getParentParser()
If this parser is contextually within a user type, obtain the parser which created this parser in order to parse the user type.

Returns:
the parser for the context within which this parser is operating

ensureReferenceRegistry

protected SparseArray ensureReferenceRegistry()
Obtain the registry for identity-reference pairs, creating it if necessary.

Returns:
the identity-reference registry, never null

registerIdentity

protected void registerIdentity(int nId,
                                Object oValue)
                         throws IOException
Register the passed value with the passed identity.

Parameters:
nId -
oValue -
Throws:
IOException - if the specified identity is already registered

lookupIdentity

protected Object lookupIdentity(int nId)
                         throws IOException
Look up the specified identity and return the object to which it refers.

Parameters:
nId - the identity
Returns:
the object registered under that identity
Throws:
IOException - if the requested identity is not registered

readAsObject

protected Object readAsObject(int nType)
                       throws IOException
Read a POF value as an Object.

Parameters:
nType - the type identifier of the value
Returns:
an Object value
Throws:
IOException - if an I/O error occurs

readAsObjectArray

protected Object[] readAsObjectArray(int nType,
                                     Object[] ao)
                              throws IOException
Read a POF value as an Object array.

Parameters:
nType - the type identifier of the value
ao - the optional array to use to store the values, or to use as a typed template for creating an array to store the values, following the documentation for Collection.toArray()
Returns:
an Object array
Throws:
IOException - if an I/O error occurs

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation