1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.xmerge.converter.xml.sxc.pexcel.records;
25 
26 import java.io.OutputStream;
27 import java.io.InputStream;
28 import java.io.IOException;
29 
30 import org.openoffice.xmerge.util.Debug;
31 import org.openoffice.xmerge.util.EndianConverter;
32 import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelConstants;
33 
34 /**
35  * Represents a BIFF Record describing a floating point
36  */
37 public class FloatNumber extends CellValue {
38 
39     protected byte[] num  = new byte[8];
40 
41 	/**
42  	 * Constructs a pocket Excel Document from the
43  	 * <code>InputStream</code> and assigns it the document name passed in
44 	 *
45  	 * @param	is InputStream containing a Pocket Excel Data file.
46  	 */
FloatNumber(InputStream is)47     public FloatNumber(InputStream is) throws IOException {
48     	read(is);
49 	}
50 
51 	/**
52  	 * Constructs a <code>FloatNumber</code> using specified attributes
53 	 *
54 	 * @param row row number
55 	 * @param column column number
56 	 * @param cellContents contents of the cell
57 	 * @param ixfe font index
58  	 */
FloatNumber(int row, int column, String cellContents, int ixfe)59     public FloatNumber(int row, int column, String cellContents, int ixfe) throws IOException {
60 
61 		setIxfe(ixfe);
62 		setRow(row);
63 	   	setCol(column);
64 		double cellLong = (double) Double.parseDouble(cellContents);
65 		num 	= EndianConverter.writeDouble(cellLong);
66 	}
67 
68     /**
69 	 * Get the hex code for this particular <code>BIFFRecord</code>
70 	 *
71 	 * @return the hex code for <code>FloatNumber</code>
72 	 */
getBiffType()73     public short getBiffType() {
74         return PocketExcelConstants.NUMBER_CELL;
75     }
76 
77     /**
78 	 * Reads a<code>FloatNumber</code> from the specified <code>InputStream</code>
79 	 *
80 	 * @param input the <code>InputStram</code> to read from
81 	 */
read(InputStream input)82     public int read(InputStream input) throws IOException {
83 
84 		int numOfBytesRead = super.read(input);
85 
86         numOfBytesRead += input.read(num);
87 
88         Debug.log(Debug.TRACE," num : " + getString());
89         return numOfBytesRead;
90     }
91 
write(OutputStream output)92     public void write(OutputStream output) throws IOException {
93 
94     	output.write(getBiffType());
95 
96 		super.write(output);
97 
98 	    output.write(num);
99 
100 		Debug.log(Debug.TRACE,"Writing FloatNumber record");
101     }
102 
103 
104     /**
105 	 * Gets the numerical value the cell represents
106 	 *
107 	 * @return the <code>String</code> representing a double value
108 	 */
getString()109 	public String getString() throws IOException {
110 
111 		double value = EndianConverter.readDouble(num);
112 		Double myDo = new Double(value);
113 		return myDo.toString();
114 	}
115 
116 }
117