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);
}
}
use of java.util.zip.InflaterInputStream in project intellij-community by JetBrains.
the class RefCountingStorage method internalReadStream.
private BufferExposingByteArrayOutputStream internalReadStream(int record) throws IOException {
waitForPendingWriteForRecord(record);
byte[] result;
synchronized (myLock) {
result = super.readBytes(record);
}
InflaterInputStream in = new CustomInflaterInputStream(result);
try {
final BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
StreamUtil.copyStreamContent(in, outputStream);
return outputStream;
} finally {
in.close();
}
}
use of java.util.zip.InflaterInputStream in project intellij-community by JetBrains.
the class ConnectionStreams method setGzipped.
// Actions ================================================================
// Actions ================================================================
public void setGzipped() throws IOException {
loggedWriter.flush();
loggedOutputStream.flush();
deflaterOutputStream = new DeflaterOutputStream(connection.getOutputStream(), new Deflater(6));
setOutputStream(deflaterOutputStream);
setInputStream(new InflaterInputStream(connection.getInputStream()));
}
use of java.util.zip.InflaterInputStream in project gerrit by GerritCodeReview.
the class PatchList method readObject.
private void readObject(final ObjectInputStream input) throws IOException {
final ByteArrayInputStream buf = new ByteArrayInputStream(readBytes(input));
try (InflaterInputStream in = new InflaterInputStream(buf)) {
oldId = readCanBeNull(in);
newId = readNotNull(in);
isMerge = readVarInt32(in) != 0;
comparisonType = ComparisonType.readFrom(in);
insertions = readVarInt32(in);
deletions = readVarInt32(in);
final int cnt = readVarInt32(in);
final PatchListEntry[] all = new PatchListEntry[cnt];
for (int i = 0; i < all.length; i++) {
all[i] = PatchListEntry.readFrom(in);
}
patches = all;
}
}
Aggregations