Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndian.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndian.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndian.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndian.java Thu Apr 16 
22:11:16 2020
@@ -26,93 +26,38 @@ import java.io.Serializable;
  * a utility class for handling little-endian numbers, which the 80x86 world is
  * replete with. The methods are all static, and input/output is from/to byte
  * arrays, or from InputStreams.
- * 
- * @author Marc Johnson (mjohnson at apache dot org)
- * @author Andrew Oliver (acoliver at apache dot org)
  */
-public class LittleEndian implements LittleEndianConsts
-{
+@Internal
+public final class LittleEndian implements LittleEndianConsts {
 
     /**
      * Exception to handle buffer underruns
-     * 
+     *
      * @author Marc Johnson (mjohnson at apache dot org)
      */
-    public static final class BufferUnderrunException extends IOException
-    {
+    public static final class BufferUnderrunException extends IOException {
         /**
          * Serial version UID
-         * 
+         *
          * @see Serializable
          */
         private static final long serialVersionUID = 8736973884877006145L;
 
-        BufferUnderrunException()
-        {
+        BufferUnderrunException() {
             super( "buffer underrun" );
         }
     }
 
     /**
-     * Copy a portion of a byte array
-     * 
-     * @param data
-     *            the original byte array
-     * @param offset
-     *            Where to start copying from.
-     * @param size
-     *            Number of bytes to copy.
-     * @return The byteArray value
-     *
-     * @see #getByteArray(byte[], int, int, int) if size is not a constant
-     *
-     * @throws IndexOutOfBoundsException
-     *             - if copying would cause access of data outside array 
bounds.
-     */
-    public static byte[] getByteArray( byte[] data, int offset, int size )
-    {
-        byte[] copy = new byte[size];
-        System.arraycopy( data, offset, copy, 0, size );
-
-        return copy;
-    }
-
-    /**
-     * Copy a portion of a byte array
-     *
-     * @param data
-     *            the original byte array
-     * @param offset
-     *            Where to start copying from.
-     * @param size
-     *            Number of bytes to copy.
-     * @param maxSize
-     *            Size must be <= maxSize or an exception is thrown.
-     *            Use this to avoid potential OOMs on corrupt data.
-     * @return The byteArray value
-     * @throws IndexOutOfBoundsException
-     *             - if copying would cause access of data outside array 
bounds.
-     */
-    public static byte[] getByteArray( byte[] data, int offset, int size, int 
maxSize)
-    {
-        byte[] copy = IOUtils.safelyAllocate(size, maxSize);
-        System.arraycopy( data, offset, copy, 0, size );
-
-        return copy;
-    }
-
-
-    /**
      * get a double value from a byte array, reads it in little endian format
      * then converts the resulting revolting IEEE 754 (curse them) floating
      * point number to a happy java double
-     * 
+     *
      * @param data
      *            the byte array
      * @return the double (64-bit) value
      */
-    public static double getDouble( byte[] data )
-    {
+    public static double getDouble( byte[] data ) {
         return Double.longBitsToDouble( getLong( data, 0 ) );
     }
 
@@ -120,15 +65,14 @@ public class LittleEndian implements Lit
      * get a double value from a byte array, reads it in little endian format
      * then converts the resulting revolting IEEE 754 (curse them) floating
      * point number to a happy java double
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @return the double (64-bit) value
      */
-    public static double getDouble( byte[] data, int offset )
-    {
+    public static double getDouble( byte[] data, int offset ) {
         return Double.longBitsToDouble( getLong( data, offset ) );
     }
 
@@ -136,13 +80,12 @@ public class LittleEndian implements Lit
      * get a float value from a byte array, reads it in little endian format
      * then converts the resulting revolting IEEE 754 (curse them) floating
      * point number to a happy java float
-     * 
+     *
      * @param data
      *            the byte array
      * @return the double (64-bit) value
      */
-    public static float getFloat( byte[] data )
-    {
+    public static float getFloat( byte[] data ) {
         return getFloat( data, 0 );
     }
 
@@ -150,72 +93,67 @@ public class LittleEndian implements Lit
      * get a float value from a byte array, reads it in little endian format
      * then converts the resulting revolting IEEE 754 (curse them) floating
      * point number to a happy java float
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @return the double (64-bit) value
      */
-    public static float getFloat( byte[] data, int offset )
-    {
+    public static float getFloat( byte[] data, int offset ) {
         return Float.intBitsToFloat( getInt( data, offset ) );
     }
 
     /**
      * get an int value from the beginning of a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @return the int (32-bit) value
      */
-    public static int getInt( byte[] data )
-    {
+    public static int getInt( byte[] data ) {
         return getInt( data, 0 );
     }
 
     /**
      * get an int value from a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @return the int (32-bit) value
      */
-    public static int getInt( byte[] data, int offset )
-    {
+    public static int getInt( byte[] data, int offset ) {
         int i = offset;
         int b0 = data[i++] & 0xFF;
         int b1 = data[i++] & 0xFF;
         int b2 = data[i++] & 0xFF;
-        int b3 = data[i++] & 0xFF;
-        return ( b3 << 24 ) + ( b2 << 16 ) + ( b1 << 8 ) + ( b0 << 0 );
+        int b3 = data[i  ] & 0xFF;
+        return ( b3 << 24 ) + ( b2 << 16 ) + ( b1 << 8 ) + (b0);
     }
 
     /**
      * get a long value from a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @return the long (64-bit) value
      */
-    public static long getLong( byte[] data )
-    {
+    public static long getLong( byte[] data ) {
         return getLong( data, 0 );
     }
 
     /**
      * get a long value from a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @return the long (64-bit) value
      */
-    public static long getLong( byte[] data, int offset )
-    {
+    public static long getLong( byte[] data, int offset ) {
         long result = 0xff & data[offset + 7];
 
         for ( int j = offset + LONG_SIZE - 1; j >= offset; j-- )
@@ -228,35 +166,33 @@ public class LittleEndian implements Lit
 
     /**
      * get a short value from the beginning of a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @return the short (16-bit) value
      */
-    public static short getShort( byte[] data )
-    {
+    public static short getShort( byte[] data ) {
         return getShort( data, 0 );
     }
 
     /**
      * get a short value from a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @return the short (16-bit) value
      */
-    public static short getShort( byte[] data, int offset )
-    {
+    public static short getShort( byte[] data, int offset ) {
         int b0 = data[offset] & 0xFF;
         int b1 = data[offset + 1] & 0xFF;
-        return (short) ( ( b1 << 8 ) + ( b0 << 0 ) );
+        return (short) ( ( b1 << 8 ) + (b0) );
     }
 
     /**
      * Read short array
-     * 
+     *
      * @param data
      *            the original byte array
      * @param offset
@@ -266,8 +202,7 @@ public class LittleEndian implements Lit
      * @throws IndexOutOfBoundsException
      *             - if read would cause access of data outside array bounds.
      */
-    public static short[] getShortArray( byte[] data, int offset, int size )
-    {
+    public static short[] getShortArray( byte[] data, int offset, int size ) {
         short[] result = new short[size / SHORT_SIZE];
         for ( int i = 0; i < result.length; i++ )
         {
@@ -278,83 +213,77 @@ public class LittleEndian implements Lit
 
     /**
      * get the unsigned value of a byte.
-     * 
+     *
      * @param data
      *            the byte array.
      * @return the unsigned value of the byte as a 16 bit short
      */
-    public static short getUByte( byte[] data )
-    {
+    public static short getUByte( byte[] data ) {
         return (short) ( data[0] & 0xFF );
     }
 
     /**
      * get the unsigned value of a byte.
-     * 
+     *
      * @param data
      *            the byte array.
      * @param offset
      *            a starting offset into the byte array.
      * @return the unsigned value of the byte as a 16 bit short
      */
-    public static short getUByte( byte[] data, int offset )
-    {
+    public static short getUByte( byte[] data, int offset ) {
         return (short) ( data[offset] & 0xFF );
     }
 
     /**
      * get an unsigned int value from a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @return the unsigned int (32-bit) value in a long
      */
-    public static long getUInt( byte[] data )
-    {
+    public static long getUInt( byte[] data ) {
         return getUInt( data, 0 );
     }
 
     /**
      * get an unsigned int value from a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @return the unsigned int (32-bit) value in a long
      */
-    public static long getUInt( byte[] data, int offset )
-    {
+    public static long getUInt( byte[] data, int offset ) {
         long retNum = getInt( data, offset );
-        return retNum & 0x00FFFFFFFFl;
+        return retNum & 0x00FFFFFFFFL;
     }
 
     /**
      * get an unsigned short value from the beginning of a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @return the unsigned short (16-bit) value in an int
      */
-    public static int getUShort( byte[] data )
-    {
+    public static int getUShort( byte[] data ) {
         return getUShort( data, 0 );
     }
 
     /**
      * get an unsigned short value from a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @return the unsigned short (16-bit) value in an integer
      */
-    public static int getUShort( byte[] data, int offset )
-    {
+    public static int getUShort( byte[] data, int offset ) {
         int b0 = data[offset] & 0xFF;
         int b1 = data[offset + 1] & 0xFF;
-        return ( b1 << 8 ) + ( b0 << 0 );
+        return ( b1 << 8 ) + (b0);
     }
 
     /**
@@ -366,14 +295,13 @@ public class LittleEndian implements Lit
      * </p>
      * Added for consistency with other put~() methods
      */
-    public static void putByte( byte[] data, int offset, int value )
-    {
+    public static void putByte( byte[] data, int offset, int value ) {
         data[offset] = (byte) value;
     }
 
     /**
      * put a double value into a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
@@ -381,14 +309,13 @@ public class LittleEndian implements Lit
      * @param value
      *            the double (64-bit) value
      */
-    public static void putDouble( byte[] data, int offset, double value )
-    {
+    public static void putDouble( byte[] data, int offset, double value ) {
         putLong( data, offset, Double.doubleToLongBits( value ) );
     }
 
     /**
      * put a double value into a byte array
-     * 
+     *
      * @param value
      *            the double (64-bit) value
      * @param outputStream
@@ -396,15 +323,13 @@ public class LittleEndian implements Lit
      * @throws IOException
      *             if an I/O error occurs
      */
-    public static void putDouble( double value, OutputStream outputStream )
-            throws IOException
-    {
+    public static void putDouble( double value, OutputStream outputStream ) 
throws IOException {
         putLong( Double.doubleToLongBits( value ), outputStream );
     }
 
     /**
      * put a float value into a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
@@ -412,14 +337,13 @@ public class LittleEndian implements Lit
      * @param value
      *            the float (32-bit) value
      */
-    public static void putFloat( byte[] data, int offset, float value )
-    {
+    public static void putFloat( byte[] data, int offset, float value ) {
         putInt( data, offset, Float.floatToIntBits( value ) );
     }
 
     /**
      * put a float value into a byte array
-     * 
+     *
      * @param value
      *            the float (32-bit) value
      * @param outputStream
@@ -427,15 +351,14 @@ public class LittleEndian implements Lit
      * @throws IOException
      *             if an I/O error occurs
      */
-    public static void putFloat( float value, OutputStream outputStream )
-            throws IOException
-    {
+    @SuppressWarnings("unused")
+    public static void putFloat(float value, OutputStream outputStream ) 
throws IOException {
         putInt( Float.floatToIntBits( value ), outputStream );
     }
 
     /**
      * put an int value into a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
@@ -443,18 +366,17 @@ public class LittleEndian implements Lit
      * @param value
      *            the int (32-bit) value
      */
-    public static void putInt( byte[] data, int offset, int value )
-    {
+    public static void putInt( byte[] data, int offset, int value ) {
         int i = offset;
-        data[i++] = (byte) ( ( value >>> 0 ) & 0xFF );
-        data[i++] = (byte) ( ( value >>> 8 ) & 0xFF );
+        data[i++] = (byte) ( ( value        ) & 0xFF );
+        data[i++] = (byte) ( ( value >>> 8  ) & 0xFF );
         data[i++] = (byte) ( ( value >>> 16 ) & 0xFF );
-        data[i++] = (byte) ( ( value >>> 24 ) & 0xFF );
+        data[i] =   (byte) ( ( value >>> 24 ) & 0xFF );
     }
 
     /**
      * Put int into output stream
-     * 
+     *
      * @param value
      *            the int (32-bit) value
      * @param outputStream
@@ -462,18 +384,16 @@ public class LittleEndian implements Lit
      * @throws IOException
      *             if an I/O error occurs
      */
-    public static void putInt( int value, OutputStream outputStream )
-            throws IOException
-    {
-        outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
-        outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
+    public static void putInt( int value, OutputStream outputStream ) throws 
IOException {
+        outputStream.write( (byte) ( ( value        ) & 0xFF ) );
+        outputStream.write( (byte) ( ( value >>>  8 ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 16 ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 24 ) & 0xFF ) );
     }
 
     /**
      * put a long value into a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
@@ -481,10 +401,9 @@ public class LittleEndian implements Lit
      * @param value
      *            the long (64-bit) value
      */
-    public static void putLong( byte[] data, int offset, long value )
-    {
-        data[offset + 0] = (byte) ( ( value >>> 0 ) & 0xFF );
-        data[offset + 1] = (byte) ( ( value >>> 8 ) & 0xFF );
+    public static void putLong( byte[] data, int offset, long value ) {
+        data[offset    ] = (byte) ( ( value        ) & 0xFF );
+        data[offset + 1] = (byte) ( ( value >>>  8 ) & 0xFF );
         data[offset + 2] = (byte) ( ( value >>> 16 ) & 0xFF );
         data[offset + 3] = (byte) ( ( value >>> 24 ) & 0xFF );
         data[offset + 4] = (byte) ( ( value >>> 32 ) & 0xFF );
@@ -495,7 +414,7 @@ public class LittleEndian implements Lit
 
     /**
      * Put long into output stream
-     * 
+     *
      * @param value
      *            the long (64-bit) value
      * @param outputStream
@@ -503,11 +422,9 @@ public class LittleEndian implements Lit
      * @throws IOException
      *             if an I/O error occurs
      */
-    public static void putLong( long value, OutputStream outputStream )
-            throws IOException
-    {
-        outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
-        outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
+    public static void putLong( long value, OutputStream outputStream ) throws 
IOException {
+        outputStream.write( (byte) ( ( value        ) & 0xFF ) );
+        outputStream.write( (byte) ( ( value >>>  8 ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 16 ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 24 ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 32 ) & 0xFF ) );
@@ -518,7 +435,7 @@ public class LittleEndian implements Lit
 
     /**
      * put a short value into a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
@@ -526,16 +443,15 @@ public class LittleEndian implements Lit
      * @param value
      *            the short (16-bit) value
      */
-    public static void putShort( byte[] data, int offset, short value )
-    {
+    public static void putShort( byte[] data, int offset, short value ) {
         int i = offset;
-        data[i++] = (byte) ( ( value >>> 0 ) & 0xFF );
-        data[i++] = (byte) ( ( value >>> 8 ) & 0xFF );
+        data[i++] = (byte) ( ( value       ) & 0xFF );
+        data[i  ] = (byte) ( ( value >>> 8 ) & 0xFF );
     }
 
     /**
      * Put signed short into output stream
-     * 
+     *
      * @param value
      *            the short (16-bit) value
      * @param outputStream
@@ -543,16 +459,14 @@ public class LittleEndian implements Lit
      * @throws IOException
      *             if an I/O error occurs
      */
-    public static void putShort( OutputStream outputStream, short value )
-            throws IOException
-    {
-        outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
+    public static void putShort( OutputStream outputStream, short value ) 
throws IOException {
+        outputStream.write( (byte) ( ( value       ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
     }
 
     /**
      * Stores short array in buffer
-     * 
+     *
      * @param data
      *            the byte array
      * @param startOffset
@@ -560,9 +474,7 @@ public class LittleEndian implements Lit
      * @param value
      *            the short (16-bit) values
      */
-    public static void putShortArray( byte[] data, int startOffset,
-            short[] value )
-    {
+    public static void putShortArray( byte[] data, int startOffset, short[] 
value ) {
         int offset = startOffset;
         for ( short s : value )
         {
@@ -573,47 +485,45 @@ public class LittleEndian implements Lit
 
     /**
      * put an unsigned byte value into a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @param value
      *            the short (16-bit) value
-     * 
+     *
      * @exception ArrayIndexOutOfBoundsException
      *                may be thrown
      */
-    public static void putUByte( byte[] data, int offset, short value )
-    {
+    public static void putUByte( byte[] data, int offset, short value ) {
         data[offset] = (byte) ( value & 0xFF );
     }
 
     /**
      * put an unsigned int value into a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @param value
      *            the int (32-bit) value
-     * 
+     *
      * @exception ArrayIndexOutOfBoundsException
      *                may be thrown
      */
-    public static void putUInt( byte[] data, int offset, long value )
-    {
+    public static void putUInt( byte[] data, int offset, long value ) {
         int i = offset;
-        data[i++] = (byte) ( ( value >>> 0 ) & 0xFF );
-        data[i++] = (byte) ( ( value >>> 8 ) & 0xFF );
+        data[i++] = (byte) ( ( value        ) & 0xFF );
+        data[i++] = (byte) ( ( value >>> 8  ) & 0xFF );
         data[i++] = (byte) ( ( value >>> 16 ) & 0xFF );
-        data[i++] = (byte) ( ( value >>> 24 ) & 0xFF );
+        data[i  ] = (byte) ( ( value >>> 24 ) & 0xFF );
     }
 
     /**
      * Put unsigned int into output stream
-     * 
+     *
      * @param value
      *            the int (32-bit) value
      * @param outputStream
@@ -621,38 +531,35 @@ public class LittleEndian implements Lit
      * @throws IOException
      *             if an I/O error occurs
      */
-    public static void putUInt( long value, OutputStream outputStream )
-            throws IOException
-    {
-        outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
-        outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
+    public static void putUInt( long value, OutputStream outputStream ) throws 
IOException {
+        outputStream.write( (byte) ( ( value        ) & 0xFF ) );
+        outputStream.write( (byte) ( ( value >>>  8 ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 16 ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 24 ) & 0xFF ) );
     }
 
     /**
      * put an unsigned short value into a byte array
-     * 
+     *
      * @param data
      *            the byte array
      * @param offset
      *            a starting offset into the byte array
      * @param value
      *            the short (16-bit) value
-     * 
+     *
      * @exception ArrayIndexOutOfBoundsException
      *                may be thrown
      */
-    public static void putUShort( byte[] data, int offset, int value )
-    {
+    public static void putUShort( byte[] data, int offset, int value ) {
         int i = offset;
-        data[i++] = (byte) ( ( value >>> 0 ) & 0xFF );
-        data[i++] = (byte) ( ( value >>> 8 ) & 0xFF );
+        data[i++] = (byte) ( ( value       ) & 0xFF );
+        data[i  ] = (byte) ( ( value >>> 8 ) & 0xFF );
     }
 
     /**
      * Put unsigned short into output stream
-     * 
+     *
      * @param value
      *            the unsigned short (16-bit) value
      * @param outputStream
@@ -660,16 +567,14 @@ public class LittleEndian implements Lit
      * @throws IOException
      *             if an I/O error occurs
      */
-    public static void putUShort( int value, OutputStream outputStream )
-            throws IOException
-    {
-        outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
+    public static void putUShort( int value, OutputStream outputStream ) 
throws IOException {
+        outputStream.write( (byte) ( ( value       ) & 0xFF ) );
         outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
     }
 
     /**
      * get an int value from an InputStream
-     * 
+     *
      * @param stream
      *            the InputStream from which the int is to be read
      * @return the int (32-bit) value
@@ -678,9 +583,7 @@ public class LittleEndian implements Lit
      * @exception BufferUnderrunException
      *                if the stream cannot provide enough bytes
      */
-    public static int readInt( InputStream stream ) throws IOException,
-            BufferUnderrunException
-    {
+    public static int readInt( InputStream stream ) throws IOException {
         int ch1 = stream.read();
         int ch2 = stream.read();
         int ch3 = stream.read();
@@ -689,12 +592,12 @@ public class LittleEndian implements Lit
         {
             throw new BufferUnderrunException();
         }
-        return ( ch4 << 24 ) + ( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 << 0 );
+        return ( ch4 << 24 ) + ( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 );
     }
-    
+
     /**
      * get an unsigned int value from an InputStream
-     * 
+     *
      * @param stream
      *            the InputStream from which the int is to be read
      * @return the unsigned int (32-bit) value
@@ -703,16 +606,14 @@ public class LittleEndian implements Lit
      * @exception BufferUnderrunException
      *                if the stream cannot provide enough bytes
      */
-    public static long readUInt( InputStream stream ) throws IOException,
-            BufferUnderrunException
-    {
+    public static long readUInt( InputStream stream ) throws IOException {
        long retNum = readInt(stream);
-       return retNum & 0x00FFFFFFFFl;
+       return retNum & 0x00FFFFFFFFL;
     }
 
     /**
      * get a long value from an InputStream
-     * 
+     *
      * @param stream
      *            the InputStream from which the long is to be read
      * @return the long (64-bit) value
@@ -721,9 +622,7 @@ public class LittleEndian implements Lit
      * @exception BufferUnderrunException
      *                if the stream cannot provide enough bytes
      */
-    public static long readLong( InputStream stream ) throws IOException,
-            BufferUnderrunException
-    {
+    public static long readLong( InputStream stream ) throws IOException {
         int ch1 = stream.read();
         int ch2 = stream.read();
         int ch3 = stream.read();
@@ -732,8 +631,7 @@ public class LittleEndian implements Lit
         int ch6 = stream.read();
         int ch7 = stream.read();
         int ch8 = stream.read();
-        if ( ( ch1 | ch2 | ch3 | ch4 | ch5 | ch6 | ch7 | ch8 ) < 0 )
-        {
+        if ( ( ch1 | ch2 | ch3 | ch4 | ch5 | ch6 | ch7 | ch8 ) < 0 ) {
             throw new BufferUnderrunException();
         }
 
@@ -741,12 +639,12 @@ public class LittleEndian implements Lit
                 + ( (long) ch6 << 40 ) + ( (long) ch5 << 32 )
                 + ( (long) ch4 << 24 ) + // cast to long to preserve bit 31
                                          // (sign bit for ints)
-                ( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 << 0 );
+                ( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 );
     }
 
     /**
      * get a short value from an InputStream
-     * 
+     *
      * @param stream
      *            the InputStream from which the short is to be read
      * @return the short (16-bit) value
@@ -755,39 +653,32 @@ public class LittleEndian implements Lit
      * @exception BufferUnderrunException
      *                if the stream cannot provide enough bytes
      */
-    public static short readShort( InputStream stream ) throws IOException,
-            BufferUnderrunException
-    {
+    public static short readShort( InputStream stream ) throws IOException {
         return (short) readUShort( stream );
     }
 
-    public static int readUShort( InputStream stream ) throws IOException,
-            BufferUnderrunException
-    {
+    public static int readUShort( InputStream stream ) throws IOException {
         int ch1 = stream.read();
         int ch2 = stream.read();
-        if ( ( ch1 | ch2 ) < 0 )
-        {
+        if ( ( ch1 | ch2 ) < 0 ) {
             throw new BufferUnderrunException();
         }
-        return ( ch2 << 8 ) + ( ch1 << 0 );
+        return ( ch2 << 8 ) + ( ch1 );
     }
 
     /**
      * Convert an 'unsigned' byte to an integer. ie, don't carry across the
      * sign.
-     * 
+     *
      * @param b
      *            Description of the Parameter
      * @return Description of the Return Value
      */
-    public static int ubyteToInt( byte b )
-    {
+    public static int ubyteToInt( byte b ) {
         return b & 0xFF;
     }
 
-    private LittleEndian()
-    {
+    private LittleEndian() {
         // no instances of this class
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/util/StringUtil.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/StringUtil.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/StringUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/StringUtil.java Thu Apr 16 22:11:16 
2020
@@ -65,6 +65,9 @@ public final class StringUtil {
             final int offset,
             final int len)
             throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
+        if (len == 0) {
+            return "";
+        }
         if ((offset < 0) || (offset >= string.length)) {
             throw new ArrayIndexOutOfBoundsException("Illegal offset " + 
offset + " (String data is of length " + string.length + ")");
         }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java Thu 
Apr 16 22:11:16 2020
@@ -41,7 +41,7 @@ public class XSSFColor extends ExtendedC
         //noinspection deprecation
         return color == null ? null : new XSSFColor(color, map);
     }
-    
+
     /**
      * Create an instance of XSSFColor from the supplied XML bean, with 
default color indexes
      * @param color The {@link CTColor} to use as color-value.
@@ -52,7 +52,7 @@ public class XSSFColor extends ExtendedC
     public XSSFColor(CTColor color) {
         this(color, new DefaultIndexedColorMap());
     }
-    
+
     /**
      * Create an instance of XSSFColor from the supplied XML bean, with the 
given color indexes
      * @param color The {@link CTColor} to use as color-value.
@@ -119,7 +119,7 @@ public class XSSFColor extends ExtendedC
         this(CTColor.Factory.newInstance(), colorMap);
         ctColor.setRgb(rgb);
     }
-    
+
     /**
      * @param indexedColor color index (Enum named for default colors)
      * @param colorMap The IndexedColorMap to use instead of the default one
@@ -167,7 +167,7 @@ public class XSSFColor extends ExtendedC
     public boolean isThemed() {
         return ctColor.isSetTheme();
     }
-    
+
     /**
      * @return true if the ctColor has a alpha
      */
@@ -215,14 +215,8 @@ public class XSSFColor extends ExtendedC
           return null;
       }
 
-      if(rgb.length == 4) {
-         // Need to trim off the alpha
-         byte[] tmp = new byte[3];
-         System.arraycopy(rgb, 1, tmp, 0, 3);
-         return tmp;
-      } else {
-         return rgb;
-      }
+       // Need to trim off the alpha
+       return rgb.length == 4 ? Arrays.copyOfRange(rgb, 1, 4) : rgb;
    }
 
    /**
@@ -258,7 +252,7 @@ public class XSSFColor extends ExtendedC
        }
        return null;
    }
-   
+
     /**
      * Standard Alpha Red Green Blue ctColor value (ARGB).
      */
@@ -403,7 +397,7 @@ public class XSSFColor extends ExtendedC
         }
         return (XSSFColor)color;
     }
-    
+
     @Override
     public int hashCode(){
         return ctColor.toString().hashCode();
@@ -437,7 +431,7 @@ public class XSSFColor extends ExtendedC
     private boolean sameAuto(XSSFColor other) {
         return isAuto() == other.isAuto();
     }
-    
+
     @Override
     public boolean equals(Object o){
         if(!(o instanceof XSSFColor)) {
@@ -445,7 +439,7 @@ public class XSSFColor extends ExtendedC
         }
 
         XSSFColor other = (XSSFColor)o;
-        
+
         // Compare each field in ctColor.
         // Cannot compare ctColor's XML string representation because 
equivalent
         // colors may have different relation namespace URI's

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java 
Thu Apr 16 22:11:16 2020
@@ -188,8 +188,7 @@ public final class ChunkFactory {
                }
 
                // Now, create the chunk
-               byte[] contents = IOUtils.safelyAllocate(header.getLength(), 
MAX_RECORD_LENGTH);
-               System.arraycopy(data, offset+header.getSizeInBytes(), 
contents, 0, contents.length);
+               byte[] contents = IOUtils.safelyClone(data, 
offset+header.getSizeInBytes(), header.getLength(), MAX_RECORD_LENGTH);
                Chunk chunk = new Chunk(header, trailer, separator, contents);
 
                // Feed in the stuff from  chunks_parse_cmds.tbl

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java 
Thu Apr 16 22:11:16 2020
@@ -17,16 +17,17 @@
 
 package org.apache.poi.hdgf.chunks;
 
+import java.util.Arrays;
+
 /**
  * A separator between the trailer of one chunk, and the
  *  header of the next one
  */
 public final class ChunkSeparator {
-       protected byte[] separatorData;
+       final byte[] separatorData;
 
        public ChunkSeparator(byte[] data, int offset) {
-               separatorData = new byte[4];
-               System.arraycopy(data, offset, separatorData, 0, 4);
+               separatorData = Arrays.copyOfRange(data, offset, offset+4);
        }
 
        public String toString() {

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java 
Thu Apr 16 22:11:16 2020
@@ -17,15 +17,16 @@
 
 package org.apache.poi.hdgf.chunks;
 
+import java.util.Arrays;
+
 /**
  * A trailer that follows a chunk
  */
 public final class ChunkTrailer {
-       private byte[] trailerData;
+       private final byte[] trailerData;
 
        public ChunkTrailer(byte[] data, int offset) {
-               trailerData = new byte[8];
-               System.arraycopy(data, offset, trailerData, 0, 8);
+               trailerData = Arrays.copyOfRange(data, offset, offset+8);
        }
 
        public String toString() {

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java
 Thu Apr 16 22:11:16 2020
@@ -38,21 +38,19 @@ public final class CompressedStreamStore
         * We're not sure what this is, but it comes before the
         *  real contents in the de-compressed data
         */
-       private byte[] blockHeader = new byte[4];
+       private final byte[] blockHeader;
        private boolean blockHeaderInContents;
 
-       protected byte[] _getCompressedContents() { return compressedContents; }
-       protected byte[] _getBlockHeader() { return blockHeader; }
+       byte[] _getCompressedContents() { return compressedContents; }
+       byte[] _getBlockHeader() { return blockHeader; }
 
        /**
         * Creates a new compressed StreamStore, which will handle
         *  the decompression.
         */
-       protected CompressedStreamStore(byte[] data, int offset, int length) 
throws IOException {
+       CompressedStreamStore(byte[] data, int offset, int length) throws 
IOException {
                this(decompress(data,offset,length));
-
-               compressedContents = IOUtils.safelyAllocate(length, 
MAX_RECORD_LENGTH);
-               System.arraycopy(data, offset, compressedContents, 0, length);
+               compressedContents = IOUtils.safelyClone(data, offset, length, 
MAX_RECORD_LENGTH);
        }
        /**
         * Handles passing the de-compressed data onto our superclass.

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java 
Thu Apr 16 22:11:16 2020
@@ -34,8 +34,7 @@ public class StreamStore { // TODO - ins
         * Creates a new, non compressed Stream Store
         */
        protected StreamStore(byte[] data, int offset, int length) {
-               contents = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
-               System.arraycopy(data, offset, contents, 0, length);
+               contents = IOUtils.safelyClone(data, offset, length, 
MAX_RECORD_LENGTH);
        }
 
        protected void prependContentsWith(byte[] b) {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java Thu Apr 
16 22:11:16 2020
@@ -20,7 +20,7 @@ package org.apache.poi.hmef;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LZWDecompresser;
@@ -43,18 +43,18 @@ public final class CompressedRTF extends
       LittleEndian.getInt(COMPRESSED_SIGNATURE);
    public static final int UNCOMPRESSED_SIGNATURE_INT =
       LittleEndian.getInt(UNCOMPRESSED_SIGNATURE);
-   
+
    // The 4096 byte LZW dictionary is pre-loaded with some common
    //  RTF fragments. These come from RTFLIB32.LIB, which ships
    //  with older versions of Visual Studio or the EDK
-   public static final String LZW_RTF_PRELOAD = 
+   public static final String LZW_RTF_PRELOAD =
       "{\\rtf1\\ansi\\mac\\deff0\\deftab720{\\fonttbl;}{\\f0\\fnil \\froman 
\\fswiss " +
       "\\fmodern \\fscript \\fdecor MS Sans SerifSymbolArialTimes New 
RomanCourier" +
       "{\\colortbl\\red0\\green0\\blue0\n\r\\par 
\\pard\\plain\\f0\\fs20\\b\\i\\u\\tab\\tx";
 
    private int compressedSize;
    private int decompressedSize;
-   
+
    public CompressedRTF() {
       // Out flag has the normal meaning
       // Length wise, we're 2 longer than we say, so the max len is 18
@@ -76,9 +76,9 @@ public final class CompressedRTF extends
       decompressedSize = LittleEndian.readInt(src);
       int compressionType = LittleEndian.readInt(src);
       /* int dataCRC = */ LittleEndian.readInt(src);
-      
+
       // TODO - Handle CRC checking on the output side
-      
+
       // Do we need to do anything?
       if(compressionType == UNCOMPRESSED_SIGNATURE_INT) {
          // Nope, nothing fancy to do
@@ -92,7 +92,7 @@ public final class CompressedRTF extends
       // Have it processed
       super.decompress(src, res);
    }
-   
+
    /**
     * Returns how big the compressed version was.
     */
@@ -100,7 +100,7 @@ public final class CompressedRTF extends
       // Return the size less the header
       return compressedSize - 12;
    }
-   
+
    /**
     * Returns how big the decompressed version was.
     */
@@ -119,10 +119,10 @@ public final class CompressedRTF extends
 
    @Override
    protected int populateDictionary(byte[] dict) {
-     // Copy in the RTF constants 
-     byte[] preload = LZW_RTF_PRELOAD.getBytes(Charset.forName("US-ASCII"));
+     // Copy in the RTF constants
+     byte[] preload = LZW_RTF_PRELOAD.getBytes(StandardCharsets.US_ASCII);
      System.arraycopy(preload, 0, dict, 0, preload.length);
-     
+
      // Start adding new codes after the constants
      return preload.length;
    }

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java 
Thu Apr 16 22:11:16 2020
@@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.poi.hmef.Attachment;
@@ -45,7 +46,7 @@ public class MAPIAttribute {
    private final MAPIProperty property;
    private final int type;
    private final byte[] data;
-   
+
    /**
     * Constructs a single new attribute from
     *  the contents of the stream
@@ -67,21 +68,20 @@ public class MAPIAttribute {
    public byte[] getData() {
       return data;
    }
-   
+
    public String toString() {
       String hex;
       if(data.length <= 16) {
          hex = HexDump.toHex(data);
       } else {
-         byte[] d = new byte[16];
-         System.arraycopy(data, 0, d, 0, 16);
+         byte[] d = Arrays.copyOf(data, 16);
          hex = HexDump.toHex(d);
          hex = hex.substring(0, hex.length()-1) + ", ....]";
       }
-      
+
       return property + " " + hex;
    }
-   
+
    /**
     * Parses a MAPI Properties TNEF Attribute, and returns
     *  the list of MAPI Attributes contained within it
@@ -101,16 +101,16 @@ public class MAPIAttribute {
          );
       }
       ByteArrayInputStream inp = new ByteArrayInputStream(parent.getData());
-      
+
       // First up, get the number of attributes
       int count = LittleEndian.readInt(inp);
       List<MAPIAttribute> attrs = new ArrayList<>();
-      
+
       // Now, read each one in in turn
       for(int i=0; i<count; i++) {
          int typeAndMV = LittleEndian.readUShort(inp);
          int id = LittleEndian.readUShort(inp);
-         
+
          // Is it either Multi-Valued or Variable-Length?
          boolean isMV = false;
          boolean isVL = false;
@@ -123,13 +123,13 @@ public class MAPIAttribute {
                typeId == Types.BINARY.getId() || typeId == 
Types.DIRECTORY.getId()) {
             isVL = true;
          }
-         
+
          // Turn the type ID into a strongly typed thing
          MAPIType type = Types.getById(typeId);
          if (type == null) {
             type = Types.createCustom(typeId);
          }
-         
+
          // If it's a named property, rather than a standard
          //  MAPI property, grab the details of it
          MAPIProperty prop = MAPIProperty.get(id);
@@ -137,7 +137,7 @@ public class MAPIAttribute {
             byte[] guid = new byte[16];
             IOUtils.readFully(inp, guid);
             int mptype = LittleEndian.readInt(inp);
-            
+
             // Get the name of it
             String name;
             if(mptype == 0) {
@@ -153,14 +153,14 @@ public class MAPIAttribute {
                name = StringUtil.getFromUnicodeLE(mpdata, 0, (mplen/2)-1);
                skipToBoundary(mplen, inp);
             }
-            
+
             // Now create
             prop = MAPIProperty.createCustom(id, type, name);
          }
          if(prop == MAPIProperty.UNKNOWN) {
             prop = MAPIProperty.createCustom(id, type, "(unknown " + 
Integer.toHexString(id) + ")");
          }
-         
+
          // Now read in the value(s)
          int values = 1;
          if(isMV || isVL) {
@@ -171,7 +171,7 @@ public class MAPIAttribute {
             byte[] data = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
             IOUtils.readFully(inp, data);
             skipToBoundary(len, inp);
-            
+
             // Create
             MAPIAttribute attr;
             if(type == Types.UNICODE_STRING || type == Types.ASCII_STRING) {
@@ -186,7 +186,7 @@ public class MAPIAttribute {
             attrs.add(attr);
          }
       }
-      
+
       // All done
       return attrs;
    }

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java
 Thu Apr 16 22:11:16 2020
@@ -28,7 +28,7 @@ import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.StringUtil;
 
 /**
- * A pure-MAPI attribute holding RTF (compressed or not), which applies 
+ * A pure-MAPI attribute holding RTF (compressed or not), which applies
  *  to a {@link HMEFMessage} or one of its {@link Attachment}s.
  */
 public final class MAPIRtfAttribute extends MAPIAttribute {
@@ -38,45 +38,44 @@ public final class MAPIRtfAttribute exte
 
    private final byte[] decompressed;
    private final String data;
-   
+
    public MAPIRtfAttribute(MAPIProperty property, int type, byte[] data) 
throws IOException {
       super(property, type, data);
-      
+
       // Decompress it, removing any trailing padding as needed
       CompressedRTF rtf = new CompressedRTF();
       byte[] tmp = rtf.decompress(new ByteArrayInputStream(data));
       if(tmp.length > rtf.getDeCompressedSize()) {
-         this.decompressed = IOUtils.safelyAllocate(rtf.getDeCompressedSize(), 
MAX_RECORD_LENGTH);
-         System.arraycopy(tmp, 0, decompressed, 0, decompressed.length);
+         this.decompressed = IOUtils.safelyClone(tmp, 0, 
rtf.getDeCompressedSize(), MAX_RECORD_LENGTH);
       } else {
          this.decompressed = tmp;
       }
-      
+
       // Turn the RTF data into a more useful string
       this.data = StringUtil.getFromCompressedUnicode(decompressed, 0, 
decompressed.length);
    }
-   
+
    /**
     * Returns the original, compressed RTF
     */
    public byte[] getRawData() {
       return super.getData();
    }
-   
+
    /**
     * Returns the raw uncompressed RTF data
     */
    public byte[] getData() {
       return decompressed;
    }
-   
+
    /**
     * Returns the uncompressed RTF as a string
     */
    public String getDataString() {
       return data;
    }
-   
+
    public String toString() {
       return getProperty() + " " + data;
    }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java Thu 
Apr 16 22:11:16 2020
@@ -44,7 +44,7 @@ public final class HMEFDumper {
       if(args.length < 1) {
          throw new IllegalArgumentException("Filename must be given");
       }
-      
+
       boolean truncatePropData = true;
       for (String arg : args) {
          if (arg.equalsIgnoreCase("--full")) {
@@ -62,77 +62,77 @@ public final class HMEFDumper {
 
    private InputStream inp;
    private boolean truncatePropertyData;
-   
+
    public HMEFDumper(InputStream inp) throws IOException {
       this.inp = inp;
-      
+
       // Check the signature matches
       int sig = LittleEndian.readInt(inp);
       if(sig != HMEFMessage.HEADER_SIGNATURE) {
          throw new IllegalArgumentException(
                "TNEF signature not detected in file, " +
-               "expected " + HMEFMessage.HEADER_SIGNATURE + 
+               "expected " + HMEFMessage.HEADER_SIGNATURE +
                " but got " + sig
          );
       }
-      
+
       // Skip over the File ID
       LittleEndian.readUShort(inp);
    }
-   
+
    public void setTruncatePropertyData(boolean truncate) {
       truncatePropertyData = truncate;
    }
-   
+
    private void dump() throws IOException {
       int level;
       int attachments = 0;
-      
+
       while(true) {
          // Fetch the level
          level = inp.read();
          if(level == TNEFProperty.LEVEL_END_OF_FILE) {
             break;
          }
-       
+
          // Build the attribute
          TNEFAttribute attr = TNEFAttribute.create(inp);
-         
+
          // Is it a new attachment?
-         if(level == TNEFProperty.LEVEL_ATTACHMENT && 
+         if(level == TNEFProperty.LEVEL_ATTACHMENT &&
                attr.getProperty() == TNEFProperty.ID_ATTACHRENDERDATA) {
             attachments++;
             System.out.println();
             System.out.println("Attachment # " + attachments);
             System.out.println();
          }
-         
+
          // Print the attribute into
          System.out.println(
                "Level " + level + " : Type " + attr.getType() +
                " : ID " + attr.getProperty()
          );
-         
+
          // Print the contents
          String indent = "  ";
-         
+
          if(attr instanceof TNEFStringAttribute) {
             System.out.println(indent + indent + indent + 
((TNEFStringAttribute)attr).getString());
          }
          if(attr instanceof TNEFDateAttribute) {
             System.out.println(indent + indent + indent + 
((TNEFDateAttribute)attr).getDate());
          }
-         
+
          System.out.println(indent + "Data of length " + 
attr.getData().length);
          if(attr.getData().length > 0) {
             int len = attr.getData().length;
             if(truncatePropertyData) {
                len = Math.min( attr.getData().length, 48 );
             }
-            
+
             int loops = len/16;
             if(loops == 0) loops = 1;
-            
+
             for(int i=0; i<loops; i++) {
                int thisLen = 16;
                int offset = i*16;
@@ -140,16 +140,15 @@ public final class HMEFDumper {
                   thisLen = len - offset;
                }
 
-                byte[] data = IOUtils.safelyAllocate(thisLen, 
MAX_RECORD_LENGTH);
-               System.arraycopy(attr.getData(), offset, data, 0, thisLen);
-               
+               byte[] data = IOUtils.safelyClone(attr.getData(), offset, 
thisLen, MAX_RECORD_LENGTH);
+
                System.out.print(
                      indent + HexDump.dump(data, 0, 0)
                );
             }
          }
          System.out.println();
-         
+
          if(attr.getProperty() == TNEFProperty.ID_MAPIPROPERTIES ||
                attr.getProperty() == TNEFProperty.ID_ATTACHMENT) {
             List<MAPIAttribute> attrs = MAPIAttribute.create(attr);

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java 
Thu Apr 16 22:11:16 2020
@@ -69,8 +69,7 @@ public final class QuillContents extends
                                int from = (int)LittleEndian.getUInt(data, 
offset+16);
                                int len = (int)LittleEndian.getUInt(data, 
offset+20);
 
-                               byte[] bitData = IOUtils.safelyAllocate(len, 
MAX_RECORD_LENGTH);
-                               System.arraycopy(data, from, bitData, 0, len);
+                               byte[] bitData = IOUtils.safelyClone(data, 
from, len, MAX_RECORD_LENGTH);
 
                                // Create
                                if(bitType.equals("TEXT")) {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java Thu Apr 
16 22:11:16 2020
@@ -39,9 +39,7 @@ public abstract class Bitmap extends HSL
     public byte[] getData(){
         byte[] rawdata = getRawData();
         int prefixLen = 16*getUIDInstanceCount()+1;
-        byte[] imgdata = IOUtils.safelyAllocate(rawdata.length-prefixLen, 
rawdata.length);
-        System.arraycopy(rawdata, prefixLen, imgdata, 0, imgdata.length);
-        return imgdata;
+        return IOUtils.safelyClone(rawdata, prefixLen, 
rawdata.length-prefixLen, rawdata.length);
     }
 
     @Override

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java Thu Apr 16 
22:11:16 2020
@@ -62,9 +62,9 @@ public final class DIB extends Bitmap {
                 break;
             default:
                 throw new IllegalArgumentException(signature+" is not a valid 
instance/signature value for DIB");
-        }        
-    }    
-    
+        }
+    }
+
     @Override
     public byte[] getData(){
         return addBMPHeader ( super.getData() );
@@ -83,14 +83,14 @@ public final class DIB extends Bitmap {
         int imageSize = LittleEndian.getInt(data, 0x22 - HEADER_SIZE);
         int fileSize = data.length + HEADER_SIZE;
         int offset = fileSize - imageSize;
-        
+
                // specifies the size, in bytes, of the bitmap file - must add 
the length of the header
-        LittleEndian.putInt(header, 2, fileSize); 
+        LittleEndian.putInt(header, 2, fileSize);
         // Reserved; set to zero
         LittleEndian.putInt(header, 6, 0);
         // the offset, i.e. starting address, of the byte where the bitmap 
data can be found
         LittleEndian.putInt(header, 10, offset);
-        
+
         //DIB data is the header + dib bytes
         byte[] dib = IOUtils.safelyAllocate(header.length + data.length, 
MAX_RECORD_LENGTH);
         System.arraycopy(header, 0, dib, 0, header.length);
@@ -102,8 +102,7 @@ public final class DIB extends Bitmap {
     @Override
     public void setData(byte[] data) throws IOException {
         //cut off the bitmap file-header
-        byte[] dib = IOUtils.safelyAllocate(data.length-HEADER_SIZE, 
data.length);
-        System.arraycopy(data, HEADER_SIZE, dib, 0, dib.length);
+        byte[] dib = IOUtils.safelyClone(data, HEADER_SIZE, 
data.length-HEADER_SIZE, data.length);
         super.setData(dib);
     }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java Thu Apr 16 
22:11:16 2020
@@ -36,8 +36,8 @@ import org.apache.poi.util.Units;
  */
 public final class PICT extends Metafile {
     private static final POILogger LOG = POILogFactory.getLogger(PICT.class);
-    
-    
+
+
     @Override
     public byte[] getData(){
         byte[] rawdata = getRawData();
@@ -95,7 +95,7 @@ public final class PICT extends Metafile
         // skip the first 512 bytes - they are MAC specific crap
         final int nOffset = ImageHeaderPICT.PICT_HEADER_OFFSET;
         ImageHeaderPICT nHeader = new ImageHeaderPICT(data, nOffset);
-        
+
         Header header = new Header();
         int wmfSize = data.length - nOffset;
         header.setWmfSize(wmfSize);
@@ -144,12 +144,12 @@ public final class PICT extends Metafile
                 break;
             default:
                 throw new IllegalArgumentException(signature+" is not a valid 
instance/signature value for PICT");
-        }        
+        }
     }
-    
-    
+
+
     /*
-     * initialize a smaller piece of the array and use the System.arraycopy 
+     * initialize a smaller piece of the array and use the System.arraycopy
      * call to fill in the rest of the array in an expanding binary fashion
      */
     private static void bytefill(byte[] array, byte value) {
@@ -161,7 +161,7 @@ public final class PICT extends Metafile
         }
 
         for (int i = 1; i < len; i += i) {
-            System.arraycopy(array, 0, array, i, ((len - i) < i) ? (len - i) : 
i);
+            System.arraycopy(array, 0, array, i, Math.min(len - i, i));
         }
     }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java Thu 
Apr 16 22:11:16 2020
@@ -26,6 +26,7 @@ import java.io.OutputStreamWriter;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
 
 import org.apache.poi.hslf.record.RecordTypes;
 import org.apache.poi.hslf.usermodel.HSLFSlideShow;
@@ -161,20 +162,18 @@ public final class PPTXMLDump {
     public void dumpPictures(byte[] data, int padding) throws IOException {
         int pos = 0;
         while (pos < data.length) {
-            byte[] header = new byte[PICT_HEADER_SIZE];
-
-            if(data.length - pos < header.length) {
+            if(data.length - pos < PICT_HEADER_SIZE) {
                 // corrupt file, cannot read header
                 return;
             }
-            System.arraycopy(data, pos, header, 0, header.length);
+            byte[] header = Arrays.copyOfRange(data, pos, pos + 
PICT_HEADER_SIZE);
             int size = LittleEndian.getInt(header, 4) - 17;
             if(size < 0) {
                 // corrupt file, negative image size
                 return;
             }
-            byte[] pictdata = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
-            System.arraycopy(data, pos + PICT_HEADER_SIZE, pictdata, 0, 
pictdata.length);
+
+            byte[] pictdata = IOUtils.safelyClone(data, pos + 
PICT_HEADER_SIZE, size, MAX_RECORD_LENGTH);
             pos += PICT_HEADER_SIZE + size;
 
             padding++;

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java 
Thu Apr 16 22:11:16 2020
@@ -58,7 +58,7 @@ public final class SlideShowDumper {
   private boolean ddfEscher;
   /** Do we use our own built-in basic escher groker to understand the escher 
objects? */
   private boolean basicEscher;
-  
+
   private PrintStream out;
 
   /**
@@ -213,8 +213,7 @@ public void walkTree(int depth, int star
 
        final String ind = (indent == 0) ? "%1$s" : "%1$"+indent+"s";
 
-       byte[] contents = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
-       System.arraycopy(docstream,pos,contents,0,len);
+    byte[] contents = IOUtils.safelyClone(docstream, pos, len, 
MAX_RECORD_LENGTH);
        DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();
        EscherRecord record = erf.createRecord(contents,0);
 
@@ -229,8 +228,8 @@ public void walkTree(int depth, int star
 
     String fmt = ind+"At position %2$d (%2$04x): type is %3$d (%3$04x), len is 
%4$d (%4$04x) (%5$d) - record claims %6$d";
     out.println(String.format(Locale.ROOT, fmt, "", pos, atomType, atomLen, 
atomLen+8, recordLen));
-       
-       
+
+
        // Check for corrupt / lying ones
        if(recordLen != 8 && (recordLen != (atomLen+8))) {
                out.println(String.format(Locale.ROOT, ind+"** Atom length of 
$2d ($3d) doesn't match record length of %4d", "", atomLen, atomLen+8, 
recordLen));

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java 
Thu Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogger;
@@ -39,8 +40,7 @@ public final class AnimationInfo extends
         */
        protected AnimationInfo(byte[] source, int start, int len) {
                // Grab the header
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source, start, start+8);
 
                // Find our children
                _children = Record.findChildRecords(source,start+8,len-8);

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java 
Thu Apr 16 22:11:16 2020
@@ -21,6 +21,7 @@ import static org.apache.poi.util.Generi
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.function.Supplier;
 
@@ -101,7 +102,7 @@ public final class AnimationInfoAtom ext
     /**
      * record data
      */
-    private byte[] _recdata;
+    private final byte[] _recdata;
 
     /**
      * Constructs a brand new link related atom record.
@@ -125,12 +126,10 @@ public final class AnimationInfoAtom ext
      */
     protected AnimationInfoAtom(byte[] source, int start, int len) {
         // Get the header
-        _header = new byte[8];
-        System.arraycopy(source,start,_header,0,8);
+        _header = Arrays.copyOfRange(source, start, start+8);
 
         // Grab the record data
-        _recdata = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
-        System.arraycopy(source,start+8,_recdata,0,len-8);
+        _recdata = IOUtils.safelyClone(source,start+8, len-8, 
MAX_RECORD_LENGTH);
     }
 
     /**

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java 
Thu Apr 16 22:11:16 2020
@@ -17,9 +17,11 @@
 
 package org.apache.poi.hslf.record;
 
-import org.apache.poi.util.LittleEndian;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
+
+import org.apache.poi.util.LittleEndian;
 
 /**
  * If we come across a record we know has children of (potential)
@@ -44,8 +46,7 @@ public final class BinaryTagDataBlob ext
         */
        protected BinaryTagDataBlob(byte[] source, int start, int len) {
                // Just grab the header, not the whole contents
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source, start, start+8);
                _type = LittleEndian.getUShort(_header,2);
 
                // Find our children

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CString.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CString.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CString.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CString.java Thu 
Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.function.Supplier;
 
@@ -86,12 +87,10 @@ public final class CString extends Recor
                if(len < 8) { len = 8; }
 
                // Get the header
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source, start, start+8);
 
                // Grab the text
-               _text = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
-               System.arraycopy(source,start+8,_text,0,len-8);
+               _text = IOUtils.safelyClone(source,start+8, len-8, 
MAX_RECORD_LENGTH);
        }
        /**
         * Create an empty CString

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java 
Thu Apr 16 22:11:16 2020
@@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -108,11 +109,10 @@ public final class ColorSchemeAtom exten
                }
 
                // Get the header
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source, start, start+8);
 
                // Grab the rgb values
-               backgroundColourRGB = LittleEndian.getInt(source,start+8+0);
+               backgroundColourRGB = LittleEndian.getInt(source, start+8);
                textAndLinesColourRGB = LittleEndian.getInt(source,start+8+4);
                shadowsColourRGB = LittleEndian.getInt(source,start+8+8);
                titleTextColourRGB = LittleEndian.getInt(source,start+8+12);

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java 
Thu Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogger;
@@ -101,8 +102,7 @@ public final class Comment2000 extends R
         */
        protected Comment2000(byte[] source, int start, int len) {
                // Grab the header
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source, start, start+8);
 
                // Find our children
                _children = 
org.apache.poi.hslf.record.Record.findChildRecords(source,start+8,len-8);

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java 
Thu Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.Map;
 import java.util.function.Supplier;
@@ -72,12 +73,10 @@ public final class Comment2000Atom exten
      */
     protected Comment2000Atom(byte[] source, int start, int len) {
         // Get the header.
-        _header = new byte[8];
-        System.arraycopy(source,start,_header,0,8);
+        _header = Arrays.copyOfRange(source, start, start+8);
 
         // Get the record data.
-        _data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
-        System.arraycopy(source,start+8,_data,0,len-8);
+        _data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
     }
 
     /**

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java 
Thu Apr 16 22:11:16 2020
@@ -192,17 +192,12 @@ public class CurrentUserAtom
 
                // Grab the unicode username, if stored
                int start = 28+(int)usernameLen+4;
-               int len = 2*(int)usernameLen;
 
-               if(_contents.length >= start+len) {
-                       byte[] textBytes = IOUtils.safelyAllocate(len, 
MAX_RECORD_LENGTH);
-                       System.arraycopy(_contents,start,textBytes,0,len);
-                       lastEditUser = StringUtil.getFromUnicodeLE(textBytes);
+               if(_contents.length >= start+2*usernameLen) {
+                       lastEditUser = StringUtil.getFromUnicodeLE(_contents, 
start, (int)usernameLen);
                } else {
                        // Fake from the 8 bit version
-                       byte[] textBytes = IOUtils.safelyAllocate(usernameLen, 
MAX_RECORD_LENGTH);
-                       
System.arraycopy(_contents,28,textBytes,0,(int)usernameLen);
-                       lastEditUser = 
StringUtil.getFromCompressedUnicode(textBytes,0,(int)usernameLen);
+                       lastEditUser = 
StringUtil.getFromCompressedUnicode(_contents, 28, (int)usernameLen);
                }
        }
 

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java
 Thu Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.function.Supplier;
 
@@ -38,8 +39,7 @@ public final class DocInfoListContainer
         */
        protected DocInfoListContainer(byte[] source, int start, int len) {
                // Grab the header
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source,start,start+8);
 
                // Find our children
                _children = Record.findChildRecords(source,start+8,len-8);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java Thu 
Apr 16 22:11:16 2020
@@ -17,11 +17,12 @@
 
 package org.apache.poi.hslf.record;
 
-import org.apache.poi.util.POILogger;
-
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.apache.poi.util.POILogger;
 
 /**
  * Master container for Document. There is one of these for every
@@ -46,24 +47,24 @@ public final class Document extends Posi
         * Returns the DocumentAtom of this Document
         */
        public DocumentAtom getDocumentAtom() { return documentAtom; }
-       
+
        /**
         * Returns the Environment of this Notes, which lots of
         * settings for the document in it
         */
        public Environment getEnvironment() { return environment; }
-       
+
        /**
         * Returns the PPDrawingGroup, which holds an Escher Structure
         * that contains information on pictures in the slides.
         */
        public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; }
-       
+
        /**
         * Returns the ExObjList, which holds the references to
         * external objects used in the slides. This may be null, if
         * there are no external references.
-        *  
+        *
         * @param create if true, create an ExObjList if it doesn't exist
         */
        public ExObjList getExObjList(boolean create) {
@@ -126,8 +127,7 @@ public final class Document extends Posi
         */
        /* package */ Document(byte[] source, int start, int len) {
                // Grab the header
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source, start, start+8);
 
                // Find our children
                _children = Record.findChildRecords(source,start+8,len-8);

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java
 Thu Apr 16 22:11:16 2020
@@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.function.Supplier;
 
@@ -51,8 +52,7 @@ public final class DocumentEncryptionAto
         */
        protected DocumentEncryptionAtom(byte[] source, int start, int len) {
                // Get the header
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source,start,start+8);
 
                ByteArrayInputStream bis = new ByteArrayInputStream(source, 
start+8, len-8);
                try (LittleEndianInputStream leis = new 
LittleEndianInputStream(bis)) {
@@ -67,10 +67,10 @@ public final class DocumentEncryptionAto
            LittleEndian.putShort(_header, 0, (short)0x000F);
            LittleEndian.putShort(_header, 2, (short)_type);
            // record length not yet known ...
-           
+
            ei = new EncryptionInfo(EncryptionMode.cryptoAPI);
        }
-       
+
        /**
         * Initializes the encryption settings
         *
@@ -79,7 +79,7 @@ public final class DocumentEncryptionAto
        public void initializeEncryptionInfo(int keyBits) {
            ei = new EncryptionInfo(EncryptionMode.cryptoAPI, 
CipherAlgorithm.rc4, HashAlgorithm.sha1, keyBits, -1, null);
        }
-       
+
        /**
         * Return the length of the encryption key, in bits
         */
@@ -100,8 +100,8 @@ public final class DocumentEncryptionAto
        public EncryptionInfo getEncryptionInfo() {
            return ei;
        }
-       
-       
+
+
        /**
         * We are of type 12052
         */
@@ -119,10 +119,10 @@ public final class DocumentEncryptionAto
                bos.writeShort(ei.getVersionMajor());
                bos.writeShort(ei.getVersionMinor());
                bos.writeInt(ei.getEncryptionFlags());
-               
+
                ((CryptoAPIEncryptionHeader)ei.getHeader()).write(bos);
                ((CryptoAPIEncryptionVerifier)ei.getVerifier()).write(bos);
-               
+
         // Header
                LittleEndian.putInt(_header, 4, bos.getWriteIndex());
         out.write(_header);

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java
 Thu Apr 16 22:11:16 2020
@@ -17,9 +17,11 @@
 
 package org.apache.poi.hslf.record;
 
-import org.apache.poi.util.LittleEndian;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
+
+import org.apache.poi.util.LittleEndian;
 
 /**
  * If we come across a record we know has children of (potential)
@@ -44,8 +46,7 @@ public final class DummyPositionSensitiv
         */
        protected DummyPositionSensitiveRecordWithChildren(byte[] source, int 
start, int len) {
                // Just grab the header, not the whole contents
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source,start,start+8);
                _type = LittleEndian.getUShort(_header,2);
 
                // Find our children

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java
 Thu Apr 16 22:11:16 2020
@@ -17,9 +17,11 @@
 
 package org.apache.poi.hslf.record;
 
-import org.apache.poi.util.LittleEndian;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
+
+import org.apache.poi.util.LittleEndian;
 
 /**
  * If we come across a record we know has children of (potential)
@@ -39,8 +41,7 @@ public final class DummyRecordWithChildr
         */
        protected DummyRecordWithChildren(byte[] source, int start, int len) {
                // Just grab the header, not the whole contents
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source, start, start+8);
                _type = LittleEndian.getUShort(_header,2);
 
                // Find our children

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java 
Thu Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 
 /**
  * Environment, which contains lots of settings for the document.
@@ -47,8 +48,7 @@ public final class Environment extends P
         */
        protected Environment(byte[] source, int start, int len) {
                // Grab the header
-               _header = new byte[8];
-               System.arraycopy(source,start,_header,0,8);
+               _header = Arrays.copyOfRange(source, start, start+8);
 
                // Find our children
                _children = Record.findChildRecords(source,start+8,len-8);

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java 
Thu Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.function.Supplier;
 
@@ -63,8 +64,7 @@ public final class ExControlAtom extends
      */
     protected ExControlAtom(byte[] source, int start, int len) {
         // Get the header.
-        _header = new byte[8];
-        System.arraycopy(source, start, _header, 0, 8);
+        _header = Arrays.copyOfRange(source, start, start+8);
 
         _id = LittleEndian.getInt(source, start + 8);
     }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java Thu 
Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogger;
@@ -49,8 +50,7 @@ public class ExEmbed extends RecordConta
      */
     protected ExEmbed(final byte[] source, final int start, final int len) {
         // Grab the header
-        _header = new byte[8];
-        System.arraycopy(source,start,_header,0,8);
+        _header = Arrays.copyOfRange(source, start, start+8);
 
         // Find our children
         _children = Record.findChildRecords(source,start+8,len-8);
@@ -66,9 +66,9 @@ public class ExEmbed extends RecordConta
         this();
         _children[0] = this.embedAtom = embedAtom;
     }
-    
-    
-    
+
+
+
     /**
      * Create a new ExEmbed, with blank fields
      */
@@ -163,7 +163,7 @@ public class ExEmbed extends RecordConta
 
     /**
      * Gets the OLE Programmatic Identifier.
-     * 
+     *
      * @return the OLE Programmatic Identifier.
      */
     public String getProgId() {
@@ -175,8 +175,8 @@ public class ExEmbed extends RecordConta
         this.progId.setText(progId);
     }
 
-    
-    
+
+
     /**
      * Gets the name that appears in the paste special dialog.
      *
@@ -190,7 +190,7 @@ public class ExEmbed extends RecordConta
         this.clipboardName = safeCString(this.clipboardName, 0x3);
         this.clipboardName.setText(clipboardName);
     }
-    
+
     /**
      * Returns the type (held as a little endian in bytes 3 and 4)
      * that this class handles.
@@ -213,7 +213,7 @@ public class ExEmbed extends RecordConta
     public void writeOut(final OutputStream out) throws IOException {
         writeOut(_header[0],_header[1],getRecordType(),_children,out);
     }
-    
+
     private CString safeCString(CString oldStr, int optionsId) {
         CString newStr = oldStr;
         if (newStr == null) {
@@ -233,7 +233,7 @@ public class ExEmbed extends RecordConta
         if (!found) {
             appendChildRecord(newStr);
         }
-        
+
         return newStr;
     }
 }

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java 
Thu Apr 16 22:11:16 2020
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.function.Supplier;
 
@@ -94,12 +95,10 @@ public class ExEmbedAtom extends RecordA
      */
     protected ExEmbedAtom(byte[] source, int start, int len) {
         // Get the header.
-        _header = new byte[8];
-        System.arraycopy(source,start,_header,0,8);
+        _header = Arrays.copyOfRange(source, start, start+8);
 
         // Get the record data.
-        _data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
-        System.arraycopy(source,start+8,_data,0,len-8);
+        _data = IOUtils.safelyClone(source,start+8,len-8, MAX_RECORD_LENGTH);
 
         // Must be at least 8 bytes long
         if(_data.length < 8) {
@@ -130,7 +129,7 @@ public class ExEmbedAtom extends RecordA
     public void setCantLockServerB(boolean cantBeLocked) {
        _data[4] = (byte)(cantBeLocked ? 1 : 0);
     }
-    
+
     /**
      * Gets whether it is not required to send the dimensions to the embedded 
object.
      *



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to