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.RangeCheck
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.
|
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.
|
BaseDataType |
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 |
instantiateUnknown()
Creates a new instance of the same type that represents
unknown . |
static BaseDataType |
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 |
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,
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, assign, defaultFormatString, genLimitedLengthError, 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, setDouble, setDouble, setDouble, setDouble, setFloat, setFloat, setFloat, setFloat, setInt64, setInt64, setInt64, setInt64, setLength, setLong, setLong, setLong, setLong, setShort, setShort, setShort, setShort, setString, setString, setString, setString, setString, setString, setString, setString, setString, setString, setString, setString, setUnsignedLong, setUnsignedLong, setUnsignedLong, setUnsignedLong, setUnsignedShort, setUnsignedShort, setUnsignedShort, setUnsignedShort
calcFormatLength, deepCopy, elementsOfType, equals, formatLength, generateDefault, generateUnknown, getTypeName, incompatibleTypesOnConversion, initializeDefaultExtent, instantiateDefault, instantiateDefaultExtent, isUnknownValue, maximum, minimum, notUnknownValue, sameType
changed, checkUndoable, checkUndoable, checkUndoable, getTransLevel, isGlobal, isUndoable, markUndoable, popBlock, rollback, setGlobal
public static final int MAX_SIZE
private byte[] value
unknown
.public raw()
public raw(BaseDataType value)
BinaryData.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.Comparable
compareTo
in class BinaryData
obj
- The instance to compare against.obj
.public static BaseDataType instantiateUnknownRaw()
unknown
.unknown
.public BaseDataType duplicate()
Object.clone()
method but returns an instance of
BaseDataType
and doesn't throw the CloneNotSupportedException
.duplicate
in class BaseDataType
public BaseDataType instantiateUnknown()
unknown
.instantiateUnknown
in class BaseDataType
unknown
.public boolean isUninitialized()
unknown
is also different from being uninitialized.isUninitialized
in class BinaryData
true
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.Object
public 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 BaseDataType
fmt
- 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 BaseDataType
public 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 BaseDataType
public BinaryData setLength(long len)
setLength
in class BinaryData
len
- New length of the array.public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
readExternal
in class BinaryData
in
- 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.Externalizable
writeExternal
in class BinaryData
out
- 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 BinaryData
protected void clearUnknown()
unknown
flag to false
.clearUnknown
in class BinaryData
protected void deallocate()
deallocate
in class BinaryData
protected boolean isLengthLimited()
isLengthLimited
in class BinaryData
true
if the length must be limited.protected long lengthLimit()
lengthLimit
in class BinaryData
protected boolean isAutoExtend()
null
bytes.isAutoExtend
in class BinaryData
true
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 BinaryData
value
- The new contents.protected byte[] asByteArray()
asByteArray
in class BinaryData
unknown
or has an undefined size, then null
will be returned.protected long visibleLength()
visibleLength
in class BinaryData
protected long internalLength()
internalLength
in class BinaryData
protected long findNextNull(long pos)
null
byte,
starting at a given index position.findNextNull
in class BinaryData
pos
- 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 BinaryData
len
- 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 BinaryData
pos
- The 0-based index position at which to read the byte.protected void writeByte(byte val, long pos)
writeByte
in class BinaryData
val
- 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 BinaryData
pos
- 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, boolean endian)
writeByteRange
in class BinaryData
data
- The bytes to write.pos
- The 0-based index position at which to start writing the bytes.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.