]> source.dussan.org Git - poi.git/commitdiff
Removed String methods from LittleEndianInput
authorJosh Micich <josh@apache.org>
Fri, 24 Oct 2008 04:30:38 +0000 (04:30 +0000)
committerJosh Micich <josh@apache.org>
Fri, 24 Oct 2008 04:30:38 +0000 (04:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@707541 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
src/java/org/apache/poi/hssf/record/formula/StringPtg.java
src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
src/java/org/apache/poi/util/LittleEndianInput.java
src/java/org/apache/poi/util/LittleEndianInputStream.java

index f40dc0a49a86015c1ed1a77910ba973343cf8080..f033149ee871e40862c756f7915a44278ea2eddf 100644 (file)
@@ -26,7 +26,6 @@ import org.apache.poi.hssf.record.formula.Ref3DPtg;
 import org.apache.poi.hssf.record.formula.RefPtg;
 import org.apache.poi.util.HexDump;
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.LittleEndianByteArrayOutputStream;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianInputStream;
 import org.apache.poi.util.LittleEndianOutput;
@@ -113,10 +112,10 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
                                field_3_unicode_flag = ( in.readByte() & 0x01 ) != 0;
                                remaining -= LittleEndian.BYTE_SIZE;
                                if (field_3_unicode_flag) {
-                                       field_4_ole_classname = in.readUnicodeLEString(nChars);
+                                       field_4_ole_classname = StringUtil.readUnicodeLE(in, nChars);
                                        stringByteCount = nChars * 2;
                                } else {
-                                       field_4_ole_classname = in.readCompressedUnicode(nChars);
+                                       field_4_ole_classname = StringUtil.readCompressedUnicode(in, nChars);
                                        stringByteCount = nChars;
                                }
                        } else {
index 59a5521cc2c577415f6388aa41bf0d4821ab420f..be6a20d6e4952c38d3e21b23e4a782f06fe7c889 100644 (file)
@@ -17,8 +17,6 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.util.BitField;
-import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianOutput;
 import org.apache.poi.util.StringUtil;
@@ -32,29 +30,26 @@ import org.apache.poi.util.StringUtil;
  * @author Bernard Chesnoy
  */
 public final class StringPtg extends ScalarConstantPtg {
-    public final static int SIZE = 9;
-    public final static byte sid = 0x17;
-    private static final BitField fHighByte = BitFieldFactory.getInstance(0x01);
-    /** the character (")used in formulas to delimit string literals */
+     public final static byte sid = 0x17;
+    /** the character (") used in formulas to delimit string literals */
     private static final char FORMULA_DELIMITER = '"';
 
+    private final boolean _is16bitUnicode;
     /**
      * NOTE: OO doc says 16bit length, but BiffViewer says 8 Book says something
      * totally different, so don't look there!
      */
-    private final int field_1_length;
-    private final byte field_2_options;
     private final String field_3_string;
 
     /** Create a StringPtg from a stream */
     public StringPtg(LittleEndianInput in)  {
-        field_1_length = in.readUByte();
-        field_2_options = in.readByte();
-        if (fHighByte.isSet(field_2_options)) {
-            field_3_string = in.readUnicodeLEString(field_1_length);
-        } else {
-            field_3_string = in.readCompressedUnicode(field_1_length);
-        }
+       int nChars = in.readUByte(); // Note - nChars is 8-bit
+       _is16bitUnicode = (in.readByte() & 0x01) != 0;
+       if (_is16bitUnicode) {
+               field_3_string = StringUtil.readUnicodeLE(in, nChars);
+       } else {
+               field_3_string = StringUtil.readCompressedUnicode(in, nChars);
+       }
     }
 
     /**
@@ -70,9 +65,8 @@ public final class StringPtg extends ScalarConstantPtg {
             throw new IllegalArgumentException(
                     "String literals in formulas can't be bigger than 255 characters ASCII");
         }
-        field_2_options = (byte) fHighByte.setBoolean(0, StringUtil.hasMultibyte(value));
+        _is16bitUnicode = StringUtil.hasMultibyte(value);
         field_3_string = value;
-        field_1_length = value.length(); // for the moment, we support only ASCII strings in formulas we create
     }
 
     public String getValue() {
@@ -81,21 +75,17 @@ public final class StringPtg extends ScalarConstantPtg {
 
     public void write(LittleEndianOutput out) {
         out.writeByte(sid + getPtgClass());
-        out.writeByte(field_1_length);
-        out.writeByte(field_2_options);
-        if (fHighByte.isSet(field_2_options)) {
-            StringUtil.putUnicodeLE(getValue(), out);
+        out.writeByte(field_3_string.length()); // Note - nChars is 8-bit
+        out.writeByte(_is16bitUnicode ? 0x01 : 0x00);
+        if (_is16bitUnicode) {
+               StringUtil.putUnicodeLE(field_3_string, out);
         } else {
-            StringUtil.putCompressedUnicode(getValue(), out);
+               StringUtil.putCompressedUnicode(field_3_string, out);
         }
     }
 
     public int getSize() {
-        if (fHighByte.isSet(field_2_options)) {
-            return 2 * field_1_length + 3;
-        } else {
-            return field_1_length + 3;
-        }
+       return 3 +  field_3_string.length() * (_is16bitUnicode ? 2 : 1);
     }
 
     public String toFormulaString() {
index 3ea0ab61a2cee3eb5f35be3769c0fc36df500fbc..2729ab773ac8b59981c95d05782fd56af47520a4 100644 (file)
@@ -114,20 +114,4 @@ public final class LittleEndianByteArrayInputStream implements LittleEndianInput
        public double readDouble() {
                return Double.longBitsToDouble(readLong());
        }
-       public String readCompressedUnicode(int nChars) {
-               checkPosition(nChars);
-               char[] buf = new char[nChars];
-               for (int i = 0; i < buf.length; i++) {
-                       buf[i] = (char) readUByte();
-               }
-               return new String(buf);
-       }
-       public String readUnicodeLEString(int nChars) {
-               checkPosition(nChars*2);
-               char[] buf = new char[nChars];
-               for (int i = 0; i < buf.length; i++) {
-                       buf[i] = (char) readUShort();
-               }
-               return new String(buf);
-       }
 }
index 433999dfc3fe5f42d0a5d1027d39b1c51e0fc746..64bbd186261c7d028d3d9df47b06ba206760d751 100644 (file)
@@ -30,6 +30,4 @@ public interface LittleEndianInput {
        double readDouble();\r
        void readFully(byte[] buf);\r
        void readFully(byte[] buf, int off, int len);\r
-       String readUnicodeLEString(int nChars);\r
-       String readCompressedUnicode(int nChars);\r
 }\r
index 035230491baccd8d2f56a3ebfb99235960c59707..329119bfbe18e34ab271f7c74442576b13af9d14 100644 (file)
@@ -131,34 +131,4 @@ public class LittleEndianInputStream extends FilterInputStream implements Little
                        buf[i] = (byte) ch;\r
                }\r
        }\r
-       public String readCompressedUnicode(int nChars) {\r
-               char[] buf = new char[nChars];\r
-               for (int i = 0; i < buf.length; i++) {\r
-                       int ch;\r
-                       try {\r
-                               ch = in.read();\r
-                       } catch (IOException e) {\r
-                               throw new RuntimeException(e);\r
-                       }\r
-                       checkEOF(ch);\r
-                       buf[i] = (char) ch;\r
-                       \r
-               }\r
-               return new String(buf);\r
-       }\r
-       public String readUnicodeLEString(int nChars) {\r
-               char[] buf = new char[nChars];\r
-               for (int i = 0; i < buf.length; i++) {\r
-                       int ch;\r
-                       try {\r
-                               ch = in.read();\r
-                       } catch (IOException e) {\r
-                               throw new RuntimeException(e);\r
-                       }\r
-                       checkEOF(ch);\r
-                       buf[i] = (char) ch;\r
-                       \r
-               }\r
-               return new String(buf);\r
-       }\r
 }\r