使用文件实例化 NPOIFSFileSystem 对象的问题 [英] Issues instantiating NPOIFSFileSystem Object with File

查看:43
本文介绍了使用文件实例化 NPOIFSFileSystem 对象的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是在家里问这个问题 =- 远离所有来源;我明天会尝试更新.

First up I am asking this question from home =- away from all the source; I will attempt to update tomorrow.

本质上,我正在像这样实例化 NPOIFSFileSystem:

Essentially I am instantiating NPOIFSFileSystem like so:

NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(this.getLocalFile()));

getLocalFile() 方法将字符串返回到文件路径 - 我知道该文件存在于该位置.但是,安装返回错误:

The getLocalFile() method returns a String to a file path - I know the file exists in that location. However, the instatiation is returning an error:

ArrayIndexOutOfBounds

有没有人对此有任何想法?

Does anyone have any ideas on this at all?

有问题的文件是一个 XLS 文件,它确实包含阿拉伯字符,我想知道这是否会导致问题.

The file in question is an XLS file, it does contain Arabic characters and I wonder if that could cause the problem.

我之前确实使用过POIFSFileSystem,但有问题的XLS文件引起了一些问题,各种论坛建议移至NPOIFSFileSystem

I did previously have this using POIFSFileSystem but the XLS file in question caused some issues and various forums recommended moving to NPOIFSFileSystem

那么,有没有人见过这个?或者任何人都可以给我一些提示/指示吗?

So, has anyone seen this before? Or can anyone offer me some tips/pointers on this please?

如果需要进一步澄清,请询问明天,当我回到工作岗位(并且我们已经修复了我们的互联网连接)时,我会更新这个问题.

If any further clarity is needed just ask and tomorrow, when I'm back at work (and we have fixed our internet connection) I will update this question.

提前致谢内森

编辑 1这是完整的堆栈跟踪:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at org.apache.poi.poifs.filesystem.BlockStore$ChainLoopDetector.claim(BlockStore.java:95)
    at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:212)
    at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:186)
    at org.apache.poi.poifs.property.NPropertyTable.buildProperties(NPropertyTable.java:88)
    at org.apache.poi.poifs.property.NPropertyTable.<init>(NPropertyTable.java:66)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.readCoreContents(NPOIFSFileSystem.java:379)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:202)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:163)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:145)
    at com.turnitin.datamap.parser.standard.XLSParser.defineParsableObject(XLSParser.java:67)
    at com.turnitin.datamap.parser.standard.XLSParser.setUp(XLSParser.java:56)
    at com.turnitin.datamap.parser.standard.XLSParser.<init>(XLSParser.java:46)
    at com.turnitin.datamap.controller.DataMapController.parseData(DataMapController.java:255)
    at com.turnitin.datamap.controller.DataMapController.processControl(DataMapController.java:162)
    at com.turnitin.datamap.controller.DataMapController.processStart(DataMapController.java:130)
    at com.turnitin.datamap.controller.DataMapController.main(DataMapController.java:61)

我正在运行 POI3-8

I am running POI3-8

我将升级到 3.9 并重试并通知您.

I will upgrade to 3.9 and try again and let you know.

再次感谢内森

编辑 2

我已经更新到 3.9,很快就会再次测试 - 只是在测试之前等待其他一些项目完成.我会发回结果.

I have updated to 3.9 and will test again soon - just waiting for some other items to complete prior to testing. I will post back the results.

谢谢内森

编辑 3同样奇怪的问题.这是我现在使用 POI 3.9 的堆栈跟踪:

EDIT 3 Same odd problem. Here is the stack trace now I'm using POI 3.9:

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at org.apache.poi.poifs.filesystem.BlockStore$ChainLoopDetector.claim(BlockStore.java:95)
    at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:212)
    at org.apache.poi.poifs.filesystem.NPOIFSStream$StreamBlockByteBufferIterator.next(NPOIFSStream.java:186)
    at org.apache.poi.poifs.property.NPropertyTable.buildProperties(NPropertyTable.java:88)
    at org.apache.poi.poifs.property.NPropertyTable.<init>(NPropertyTable.java:66)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.readCoreContents(NPOIFSFileSystem.java:379)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:202)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:163)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:145)
    at com.turnitin.datamap.parser.standard.XLSParser.defineParsableObject(XLSParser.java:67)
    at com.turnitin.datamap.parser.standard.XLSParser.setUp(XLSParser.java:56)
    at com.turnitin.datamap.parser.standard.XLSParser.<init>(XLSParser.java:46)
    at com.turnitin.datamap.controller.DataMapController.parseData(DataMapController.java:264)
    at com.turnitin.datamap.controller.DataMapController.processControl(DataMapController.java:162)
    at com.turnitin.datamap.controller.DataMapController.processStart(DataMapController.java:130)
    at com.turnitin.datamap.controller.DataMapController.main(DataMapController.java:61)

谢谢内森

编辑 4我已经从 NPOIFSFileSystem 切换到 POIFSFileSystem:

EDIT 4 I have switched from NPOIFSFileSystem to POIFSFileSystem:

FileInputStream fis = new FileInputStream(this.getFileToParse());
    POIFSFileSystem excelFile = new POIFSFileSystem(fis);
    Workbook wb = WorkbookFactory.create(excelFile);

这给了我以下堆栈跟踪:

This give me the following stack trace:

    java.io.IOException: block[ 1273 ] already removed - does your POIFS have circular or duplicate block references?
    at org.apache.poi.poifs.storage.BlockListImpl.remove(BlockListImpl.java:89)
    at org.apache.poi.poifs.storage.RawDataBlockList.remove(RawDataBlockList.java:34)
    at org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableReader.java:221)
    at org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
    at org.apache.poi.poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:34)
    at org.apache.poi.poifs.property.PropertyTable.<init>(PropertyTable.java:63)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:159)
    at com.turnitin.datamap.parser.standard.XLSParser.defineParsableObject(XLSParser.java:68)
    at com.turnitin.datamap.parser.standard.XLSParser.setUp(XLSParser.java:56)
    at com.turnitin.datamap.parser.standard.XLSParser.<init>(XLSParser.java:46)
    at com.turnitin.datamap.controller.DataMapController.parseData(DataMapController.java:264)
    at com.turnitin.datamap.controller.DataMapController.processControl(DataMapController.java:162)
    at com.turnitin.datamap.controller.DataMapController.processStart(DataMapController.java:130)
    at com.turnitin.datamap.controller.DataMapController.main(DataMapController.java:61)

我知道该文件存在并且是有效的 XLS 文件.

I know the file exists and is a valid XLS file.

我使用的是 Java 1.7 和 Poi 3.9.

I am using Java 1.7 and Poi 3.9.

应用程序从/usr/java/data_map_tool 运行,文件从/home/javaapp/data_map_files 下载和处理

The application is running from /usr/java/data_map_tool and the files are downloaded to and processed from /home/javaapp/data_map_files

应用程序在 javaapp 用户下运行,该用户是相关目录的所有者.

The application runs under the javaapp user who is the owner of the directories in question.

有一次,我将文件下载到运行应用程序的目录中的一个目录中,并且可以正常工作 - 但是,文件大小禁止将其用作文件存储.

At one point I had the files downloaded to a directory within the directory the application is running under and that worked - however, the file size prohibits on going use of that as a the file store.

有没有人对此有任何想法,因为我正用这个头撞墙.

Does anyone have any ideas on this as I am banging my head against the wall with this.

推荐答案

好吧,我已经破解了!正如所建议的,问题出在原始源文件上.长话短说,它是 BOM.XSL 文件的开头有一个字节顺序标记.当我的 Java 应用程序使用 FileInputStream 打开它时,它会导致混乱.

Well, I've cracked it! As suggested the issue was with the original source file. To cut a long story short it was BOM. There was a Byte Order Marker at the start of the XSL file. When my Java application opens this with a FileInputStream it causes chaos.

所以,我只是更新了我的代码来打开文件

So, I just updated my code to open the file with

BOMInputStream();

来自 Apache commons io.

from Apache commons io.

这已经解决了这个问题.

This has resolved the issue.

非常感谢内森

这篇关于使用文件实例化 NPOIFSFileSystem 对象的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆