Module jcifs

Class Encdec

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

public final class Encdec extends Object
Encoding and decoding utility class for SMB protocol. Provides methods for encoding/decoding various data types in different byte orders.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    dec_doublebe(byte[] src, int si)
    Decodes a double value from big-endian byte order.
    static double
    dec_doublele(byte[] src, int si)
    Decodes a double value from little-endian byte order.
    static float
    dec_floatbe(byte[] src, int si)
    Decodes a float value from big-endian byte order.
    static float
    dec_floatle(byte[] src, int si)
    Decodes a float value from little-endian byte order.
    static Date
    dec_time(byte[] src, int si, int enc)
    Decodes a Date value according to the specified time encoding type.
    static String
    dec_ucs2le(byte[] src, int si, int slim, char[] buf)
    Decodes a UCS-2 little-endian encoded string from a byte array.
    static short
    dec_uint16be(byte[] src, int si)
    Decodes a 16-bit unsigned integer from big-endian byte order.
    static short
    dec_uint16le(byte[] src, int si)
    Decodes a 16-bit unsigned integer from little-endian byte order.
    static int
    dec_uint32be(byte[] src, int si)
    Decodes a 32-bit unsigned integer from big-endian byte order.
    static int
    dec_uint32le(byte[] src, int si)
    Decodes a 32-bit unsigned integer from little-endian byte order.
    static long
    dec_uint64be(byte[] src, int si)
    Decodes a 64-bit unsigned integer from big-endian byte order.
    static long
    dec_uint64le(byte[] src, int si)
    Decodes a 64-bit unsigned integer from little-endian byte order.
    static String
    dec_utf8(byte[] src, int si, int slim)
    Decodes a UTF-8 encoded string from a byte array.
    static int
    enc_doublebe(double d, byte[] dst, int di)
    Encodes a double value in big-endian byte order.
    static int
    enc_doublele(double d, byte[] dst, int di)
    Encodes a double value in little-endian byte order.
    static int
    enc_floatbe(float f, byte[] dst, int di)
    Encodes a float value in big-endian byte order.
    static int
    enc_floatle(float f, byte[] dst, int di)
    Encodes a float value in little-endian byte order.
    static int
    enc_time(Date date, byte[] dst, int di, int enc)
    Encodes a Date value according to the specified time encoding type.
    static int
    enc_uint16be(short s, byte[] dst, int di)
    Encodes a 16-bit unsigned integer in big-endian byte order.
    static int
    enc_uint16le(short s, byte[] dst, int di)
    Encodes a 16-bit unsigned integer in little-endian byte order.
    static int
    enc_uint32be(int i, byte[] dst, int di)
    Encodes a 32-bit unsigned integer in big-endian byte order.
    static int
    enc_uint32le(int i, byte[] dst, int di)
    Encodes a 32-bit unsigned integer in little-endian byte order.
    static int
    enc_uint64be(long l, byte[] dst, int di)
    Encodes a 64-bit unsigned integer in big-endian byte order.
    static int
    enc_uint64le(long l, byte[] dst, int di)
    Encodes a 64-bit unsigned integer in little-endian byte order.
    static int
    enc_utf8(String str, byte[] dst, int di, int dlim)
    Encodes a String as UTF-8 bytes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • enc_uint16be

      public static int enc_uint16be(short s, byte[] dst, int di)
      Encodes a 16-bit unsigned integer in big-endian byte order.
      Parameters:
      s - the short value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (2)
    • enc_uint32be

      public static int enc_uint32be(int i, byte[] dst, int di)
      Encodes a 32-bit unsigned integer in big-endian byte order.
      Parameters:
      i - the integer value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (4)
    • enc_uint16le

      public static int enc_uint16le(short s, byte[] dst, int di)
      Encodes a 16-bit unsigned integer in little-endian byte order.
      Parameters:
      s - the short value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (2)
    • enc_uint32le

      public static int enc_uint32le(int i, byte[] dst, int di)
      Encodes a 32-bit unsigned integer in little-endian byte order.
      Parameters:
      i - the integer value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (4)
    • dec_uint16be

      public static short dec_uint16be(byte[] src, int si)
      Decodes a 16-bit unsigned integer from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded short value
    • dec_uint32be

      public static int dec_uint32be(byte[] src, int si)
      Decodes a 32-bit unsigned integer from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded integer value
    • dec_uint16le

      public static short dec_uint16le(byte[] src, int si)
      Decodes a 16-bit unsigned integer from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded short value
    • dec_uint32le

      public static int dec_uint32le(byte[] src, int si)
      Decodes a 32-bit unsigned integer from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded integer value
    • enc_uint64be

      public static int enc_uint64be(long l, byte[] dst, int di)
      Encodes a 64-bit unsigned integer in big-endian byte order.
      Parameters:
      l - the long value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (8)
    • enc_uint64le

      public static int enc_uint64le(long l, byte[] dst, int di)
      Encodes a 64-bit unsigned integer in little-endian byte order.
      Parameters:
      l - the long value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (8)
    • dec_uint64be

      public static long dec_uint64be(byte[] src, int si)
      Decodes a 64-bit unsigned integer from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded long value
    • dec_uint64le

      public static long dec_uint64le(byte[] src, int si)
      Decodes a 64-bit unsigned integer from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded long value
    • enc_floatle

      public static int enc_floatle(float f, byte[] dst, int di)
      Encodes a float value in little-endian byte order.
      Parameters:
      f - the float value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (4)
    • enc_floatbe

      public static int enc_floatbe(float f, byte[] dst, int di)
      Encodes a float value in big-endian byte order.
      Parameters:
      f - the float value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (4)
    • dec_floatle

      public static float dec_floatle(byte[] src, int si)
      Decodes a float value from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded float value
    • dec_floatbe

      public static float dec_floatbe(byte[] src, int si)
      Decodes a float value from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded float value
    • enc_doublele

      public static int enc_doublele(double d, byte[] dst, int di)
      Encodes a double value in little-endian byte order.
      Parameters:
      d - the double value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (8)
    • enc_doublebe

      public static int enc_doublebe(double d, byte[] dst, int di)
      Encodes a double value in big-endian byte order.
      Parameters:
      d - the double value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (8)
    • dec_doublele

      public static double dec_doublele(byte[] src, int si)
      Decodes a double value from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded double value
    • dec_doublebe

      public static double dec_doublebe(byte[] src, int si)
      Decodes a double value from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded double value
    • enc_time

      public static int enc_time(Date date, byte[] dst, int di, int enc)
      Encodes a Date value according to the specified time encoding type.
      Parameters:
      date - the Date to encode
      dst - the destination byte array
      di - the starting index in the destination array
      enc - the time encoding type (e.g., TIME_1970_SEC_32BE)
      Returns:
      the number of bytes written
    • dec_time

      public static Date dec_time(byte[] src, int si, int enc)
      Decodes a Date value according to the specified time encoding type.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      enc - the time encoding type (e.g., TIME_1970_SEC_32BE)
      Returns:
      the decoded Date value
    • enc_utf8

      public static int enc_utf8(String str, byte[] dst, int di, int dlim)
      Encodes a String as UTF-8 bytes.
      Parameters:
      str - the String to encode
      dst - the destination byte array
      di - the starting index in the destination array
      dlim - the maximum index in the destination array
      Returns:
      the number of bytes written
    • dec_utf8

      public static String dec_utf8(byte[] src, int si, int slim) throws IOException
      Decodes a UTF-8 encoded string from a byte array.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      slim - the limit index in the source array
      Returns:
      the decoded String
      Throws:
      IOException - if a decoding error occurs
    • dec_ucs2le

      public static String dec_ucs2le(byte[] src, int si, int slim, char[] buf)
      Decodes a UCS-2 little-endian encoded string from a byte array.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      slim - the limit index in the source array
      buf - the character buffer for decoding
      Returns:
      the decoded String