]> source.dussan.org Git - poi.git/commitdiff
Fixes to chart handling and to a hidden bug to do with where the beginning of the...
authorGlen Stampoultzis <glens@apache.org>
Wed, 21 Aug 2002 11:56:49 +0000 (11:56 +0000)
committerGlen Stampoultzis <glens@apache.org>
Wed, 21 Aug 2002 11:56:49 +0000 (11:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352827 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/eventmodel/HSSFEventFactory.java
src/java/org/apache/poi/hssf/model/Sheet.java
src/java/org/apache/poi/hssf/record/DBCellRecord.java
src/java/org/apache/poi/hssf/record/FormulaRecord.java
src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java
src/java/org/apache/poi/hssf/record/formula/Ptg.java
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/java/org/apache/poi/util/LittleEndian.java
src/testcases/org/apache/poi/util/TestLittleEndian.java

index 4935f1ef4c425073bb3fb09ca1ae736424f7c01a..5e07c953f05cf01c201e6a9899adbd42de268987 100644 (file)
@@ -78,7 +78,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  * @see org.apache.poi.hssf.dev.EFHSSF
  *
  * @author Andrew C. Oliver (acoliver at apache dot org)
- * @authro Carey Sublette  (careysub@earthling.net)
+ * @author Carey Sublette  (careysub@earthling.net)
  */
 
 public class HSSFEventFactory
@@ -103,7 +103,7 @@ public class HSSFEventFactory
 
         processEvents(req, in);
     }
-    
+
     /**
         * Processes a file into essentially record events.
         *
@@ -111,7 +111,7 @@ public class HSSFEventFactory
         * @param fs        a POIFS filesystem containing your workbook
         * @return                      numeric user-specified result code.
         */
-       
+
        public short abortableProcessWorkbookEvents(HSSFRequest req, POIFSFileSystem fs)
                throws IOException, HSSFUserException
        {
@@ -121,9 +121,9 @@ public class HSSFEventFactory
 
     /**
      * Processes a DocumentInputStream into essentially Record events.
-     * 
+     *
      * If an <code>AbortableHSSFListener</code> causes a halt to processing during this call
-     * the method will return just as with <code>abortableProcessEvents</code>, but no 
+     * the method will return just as with <code>abortableProcessEvents</code>, but no
      * user code or <code>HSSFUserException</code> will be passed back.
      *
      * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String)
@@ -133,15 +133,15 @@ public class HSSFEventFactory
 
     public void processEvents(HSSFRequest req, InputStream in)
         throws IOException
-       { 
+       {
                try
                {
                        genericProcessEvents(req, in);
                }
-               catch (HSSFUserException hue) 
+               catch (HSSFUserException hue)
                {/*If an HSSFUserException user exception is thrown, ignore it.*/ }
        }
-    
+
 
     /**
      * Processes a DocumentInputStream into essentially Record events.
@@ -153,11 +153,11 @@ public class HSSFEventFactory
      */
 
     public short abortableProcessEvents(HSSFRequest req, InputStream in)
-        throws IOException, HSSFUserException 
+        throws IOException, HSSFUserException
     {
                return genericProcessEvents(req, in);
-    } 
-    
+    }
+
      /**
         * Processes a DocumentInputStream into essentially Record events.
         *
index 9b88a67f98c201c4cf36e5b65b68fe8fa2e747cb..0fc37939a8299063fdeab0a61bbc1b40c5a2d9e9 100644 (file)
@@ -59,12 +59,10 @@ import java.util.List;
 import java.util.ArrayList;
 import java.util.Iterator;
 
-import org.apache.poi.util.POILogFactory;
 import org.apache.poi.hssf
     .record.*;       // normally I don't do this, buy we literally mean ALL
 import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.util.IntList;
-import org.apache.poi.util.POILogger;
+import org.apache.poi.util.*;
 import org.apache.poi.hssf.record
     .aggregates.*;   // normally I don't do this, buy we literally mean ALL
 
@@ -91,35 +89,33 @@ import org.apache.poi.hssf.record
 public class Sheet
     extends java.lang.Object
 {
-    public static final short LeftMargin = 0;
-    public static final short RightMargin = 1;
-    public static final short TopMargin = 2;
-    public static final short BottomMargin = 3;
-
-    protected ArrayList              records        = null;
-    int                              preoffset      = 0;      // offset of the sheet in a new file
-    int                              loc            = 0;
-    protected boolean                containsLabels = false;
-    ;
-    protected int                    dimsloc        = 0;
-    protected DimensionsRecord       dims;
-    protected DefaultColWidthRecord  defaultcolwidth  = null;
-    protected DefaultRowHeightRecord defaultrowheight = null;
-    protected GridsetRecord          gridset          = null;
-    protected PrintSetupRecord       printSetup       = null;
-    protected HeaderRecord           header           = null;
-    protected FooterRecord           footer           = null;
-    protected PrintGridlinesRecord printGridlines     = null;
-    protected MergeCellsRecord       merged           = null;
-    protected int                    mergedloc        = 0;
-    private static POILogger         log              =
-        POILogFactory.getLogger(Sheet.class);
-    private ArrayList                columnSizes      =
-        null;   // holds column info
-    protected ValueRecordsAggregate  cells            = null;
-    protected RowRecordsAggregate    rows             = null;
-    private Iterator                 valueRecIterator = null;
-    private Iterator                 rowRecIterator   = null;
+    public static final short   LeftMargin = 0;
+    public static final short   RightMargin = 1;
+    public static final short   TopMargin = 2;
+    public static final short   BottomMargin = 3;
+
+    protected ArrayList                 records        = null;
+    int                                 preoffset      = 0;      // offset of the sheet in a new file
+    int                                 loc            = 0;
+    protected boolean                   containsLabels = false;
+    protected int                       dimsloc        = 0;
+    protected DimensionsRecord          dims;
+    protected DefaultColWidthRecord     defaultcolwidth  = null;
+    protected DefaultRowHeightRecord    defaultrowheight = null;
+    protected GridsetRecord             gridset          = null;
+    protected PrintSetupRecord          printSetup       = null;
+    protected HeaderRecord              header           = null;
+    protected FooterRecord              footer           = null;
+    protected PrintGridlinesRecord      printGridlines   = null;
+    protected MergeCellsRecord          merged           = null;
+    protected int                       mergedloc        = 0;
+    private static POILogger            log              = POILogFactory.getLogger(Sheet.class);
+    private ArrayList                   columnSizes      = null;  // holds column info
+    protected ValueRecordsAggregate     cells            = null;
+    protected RowRecordsAggregate       rows             = null;
+    private Iterator                    valueRecIterator = null;
+    private Iterator                    rowRecIterator   = null;
+    protected int                       eofLoc           = 0;
 
     /**
      * Creates new Sheet with no intialization --useless at this point
@@ -164,19 +160,23 @@ public class Sheet
 
             if (rec.getSid() == LabelRecord.sid)
             {
-                log.log(log.DEBUG, "Hit label record");
+                log.log(log.DEBUG, "Hit label record.");
                 retval.containsLabels = true;
             }
             else if (rec.getSid() == BOFRecord.sid)
             {
                 bofEofNestingLevel++;
+                log.log(log.DEBUG, "Hit BOF record. Nesting increased to " + bofEofNestingLevel);
             }
-            else if ((rec.getSid() == EOFRecord.sid)
-                     && (--bofEofNestingLevel == 0))
+            else if (rec.getSid() == EOFRecord.sid)
             {
-                log.log(log.DEBUG, "Hit EOF record at ");
-                records.add(rec);
-                break;
+                --bofEofNestingLevel;
+                log.log(log.DEBUG, "Hit EOF record. Nesting decreased to " + bofEofNestingLevel);
+                if (bofEofNestingLevel == 0) {
+                    records.add(rec);
+                    retval.eofLoc = k;
+                    break;
+                }
             }
             else if (rec.getSid() == DimensionsRecord.sid)
             {
@@ -204,7 +204,7 @@ public class Sheet
             {
                 retval.defaultrowheight = ( DefaultRowHeightRecord ) rec;
             }
-            else if ( rec.isValue() )
+            else if ( rec.isValue() && bofEofNestingLevel == 1 )
             {
                 if ( isfirstcell )
                 {
@@ -218,6 +218,10 @@ public class Sheet
                     rec = null;
                 }
             }
+            else if ( rec.getSid() == StringRecord.sid )
+            {
+                rec = null;
+            }
             else if ( rec.getSid() == RowRecord.sid )
             {
                 if ( isfirstrow )
@@ -255,6 +259,14 @@ public class Sheet
             }
         }
         retval.records = records;
+        if (retval.rows == null)
+        {
+            retval.rows = new RowRecordsAggregate();
+        }
+        if (retval.cells == null)
+        {
+            retval.cells = new ValueRecordsAggregate();
+        }
         log.log(log.DEBUG, "sheet createSheet (existing file) exited");
         return retval;
     }
@@ -421,7 +433,7 @@ public class Sheet
                     newrec.setColumn(oldrec.getColumn());
                     newrec.setXFIndex(oldrec.getXFIndex());
                     newrec.setSSTIndex(stringid);
-                    records.add(k, newrec);
+                          records.add(k, newrec);
                 }
             }
         }
@@ -608,11 +620,19 @@ public class Sheet
         // }
         for (int k = 0; k < records.size(); k++)
         {
-
-            // byte[] rec = (( byte [] ) bytes.get(k));
+//             byte[] rec = (( byte [] ) bytes.get(k));
             // System.arraycopy(rec, 0, data, offset + pos, rec.length);
-            pos += (( Record ) records.get(k)).serialize(pos + offset,
-                    data);   // rec.length;
+            Record record = (( Record ) records.get(k));
+
+            //uncomment to test record sizes
+//            byte[] data2 = new byte[record.getRecordSize()];
+//            record.serialize(0, data2 );   // rec.length;
+//            if (LittleEndian.getUShort(data2, 2) != record.getRecordSize() - 4
+//                    && record instanceof RowRecordsAggregate == false && record instanceof ValueRecordsAggregate == false)
+//                throw new RuntimeException("Blah!!!");
+
+            pos += record.serialize(pos + offset, data );   // rec.length;
+
         }
         log.log(log.DEBUG, "Sheet.serialize returning ");
         return pos;
@@ -2116,4 +2136,10 @@ public class Sheet
        }
        m.setMargin(size);
      }
+
+    public int getEofLoc()
+    {
+        return eofLoc;
+    }
+
 }
index 3ccfbe1277a52ff808af84ed3630f50c57549b53..24ae29b903d548996f3e8c9a48dbed963fe666d5 100644 (file)
@@ -57,8 +57,6 @@ package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.LittleEndian;
 
-import java.util.ArrayList;
-
 /**
  * Title:        DBCell Record (Currently read only.  Not required.)
  * Description:  Used to find rows in blocks...TODO<P>
@@ -130,7 +128,7 @@ public class DBCellRecord
      * sets offset from the start of this DBCellRecord to the start of the first cell in
      * the next DBCell block.
      *
-     * @param rowoffset to the start of the first cell in the next DBCell block
+     * @param offset    offset to the start of the first cell in the next DBCell block
      */
 
     public void setRowOffset(int offset)
index b5ee198f1f7ee200eca956346fef2a607d0efe80..836bd08d9768d1207fa11950bf18355d9dac9d9f 100644 (file)
@@ -370,7 +370,7 @@ public class FormulaRecord
         LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
         LittleEndian.putShort(data, 6 + offset, getColumn());
         LittleEndian.putShort(data, 8 + offset, getXFIndex());
-        LittleEndian.putDouble(data, 10 + offset, getValue());
+        LittleEndian.putDouble(data, 10 + offset, field_4_value);
         LittleEndian.putShort(data, 18 + offset, getOptions());
         LittleEndian.putInt(data, 20 + offset, field_6_zero);
         LittleEndian.putShort(data, 24 + offset, getExpressionLength());
index c949e6fc5dd8bbedd96b7f357cf526c84310a8cf..f30a5afd5a0c233501225c0c480ec9158919a130 100644 (file)
@@ -55,9 +55,7 @@
 
 package org.apache.poi.hssf.record.aggregates;
 
-import org.apache.poi.hssf.record.CellValueRecordInterface;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.UnknownRecord;
+import org.apache.poi.hssf.record.*;
 
 import java.util.Iterator;
 import java.util.List;
@@ -100,7 +98,8 @@ public class ValueRecordsAggregate
         }*/
 
         // XYLocator xy = new XYLocator(cell.getRow(), cell.getColumn());
-        records.put(cell, cell);
+        Object o = records.put(cell, cell);
+
         if ((cell.getColumn() < firstcell) || (firstcell == -1))
         {
             firstcell = cell.getColumn();
@@ -138,15 +137,26 @@ public class ValueRecordsAggregate
     {
         int k = 0;
 
+        FormulaRecordAggregate lastFormulaAggregate = null;
+
         for (k = offset; k < records.size(); k++)
         {
             Record rec = ( Record ) records.get(k);
 
-            if (!rec.isInValueSection() && !(rec instanceof UnknownRecord))
+            if (rec instanceof StringRecord == false && !rec.isInValueSection() && !(rec instanceof UnknownRecord))
             {
                 break;
             }
-            if (rec.isValue())
+            if (rec instanceof FormulaRecord)
+            {
+                lastFormulaAggregate = new FormulaRecordAggregate((FormulaRecord)rec, null);
+                insertCell( lastFormulaAggregate );
+            }
+            else if (rec instanceof StringRecord)
+            {
+                lastFormulaAggregate.setStringRecord((StringRecord)rec);
+            }
+            else if (rec.isValue())
             {
                 insertCell(( CellValueRecordInterface ) rec);
             }
@@ -175,7 +185,6 @@ public class ValueRecordsAggregate
         }
         return pos - offset;
     }
-
     /**
      * called by the constructor, should set class level fields.  Should throw
      * runtime exception for bad/icomplete data.
index 9bebec869d20034660cecfccd0819cffa78e3d38..0781c3caca5a1219e2391b621dc034b1b7cbf562 100644 (file)
@@ -299,14 +299,14 @@ public abstract class Ptg
      */
     public abstract String toFormulaString(SheetReferences refs);
     /**
-     * dump a debug representation (hexdump) to a strnig
+     * dump a debug representation (hexdump) to a string
      */
     public String toDebugString() {
         byte[] ba = new byte[getSize()];
         String retval=null;
         writeBytes(ba,0);        
         try {
-        retval = org.apache.poi.util.HexDump.dump(ba,0,0);       
+            retval = org.apache.poi.util.HexDump.dump(ba,0,0);
         } catch (Exception e) {
             e.printStackTrace();
         }
index 6ba0c63f755d9dbd975563556823eecd3fae26c9..27d9d681e3cf8d2228a22cab8d09ceaf23e3aad6 100644 (file)
@@ -71,6 +71,7 @@ import org.apache.poi.hssf.record.NumberRecord;
 import org.apache.poi.hssf.record.BlankRecord;
 import org.apache.poi.hssf.record.BoolErrRecord;
 import org.apache.poi.hssf.record.ExtendedFormatRecord;
+import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.util.SheetReferences;
 
@@ -259,10 +260,11 @@ public class HSSFCell
                 break;
 
             case CELL_TYPE_FORMULA :
-                record = new FormulaRecord();
-                (( FormulaRecord ) record).setColumn(col);
-                (( FormulaRecord ) record).setRow(row);
-                (( FormulaRecord ) record).setXFIndex(( short ) 0);
+                FormulaRecord formulaRecord = new FormulaRecord();
+                record = new FormulaRecordAggregate(formulaRecord,null);
+                formulaRecord.setColumn(col);
+                formulaRecord.setRow(row);
+                formulaRecord.setXFIndex(( short ) 0);
             case CELL_TYPE_BOOLEAN :
                 record = new BoolErrRecord();
                 (( BoolErrRecord ) record).setColumn(col);
@@ -314,15 +316,14 @@ public class HSSFCell
 
             case CELL_TYPE_STRING :
                 stringValue =
-                    book
-                    .getSSTString((( LabelSSTRecord ) cval).getSSTIndex());
+                    book.getSSTString( ( (LabelSSTRecord ) cval).getSSTIndex());
                 break;
 
             case CELL_TYPE_BLANK :
                 break;
 
             case CELL_TYPE_FORMULA :
-                cellValue = (( FormulaRecord ) cval).getValue();
+                cellValue = (( FormulaRecordAggregate ) cval).getFormulaRecord().getValue();
                 break;
 
             case CELL_TYPE_BOOLEAN :
@@ -369,7 +370,7 @@ public class HSSFCell
                 retval = HSSFCell.CELL_TYPE_STRING;
                 break;
 
-            case FormulaRecord.sid :
+            case FormulaRecordAggregate.sid :
                 retval = HSSFCell.CELL_TYPE_FORMULA;
                 break;
 
@@ -446,20 +447,20 @@ public class HSSFCell
         {
 
             case CELL_TYPE_FORMULA :
-                FormulaRecord frec = null;
+                FormulaRecordAggregate frec = null;
 
                 if (cellType != this.cellType)
                 {
-                    frec = new FormulaRecord();
+                    frec = new FormulaRecordAggregate(new FormulaRecord(),null);
                 }
                 else
                 {
-                    frec = ( FormulaRecord ) record;
+                    frec = ( FormulaRecordAggregate ) record;
                 }
                 frec.setColumn(getCellNum());
                 if (setValue)
                 {
-                    frec.setValue(getNumericCellValue());
+                    frec.getFormulaRecord().setValue(getNumericCellValue());
                 }
                 frec.setXFIndex(( short ) cellStyle.getIndex());
                 frec.setRow(row);
@@ -676,8 +677,7 @@ public class HSSFCell
         }
         else
         {
-            if ((cellType != CELL_TYPE_STRING)
-                    && (cellType != CELL_TYPE_FORMULA))
+            if ((cellType != CELL_TYPE_STRING ) && ( cellType != CELL_TYPE_FORMULA))
             {
                 setCellType(CELL_TYPE_STRING, false);
             }
@@ -702,9 +702,9 @@ public class HSSFCell
             setCellType(CELL_TYPE_BLANK,false);
         } else {
             setCellType(CELL_TYPE_FORMULA,false);
-            FormulaRecord rec = (FormulaRecord) record;
-            rec.setOptions(( short ) 2);
-            rec.setValue(0);
+            FormulaRecordAggregate rec = (FormulaRecordAggregate) record;
+            rec.getFormulaRecord().setOptions(( short ) 2);
+            rec.getFormulaRecord().setValue(0);
             rec.setXFIndex(( short ) 0x0f);
             FormulaParser fp = new FormulaParser(formula+";",book);
             fp.parse();
@@ -713,9 +713,9 @@ public class HSSFCell
             //System.out.println("got Ptgs " + ptg.length);
             for (int k = 0; k < ptg.length; k++) {
                 size += ptg[ k ].getSize();
-                rec.pushExpressionToken(ptg[ k ]);
+                rec.getFormulaRecord().pushExpressionToken(ptg[ k ]);
             }
-            rec.setExpressionLength(( short ) size);
+            rec.getFormulaRecord().setExpressionLength(( short ) size);
             //Workbook.currentBook = null;
         }
     }
@@ -723,7 +723,7 @@ public class HSSFCell
     public String getCellFormula() {
         //Workbook.currentBook=book;
         SheetReferences refs = book.getSheetReferences();
-        String retval = FormulaParser.toFormulaString(refs, ((FormulaRecord)record).getParsedExpression());
+        String retval = FormulaParser.toFormulaString(refs, ((FormulaRecordAggregate)record).getFormulaRecord().getParsedExpression());
         //Workbook.currentBook=null;
         return retval;   
     }
@@ -825,8 +825,7 @@ public class HSSFCell
 
     public void setCellValue(boolean value)
     {
-        if ((cellType != CELL_TYPE_BOOLEAN)
-                && (cellType != CELL_TYPE_FORMULA))
+        if ((cellType != CELL_TYPE_BOOLEAN ) && ( cellType != CELL_TYPE_FORMULA))
         {
             setCellType(CELL_TYPE_BOOLEAN, false);
         }
index 3c9df3c27cc9a40cb973226bd8c55043ac69f42a..89d4b1b18e28b303914cfc97a733063749123404 100644 (file)
@@ -152,14 +152,14 @@ public class HSSFWorkbook
 
         workbook = Workbook.createWorkbook(records);
         setPropertiesFromWorkbook(workbook);
-        int numRecords = workbook.getNumRecords();
+        int recOffset = workbook.getNumRecords();
         int sheetNum = 0;
 
-        while (numRecords < records.size())
+        while (recOffset < records.size())
         {
-            Sheet sheet = Sheet.createSheet(records, sheetNum++, numRecords);
+            Sheet sheet = Sheet.createSheet(records, sheetNum++, recOffset );
 
-            numRecords += sheet.getNumRecords();
+            recOffset = sheet.getEofLoc()+1;
             sheet.convertLabelRecords(
                     workbook);   // convert all LabelRecord records to LabelSSTRecord
             HSSFSheet hsheet = new HSSFSheet(workbook, sheet);
@@ -511,8 +511,8 @@ public class HSSFWorkbook
         {
             totalsize = 4096;
         }
-        byte[] retval = new byte[totalsize];
-        int pos = workbook.serialize(0, retval);
+        byte[] data = new byte[totalsize];
+        int pos = workbook.serialize(0, data);
 
         // System.arraycopy(wb, 0, retval, 0, wb.length);
         for (int k = 0; k < sheets.size(); k++)
@@ -521,13 +521,13 @@ public class HSSFWorkbook
             // byte[] sb = (byte[])sheetbytes.get(k);
             // System.arraycopy(sb, 0, retval, pos, sb.length);
             pos += ((HSSFSheet) sheets.get(k)).getSheet().serialize(pos,
-                    retval);   // sb.length;
+                    data);   // sb.length;
         }
         for (int k = pos; k < totalsize; k++)
         {
-            retval[k] = 0;
+            data[k] = 0;
         }
-        return retval;
+        return data;
     }
 
     public int addSSTString(String string)
index 95752e56a744512b1c2425c4bc0fde1883ed02f0..935fd5a6682960c9d4cfc15cf1363f8a2cb14bb6 100644 (file)
@@ -386,7 +386,7 @@ public class LittleEndian
 
     public static void putDouble(final byte[] data, final int offset,
             final double value) {
-        putNumber(data, offset, Double.doubleToLongBits(value), DOUBLE_SIZE);
+        putNumber(data, offset, Double.doubleToRawLongBits(value), DOUBLE_SIZE);
     }
 
 
index a42686cea932045f6771abde68dfa76bf5f246ef..56d830cc0e873dde58dbf7f2af370d4b65bd1d73 100644 (file)
@@ -147,9 +147,13 @@ public class TestLittleEndian
     {
         56, 50, -113, -4, -63, -64, -13, 63, 76, -32, -42, -35, 60, -43, 3, 64
     };
+    private static final byte[]   _nan_double_array =
+    {
+        (byte)0x00, (byte)0x00, (byte)0x3C, (byte)0x00, (byte)0x20, (byte)0x04, (byte)0xFF, (byte)0xFF
+    };
     private static final double[] _doubles      =
     {
-        1.23456, 2.47912
+        1.23456, 2.47912, Double.NaN
     };
 
     /**
@@ -158,10 +162,21 @@ public class TestLittleEndian
 
     public void testGetDouble()
     {
-        assertEquals(_doubles[ 0 ], LittleEndian.getDouble(_double_array),
-                     0.000001);
-        assertEquals(_doubles[ 1 ], LittleEndian
-            .getDouble(_double_array, LittleEndian.DOUBLE_SIZE), 0.000001);
+        assertEquals(_doubles[ 0 ], LittleEndian.getDouble(_double_array), 0.000001 );
+        assertEquals(_doubles[ 1 ], LittleEndian.getDouble( _double_array, LittleEndian.DOUBLE_SIZE), 0.000001);
+        assertTrue(Double.isNaN(LittleEndian.getDouble(_nan_double_array)));
+
+        // does not work.  apparently nan does not always equal nan!
+        //assertEquals(_doubles[ 2 ], LittleEndian.getDouble(_nan_double_array), 0.000001);
+
+        double nan = LittleEndian.getDouble(_nan_double_array);
+        byte[] data = new byte[8];
+        LittleEndian.putDouble(data, nan);
+        for ( int i = 0; i < data.length; i++ )
+        {
+            byte b = data[i];
+            assertEquals(data[i], _nan_double_array[i]);
+        }
     }
 
     /**