From c465577bd5c1528a50e83eaf09ac6bdf159293ea Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Thu, 21 Mar 2002 02:09:31 +0000 Subject: [PATCH] Applied fixes from Shawn Laubach for footer and header records PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352259 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/record/FooterRecord.java | 14 +++++++------- .../org/apache/poi/hssf/record/HeaderRecord.java | 15 ++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/FooterRecord.java b/src/java/org/apache/poi/hssf/record/FooterRecord.java index 7ef88b95e7..5a633de1d8 100644 --- a/src/java/org/apache/poi/hssf/record/FooterRecord.java +++ b/src/java/org/apache/poi/hssf/record/FooterRecord.java @@ -117,7 +117,7 @@ public class FooterRecord if (size > 0) { field_1_footer_len = data[ 0 + offset ]; - field_2_footer = new String(data, 1 + offset, + field_2_footer = new String(data, 3 + offset, // [Shawn] Changed 1 to 3 for offset of string LittleEndian.ubyteToInt( field_1_footer_len) ); } } @@ -153,9 +153,9 @@ public class FooterRecord * @see #getFooter() */ - public byte getFooterLength() + public short getFooterLength() { - return field_1_footer_len; + return (short)(0xFF & field_1_footer_len); // [Shawn] Fixed needing unsigned byte } /** @@ -189,15 +189,15 @@ public class FooterRecord if (getFooterLength() > 0) { - len++; + len+=3; // [Shawn] Fixed for two null bytes in the length } LittleEndian.putShort(data, 0 + offset, sid); LittleEndian.putShort(data, 2 + offset, ( short ) ((len - 4) + getFooterLength())); if (getFooterLength() > 0) { - data[ 4 + offset ] = getFooterLength(); - StringUtil.putCompressedUnicode(getFooter(), data, 5 + offset); + data[ 4 + offset ] = (byte)getFooterLength(); + StringUtil.putCompressedUnicode(getFooter(), data, 7 + offset); // [Shawn] Place the string in the correct offset } return getRecordSize(); } @@ -208,7 +208,7 @@ public class FooterRecord if (getFooterLength() > 0) { - retval++; + retval+=3; // [Shawn] Fixed for two null bytes in the length } return retval + getFooterLength(); } diff --git a/src/java/org/apache/poi/hssf/record/HeaderRecord.java b/src/java/org/apache/poi/hssf/record/HeaderRecord.java index d5371b322c..084d3a816a 100644 --- a/src/java/org/apache/poi/hssf/record/HeaderRecord.java +++ b/src/java/org/apache/poi/hssf/record/HeaderRecord.java @@ -117,7 +117,7 @@ public class HeaderRecord if (size > 0) { field_1_header_len = data[ 0 + offset ]; - field_2_header = new String(data, 1 + offset, + field_2_header = new String(data, 3 + offset, // [Shawn] Changed 1 to 3 for offset of string LittleEndian.ubyteToInt(field_1_header_len)); } } @@ -153,9 +153,9 @@ public class HeaderRecord * @see #getHeader() */ - public byte getHeaderLength() + public short getHeaderLength() { - return field_1_header_len; + return (short)(0xFF & field_1_header_len); // [Shawn] Fixed needing unsigned byte } /** @@ -189,15 +189,16 @@ public class HeaderRecord if (getHeaderLength() != 0) { - len++; + len+=3; // [Shawn] Fixed for two null bytes in the length } LittleEndian.putShort(data, 0 + offset, sid); LittleEndian.putShort(data, 2 + offset, ( short ) ((len - 4) + getHeaderLength())); + if (getHeaderLength() > 0) { - data[ 4 + offset ] = getHeaderLength(); - StringUtil.putCompressedUnicode(getHeader(), data, 5 + offset); + data[ 4 + offset ] = (byte)getHeaderLength(); + StringUtil.putCompressedUnicode(getHeader(), data, 7 + offset); // [Shawn] Place the string in the correct offset } return getRecordSize(); } @@ -208,7 +209,7 @@ public class HeaderRecord if (getHeaderLength() != 0) { - retval++; + retval+=3; // [Shawn] Fixed for two null bytes in the length } retval += getHeaderLength(); return retval;