- java.lang.Object
-
- de.carne.mcd.io.MCDInputBuffer
-
-
Constructor Summary
Constructors Constructor Description MCDInputBuffer(java.nio.channels.ReadableByteChannel in, java.nio.ByteOrder byteOrder)Constructs a new MCDInputBuffer instance.MCDInputBuffer(java.nio.channels.ReadableByteChannel in, java.nio.ByteOrder byteOrder, int bufferSize)Constructs a new MCDInputBuffer instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit()Commits any buffered data operation.floatdecodeF32()Decodes a float value.doubledecodeF64()Decodes a double byte value.shortdecodeI16()Decodes ashortvalue.java.nio.ByteBufferdecodeI16Array(int arrayLength)Decodes an array ofshortvalues.intdecodeI32()Decodes anintvalue.java.nio.ByteBufferdecodeI32Array(int arrayLength)Decodes an array ofintvalues.longdecodeI64()Decodes alongvalue.java.nio.ByteBufferdecodeI64Array(int arrayLength)Decodes an array oflongvalues.bytedecodeI8()Decodes abytevalue.java.nio.ByteBufferdecodeI8Array(int arrayLength)Decodes an array ofbytevalues.voiddecodeMagic(byte expectedMagic)Decodes the given magic byte.voiddecodeMagic(int expectedMagic)Decodes the given magic dword.voiddecodeMagic(long expectedMagic)Decodes the given magic qword.voiddecodeMagic(short expectedMagic)Decodes the given magic word.voiddiscard()Discard any buffered data operation.voiddiscard(int length)Discards a specific number of uncommitted bytes.longgetTotalRead()Gets the total number of bytes read via this MCDInputBuffer instance.intread()Reads a single byte value.booleansetAutoCommit(boolean autoCommit)Sets the auto-commit flag for this MCDBuffer instance.voidskip(long length)Skips the requested number of bytes from the byte channel.java.nio.channels.SeekableByteChannelslice(long length)Slices the requested number of bytes from the byte channel and wraps them into a SeekableByteChannel instance for later decoding.static short[]toI16Array(java.nio.ByteBuffer buffer)Decodes ashortarray from a buffer returned from decodeI16Array(int).static int[]toI32Array(java.nio.ByteBuffer buffer)Decodes anintarray from a buffer returned from decodeI32Array(int).static long[]toI64Array(java.nio.ByteBuffer buffer)Decodes alongarray from a buffer returned from decodeI64Array(int).static byte[]toI8Array(java.nio.ByteBuffer buffer)Decodes abytearray from a buffer returned from decodeI8Array(int).@NonNull java.lang.StringtoString()
-
-
-
Constructor Detail
-
MCDInputBuffer
public MCDInputBuffer(java.nio.channels.ReadableByteChannel in, java.nio.ByteOrder byteOrder)Constructs a new MCDInputBuffer instance.- Parameters:
in- the ReadableByteChannel to read from.byteOrder- the ByteOrder to use for decoding.
-
MCDInputBuffer
public MCDInputBuffer(java.nio.channels.ReadableByteChannel in, java.nio.ByteOrder byteOrder, int bufferSize)Constructs a new MCDInputBuffer instance.- Parameters:
in- the ReadableByteChannel to read from.byteOrder- the ByteOrder to use for decoding.bufferSize- the buffer size to use.
-
-
Method Detail
-
getTotalRead
public long getTotalRead()
Gets the total number of bytes read via this MCDInputBuffer instance.- Returns:
- the total number of bytes read via this MCDInputBuffer instance.
-
setAutoCommit
public boolean setAutoCommit(boolean autoCommit)
Description copied from interface:MCDBufferSets the auto-commit flag for this MCDBuffer instance.- Specified by:
setAutoCommitin interfaceMCDBuffer- Parameters:
autoCommit- whether to auto-commit any buffer operation or not.- Returns:
- the previous auto-commit flag state.
-
commit
public void commit() throws java.io.IOExceptionDescription copied from interface:MCDBufferCommits any buffered data operation.
-
discard
public void discard()
Description copied from interface:MCDBufferDiscard any buffered data operation.
-
discard
public void discard(int length)
Discards a specific number of uncommitted bytes.If
lengthis positive the corresponding number of bytes are kept as uncommitted and any following byte is discarded. Iflengthis negative the last-lengthbytes are discarded and any other byte is kept as uncommitted.- Parameters:
length- the amount of bytes to discard.
-
slice
public java.nio.channels.SeekableByteChannel slice(long length) throws java.io.IOExceptionSlices the requested number of bytes from the byte channel and wraps them into a SeekableByteChannel instance for later decoding.This function requires this buffer instance to be committed prior to calling it.
- Parameters:
length- the number of bytes to slice.- Returns:
- the SeekableByteChannel providing access to the sliced bytes.
- Throws:
java.io.IOException- if an I/O error occurs.
-
skip
public void skip(long length) throws java.io.IOExceptionSkips the requested number of bytes from the byte channel.This function requires this buffer instance to be committed prior to calling it.
- Parameters:
length- the number of bytes to skip.- Throws:
java.io.IOException- if an I/O error occurs.
-
read
public int read() throws java.io.IOExceptionReads a single byte value.In contrast to the decode functions this function handles EOF gracefully by returning
-1.- Returns:
- the read byte value or
-1if EOF has been reached. - Throws:
java.io.IOException- if an I/O error occurs.
-
decodeI8
public byte decodeI8() throws java.io.IOExceptionDecodes abytevalue.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
decodeI8Array
public java.nio.ByteBuffer decodeI8Array(int arrayLength) throws java.io.IOExceptionDecodes an array ofbytevalues.- Parameters:
arrayLength- the array length to decode.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
toI8Array
public static byte[] toI8Array(java.nio.ByteBuffer buffer)
Decodes abytearray from a buffer returned from decodeI8Array(int).- Parameters:
buffer- the buffer to decode.- Returns:
- the decoded array.
-
decodeMagic
public void decodeMagic(byte expectedMagic) throws java.io.IOExceptionDecodes the given magic byte.- Parameters:
expectedMagic- the expected magic byte.- Throws:
java.io.IOException- if the decoded byte does not match the expected magic byte or if an I/O error occurs.
-
decodeI16
public short decodeI16() throws java.io.IOExceptionDecodes ashortvalue.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
decodeI16Array
public java.nio.ByteBuffer decodeI16Array(int arrayLength) throws java.io.IOExceptionDecodes an array ofshortvalues.- Parameters:
arrayLength- the array length to decode.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
toI16Array
public static short[] toI16Array(java.nio.ByteBuffer buffer)
Decodes ashortarray from a buffer returned from decodeI16Array(int).- Parameters:
buffer- the buffer to decode.- Returns:
- the decoded array.
-
decodeMagic
public void decodeMagic(short expectedMagic) throws java.io.IOExceptionDecodes the given magic word.- Parameters:
expectedMagic- the expected magic word.- Throws:
java.io.IOException- if the decoded word does not match the expected magic word or if an I/O error occurs.
-
decodeI32
public int decodeI32() throws java.io.IOExceptionDecodes anintvalue.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
decodeI32Array
public java.nio.ByteBuffer decodeI32Array(int arrayLength) throws java.io.IOExceptionDecodes an array ofintvalues.- Parameters:
arrayLength- the array length to decode.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
toI32Array
public static int[] toI32Array(java.nio.ByteBuffer buffer)
Decodes anintarray from a buffer returned from decodeI32Array(int).- Parameters:
buffer- the buffer to decode.- Returns:
- the decoded array.
-
decodeMagic
public void decodeMagic(int expectedMagic) throws java.io.IOExceptionDecodes the given magic dword.- Parameters:
expectedMagic- the expected magic dword.- Throws:
java.io.IOException- if the decoded dword does not match the expected magic dword or if an I/O error occurs.
-
decodeI64
public long decodeI64() throws java.io.IOExceptionDecodes alongvalue.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
decodeI64Array
public java.nio.ByteBuffer decodeI64Array(int arrayLength) throws java.io.IOExceptionDecodes an array oflongvalues.- Parameters:
arrayLength- the array length to decode.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
toI64Array
public static long[] toI64Array(java.nio.ByteBuffer buffer)
Decodes alongarray from a buffer returned from decodeI64Array(int).- Parameters:
buffer- the buffer to decode.- Returns:
- the decoded array.
-
decodeMagic
public void decodeMagic(long expectedMagic) throws java.io.IOExceptionDecodes the given magic qword.- Parameters:
expectedMagic- the expected magic qword.- Throws:
java.io.IOException- if the decoded qword does not match the expected magic qword or if an I/O error occurs.
-
decodeF32
public float decodeF32() throws java.io.IOExceptionDecodes a float value.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
decodeF64
public double decodeF64() throws java.io.IOExceptionDecodes a double byte value.- Returns:
- the decoded value.
- Throws:
java.io.IOException- if an I/O error occurs.
-
toString
public @NonNull java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-