Class AbstractCartridge

java.lang.Object
me.hugmanrique.cartage.AbstractCartridge
All Implemented Interfaces:
AutoCloseable, Cartridge

public abstract class AbstractCartridge extends Object implements Cartridge
Skeleton Cartridge implementation.
  • Constructor Details

  • Method Details

    • order

      public ByteOrder order()
      Description copied from interface: Cartridge
      Returns the cartridge's byte order.
      Specified by:
      order in interface Cartridge
      Returns:
      the current byte order
    • order

      public void order(ByteOrder order)
      Description copied from interface: Cartridge
      Sets the cartridge's byte order.
      Specified by:
      order in interface Cartridge
      Parameters:
      order - the new byte order
    • offset

      public long offset()
      Description copied from interface: Cartridge
      Returns the cartridge's offset.
      Specified by:
      offset in interface Cartridge
      Returns:
      the current offset, in bytes
    • setOffset

      public void setOffset(long offset)
      Description copied from interface: Cartridge
      Sets the cartridge's offset.
      Specified by:
      setOffset in interface Cartridge
      Parameters:
      offset - the new offset, in bytes
    • size

      public long size()
      Description copied from interface: Cartridge
      Returns the size of the cartridge.
      Specified by:
      size in interface Cartridge
      Returns:
      the cartridge size, in bytes
    • remaining

      public long remaining()
      Description copied from interface: Cartridge
      Returns the number of bytes between the current offset and the end of the cartridge.
      Specified by:
      remaining in interface Cartridge
      Returns:
      the number of remaining bytes
    • hasRemaining

      public boolean hasRemaining()
      Description copied from interface: Cartridge
      Returns whether there exist any bytes between the current offset and the end of the cartridge.
      Specified by:
      hasRemaining in interface Cartridge
      Returns:
      true if and only if Cartridge.remaining() equals 0
    • skip

      public void skip(long count)
      Description copied from interface: Cartridge
      Increases the cartridge's offset.
      Specified by:
      skip in interface Cartridge
      Parameters:
      count - the number of bytes to skip
    • close

      public void close()
      Description copied from interface: Cartridge
      Closes the cartridge. Once closed, any subsequent operation on the cartridge will fail with IllegalStateException.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Cartridge
    • readByte

      public byte readByte()
    • getByte

      public byte getByte(long offset)
    • readUnsignedByte

      public int readUnsignedByte()
    • getUnsignedByte

      public int getUnsignedByte(long offset)
    • writeByte

      public void writeByte(byte value)
    • setByte

      public void setByte(long offset, byte value)
    • writeUnsignedByte

      public void writeUnsignedByte(int value)
    • setUnsignedByte

      public void setUnsignedByte(long offset, int value)
    • readShort

      public short readShort()
    • getShort

      public short getShort(long offset)
    • readUnsignedShort

      public int readUnsignedShort()
    • getUnsignedShort

      public int getUnsignedShort(long offset)
    • writeShort

      public void writeShort(short value)
    • setShort

      public void setShort(long offset, short value)
    • writeUnsignedShort

      public void writeUnsignedShort(int value)
    • setUnsignedShort

      public void setUnsignedShort(long offset, int value)
    • readInt

      public int readInt()
    • getInt

      public int getInt(long offset)
    • readUnsignedInt

      public long readUnsignedInt()
    • getUnsignedInt

      public long getUnsignedInt(long offset)
    • writeInt

      public void writeInt(int value)
    • setInt

      public void setInt(long offset, int value)
    • writeUnsignedInt

      public void writeUnsignedInt(long value)
    • setUnsignedInt

      public void setUnsignedInt(long offset, long value)
    • readLong

      public long readLong()
    • getLong

      public long getLong(long offset)
    • writeLong

      public void writeLong(long value)
    • setLong

      public void setLong(long offset, long value)
    • readBytes

      public void readBytes(byte[] dest)
    • readBytes

      public void readBytes(byte[] destArray, int destOffset, int length)
    • getBytes

      public void getBytes(long offset, byte[] dest)
    • getBytes

      public void getBytes(long offset, byte[] destArray, int destOffset, int length)
    • writeBytes

      public void writeBytes(byte[] source)
    • writeBytes

      public void writeBytes(byte[] source, int sourceOffset, int length)
    • setBytes

      public void setBytes(long offset, byte[] source)
    • setBytes

      public void setBytes(long offset, byte[] sourceArray, int sourceOffset, int length)
    • readString

      public String readString(int length, Charset charset)
    • getString

      public String getString(long offset, int length, Charset charset)
    • readAscii

      public String readAscii(int length)
    • getAscii

      public String getAscii(long offset, int length)
    • readUtf8

      public String readUtf8(int length)
    • getUtf8

      public String getUtf8(long offset, int length)
    • writeString

      public int writeString(CharSequence sequence, Charset charset)
    • setString

      public int setString(long offset, CharSequence sequence, Charset charset)
    • writeAscii

      public int writeAscii(CharSequence sequence)
    • setAscii

      public int setAscii(long offset, CharSequence sequence)
    • writeUtf8

      public int writeUtf8(CharSequence sequence)
    • setUtf8

      public int setUtf8(long offset, CharSequence sequence)
    • copyFrom

      public void copyFrom(MemorySegment source)
      Description copied from interface: Cartridge
      Copies the contents from the given segment to this cartridge. More specifically, the bytes at offset 0 through cartridge.size() - 1 in the source segment are copied into this cartridge at offset 0 through cartridge.size() - 1.
      Specified by:
      copyFrom in interface Cartridge
      Parameters:
      source - the source segment
    • copyTo

      public void copyTo(MemorySegment dest)
      Description copied from interface: Cartridge
      Copies the cartridge contents to the given segment. More specifically, the bytes at offset 0 through dest.byteSize() - 1 in the cartridge are copied into the given segment at offset 0 through dest.byteSize() - 1.
      Specified by:
      copyTo in interface Cartridge
      Parameters:
      dest - the destination segment
    • copyTo

      public void copyTo(Path path) throws IOException
      Description copied from interface: Cartridge
      Copies the cartridge contents to the given path.
      Specified by:
      copyTo in interface Cartridge
      Parameters:
      path - the destination path
      Throws:
      IOException - if an I/O error occurs
    • copyTo

      public void copyTo(OutputStream stream) throws IOException
      Description copied from interface: Cartridge
      Copies the cartridge contents to the given stream. The stream is not closed.
      Specified by:
      copyTo in interface Cartridge
      Parameters:
      stream - the output stream
      Throws:
      IOException - if an I/O error occurs
    • toString

      public String toString()
      Overrides:
      toString in class Object