Package morfologik.stemming
Class BufferUtils
- java.lang.Object
-
- morfologik.stemming.BufferUtils
-
public final class BufferUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description privateBufferUtils()No instances.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.nio.CharBufferbytesToChars(java.nio.charset.CharsetDecoder decoder, java.nio.ByteBuffer bytes, java.nio.CharBuffer chars)Convert byte buffer's content into characters.static java.nio.ByteBuffercharsToBytes(java.nio.charset.CharsetEncoder encoder, java.nio.CharBuffer chars, java.nio.ByteBuffer bytes)Convert chars into bytes.static java.nio.ByteBufferclearAndEnsureCapacity(java.nio.ByteBuffer buffer, int elements)Ensure the buffer's capacity is large enough to hold a given number of elements.static java.nio.CharBufferclearAndEnsureCapacity(java.nio.CharBuffer buffer, int elements)Ensure the buffer's capacity is large enough to hold a given number of elements.(package private) static intsharedPrefixLength(java.nio.ByteBuffer a, int aStart, java.nio.ByteBuffer b, int bStart)Compute the length of the shared prefix between two byte sequences.(package private) static intsharedPrefixLength(java.nio.ByteBuffer a, java.nio.ByteBuffer b)Compute the length of the shared prefix between two byte sequences.static byte[]toArray(java.nio.ByteBuffer buffer)static java.lang.StringtoString(java.nio.ByteBuffer buffer, java.nio.charset.Charset charset)static java.lang.StringtoString(java.nio.CharBuffer buffer)
-
-
-
Method Detail
-
clearAndEnsureCapacity
public static java.nio.ByteBuffer clearAndEnsureCapacity(java.nio.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 ornullif a new buffer should be allocated.- Returns:
- Returns the same buffer or a new buffer with the given capacity.
-
clearAndEnsureCapacity
public static java.nio.CharBuffer clearAndEnsureCapacity(java.nio.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 ornullif a new buffer should be allocated.- Returns:
- Returns the same buffer or a new buffer with the given capacity.
-
toString
public static java.lang.String toString(java.nio.ByteBuffer buffer, java.nio.charset.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 java.lang.String toString(java.nio.CharBuffer buffer)
-
toArray
public static byte[] toArray(java.nio.ByteBuffer buffer)
- Parameters:
buffer- The buffer to read from.- Returns:
- Returns the remaining bytes from the buffer copied to an array.
-
sharedPrefixLength
static int sharedPrefixLength(java.nio.ByteBuffer a, int aStart, java.nio.ByteBuffer b, int bStart)Compute the length of the shared prefix between two byte sequences.
-
sharedPrefixLength
static int sharedPrefixLength(java.nio.ByteBuffer a, java.nio.ByteBuffer b)Compute the length of the shared prefix between two byte sequences.
-
bytesToChars
public static java.nio.CharBuffer bytesToChars(java.nio.charset.CharsetDecoder decoder, java.nio.ByteBuffer bytes, java.nio.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 java.nio.ByteBuffer charsToBytes(java.nio.charset.CharsetEncoder encoder, java.nio.CharBuffer chars, java.nio.ByteBuffer bytes) throws UnmappableInputExceptionConvert chars into bytes.- Throws:
UnmappableInputException
-
-