Class DataBuffer
java.lang.Object
org.applecommander.util.DataBuffer
A DataBuffer is a bunch of bytes with Apple II knowledge.
This shares the technical details as well as the actual image data
across all components in the application.
There are two sets of accessors:
get/putaccess the buffer via an index (explicit positioning); andread/writethat navigate via position. Note that read and write can overrun the buffer and generate an error.
Creational patterns are via the wrap methods for existing data
or via the create method.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]asBytes()A utility method to pull the buffer as bytes.static DataBuffercreate(int size) booleanvoidfill(int value) voidget(int position, byte[] data) getFixedLengthString(int index, int length) intgetInt(int index) intgetIntBE(int index) getPascalDate(int offset) Extract a Pascal date.getPascalString(int index) getProdosDate(int offset) Decode a ProDOS formatted date.intgetSignedShort(int index) intgetUnsignedByte(int index) intgetUnsignedShort(int index) intgetUnsignedShort3(int index) Retrieve a 3 byte number (as in ProDOS EOF values).intgetUnsignedShortBE(int index) booleanbooleanisBitSet(int index, int bit) Determine if a specific bit is set.intlimit()voidlimit(int newLimit) booleanmatches(int offset, byte... data) booleanmatches(IntPredicate predicate) Test the entire `ByteBuffer` against the condition.intposition()voidposition(int n) voidput(int offset, DataBuffer data) voidputByte(int offset, int value) voidputBytes(int offset, int... values) voidputFixedLengthString(int index, int length, String value, boolean setHighBit) voidputPascalDate(int offset, Date date) Set a Pascal date.voidputPascalString(int index, int maxLength, String value, boolean setHighBit) voidputShort(int offset, short value) voidputUnsignedShort(int offset, int value) voidread(byte[] data) readBuffer(int length) readFixedLengthString(int length) intreadInt()intRead an int but in big endian format.readPascalString(int maxLength) intintintRead an short but in big endian format.static DataBufferresize(DataBuffer source, int newSize) scan(byte[] marker, int start) Search a sequence of bytes and locate the starting position of a search sequence.scan(byte[] marker, int mask, int start) Search a sequence of bytes and locate the starting position of a search sequence masking both the marker and the buffer.slice(int offset, int length) booleantestForFixedLengthString(int index, int length) booleantestUnsignedByte(int index, int... expecteds) static DataBufferwrap(byte[] data) static DataBufferwrap(byte[] data, int offset, int length) static DataBufferwrap(int... bytes) voidwriteByte(int value) voidwriteFixedLengthString(String value, int length) voidwriteInt(int value) voidwriteIntBE(int value) voidwriteShort(int value)
-
Method Details
-
wrap
-
wrap
-
wrap
-
create
-
resize
-
slice
-
limit
public int limit() -
limit
public void limit(int newLimit) -
matches
public boolean matches(int offset, byte... data) -
equals
-
asBytes
public byte[] asBytes()A utility method to pull the buffer as bytes. -
fill
public void fill(int value) -
matches
Test the entire `ByteBuffer` against the condition. This can be useful in pulling out a specific slice of data and checking the contents. -
scan
-
scan
-
testUnsignedByte
public boolean testUnsignedByte(int index, int... expecteds) -
testForFixedLengthString
public boolean testForFixedLengthString(int index, int length) -
getUnsignedByte
public int getUnsignedByte(int index) -
getSignedShort
public int getSignedShort(int index) -
getUnsignedShort
public int getUnsignedShort(int index) -
getUnsignedShort3
public int getUnsignedShort3(int index) Retrieve a 3 byte number (as in ProDOS EOF values). Bytes are little endian. -
getUnsignedShortBE
public int getUnsignedShortBE(int index) -
getInt
public int getInt(int index) -
getIntBE
public int getIntBE(int index) -
get
public void get(int position, byte[] data) -
getFixedLengthString
-
putFixedLengthString
-
getPascalString
-
putPascalString
-
getPascalDate
Extract a Pascal date. If the date is not set (all zeroes) this returns a
null.Bits Description Range 0..3 Month 1..12 4..8 Day 1..31 9..15 Year 0..99 -
putPascalDate
Set a Pascal date. If a
nulldate is given, sets a value of$0000.Bits Description Range 0..3 Month 1..12 4..8 Day 1..31 9..15 Year 0..99 -
put
-
putByte
public void putByte(int offset, int value) -
putBytes
public void putBytes(int offset, int... values) -
putUnsignedShort
public void putUnsignedShort(int offset, int value) -
putShort
public void putShort(int offset, short value) -
isBitSet
public boolean isBitSet(int index, int bit) Determine if a specific bit is set. -
getProdosDate
Decode a ProDOS formatted date. This can return null if the date is all$0000 0000. -
hasRemaining
public boolean hasRemaining() -
position
public int position() -
position
public void position(int n) -
readUnsignedByte
public int readUnsignedByte() -
readUnsignedShort
public int readUnsignedShort() -
readUnsignedShortBE
public int readUnsignedShortBE()Read an short but in big endian format. Used for marker bytes so they "look" as expected in program code. -
read
public void read(byte[] data) -
readInt
public int readInt() -
readIntBE
public int readIntBE()Read an int but in big endian format. Used for marker bytes so they "look" as expected in program code. -
readBuffer
-
readFixedLengthString
-
readPascalString
-
writeByte
public void writeByte(int value) -
writeShort
public void writeShort(int value) -
writeInt
public void writeInt(int value) -
writeIntBE
public void writeIntBE(int value) -
writeFixedLengthString
-