Module jcifs

Class Strings

java.lang.Object
org.codelibs.jcifs.smb.util.Strings

public final class Strings extends Object
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 Details

    • getBytes

      public static byte[] getBytes(String str, Charset encoding)
      Encodes a string into bytes using the specified encoding.
      Parameters:
      str - the string to encode
      encoding - the character encoding to use
      Returns:
      encoded byte array, or empty array if str is null
    • getUNIBytes

      public static byte[] getUNIBytes(String str)
      Encodes a string into UTF-16LE (Unicode Little Endian) bytes.
      Parameters:
      str - the string to encode
      Returns:
      the string as bytes (UTF16-LE)
    • getASCIIBytes

      public static byte[] getASCIIBytes(String str)
      Encodes a string into ASCII bytes.
      Parameters:
      str - the string to encode
      Returns:
      the string as bytes (ASCII)
    • getOEMBytes

      public static byte[] getOEMBytes(String str, Configuration config)
      Encodes a string into bytes using the OEM encoding from the configuration.
      Parameters:
      str - the string to encode
      config - the configuration providing the OEM encoding
      Returns:
      the string as bytes
    • fromUNIBytes

      public static String fromUNIBytes(byte[] src, int srcIndex, int len)
      Decodes a string from UTF-16LE (Unicode Little Endian) bytes.
      Parameters:
      src - the byte array containing the encoded string
      srcIndex - the starting offset in the byte array
      len - 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 search
      bufferIndex - the starting position in the buffer
      maxLen - the maximum length to search
      Returns:
      position of terminating null bytes
    • fromOEMBytes

      public static String fromOEMBytes(byte[] src, int srcIndex, int len, Configuration config)
      Decodes a string from OEM-encoded bytes.
      Parameters:
      src - the byte array containing the encoded string
      srcIndex - the starting offset in the byte array
      len - the number of bytes to decode
      config - 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 search
      bufferIndex - the starting position in the buffer
      maxLen - the maximum length to search
      Returns:
      position of terminating null byte
    • maskSecretValue

      public static String maskSecretValue(String value)
      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