Package org.apache.poi.poifs.filesystem

Examples of org.apache.poi.poifs.filesystem.POIFSFileSystem


    public static List getTypes(InputStream istream) throws IOException
    {
        List results = new ArrayList(1);

        //do Ole stuff
        POIFSFileSystem filesystem = new POIFSFileSystem(istream);

        DocumentEntry headerProps =
            (DocumentEntry)filesystem.getRoot().getEntry("WordDocument");

        byte[] mainDocument = new byte[headerProps.getSize()];
        filesystem.createDocumentInputStream("WordDocument").read(mainDocument);

        FileInformationBlock fib = new FileInformationBlock(mainDocument);


        results.add(fib);
View Full Code Here


  public WordDocument(InputStream inputStream) throws IOException
  {
        //do Ole stuff
        istream = inputStream;
        filesystem = new POIFSFileSystem(istream);

        //get important stuff from the Header block and parse all the
        //data structures
        readFIB();
View Full Code Here

  }
 
  public void testPOIFS() throws Exception {
    // Excel
    assertTrue(
        ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)))
        instanceof ExcelExtractor
    );
    assertTrue(
        ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls))).getText().length() > 200
    );
   
    // Word
    assertTrue(
        ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc)))
        instanceof WordExtractor
    );
    assertTrue(
        ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc))).getText().length() > 120
    );
   
    // PowerPoint
    assertTrue(
        ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(ppt)))
        instanceof PowerPointExtractor
    );
    assertTrue(
        ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(ppt))).getText().length() > 120
    );
   
    // Visio
    assertTrue(
        ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(vsd)))
        instanceof VisioTextExtractor
    );
    assertTrue(
        ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(vsd))).getText().length() > 50
    );
   
    // Text
    try {
      ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(txt)));
      fail();
    } catch(IOException e) {
      // Good
    }
  }
View Full Code Here

  public void testCreateNative() throws Exception {
    Workbook wb;
   
    // POIFS -> hssf
    wb = WorkbookFactory.create(
        new POIFSFileSystem(new FileInputStream(xls))
    );
    assertNotNull(wb);
    assertTrue(wb instanceof HSSFWorkbook);
   
    // Package -> xssf
View Full Code Here

  public static POITextExtractor createExtractor(File f) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
    InputStream inp = new PushbackInputStream(
      new FileInputStream(f), 8);
   
    if(POIFSFileSystem.hasPOIFSHeader(inp)) {
      return createExtractor(new POIFSFileSystem(inp));
    }
    if(POIXMLDocument.hasOOXMLHeader(inp)) {
      inp.close();
      return createExtractor(OPCPackage.open(f.toString()));
    }
View Full Code Here

    if(! inp.markSupported()) {
      inp = new PushbackInputStream(inp, 8);
    }
   
    if(POIFSFileSystem.hasPOIFSHeader(inp)) {
      return createExtractor(new POIFSFileSystem(inp));
    }
    if(POIXMLDocument.hasOOXMLHeader(inp)) {
      return createExtractor(OPCPackage.open(inp));
    }
    throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
View Full Code Here

   {@link POITextExtractor} for each embeded file.
   */
  public static POITextExtractor[] getEmbededDocsTextExtractors(POIOLE2TextExtractor ext) throws IOException {
    // Find all the embeded directories
    ArrayList dirs = new ArrayList();
    POIFSFileSystem fs = ext.getFileSystem();
    if(fs == null) {
      throw new IllegalStateException("The extractor didn't know which POIFS it came from!");
    }
   
    if(ext instanceof ExcelExtractor) {
      // These are in MBD... under the root
      Iterator it = fs.getRoot().getEntries();
      while(it.hasNext()) {
        Entry entry = (Entry)it.next();
        if(entry.getName().startsWith("MBD")) {
          dirs.add(entry);
        }
      }
    } else if(ext instanceof WordExtractor) {
      // These are in ObjectPool -> _... under the root
      try {
        DirectoryEntry op = (DirectoryEntry)
          fs.getRoot().getEntry("ObjectPool");
        Iterator it = op.getEntries();
        while(it.hasNext()) {
          Entry entry = (Entry)it.next();
          if(entry.getName().startsWith("_")) {
            dirs.add(entry);
View Full Code Here

     * Extracts properties and text from an MS Document input stream
     */
    public void parse(
            InputStream stream, ContentHandler handler, Metadata metadata)
            throws IOException, SAXException, TikaException {
        POIFSFileSystem filesystem = new POIFSFileSystem(stream);

        metadata.set(Metadata.CONTENT_TYPE, getContentType());
        getMetadata(
                filesystem, SummaryInformation.DEFAULT_STREAM_NAME, metadata);
        getMetadata(
View Full Code Here

    public HSSF(String filename)
        throws IOException
    {
        this.filename = filename;
        POIFSFileSystem fs =
            new POIFSFileSystem(new FileInputStream(filename));

        hssfworkbook = new HSSFWorkbook(fs);

        // records = RecordFactory.createRecords(stream);
    }
View Full Code Here

    public HSSF(String infile, String outfile, boolean write)
        throws IOException
    {
        this.filename = filename;
        POIFSFileSystem fs =
            new POIFSFileSystem(new FileInputStream(filename));

        hssfworkbook = new HSSFWorkbook(fs);

        // HSSFWorkbook book = hssfstream.getWorkbook();
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.poifs.filesystem.POIFSFileSystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.