Index: src/java/org/apache/poi/hpsf/Property.java =================================================================== RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hpsf/Property.java,v --- src/java/org/apache/poi/hpsf/Property.java 1.20 +++ src/java/org/apache/poi/hpsf/Property.java @@ -170,9 +170,12 @@ * @param length The dictionary contains at most this many bytes. * @param codepage The codepage of the string values. * @return The dictonary + * @exception UnsupportedEncodingException if the specified codepage is not + * supported. */ protected Map readDictionary(final byte[] src, final long offset, final int length, final int codepage) + throws UnsupportedEncodingException { /* Check whether "offset" points into the "src" array". */ if (offset < 0 || offset > src.length) @@ -202,19 +205,23 @@ long sLength = LittleEndian.getUInt(src, o); o += LittleEndian.INT_SIZE; - /* Read the bytes or characters depending on whether the - * character set is Unicode or not. */ - StringBuffer b = new StringBuffer((int) sLength); - for (int j = 0; j < sLength; j++) - if (codepage == Constants.CP_UNICODE) - { - final int i1 = o + (j * 2); - final int i2 = i1 + 1; - b.append((char) ((src[i2] << 8) + src[i1])); - } - else - b.append((char) src[o + j]); - + String value; + switch (codepage) + { + case -1: + value = new String(src, o, (int) sLength); + break; + case Constants.CP_UNICODE: + // In the case of UTF-16, the length represents the number of characters. + value = new String(src, o, (int) sLength * 2, VariantSupport.codepageToEncoding(codepage)); + break; + default: + // TODO: Confirm the behaviour of UTF-8. + value = new String(src, o, (int) sLength, VariantSupport.codepageToEncoding(codepage)); + } + + StringBuffer b = new StringBuffer(value); + /* Strip 0x00 characters from the end of the string: */ while (b.length() > 0 && b.charAt(b.length() - 1) == 0x00) b.setLength(b.length() - 1);