From 9a3408108819700713678270af50409d706c0601 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Sat, 22 Oct 2011 02:01:04 +0000 Subject: [PATCH] accept java string git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1187637 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hpsf/UnicodeString.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/UnicodeString.java b/src/java/org/apache/poi/hpsf/UnicodeString.java index b2595d87d5..5d10740068 100644 --- a/src/java/org/apache/poi/hpsf/UnicodeString.java +++ b/src/java/org/apache/poi/hpsf/UnicodeString.java @@ -2,6 +2,7 @@ package org.apache.poi.hpsf; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; @Internal class UnicodeString @@ -18,9 +19,8 @@ class UnicodeString return; } - _value = new byte[length * 2]; - LittleEndian.getByteArray( data, offset + LittleEndian.INT_SIZE, - length * 2 ); + _value = LittleEndian.getByteArray( data, offset + + LittleEndian.INT_SIZE, length * 2 ); if ( _value[length * 2 - 1] != 0 || _value[length * 2 - 2] != 0 ) throw new IllegalPropertySetDataException( @@ -28,8 +28,22 @@ class UnicodeString + " is not NULL-terminated" ); } + String toJavaString() + { + if ( _value.length == 0 ) + return null; + + return StringUtil.getFromUnicodeLE( _value, 0, + ( _value.length - 2 ) >> 1 ); + } + int getSize() { return LittleEndian.INT_SIZE + _value.length; } + + byte[] getValue() + { + return _value; + } } -- 2.39.5