Search in sources :

Example 1 with InvalidDocumentHeader

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);
    }
}
Also used : InvalidDocumentHeader(datawave.query.exceptions.InvalidDocumentHeader) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) QueryException(datawave.webservice.query.exception.QueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) ByteArrayInputStream(java.io.ByteArrayInputStream) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException)

Aggregations

InvalidDocumentHeader (datawave.query.exceptions.InvalidDocumentHeader)1 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)1 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)1 QueryException (datawave.webservice.query.exception.QueryException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Inflater (java.util.zip.Inflater)1 InflaterInputStream (java.util.zip.InflaterInputStream)1