You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2016/11/27 20:19:19 UTC

svn commit: r1771640 [4/4] - in /poi: site/src/documentation/content/xdocs/ trunk/src/java/org/apache/poi/hpsf/ trunk/src/java/org/apache/poi/hpsf/extractor/ trunk/src/java/org/apache/poi/util/ trunk/src/testcases/org/apache/poi/hpsf/basic/

Modified: poi/trunk/src/java/org/apache/poi/hpsf/Util.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/Util.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/Util.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/Util.java Sun Nov 27 20:19:18 2016
@@ -20,110 +20,17 @@ package org.apache.poi.hpsf;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.util.Collection;
 import java.util.Date;
 
+import org.apache.poi.util.Internal;
 import org.apache.poi.util.SuppressForbidden;
 
 /**
  * <p>Provides various static utility methods.</p>
  */
+@Internal
 public class Util
 {
-
-    /**
-     * <p>Checks whether two byte arrays <var>a</var> and <var>b</var>
-     * are equal. They are equal</p>
-     *
-     * <ul>
-     *
-     *  <li><p>if they have the same length and</p></li>
-     *
-     *  <li><p>if for each <var>i</var> with
-     *  <var>i</var>&nbsp;&gt;=&nbsp;0 and
-     *  <var>i</var>&nbsp;&lt;&nbsp;<var>a.length</var> holds
-     *  <var>a</var>[<var>i</var>]&nbsp;== <var>b</var>[<var>i</var>].</p></li>
-     *
-     * </ul>
-     *
-     * @param a The first byte array
-     * @param b The first byte array
-     * @return <code>true</code> if the byte arrays are equal, else
-     * <code>false</code>
-     */
-    public static boolean equal(final byte[] a, final byte[] b)
-    {
-        if (a.length != b.length)
-            return false;
-        for (int i = 0; i < a.length; i++)
-            if (a[i] != b[i])
-                return false;
-        return true;
-    }
-
-
-
-    /**
-     * <p>Copies a part of a byte array into another byte array.</p>
-     *
-     * @param src The source byte array.
-     * @param srcOffset Offset in the source byte array.
-     * @param length The number of bytes to copy.
-     * @param dst The destination byte array.
-     * @param dstOffset Offset in the destination byte array.
-     */
-    public static void copy(final byte[] src, final int srcOffset,
-                            final int length, final byte[] dst,
-                            final int dstOffset)
-    {
-        for (int i = 0; i < length; i++)
-            dst[dstOffset + i] = src[srcOffset + i];
-    }
-
-
-
-    /**
-     * <p>Concatenates the contents of several byte arrays into a
-     * single one.</p>
-     *
-     * @param byteArrays The byte arrays to be concatened.
-     * @return A new byte array containing the concatenated byte
-     * arrays.
-     */
-    public static byte[] cat(final byte[][] byteArrays)
-    {
-        int capacity = 0;
-        for (int i = 0; i < byteArrays.length; i++)
-            capacity += byteArrays[i].length;
-        final byte[] result = new byte[capacity];
-        int r = 0;
-        for (int i = 0; i < byteArrays.length; i++)
-            for (int j = 0; j < byteArrays[i].length; j++)
-                result[r++] = byteArrays[i][j];
-        return result;
-    }
-
-
-
-    /**
-     * <p>Copies bytes from a source byte array into a new byte
-     * array.</p>
-     *
-     * @param src Copy from this byte array.
-     * @param offset Start copying here.
-     * @param length Copy this many bytes.
-     * @return The new byte array. Its length is number of copied bytes.
-     */
-    public static byte[] copy(final byte[] src, final int offset,
-                              final int length)
-    {
-        final byte[] result = new byte[length];
-        copy(src, offset, length, result, 0);
-        return result;
-    }
-
-
-
     /**
      * <p>The difference between the Windows epoch (1601-01-01
      * 00:00:00) and the Unix epoch (1970-01-01 00:00:00) in
@@ -189,36 +96,6 @@ public class Util
     }
 
 
-    /**
-     * <p>Checks whether two collections are equal. Two collections
-     * C<sub>1</sub> and C<sub>2</sub> are equal, if the following conditions
-     * are true:</p>
-     *
-     * <ul>
-     *
-     * <li><p>For each c<sub>1<em>i</em></sub> (element of C<sub>1</sub>) there
-     * is a c<sub>2<em>j</em></sub> (element of C<sub>2</sub>), and
-     * c<sub>1<em>i</em></sub> equals c<sub>2<em>j</em></sub>.</p></li>
-     *
-     * <li><p>For each c<sub>2<em>i</em></sub> (element of C<sub>2</sub>) there
-     * is a c<sub>1<em>j</em></sub> (element of C<sub>1</sub>) and
-     * c<sub>2<em>i</em></sub> equals c<sub>1<em>j</em></sub>.</p></li>
-     *
-     * </ul>
-     *
-     * @param c1 the first collection
-     * @param c2 the second collection
-     * @return <code>true</code> if the collections are equal, else
-     * <code>false</code>.
-     */
-    public static boolean equals(Collection<?> c1, Collection<?> c2)
-    {
-        Object[] o1 = c1.toArray();
-        Object[] o2 = c2.toArray();
-        return internalEquals(o1, o2);
-    }
-
-
 
     /**
      * <p>Compares to object arrays with regarding the objects' order. For
@@ -231,24 +108,17 @@ public class Util
      */
     public static boolean equals(Object[] c1, Object[] c2)
     {
-        final Object[] o1 = c1.clone();
-        final Object[] o2 = c2.clone();
-        return internalEquals(o1, o2);
-    }
-
-    private static boolean internalEquals(Object[] o1, Object[] o2)
-    {
-        for (int i1 = 0; i1 < o1.length; i1++)
+        for (int i1 = 0; i1 < c1.length; i1++)
         {
-            final Object obj1 = o1[i1];
+            final Object obj1 = c1[i1];
             boolean matchFound = false;
-            for (int i2 = 0; !matchFound && i2 < o1.length; i2++)
+            for (int i2 = 0; !matchFound && i2 < c1.length; i2++)
             {
-                final Object obj2 = o2[i2];
+                final Object obj2 = c2[i2];
                 if (obj1.equals(obj2))
                 {
                     matchFound = true;
-                    o2[i2] = null;
+                    c2[i2] = null;
                 }
             }
             if (!matchFound)
@@ -257,8 +127,6 @@ public class Util
         return true;
     }
 
-
-
     /**
      * <p>Pads a byte array with 0x00 bytes so that its length is a multiple of
      * 4.</p>
@@ -283,46 +151,6 @@ public class Util
     }
 
 
-
-    /**
-     * <p>Pads a character array with 0x0000 characters so that its length is a
-     * multiple of 4.</p>
-     *
-     * @param ca The character array to pad.
-     * @return The padded character array.
-     */
-    public static char[] pad4(final char[] ca)
-    {
-        final int PAD = 4;
-        final char[] result;
-        int l = ca.length % PAD;
-        if (l == 0)
-            result = ca;
-        else
-        {
-            l = PAD - l;
-            result = new char[ca.length + l];
-            System.arraycopy(ca, 0, result, 0, ca.length);
-        }
-        return result;
-    }
-
-
-
-    /**
-     * <p>Pads a string with 0x0000 characters so that its length is a
-     * multiple of 4.</p>
-     *
-     * @param s The string to pad.
-     * @return The padded string as a character array.
-     */
-    public static char[] pad4(final String s)
-    {
-        return pad4(s.toCharArray());
-    }
-
-
-
     /**
      * <p>Returns a textual representation of a {@link Throwable}, including a
      * stacktrace.</p>

Modified: poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java Sun Nov 27 20:19:18 2016
@@ -27,70 +27,77 @@ import java.util.List;
 import org.apache.poi.util.CodePageUtil;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
 
 /**
- * <p>Supports reading and writing of variant data.</p>
+ * Supports reading and writing of variant data.<p>
  *
- * <p><strong>FIXME (3):</strong> Reading and writing should be made more
- * uniform than it is now. The following items should be resolved:
+ * <strong>FIXME (3):</strong> Reading and writing should be made more
+ * uniform than it is now. The following items should be resolved:<p>
  *
  * <ul>
  *
- * <li><p>Reading requires a length parameter that is 4 byte greater than the
- * actual data, because the variant type field is included. </p></li>
+ * <li>Reading requires a length parameter that is 4 byte greater than the
+ * actual data, because the variant type field is included.
  *
- * <li><p>Reading reads from a byte array while writing writes to an byte array
- * output stream.</p></li>
+ * <li>Reading reads from a byte array while writing writes to an byte array
+ * output stream.
  *
  * </ul>
  */
-public class VariantSupport extends Variant
-{
-	private static final POILogger logger = POILogFactory.getLogger(VariantSupport.class);
+public class VariantSupport extends Variant {
+    /**
+     * HPSF is able to read these {@link Variant} types.
+     */
+    public static final int[] SUPPORTED_TYPES = { Variant.VT_EMPTY,
+            Variant.VT_I2, Variant.VT_I4, Variant.VT_I8, Variant.VT_R8,
+            Variant.VT_FILETIME, Variant.VT_LPSTR, Variant.VT_LPWSTR,
+            Variant.VT_CF, Variant.VT_BOOL };
+
+    
+    private static final POILogger logger = POILogFactory.getLogger(VariantSupport.class);
     private static boolean logUnsupportedTypes = false;
 
     /**
-     * <p>Specifies whether warnings about unsupported variant types are to be
-     * written to <code>System.err</code> or not.</p>
+     * Keeps a list of the variant types an "unsupported" message has already
+     * been issued for.
+     */
+    protected static List<Long> unsupportedMessage;
+
+    
+    /**
+     * Specifies whether warnings about unsupported variant types are to be
+     * written to {@code System.err} or not.
      *
-     * @param logUnsupportedTypes If <code>true</code> warnings will be written,
-     * if <code>false</code> they won't.
+     * @param logUnsupportedTypes If {@code true} warnings will be written,
+     * if {@code false} they won't.
      */
-    public static void setLogUnsupportedTypes(final boolean logUnsupportedTypes)
-    {
+    public static void setLogUnsupportedTypes(final boolean logUnsupportedTypes) {
         VariantSupport.logUnsupportedTypes = logUnsupportedTypes;
     }
 
     /**
-     * <p>Checks whether logging of unsupported variant types warning is turned
-     * on or off.</p>
+     * Checks whether logging of unsupported variant types warning is turned
+     * on or off.
      *
-     * @return <code>true</code> if logging is turned on, else
-     * <code>false</code>.
+     * @return {@code true} if logging is turned on, else
+     * {@code false}.
      */
-    public static boolean isLogUnsupportedTypes()
-    {
+    public static boolean isLogUnsupportedTypes() {
         return logUnsupportedTypes;
     }
 
 
 
     /**
-     * <p>Keeps a list of the variant types an "unsupported" message has already
-     * been issued for.</p>
-     */
-    protected static List<Long> unsupportedMessage;
-
-    /**
-     * <p>Writes a warning to <code>System.err</code> that a variant type is
+     * Writes a warning to {@code System.err} that a variant type is
      * unsupported by HPSF. Such a warning is written only once for each variant
-     * type. Log messages can be turned on or off by </p>
+     * type. Log messages can be turned on or off by
      *
      * @param ex The exception to log
      */
     protected static void writeUnsupportedTypeMessage
-        (final UnsupportedVariantTypeException ex)
-    {
+        (final UnsupportedVariantTypeException ex) {
         if (isLogUnsupportedTypes())
         {
             if (unsupportedMessage == null)
@@ -105,28 +112,18 @@ public class VariantSupport extends Vari
     }
 
 
-    /**
-     * <p>HPSF is able to read these {@link Variant} types.</p>
-     */
-    final static public int[] SUPPORTED_TYPES = { Variant.VT_EMPTY,
-            Variant.VT_I2, Variant.VT_I4, Variant.VT_I8, Variant.VT_R8,
-            Variant.VT_FILETIME, Variant.VT_LPSTR, Variant.VT_LPWSTR,
-            Variant.VT_CF, Variant.VT_BOOL };
-
-
 
     /**
-     * <p>Checks whether HPSF supports the specified variant type. Unsupported
+     * Checks whether HPSF supports the specified variant type. Unsupported
      * types should be implemented included in the {@link #SUPPORTED_TYPES}
-     * array.</p>
+     * array.
      *
      * @see Variant
      * @param variantType the variant type to check
-     * @return <code>true</code> if HPFS supports this type, else
-     *         <code>false</code>
+     * @return {@code true} if HPFS supports this type, else
+     *         {@code false}
      */
-    public boolean isSupportedType(final int variantType)
-    {
+    public boolean isSupportedType(final int variantType) {
         for (int i = 0; i < SUPPORTED_TYPES.length; i++)
             if (variantType == SUPPORTED_TYPES[i])
                 return true;
@@ -136,7 +133,7 @@ public class VariantSupport extends Vari
 
 
     /**
-     * <p>Reads a variant type from a byte array.</p>
+     * Reads a variant type from a byte array.
      *
      * @param src The byte array
      * @param offset The offset in the byte array where the variant starts
@@ -154,66 +151,50 @@ public class VariantSupport extends Vari
      */
     public static Object read( final byte[] src, final int offset,
             final int length, final long type, final int codepage )
-            throws ReadingNotSupportedException, UnsupportedEncodingException
-    {
-        TypedPropertyValue typedPropertyValue = new TypedPropertyValue(
-                (int) type, null );
+    throws ReadingNotSupportedException, UnsupportedEncodingException {
+        TypedPropertyValue typedPropertyValue = new TypedPropertyValue( (int) type, null );
         int unpadded;
-        try
-        {
+        try {
             unpadded = typedPropertyValue.readValue( src, offset );
-        }
-        catch ( UnsupportedOperationException exc )
-        {
+        } catch ( UnsupportedOperationException exc ) {
             int propLength = Math.min( length, src.length - offset );
             final byte[] v = new byte[propLength];
             System.arraycopy( src, offset, v, 0, propLength );
             throw new ReadingNotSupportedException( type, v );
         }
 
-        switch ( (int) type )
-        {
-        case Variant.VT_EMPTY:
-        case Variant.VT_I4:
-        case Variant.VT_I8:
-        case Variant.VT_R8:
+        switch ( (int) type ) {
             /*
              * we have more property types that can be converted into Java
              * objects, but current API need to be preserved, and it returns
              * other types as byte arrays. In future major versions it shall be
              * changed -- sergey
              */
-            return typedPropertyValue.getValue();
+            case Variant.VT_EMPTY:
+            case Variant.VT_I4:
+            case Variant.VT_I8:
+            case Variant.VT_R8:
+                return typedPropertyValue.getValue();
 
-        case Variant.VT_I2:
-        {
             /*
              * also for backward-compatibility with prev. versions of POI
              * --sergey
              */
-            return Integer.valueOf( ( (Short) typedPropertyValue.getValue() )
-                    .intValue() );
-        }
-        case Variant.VT_FILETIME:
-        {
-            Filetime filetime = (Filetime) typedPropertyValue.getValue();
-            return Util.filetimeToDate( (int) filetime.getHigh(),
-                    (int) filetime.getLow() );
-        }
-        case Variant.VT_LPSTR:
-        {
-            CodePageString string = (CodePageString) typedPropertyValue
-                    .getValue();
-            return string.getJavaValue( codepage );
-        }
-        case Variant.VT_LPWSTR:
-        {
-            UnicodeString string = (UnicodeString) typedPropertyValue
-                    .getValue();
-            return string.toJavaString();
-        }
-        case Variant.VT_CF:
-        {
+            case Variant.VT_I2:
+                return ( (Short) typedPropertyValue.getValue() ).intValue();
+
+            case Variant.VT_FILETIME:
+                Filetime filetime = (Filetime) typedPropertyValue.getValue();
+                return Util.filetimeToDate( (int) filetime.getHigh(), (int) filetime.getLow() );
+
+            case Variant.VT_LPSTR:
+                CodePageString cpString = (CodePageString) typedPropertyValue.getValue();
+                return cpString.getJavaValue( codepage );
+
+            case Variant.VT_LPWSTR:
+                UnicodeString uniString = (UnicodeString) typedPropertyValue.getValue();
+                return uniString.toJavaString();
+
             // if(l1 < 0) {
             /**
              * YK: reading the ClipboardData packet (VT_CF) is not quite
@@ -223,7 +204,7 @@ public class VariantSupport extends Vari
              * 45583 clearly show that this approach does not always work. The
              * workaround below attempts to gracefully handle such cases instead
              * of throwing exceptions.
-             * 
+             *
              * August 20, 2009
              */
             // l1 = LittleEndian.getInt(src, o1); o1 += LittleEndian.INT_SIZE;
@@ -232,33 +213,28 @@ public class VariantSupport extends Vari
             // System.arraycopy(src, o1, v, 0, v.length);
             // value = v;
             // break;
-            ClipboardData clipboardData = (ClipboardData) typedPropertyValue
-                    .getValue();
-            return clipboardData.toByteArray();
-        }
+            case Variant.VT_CF:
+                ClipboardData clipboardData = (ClipboardData) typedPropertyValue.getValue();
+                return clipboardData.toByteArray();
 
-        case Variant.VT_BOOL:
-        {
-            VariantBool bool = (VariantBool) typedPropertyValue.getValue();
-            return Boolean.valueOf( bool.getValue() );
-        }
+            case Variant.VT_BOOL:
+                VariantBool bool = (VariantBool) typedPropertyValue.getValue();
+                return bool.getValue();
 
-        default:
-        {
             /*
              * it is not very good, but what can do without breaking current
              * API? --sergey
              */
-            final byte[] v = new byte[unpadded];
-            System.arraycopy( src, offset, v, 0, unpadded );
-            throw new ReadingNotSupportedException( type, v );
-        }
+            default:
+                final byte[] v = new byte[unpadded];
+                System.arraycopy( src, offset, v, 0, unpadded );
+                throw new ReadingNotSupportedException( type, v );
         }
     }
 
     /**
-     * <p>Turns a codepage number into the equivalent character encoding's
-     * name.</p>
+     * Turns a codepage number into the equivalent character encoding's
+     * name.
      *
      * @param codepage The codepage number
      *
@@ -269,7 +245,10 @@ public class VariantSupport extends Vari
      *
      * @exception UnsupportedEncodingException if the specified codepage is
      * less than zero.
+     *
+     * @deprecated POI 3.16 - use {@link CodePageUtil#codepageToEncoding(int)}
      */
+    @Removal(version="3.18")
     public static String codepageToEncoding(final int codepage)
     throws UnsupportedEncodingException
     {
@@ -278,13 +257,13 @@ public class VariantSupport extends Vari
 
 
     /**
-     * <p>Writes a variant value to an output stream. This method ensures that
-     * always a multiple of 4 bytes is written.</p>
+     * Writes a variant value to an output stream. This method ensures that
+     * always a multiple of 4 bytes is written.<p>
      *
-     * <p>If the codepage is UTF-16, which is encouraged, strings
+     * If the codepage is UTF-16, which is encouraged, strings
      * <strong>must</strong> always be written as {@link Variant#VT_LPWSTR}
      * strings, not as {@link Variant#VT_LPSTR} strings. This method ensure this
-     * by converting strings appropriately, if needed.</p>
+     * by converting strings appropriately, if needed.
      *
      * @param out The stream to write the value to.
      * @param type The variant's type.
@@ -298,42 +277,31 @@ public class VariantSupport extends Vari
      */
     public static int write(final OutputStream out, final long type,
                             final Object value, final int codepage)
-        throws IOException, WritingNotSupportedException
-    {
+    throws IOException, WritingNotSupportedException {
         int length = 0;
-        switch ((int) type)
-        {
+        switch ((int) type) {
             case Variant.VT_BOOL:
-            {
-                if ( ( (Boolean) value ).booleanValue() )
-                {
+                if ( ( (Boolean) value ).booleanValue() ) {
                     out.write( 0xff );
                     out.write( 0xff );
-                }
-                else
-                {
+                } else {
                     out.write( 0x00 );
                     out.write( 0x00 );
                 }
                 length += 2;
                 break;
-            }
+
             case Variant.VT_LPSTR:
-            {
-                CodePageString codePageString = new CodePageString( (String) value,
-                        codepage );
+                CodePageString codePageString = new CodePageString( (String) value, codepage );
                 length += codePageString.write( out );
                 break;
-            }
+
             case Variant.VT_LPWSTR:
-            {
                 final int nrOfChars = ( (String) value ).length() + 1;
                 length += TypeWriter.writeUIntToStream( out, nrOfChars );
-                char[] s = ( (String) value ).toCharArray();
-                for ( int i = 0; i < s.length; i++ )
-                {
-                    final int high = ( ( s[i] & 0x0000ff00 ) >> 8 );
-                    final int low = ( s[i] & 0x000000ff );
+                for ( char s : ( (String) value ).toCharArray() ) {
+                    final int high = ( ( s & 0x0000ff00 ) >> 8 );
+                    final int low = ( s & 0x000000ff );
                     final byte highb = (byte) high;
                     final byte lowb = (byte) low;
                     out.write( lowb );
@@ -345,79 +313,63 @@ public class VariantSupport extends Vari
                 out.write( 0x00 );
                 length += 2;
                 break;
-            }
+
             case Variant.VT_CF:
-            {
-                final byte[] b = (byte[]) value;
-                out.write(b);
-                length = b.length;
+                final byte[] cf = (byte[]) value;
+                out.write(cf);
+                length = cf.length;
                 break;
-            }
+
             case Variant.VT_EMPTY:
-            {
                 length += TypeWriter.writeUIntToStream( out, Variant.VT_EMPTY );
                 break;
-            }
+
             case Variant.VT_I2:
-            {
-                length += TypeWriter.writeToStream( out,
-                        ( (Integer) value ).shortValue() );
+                length += TypeWriter.writeToStream( out, ( (Integer) value ).shortValue() );
                 break;
-            }
+
             case Variant.VT_I4:
-            {
-                if (!(value instanceof Integer))
-                {
+                if (!(value instanceof Integer)) {
                     throw new ClassCastException("Could not cast an object to "
                             + Integer.class.toString() + ": "
                             + value.getClass().toString() + ", "
                             + value.toString());
                 }
-                length += TypeWriter.writeToStream(out,
-                          ((Integer) value).intValue());
+                length += TypeWriter.writeToStream(out, ((Integer) value).intValue());
                 break;
-            }
+
             case Variant.VT_I8:
-            {
                 length += TypeWriter.writeToStream(out, ((Long) value).longValue());
                 break;
-            }
+
             case Variant.VT_R8:
-            {
-                length += TypeWriter.writeToStream(out,
-                          ((Double) value).doubleValue());
+                length += TypeWriter.writeToStream(out, ((Double) value).doubleValue());
                 break;
-            }
+
             case Variant.VT_FILETIME:
-            {
                 long filetime = Util.dateToFileTime((Date) value);
                 int high = (int) ((filetime >> 32) & 0x00000000FFFFFFFFL);
                 int low = (int) (filetime & 0x00000000FFFFFFFFL);
                 Filetime filetimeValue = new Filetime( low, high);
                 length += filetimeValue.write( out );
                 break;
-            }
+
             default:
-            {
                 /* The variant type is not supported yet. However, if the value
                  * is a byte array we can write it nevertheless. */
-                if (value instanceof byte[])
-                {
+                if (value instanceof byte[]) {
                     final byte[] b = (byte[]) value;
                     out.write(b);
                     length = b.length;
-                    writeUnsupportedTypeMessage
-                        (new WritingNotSupportedException(type, value));
-                }
-                else
+                    writeUnsupportedTypeMessage(new WritingNotSupportedException(type, value));
+                } else {
                     throw new WritingNotSupportedException(type, value);
+                }
                 break;
-            }
         }
 
         /* pad values to 4-bytes */
-        while ( ( length & 0x3 ) != 0 )
-        {
+        while ( ( length & 0x3 ) != 0 ) {
             out.write( 0x00 );
             length++;
         }

Modified: poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java Sun Nov 27 20:19:18 2016
@@ -27,6 +27,7 @@ import org.apache.poi.hpsf.CustomPropert
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
 import org.apache.poi.hpsf.Property;
+import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.SpecialPropertySet;
 import org.apache.poi.hpsf.SummaryInformation;
 import org.apache.poi.hpsf.wellknown.PropertyIDMap;
@@ -67,7 +68,7 @@ public class HPSFPropertiesExtractor ext
         CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
         if (cps != null) {
             for (String key : cps.nameSet()) {
-                String val = HelperPropertySet.getPropertyValueText(cps.get(key));
+                String val = getPropertyValueText(cps.get(key));
                 text.append(key).append(" = ").append(val).append("\n");
             }
         }
@@ -86,7 +87,7 @@ public class HPSFPropertiesExtractor ext
         return getPropertiesText(si);
     }
 
-    private static String getPropertiesText(SpecialPropertySet ps) {
+    private static String getPropertiesText(PropertySet ps) {
         if (ps == null) {
             // Not defined, oh well
             return "";
@@ -98,12 +99,12 @@ public class HPSFPropertiesExtractor ext
         Property[] props = ps.getProperties();
         for (Property prop : props) {
             String type = Long.toString(prop.getID());
-            Object typeObj = idMap.get(prop.getID());
+            Object typeObj = (idMap == null) ? null : idMap.get(prop.getID());
             if (typeObj != null) {
                 type = typeObj.toString();
             }
 
-            String val = HelperPropertySet.getPropertyValueText(prop.getValue());
+            String val = getPropertyValueText(prop.getValue());
             text.append(type).append(" = ").append(val).append("\n");
         }
 
@@ -125,18 +126,12 @@ public class HPSFPropertiesExtractor ext
         throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!");
     }
 
-    private static abstract class HelperPropertySet extends SpecialPropertySet {
-        public HelperPropertySet() {
-            super(null);
-        }
-        public static String getPropertyValueText(Object val) {
-            if (val == null) {
-                return "(not set)";
-            }
-            return SpecialPropertySet.getPropertyStringValue(val);
-        }
+    private static String getPropertyValueText(Object val) {
+        return (val == null) 
+            ? "(not set)"
+            : PropertySet.getPropertyStringValue(val);
     }
-
+    
     @Override
     public boolean equals(Object o) {
         return super.equals(o);

Modified: poi/trunk/src/java/org/apache/poi/util/IOUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/IOUtils.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/IOUtils.java Sun Nov 27 20:19:18 2016
@@ -45,26 +45,42 @@ public final class IOUtils {
      * @throws EmptyFileException if the stream is empty
      */
     public static byte[] peekFirst8Bytes(InputStream stream) throws IOException, EmptyFileException {
-        // We want to peek at the first 8 bytes
-        stream.mark(8);
+        return peekFirstNBytes(stream, 8);
+    }
 
-        byte[] header = new byte[8];
-        int read = IOUtils.readFully(stream, header);
+    /**
+     * Peeks at the first N bytes of the stream. Returns those bytes, but
+     *  with the stream unaffected. Requires a stream that supports mark/reset,
+     *  or a PushbackInputStream. If the stream has &gt;0 but &lt;N bytes, 
+     *  remaining bytes will be zero.
+     * @throws EmptyFileException if the stream is empty
+     */
+    public static byte[] peekFirstNBytes(InputStream stream, int limit) throws IOException, EmptyFileException {
+        stream.mark(limit);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(limit);
+        copy(new BoundedInputStream(stream, limit), bos);
 
-        if (read < 1)
+        int readBytes = bos.size();
+        if (readBytes == 0) {
             throw new EmptyFileException();
-
-        // Wind back those 8 bytes
+        }
+        
+        if (readBytes < limit) {
+            bos.write(new byte[limit-readBytes]);
+        }
+        byte peekedBytes[] = bos.toByteArray();
         if(stream instanceof PushbackInputStream) {
             PushbackInputStream pin = (PushbackInputStream)stream;
-            pin.unread(header, 0, read);
+            pin.unread(peekedBytes, 0, readBytes);
         } else {
             stream.reset();
         }
 
-        return header;
+        return peekedBytes;
     }
-
+    
+    
+    
     /**
      * Reads all the data from the input stream, and returns the bytes read.
      */

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java Sun Nov 27 20:19:18 2016
@@ -192,8 +192,7 @@ public final class TestBasic {
                 (poiFiles[0].getBytes()));
         final List<Section> sections = si.getSections();
         final Section s = sections.get(0);
-        assertTrue(org.apache.poi.hpsf.Util.equal
-            (s.getFormatID().getBytes(), SectionIDMap.SUMMARY_INFORMATION_ID));
+        assertArrayEquals(s.getFormatID().getBytes(), SectionIDMap.SUMMARY_INFORMATION_ID);
         assertNotNull(s.getProperties());
         assertEquals(17, s.getPropertyCount());
         assertEquals("Titel", s.getProperty(2));

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java Sun Nov 27 20:19:18 2016
@@ -216,7 +216,8 @@ public class TestWrite
         final MutablePropertySet ps = new MutablePropertySet();
         final MutableSection si = new MutableSection();
         si.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID);
-        ps.getSections().set(0, si);
+        ps.clearSections();
+        ps.addSection(si);
 
         final MutableProperty p = new MutableProperty();
         p.setID(PropertyIDMap.PID_AUTHOR);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org