Its the code for testing FontTable class . I am just sending it here with.
The Doc file is read from the setUp() method of HWPFDocFixture class.

/*
 *  ====================================================================
 *  The Apache Software License, Version 1.1
 *
 *  Copyright (c) 2003 The Apache Software Foundation.  All rights
 *  reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *  1. Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 *  2. Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in
 *  the documentation and/or other materials provided with the
 *  distribution.
 *
 *  3. The end-user documentation included with the redistribution,
 *  if any, must include the following acknowledgment:
 *  "This product includes software developed by the
 *  Apache Software Foundation (http://www.apache.org/)."
 *  Alternately, this acknowledgment may appear in the software itself,
 *  if and wherever such third-party acknowledgments normally appear.
 *
 *  4. The names "Apache" and "Apache Software Foundation" and
 *  "Apache POI" must not be used to endorse or promote products
 *  derived from this software without prior written permission. For
 *  written permission, please contact [EMAIL PROTECTED]
 *
 *  5. Products derived from this software may not be called "Apache",
 *  "Apache POI", nor may "Apache" appear in their name, without
 *  prior written permission of the Apache Software Foundation.
 *
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 *  SUCH DAMAGE.
 *  ====================================================================
 *
 *  This software consists of voluntary contributions made by many
 *  individuals on behalf of the Apache Software Foundation.  For more
 *  information on the Apache Software Foundation, please see
 *  <http://www.apache.org/>.
 */
package org.apache.poi.hwpf;

import java.io.InputStream;
//import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.util.HexDump;
//import junit.framework.*;


import org.apache.poi.hwpf.model.hdftypes.*;


/**
 * @author Ryan Ackley
 */
public class HWPFDocument
{
  /** OLE stuff*/
  private POIFSFileSystem _filesystem; 

  /** The FIB*/
  private FileInformationBlock _fib;

  /** main document stream buffer*/
  byte[] _mainStream;

  /** table stream buffer*/
  byte[] _tableStream;

  public HWPFDocument(InputStream istream) throws IOException
  {
    //do Ole stuff
        int inset = 512;
    _filesystem = new POIFSFileSystem(istream); 

    // read in the main stream.
    DocumentEntry documentProps =
       (DocumentEntry)_filesystem.getRoot().getEntry("WordDocument");
    _mainStream = new byte[documentProps.getSize()];
    _filesystem.createDocumentInputStream("WordDocument").read(_mainStream);

    // use the fib to determine the name of the table stream.
    _fib = new FileInformationBlock(_mainStream);

    String name = "0Table";
    if (_fib.isFWhichTblStm())
    {
      name = "1Table";
    }

    // read in the table stream.
    DocumentEntry tableProps =
      (DocumentEntry)_filesystem.getRoot().getEntry(name);
    _tableStream = new byte[tableProps.getSize()];
    _filesystem.createDocumentInputStream(name).read(_tableStream);

    // get the start of text in the main stream
    int fcMin = _fib.getFcMin();
 
    System.out.println(" MainStream Length : " + HexDump.toHex(inset + 
(int)_mainStream.length) + "     " + _mainStream.length );
        System.out.println(_fib.printOffsetFileds(_mainStream));
        System.out.println(_fib);

    DocumentProperties dop = new DocumentProperties(_tableStream, _fib.getFcDop());
    ComplexFileTable cft = new ComplexFileTable(_mainStream, _tableStream, 
_fib.getFcClx(), fcMin);
    CHPBinTable cbt = new CHPBinTable(_mainStream, _tableStream, 
_fib.getFcPlcfbteChpx(), 
_fib.getLcbPlcfbteChpx(), fcMin);
    PAPBinTable pbt = new PAPBinTable(_mainStream, _tableStream, 
_fib.getFcPlcfbtePapx(), 
_fib.getLcbPlcfbtePapx(), fcMin);
    SectionTable st = new SectionTable(_mainStream, _tableStream, _fib.getFcPlcfsed(), 
_fib.getLcbPlcfsed(), fcMin);
    StyleSheet ss = new StyleSheet(_tableStream, _fib.getFcStshf());

    int x = 0;

  }

  public static void main(String[] args)
  {
 
    try
    {
      //HWPFDocument doc = new HWPFDocument(new FileInputStream(args[0]));
      System.out.println("Hai");
          TestFontTable tf = new TestFontTable("TestFontTable");
          tf.setUp();
          tf.testReadWrite();
          System.out.println("End");

    }
    catch (Throwable t)
    {
      t.printStackTrace();
    }
 
 
  }
}

The error I got is as follows....

java.io.IOException: Invalid header signature; read 25294191745023, 
expected -2226271756974174256
        at 
org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:124)
        at 
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:120)
        at 
org.apache.poi.hwpf.HWPFDocFixture.setUp(HWPFDocFixture.java:26)
        at 
org.apache.poi.hwpf.model.hdftypes.TestFontTable.setUp(TestFontTable.java:62)
        at org.apache.poi.hwpf.HWPFDocument.main(HWPFDocument.java:140)
java.lang.NullPointerException
        at 
org.apache.poi.hwpf.model.hdftypes.TestFontTable.testReadWrite(TestFontTable.java:27)
        at org.apache.poi.hwpf.HWPFDocument.main(HWPFDocument.java:141)



Thanks & Regards
Praveen






"Ryan Ackley" <[EMAIL PROTECTED]>
14/07/2003 17:17
Please respond to "POI Developers List"

 
        To:     "POI Developers List" <[EMAIL PROTECTED]>
        cc: 
        Subject:        Re: success!!

 

Praveen my friend, I would have to look at the code but it sounds like 
your
document is not an OLE file.

Ryan

----- Original Message ----- 
From: "Praveen Mathew" <[EMAIL PROTECTED]>
To: "POI Developers List" <[EMAIL PROTECTED]>
Sent: Monday, July 14, 2003 12:42 AM
Subject: Re: success!!


> Congrats Ryan! This is indeed a great acheivement towards our goal of
> making HWPF out of scratchpad,& also for my Word Converter. It sounds 
good
> that it has opened both in Word & WordPerfect.
> Once you commit , I will check out with WordPro & StarOffice.
>
> When I had tried opening a Doc file created with WordPro using our HWPF,
> it gave the following error
> Invalid header signature; read 25294191745023, expected
> -2226271756974174256.. why is this so?
>
>
> Thanks & Regards
> Praveen
>
>
>
>
>
>
> "Ryan Ackley" <[EMAIL PROTECTED]>
> 14/07/2003 07:08
> Please respond to "POI Developers List"
>
>
>         To:     "POI Developers List" <[EMAIL PROTECTED]>
>         cc:
>         Subject:        success!!
>
>
>
> I have successfully loaded a Word document into memory and written it 
back
> out! The document only contained text with different formatting and
> paragraph properties. It may not be such a big deal to anyone but me and
> Praveen because Praveen and I have been working towards this goal for ~2
> months. It will open in Word and WordPerfect. I will be committing
> tomorrow
> night. I am too tired to do it tonight. There is a lot of commenting to
> do...
>
> Ryan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to