当前位置: 首页>>代码示例>>Java>>正文


Java NPOIFSFileSystem类代码示例

本文整理汇总了Java中org.apache.poi.poifs.filesystem.NPOIFSFileSystem的典型用法代码示例。如果您正苦于以下问题:Java NPOIFSFileSystem类的具体用法?Java NPOIFSFileSystem怎么用?Java NPOIFSFileSystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NPOIFSFileSystem类属于org.apache.poi.poifs.filesystem包,在下文中一共展示了NPOIFSFileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
public void execute(String fileName, JOfficeFrame jOfficeFrame) 
    throws FileNotFoundException, IOException {
  
  NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(fileName));

  DirectoryNode directoryNode = fs.getRoot();
  
  String workbookName = HSSFWorkbook.getWorkbookDirEntryName(directoryNode);
  
  HSSFWorkbook workbook = new HSSFWorkbook(directoryNode, true);
  
  workbook.getDocumentSummaryInformation();
  workbook.getSummaryInformation();
  
  InputStream stream = directoryNode
      .createDocumentInputStream(workbookName);

  jOfficeFrame.updateTreeTable(RecordFactory.createRecords(stream));
  
  /**
   * Process Summary Information and Document SummaryInformation
   */
  processDocumentSummaryInformation(workbook.getDocumentSummaryInformation(), jOfficeFrame);
  processSummaryInformation(workbook.getSummaryInformation(), jOfficeFrame);
  fs.close();
}
 
开发者ID:hussainp,项目名称:JOffVis,代码行数:27,代码来源:XLSStrategy.java

示例2: isNewExcelFormat

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
/**
 * Detect the excel format with only peeking at the first 8 bytes of the input stream (leaving the stream untouched).
 *
 * @param inputStream the xls input stream.
 * @return true if the given input stream is a xls new format.
 * @throws IOException if an error occurs.
 */
public static boolean isNewExcelFormat(InputStream inputStream) throws IOException {

    boolean newFormat = false;

    // Ensure that there is at least some data there
    byte[] headers = IOUtils.peekFirst8Bytes(inputStream);

    if (NPOIFSFileSystem.hasPOIFSHeader(headers)) {
        newFormat = false;
    }
    if (POIXMLDocument.hasOOXMLHeader(new ByteArrayInputStream(headers))) {
        newFormat = true;
    }

    return newFormat;

}
 
开发者ID:Talend,项目名称:data-prep,代码行数:25,代码来源:XlsUtils.java

示例3: open

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
private Workbook open(ContentReader reader) throws IOException
{
   // If we can use a FileChannel, do
   if (reader.getMimetype().equals(MimetypeMap.MIMETYPE_EXCEL))
   {
      NPOIFSFileSystem fs = new NPOIFSFileSystem(reader.getFileChannel());
      return WorkbookFactory.create(fs);
   }

   // Otherwise, ContentReader doesn't offer a File
   // So, we have to go via the InputStream
   try
   {
      return WorkbookFactory.create(reader.getContentInputStream());
   }
   catch (InvalidFormatException e)
   {
      throw new IOException("File broken", e);
   }
}
 
开发者ID:Gagravarr,项目名称:AlfrescoSpreadsheetExcerpter,代码行数:21,代码来源:POIExcerpterAndMerger.java

示例4: isContentIdentical

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
private boolean isContentIdentical(NPOIFSFileSystem fs1, NPOIFSFileSystem fs2, Collection<String> excludes) throws IOException
{
    DirectoryEntry de1 = fs1.getRoot();
    DirectoryEntry de2 = fs2.getRoot();

    FilteringDirectoryNode fs1Filtered = new FilteringDirectoryNode(de1, excludes);
    FilteringDirectoryNode fs2Filtered = new FilteringDirectoryNode(de2, excludes);

    boolean retVal = EntryUtils.areDirectoriesIdentical(fs1Filtered, fs2Filtered);
    if(logger.isDebugEnabled())
    {
        logger.debug("returning equal="+ retVal);
    }
    return retVal;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:16,代码来源:CIFSContentComparator.java

示例5: cleanupAndSaveExcel97

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
protected static void cleanupAndSaveExcel97(NPOIFSFileSystem fs, OutputStream outputStream) throws IOException {
    Workbook wb = WorkbookFactory.create(fs);

    if (wb instanceof HSSFWorkbook) {
        HSSFWorkbook hwb = (HSSFWorkbook) wb;
        InternalWorkbook internal = hwb.getInternalWorkbook();
        if (internal != null) {
            LOGGER.trace("# of Records: {}", internal.getNumRecords());
            removeObProjRecord(internal.getRecords());
            LOGGER.trace("# of Records: {}", internal.getNumRecords());
        }
    }

    wb.write(outputStream);
}
 
开发者ID:docbleach,项目名称:DocBleach,代码行数:16,代码来源:ExcelRecordCleaner.java

示例6: signEncryptedPackage

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
private void signEncryptedPackage(InputStream tmpFileInputStream, SignatureConfig sc, String password) throws IOException, InvalidFormatException, FormatNotUnderstoodException, XMLSignatureException, MarshalException {

	NPOIFSFileSystem poifsTemp = new NPOIFSFileSystem(tmpFileInputStream);
	EncryptionInfo info = new EncryptionInfo(poifsTemp);
	Decryptor d = Decryptor.getInstance(info);
	try {
		if (!d.verifyPassword(password)) {
			throw new FormatNotUnderstoodException("Error: Cannot decrypt new Excel file (.xlsx) for signing. Invalid password");
		}
		// signing
		OPCPackage pkg = OPCPackage.open(d.getDataStream(poifsTemp));
		sc.setOpcPackage(pkg);
		SignatureInfo si = new SignatureInfo();
		si.setSignatureConfig(sc);
		si.confirmSignature();
		// encrypt again
		Encryptor enc = info.getEncryptor();
		enc.confirmPassword(password);
		NPOIFSFileSystem poifs = new NPOIFSFileSystem();
		OutputStream os = enc.getDataStream(poifs);
		pkg.save(os);
		pkg.close();
		if (os!=null) {
			os.close();
		}
		poifs.writeFilesystem(this.finalOutputStream);
		if (poifs!=null) {
			poifs.close();
		}
		if (poifsTemp!=null) {
			poifsTemp.close();
		}
	} catch (GeneralSecurityException e) {
		
		LOG.error(e);
		throw new FormatNotUnderstoodException("Error: Cannot decrypt new Excel file (.xlsx)  for signing.");
	}
}
 
开发者ID:ZuInnoTe,项目名称:hadoopoffice,代码行数:39,代码来源:MSExcelOOXMLSignUtil.java

示例7: checkCompoundStorage

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
private static void checkCompoundStorage(OleBlob.CompoundContent cc, 
                                         Attachment attach)
  throws Exception
{
  File tmpData = File.createTempFile("attach_", ".dat");

  try {
    FileOutputStream fout = new FileOutputStream(tmpData);
    fout.write(attach.getFileData());
    fout.close();

    NPOIFSFileSystem attachFs = new NPOIFSFileSystem(tmpData, true);

    for(OleBlob.CompoundContent.Entry e : cc) {
      DocumentEntry attachE = null;
      try {
        attachE = CompoundOleUtil.getDocumentEntry(e.getName(), attachFs.getRoot());
      } catch(FileNotFoundException fnfe) {
        // ignored, the ole data has extra entries
        continue;
      }

      byte[] attachEBytes = toByteArray(new DocumentInputStream(attachE), 
                                        attachE.getSize());
      byte[] entryBytes = toByteArray(e.getStream(), e.length());

      assertTrue(Arrays.equals(attachEBytes, entryBytes));
    }

    ByteUtil.closeQuietly(attachFs);
    
  } finally {
    tmpData.delete();
  }    
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:36,代码来源:OleBlobTest.java

示例8: main

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
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() );
   }
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:9,代码来源:OutlookTextExtactor.java

示例9: PoiWorkbook

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
public PoiWorkbook( String filename, String encoding ) throws KettleException {
  this.filename = filename;
  this.encoding = encoding;
  this.log = KettleLogStore.getLogChannelInterfaceFactory().create( this );
  try {
    FileObject fileObject = KettleVFS.getFileObject( filename );
    if ( fileObject instanceof LocalFile ) {
      // This supposedly shaves off a little bit of memory usage by allowing POI to randomly access data in the file
      //
      String localFilename = KettleVFS.getFilename( fileObject );
      File excelFile = new File( localFilename );
      try {
        npoifs = new NPOIFSFileSystem( excelFile );
        workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( npoifs );
      } catch ( Exception ofe ) {
        try {
          opcpkg = OPCPackage.open( excelFile );
          workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( opcpkg );
        } catch ( Exception ex ) {
          workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( excelFile );
        }
      }
    } else {
      internalIS = KettleVFS.getInputStream( filename );
      workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( internalIS );
    }
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:31,代码来源:PoiWorkbook.java

示例10: SheetParser

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
public SheetParser(InputStream stream, int sheetIndex, int headerRow) throws IOException {
    this(new HSSFWorkbook(new NPOIFSFileSystem(stream).getRoot(), true).getSheetAt(sheetIndex), headerRow);
}
 
开发者ID:jonestimd,项目名称:finances,代码行数:4,代码来源:SheetParser.java

示例11: detectType

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
public static POIFSDocumentType detectType(NPOIFSFileSystem fs) {
  return detectType(fs.getRoot());
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:4,代码来源:OfficeParser.java

示例12: detect

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
public MediaType detect(InputStream input, Metadata metadata)
         throws IOException {
    // Check if we have access to the document
    if (input == null) {
        return MediaType.OCTET_STREAM;
    }

    // If this is a TikaInputStream wrapping an already
    // parsed NPOIFileSystem/DirectoryNode, just get the
    // names from the root:
    TikaInputStream tis = TikaInputStream.cast(input);
    Set<String> names = null;
    if (tis != null) {
        Object container = tis.getOpenContainer();
        if (container instanceof NPOIFSFileSystem) {
            names = getTopLevelNames(((NPOIFSFileSystem) container).getRoot());
        } else if (container instanceof DirectoryNode) {
            names = getTopLevelNames((DirectoryNode) container);
        }
    }

    if (names == null) {
        // Check if the document starts with the OLE header
        input.mark(8);
        try {
            if (input.read() != 0xd0 || input.read() != 0xcf
                || input.read() != 0x11 || input.read() != 0xe0
                || input.read() != 0xa1 || input.read() != 0xb1
                || input.read() != 0x1a || input.read() != 0xe1) {
                return MediaType.OCTET_STREAM;
            }
        } finally {
            input.reset();
        }
    }

    // We can only detect the exact type when given a TikaInputStream
    if (names == null && tis != null) {
        // Look for known top level entry names to detect the document type
        names = getTopLevelNames(tis);
    }
    
    // Detect based on the names (as available)
    if (tis != null && 
        tis.getOpenContainer() != null && 
        tis.getOpenContainer() instanceof NPOIFSFileSystem) {
        return detect(names, ((NPOIFSFileSystem)tis.getOpenContainer()).getRoot());
    } else {
        return detect(names, null);
    }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:52,代码来源:POIFSContainerDetector.java

示例13: OutlookExtractor

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
public OutlookExtractor(NPOIFSFileSystem filesystem, ParseContext context) throws TikaException {
    this(filesystem.getRoot(), context);
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:4,代码来源:OutlookExtractor.java

示例14: parse

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
protected void parse(NPOIFSFileSystem filesystem, XHTMLContentHandler xhtml)
    throws IOException, SAXException, TikaException {
  parse(filesystem.getRoot(), xhtml);
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:5,代码来源:HSLFExtractor.java

示例15: parseWord6

import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
protected void parseWord6(NPOIFSFileSystem filesystem,
    XHTMLContentHandler xhtml) throws IOException, SAXException,
    TikaException {
  parseWord6(filesystem.getRoot(), xhtml);
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:6,代码来源:WordExtractor.java


注:本文中的org.apache.poi.poifs.filesystem.NPOIFSFileSystem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。