mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
refactor some stream code
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898221 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
839f1ad02a
commit
1d0b478c16
@ -17,11 +17,11 @@
|
|||||||
|
|
||||||
package org.apache.poi.hpbf.model;
|
package org.apache.poi.hpbf.model;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
|
||||||
@ -83,8 +83,9 @@ public abstract class HPBFPart {
|
|||||||
generateData();
|
generateData();
|
||||||
|
|
||||||
// Write out
|
// Write out
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
try (UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(data)) {
|
||||||
dir.createDocument(path[path.length-1], bais);
|
dir.createDocument(path[path.length-1], bais);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -18,11 +18,11 @@
|
|||||||
package org.apache.poi.hslf.blip;
|
package org.apache.poi.hslf.blip;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.ddf.EscherBSERecord;
|
import org.apache.poi.ddf.EscherBSERecord;
|
||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
@ -68,10 +68,11 @@ public final class EMF extends Metafile {
|
|||||||
Header header = new Header();
|
Header header = new Header();
|
||||||
header.read(rawdata, CHECKSUM_SIZE);
|
header.read(rawdata, CHECKSUM_SIZE);
|
||||||
|
|
||||||
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
try (
|
||||||
InputStream is = new ByteArrayInputStream(rawdata);
|
InputStream is = new UnsynchronizedByteArrayInputStream(rawdata);
|
||||||
InflaterInputStream inflater = new InflaterInputStream(is)) {
|
InflaterInputStream inflater = new InflaterInputStream(is);
|
||||||
|
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()
|
||||||
|
) {
|
||||||
long len = IOUtils.skipFully(is,header.getSize() + (long)CHECKSUM_SIZE);
|
long len = IOUtils.skipFully(is,header.getSize() + (long)CHECKSUM_SIZE);
|
||||||
assert(len == header.getSize() + CHECKSUM_SIZE);
|
assert(len == header.getSize() + CHECKSUM_SIZE);
|
||||||
|
|
||||||
|
|||||||
@ -19,21 +19,19 @@ package org.apache.poi.hslf.blip;
|
|||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.zip.DeflaterOutputStream;
|
import java.util.zip.DeflaterOutputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.ddf.EscherBSERecord;
|
import org.apache.poi.ddf.EscherBSERecord;
|
||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.util.LittleEndianInputStream;
|
import org.apache.poi.util.LittleEndianInputStream;
|
||||||
import org.apache.poi.util.LittleEndianOutputStream;
|
import org.apache.poi.util.LittleEndianOutputStream;
|
||||||
import org.apache.poi.util.Removal;
|
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,26 +88,29 @@ public abstract class Metafile extends HSLFPictureData {
|
|||||||
*/
|
*/
|
||||||
private int filter = 254;
|
private int filter = 254;
|
||||||
|
|
||||||
public void read(byte[] data, int offset){
|
public void read(byte[] data, int offset) {
|
||||||
@SuppressWarnings("resource")
|
try (
|
||||||
LittleEndianInputStream leis = new LittleEndianInputStream(
|
LittleEndianInputStream leis = new LittleEndianInputStream(
|
||||||
new ByteArrayInputStream(data, offset, RECORD_LENGTH));
|
new UnsynchronizedByteArrayInputStream(data, offset, RECORD_LENGTH))
|
||||||
|
) {
|
||||||
|
wmfsize = leis.readInt();
|
||||||
|
|
||||||
wmfsize = leis.readInt();
|
int left = leis.readInt();
|
||||||
|
int top = leis.readInt();
|
||||||
|
int right = leis.readInt();
|
||||||
|
int bottom = leis.readInt();
|
||||||
|
bounds.setBounds(left, top, right - left, bottom - top);
|
||||||
|
|
||||||
int left = leis.readInt();
|
int width = leis.readInt();
|
||||||
int top = leis.readInt();
|
int height = leis.readInt();
|
||||||
int right = leis.readInt();
|
size.setSize(width, height);
|
||||||
int bottom = leis.readInt();
|
|
||||||
bounds.setBounds(left, top, right-left, bottom-top);
|
|
||||||
|
|
||||||
int width = leis.readInt();
|
zipsize = leis.readInt();
|
||||||
int height = leis.readInt();
|
compression = leis.readUByte();
|
||||||
size.setSize(width, height);
|
filter = leis.readUByte();
|
||||||
|
} catch (IOException e) {
|
||||||
zipsize = leis.readInt();
|
throw new IllegalStateException(e);
|
||||||
compression = leis.readUByte();
|
}
|
||||||
filter = leis.readUByte();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(OutputStream out) throws IOException {
|
public void write(OutputStream out) throws IOException {
|
||||||
|
|||||||
@ -18,11 +18,11 @@
|
|||||||
package org.apache.poi.hslf.blip;
|
package org.apache.poi.hslf.blip;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||||
import org.apache.poi.ddf.EscherBSERecord;
|
import org.apache.poi.ddf.EscherBSERecord;
|
||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
@ -64,10 +64,10 @@ public final class WMF extends Metafile {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getData(){
|
public byte[] getData(){
|
||||||
try {
|
byte[] rawdata = getRawData();
|
||||||
byte[] rawdata = getRawData();
|
try (InputStream is = new UnsynchronizedByteArrayInputStream(rawdata)) {
|
||||||
|
|
||||||
|
|
||||||
InputStream is = new ByteArrayInputStream( rawdata );
|
|
||||||
Header header = new Header();
|
Header header = new Header();
|
||||||
header.read(rawdata, CHECKSUM_SIZE*getUIDInstanceCount());
|
header.read(rawdata, CHECKSUM_SIZE*getUIDInstanceCount());
|
||||||
long skipLen = header.getSize() + (long)CHECKSUM_SIZE*getUIDInstanceCount();
|
long skipLen = header.getSize() + (long)CHECKSUM_SIZE*getUIDInstanceCount();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user