Search in sources :

Example 1 with InputStreamAdapter

use of it.geosolutions.io.input.adapter.InputStreamAdapter in project imageio-ext by geosolutions-it.

the class GZIPImageInputStream method readTrailer.

/**
 * Reads GZIP member trailer.
 */
private void readTrailer() throws IOException {
    InputStream in = new InputStreamAdapter(this.iis);
    int n = inf.getRemaining();
    if (n > 0) {
        in = new SequenceInputStream(new ByteArrayInputStream(buf, len - n, n), in);
    }
    // Uses left-to-right evaluation order
    if ((readUInt(in) != crc.getValue()) || // should be preferred)
    (readUInt(in) != (inf.getTotalOut() & 0xffffffffL)))
        throw new IOException("Corrupt GZIP trailer");
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CheckedInputStream(java.util.zip.CheckedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) InputStreamAdapter(it.geosolutions.io.input.adapter.InputStreamAdapter) IOException(java.io.IOException)

Example 2 with InputStreamAdapter

use of it.geosolutions.io.input.adapter.InputStreamAdapter in project imageio-ext by geosolutions-it.

the class GZIPImageInputStream method readHeader.

/**
 * Reads GZIP member header.
 */
private void readHeader() throws IOException {
    CheckedInputStream in = new CheckedInputStream(new InputStreamAdapter(this.iis), crc);
    crc.reset();
    // Check header magic
    if (readUShort(in) != GZIP_MAGIC) {
        throw new IOException("Not in GZIP format");
    }
    // Check compression method
    if (readUByte(in) != 8) {
        throw new IOException("Unsupported compression method");
    }
    // Read flags
    int flg = readUByte(in);
    // Skip MTIME, XFL, and OS fields
    skipBytes(in, 6);
    // Skip optional extra field
    if ((flg & FEXTRA) == FEXTRA) {
        skipBytes(in, readUShort(in));
    }
    // Skip optional eraf name
    if ((flg & FNAME) == FNAME) {
        while (readUByte(in) != 0) ;
    }
    // Skip optional eraf comment
    if ((flg & FCOMMENT) == FCOMMENT) {
        while (readUByte(in) != 0) ;
    }
    // Check optional header CRC
    if ((flg & FHCRC) == FHCRC) {
        int v = (int) crc.getValue() & 0xffff;
        if (readUShort(in) != v) {
            throw new IOException("Corrupt GZIP header");
        }
    }
}
Also used : InputStreamAdapter(it.geosolutions.io.input.adapter.InputStreamAdapter) IOException(java.io.IOException) CheckedInputStream(java.util.zip.CheckedInputStream)

Aggregations

InputStreamAdapter (it.geosolutions.io.input.adapter.InputStreamAdapter)2 IOException (java.io.IOException)2 CheckedInputStream (java.util.zip.CheckedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 ImageInputStream (javax.imageio.stream.ImageInputStream)1