From 43e7e42b1c3fc4686556ff1e61fa6871a9c80aca Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Tue, 22 Apr 2003 16:29:43 +0000 Subject: [PATCH] http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18947 PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353064 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/BoundSheetRecord.java | 2 +- .../apache/poi/hssf/record/FontRecord.java | 2 +- .../apache/poi/hssf/record/FooterRecord.java | 2 +- .../apache/poi/hssf/record/FormatRecord.java | 2 +- .../apache/poi/hssf/record/HeaderRecord.java | 2 +- .../apache/poi/hssf/record/LabelRecord.java | 2 +- .../apache/poi/hssf/record/NameRecord.java | 10 +++++----- .../apache/poi/hssf/record/StringRecord.java | 2 +- .../apache/poi/hssf/record/StyleRecord.java | 2 +- .../poi/hssf/record/WriteAccessRecord.java | 2 +- src/java/org/apache/poi/util/StringUtil.java | 20 +++++++++++++++++++ 11 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java b/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java index 3202baae39..c18a202bb5 100644 --- a/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java +++ b/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java @@ -142,7 +142,7 @@ public class BoundSheetRecord } else { - field_5_sheetname = new String( data, 8 + offset, nameLength ); + field_5_sheetname = StringUtil.getFromCompressedUnicode( data, 8 + offset, nameLength ); } } diff --git a/src/java/org/apache/poi/hssf/record/FontRecord.java b/src/java/org/apache/poi/hssf/record/FontRecord.java index a7bd970efe..332f2b304a 100644 --- a/src/java/org/apache/poi/hssf/record/FontRecord.java +++ b/src/java/org/apache/poi/hssf/record/FontRecord.java @@ -164,7 +164,7 @@ public class FontRecord { if (data[ 15 ] == 0) { // is compressed unicode - field_11_font_name = new String(data, 16, + field_11_font_name = StringUtil.getFromCompressedUnicode(data, 16, LittleEndian.ubyteToInt(field_10_font_name_len)); } else diff --git a/src/java/org/apache/poi/hssf/record/FooterRecord.java b/src/java/org/apache/poi/hssf/record/FooterRecord.java index 879a9036a0..4082c16ee4 100644 --- a/src/java/org/apache/poi/hssf/record/FooterRecord.java +++ b/src/java/org/apache/poi/hssf/record/FooterRecord.java @@ -119,7 +119,7 @@ public class FooterRecord if (size > 0) { field_1_footer_len = data[ 0 + offset ]; - field_2_footer = new String(data, 3 + offset, // [Shawn] Changed 1 to 3 for offset of string + field_2_footer = StringUtil.getFromCompressedUnicode(data, 3 + offset, // [Shawn] Changed 1 to 3 for offset of string LittleEndian.ubyteToInt( field_1_footer_len) ); } } diff --git a/src/java/org/apache/poi/hssf/record/FormatRecord.java b/src/java/org/apache/poi/hssf/record/FormatRecord.java index 5dd1b01572..4feaee674c 100644 --- a/src/java/org/apache/poi/hssf/record/FormatRecord.java +++ b/src/java/org/apache/poi/hssf/record/FormatRecord.java @@ -132,7 +132,7 @@ public class FormatRecord } else { // not unicode - field_4_formatstring = new String(data, 5 + offset, field_3_unicode_len ); + field_4_formatstring = StringUtil.getFromCompressedUnicode(data, 5 + offset, field_3_unicode_len ); } } diff --git a/src/java/org/apache/poi/hssf/record/HeaderRecord.java b/src/java/org/apache/poi/hssf/record/HeaderRecord.java index 3883317fb7..c87ed25896 100644 --- a/src/java/org/apache/poi/hssf/record/HeaderRecord.java +++ b/src/java/org/apache/poi/hssf/record/HeaderRecord.java @@ -119,7 +119,7 @@ public class HeaderRecord if (size > 0) { field_1_header_len = data[ 0 + offset ]; - field_2_header = new String(data, 3 + offset, // [Shawn] Changed 1 to 3 for offset of string + field_2_header = StringUtil.getFromCompressedUnicode(data, 3 + offset, // [Shawn] Changed 1 to 3 for offset of string LittleEndian.ubyteToInt(field_1_header_len)); } } diff --git a/src/java/org/apache/poi/hssf/record/LabelRecord.java b/src/java/org/apache/poi/hssf/record/LabelRecord.java index 9a7d73dd2e..171d65abb3 100644 --- a/src/java/org/apache/poi/hssf/record/LabelRecord.java +++ b/src/java/org/apache/poi/hssf/record/LabelRecord.java @@ -157,7 +157,7 @@ public class LabelRecord } else { - field_6_value = new String(data, 9 + offset, getStringLength()); + field_6_value = StringUtil.getFromCompressedUnicode(data, 9 + offset, getStringLength()); } } diff --git a/src/java/org/apache/poi/hssf/record/NameRecord.java b/src/java/org/apache/poi/hssf/record/NameRecord.java index 406b06b23c..dab7597464 100644 --- a/src/java/org/apache/poi/hssf/record/NameRecord.java +++ b/src/java/org/apache/poi/hssf/record/NameRecord.java @@ -756,7 +756,7 @@ public class NameRecord extends Record { field_12_builtIn_name = data[ 15 + offset ]; } - field_12_name_text = new String(data, 15 + offset, + field_12_name_text = StringUtil.getFromCompressedUnicode(data, 15 + offset, LittleEndian.ubyteToInt(field_3_length_name_text)); int start_of_name_definition = 15 + field_3_length_name_text; @@ -764,19 +764,19 @@ public class NameRecord extends Record { offset, start_of_name_definition); int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition; - field_14_custom_menu_text = new String(data, start_of_custom_menu_text + offset, + field_14_custom_menu_text = StringUtil.getFromCompressedUnicode(data, start_of_custom_menu_text + offset, LittleEndian.ubyteToInt(field_7_length_custom_menu)); int start_of_description_text = start_of_custom_menu_text + field_8_length_description_text; - field_15_description_text = new String(data, start_of_description_text + offset, + field_15_description_text = StringUtil.getFromCompressedUnicode(data, start_of_description_text + offset, LittleEndian.ubyteToInt(field_8_length_description_text)); int start_of_help_topic_text = start_of_description_text + field_9_length_help_topic_text; - field_16_help_topic_text = new String(data, start_of_help_topic_text + offset, + field_16_help_topic_text = StringUtil.getFromCompressedUnicode(data, start_of_help_topic_text + offset, LittleEndian.ubyteToInt(field_9_length_help_topic_text)); int start_of_status_bar_text = start_of_help_topic_text + field_10_length_status_bar_text; - field_17_status_bar_text = new String(data, start_of_status_bar_text + offset, + field_17_status_bar_text = StringUtil.getFromCompressedUnicode(data, start_of_status_bar_text + offset, LittleEndian.ubyteToInt(field_10_length_status_bar_text)); /*} */ } diff --git a/src/java/org/apache/poi/hssf/record/StringRecord.java b/src/java/org/apache/poi/hssf/record/StringRecord.java index 6b6cdea241..2e5fc734c4 100644 --- a/src/java/org/apache/poi/hssf/record/StringRecord.java +++ b/src/java/org/apache/poi/hssf/record/StringRecord.java @@ -134,7 +134,7 @@ public class StringRecord } else { - field_3_string = new String(data, 3 + offset, field_1_string_length); + field_3_string = StringUtil.getFromCompressedUnicode(data, 3 + offset, field_1_string_length); } } diff --git a/src/java/org/apache/poi/hssf/record/StyleRecord.java b/src/java/org/apache/poi/hssf/record/StyleRecord.java index 3ce8c4ea91..2a5a63bea0 100644 --- a/src/java/org/apache/poi/hssf/record/StyleRecord.java +++ b/src/java/org/apache/poi/hssf/record/StyleRecord.java @@ -134,7 +134,7 @@ public class StyleRecord else if (getType() == 0) { field_2_name_length = data[ 2 + offset ]; - field_3_name = new String(data, 3 + offset, + field_3_name = StringUtil.getFromCompressedUnicode(data, 3 + offset, LittleEndian.ubyteToInt(field_2_name_length)); } diff --git a/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java b/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java index c35b94c851..698997f539 100644 --- a/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java +++ b/src/java/org/apache/poi/hssf/record/WriteAccessRecord.java @@ -115,7 +115,7 @@ public class WriteAccessRecord protected void fillFields(byte [] data, short size, int offset) { - field_1_username = new String(data, 3 + offset, data.length - 4); + field_1_username = StringUtil.getFromCompressedUnicode(data, 3 + offset, data.length - 4); } /** diff --git a/src/java/org/apache/poi/util/StringUtil.java b/src/java/org/apache/poi/util/StringUtil.java index 378b1af0ae..f1e16c707a 100644 --- a/src/java/org/apache/poi/util/StringUtil.java +++ b/src/java/org/apache/poi/util/StringUtil.java @@ -197,6 +197,26 @@ public class StringUtil { } + /** + * read compressed unicode(8bit) + * + * @author Toshiaki Kamoshida(kamoshida.toshiaki at future dot co dot jp) + * + * @param string byte array to read + * @param offset offset to read byte array + * @param len length to read byte array + * @return String generated String instance by reading byte array + */ + public static String getFromCompressedUnicode(final byte[] string, + final int offset, final int len){ + try{ + return new String(string,offset,len,"ISO-8859-1"); + } + catch(UnsupportedEncodingException e){ + throw new InternalError();/* unreachable */ + } + } + /** * write compressed unicode * -- 2.39.5