- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
GBACartridge,GBCartridge
- All Known Implementing Classes:
AbstractCartridge
Represents the contents of a cartridge as a byte buffer.
The cartridge has a certain size, and an offset position for accessing data. The size is non-negative and immutable. The offset is the zero-based index of the next element to be read or written.
Cartridges are closed explicitly (see close()). When a cartridge is closed,
the underlying resources associated with said cartridge might be deallocated, and subsequent
operation on the cartridge will fail with IllegalStateException.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the cartridge.voidcopyFrom(MemorySegment source)Copies the contents from the given segment to this cartridge.voidcopyTo(OutputStream stream)Copies the cartridge contents to the given stream.voidCopies the cartridge contents to the given path.voidcopyTo(MemorySegment dest)Copies the cartridge contents to the given segment.getAscii(long offset, int length)Decodeslengthbytes to characters using theStandardCharsets.US_ASCIIcharset, beginning at the given offset in the cartridge.bytegetByte(long offset)Reads the byte at the given offset.voidgetBytes(long offset, byte[] dest)Transfers bytes from the cartridge into the given array, beginning at the given offset in the cartridge.voidgetBytes(long offset, byte[] dest, int destOffset, int length)Transferslengthbytes from the cartridge into the given array, beginning at the given offset in the cartridge and at the given offset in the array.intgetInt(long offset)Reads the int at the given offset.longgetLong(long offset)Reads the long at the given offset.shortgetShort(long offset)Reads the short at the given offset.Decodeslengthbytes to characters using the given charset, beginning at the given offset in the cartridge.intgetUnsignedByte(long offset)Reads the unsigned byte at the given offset.longgetUnsignedInt(long offset)Reads the unsigned int at the given offset.intgetUnsignedShort(long offset)Reads the unsigned short at the given offset.getUtf8(long offset, int length)Decodeslengthbytes to characters using theStandardCharsets.UTF_8charset, beginning at the given offset in the cartridge.booleanReturns whether there exist any bytes between the current offset and the end of the cartridge.longoffset()Returns the cartridge's offset.order()Returns the cartridge's byte order.voidSets the cartridge's byte order.readAscii(int length)Decodeslengthbytes to characters using theStandardCharsets.US_ASCIIcharset, beginning at the cartridge's current offset, which is then incremented bylength.bytereadByte()Reads the byte at the cartridge's current offset, and then increments the offset.voidreadBytes(byte[] dest)Transfers bytes from the cartridge into the given array, beginning at the cartridge's current offset, which is then incremented bydest.length.voidreadBytes(byte[] dest, int destOffset, int length)Transferslengthbytes from the cartridge into the given array, beginning at the cartridge's current offset and at the given offset in the array.intreadInt()Reads the int at the cartridge's current offset, and then increments the offset byInteger.BYTES.longreadLong()Reads the long at the cartridge's current offset, and then increments the offset byLong.BYTES.shortReads the short at the cartridge's current offset, and then increments the offset byShort.BYTES.readString(int length, Charset charset)Decodeslengthbytes to characters using the given charset, beginning at the cartridge's current offset, which is then incremented bylength.intReads the unsigned byte at the cartridge's current offset, and then increments the offset.longReads the unsigned int at the cartridge's current offset, and then increments the offset byInteger.BYTES.intReads the unsigned short at the cartridge's current offset, and then increments the offset byShort.BYTES.readUtf8(int length)Decodeslengthbytes to characters using theStandardCharsets.UTF_8charset, beginning at the cartridge's current offset, which is then incremented bylength.longReturns the number of bytes between the current offset and the end of the cartridge.intsetAscii(long offset, CharSequence sequence)Writes the encoded characters using theStandardCharsets.US_ASCIIcharset, beginning at the given offset in the cartridge.voidsetByte(long offset, byte value)Writes the given byte at the given offset.voidsetBytes(long offset, byte[] source)Transfers bytes from the given array into the cartridge, beginning at the given offset in the cartridge.voidsetBytes(long offset, byte[] source, int sourceOffset, int length)Transferslengthbytes from the given array into the cartridge, beginning at the given offset in the cartridge and at the given offset in the array.voidsetInt(long offset, int value)Writes the given int at the given offset.voidsetLong(long offset, long value)Writes the given long at the given offset.voidsetOffset(long offset)Sets the cartridge's offset.voidsetShort(long offset, short value)Writes the given short at the given offset.intsetString(long offset, CharSequence sequence, Charset charset)Writes the encoded characters using the given charset, beginning at the given offset in the cartridge.voidsetUnsignedByte(long offset, int value)Writes the given unsigned byte at the given offset.voidsetUnsignedInt(long offset, long value)Writes the given unsigned int at the given offset.voidsetUnsignedShort(long offset, int value)Writes the given unsigned short at the given offset.intsetUtf8(long offset, CharSequence sequence)Writes the encoded characters using theStandardCharsets.UTF_8charset, beginning at the given offset in the cartridge.longsize()Returns the size of the cartridge.voidskip(long count)Increases the cartridge's offset.intwriteAscii(CharSequence sequence)Writes the encoded characters using theStandardCharsets.US_ASCIIcharset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.voidwriteByte(byte value)Writes the given byte at the cartridge's current offset, and then increments the offset.voidwriteBytes(byte[] source)Transfers the entire content of the given array into the cartridge, beginning at the cartridge's current offset, which is then incremented bysource.length.voidwriteBytes(byte[] source, int sourceOffset, int length)Transferslengthbytes from the given array into the cartridge, beginning at the cartridge's current offset and at the given offset in the array.voidwriteInt(int value)Writes the given int at the cartridge's current offset, and then increments the offset byInteger.BYTES.voidwriteLong(long value)Writes the given long at the cartridge's current offset, and then increments the offset byLong.BYTES.voidwriteShort(short value)Writes the given short at the cartridge's current offset, and then increments the offset byShort.BYTES.intwriteString(CharSequence sequence, Charset charset)Writes the encoded characters using the given charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.voidwriteUnsignedByte(int value)Writes the given unsigned byte at the cartridge's current offset, and then increments the offset.voidwriteUnsignedInt(long value)Writes the given unsigned int at the cartridge's current offset, and then increments the offset byInteger.BYTES.voidwriteUnsignedShort(int value)Writes the given unsigned short at the cartridge's current offset, and then increments the offset byShort.BYTES.intwriteUtf8(CharSequence sequence)Writes the encoded characters using theStandardCharsets.UTF_8charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.
-
Method Details
-
order
ByteOrder order()Returns the cartridge's byte order.- Returns:
- the current byte order
- Throws:
IllegalStateException- if the cartridge is closed
-
order
Sets the cartridge's byte order.- Parameters:
order- the new byte order- Throws:
IllegalStateException- if the cartridge is closed
-
offset
long offset()Returns the cartridge's offset.- Returns:
- the current offset, in bytes
- Throws:
IllegalStateException- if the cartridge is closed
-
setOffset
void setOffset(long offset)Sets the cartridge's offset.- Parameters:
offset- the new offset, in bytes- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater thansize()IllegalStateException- if the cartridge is closed
-
size
long size()Returns the size of the cartridge.- Returns:
- the cartridge size, in bytes
- Throws:
IllegalStateException- if the cartridge is closed
-
remaining
long remaining()Returns the number of bytes between the current offset and the end of the cartridge.- Returns:
- the number of remaining bytes
- Throws:
IllegalStateException- if the cartridge is closed
-
hasRemaining
boolean hasRemaining()Returns whether there exist any bytes between the current offset and the end of the cartridge.- Returns:
trueif and only ifremaining()equals 0- Throws:
IllegalStateException- if the cartridge is closed
-
skip
void skip(long count)Increases the cartridge's offset.- Parameters:
count- the number of bytes to skip- Throws:
IndexOutOfBoundsException- if the given count is less than 0 or greater thanremaining()IllegalStateException- if the cartridge is closed
-
close
void close()Closes the cartridge. Once closed, any subsequent operation on the cartridge will fail withIllegalStateException.- Specified by:
closein interfaceAutoCloseable- Throws:
IllegalStateException- if the cartridge is closed
-
copyFrom
Copies the contents from the given segment to this cartridge. More specifically, the bytes at offset0throughcartridge.size() - 1in the source segment are copied into this cartridge at offset0throughcartridge.size() - 1.- Parameters:
source- the source segment- Throws:
IndexOutOfBoundsException- ifsource.byteSize() > this.size()IllegalStateException- if either the source segment or the cartridge are closed
-
copyTo
Copies the cartridge contents to the given segment. More specifically, the bytes at offset0throughdest.byteSize() - 1in the cartridge are copied into the given segment at offset0throughdest.byteSize() - 1.- Parameters:
dest- the destination segment- Throws:
IndexOutOfBoundsException- ifthis.size() > dest.byteSize()IllegalStateException- if either the destination segment or the cartridge are closed
-
copyTo
Copies the cartridge contents to the given path.- Parameters:
path- the destination path- Throws:
IOException- if an I/O error occursIllegalStateException- if the cartridge is closed
-
copyTo
Copies the cartridge contents to the given stream. The stream is not closed.- Parameters:
stream- the output stream- Throws:
UnsupportedOperationException- if this cartridge's contents cannot be copied into abyte[]instance, e.g. its size is greater thanInteger.MAX_VALUEIOException- if an I/O error occursIllegalStateException- if the cartridge is closed
-
readByte
byte readByte()Reads the byte at the cartridge's current offset, and then increments the offset.- Returns:
- the byte value at the current offset
- Throws:
IndexOutOfBoundsException- ifremaining()is 0
-
getByte
byte getByte(long offset)Reads the byte at the given offset.- Parameters:
offset- the offset to read from- Returns:
- the byte value at the given offset
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than or equal tosize()
-
readUnsignedByte
int readUnsignedByte()Reads the unsigned byte at the cartridge's current offset, and then increments the offset.- Returns:
- the unsigned byte value at the current offset
- Throws:
IndexOutOfBoundsException- ifremaining()is 0
-
getUnsignedByte
int getUnsignedByte(long offset)Reads the unsigned byte at the given offset.- Parameters:
offset- the offset to read from- Returns:
- the unsigned byte value at the given offset
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than or equal tosize()
-
writeByte
void writeByte(byte value)Writes the given byte at the cartridge's current offset, and then increments the offset.- Parameters:
value- the byte value to write- Throws:
IndexOutOfBoundsException- ifremaining()is 0
-
setByte
void setByte(long offset, byte value)Writes the given byte at the given offset.- Parameters:
offset- the offset to write tovalue- the byte value to write- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than or equal tosize()
-
writeUnsignedByte
void writeUnsignedByte(int value)Writes the given unsigned byte at the cartridge's current offset, and then increments the offset.- Parameters:
value- the unsigned byte value to write- Throws:
IndexOutOfBoundsException- ifremaining()is 0
-
setUnsignedByte
void setUnsignedByte(long offset, int value)Writes the given unsigned byte at the given offset.- Parameters:
offset- the offset to write tovalue- the byte value to write- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than or equal tosize()
-
readShort
short readShort()Reads the short at the cartridge's current offset, and then increments the offset byShort.BYTES.- Returns:
- the short value at the current offset
- Throws:
IndexOutOfBoundsException- ifremaining()is less thanShort.BYTES.
-
getShort
short getShort(long offset)Reads the short at the given offset.- Parameters:
offset- the offset to read from- Returns:
- the short value at the given offset
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Short#BYTES})
-
readUnsignedShort
int readUnsignedShort()Reads the unsigned short at the cartridge's current offset, and then increments the offset byShort.BYTES.- Returns:
- the unsigned short value at the current offset
- Throws:
IndexOutOfBoundsException- ifremaining()is less thanShort.BYTES.
-
getUnsignedShort
int getUnsignedShort(long offset)Reads the unsigned short at the given offset.- Parameters:
offset- the offset to read from- Returns:
- the unsigned short value at the given offset
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than{@link Cartridge#size()} - {@link Short#BYTES}
-
writeShort
void writeShort(short value)Writes the given short at the cartridge's current offset, and then increments the offset byShort.BYTES.- Parameters:
value- the short value to write- Throws:
IndexOutOfBoundsException- ifremaining()is less thanShort.BYTES
-
setShort
void setShort(long offset, short value)Writes the given short at the given offset.- Parameters:
offset- the offset to write tovalue- the short value to write- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Short#BYTES})
-
writeUnsignedShort
void writeUnsignedShort(int value)Writes the given unsigned short at the cartridge's current offset, and then increments the offset byShort.BYTES.- Parameters:
value- the unsigned short value to write- Throws:
IndexOutOfBoundsException- ifremaining()is less thanShort.BYTES
-
setUnsignedShort
void setUnsignedShort(long offset, int value)Writes the given unsigned short at the given offset.- Parameters:
offset- the offset to write tovalue- the unsigned short value to write- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Short#BYTES})
-
readInt
int readInt()Reads the int at the cartridge's current offset, and then increments the offset byInteger.BYTES.- Returns:
- the int value at the current offset
- Throws:
IndexOutOfBoundsException- ifremaining()is less thanInteger.BYTES.
-
getInt
int getInt(long offset)Reads the int at the given offset.- Parameters:
offset- the offset to read from- Returns:
- the int value at the given offset
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Integer#BYTES})
-
readUnsignedInt
long readUnsignedInt()Reads the unsigned int at the cartridge's current offset, and then increments the offset byInteger.BYTES.- Returns:
- the unsigned int value at the current offset
- Throws:
IndexOutOfBoundsException- ifremaining()is less thanInteger.BYTES.
-
getUnsignedInt
long getUnsignedInt(long offset)Reads the unsigned int at the given offset.- Parameters:
offset- the offset to read from- Returns:
- the unsigned int value at the given offset
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Integer#BYTES})
-
writeInt
void writeInt(int value)Writes the given int at the cartridge's current offset, and then increments the offset byInteger.BYTES.- Parameters:
value- the int value to write- Throws:
IndexOutOfBoundsException- ifremaining()is less thanInteger.BYTES
-
setInt
void setInt(long offset, int value)Writes the given int at the given offset.- Parameters:
offset- the offset to write tovalue- the int value to write- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Integer#BYTES})
-
writeUnsignedInt
void writeUnsignedInt(long value)Writes the given unsigned int at the cartridge's current offset, and then increments the offset byInteger.BYTES.- Parameters:
value- the unsigned int value to write- Throws:
IndexOutOfBoundsException- ifremaining()is less thanInteger.BYTES
-
setUnsignedInt
void setUnsignedInt(long offset, long value)Writes the given unsigned int at the given offset.- Parameters:
offset- the offset to write tovalue- the unsigned int value to write- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Integer#BYTES})
-
readLong
long readLong()Reads the long at the cartridge's current offset, and then increments the offset byLong.BYTES.- Returns:
- the long value at the current offset
- Throws:
IndexOutOfBoundsException- ifremaining()is less thanLong.BYTES.
-
getLong
long getLong(long offset)Reads the long at the given offset.- Parameters:
offset- the offset to read from- Returns:
- the long value at the given offset
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Long#BYTES})
-
writeLong
void writeLong(long value)Writes the given long at the cartridge's current offset, and then increments the offset byLong.BYTES.- Parameters:
value- the long value to write- Throws:
IndexOutOfBoundsException- ifremaining()is less thanLong.BYTES
-
setLong
void setLong(long offset, long value)Writes the given long at the given offset.- Parameters:
offset- the offset to write tovalue- the long value to write- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - {@link Long#BYTES})
-
readBytes
void readBytes(byte[] dest)Transfers bytes from the cartridge into the given array, beginning at the cartridge's current offset, which is then incremented bydest.length.- Parameters:
dest- the destination array- Throws:
IndexOutOfBoundsException- ifremaining()is less thandest.length
-
readBytes
void readBytes(byte[] dest, int destOffset, int length)Transferslengthbytes from the cartridge into the given array, beginning at the cartridge's current offset and at the given offset in the array. The cartridge's offset is then incremented bylength.- Parameters:
dest- the destination arraydestOffset- the offset within the array of the first byte to be writtenlength- the number of bytes to be written- Throws:
IndexOutOfBoundsException- ifdestOffsetis out of bounds, i.e. less than 0 or greater thandest.length - destOffset; orremaining()is less thanlength
-
getBytes
void getBytes(long offset, byte[] dest)Transfers bytes from the cartridge into the given array, beginning at the given offset in the cartridge.- Parameters:
offset- the offset in the cartridge from which the first byte will be readdest- the destination array- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - dest.length)
-
getBytes
void getBytes(long offset, byte[] dest, int destOffset, int length)Transferslengthbytes from the cartridge into the given array, beginning at the given offset in the cartridge and at the given offset in the array.- Parameters:
offset- the offset in the cartridge from which the first byte will be readdest- the destination arraydestOffset- the offset within the array of the first byte to be writtenlength- the number of bytes to be written- Throws:
IndexOutOfBoundsException- ifoffsetis out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - length); ordestOffsetis out of bounds, i.e. less than 0 or greater thandest.length - length; orremaining()is less thanlength
-
writeBytes
void writeBytes(byte[] source)Transfers the entire content of the given array into the cartridge, beginning at the cartridge's current offset, which is then incremented bysource.length.- Parameters:
source- the source array- Throws:
IndexOutOfBoundsException- ifremaining()is less thansource.length
-
writeBytes
void writeBytes(byte[] source, int sourceOffset, int length)Transferslengthbytes from the given array into the cartridge, beginning at the cartridge's current offset and at the given offset in the array. The cartridge's offset is then incremented bylength.- Parameters:
source- the source arraysourceOffset- the offset within the array of the first byte to be readlength- the number of bytes to be written- Throws:
IndexOutOfBoundsException- ifsourceOffsetis out of bounds, i.e. less than 0 or greater than(source.length - sourceOffset); orremaining()is less thanlength
-
setBytes
void setBytes(long offset, byte[] source)Transfers bytes from the given array into the cartridge, beginning at the given offset in the cartridge.- Parameters:
offset- the offset in the cartridge at which the first byte will be writtensource- the source array- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater than{@link Cartridge#remaining()} - source.length
-
setBytes
void setBytes(long offset, byte[] source, int sourceOffset, int length)Transferslengthbytes from the given array into the cartridge, beginning at the given offset in the cartridge and at the given offset in the array.- Parameters:
offset- the offset in the cartridge at which the first byte will be writtensource- the source arraysourceOffset- the offset within the array of the first byte to be readlength- the number of bytes to be written- Throws:
IndexOutOfBoundsException- ifoffsetis out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - length); orsourceOffsetis out of bounds, i.e. less than 0 or greater than(source.length - length); orremaining()is less thanlength
-
readString
Decodeslengthbytes to characters using the given charset, beginning at the cartridge's current offset, which is then incremented bylength.- Parameters:
length- the number of bytes to be readcharset- the charset to be used- Returns:
- a string containing the decoded characters
- Throws:
IndexOutOfBoundsException- ifremaining()is less thanlength
-
getString
Decodeslengthbytes to characters using the given charset, beginning at the given offset in the cartridge.- Parameters:
offset- the offset in the cartridge from which the first byte will be readlength- the number of bytes to be readcharset- the charset to be used- Returns:
- a string containing the decoded characters
- Throws:
IndexOutOfBoundsException- ifoffsetis out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - length)
-
readAscii
Decodeslengthbytes to characters using theStandardCharsets.US_ASCIIcharset, beginning at the cartridge's current offset, which is then incremented bylength.- Parameters:
length- the number of bytes to be read- Returns:
- a string containing the decoded characters
- Throws:
IndexOutOfBoundsException- ifremaining()is less thanlength
-
getAscii
Decodeslengthbytes to characters using theStandardCharsets.US_ASCIIcharset, beginning at the given offset in the cartridge.- Parameters:
offset- the offset in the cartridge from which the first byte will be readlength- the number of bytes to be read- Returns:
- a string containing the decoded characters
- Throws:
IndexOutOfBoundsException- ifoffsetis out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - length)
-
readUtf8
Decodeslengthbytes to characters using theStandardCharsets.UTF_8charset, beginning at the cartridge's current offset, which is then incremented bylength.- Parameters:
length- the number of bytes to be read- Returns:
- a string containing the decoded characters
- Throws:
IndexOutOfBoundsException- ifremaining()is less thanlength
-
getUtf8
Decodeslengthbytes to characters using theStandardCharsets.UTF_8charset, beginning at the given offset in the cartridge.- Parameters:
offset- the offset in the cartridge from which the first byte will be readlength- the number of bytes to be read- Returns:
- a string containing the decoded characters
- Throws:
IndexOutOfBoundsException- ifoffsetis out of bounds, i.e. less than 0 or greater than({@link Cartridge#size()} - length)
-
writeString
Writes the encoded characters using the given charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.- Parameters:
sequence- the sequence of characters to be encodedcharset- the charset to be used- Returns:
- the number of bytes written to the cartridge
- Throws:
IndexOutOfBoundsException- ifremaining()} is less than the number of bytes to be written
-
setString
Writes the encoded characters using the given charset, beginning at the given offset in the cartridge.- Parameters:
offset- the offset in the cartridge at which the first byte will be writtensequence- the sequence of characters to be encodedcharset- the charset to be used- Returns:
- the number of bytes written to the cartridge
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater thansize()minus the number of bytes to be written
-
writeAscii
Writes the encoded characters using theStandardCharsets.US_ASCIIcharset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.- Parameters:
sequence- the sequence of characters to be encoded- Returns:
- the number of bytes written to the cartridge
- Throws:
IndexOutOfBoundsException- ifremaining()is less than the number of bytes to be written
-
setAscii
Writes the encoded characters using theStandardCharsets.US_ASCIIcharset, beginning at the given offset in the cartridge.- Parameters:
offset- the offset in the cartridge at which the first byte will be writtensequence- the sequence of characters to be encoded- Returns:
- the number of bytes written to the cartridge
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater thansize()minus the number of bytes to be written
-
writeUtf8
Writes the encoded characters using theStandardCharsets.UTF_8charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.- Parameters:
sequence- the sequence of characters to be encoded- Returns:
- the number of bytes written to the cartridge
- Throws:
IndexOutOfBoundsException- ifremaining()is less than the number of bytes to be written
-
setUtf8
Writes the encoded characters using theStandardCharsets.UTF_8charset, beginning at the given offset in the cartridge.- Parameters:
offset- the offset in the cartridge at which the first byte will be writtensequence- the sequence of characters to be encoded- Returns:
- the number of bytes written to the cartridge
- Throws:
IndexOutOfBoundsException- if the given offset is out of bounds, i.e. less than 0 or greater thansize()minus the number of bytes to be written
-