Package alluxio.util.io
Class ByteIOUtils
- java.lang.Object
-
- alluxio.util.io.ByteIOUtils
-
@ThreadSafe public final class ByteIOUtils extends java.lang.Object
A collection of utility functions to read/write primitive values from/to a byte array.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte
readByte(byte[] buf, int pos)
Reads a specific byte value from the input byte array at the given offset.static byte
readByte(java.nio.ByteBuffer buf, int pos)
Reads a specific byte value from the input byte buffer at the given offset.static int
readInt(byte[] buf, int pos)
Reads a specific integer byte value (4 bytes) from the input byte array at the given offset.static int
readInt(java.nio.ByteBuffer buf, int pos)
Reads a specific integer byte value (4 bytes) from the input byte buffer at the given offset.static long
readLong(byte[] buf, int pos)
Reads a specific long byte value (8 bytes) from the input byte array at the given offset.static short
readShort(byte[] buf, int pos)
Reads a specific short byte value (2 bytes) from the input byte array at the given offset.static void
writeByte(byte[] buf, int pos, byte v)
Writes a single byte value (1 byte) to the output byte array at the given offset.static void
writeByte(java.io.OutputStream out, byte v)
Writes a single byte value (1 byte) to the output stream.static void
writeByte(java.nio.ByteBuffer buf, int pos, byte v)
Writes a single byte value (1 byte) to the output byte buffer at the given offset.static void
writeInt(byte[] buf, int pos, int v)
Writes a specific integer value (4 bytes) to the output byte array at the given offset.static void
writeInt(java.io.OutputStream out, int v)
Writes a specific integer value (4 bytes) to the output stream.static void
writeInt(java.nio.ByteBuffer buf, int pos, int v)
Writes a specific integer value (4 bytes) to the output byte buffer at the given offset.static void
writeLong(byte[] buf, int pos, long v)
Writes a specific long value (8 bytes) to the output byte array at the given offset.static void
writeLong(java.io.OutputStream out, long v)
Writes a specific long value (8 bytes) to the output stream.static void
writeShort(byte[] buf, int pos, short v)
Writes a specific short value (2 bytes) to the output byte buffer at the given offset.static void
writeShort(java.io.OutputStream out, short v)
Writes a specific short value (2 bytes) to the output stream.
-
-
-
Method Detail
-
readByte
public static byte readByte(byte[] buf, int pos)
Reads a specific byte value from the input byte array at the given offset.- Parameters:
buf
- input byte arraypos
- offset into the byte buffer to read- Returns:
- the byte value read
-
readByte
public static byte readByte(java.nio.ByteBuffer buf, int pos)
Reads a specific byte value from the input byte buffer at the given offset.- Parameters:
buf
- input byte bufferpos
- offset into the byte buffer to read- Returns:
- the byte value read
-
readShort
public static short readShort(byte[] buf, int pos)
Reads a specific short byte value (2 bytes) from the input byte array at the given offset.- Parameters:
buf
- input byte bufferpos
- offset into the byte buffer to read- Returns:
- the short value read
-
readInt
public static int readInt(byte[] buf, int pos)
Reads a specific integer byte value (4 bytes) from the input byte array at the given offset.- Parameters:
buf
- input byte arraypos
- offset into the byte buffer to read- Returns:
- the int value read
-
readInt
public static int readInt(java.nio.ByteBuffer buf, int pos)
Reads a specific integer byte value (4 bytes) from the input byte buffer at the given offset.- Parameters:
buf
- input byte bufferpos
- offset into the byte buffer to read- Returns:
- the int value read
-
readLong
public static long readLong(byte[] buf, int pos)
Reads a specific long byte value (8 bytes) from the input byte array at the given offset.- Parameters:
buf
- input byte bufferpos
- offset into the byte buffer to read- Returns:
- the long value read
-
writeByte
public static void writeByte(byte[] buf, int pos, byte v)
Writes a single byte value (1 byte) to the output byte array at the given offset.- Parameters:
buf
- output byte bufferpos
- offset into the byte buffer to writev
- byte value to write
-
writeByte
public static void writeByte(java.nio.ByteBuffer buf, int pos, byte v)
Writes a single byte value (1 byte) to the output byte buffer at the given offset.- Parameters:
buf
- output byte bufferpos
- offset into the byte buffer to writev
- byte value to write
-
writeByte
public static void writeByte(java.io.OutputStream out, byte v) throws java.io.IOException
Writes a single byte value (1 byte) to the output stream. This is equivalent ofOutputStream.write(int)
.- Parameters:
out
- output streamv
- byte value to write- Throws:
java.io.IOException
-
writeShort
public static void writeShort(byte[] buf, int pos, short v)
Writes a specific short value (2 bytes) to the output byte buffer at the given offset.- Parameters:
buf
- output byte bufferpos
- offset into the byte buffer to writev
- short value to write
-
writeShort
public static void writeShort(java.io.OutputStream out, short v) throws java.io.IOException
Writes a specific short value (2 bytes) to the output stream.- Parameters:
out
- output streamv
- short value to write- Throws:
java.io.IOException
-
writeInt
public static void writeInt(byte[] buf, int pos, int v)
Writes a specific integer value (4 bytes) to the output byte array at the given offset.- Parameters:
buf
- output byte arraypos
- offset into the byte buffer to writev
- int value to write
-
writeInt
public static void writeInt(java.nio.ByteBuffer buf, int pos, int v)
Writes a specific integer value (4 bytes) to the output byte buffer at the given offset.- Parameters:
buf
- output byte bufferpos
- offset into the byte buffer to writev
- int value to write
-
writeInt
public static void writeInt(java.io.OutputStream out, int v) throws java.io.IOException
Writes a specific integer value (4 bytes) to the output stream.- Parameters:
out
- output streamv
- integer value to write- Throws:
java.io.IOException
-
writeLong
public static void writeLong(byte[] buf, int pos, long v)
Writes a specific long value (8 bytes) to the output byte array at the given offset.- Parameters:
buf
- output byte arraypos
- offset into the byte buffer to writev
- long value to write
-
writeLong
public static void writeLong(java.io.OutputStream out, long v) throws java.io.IOException
Writes a specific long value (8 bytes) to the output stream.- Parameters:
out
- output streamv
- long value to write- Throws:
java.io.IOException
-
-