public final class NullTerminatedStringUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
nullTerminatedBytesToString(byte[] bytes,
java.nio.charset.Charset encoding)
Converts a null-terminated array of bytes to a string.
|
static java.lang.String |
nullTerminatedBytesToString(byte[] bytes,
java.nio.charset.Charset encoding,
boolean strict)
Converts a null-terminated array of bytes to a string.
|
static java.lang.String |
nullTerminatedBytesToString(byte[] bytes,
int offset,
int length,
java.nio.charset.Charset encoding,
boolean strict)
Converts a null-terminated part of an array of bytes to a string.
|
static Pair<byte[],java.lang.Integer> |
stringToSizeLimitedNullTerminatedBytesOrNull(java.lang.String string,
int maximumLength,
java.nio.charset.Charset encoding)
Converts a string to an array of null-terminated bytes.
|
static Pair<byte[],java.lang.Integer> |
stringToSizeLimitedNullTerminatedBytesOrNull(java.lang.String string,
int maximumLength,
int alignTo,
java.nio.charset.Charset encoding)
Converts a string to an array of null-terminated bytes.
|
static Pair<byte[],java.lang.Integer> |
stringToTruncatedNullTerminatedBytes(java.lang.String string,
int maximumLength,
java.nio.charset.Charset encoding)
Converts a string to an array of null-terminated bytes, truncating the
string if necessary.
|
static Pair<byte[],java.lang.Integer> |
stringToTruncatedNullTerminatedBytes(java.lang.String string,
int maximumLength,
int alignTo,
java.nio.charset.Charset encoding)
Converts a string to an array of null-terminated bytes, truncating the
string if necessary.
|
static byte[] |
stringToTruncatedNullTerminatedFixedBytes(java.lang.String string,
int fixedLength,
java.nio.charset.Charset encoding)
Converts a string to an array of null-terminated bytes, truncating the
string if necessary.
|
public static java.lang.String nullTerminatedBytesToString(byte[] bytes,
int offset,
int length,
java.nio.charset.Charset encoding,
boolean strict)
strict
option.bytes - array of bytesoffset - offset into the bytes array. This method will
start reading at this position.length - maximum number of bytes that should be read from the
bytes array.encoding - character set to use for converting the bytes to a string.strict - if true, this method throws an
IllegalArgumentException if the string is not null terminated
(there is no null byte in the range denoted by
offset and length. If
false, all bytes are used for the string (an
implicit null byte after the end of the byte range is
assumed).java.lang.IndexOutOfBoundsException - if offset + length exceed the size
of bytes.public static java.lang.String nullTerminatedBytesToString(byte[] bytes,
java.nio.charset.Charset encoding,
boolean strict)
strict
option.bytes - array of bytesencoding - character set to use for converting the bytes to a string.strict - if true, this method throws an
IllegalArgumentException if the string is not null terminated.
If false, all bytes are used for the string (an
implicit null byte after the end of the byte array is
assumed).public static java.lang.String nullTerminatedBytesToString(byte[] bytes,
java.nio.charset.Charset encoding)
bytes - array of bytesencoding - character set to use for converting the bytes to a string.public static Pair<byte[],java.lang.Integer> stringToTruncatedNullTerminatedBytes(java.lang.String string, int maximumLength, int alignTo, java.nio.charset.Charset encoding)
maximumLength and always has at least one terminating
null-byte.string - the string that shall be converted to bytes.maximumLength - the maximum length of the resulting byte array (including the
terminating null-byte).alignTo - number of bytes that the string length (including the
terminating null-bytes) should be aligned to. This means that
some additional null-bytes will be added to match the
alignment if needed. The total length is still guaranteed to
be less than or equal to maximumLength.encoding - the character set to be used for converting the string.java.lang.IllegalArgumentException - if maximumLength is negative,
alignTo is less than or equal to zero, or
maximumLength is less than alignTo.public static Pair<byte[],java.lang.Integer> stringToTruncatedNullTerminatedBytes(java.lang.String string, int maximumLength, java.nio.charset.Charset encoding)
maximumLength and always has at least one terminating
null-byte.string - the string that shall be converted to bytes.maximumLength - the maximum length of the resulting byte array (including the
terminating null-byte).encoding - the character set to be used for converting the string.java.lang.IllegalArgumentException - if maximumLength is less than or equal to zero.public static byte[] stringToTruncatedNullTerminatedFixedBytes(java.lang.String string,
int fixedLength,
java.nio.charset.Charset encoding)
fixedLength bytes. If the string is shorter than the space
available in the array, the remaining space is filled with null bytes.string - the string that shall be converted to bytes.fixedLength - the length of the resulting byte array (including the
terminating null-byte).encoding - the character set to be used for converting the string.java.lang.IllegalArgumentException - if fixedLength is less than or equal to zero.public static Pair<byte[],java.lang.Integer> stringToSizeLimitedNullTerminatedBytesOrNull(java.lang.String string, int maximumLength, int alignTo, java.nio.charset.Charset encoding)
maximumLength and always has at
least one terminating null-byte. If the string is too long to fit into
maximumLength bytes, null is returned.string - the string that shall be converted to bytes.maximumLength - the maximum length of the resulting byte array (including the
terminating null-byte).alignTo - number of bytes that the string length (including the
terminating null-bytes) should be aligned to. This means that
some additional null-bytes will be added to match the
alignment if needed. The total length is still guaranteed to
be less than or equal to maximumLength.encoding - the character set to be used for converting the string.null if the byte representation of the
string (including one terminating null-byte) is longer than
maximumLength.java.lang.IllegalArgumentException - if maximumLength is negative or
alignTo is less than or equal to zero.public static Pair<byte[],java.lang.Integer> stringToSizeLimitedNullTerminatedBytesOrNull(java.lang.String string, int maximumLength, java.nio.charset.Charset encoding)
maximumLength and always has at
least one terminating null-byte. If the string is too long to fit into
maximumLength bytes, null is returned.string - the string that shall be converted to bytes.maximumLength - the maximum length of the resulting byte array (including the
terminating null-byte).encoding - the character set to be used for converting the string.null if the byte representation of the
string (including one terminating null-byte) is longer than
maximumLength.java.lang.IllegalArgumentException - if maximumLength is negative.Copyright © 2014–2018 aquenos GmbH. All rights reserved.