mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
more use of commons-io
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892669 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
57e18ccd65
commit
1e6416551e
@ -17,7 +17,6 @@
|
||||
|
||||
package org.apache.poi.hpsf;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -26,6 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||
import org.apache.poi.EmptyFileException;
|
||||
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
|
||||
@ -598,7 +598,7 @@ public class PropertySet {
|
||||
* @throws IOException if an I/O exception occurs.
|
||||
*/
|
||||
public InputStream toInputStream() throws WritingNotSupportedException, IOException {
|
||||
return new ByteArrayInputStream(toBytes());
|
||||
return new UnsynchronizedByteArrayInputStream(toBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -18,11 +18,11 @@
|
||||
*/
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.poi.util.GenericRecordUtil;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
@ -278,7 +278,7 @@ public class DConRefRecord extends StandardRecord {
|
||||
}
|
||||
|
||||
private static RecordInputStream bytesToRIStream(byte[] data) {
|
||||
RecordInputStream ric = new RecordInputStream(new ByteArrayInputStream(data));
|
||||
RecordInputStream ric = new RecordInputStream(new UnsynchronizedByteArrayInputStream(data));
|
||||
ric.nextRecord();
|
||||
return ric;
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -48,7 +49,7 @@ public final class DrawingRecordForBiffViewer extends AbstractEscherHolderRecord
|
||||
{
|
||||
byte[] data = r.serialize();
|
||||
RecordInputStream rinp = new RecordInputStream(
|
||||
new ByteArrayInputStream(data)
|
||||
new UnsynchronizedByteArrayInputStream(data)
|
||||
);
|
||||
rinp.nextRecord();
|
||||
return rinp;
|
||||
|
||||
@ -17,10 +17,10 @@
|
||||
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.poi.ss.formula.ptg.Area3DPtg;
|
||||
@ -179,7 +179,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
|
||||
}
|
||||
|
||||
private static Ptg readRefPtg(byte[] formulaRawBytes) {
|
||||
LittleEndianInput in = new LittleEndianInputStream(new ByteArrayInputStream(formulaRawBytes));
|
||||
LittleEndianInput in = new LittleEndianInputStream(new UnsynchronizedByteArrayInputStream(formulaRawBytes));
|
||||
byte ptgSid = in.readByte();
|
||||
switch(ptgSid) {
|
||||
case AreaPtg.sid: return new AreaPtg(in);
|
||||
|
||||
@ -17,8 +17,7 @@
|
||||
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.poi.common.Duplicatable;
|
||||
import org.apache.poi.common.usermodel.GenericRecord;
|
||||
import org.apache.poi.util.GenericRecordJsonWriter;
|
||||
@ -76,7 +75,7 @@ public abstract class Record extends RecordBase implements Duplicatable, Generic
|
||||
// Do it via a re-serialization
|
||||
// It's a cheat, but it works...
|
||||
byte[] b = serialize();
|
||||
RecordInputStream rinp = new RecordInputStream(new ByteArrayInputStream(b));
|
||||
RecordInputStream rinp = new RecordInputStream(new UnsynchronizedByteArrayInputStream(b));
|
||||
rinp.nextRecord();
|
||||
|
||||
Record[] r = RecordFactory.createRecord(rinp);
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.poi.ddf.DefaultEscherRecordFactory;
|
||||
import org.apache.poi.ddf.EscherBSERecord;
|
||||
import org.apache.poi.ddf.EscherBlipRecord;
|
||||
@ -191,7 +191,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
|
||||
EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
|
||||
byte[] data = bse.getBlipRecord().getPicturedata();
|
||||
int type = bse.getBlipTypeWin32();
|
||||
return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type);
|
||||
return ImageUtils.getImageDimension(new UnsynchronizedByteArrayInputStream(data), type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -22,7 +22,6 @@ import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_
|
||||
import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -46,6 +45,7 @@ import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -1305,7 +1305,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
|
||||
DocumentNode workbookNode = (DocumentNode) dir.getEntry(
|
||||
getWorkbookDirEntryName(dir));
|
||||
POIFSDocument workbookDoc = new POIFSDocument(workbookNode);
|
||||
workbookDoc.replaceContents(new ByteArrayInputStream(getBytes()));
|
||||
workbookDoc.replaceContents(new UnsynchronizedByteArrayInputStream(getBytes()));
|
||||
|
||||
// Update the properties streams in the file
|
||||
writeProperties();
|
||||
@ -1367,7 +1367,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
|
||||
List<String> excepts = new ArrayList<>(1);
|
||||
|
||||
// Write out the Workbook stream
|
||||
fs.createDocument(new ByteArrayInputStream(getBytes()), "Workbook");
|
||||
fs.createDocument(new UnsynchronizedByteArrayInputStream(getBytes()), "Workbook");
|
||||
|
||||
// Write out our HPFS properties, if we have them
|
||||
writeProperties(fs, excepts);
|
||||
|
||||
@ -17,10 +17,10 @@
|
||||
|
||||
package org.apache.poi.poifs.filesystem;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||
import org.apache.poi.poifs.common.POIFSConstants;
|
||||
import org.apache.poi.poifs.property.DocumentProperty;
|
||||
@ -105,7 +105,7 @@ public final class DocumentOutputStream extends OutputStream {
|
||||
}
|
||||
|
||||
// Have an empty one created for now
|
||||
return parent.createDocument(name, new ByteArrayInputStream(new byte[0]));
|
||||
return parent.createDocument(name, new UnsynchronizedByteArrayInputStream(new byte[0]));
|
||||
}
|
||||
|
||||
private void checkBufferSize() throws IOException {
|
||||
|
||||
@ -21,7 +21,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
|
||||
import static org.apache.poi.util.StringUtil.endsWithIgnoreCase;
|
||||
import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
@ -37,6 +36,7 @@ import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -232,7 +232,7 @@ public class VBAMacroReader implements Closeable {
|
||||
} else {
|
||||
// Decompress a previously found module and store the decompressed result into module.buf
|
||||
InputStream stream = new RLEDecompressingInputStream(
|
||||
new ByteArrayInputStream(module.buf, moduleOffset, module.buf.length - moduleOffset)
|
||||
new UnsynchronizedByteArrayInputStream(module.buf, moduleOffset, module.buf.length - moduleOffset)
|
||||
);
|
||||
module.read(stream);
|
||||
stream.close();
|
||||
@ -274,7 +274,7 @@ public class VBAMacroReader implements Closeable {
|
||||
}
|
||||
|
||||
if (decompressedBytes != null) {
|
||||
module.read(new ByteArrayInputStream(decompressedBytes));
|
||||
module.read(new UnsynchronizedByteArrayInputStream(decompressedBytes));
|
||||
}
|
||||
}
|
||||
|
||||
@ -802,7 +802,7 @@ public class VBAMacroReader implements Closeable {
|
||||
if (w <= 0 || (w & 0x7000) != 0x3000) {
|
||||
continue;
|
||||
}
|
||||
decompressed = tryToDecompress(new ByteArrayInputStream(compressed, i, compressed.length - i));
|
||||
decompressed = tryToDecompress(new UnsynchronizedByteArrayInputStream(compressed, i, compressed.length - i));
|
||||
if (decompressed != null) {
|
||||
if (decompressed.length > 9) {
|
||||
//this is a complete hack. The challenge is that there
|
||||
|
||||
@ -20,7 +20,6 @@ import static org.apache.poi.util.Units.EMU_PER_PIXEL;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
@ -31,6 +30,7 @@ import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
||||
@ -151,7 +151,7 @@ public final class ImageUtils {
|
||||
|
||||
// in pixel
|
||||
final Dimension imgSize = (scaleX == Double.MAX_VALUE || scaleY == Double.MAX_VALUE)
|
||||
? getImageDimension(new ByteArrayInputStream(data.getData()), data.getPictureType())
|
||||
? getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType())
|
||||
: new Dimension();
|
||||
|
||||
// in emus
|
||||
@ -191,7 +191,7 @@ public final class ImageUtils {
|
||||
Dimension imgSize = null;
|
||||
if (anchor.getCol2() < anchor.getCol1() || anchor.getRow2() < anchor.getRow1()) {
|
||||
PictureData data = picture.getPictureData();
|
||||
imgSize = getImageDimension(new ByteArrayInputStream(data.getData()), data.getPictureType());
|
||||
imgSize = getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType());
|
||||
}
|
||||
|
||||
int w = getDimFromCell(imgSize == null ? 0 : imgSize.getWidth(), anchor.getCol1(), anchor.getDx1(), anchor.getCol2(), anchor.getDx2(),
|
||||
|
||||
@ -17,11 +17,11 @@
|
||||
|
||||
package org.apache.poi.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||
|
||||
/**
|
||||
@ -278,8 +278,8 @@ public class RLEDecompressingInputStream extends InputStream {
|
||||
|
||||
public static byte[] decompress(byte[] compressed, int offset, int length) throws IOException {
|
||||
try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
|
||||
InputStream instream = new ByteArrayInputStream(compressed, offset, length);
|
||||
InputStream stream = new RLEDecompressingInputStream(instream)) {
|
||||
InputStream instream = new UnsynchronizedByteArrayInputStream(compressed, offset, length);
|
||||
InputStream stream = new RLEDecompressingInputStream(instream)) {
|
||||
|
||||
IOUtils.copy(stream, out);
|
||||
return out.toByteArray();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user