poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r707541 - in /poi/trunk/src/java/org/apache/poi: hssf/record/EmbeddedObjectRefSubRecord.java hssf/record/formula/StringPtg.java util/LittleEndianByteArrayInputStream.java util/LittleEndianInput.java util/LittleEndianInputStream.java
Date Fri, 24 Oct 2008 04:30:39 GMT
Author: josh
Date: Thu Oct 23 21:30:38 2008
New Revision: 707541

URL: http://svn.apache.org/viewvc?rev=707541&view=rev
Log:
Removed String methods from LittleEndianInput

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

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java?rev=707541&r1=707540&r2=707541&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java Thu Oct
23 21:30:38 2008
@@ -26,7 +26,6 @@
 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 @@
 				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 {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java?rev=707541&r1=707540&r2=707541&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java Thu Oct 23 21:30:38
2008
@@ -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 @@
  * @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 @@
             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 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() {

Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java?rev=707541&r1=707540&r2=707541&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java Thu Oct 23
21:30:38 2008
@@ -114,20 +114,4 @@
 	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);
-	}
 }

Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndianInput.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianInput.java?rev=707541&r1=707540&r2=707541&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianInput.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianInput.java Thu Oct 23 21:30:38 2008
@@ -30,6 +30,4 @@
 	double readDouble();
 	void readFully(byte[] buf);
 	void readFully(byte[] buf, int off, int len);
-	String readUnicodeLEString(int nChars);
-	String readCompressedUnicode(int nChars);
 }

Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java?rev=707541&r1=707540&r2=707541&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java Thu Oct 23 21:30:38
2008
@@ -131,34 +131,4 @@
 			buf[i] = (byte) ch;
 		}
 	}
-	public String readCompressedUnicode(int nChars) {
-		char[] buf = new char[nChars];
-		for (int i = 0; i < buf.length; i++) {
-			int ch;
-			try {
-				ch = in.read();
-			} catch (IOException e) {
-				throw new RuntimeException(e);
-			}
-			checkEOF(ch);
-			buf[i] = (char) ch;
-			
-		}
-		return new String(buf);
-	}
-	public String readUnicodeLEString(int nChars) {
-		char[] buf = new char[nChars];
-		for (int i = 0; i < buf.length; i++) {
-			int ch;
-			try {
-				ch = in.read();
-			} catch (IOException e) {
-				throw new RuntimeException(e);
-			}
-			checkEOF(ch);
-			buf[i] = (char) ch;
-			
-		}
-		return new String(buf);
-	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message