private static string FormatDoubleAsHex(double d)
        {
            long          l  = BitConverter.DoubleToInt64Bits(d);
            StringBuilder sb = new StringBuilder(20);

            sb.Append(HexDump.LongToHex(l)).Append('L');
            return(sb.ToString());
        }
Beispiel #2
0
        /**
         * Just so there is no ambiguity.  The two double values have to be exactly equal
         */
        private static void assertDouble(double a, double b)
        {
            long bitsA = BitConverter.DoubleToInt64Bits(a);
            long bitsB = BitConverter.DoubleToInt64Bits(b);

            if (bitsA != bitsB)
            {
                throw new ComparisonFailure("value different to expected",
                                            new String(HexDump.LongToHex(bitsA)), new String(HexDump.LongToHex(bitsB)));
            }
        }
Beispiel #3
0
        public string FormatAsString()
        {
            StringBuilder sb = new StringBuilder(36);

            int PREFIX_LEN = "0x".Length;

            sb.Append(HexDump.IntToHex(_d1), PREFIX_LEN, 8);
            sb.Append("-");
            sb.Append(HexDump.ShortToHex(_d2), PREFIX_LEN, 4);
            sb.Append("-");
            sb.Append(HexDump.ShortToHex(_d3), PREFIX_LEN, 4);
            sb.Append("-");
            char[] d4Chars = HexDump.LongToHex(D4);
            sb.Append(d4Chars, PREFIX_LEN, 4);
            sb.Append("-");
            sb.Append(d4Chars, PREFIX_LEN + 4, 12);
            return(sb.ToString());
        }
Beispiel #4
0
 private static String LongToHex(long value)
 {
     return(new String(HexDump.LongToHex(value)));
 }
 public void ConfirmLong(long expVal)
 {
     cmp(HexDump.LongToHex(expVal), HexDump.LongToHex(_bds.ReadLong()));
 }
Beispiel #6
0
        public void PrivateHeaderBlock(byte[] data)
        {
            _data = data;

            long signature = LittleEndian.GetLong(_data, _signature_offset);

            if (signature != _signature)
            {
                if (cmp(POIFSConstants.OOXML_FILE_HEADER, data))
                {
                    throw new OfficeXmlFileException("The supplied data appears to be in the Office 2007+ XML. "
                                                     + "You are calling the part of POI that deals with OLE2 Office Documents. "
                                                     + "You need to call a different part of POI to process this data (eg XSSF instead of HSSF)");
                }

                if (cmp(POIFSConstants.RAW_XML_FILE_HEADER, data))
                {
                    throw new NotOLE2FileException("The supplied data appears to be a raw XML file. "
                                                   + "Formats such as Office 2003 XML are not supported");
                }

                // BIFF2 raw stream
                if (cmp(MAGIC_BIFF2, data))
                {
                    throw new OldExcelFormatException("The supplied data appears to be in BIFF2 format. "
                                                      + "HSSF only supports the BIFF8 format, try OldExcelExtractor");
                }

                // BIFF3 raw stream
                if (cmp(MAGIC_BIFF3, data))
                {
                    throw new OldExcelFormatException("The supplied data appears to be in BIFF3 format. "
                                                      + "HSSF only supports the BIFF8 format, try OldExcelExtractor");
                }

                // BIFF4 raw stream
                if (cmp(MAGIC_BIFF4a, data) || cmp(MAGIC_BIFF4b, data))
                {
                    throw new OldExcelFormatException("The supplied data appears to be in BIFF4 format. "
                                                      + "HSSF only supports the BIFF8 format, try OldExcelExtractor");
                }


                // Give a generic error if the OLE2 signature isn't found
                throw new NotOLE2FileException("Invalid header signature; read "
                                               + HexDump.LongToHex(signature) + ", expected "
                                               + HexDump.LongToHex(_signature) + " - Your file appears "
                                               + "not to be a valid OLE2 document");
            }

            if (_data[30] == 12)
            {
                bigBlockSize = POIFSConstants.LARGER_BIG_BLOCK_SIZE_DETAILS;
            }
            else if (_data[30] == 9)
            {
                bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
            }
            else
            {
                throw new IOException("Unsupported blocksize  (2^" + _data[30] + "). Expected 2^9 or 2^12.");
            }

            // Setup the fields to read and write the counts and starts
            _bat_count      = new IntegerField(HeaderBlockConstants._bat_count_offset, _data).Value;
            _property_start = new IntegerField(HeaderBlockConstants._property_start_offset, _data).Value;
            _sbat_start     = new IntegerField(HeaderBlockConstants._sbat_start_offset, _data).Value;
            _sbat_count     = new IntegerField(HeaderBlockConstants._sbat_block_count_offset, _data).Value;
            _xbat_start     = new IntegerField(HeaderBlockConstants._xbat_start_offset, _data).Value;
            _xbat_count     = new IntegerField(HeaderBlockConstants._xbat_count_offset, _data).Value;
        }