more use of commons-io

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892658 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-08-27 18:54:01 +00:00
parent 5d0ea93bb4
commit 57e18ccd65
5 changed files with 12 additions and 9 deletions

View File

@ -21,7 +21,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
@ -30,6 +29,7 @@ import java.util.function.Supplier;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
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;
@ -177,7 +177,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
* @return the inflated picture data.
*/
private static byte[] inflatePictureData(byte[] data) {
try (InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data));
try (InflaterInputStream in = new InflaterInputStream(new UnsynchronizedByteArrayInputStream(data));
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
IOUtils.copy(in, out);
return out.toByteArray();

View File

@ -17,12 +17,12 @@
package org.apache.poi.poifs.filesystem;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
@ -224,7 +224,7 @@ public class Ole10Native {
*/
public static void createOleMarkerEntry(final DirectoryEntry parent) throws IOException {
if (!parent.hasEntry(OLE_MARKER_NAME)) {
parent.createDocument(OLE_MARKER_NAME, new ByteArrayInputStream(OLE_MARKER_BYTES));
parent.createDocument(OLE_MARKER_NAME, new UnsynchronizedByteArrayInputStream(OLE_MARKER_BYTES));
}
}

View File

@ -39,6 +39,7 @@ import javax.imageio.ImageTypeSpecifier;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.MemoryCacheImageInputStream;
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;
@ -91,7 +92,7 @@ public class BitmapImageRenderer implements ImageRenderer {
cachedImage = data.clone();
cachedContentType = contentType;
}
img = readImage(new ByteArrayInputStream(data), contentType);
img = readImage(new UnsynchronizedByteArrayInputStream(data), contentType);
}
/**
@ -110,6 +111,8 @@ public class BitmapImageRenderer implements ImageRenderer {
final InputStream bis;
if (data instanceof ByteArrayInputStream) {
bis = data;
} else if (data instanceof UnsynchronizedByteArrayInputStream) {
bis = data;
} else {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(0x3FFFF);
IOUtils.copy(data, bos);

View File

@ -19,11 +19,11 @@ package org.apache.poi.sl.image;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.util.Internal;
@ -38,7 +38,7 @@ public class ImageHeaderBitmap {
public ImageHeaderBitmap(byte[] data, int offset) {
BufferedImage img = null;
try {
img = ImageIO.read(new ByteArrayInputStream(data, offset, data.length-offset));
img = ImageIO.read(new UnsynchronizedByteArrayInputStream(data, offset, data.length-offset));
} catch (IOException e) {
LOG.atWarn().withThrowable(e).log("Can't determine image dimensions");
}

View File

@ -18,10 +18,10 @@
package org.apache.poi.sl.image;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.RecordFormatException;
@ -46,7 +46,7 @@ public final class ImageHeaderPNG {
public byte[] extractPNG() {
//
//Just cut it off!.
try (InputStream is = new ByteArrayInputStream(data)) {
try (InputStream is = new UnsynchronizedByteArrayInputStream(data)) {
if (is.skip(MAGIC_OFFSET) == MAGIC_OFFSET && FileMagic.valueOf(is) == FileMagic.PNG) {
return IOUtils.toByteArray(is);
}