use of java.util.zip.InflaterInputStream in project poi by apache.
the class ExOleObjStg method getData.
/**
* Opens an input stream which will decompress the data on the fly.
*
* @return the data input stream.
*/
public InputStream getData() {
if (isCompressed()) {
int size = LittleEndian.getInt(_data);
InputStream compressedStream = new ByteArrayInputStream(_data, 4, _data.length);
return new BoundedInputStream(new InflaterInputStream(compressedStream), size);
} else {
return new ByteArrayInputStream(_data, 0, _data.length);
}
}
use of java.util.zip.InflaterInputStream in project poi by apache.
the class EscherMetafileBlip method inflatePictureData.
/**
* Decompresses the provided data, returning the inflated result.
*
* @param data the deflated picture data.
* @return the inflated picture data.
*/
private static byte[] inflatePictureData(byte[] data) {
try {
InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int readBytes;
while ((readBytes = in.read(buf)) > 0) {
out.write(buf, 0, readBytes);
}
return out.toByteArray();
} catch (IOException e) {
log.log(POILogger.WARN, "Possibly corrupt compression or non-compressed data", e);
return data;
}
}
use of java.util.zip.InflaterInputStream in project poi by apache.
the class EscherPictBlip method inflatePictureData.
/**
* Decompresses the provided data, returning the inflated result.
*
* @param data the deflated picture data.
* @return the inflated picture data.
*/
private static byte[] inflatePictureData(byte[] data) {
try {
InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int readBytes;
while ((readBytes = in.read(buf)) > 0) {
out.write(buf, 0, readBytes);
}
return out.toByteArray();
} catch (IOException e) {
log.log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e);
return data;
}
}
use of java.util.zip.InflaterInputStream in project poi by apache.
the class PICT method read.
private byte[] read(byte[] data, int pos) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(data);
Header header = new Header();
header.read(data, pos);
long bs_exp = (long) pos + header.getSize();
long bs_act = bis.skip(bs_exp);
if (bs_exp != bs_act) {
throw new EOFException();
}
byte[] chunk = new byte[4096];
ByteArrayOutputStream out = new ByteArrayOutputStream(header.getWmfSize());
InflaterInputStream inflater = new InflaterInputStream(bis);
try {
int count;
while ((count = inflater.read(chunk)) >= 0) {
out.write(chunk, 0, count);
// PICT zip-stream can be erroneous, so we clear the array to determine
// the maximum of read bytes, after the inflater crashed
bytefill(chunk, (byte) 0);
}
} catch (Exception e) {
int lastLen;
for (lastLen = chunk.length - 1; lastLen >= 0 && chunk[lastLen] == 0; lastLen--) ;
if (++lastLen > 0) {
if (header.getWmfSize() > out.size()) {
// sometimes the wmfsize is smaller than the amount of already successfully read bytes
// in this case we take the lastLen as-is, otherwise we truncate it to the given size
lastLen = Math.min(lastLen, header.getWmfSize() - out.size());
}
out.write(chunk, 0, lastLen);
}
// End of picture marker for PICT is 0x00 0xFF
LOG.log(POILogger.ERROR, "PICT zip-stream is invalid, read as much as possible. Uncompressed length of header: " + header.getWmfSize() + " / Read bytes: " + out.size(), e);
} finally {
inflater.close();
}
return out.toByteArray();
}
use of java.util.zip.InflaterInputStream in project poi by apache.
the class EMF method getData.
@Override
public byte[] getData() {
try {
byte[] rawdata = getRawData();
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream is = new ByteArrayInputStream(rawdata);
Header header = new Header();
header.read(rawdata, CHECKSUM_SIZE);
long len = is.skip(header.getSize() + (long) CHECKSUM_SIZE);
assert (len == header.getSize() + CHECKSUM_SIZE);
InflaterInputStream inflater = new InflaterInputStream(is);
byte[] chunk = new byte[4096];
int count;
while ((count = inflater.read(chunk)) >= 0) {
out.write(chunk, 0, count);
}
inflater.close();
return out.toByteArray();
} catch (IOException e) {
throw new HSLFException(e);
}
}
Aggregations