com.alibaba.dubbo.common.io
Class Bytes

java.lang.Object
  extended by com.alibaba.dubbo.common.io.Bytes

public class Bytes
extends Object

CodecUtils.

Author:
qian.lei

Method Summary
static byte[] base642bytes(String str)
          from base64 string.
static byte[] base642bytes(String str, char[] code)
          from base64 string.
static byte[] base642bytes(String str, int offset, int length)
          from base64 string.
static byte[] base642bytes(String str, int off, int len, char[] code)
          from base64 string.
static byte[] base642bytes(String str, int off, int len, String code)
          from base64 string.
static byte[] base642bytes(String str, String code)
          from base64 string.
static String bytes2base64(byte[] b)
          to base64 string.
static String bytes2base64(byte[] b, char[] code)
          to base64 string.
static String bytes2base64(byte[] b, int offset, int length)
          to base64 string.
static String bytes2base64(byte[] bs, int off, int len, char[] code)
          to base64 string.
static String bytes2base64(byte[] b, int offset, int length, String code)
          to base64 string.
static String bytes2base64(byte[] b, String code)
          to base64 string.
static double bytes2double(byte[] b)
          to long.
static double bytes2double(byte[] b, int off)
          to long.
static float bytes2float(byte[] b)
          to int.
static float bytes2float(byte[] b, int off)
          to int.
static String bytes2hex(byte[] bs)
          to hex string.
static String bytes2hex(byte[] bs, int off, int len)
          to hex string.
static int bytes2int(byte[] b)
          to int.
static int bytes2int(byte[] b, int off)
          to int.
static long bytes2long(byte[] b)
          to long.
static long bytes2long(byte[] b, int off)
          to long.
static short bytes2short(byte[] b)
          to short.
static short bytes2short(byte[] b, int off)
          to short.
static byte[] copyOf(byte[] src, int length)
          byte array copy.
static byte[] double2bytes(double v)
          to byte array.
static void double2bytes(double v, byte[] b)
          to byte array.
static void double2bytes(double v, byte[] b, int off)
          to byte array.
static byte[] float2bytes(float v)
          to byte array.
static void float2bytes(float v, byte[] b)
          to byte array.
static void float2bytes(float v, byte[] b, int off)
          to byte array.
static byte[] getMD5(byte[] source)
          get md5.
static byte[] getMD5(File file)
          get md5.
static byte[] getMD5(InputStream is)
          get md5.
static byte[] getMD5(String str)
          get md5.
static byte[] hex2bytes(String str)
          from hex string.
static byte[] hex2bytes(String str, int off, int len)
          from hex string.
static byte[] int2bytes(int v)
          to byte array.
static void int2bytes(int v, byte[] b)
          to byte array.
static void int2bytes(int v, byte[] b, int off)
          to byte array.
static byte[] long2bytes(long v)
          to byte array.
static void long2bytes(long v, byte[] b)
          to byte array.
static void long2bytes(long v, byte[] b, int off)
          to byte array.
static byte[] short2bytes(short v)
          to byte array.
static void short2bytes(short v, byte[] b)
          to byte array.
static void short2bytes(short v, byte[] b, int off)
          to byte array.
static byte[] unzip(byte[] bytes)
          unzip.
static byte[] zip(byte[] bytes)
          zip.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyOf

public static byte[] copyOf(byte[] src,
                            int length)
byte array copy.

Parameters:
src - src.
length - new length.
Returns:
new byte array.

short2bytes

public static byte[] short2bytes(short v)
to byte array.

Parameters:
v - value.
Returns:
byte[].

short2bytes

public static void short2bytes(short v,
                               byte[] b)
to byte array.

Parameters:
v - value.
b - byte array.

short2bytes

public static void short2bytes(short v,
                               byte[] b,
                               int off)
to byte array.

Parameters:
v - value.
b - byte array.

int2bytes

public static byte[] int2bytes(int v)
to byte array.

Parameters:
v - value.
Returns:
byte[].

int2bytes

public static void int2bytes(int v,
                             byte[] b)
to byte array.

Parameters:
v - value.
b - byte array.

int2bytes

public static void int2bytes(int v,
                             byte[] b,
                             int off)
to byte array.

Parameters:
v - value.
b - byte array.
off - array offset.

float2bytes

public static byte[] float2bytes(float v)
to byte array.

Parameters:
v - value.
Returns:
byte[].

float2bytes

public static void float2bytes(float v,
                               byte[] b)
to byte array.

Parameters:
v - value.
b - byte array.

float2bytes

public static void float2bytes(float v,
                               byte[] b,
                               int off)
to byte array.

Parameters:
v - value.
b - byte array.
off - array offset.

long2bytes

public static byte[] long2bytes(long v)
to byte array.

Parameters:
v - value.
Returns:
byte[].

long2bytes

public static void long2bytes(long v,
                              byte[] b)
to byte array.

Parameters:
v - value.
b - byte array.

long2bytes

public static void long2bytes(long v,
                              byte[] b,
                              int off)
to byte array.

Parameters:
v - value.
b - byte array.
off - array offset.

double2bytes

public static byte[] double2bytes(double v)
to byte array.

Parameters:
v - value.
Returns:
byte[].

double2bytes

public static void double2bytes(double v,
                                byte[] b)
to byte array.

Parameters:
v - value.
b - byte array.

double2bytes

public static void double2bytes(double v,
                                byte[] b,
                                int off)
to byte array.

Parameters:
v - value.
b - byte array.
off - array offset.

bytes2short

public static short bytes2short(byte[] b)
to short.

Parameters:
b - byte array.
Returns:
short.

bytes2short

public static short bytes2short(byte[] b,
                                int off)
to short.

Parameters:
b - byte array.
off - offset.
Returns:
short.

bytes2int

public static int bytes2int(byte[] b)
to int.

Parameters:
b - byte array.
Returns:
int.

bytes2int

public static int bytes2int(byte[] b,
                            int off)
to int.

Parameters:
b - byte array.
off - offset.
Returns:
int.

bytes2float

public static float bytes2float(byte[] b)
to int.

Parameters:
b - byte array.
Returns:
int.

bytes2float

public static float bytes2float(byte[] b,
                                int off)
to int.

Parameters:
b - byte array.
off - offset.
Returns:
int.

bytes2long

public static long bytes2long(byte[] b)
to long.

Parameters:
b - byte array.
Returns:
long.

bytes2long

public static long bytes2long(byte[] b,
                              int off)
to long.

Parameters:
b - byte array.
off - offset.
Returns:
long.

bytes2double

public static double bytes2double(byte[] b)
to long.

Parameters:
b - byte array.
Returns:
double.

bytes2double

public static double bytes2double(byte[] b,
                                  int off)
to long.

Parameters:
b - byte array.
off - offset.
Returns:
double.

bytes2hex

public static String bytes2hex(byte[] bs)
to hex string.

Parameters:
bs - byte array.
Returns:
hex string.

bytes2hex

public static String bytes2hex(byte[] bs,
                               int off,
                               int len)
to hex string.

Parameters:
bs - byte array.
off - offset.
len - length.
Returns:
hex string.

hex2bytes

public static byte[] hex2bytes(String str)
from hex string.

Parameters:
str - hex string.
Returns:
byte array.

hex2bytes

public static byte[] hex2bytes(String str,
                               int off,
                               int len)
from hex string.

Parameters:
str - hex string.
off - offset.
len - length.
Returns:
byte array.

bytes2base64

public static String bytes2base64(byte[] b)
to base64 string.

Parameters:
b - byte array.
Returns:
base64 string.

bytes2base64

public static String bytes2base64(byte[] b,
                                  int offset,
                                  int length)
to base64 string.

Parameters:
b - byte array.
Returns:
base64 string.

bytes2base64

public static String bytes2base64(byte[] b,
                                  String code)
to base64 string.

Parameters:
b - byte array.
code - base64 code string(0-63 is base64 char,64 is pad char).
Returns:
base64 string.

bytes2base64

public static String bytes2base64(byte[] b,
                                  int offset,
                                  int length,
                                  String code)
to base64 string.

Parameters:
b - byte array.
code - base64 code string(0-63 is base64 char,64 is pad char).
Returns:
base64 string.

bytes2base64

public static String bytes2base64(byte[] b,
                                  char[] code)
to base64 string.

Parameters:
b - byte array.
code - base64 code(0-63 is base64 char,64 is pad char).
Returns:
base64 string.

bytes2base64

public static String bytes2base64(byte[] bs,
                                  int off,
                                  int len,
                                  char[] code)
to base64 string.

Parameters:
bs - byte array.
off - offset.
len - length.
code - base64 code(0-63 is base64 char,64 is pad char).
Returns:
base64 string.

base642bytes

public static byte[] base642bytes(String str)
from base64 string.

Parameters:
str - base64 string.
Returns:
byte array.

base642bytes

public static byte[] base642bytes(String str,
                                  int offset,
                                  int length)
from base64 string.

Parameters:
str - base64 string.
offset - offset.
length - length.
Returns:
byte array.

base642bytes

public static byte[] base642bytes(String str,
                                  String code)
from base64 string.

Parameters:
str - base64 string.
code - base64 code(0-63 is base64 char,64 is pad char).
Returns:
byte array.

base642bytes

public static byte[] base642bytes(String str,
                                  int off,
                                  int len,
                                  String code)
from base64 string.

Parameters:
str - base64 string.
off - offset.
len - length.
code - base64 code(0-63 is base64 char,64 is pad char).
Returns:
byte array.

base642bytes

public static byte[] base642bytes(String str,
                                  char[] code)
from base64 string.

Parameters:
str - base64 string.
code - base64 code(0-63 is base64 char,64 is pad char).
Returns:
byte array.

base642bytes

public static byte[] base642bytes(String str,
                                  int off,
                                  int len,
                                  char[] code)
from base64 string.

Parameters:
str - base64 string.
off - offset.
len - length.
code - base64 code(0-63 is base64 char,64 is pad char).
Returns:
byte array.

zip

public static byte[] zip(byte[] bytes)
                  throws IOException
zip.

Parameters:
bytes - source.
Returns:
compressed byte array.
Throws:
IOException.
IOException

unzip

public static byte[] unzip(byte[] bytes)
                    throws IOException
unzip.

Parameters:
bytes - compressed byte array.
Returns:
byte uncompressed array.
Throws:
IOException

getMD5

public static byte[] getMD5(String str)
get md5.

Parameters:
str - input string.
Returns:
MD5 byte array.

getMD5

public static byte[] getMD5(byte[] source)
get md5.

Parameters:
source - byte array source.
Returns:
MD5 byte array.

getMD5

public static byte[] getMD5(File file)
                     throws IOException
get md5.

Parameters:
file - file source.
Returns:
MD5 byte array.
Throws:
IOException

getMD5

public static byte[] getMD5(InputStream is)
                     throws IOException
get md5.

Parameters:
is - input stream.
Returns:
MD5 byte array.
Throws:
IOException


Copyright © 2012–2017 Alibaba. All rights reserved.