public class ByteStreamSerializer
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MAXREADLIMIT
This is the largest data size allowed for certificate transparency, so CAP
reading input at this size (by default).
|
| Constructor and Description |
|---|
ByteStreamSerializer() |
| Modifier and Type | Method and Description |
|---|---|
static int |
calculateByteLength(long datalen)
This helper function calculates the number of bytes required to store
the length of the given data.
|
static byte[] |
readDefiniteLength(java.io.InputStream is,
int datalen)
Reads datalen number of bytes from the specified input Stream.
|
static byte[] |
readDefiniteLengthFromStream(java.io.InputStream is,
int datalen,
int limit)
Read a fixed number of bytes from the specified input stream, but do not allow more
than limit to be read.
|
static byte[] |
readIndefiniteLength(java.io.InputStream is,
int maxBytes)
This function will read indefinite length data.
|
static byte[] |
readIndefiniteLength(java.io.InputStream is,
int maxBytes,
int readLimit)
This function will read indefinite length data.
|
static long |
readLongValue(java.io.InputStream is,
int bytes)
Reads the specified number of bytes and returns them as a Long value.
|
static void |
writeDefiniteLength(java.io.OutputStream os,
byte[] data)
Writes a pre-defined number of bytes to the specified output stream.
|
static void |
writeIndefiniteLength(java.io.OutputStream os,
byte[] data,
int maxByteLength)
Write the specified data of indefinite length to the given OutputStream.
|
static void |
writeLongValue(java.io.OutputStream os,
long value)
Writes the specified Long value to the given OutputStream
|
static void |
writeLongValue(java.io.OutputStream os,
long value,
int bytes)
Write the specified long value to the given OutputStream by converting the long value
to a stream of bytes where the most significant bit is first.
|
public static final int MAXREADLIMIT
public static byte[] readDefiniteLength(java.io.InputStream is,
int datalen)
throws java.io.IOException
is - The InputStream to read the datadatalen - the number of bytes to read from the inputStream.java.io.IOException - if error reading data, or data is too largepublic static byte[] readDefiniteLengthFromStream(java.io.InputStream is,
int datalen,
int limit)
throws java.io.IOException
is - The InputStream to read datadatalen - The length of the definite length data to be readlimit - the limit on the size of the datajava.io.IOException - if error reading data, or data is too largepublic static long readLongValue(java.io.InputStream is,
int bytes)
throws java.io.IOException
is - The input stream for the data to be readbytes - the number of bytes that will be used to compute the long valuejava.io.IOException - if error reading InputStream, or bytes is negative or greater than 8.public static byte[] readIndefiniteLength(java.io.InputStream is,
int maxBytes)
throws java.io.IOException
is - the inputstream used to read the datamaxBytes - the maximum size of the data length (used to read the length of the data)java.io.IOException - if an error occurs when reading the datapublic static byte[] readIndefiniteLength(java.io.InputStream is,
int maxBytes,
int readLimit)
throws java.io.IOException
Note: The maxBytes parameter is required so that the number of bytes required can be read. To know how many bytes need to be read, the maximum data length needs to be known so that the correct length can be read.
is - the inputstream used to read the datamaxBytes - the maximum size of the data lengthreadLimit - The absolute maximum data this function will allow to be readjava.io.IOException - if an error occurs when reading the datapublic static int calculateByteLength(long datalen)
datalen - the length of the data as an integerpublic static void writeLongValue(java.io.OutputStream os,
long value,
int bytes)
throws java.io.IOException
Note: The numbers of bytes must be in the range 0 to 8.
os - The OutputStream to write the datavalue - the long value that will be converted to a byte arraybytes - The number of bytes to write the datajava.io.IOException - if an error occurs when writing the data or bytes is not
in the range of 0 to 8.public static void writeLongValue(java.io.OutputStream os,
long value)
throws java.io.IOException
os - The OutputStream to write the long valuevalue - The value of the Longjava.io.IOException - if an error occurspublic static void writeIndefiniteLength(java.io.OutputStream os,
byte[] data,
int maxByteLength)
throws java.io.IOException
Note: This function writes the length of the data to the stream before writing the actual data. The size of the field holding the length is always the number of bytes that can hold the specified length. For example, if the length of data was 250 bytes, but the maxByteLength is 2^24-1, the data length value being written would occupy 3 bytes even those only 1 byte actually holds the value.
os - The OutputStream data will be written todata - The data to writemaxByteLength - The Maximum data Length to writejava.io.IOException - if an error occurspublic static void writeDefiniteLength(java.io.OutputStream os,
byte[] data)
throws java.io.IOException
os - The OutputStream to write the datadata - The data to be written.java.io.IOException - if problem occurs when writing to the stream