public class Bytes
extends java.lang.Object
implements java.io.Serializable
toArray() - no copying.| Constructor and Description |
|---|
Bytes(byte[]... arrays) |
Bytes(java.io.ByteArrayOutputStream bos)
Construct from
ByteArrayOutputStream.toByteArray() bytes |
Bytes(java.io.InputStream in,
int length)
Construct by reading certain number of bytes, or all of them, from a stream.
|
Bytes(int size)
Create zero-filled instance of the specified size
|
Bytes(java.lang.String string) |
| Modifier and Type | Method and Description |
|---|---|
Bytes |
concatenate(byte[] otherBytes)
Return new buffer that is a concatenation of this and other.
|
Bytes |
concatenate(Bytes other)
Return new buffer that is a concatenation of this and other.
|
<T> Bytes |
concatenate(java.util.List<T> other) |
Bytes |
concatenate(java.lang.String s) |
Bytes |
correctIntFromGMP() |
void |
dump()
Writes dump to standard output, in the same format as
toDump(byte[]) |
static void |
dump(byte[] data)
Writes dump into standrd output.
|
boolean |
empty()
Check whether that the buffer is empty
|
boolean |
equals(java.lang.Object obj) |
Bytes |
fillRandom(int length)
Return new block that is contcatenation of this block and length random bytes
|
Bytes |
flipSelf()
Reverse order of own bytes.
|
static Bytes |
fromBase64(java.lang.String baseStr)
Decode Base64 string into Bytes instance
|
static Bytes |
fromBigInt(java.math.BigInteger value) |
static Bytes |
fromDouble(double value)
Create buffer as standard IEEE double(8) representation, little-endian.
|
static Bytes |
fromHex(java.lang.String hex)
Construct from hexadecimal string.
|
static Bytes |
fromString(java.lang.String str) |
byte[] |
getData() |
int |
hashCode() |
static byte[] |
hexToByteArray(java.lang.String hex)
Convert HEX string (ignoring whitespaces) to a byte[]
|
java.lang.String |
inspect()
Tries to convert bytes to UTF8 string.
|
Bytes |
padToSize(int size,
int fillByte)
Return new Bytes instance padded to the required size.
|
Bytes |
part(int start)
Extract part of the data from ith index (inclusive) to the end.
|
Bytes |
part(int start,
int length)
Extract a part of bytes into new instance.
|
static Bytes |
random(int length)
Create random bytes using
SecureRandom RNG in SHA1PRNG mode. |
Bytes |
reverse()
Create a copy with this data in reverse order
|
Bytes |
sha1() |
Bytes |
sha256(java.lang.Object... chunks)
Calculate SHA256 hash for this instance optionally with any number of additional chinks.
|
int |
size() |
byte[] |
toArray()
return underlying bytes.
|
java.lang.String |
toBase64() |
java.lang.String |
toBase64Lines() |
java.math.BigInteger |
toBigInteger()
Convert to a BigInteger value.
|
java.lang.Object |
toDouble() |
java.lang.String |
toDump() |
static java.lang.String[] |
toDump(byte[] data)
Generate dump string with address, hex bytes and ASCII character areas, line endings are "\n"s.
|
java.lang.String |
toHex() |
java.lang.String |
toHex(boolean useSpaces) |
static java.lang.String |
toHex(byte[] data) |
java.io.ByteArrayInputStream |
toInputStream()
Get an input stream to read contents of this buffer
|
java.lang.String |
toString() |
void |
write(java.io.OutputStream out) |
public Bytes(java.lang.String string)
public Bytes(byte[]... arrays)
public Bytes(java.io.InputStream in,
int length)
throws java.io.IOException
in - stream to read fromlength - how many bytes to read. If < 1, all file will be read.java.io.IOExceptionpublic Bytes(java.io.ByteArrayOutputStream bos)
ByteArrayOutputStream.toByteArray() bytesbos - public Bytes(int size)
size - desired sizepublic static Bytes fromHex(java.lang.String hex)
hex - hexidecomal string, like "FF 01"public static byte[] hexToByteArray(java.lang.String hex)
hex - strignpublic static Bytes fromBase64(java.lang.String baseStr)
baseStr - base64 string, possibily split to lines. Tries to add missing '=' to the endpublic static Bytes fromString(java.lang.String str)
public static Bytes fromBigInt(java.math.BigInteger value)
public static Bytes fromDouble(double value)
value - public int size()
public boolean empty()
public Bytes flipSelf()
public final byte[] toArray()
public void dump()
toDump(byte[])public static void dump(byte[] data)
toDump(byte[]).data - data to dump.public static java.lang.String[] toDump(byte[] data)
data - data to dumppublic java.lang.String toDump()
public java.math.BigInteger toBigInteger()
flipSelf() first if
necessary. See BigInteger.BigInteger(byte[]).public java.lang.String inspect()
public java.lang.String toBase64()
public java.lang.String toHex()
public java.lang.String toHex(boolean useSpaces)
public java.lang.String toBase64Lines()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic void write(java.io.OutputStream out)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.Object toDouble()
public Bytes sha1()
public Bytes sha256(java.lang.Object... chunks)
chunks - chunks to concatenate to the calculated hash. Each chink should be either Bytes instance, String or
byte[] arraypublic java.io.ByteArrayInputStream toInputStream()
public Bytes part(int start)
part(i, 0); see
part(int, int) for details. Note this method actually copy bytes!start - index to copy. If < 0 means offstet from the end.Bytes instance with copied bytes.public Bytes part(int start, int length)
Negative start index means offser from the last element:
part(-3, 3); // extracts last 3 bytes
Length == 0 means all bytes since the start:
part(10, 0); // all bytes starting with 10th part(-3, 0); // extracts last 3 bytesLength parameter is truncated if is bigger than remaining bytes length.
start - the start index, inclusive. If < 0 then means offset from the end of datalength - the number of bytes to copy. When 0 then the all the rest of bytes will be copied. Is automatically
truncated as need.Bytes instance with copied part.public Bytes fillRandom(int length)
length - public Bytes concatenate(Bytes other)
other - Bytes buffer to concatenatepublic <T> Bytes concatenate(java.util.List<T> other)
public Bytes concatenate(byte[] otherBytes)
otherBytes - Bytes buffer to concatenatepublic static Bytes random(int length)
SecureRandom RNG in SHA1PRNG mode.length - length if bytespublic Bytes padToSize(int size, int fillByte)
size - desired sizefillByte - fill byteBytes instance padded if necessary. Its size is always lesss or equal than size.public Bytes concatenate(java.lang.String s)
public Bytes reverse()
public Bytes correctIntFromGMP()
public static java.lang.String toHex(byte[] data)
public byte[] getData()