public class ByteBuilder
extends java.lang.Object
implements java.util.Iterator<java.lang.Object>
StringBuilder
, but for byte[]s
and works in both directions, append(*) for adding to
a buffer and nextbyte*() to retrieve consecutive
pieces of the buffer. suitable for conversion of
wrappered types to/from byte arrays. also can deal
with Elastic PL/I Group objects. it can also be
used as an Iterator, but the native next() only works
if you have used append() to built up the ByteBuilder
wish there was non-abstract Java ByteBuffer that was
simply mapped to byte[]Constructor and Description |
---|
ByteBuilder()
Create an empty ByteBuilder, ready for append()ing
|
ByteBuilder(byte[] buf)
Create a filled ByteBuilder, ready for either appending
or next()ing
|
ByteBuilder(byte[] buf,
int offset,
int length)
Create a filled ByteBuilder, ready for either appending
or next()ing
|
ByteBuilder(int size)
Create an ByteBuilder of a certain size, ready for append()ing
|
ByteBuilder(java.lang.Object buf)
Create a filled ByteBuilder, prefilled with a PL/I var
|
Modifier and Type | Method and Description |
---|---|
void |
append(Area A)
append - add a Area to the end
|
void |
append(Array<?> A)
append - add a Array to the end
|
void |
append(java.math.BigDecimal B)
append - add a BigDecimal to the end
|
void |
append(java.math.BigInteger B)
append - add a BigInteger to the end
|
void |
append(BitN B)
append - add a BitN to the end
|
void |
append(java.lang.Boolean B)
append - add a Boolean to the end
|
void |
append(java.lang.Byte B)
append - add a Byte to the end
|
void |
append(byte[] b)
append - add a byte string to the end
|
void |
append(ByteBuilder b)
append - add a ByteBuilder to this ByteBuilder
|
void |
append(Complex C)
append - add a Complex to the end
|
void |
append(java.lang.Double D)
append - add a Double to the end
|
void |
append(EPLITYPES type,
java.lang.Object O)
append - add an Object (which still must be an
instanceof a wrappered primitive) to the end
|
void |
append(EPLITYPES type,
java.lang.Object O,
short len)
append - add an Object (which still must be an
instanceof a wrappered primitive) to the end.
|
void |
append(FixedBin FB)
append - add a FixedBin to the end
|
void |
append(java.lang.Float F)
append - add a Float to the end
|
void |
append(Group G)
append - add a Elastic PL/I Group to the end
|
void |
append(java.lang.Integer I)
append - add an Integer to the end
|
void |
append(java.lang.Long L)
append - add an Long to the end
|
void |
append(java.lang.Object O)
append - add an Object (which still must be an
instanceof a wrappered primitive) to the end
|
void |
append(java.lang.Object O,
short len)
append - add an Object (which still must be an
instanceof a wrappered primitive) to the end.
|
void |
append(Offset<?> O)
append - add a Offset to the end
|
void |
append(Picture P)
append - add a Picture to the end
|
void |
append(Pointer<?> P)
append - add a Pointer to the end
|
void |
append(java.lang.Short S)
append - add a Short to the end
|
void |
append(java.lang.String S)
append - add a Varying Char String to the end
|
void |
append(java.lang.String FS,
int len)
append - add a Fixed Char String to the end
|
void |
clear()
clear - clear the ByteBuffer of contents
|
byte |
getByte(int offset)
low level individual byte getter
|
int |
getItems()
Get the number of items in this ByteBuilder
|
int |
getSize()
Get the current (used) length of the ByteBuilder byte array buffer
|
boolean |
hasNext()
hasNext() - return whether there are more bytes
to be retrieved from the buffer (when used before
non-anonymous nextInteger(), nextString(len), etc.
|
boolean |
hasNextItem()
hasNextItem() - return whether there are more items
to be retrieved from the buffer (when used before anonymous
"nextItem()" as opposed to "next()")
note: not an Override of Iterator
|
int |
length()
Get the current (used) length of the ByteBuilder byte array buffer
|
static void |
main(java.lang.String[] args)
unit test
Usage: java ByteBuilder INTEGER=22|SHORT=22|STRING=hi|FLOAT=2.3|DOUBLE=2.3|LONG=123 ...
|
java.lang.Object |
next()
next() - don't know what type the next one is,
somewhat useless but required for Iterators
|
Area |
nextArea()
retrieve the Area
|
Array<?> |
nextArray()
retrieve the Array
|
java.math.BigDecimal |
nextBigDecimal()
retrieve the next BigDecimal requiring the next item is a BigDecimal
|
java.math.BigDecimal |
nextBigDecimal(int m,
int scale)
nextBigDecimal - get the next sequence of bytes as an FIXED DEC(n)
given its scale
|
java.lang.Object |
nextBigInteger()
retrieve the next BigInteger
|
java.math.BigInteger |
nextBigInteger(int m)
nextBigInteger - get the next sequence of bytes as an FIXED BIN(n)
where n > 63 and represented as a BigInteger
|
BitN |
nextBitN(int m)
nextBitN - get the next sequence of bytes as an BIT(m)
that corresponds to n bytes in the buffer (n*8=m)
|
java.lang.Boolean |
nextBoolean()
nextBoolean - get the next byte as an Boolean
|
java.lang.Byte |
nextByte()
nextByte - get the byte as an Byte
|
byte[] |
nextBytes(int n)
Return the next sequence of n bytes as byte array
|
Complex |
nextComplex()
nextComplex - get the next sequence of bytes as an Complex
that corresponds to n bytes in the buffer (n*8=m)
|
java.lang.Double |
nextDouble()
nextDouble - get the next sequence of bytes as an Double
|
FixedBin |
nextFixedBin()
retrieve the next FixedBin(p,q)
|
FixedBin |
nextFixedBin(int n)
nextFixedBin - get the next sequence of bytes as a FixedBin
|
FixedBin |
nextFixedBin(int n,
int p,
int q)
nextFixedBin - get the next sequence of bytes as a FixedBin
|
java.lang.Float |
nextFloat()
nextFloat - get the next sequence of bytes as an Float
|
Group |
nextGroup(int n)
nextGroup - get the next sequence of n bytes as a Group
|
java.lang.Integer |
nextInteger()
nextInteger - get the next sequence of bytes as an Integer
|
java.lang.Long |
nextLong()
nextLong - get the next sequence of bytes as an Long
|
Offset<?> |
nextOffset()
retrieve the next Offset
|
Offset<?> |
nextOffset(int n)
cannot return the next sequence of bytes as an Offset>
because we don't know what ? is
|
int |
nextOrdinal()
retrieve the next enum (ordinal)
|
java.lang.Object |
nextPicture(int n)
Return the next sequence of bytes that correspond to
the picture as a Picture, used as a counter to append((Picture) O)
|
java.lang.Object |
nextPicture(java.lang.String pic)
Return the next sequence of bytes that correspond to
the given picture specification as a Picture
|
Pointer<?> |
nextPointer()
retrieve the next Pointer
|
Pointer<?> |
nextPointer(int n)
cannot return the next sequence of bytes as an Pointer>
because we don't know what ? is
|
java.lang.Short |
nextShort()
nextShort - get the next sequence of bytes as an Short
|
java.lang.String |
nextString(int n)
Return the next sequence of n bytes as an String.
|
java.lang.String |
nextString(short n)
Return the next sequence of n bytes as an String.
|
void |
reset()
reset - reset the ByteBuffer allowing it to be read again
|
void |
setByte(byte data,
int offset)
low level individual byte setter
|
byte[] |
toBytes()
Return the ByteBuilder as a byte array
|
java.lang.String |
toDebugString()
Provided as a debugging aid
|
java.lang.String |
toString()
Provided as a debugging aid because
presumably you should be using StringBuilder instead
|
public ByteBuilder()
public ByteBuilder(int size)
public ByteBuilder(byte[] buf)
buf
- - create a ByteBuilder from a byte arraypublic ByteBuilder(byte[] buf, int offset, int length)
buf
- - create a ByteBuilder from a byte arraypublic ByteBuilder(java.lang.Object buf)
buf
- - create a ByteBuilder from a PL/I var (primitive
wrappered object, FixedBin, etcpublic byte[] toBytes()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toDebugString()
public int length()
public int getSize()
public int getItems()
public byte getByte(int offset)
offset
- - the offset of the byte within the buffer to getCondition.CONDITION.ERROR
- (TOOSMALL) if offset out-of-rangepublic void setByte(byte data, int offset)
data
- - the data byte to setoffset
- - the offset of the byte within the buffer to setCondition.CONDITION.ERROR
- (TOOSMALL) if offset out-of-rangepublic void append(ByteBuilder b)
b
- the ByteBuilder to appendpublic void append(byte[] b)
b
- the byte array to appendpublic void append(java.lang.Long L)
L
- the Long to addpublic void append(java.lang.Integer I)
I
- the Integer to addpublic void append(java.lang.Byte B)
B
- the Short to addpublic void append(java.lang.Short S)
S
- the Short to addpublic void append(java.lang.String S)
S
- the String to addpublic void append(java.lang.String FS, int len)
FS
- the String to addpublic void append(java.lang.Float F)
F
- the Float to addpublic void append(java.lang.Double D)
D
- the Double to addpublic void append(Group G)
G
- the Group to addpublic void append(java.math.BigDecimal B)
B
- the BigDecimal to addpublic void append(java.math.BigInteger B)
B
- the BigInteger to addpublic void append(java.lang.Boolean B)
B
- the Boolean to addpublic void append(BitN B)
B
- the BitN to addpublic void append(FixedBin FB)
FB
- the FixedBin to addpublic void append(Array<?> A)
A
- the Array to addpublic void append(Area A)
A
- the Area to addpublic void append(Offset<?> O)
O
- the Offset to addpublic void append(Pointer<?> P)
P
- the Pointer to addpublic void append(Complex C)
C
- the Complex to addpublic void append(Picture P)
P
- the Picture to addpublic void append(java.lang.Object O)
O
- the Object to addpublic void append(EPLITYPES type, java.lang.Object O)
type
- - EPLITYPES typeO
- the Object to addpublic void append(java.lang.Object O, short len)
append(Object)
for all Objects
other than String. For String, use the len parameter to
pad or trim the String to a particular lenbufferO
- the Object to addlen
- the lenbuffer to pad or trim a String objectpublic void append(EPLITYPES type, java.lang.Object O, short len)
append(Object)
for all Objects
other than String. For String, use the len parameter to
pad or trim the String to a particular lenbuffertype
- - EPLITYPES typeO
- the Object to addlen
- the lenbuffer to pad or trim a String objectpublic void clear()
public void reset()
public java.lang.Boolean nextBoolean()
public java.lang.Byte nextByte()
public java.lang.Short nextShort()
public java.lang.Integer nextInteger()
public java.lang.Long nextLong()
public java.lang.Float nextFloat()
public java.lang.Double nextDouble()
public FixedBin nextFixedBin(int n)
n
- - the number of bytes to convertpublic FixedBin nextFixedBin(int n, int p, int q)
n
- - the number of bytes to convertp
- - the number of digits of precisionq
- - the number of digits of scalepublic java.lang.String nextString(short n)
n
- - the number of nextbyte bytes to consider as a stringpublic java.lang.String nextString(int n)
n
- - the number of nextbyte bytes to consider as a stringpublic java.lang.Object nextPicture(java.lang.String pic)
pic
- - the picture specificationpublic java.lang.Object nextPicture(int n)
n
- - the length of the picture in bytespublic BitN nextBitN(int m)
public java.math.BigInteger nextBigInteger(int m)
public java.math.BigDecimal nextBigDecimal(int m, int scale)
m
- - number of bytes comprising the unscaled (BigInteger) value in the bytebufferscale
- - integer scale amountpublic Complex nextComplex()
public Offset<?> nextOffset(int n)
public Pointer<?> nextPointer(int n)
public byte[] nextBytes(int n)
n
- - the number of nextbyte bytes to consider as a sub-byte arraypublic int nextOrdinal()
public FixedBin nextFixedBin()
public Offset<?> nextOffset()
public Pointer<?> nextPointer()
public Area nextArea()
public Array<?> nextArray()
public java.math.BigDecimal nextBigDecimal()
public java.lang.Object nextBigInteger()
public Group nextGroup(int n)
n
- - the number of nextbyte bytes to consider as a Grouppublic boolean hasNext()
hasNext
in interface java.util.Iterator<java.lang.Object>
public boolean hasNextItem()
public java.lang.Object next()
next
in interface java.util.Iterator<java.lang.Object>
public static void main(java.lang.String[] args)