diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2020-04-16 22:11:16 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2020-04-16 22:11:16 +0000 |
commit | 7daeb4278c5ace8d263db087f8014e779140423d (patch) | |
tree | 2f8a086e508c1842c2e2b641f7d89a1eab850e30 /src/java/org/apache/poi/util/IOUtils.java | |
parent | cdefe69aab015c8ca06e8212969f81a4150273a2 (diff) | |
download | poi-7daeb4278c5ace8d263db087f8014e779140423d.tar.gz poi-7daeb4278c5ace8d263db087f8014e779140423d.zip |
Replace Allocate+System.arraycopy with Array.copyOf/Range and IOUtils.safelyClone
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876640 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/util/IOUtils.java')
-rw-r--r-- | src/java/org/apache/poi/util/IOUtils.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/util/IOUtils.java b/src/java/org/apache/poi/util/IOUtils.java index 1f5214589e..26f461f12d 100644 --- a/src/java/org/apache/poi/util/IOUtils.java +++ b/src/java/org/apache/poi/util/IOUtils.java @@ -28,6 +28,7 @@ import java.io.OutputStream; import java.io.PushbackInputStream; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; +import java.util.Arrays; import java.util.zip.CRC32; import java.util.zip.Checksum; @@ -35,6 +36,8 @@ import org.apache.poi.EmptyFileException; import org.apache.poi.POIDocument; import org.apache.poi.ss.usermodel.Workbook; + +@Internal public final class IOUtils { private static final POILogger logger = POILogFactory.getLogger( IOUtils.class ); @@ -610,6 +613,18 @@ public final class IOUtils { checkLength(length, maxLength); } + public static byte[] safelyClone(byte[] src, int offset, int length, int maxLength) { + if (src == null) { + return null; + } + assert(offset >= 0 && length >= 0 && maxLength >= 0); + safelyAllocateCheck(Math.min(src.length-offset,length), maxLength); + return Arrays.copyOfRange(src, offset, offset+length); + } + + + + /** * Simple utility function to check that you haven't hit EOF * when reading a byte. |