Package org.apache.poi.poifs.filesystem

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


   }
  
   public static void main(String[] args) throws Exception {
      for(String filename : args) {
         OutlookTextExtactor extractor = new OutlookTextExtactor(
               new NPOIFSFileSystem(new File(filename))
         );
         System.out.println( extractor.getText() );
      }
   }
View Full Code Here


        // Force the document stream to a (possibly temporary) file
        // so we don't modify the current position of the stream
        FileChannel channel = stream.getFileChannel();

        try {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(channel);

            // Optimize a possible later parsing process by keeping
            // a reference to the already opened POI file system
            stream.setOpenContainer(fs);

            return getTopLevelNames(fs.getRoot());
        } catch (IOException e) {
            // Parse error in POI, so we don't know the file type
            return Collections.emptySet();
        } catch (RuntimeException e) {
            // Another problem in POI
View Full Code Here

        xhtml.startDocument();

        final DirectoryNode root;
        TikaInputStream tstream = TikaInputStream.cast(stream);
        if (tstream == null) {
            root = new NPOIFSFileSystem(new CloseShieldInputStream(stream)).getRoot();
        } else {
            final Object container = tstream.getOpenContainer();
            if (container instanceof NPOIFSFileSystem) {
                root = ((NPOIFSFileSystem) container).getRoot();
            } else if (container instanceof DirectoryNode) {
                root = (DirectoryNode) container;
            } else if (tstream.hasFile()) {
                root = new NPOIFSFileSystem(tstream.getFileChannel()).getRoot();
            } else {
                root = new NPOIFSFileSystem(new CloseShieldInputStream(tstream)).getRoot();
            }
        }
        parse(root, context, metadata, xhtml);
        xhtml.endDocument();
    }
View Full Code Here

     */
    public void testDifferentPOIFS() throws Exception {
       // Open the two filesystems
       DirectoryNode[] files = new DirectoryNode[2];
       files[0] = (new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"))).getRoot();
       files[1] = (new NPOIFSFileSystem(slTests.getFile("basic_test_ppt_file.ppt"))).getRoot();
      
       // Open directly
       for(DirectoryNode dir : files) {
          PowerPointExtractor extractor = new PowerPointExtractor(dir, null);
          assertEquals(expectText, extractor.getText());
View Full Code Here

    public void test51461() throws Exception {
       byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51461.xls");
      
       HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem(
             new ByteArrayInputStream(data)).getRoot(), false);
       HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem(
             new ByteArrayInputStream(data)).getRoot(), false);
      
       assertEquals(2, wbPOIFS.getNumberOfSheets());
       assertEquals(2, wbNPOIFS.getNumberOfSheets());
    }
View Full Code Here

    public void test51535() throws Exception {
       byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51535.xls");
      
       HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem(
             new ByteArrayInputStream(data)).getRoot(), false);
       HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem(
             new ByteArrayInputStream(data)).getRoot(), false);
      
       for(HSSFWorkbook wb : new HSSFWorkbook[] {wbPOIFS, wbNPOIFS}) {
          assertEquals(3, wb.getNumberOfSheets());
         
View Full Code Here

     */
    public void testDifferentPOIFS() throws Exception {
       // Open the two filesystems
       DirectoryNode[] files = new DirectoryNode[2];
       files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"))).getRoot();
       files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("Simple.xls"))).getRoot();
      
       // Open without preserving nodes
       for(DirectoryNode dir : files) {
          HSSFWorkbook workbook = new HSSFWorkbook(dir, false);
          HSSFSheet sheet = workbook.getSheetAt(0);
View Full Code Here

   
    public void testWordDocEmbeddedInXls() throws IOException {
       // Open the two filesystems
       DirectoryNode[] files = new DirectoryNode[2];
       files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"))).getRoot();
       files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithEmbeddedObjects.xls"))).getRoot();
      
       // Check the embedded parts
       for(DirectoryNode root : files) {
          HSSFWorkbook hw = new HSSFWorkbook(root, true);
          List<HSSFObjectData> objects = hw.getAllEmbeddedObjects();
View Full Code Here

     *  again (via POIFS) and have it be valid
     * @throws IOException
     */
    public void testWriteWorkbookFromNPOIFS() throws IOException {
       InputStream is = HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls");
       NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
      
       // Start as NPOIFS
       HSSFWorkbook wb = new HSSFWorkbook(fs.getRoot(), true);
       assertEquals(3, wb.getNumberOfSheets());
       assertEquals("Root xls", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
      
       // Will switch to POIFS
       wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
View Full Code Here

     */
    public void test51671() throws Exception
    {
        InputStream is = POIDataSamples.getDocumentInstance()
                .openResourceAsStream( "empty.doc" );
        NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem( is );
        HWPFDocument hwpfDocument = new HWPFDocument(
                npoifsFileSystem.getRoot() );
        hwpfDocument.write( new ByteArrayOutputStream() );
    }
View Full Code Here

TOP

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

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.