public class SerializeUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static Charset |
CHARSET |
static String |
SIGNED_MESSAGE_HEADER
The string that prefixes all text messages signed using Bitcoin keys.
|
static byte[] |
SIGNED_MESSAGE_HEADER_BYTES |
| 构造器和说明 |
|---|
SerializeUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
bigDecimal2Bytes(BigDecimal value) |
static byte[] |
bigInteger2Bytes(BigInteger value)
将大整数转为字节数组,结果是小端序字节数组
Converting large integers to byte arrays results in small endian byte arrays
|
static BigInteger |
bigIntegerFromBytes(byte[] array)
根据字节数组生成对应的大整数
Generate corresponding large integers from byte arrays
|
static byte[] |
bigIntegerToBytes(BigInteger b,
int numBytes)
The regular
BigInteger.toByteArray() method isn't quite what we often need: it appends a
leading zero to indicate that the number is positive and may need padding. |
static BigDecimal |
bytes2BigDecimal(byte[] bytes) |
static BigInteger |
decodeMPI(byte[] mpi,
boolean hasLength)
MPI encoded numbers are produced by the OpenSSL BN_bn2mpi function.
|
static void |
doubleToByteStream(double val,
OutputStream stream)
将Double类型数据写入输出流
|
static byte[] |
encodeMPI(BigInteger value,
boolean includeLength)
MPI encoded numbers are produced by the OpenSSL BN_bn2mpi function.
|
static byte[] |
formatMessageForSigning(String message)
Given a textual message, returns a byte buffer formatted as follows:
[24] "Bitcoin Signed Message:\n" [message.length as a varint] message
|
static void |
int16ToByteArrayLE(short val,
byte[] out,
int offset)
将一个short型数据以小端格式存储到指定字节数组指定的偏移量的连续2个字节中
|
static byte[] |
int16ToBytes(int x)
int转byte[] (只转int数据四个字节中的两个字节)
|
static void |
int16ToByteStreamLE(short val,
OutputStream stream)
Write 2 bytes to the output stream as unsigned 16-bit short in little endian format.
|
static void |
int32ToByteArrayLE(int val,
byte[] out,
int offset)
将一个int型数据以小端格式存储到指定字节数组指定的偏移量的连续4个字节中
|
static byte[] |
int32ToBytes(int x)
int转byte[]
|
static void |
int64ToByteStreamLE(long val,
OutputStream stream)
Write 8 bytes to the output stream as unsigned 64-bit long in little endian format.
|
static int |
readInt32LE(byte[] bytes,
int offset)
Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format.
|
static long |
readInt64LE(byte[] bytes,
int offset)
Parse 8 bytes from the byte array (starting at the offset) as unsigned 64-bit integer in little endian format.
|
static int |
readUint16(byte[] bytes,
int offset)
Parse 2 bytes from the byte array (starting at the offset) as unsigned 16-bit integer in little endian format.
|
static int |
readUint16BE(byte[] bytes,
int offset)
Parse 2 bytes from the byte array (starting at the offset) as unsigned 16-bit integer in big endian format.
|
static int |
readUint16LE(byte[] bytes,
int offset)
Parse 2 bytes from the byte array (starting at the offset) as unsigned 16-bit integer in little endian format.
|
static long |
readUint32(byte[] bytes,
int offset)
Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format.
|
static long |
readUint32BE(byte[] bytes,
int offset)
Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in big endian format.
|
static long |
readUint32LE(byte[] bytes,
int offset)
Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format.
|
static long |
readUint48(byte[] bytes,
int offset)
Parse 6 bytes from the byte array (starting at the offset) as unsigned 48-bit integer in little endian format.
|
static long |
readUint64(byte[] bytes,
int offset)
Parse 8 bytes from the byte array (starting at the offset) as unsigned 64-bit integer in little endian format.
|
static short |
readUint8LE(byte[] bytes,
int offset) |
static byte[] |
sha256hash160(byte[] input)
Calculates RIPEMD160(SHA256(input)).
|
static int |
sizeOfBigInteger()
获取BigInteger数据占的字节数
|
static int |
sizeOfBoolean()
获取Boolean数据占的字节数
|
static int |
sizeOfBytes(byte[] val)
获取byte[]占用的最小字节数(byte[]长度占用的最小字节数+byte[]长度)
|
static int |
sizeOfDouble(Double val) |
static int |
sizeOfInt16()
获取Int16数据占的字节数
|
static int |
sizeOfInt32()
获取Int32数据占的字节数
|
static int |
sizeOfInt64()
获取Int64数据占的字节数
|
static int |
sizeOfNonce()
获取nonce数据占的字节数
|
static int |
sizeOfNulsData(NulsData val)
获取NulsData对象所占字节长度
|
static int |
sizeOfString(String val)
字符串转为byte[]的长度
|
static int |
sizeOfUint16()
获取Uint16数据占的字节数
|
static int |
sizeOfUint32()
获取Uint32数据占的字节数
|
static int |
sizeOfUint48()
获取Unit48数据占的字节数
|
static int |
sizeOfUint8()
获取Uint8数据占的字节数
|
static int |
sizeOfVarInt(Integer val)
获取指定Integer占用的最小字节数
|
static int |
sizeOfVarInt(Long val)
计算Long型数据占几个字节
|
static void |
uint16ToByteStreamLE(int val,
OutputStream stream)
Write 2 bytes to the output stream as unsigned 16-bit integer in little endian format.
|
static void |
uint32ToByteArrayBE(long val,
byte[] out,
int offset)
将一个Long型数据以大端格式存储到指定字节数组指定的偏移量的连续4个字节中
|
static void |
uint32ToByteArrayLE(long val,
byte[] out,
int offset)
将一个Long型数据以小端格式存储到指定字节数组指定的偏移量的连续4个字节中
|
static void |
uint32ToByteStreamLE(long val,
OutputStream stream)
Write 4 bytes to the output stream as unsigned 32-bit long in little endian format.
|
static byte[] |
uint48ToBytes(long val)
long数据转byte[](只转前6个字节)
|
static byte[] |
uint64ToByteArray(long val)
long数据转byte[]
|
static void |
uint64ToByteArrayLE(long val,
byte[] out,
int offset)
将一个Long型数据以小端格式存储到指定字节数组指定的偏移量的连续8个字节中
|
static void |
uint64ToByteStreamLE(BigInteger val,
OutputStream stream)
Write 8 bytes to the output stream as unsigned 64-bit BigInteger in little endian format.
|
static void |
uint8ToByteStreamLE(short val,
OutputStream stream) |
public static final Charset CHARSET
public static final String SIGNED_MESSAGE_HEADER
public static final byte[] SIGNED_MESSAGE_HEADER_BYTES
public static BigInteger decodeMPI(byte[] mpi, boolean hasLength)
hasLength - can be set to false if the given array is missing the 4 byte length fieldpublic static byte[] encodeMPI(BigInteger value, boolean includeLength)
includeLength - indicates whether the 4 byte length field should be includedpublic static byte[] formatMessageForSigning(String message)
[24] "Bitcoin Signed Message:\n" [message.length as a varint] message
public static short readUint8LE(byte[] bytes,
int offset)
public static int readUint16LE(byte[] bytes,
int offset)
bytes - 字节数组offset - 偏移量(数组下标)public static int readUint16BE(byte[] bytes,
int offset)
bytes - 字节数组offset - 偏移量(数组下标)public static int readUint16(byte[] bytes,
int offset)
bytes - byte[]offset - int偏移量public static long readUint32LE(byte[] bytes,
int offset)
bytes - 字节数组offset - 偏移量(数组下标)public static int readInt32LE(byte[] bytes,
int offset)
bytes - 字节数组offset - 偏移量(数组下标)public static long readUint32BE(byte[] bytes,
int offset)
bytes - 字节数组offset - 偏移量(数组下标)public static long readUint32(byte[] bytes,
int offset)
bytes - byte[]offset - int偏移量public static long readUint48(byte[] bytes,
int offset)
bytes - byte[]offset - int偏移量public static long readInt64LE(byte[] bytes,
int offset)
bytes - 字节数组offset - 偏移量(数组下标)public static long readUint64(byte[] bytes,
int offset)
bytes - byte[]offset - int偏移量public static byte[] int16ToBytes(int x)
x - intpublic static byte[] int32ToBytes(int x)
x - intpublic static byte[] uint48ToBytes(long val)
val - longpublic static byte[] uint64ToByteArray(long val)
val - longpublic static byte[] sha256hash160(byte[] input)
input - 字节数组public static byte[] bigIntegerToBytes(BigInteger b, int numBytes)
BigInteger.toByteArray() method isn't quite what we often need: it appends a
leading zero to indicate that the number is positive and may need padding.b - the integer to format into a byte arraynumBytes - the desired size of the resulting byte arraypublic static void int16ToByteArrayLE(short val,
byte[] out,
int offset)
val - short数据out - 存放short型数据的字节数组offset - 偏移量public static void uint32ToByteArrayBE(long val,
byte[] out,
int offset)
val - long数据out - 存放Long型数据的字节数组offset - 偏移量public static void uint32ToByteArrayLE(long val,
byte[] out,
int offset)
val - long数据out - 存放Long型数据的字节数组offset - 偏移量public static void int32ToByteArrayLE(int val,
byte[] out,
int offset)
val - int数据out - 存放int型数据的字节数组offset - 偏移量public static void uint64ToByteArrayLE(long val,
byte[] out,
int offset)
val - long数据out - 存放Long型数据的字节数组offset - 偏移量public static void uint8ToByteStreamLE(short val,
OutputStream stream)
throws IOException
IOExceptionpublic static void int16ToByteStreamLE(short val,
OutputStream stream)
throws IOException
val - short数据stream - 输出流IOExceptionpublic static void uint16ToByteStreamLE(int val,
OutputStream stream)
throws IOException
val - int数据stream - 输出流IOExceptionpublic static void uint32ToByteStreamLE(long val,
OutputStream stream)
throws IOException
val - long数据stream - 输出流IOExceptionpublic static void int64ToByteStreamLE(long val,
OutputStream stream)
throws IOException
val - long数据stream - 输出流IOExceptionpublic static void uint64ToByteStreamLE(BigInteger val, OutputStream stream) throws IOException
val - BigInteger数据stream - 输出流IOExceptionpublic static void doubleToByteStream(double val,
OutputStream stream)
throws IOException
val - BigInteger数据stream - 输出流IOExceptionpublic static int sizeOfDouble(Double val)
public static int sizeOfString(String val)
val - Stringpublic static int sizeOfVarInt(Long val)
val - Longpublic static int sizeOfInt16()
public static int sizeOfBigInteger()
public static int sizeOfUint16()
public static int sizeOfUint8()
public static int sizeOfInt32()
public static int sizeOfUint32()
public static int sizeOfUint48()
public static int sizeOfInt64()
public static int sizeOfVarInt(Integer val)
val - Integerpublic static int sizeOfBoolean()
public static int sizeOfNonce()
public static int sizeOfBytes(byte[] val)
public static int sizeOfNulsData(NulsData val)
val - NulsDatapublic static BigInteger bigIntegerFromBytes(byte[] array)
array - 小端序的字节数组/Small-endian byte arraypublic static byte[] bigInteger2Bytes(BigInteger value)
value - 大整数、BigIntegerpublic static byte[] bigDecimal2Bytes(BigDecimal value) throws UnsupportedEncodingException
public static BigDecimal bytes2BigDecimal(byte[] bytes) throws UnsupportedEncodingException
Copyright © 2021. All rights reserved.