java.lang.Object
org.codelibs.jcifs.smb.util.Strings
Utility class for string manipulation and conversion operations in the jCIFS library.
Provides methods for encoding, decoding, and manipulating strings in SMB operations.
- Author:
- mbechler
-
Method Summary
Modifier and TypeMethodDescriptionstatic intfindTermination(byte[] buffer, int bufferIndex, int maxLen) Finds the null termination in a single-byte encoded string buffer.static intfindUNITermination(byte[] buffer, int bufferIndex, int maxLen) Finds the null termination in a UTF-16LE encoded string buffer.static StringfromOEMBytes(byte[] src, int srcIndex, int len, Configuration config) Decodes a string from OEM-encoded bytes.static StringfromUNIBytes(byte[] src, int srcIndex, int len) Decodes a string from UTF-16LE (Unicode Little Endian) bytes.static byte[]getASCIIBytes(String str) Encodes a string into ASCII bytes.static byte[]Encodes a string into bytes using the specified encoding.static byte[]getOEMBytes(String str, Configuration config) Encodes a string into bytes using the OEM encoding from the configuration.static byte[]getUNIBytes(String str) Encodes a string into UTF-16LE (Unicode Little Endian) bytes.static StringmaskSecretValue(String value) Masks sensitive values in a string for security purposes.
-
Method Details
-
getBytes
Encodes a string into bytes using the specified encoding.- Parameters:
str- the string to encodeencoding- the character encoding to use- Returns:
- encoded byte array, or empty array if str is null
-
getUNIBytes
Encodes a string into UTF-16LE (Unicode Little Endian) bytes.- Parameters:
str- the string to encode- Returns:
- the string as bytes (UTF16-LE)
-
getASCIIBytes
Encodes a string into ASCII bytes.- Parameters:
str- the string to encode- Returns:
- the string as bytes (ASCII)
-
getOEMBytes
Encodes a string into bytes using the OEM encoding from the configuration.- Parameters:
str- the string to encodeconfig- the configuration providing the OEM encoding- Returns:
- the string as bytes
-
fromUNIBytes
Decodes a string from UTF-16LE (Unicode Little Endian) bytes.- Parameters:
src- the byte array containing the encoded stringsrcIndex- the starting offset in the byte arraylen- the number of bytes to decode- Returns:
- decoded string
-
findUNITermination
public static int findUNITermination(byte[] buffer, int bufferIndex, int maxLen) Finds the null termination in a UTF-16LE encoded string buffer.- Parameters:
buffer- the byte buffer to searchbufferIndex- the starting position in the buffermaxLen- the maximum length to search- Returns:
- position of terminating null bytes
-
fromOEMBytes
Decodes a string from OEM-encoded bytes.- Parameters:
src- the byte array containing the encoded stringsrcIndex- the starting offset in the byte arraylen- the number of bytes to decodeconfig- the configuration providing the OEM encoding- Returns:
- decoded string
-
findTermination
public static int findTermination(byte[] buffer, int bufferIndex, int maxLen) Finds the null termination in a single-byte encoded string buffer.- Parameters:
buffer- the byte buffer to searchbufferIndex- the starting position in the buffermaxLen- the maximum length to search- Returns:
- position of terminating null byte
-
maskSecretValue
Masks sensitive values in a string for security purposes.- Parameters:
value- the string potentially containing sensitive information- Returns:
- the string with sensitive parts masked, or the original string if masking is disabled
-