public class raw extends BinaryData
Format string related processing is handled in method toString(String).
All RAW features other than string formatting are implemented in the common base class
BinaryData which is shared with MEMPTR types.
In Progress 4GL, the actual maximum size of a RAW cannot be reliably
determined. The largest value that has been found to consistently work is 31990. But
supposedly up to 32000 should work. It turns out these don't work in practice. This
implementation works to the 32000 size. Although the documentation suggests that 32kb
(32768 bytes or 32 times 1024) is the limit, attempting to use values of that size
actually cause memory access violations and abends, regardless of what the 4GL
documentation states. This class does NOT duplicate the instability or 4GL process
abends, but is otherwise compatible.
BinaryData.RangeCheckBaseDataType.Type, BaseDataType.WrapperHandler| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_SIZE
The maximum size of the binary data stored in an instance.
|
private byte[] |
value
Stores the state of this instance as an array of bytes.
|
unknown| Constructor and Description |
|---|
raw()
Default constructor, creates an instance that represents a 0 length byte array.
|
raw(BaseDataType value)
This is a special c'tor which should be used only when converting the
value returned by a function or method with polymorphic return type into the
expected type (i.e.
|
raw(byte[] val)
Constructor which creates an instance which is initialized based on the given binary data.
|
raw(character value)
Constructs an instance which converts the contents of the given
Progress 4GL compatible string form of a raw value into the proper
binary form.
|
raw(raw value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
raw(java.lang.String value)
Constructs an instance which converts the contents of the given
Progress 4GL compatible string form of a raw value into the proper
binary form.
|
| Modifier and Type | Method and Description |
|---|---|
protected byte[] |
asByteArray()
Return the entire contents of the current buffer as an array.
|
void |
assign(BaseDataType data)
Sets the state (data and unknown value) of this instance based on the state of the passed
instance.
|
protected void |
clearUnknown()
Sets the state of this instance's
unknown flag to false. |
int |
compareTo(java.lang.Object obj)
Compares this instance with the specified instance and returns a -1
if this instance is less than the specified, 0 if the two instances
are equal and 1 if this instance is greater than the specified
instance.
|
protected void |
deallocate()
Release any resources associated with the instance.
|
raw |
duplicate()
Does the same as standard
Object.clone() method but returns an instance of
BaseDataType and doesn't throw the CloneNotSupportedException. |
protected void |
extendBytes(long len)
Helper to create a new byte array with the same contents as the given byte array and the
specified length.
|
protected long |
findNextNull(long pos)
Returns the next index position into the array which is the
null byte,
starting at a given index position. |
BaseDataType.Type |
getType()
Get the type
|
BaseDataType |
instantiateDefault()
Creates a new instance of the same type that represents the default initialized value.
|
BaseDataType |
instantiateUnknown()
Creates a new instance of the same type that represents
unknown. |
static raw |
instantiateUnknownRaw()
Creates a new instance of the same type that represents
unknown. |
protected long |
internalLength()
Reports the current length of the buffer.
|
protected boolean |
isAutoExtend()
Determines if the array of binary data stored in an instance of this
class must be automatically extended in length when operations
write past the current length.
|
protected boolean |
isIncompatibleTypesOnConversion(BaseDataType value)
Returns true if dynamic data type conversion should not be attempted,
it can also throws in case of incompatible types for a POLY conversion.
|
protected boolean |
isLengthLimited()
Determines if the array of binary data stored in an instance of this
class must be limited in length.
|
boolean |
isUninitialized()
Reports if this instance represents an uninitialized buffer.
|
protected long |
lengthLimit()
Determines the maximum length of the array of binary data stored in an
instance of this class.
|
protected byte |
readByte(long pos)
Read the byte at the given location.
|
protected byte[] |
readByteRange(long pos,
long len,
boolean endian)
Read the bytes at the given location.
|
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
protected void |
replaceContents(byte[] value)
Replace the entire contents of the current buffer with the given array.
|
BinaryData |
setLength(long len)
Sets the array to a given length, which may result in either extending
or truncating the array.
|
void |
setUnknown()
Sets the state of this instance's
unknown flag to true. |
java.lang.String |
toString()
Creates a default string representation of the instance data which will be equivalent to the
result of
toStringExport(). |
java.lang.String |
toString(java.lang.String fmt)
Creates a string representation of the instance data using the given format string.
|
java.lang.String |
toStringExport()
Creates a string representation of the instance data using the 'export'
format in which the data is written as a base64 string prepended with 6
hexadecimal bytes of "header" information.
|
java.lang.String |
toStringMessage()
Creates a string representation of the instance data in a form that is compatible with the
MESSAGE language statement. |
protected long |
visibleLength()
Reports the current length of the buffer.
|
protected void |
writeByte(byte val,
long pos)
Write the byte into the given location.
|
protected void |
writeByteRange(byte[] data,
long pos,
long len,
boolean endian)
Write the bytes at the given location.
|
void |
writeExternal(java.io.ObjectOutput out)
Replacement for the default object writing method.
|
assign, assign, assign, defaultFormatString, genIndexError, genLimitedLengthError, genUninitializedError, getByte, getByte, getByteArray, getBytes, getBytes, getBytes, getBytes, getDouble, getDouble, getFloat, getFloat, getInt64, getInt64, getLong, getLong, getShort, getShort, getString, getString, getString, getString, getString, getString, getUnprocessedDouble, getUnsignedLong, getUnsignedLong, getUnsignedShort, getUnsignedShort, hashCode, isUnknown, length, length, lengthOf, reverseBytes, setByte, setByte, setByte, setByte, setBytes, setBytes, setBytes, setDouble, setDouble, setDouble, setDouble, setFloat, setFloat, setFloat, setFloat, setInt64, setInt64, setInt64, setInt64, setLength, setLength, setLong, setLong, setLong, setLong, setShort, setShort, setShort, setShort, setString, setString, setString, setString, setString, setString, setString, setString, setString, setString, setString, setString, setString, setUnsignedLong, setUnsignedLong, setUnsignedLong, setUnsignedLong, setUnsignedShort, setUnsignedShort, setUnsignedShort, setUnsignedShortassign, assign, calcFormatLength, createProxy, createProxy, deepCopy, elementsOfType, equals, fallback, formatLength, fromTypeName, generateDefault, generateUnknown, getAssigner, getSize, getTypeName, incompatibleTypesOnConversion, initialize, initializeDefaultExtent, instantiateDefaultExtent, invalidInitializer, isAllKnown, isAllKnown, isAssignDirect, isProxy, isUnknownValue, maximum, minimum, notUnknownValue, sameType, val, variablechanged, checkUndoable, checkUndoable, checkUndoable, getTransLevel, isGlobal, isUndoable, markUndoable, popBlock, rollback, setGlobalpublic static final int MAX_SIZE
private byte[] value
unknown.public raw()
public raw(BaseDataType value)
assign(BaseDataType)).value - The value to be used for this instance.public raw(raw value)
If the parameter's represents unknown, this instance will also represent
unknown.
value - The value to be used for this instance.public raw(byte[] val)
val - The binary data to be used as the contents or if null then the
instance will represent unknown.public raw(java.lang.String value)
02 and the following 4 hexadecimal
characters are a hexadecimal representation of the length of the
resulting value. These 6 preceding bytes are simply dropped.value - The Base64 value to be converted into the resulting
instance binary data.public raw(character value)
02 and the following 4 hexadecimal
characters are a hexadecimal representation of the length of the
resulting value. These 6 preceding bytes are simply dropped.value - The Base64 value to be converted into the resulting instance binary data. If this
is the unknown, then the result is the unknown.public int compareTo(java.lang.Object obj)
Comparable interface.
The algorithm will fail to give meaningful results in the case where one tries to sort against other objects that do not represent compatible values.
compareTo in interface java.lang.ComparablecompareTo in class BinaryDataobj - The instance to compare against.obj.public static raw instantiateUnknownRaw()
unknown.unknown.public BaseDataType.Type getType()
getType in class BaseDataTypepublic raw duplicate()
Object.clone() method but returns an instance of
BaseDataType and doesn't throw the CloneNotSupportedException.duplicate in class BaseDataTypepublic BaseDataType instantiateUnknown()
unknown.instantiateUnknown in class BaseDataTypeunknown.public BaseDataType instantiateDefault()
instantiateDefault in class BaseDataTypepublic boolean isUninitialized()
unknown is also different from being uninitialized.isUninitialized in class BinaryDatatrue if this instance is uninitialized.public java.lang.String toString()
toStringExport(). If the instance represents unknown, a
'?' will be returned.toString in class java.lang.Objectpublic java.lang.String toString(java.lang.String fmt)
null format string is equivalent to the result of toStringExport().
If the instance is unknown, a '?' will be returned.toString in class BaseDataTypefmt - The format string to use.public java.lang.String toStringMessage()
MESSAGE language statement. If the instance represents unknown, a
'?' will be returned.toStringMessage in class BaseDataTypepublic java.lang.String toStringExport()
raw data in Progress, but
it may be different when records or other structured data is written)
and this is followed by 4 bytes specifying the length of the data.
If the instance represents unknown, a '?' will be returned.
toStringExport in class BaseDataTypepublic BinaryData setLength(long len)
setLength in class BinaryDatalen - New length of the array.public void readExternal(java.io.ObjectInput in)
throws java.io.IOException,
java.lang.ClassNotFoundException
readExternal in interface java.io.ExternalizablereadExternal in class BinaryDatain - The input source from which fields will be restored.java.io.IOException - In case of I/O errors.java.lang.ClassNotFoundException - If payload can't be instantiated.public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
writeExternal in interface java.io.ExternalizablewriteExternal in class BinaryDataout - The output destination to which fields will be saved.java.io.IOException - In case of I/O errors.public void setUnknown()
unknown flag to true.
Warning: the data stored in this instance WILL BE deallocated after calling this method.
setUnknown in class BinaryDataprotected void clearUnknown()
unknown flag to false.clearUnknown in class BinaryDataprotected void deallocate()
deallocate in class BinaryDataprotected boolean isLengthLimited()
isLengthLimited in class BinaryDatatrue if the length must be limited.protected long lengthLimit()
lengthLimit in class BinaryDataprotected boolean isAutoExtend()
null bytes.isAutoExtend in class BinaryDatatrue if the length must automatically extended.protected void replaceContents(byte[] value)
The BinaryData.unknown flag is also cleared, only if value is not
null and if the length is greater than 0.
replaceContents in class BinaryDatavalue - The new contents.protected byte[] asByteArray()
asByteArray in class BinaryDataunknown
or has an undefined size, then null will be returned.protected long visibleLength()
visibleLength in class BinaryDataprotected long internalLength()
internalLength in class BinaryDataprotected long findNextNull(long pos)
null byte,
starting at a given index position.findNextNull in class BinaryDatapos - The 0-based index into the array at which to start searching.null byte or the length
of the array if no null byte exists.protected void extendBytes(long len)
This is safe to use on 0 length arrays.
If the instance is unknown, this silently returns without making any changes.
extendBytes in class BinaryDatalen - The output array length. Negative values are silently ignored. Positive values
up to MAX_SIZE are accepted. Values greater than
MAX_SIZE will cause an error condition to be raised.protected byte readByte(long pos)
readByte in class BinaryDatapos - The 0-based index position at which to read the byte.protected void writeByte(byte val,
long pos)
writeByte in class BinaryDataval - The byte to write.pos - The 0-based index position at which to read the byte.protected byte[] readByteRange(long pos,
long len,
boolean endian)
readByteRange in class BinaryDatapos - The 0-based index position at which to read the bytes.len - The number of bytes to read.endian - true to force the returned data to be interpreted by the endian-ness
of the native platform. The returned data will be in little endian order if this
flag is set (but on a big endian platform the bytes will be reversed first).protected void writeByteRange(byte[] data,
long pos,
long len,
boolean endian)
writeByteRange in class BinaryDatadata - The bytes to write.pos - The 0-based index position at which to start writing the bytes.len - How many bytes should be written. -1 means write everything to the end of the
array.endian - true to honor the endian-ness of the platform. The data
array MUST be ordered in little-endian order if the endian flag is on.protected boolean isIncompatibleTypesOnConversion(BaseDataType value)
BaseDataTypeisIncompatibleTypesOnConversion in class BaseDataTypepublic void assign(BaseDataType data)
BinaryData
If the value is of type BinaryData, the result will be the same as calling
BinaryData.assign(BaseDataType). If the type is the unknown literal the instance will be
set to unknown value.
If the value is not of type BinaryData an error condition will be thrown
because the 4GL does not support automatic type conversion for other BDT's
(even character and longchar are not accepted).
This variant is meant to handle the cases of built-in functions and methods in the 4GL which have polymorphic return types (e.g. DYNAMIC-FUNCTION()). This should NOT be used for non-polymorphic assignments.
assign in class BinaryDatadata - The instance from which to copy state.