本文整理汇总了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();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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.");
}
}
示例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();
}
}
示例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() );
}
}
示例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 );
}
}
示例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);
}
示例11: detectType
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
public static POIFSDocumentType detectType(NPOIFSFileSystem fs) {
return detectType(fs.getRoot());
}
示例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);
}
}
示例13: OutlookExtractor
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; //导入依赖的package包/类
public OutlookExtractor(NPOIFSFileSystem filesystem, ParseContext context) throws TikaException {
this(filesystem.getRoot(), context);
}
示例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);
}
示例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);
}