Package com.silabs.na.pcap.util
Class BufferUtil
- java.lang.Object
-
- com.silabs.na.pcap.util.BufferUtil
-
public class BufferUtil extends java.lang.Object
Local utility class.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
paddingLength(int dataLength, int byteBoundary)
Calculates the padding bytes to a given byte boundary.static byte[]
readBytesFromChannel(java.nio.channels.ReadableByteChannel rbc, java.nio.ByteBuffer buffer, int length)
Read buffers from channel into a byte buffer.static int
readNByteIntFromBuffer(java.nio.ByteBuffer buffer, int n)
Reads a N byte integer from buffer and return it.static int
readNByteIntFromChannel(java.nio.channels.ReadableByteChannel rbc, java.nio.ByteBuffer buffer, int n)
Reads N bytes of integer from the channel, using an intermediate buffer and it's endianess.
-
-
-
Method Detail
-
paddingLength
public static int paddingLength(int dataLength, int byteBoundary)
Calculates the padding bytes to a given byte boundary.- Parameters:
dataLength
- Length of the data.byteBoundary
- Byte boundary.- Returns:
- the number of bytes that should be added to the padding.
-
readNByteIntFromChannel
public static int readNByteIntFromChannel(java.nio.channels.ReadableByteChannel rbc, java.nio.ByteBuffer buffer, int n) throws java.io.IOException
Reads N bytes of integer from the channel, using an intermediate buffer and it's endianess. Buffer will be cleared and flipped along the way, so don't expect any data to be preserved in it.- Parameters:
rbc
- Byte channel for reading.buffer
- The temporary buffer used for the operation.n
- Number of bytes that make up the int.- Returns:
- Integer value of the read buffer.
- Throws:
java.io.IOException
- if something fails with underlying IO operations.
-
readBytesFromChannel
public static byte[] readBytesFromChannel(java.nio.channels.ReadableByteChannel rbc, java.nio.ByteBuffer buffer, int length) throws java.io.IOException
Read buffers from channel into a byte buffer.- Parameters:
rbc
- Byte channel for reading.buffer
- The temporary buffer used for the operation.length
- Number of bytes to read.- Returns:
- Bytes that were read.
- Throws:
java.io.IOException
- if something fails with underlying IO operations.
-
readNByteIntFromBuffer
public static int readNByteIntFromBuffer(java.nio.ByteBuffer buffer, int n)
Reads a N byte integer from buffer and return it.- Parameters:
buffer
- Buffer from which to read bytes.n
- Number of bytes that make up an integer.- Returns:
- Integer value.
-
-