Class Bytes

  • Direct Known Subclasses:
    W.B

    public class Bytes
    extends java.lang.Object
    字节数组操作
    Author:
    WD
    • Constructor Summary

      Constructors 
      Constructor Description
      Bytes()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] add​(byte[]... bs)
      字节数组相连
      static byte[] binary​(java.lang.Object binary)
      转换Binary序列化
      static byte[] copy​(byte[] b, int offset, int len)
      拷贝字节数组
      static boolean isType​(java.lang.Class<?> c)
      是否支持序列化类型
      static java.lang.Object to​(byte[] b, java.lang.Class<?> c)
      根据c类型反序列化
      static ByteArray toBean​(ByteArray array, byte[] b)
      把字节数组转换为ByteArray
      static ByteArray toBean​(ByteArray array, byte[] b, int offset)
      把字节数组转换为ByteArray
      static ByteArray toBean​(ByteArray array, byte[] b, int offset, int len)
      把字节数组转换为ByteArray
      static <B> B toBinary​(byte[] b, java.lang.Class<B> c)
      读取字节数组变成对象
      static boolean toBoolean​(byte[] b)
      把字节数组转换成int
      static boolean toBoolean​(byte[] b, int offset)
      把字节数组转换成int
      static byte toByte​(byte[] b)
      把字节数组转换成int
      static byte toByte​(byte[] b, int offset)
      把字节数组转换成int
      static byte[] toBytes​(boolean b)
      转换Collection变成字节数组
      static byte[] toBytes​(boolean is, java.lang.Object obj)
      转换Object变成字节数组
      static byte[] toBytes​(char c)
      转换char变成字节数组
      static byte[] toBytes​(double d)
      转换double变成字节数组
      static byte[] toBytes​(float f)
      转换float变成字节数组
      static byte[] toBytes​(int i)
      转换int变成字节数组
      static byte[] toBytes​(long l)
      转换long变成字节数组
      static byte[] toBytes​(short s)
      转换short变成字节数组
      static byte[] toBytes​(Binary binary)
      转换Binary序列化
      static byte[] toBytes​(ByteArray array)
      转换ByteArray变成字节数组
      static byte[] toBytes​(java.lang.Boolean is, java.lang.Object... objs)
      转换Object变成字节数组
      static byte[] toBytes​(java.lang.Object obj)
      转换Object变成字节数组
      static byte[] toBytes​(java.lang.Object... objs)
      转换Object变成字节数组
      static byte[] toBytes​(java.lang.String s)
      转换String变成字节数组
      static byte[] toBytes​(java.lang.String s, boolean is)
      转换String变成字节数组
      static byte[] toBytes​(java.nio.ByteBuffer buff)
      转换ByteBuffer变成字节数组
      static char toChar​(byte[] b)
      把字节数组转换成char
      static char toChar​(byte[] b, int offset)
      把字节数组转换成char
      static double toDouble​(byte[] b)
      把字节数组转换成double
      static double toDouble​(byte[] b, int offset)
      把字节数组转换成double
      static float toFloat​(byte[] b)
      把字节数组转换成float
      static float toFloat​(byte[] b, int offset)
      把字节数组转换成float
      static int toInt​(byte[] b)
      把字节数组转换成int
      static int toInt​(byte[] b, int offset)
      把字节数组转换成int
      static long toLong​(byte[] b)
      把字节数组转换成long
      static long toLong​(byte[] b, boolean high)
      把字节数组转换成long
      static long toLong​(byte[] b, int offset)
      把字节数组转换成long
      static long toLong​(byte[] b, int offset, boolean high)
      把字节数组转换成long
      static short toShort​(byte[] b)
      把字节数组转换成short
      static short toShort​(byte[] b, int offset)
      把字节数组转换成short
      static java.lang.String toString​(byte[] b)
      把字节数组转换成long
      static java.lang.String toString​(byte[] b, int offset)
      把字节数组转换成字符串
      static java.lang.String toString​(byte[] b, int offset, boolean is)
      把字节数组转换成字符串
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Bytes

        public Bytes()
    • Method Detail

      • isType

        public static boolean isType​(java.lang.Class<?> c)
        是否支持序列化类型
        Parameters:
        c - 类
        Returns:
        是否支持序列化
      • to

        public static java.lang.Object to​(byte[] b,
                                          java.lang.Class<?> c)
        根据c类型反序列化
        Parameters:
        b - 要转换的对象
        o - 偏移量 数组0就可以 定义成数组是为了引用传递
        c - 要转换的类型
        Returns:
        转换后的对象
      • toBytes

        public static byte[] toBytes​(java.lang.Object... objs)
        转换Object变成字节数组
        Parameters:
        objs - 对象
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(java.lang.Boolean is,
                                     java.lang.Object... objs)
        转换Object变成字节数组
        Parameters:
        objs - 对象
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(boolean b)
        转换Collection变成字节数组
        Parameters:
        b - 布尔
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(java.lang.Object obj)
        转换Object变成字节数组
        Parameters:
        obj - 对象
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(boolean is,
                                     java.lang.Object obj)
        转换Object变成字节数组
        Parameters:
        obj - 对象
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(Binary binary)
        转换Binary序列化
        Parameters:
        binary - Binary接口
        Returns:
        字节数组
      • binary

        public static byte[] binary​(java.lang.Object binary)
        转换Binary序列化
        Parameters:
        binary - Binary接口
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(ByteArray array)
        转换ByteArray变成字节数组
        Parameters:
        array - ByteArray类型
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(java.nio.ByteBuffer buff)
        转换ByteBuffer变成字节数组
        Parameters:
        buff - ByteBuffer类型
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(int i)
        转换int变成字节数组
        Parameters:
        i - int类型
        Returns:
        字节数组
      • toInt

        public static int toInt​(byte[] b)
        把字节数组转换成int
        Parameters:
        b - 字节数组
        Returns:
        int
      • toByte

        public static byte toByte​(byte[] b)
        把字节数组转换成int
        Parameters:
        b - 字节数组
        Returns:
        int
      • toByte

        public static byte toByte​(byte[] b,
                                  int offset)
        把字节数组转换成int
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        int
      • toBoolean

        public static boolean toBoolean​(byte[] b)
        把字节数组转换成int
        Parameters:
        b - 字节数组
        Returns:
        int
      • toBoolean

        public static boolean toBoolean​(byte[] b,
                                        int offset)
        把字节数组转换成int
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        int
      • toInt

        public static int toInt​(byte[] b,
                                int offset)
        把字节数组转换成int
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        int
      • toBytes

        public static byte[] toBytes​(short s)
        转换short变成字节数组
        Parameters:
        s - short类型
        Returns:
        字节数组
      • toShort

        public static short toShort​(byte[] b)
        把字节数组转换成short
        Parameters:
        b - 字节数组
        Returns:
        short
      • toShort

        public static short toShort​(byte[] b,
                                    int offset)
        把字节数组转换成short
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        short
      • toBytes

        public static byte[] toBytes​(char c)
        转换char变成字节数组
        Parameters:
        c - char类型
        Returns:
        字节数组
      • toChar

        public static char toChar​(byte[] b)
        把字节数组转换成char
        Parameters:
        b - 字节数组
        Returns:
        char
      • toChar

        public static char toChar​(byte[] b,
                                  int offset)
        把字节数组转换成char
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        char
      • toBytes

        public static byte[] toBytes​(float f)
        转换float变成字节数组
        Parameters:
        f - float类型
        Returns:
        字节数组
      • toFloat

        public static float toFloat​(byte[] b)
        把字节数组转换成float
        Parameters:
        b - 字节数组
        Returns:
        float
      • toFloat

        public static float toFloat​(byte[] b,
                                    int offset)
        把字节数组转换成float
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        float
      • toBytes

        public static byte[] toBytes​(double d)
        转换double变成字节数组
        Parameters:
        d - double类型
        Returns:
        字节数组
      • toDouble

        public static double toDouble​(byte[] b)
        把字节数组转换成double
        Parameters:
        b - 字节数组
        Returns:
        double
      • toDouble

        public static double toDouble​(byte[] b,
                                      int offset)
        把字节数组转换成double
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        double
      • toBytes

        public static byte[] toBytes​(long l)
        转换long变成字节数组
        Parameters:
        l - long类型
        Returns:
        字节数组
      • toLong

        public static long toLong​(byte[] b)
        把字节数组转换成long
        Parameters:
        b - 字节数组
        Returns:
        long
      • toLong

        public static long toLong​(byte[] b,
                                  boolean high)
        把字节数组转换成long
        Parameters:
        b - 字节数组
        high - true 高位在前 false 低位在前
        Returns:
        long
      • toLong

        public static long toLong​(byte[] b,
                                  int offset)
        把字节数组转换成long
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        long
      • toLong

        public static long toLong​(byte[] b,
                                  int offset,
                                  boolean high)
        把字节数组转换成long
        Parameters:
        b - 字节数组
        offset - 偏移
        high - true 高位在前 false 低位在前
        Returns:
        long
      • toBytes

        public static byte[] toBytes​(java.lang.String s)
        转换String变成字节数组
        Parameters:
        s - String类型
        Returns:
        字节数组
      • toBytes

        public static byte[] toBytes​(java.lang.String s,
                                     boolean is)
        转换String变成字节数组
        Parameters:
        s - String类型
        is - 是否加上长度
        Returns:
        字节数组
      • toString

        public static java.lang.String toString​(byte[] b)
        把字节数组转换成long
        Parameters:
        b - 字节数组
        Returns:
        long
      • toString

        public static java.lang.String toString​(byte[] b,
                                                int offset)
        把字节数组转换成字符串
        Parameters:
        b - 字节数组
        offset - 偏移
        Returns:
        字符串
      • toString

        public static java.lang.String toString​(byte[] b,
                                                int offset,
                                                boolean is)
        把字节数组转换成字符串
        Parameters:
        b - 字节数组
        offset - 偏移
        is - 是否读取长度
        Returns:
        字符串
      • copy

        public static byte[] copy​(byte[] b,
                                  int offset,
                                  int len)
        拷贝字节数组
        Parameters:
        b - 字节数组
        offset - 偏移
        len - 长度
        Returns:
        字节数组
      • toBean

        public static ByteArray toBean​(ByteArray array,
                                       byte[] b)
        把字节数组转换为ByteArray
        Parameters:
        array - ByteArray 对象
        b - 字节数组
        Returns:
        ByteArray对象
      • toBean

        public static ByteArray toBean​(ByteArray array,
                                       byte[] b,
                                       int offset)
        把字节数组转换为ByteArray
        Parameters:
        array - ByteArray 对象
        b - 字节数组
        offset - 偏移
        Returns:
        ByteArray对象
      • toBean

        public static ByteArray toBean​(ByteArray array,
                                       byte[] b,
                                       int offset,
                                       int len)
        把字节数组转换为ByteArray
        Parameters:
        array - ByteArray 对象
        b - 字节数组
        offset - 偏移
        len - 长度
        Returns:
        ByteArray对象
      • toBinary

        public static <B> B toBinary​(byte[] b,
                                     java.lang.Class<B> c)
        读取字节数组变成对象
        Type Parameters:
        B - 泛型
        Parameters:
        c - 序列化类
        b - 字节数组
        Returns:
        对象
      • add

        public static byte[] add​(byte[]... bs)
        字节数组相连
        Parameters:
        bs - 字节数组
        Returns:
        相连后的数组