Package com.blackrook.rookscript
Class ScriptValue.BufferType
java.lang.Object
com.blackrook.rookscript.ScriptValue.BufferType
- All Implemented Interfaces:
Iterable<ScriptIteratorType.IteratorPair>
- Enclosing class:
- ScriptValue
public static class ScriptValue.BufferType
extends Object
implements Iterable<ScriptIteratorType.IteratorPair>
The class used for a buffer of bytes.
-
Method Summary
Modifier and TypeMethodDescriptionbyte
Gets a byte value.Gets the byte order of this buffer.double
Gets a double value.float
Gets a float value.int
getInteger
(Integer index) Gets an integer value.long
Gets a long value.int
short
Gets a short value.Sets a string value.long
getUnsignedInteger
(Integer index) Gets an unsigned integer value.int
getUnsignedShort
(Integer index) Gets an unsigned short value.iterator()
void
Sets a byte value.int
Fills bytes using a value.void
Sets a double value.void
Sets a float value.void
putInteger
(Integer index, int value) Sets an integer value.void
Sets a long value.void
Sets a short value.void
Sets a string value.void
putUnsignedInteger
(Integer index, long value) Sets an unsigned integer value.void
putUnsignedShort
(Integer index, int value) Sets an unsigned short value.int
Reads bytes from a byte array into this buffer.int
readBytes
(Integer index, ScriptValue.BufferType buffer, int length) Reads bytes from another buffer into this one.int
readBytes
(Integer index, ScriptValue.BufferType buffer, Integer offset, int length) Reads bytes from another buffer into this one.int
Reads bytes from an input stream into this buffer.void
setByteOrder
(ByteOrder byteOrder) Sets the byte order of this buffer.void
setPosition
(int position) Sets the buffer's current cursor position.void
setSize
(int size) Sets the size of this buffer in bytes.int
size()
toString()
int
writeBytes
(Integer index, DataOutput out, int length) Writes bytes from this buffer into an input stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
setPosition
public void setPosition(int position) Sets the buffer's current cursor position.- Parameters:
position
- the new position.
-
getPosition
public int getPosition()- Returns:
- the buffer's current cursor position.
-
setSize
public void setSize(int size) Sets the size of this buffer in bytes. If this is resized, the buffer's data is kept.- Parameters:
size
- the new buffer size.
-
setByteOrder
Sets the byte order of this buffer.- Parameters:
byteOrder
- the new byte order.
-
getByteOrder
Gets the byte order of this buffer.- Returns:
- order the current byte order.
-
readBytes
Reads bytes from an input stream into this buffer. If null is passed in as the index, the buffer's cursor position is advanced by the length.- Parameters:
index
- the destination index (or null for current position).in
- the input stream to read from.length
- the amount of bytes to read.- Returns:
- the amount of bytes actually read. May be less than length (see
InputStream.read(byte[], int, int)
). - Throws:
IOException
- if a read error occurs.IndexOutOfBoundsException
- ifindex + length
exceeds the buffer length.
-
writeBytes
Writes bytes from this buffer into an input stream. If null is passed in as the index, the buffer's cursor position is advanced by the amount written.- Parameters:
index
- the destination index (or null for current position).out
- the output stream to write to.length
- the maximum amount of bytes to write.- Returns:
- the amount of bytes actually written. May be less than length.
- Throws:
IOException
- if a write error occurs.IndexOutOfBoundsException
- ifindex + length
exceeds the buffer length.
-
readBytes
Reads bytes from another buffer into this one. This relies on the other buffer's position to be set to where the read should occur. If null is passed in as the index, the buffer's cursor position is advanced by the length.- Parameters:
index
- the destination index (or null for current position).buffer
- the source buffer.length
- the amount of bytes to read.- Returns:
- the amount of bytes actually read.
- Throws:
IndexOutOfBoundsException
- ifindex
exceeds this buffer's length.
-
readBytes
Reads bytes from another buffer into this one. This relies on the other buffer's position to be set to where the read should occur. If null is passed in as the index, the buffer's cursor position is advanced by the length. If null is passed in as the offset, the source buffer's cursor position is advanced by the length.- Parameters:
index
- the destination index (or null for current position).buffer
- the source buffer.offset
- the offset into the source buffer (or null for its current position).length
- the amount of bytes to read.- Returns:
- the amount of bytes actually read (length).
- Throws:
IndexOutOfBoundsException
- ifindex + length
exceeds this buffer's length.
-
readBytes
Reads bytes from a byte array into this buffer. If null is passed in as the index, the buffer's cursor position is advanced by the length.- Parameters:
index
- the destination index (or null for current position).bytes
- the source array.offset
- the offset into the provided array to start the read from.length
- the amount of bytes to read.- Returns:
- the amount of bytes read (length).
- Throws:
IndexOutOfBoundsException
- ifindex + length
exceeds this buffer's length orindex + length
exceeds the length of the provided buffer.
-
putBytes
Fills bytes using a value. If null is passed in as the index, the buffer's cursor position is advanced by the length.- Parameters:
index
- the destination index (or null for current position).value
- the fill value.length
- the amount of bytes to add.- Returns:
- the amount of bytes set (length).
- Throws:
ArrayIndexOutOfBoundsException
- ifindex + length
exceeds this buffer's length orindex + length
exceeds the length of the provided buffer.
-
putByte
Sets a byte value. If null is passed in as the index, the buffer's cursor position is advanced by 1.- Parameters:
index
- the destination index (or null for current position).value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getByte
Gets a byte value. If null is passed in as the index, the buffer's cursor position is advanced by 1.- Parameters:
index
- the source index (or null for current position).- Returns:
- the value.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
putShort
Sets a short value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 2.- Parameters:
index
- the destination index (or null for current position).value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getShort
Gets a short value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 2.- Parameters:
index
- the source index (or null for current position).- Returns:
- the value.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
putUnsignedShort
Sets an unsigned short value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 2.- Parameters:
index
- the destination index (or null for current position).value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getUnsignedShort
Gets an unsigned short value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 2.- Parameters:
index
- the source index (or null for current position).- Returns:
- the value.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
putInteger
Sets an integer value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 4.- Parameters:
index
- the destination index (or null for current position).value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getInteger
Gets an integer value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 4.- Parameters:
index
- the source index (or null for current position).- Returns:
- the value.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
putUnsignedInteger
Sets an unsigned integer value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 4.- Parameters:
index
- the destination index (or null for current position).value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getUnsignedInteger
Gets an unsigned integer value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 4.- Parameters:
index
- the source index (or null for current position).- Returns:
- the value.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
putFloat
Sets a float value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 4.- Parameters:
index
- the destination index (or null for current position).value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getFloat
Gets a float value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 4.- Parameters:
index
- the source index (or null for current position).- Returns:
- the value.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
putLong
Sets a long value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 8.- Parameters:
index
- the destination index (or null for current position).value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getLong
Gets a long value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 8.- Parameters:
index
- the source index (or null for current position).- Returns:
- the value.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
putDouble
Sets a double value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 8.- Parameters:
index
- the destination index (or null for current position).value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getDouble
Gets a double value. Pays attention to current byte order. If null is passed in as the index, the buffer's cursor position is advanced by 8.- Parameters:
index
- the source index (or null for current position).- Returns:
- the value.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
putString
Sets a string value. If null is passed in as the index, the buffer's cursor position is advanced by the amount of bytes written.- Parameters:
index
- the destination index (or null for current position).charset
- the encoding charset.value
- the value.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
getString
Sets a string value. If null is passed in as the index, the buffer's cursor position is advanced by the length.- Parameters:
index
- the destination index (or null for current position).charset
- the encoding charset.length
- the amount of bytes to use to create a string.- Returns:
- the decoded string.
- Throws:
ArrayIndexOutOfBoundsException
- if the index is out-of-bounds.
-
size
public int size()- Returns:
- the size of this buffer in bytes.
-
getInputStream
- Returns:
- an open input stream for reading from the buffer's current cursor.
-
getOutputStream
- Returns:
- an open output stream for writing from the buffer's current cursor.
-
toString
-
iterator
- Specified by:
iterator
in interfaceIterable<ScriptIteratorType.IteratorPair>
-