use of datawave.query.exceptions.InvalidDocumentHeader in project datawave by NationalSecurityAgency.
the class DocumentSerialization method consumeHeader.
public static InputStream consumeHeader(byte[] data) throws InvalidDocumentHeader {
if (null == data || 3 > data.length) {
QueryException qe = new QueryException(DatawaveErrorCode.DATA_INVALID_ERROR, MessageFormat.format("Length: {0}", (null != data ? data.length : null)));
throw new InvalidDocumentHeader(qe);
}
ByteArrayInputStream bais = new ByteArrayInputStream(data);
int magic = readUShort(bais);
if (DOC_MAGIC != magic) {
NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.EXPECTED_HEADER_NOT_FOUND);
throw new InvalidDocumentHeader(qe);
}
int compression = readUByte(bais);
if (NONE == compression) {
return new ByteArrayInputStream(data, 3, data.length - 3);
} else if (GZIP == compression) {
ByteArrayInputStream bytes = new ByteArrayInputStream(data, 3, data.length - 3);
return new InflaterInputStream(bytes, new Inflater(), 1024);
} else {
BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.UNKNOWN_COMPRESSION_SCHEME, MessageFormat.format("{0}", compression));
throw new InvalidDocumentHeader(qe);
}
}
Aggregations