Class DataBuffer

java.lang.Object
org.applecommander.util.DataBuffer

public class DataBuffer extends Object

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/put access the buffer via an index (explicit positioning); and
  • read/write that 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 Details

    • wrap

      public static DataBuffer wrap(byte[] data)
    • wrap

      public static DataBuffer wrap(byte[] data, int offset, int length)
    • wrap

      public static DataBuffer wrap(int... bytes)
    • create

      public static DataBuffer create(int size)
    • resize

      public static DataBuffer resize(DataBuffer source, int newSize)
    • slice

      public DataBuffer slice(int offset, int length)
    • limit

      public int limit()
    • limit

      public void limit(int newLimit)
    • matches

      public boolean matches(int offset, byte... data)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • asBytes

      public byte[] asBytes()
      A utility method to pull the buffer as bytes.
    • fill

      public void fill(int value)
    • matches

      public boolean matches(IntPredicate predicate)
      Test the entire `ByteBuffer` against the condition. This can be useful in pulling out a specific slice of data and checking the contents.
    • scan

      public Optional<Integer> scan(byte[] marker, int start)
      Search a sequence of bytes and locate the starting position of a search sequence.
    • scan

      public Optional<Integer> 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. This can be used to look for strings that may (or may not) have the high bit on.
    • 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

      public String getFixedLengthString(int index, int length)
    • putFixedLengthString

      public void putFixedLengthString(int index, int length, String value, boolean setHighBit)
    • getPascalString

      public String getPascalString(int index)
    • putPascalString

      public void putPascalString(int index, int maxLength, String value, boolean setHighBit)
    • getPascalDate

      public Date getPascalDate(int offset)

      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

      public void putPascalDate(int offset, Date date)

      Set a Pascal date. If a null date 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

      public void put(int offset, DataBuffer data)
    • 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

      public Date getProdosDate(int offset)
      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

      public DataBuffer readBuffer(int length)
    • readFixedLengthString

      public String readFixedLengthString(int length)
    • readPascalString

      public String readPascalString(int maxLength)
    • 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

      public void writeFixedLengthString(String value, int length)