klute       2003/07/25 23:52:54

  Modified:    src/java/org/apache/poi/hpsf TypeReader.java
  Log:
  Bug 21775
  
  Revision  Changes    Path
  1.3       +43 -33    jakarta-poi/src/java/org/apache/poi/hpsf/TypeReader.java
  
  Index: TypeReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hpsf/TypeReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TypeReader.java   5 Feb 2003 19:33:27 -0000       1.2
  +++ TypeReader.java   26 Jul 2003 06:52:54 -0000      1.3
  @@ -62,7 +62,6 @@
    */
   package org.apache.poi.hpsf;
   
  -import java.util.*;
   import org.apache.poi.util.LittleEndian;
   
   /**
  @@ -85,6 +84,7 @@
        * starts
        * @param length The length of the variant including the variant
        * type field
  +     * @param type The variant type to read
        * @return A Java object that corresponds best to the variant
        * field. For example, a VT_I4 is returned as a [EMAIL PROTECTED] Long}, a
        * VT_LPSTR as a [EMAIL PROTECTED] String}.
  @@ -92,15 +92,25 @@
        * @see Variant
        */
       public static Object read(final byte[] src, int offset, int length,
  -                           final int type)
  +                              final int type)
       {
  -     /*
  -      * FIXME: Support reading more types and clean up this code!
  -      */
  -     Object value;
  -     length = length - LittleEndian.INT_SIZE;
  +        /*
  +         * FIXME: Support reading more types and clean up this code!
  +         */
  +        Object value;
  +        length = length - LittleEndian.INT_SIZE;
           switch (type)
  -     {
  +        {
  +            case Variant.VT_EMPTY:
  +            {
  +                /*
  +                 * FIXME: The value returned by this case relies on the
  +                 * assumption that the value VT_EMPTY denotes consists of zero 
  +                 * bytes. I'd be glad if some could confirm or correct this. 
  +                 */
  +                value = null;
  +                break;
  +            }
               case Variant.VT_I2:
               {
                   /*
  @@ -137,11 +147,11 @@
                    * Read a byte string. In Java it is represented as a
                    * String object. The 0x00 bytes at the end must be
                    * stripped.
  -              *
  -              * FIXME: Reading an 8-bit string should pay attention
  -              * to the codepage. Currently the byte making out the
  -              * property's value are interpreted according to the
  -              * platform's default character set.
  +                 *
  +                 * FIXME: Reading an 8-bit string should pay attention
  +                 * to the codepage. Currently the byte making out the
  +                 * property's value are interpreted according to the
  +                 * platform's default character set.
                    */
                   final int first = offset + LittleEndian.INT_SIZE;
                   long last = first + LittleEndian.getUInt(src, offset) - 1;
  @@ -149,7 +159,7 @@
                   while (src[(int) last] == 0 && first <= last)
                       last--;
                   value = new String(src, (int) first, (int) (last - first + 1));
  -             break;
  +                break;
               }
               case Variant.VT_LPWSTR:
               {
  @@ -160,27 +170,27 @@
                    */
                   final int first = offset + LittleEndian.INT_SIZE;
                   long last = first + LittleEndian.getUInt(src, offset) - 1;
  -             long l = last - first;
  +                long l = last - first;
                   offset += LittleEndian.INT_SIZE;
  -             StringBuffer b = new StringBuffer((int) (last - first));
  -             for (int i = 0; i <= l; i++)
  -             {
  -                 final int i1 = offset + (i * 2);
  -                 final int i2 = i1 + 1;
  -                 b.append((char) ((src[i2] << 8) + src[i1]));
  -             }
  -             /* Strip 0x00 characters from the end of the string: */
  -             while (b.charAt(b.length() - 1) == 0x00)
  -                 b.setLength(b.length() - 1);
  -             value = b.toString();
  -             break;
  +                StringBuffer b = new StringBuffer((int) (last - first));
  +                for (int i = 0; i <= l; i++)
  +                {
  +                    final int i1 = offset + (i * 2);
  +                    final int i2 = i1 + 1;
  +                    b.append((char) ((src[i2] << 8) + src[i1]));
  +                }
  +                /* Strip 0x00 characters from the end of the string: */
  +                while (b.charAt(b.length() - 1) == 0x00)
  +                    b.setLength(b.length() - 1);
  +                value = b.toString();
  +                break;
               }
               case Variant.VT_CF:
               {
                   final byte[] v = new byte[length];
                   for (int i = 0; i < length; i++)
                       v[i] = src[(int) (offset + i)];
  -             value = v;
  +                value = v;
                   break;
               }
               case Variant.VT_BOOL:
  @@ -190,24 +200,24 @@
                    * src[offset + 3] contain the DWord for VT_BOOL, so
                    * skip it, we don't need it.
                    */
  -                final int first = offset + LittleEndian.INT_SIZE;
  +                // final int first = offset + LittleEndian.INT_SIZE;
                   long bool = LittleEndian.getUInt(src, offset);
                   if (bool != 0)
                       value = new Boolean(true);
                   else
                       value = new Boolean(false);
  -             break;
  +                break;
               }
               default:
               {
                   final byte[] v = new byte[length];
                   for (int i = 0; i < length; i++)
                       v[i] = src[(int) (offset + i)];
  -             value = v;
  +                value = v;
                   break;
               }
           }
  -     return value;
  +        return value;
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to