Package morfologik.stemming
Class BufferUtils
- java.lang.Object
-
- morfologik.stemming.BufferUtils
-
public final class BufferUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CharBuffer
bytesToChars(CharsetDecoder decoder, ByteBuffer bytes, CharBuffer chars)
Convert byte buffer's content into characters.static ByteBuffer
charsToBytes(CharsetEncoder encoder, CharBuffer chars, ByteBuffer bytes)
Convert chars into bytes.static ByteBuffer
clearAndEnsureCapacity(ByteBuffer buffer, int elements)
Ensure the buffer's capacity is large enough to hold a given number of elements.static CharBuffer
clearAndEnsureCapacity(CharBuffer buffer, int elements)
Ensure the buffer's capacity is large enough to hold a given number of elements.static byte[]
toArray(ByteBuffer buffer)
static String
toString(ByteBuffer buffer, Charset charset)
static String
toString(CharBuffer buffer)
-
-
-
Method Detail
-
clearAndEnsureCapacity
public static ByteBuffer clearAndEnsureCapacity(ByteBuffer buffer, int elements)
Ensure the buffer's capacity is large enough to hold a given number of elements. If the input buffer is not large enough, a new buffer is allocated and returned.- Parameters:
elements
- The required number of elements to be appended to the buffer.buffer
- The buffer to check ornull
if a new buffer should be allocated.- Returns:
- Returns the same buffer or a new buffer with the given capacity.
-
clearAndEnsureCapacity
public static CharBuffer clearAndEnsureCapacity(CharBuffer buffer, int elements)
Ensure the buffer's capacity is large enough to hold a given number of elements. If the input buffer is not large enough, a new buffer is allocated and returned.- Parameters:
elements
- The required number of elements to be appended to the buffer.buffer
- The buffer to check ornull
if a new buffer should be allocated.- Returns:
- Returns the same buffer or a new buffer with the given capacity.
-
toString
public static String toString(ByteBuffer buffer, Charset charset)
- Parameters:
buffer
- The buffer to convert to a string.charset
- The charset to use when converting bytes to characters.- Returns:
- A string representation of buffer's content.
-
toString
public static String toString(CharBuffer buffer)
-
toArray
public static byte[] toArray(ByteBuffer buffer)
- Parameters:
buffer
- The buffer to read from.- Returns:
- Returns the remaining bytes from the buffer copied to an array.
-
bytesToChars
public static CharBuffer bytesToChars(CharsetDecoder decoder, ByteBuffer bytes, CharBuffer chars)
Convert byte buffer's content into characters. The input buffer's bytes are not consumed (mark is set and reset).
-
charsToBytes
public static ByteBuffer charsToBytes(CharsetEncoder encoder, CharBuffer chars, ByteBuffer bytes) throws UnmappableInputException
Convert chars into bytes.- Throws:
UnmappableInputException
-
-