use of io.pravega.common.io.BoundedInputStream in project pravega by pravega.
the class DataFrame method read.
// endregion
// region Reading
/**
* Interprets the given InputStream as a DataFrame and returns a DataFrameEntryIterator for the entries serialized
* in it.
*
* @param source The InputStream to read from.
* @param length The size of the inputStream.
* @param address The DataFrame's address.
* @return A new DataFrameEntryIterator.
* @throws IOException If unable to parse the DataFrame's header from the InputStream.
*/
public static DataFrameEntryIterator read(InputStream source, int length, LogAddress address) throws IOException {
// Check to see that we have enough bytes in the InputStream.
ReadFrameHeader header = new ReadFrameHeader(source);
if (length < ReadFrameHeader.SERIALIZATION_LENGTH + header.getContentLength()) {
throw new SerializationException(String.format("Given buffer has insufficient number of bytes for this DataFrame. Expected %d, actual %d.", ReadFrameHeader.SERIALIZATION_LENGTH + header.getContentLength(), length));
}
BoundedInputStream contents = new BoundedInputStream(source, header.getContentLength());
return new DataFrameEntryIterator(contents, address, ReadFrameHeader.SERIALIZATION_LENGTH);
}
Aggregations