You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by individuodk <in...@gmail.com> on 2009/11/18 12:38:42 UTC

exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

hi!!
poi-3.5-FINAL.jar


			if (sourcePath == null){
				inputStream =
getClass().getClassLoader().getResourceAsStream("file.xls");
				workbook = WorkbookFactory.create(inputStream);
			}
			else{
				inputStream = new FileInputStream(sourcePath);
				workbook = WorkbookFactory.create(inputStream);
			}

When i read excel file from FileInputStream to modify it, all works fine.
When i read excel file (SAME excel file) from
getClass().getClassLoader().getResourceAsStream..., all are exceptions like
next:

convertPOIOutputStream|null|Exception||4|5|N| [ java.io.IOException ] block[
63 ] already removed -
does your POIFS have circular or duplicate block
references?java.io.IOException: block[ 63 ] 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:32)
        at
org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableR
eader.java:187)
        at
org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
        at
org.apache.poi.poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:32)
        at
org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:54
1)
        at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)


or

convertPOIOutputStream|null|Exception||4|5|N| [
org.apache.poi.hssf.record.RecordFormatException ] U
nable to construct record
instanceorg.apache.poi.hssf.record.RecordFormatException: Unable to constr
uct record instance
        at
org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.jav
a:64)
        at
org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:263)
        at
org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStre
am.java:270)
        at
org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.j
ava:236)
        at
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:377)
        at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:275)
        at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:200)
        at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:316)
        at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:297)
        at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)


any idea about how to input file to resource? why does it happen ???
thanks!
-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26406348.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by Josh Micich <jo...@gmail.com>.
My suspicion is that exceptions like the ones described probably don't
have anything to do with the type of InputStream you are using.  The
problems are probably due to corrupted file contents that would be
visible using any other InputStream on the same file contents.  If you
*do* have a test case that fails in different ways depending on the
type of InputStream please log a bug and supply the sample code and
workbook file.

The errors described typically denote a corrupted file.  Any random
mutation of the data in a worksheet file which causes POI to throw
these exceptions almost always causes Excel to fail to load the file
cleanly.  Having said that, there probably are a large number of
unusual cases that Excel handles/tolerates but POI does not.  If you
have a file that Excel opens OK but POI does not, you should log a bug
and supply that file.

-josh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by anjsag <an...@ibsplc.com>.
This sounds good .Let me give a try. 
Thanks
Anjsag
-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p29171824.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by MSB <ma...@tiscali.co.uk>.
Thinking about this problem a little further, how about trying to use a
slightly different technique to get at the file?

Rather than use the getResourceAsStream() method directly how about trying
the following;

Firstly, call the getResource() method on the ClassLoader (or even use the
static ClassLoader.getSystemResource() method). This (well, both) will
return a URL object that encapsulates information about - in this case - the
Excel workbook. With this object in hand, you have a number of options. The
most obvious is to call the URL object's openStream() method which should
open a InputStream onto the file which could be wrapped into a
FileInputStream and then passed to the constructor. The other alternative
would be to assemble the complete path to the file by calling the necessary
methods on the URL object again; getFile(), getPath(), etc. This should
allow you to create a String that encapsulates the path to and the name of
the Excel workbook and which you could then use to create an InputStream
connected to the file. Finally, you could always use the String constructed
above to instantaite a URI and then progress as you have done below.

Might be worth looking into just to see if either approach resolves the
problem you are facing; that could allow you to progress the application.

Yours

Mark B


anjsag wrote:
> 
> The excel file is a normal excel created in MS office  2007. The error is
> caused when read using 
> inputStream = ClassPathResource.class.getResourceAsStream(filePath);  In
> this case the file is located in classpath. 
> 
> But if I give an absolute path to the file  and try reading like this,
> java.net.URI uri = new URI(filePath);
> File file = new File(uri);
> inputStream = new FileInputStream(file); In this case I don't get any
> exception.
> 
> The wonderign part is that it works with a tomcat & fails in one jboss
> server. 
> Can I know When is this particular  error supposed to be thrown...
> 
> 
> 
> MSB wrote:
>> 
>> Have you tried to open the file directly - creating a simplt
>> FileInputStream attached directly to the file for example - to see
>> whether POI responds in the same way or if it opens the file? What is the
>> source of the file - was it generated by Excel or some other piece of
>> software?
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p29170106.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by MSB <ma...@tiscali.co.uk>.
Sorry to say this but it does sound like the server may be causing the
problems for you here but that is something that I am completely unable to
comment upon.

My advice would be to open a new thread, describe the problem you are
experiencing, tell people which version of POI you are using, whic operating
system and explain what the architecture of the platform is. Also, tell them
that the process works perfectly well with tomcat but fails with jboss. This
is a lot of extra work for you I accept but this way, the new post will
beter catch peoples attention and that way you stand a better chance of
someone responding who is familiar with both the tomcat or jboss servers or
who may have experienced similar problems with the jboss platform. Now that
I know the problem does not occur with tomcat, I think it is safe to say
that you are looking for problems with jboss and need specific help in that
area.

Yours

Mark B

PS Just as an aside, is there a jboss forum that you could post a back up
question in, something more general and relating to fetching files in this
manner?


anjsag wrote:
> 
> The excel file is a normal excel created in MS office  2007. The error is
> caused when read using 
> inputStream = ClassPathResource.class.getResourceAsStream(filePath);  In
> this case the file is located in classpath. 
> 
> But if I give an absolute path to the file  and try reading like this,
> java.net.URI uri = new URI(filePath);
> File file = new File(uri);
> inputStream = new FileInputStream(file); In this case I don't get any
> exception.
> 
> The wonderign part is that it works with a tomcat & fails in one jboss
> server. 
> Can I know When is this particular  error supposed to be thrown...
> 
> 
> 
> MSB wrote:
>> 
>> Have you tried to open the file directly - creating a simplt
>> FileInputStream attached directly to the file for example - to see
>> whether POI responds in the same way or if it opens the file? What is the
>> source of the file - was it generated by Excel or some other piece of
>> software?
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p29169712.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by anjsag <an...@ibsplc.com>.
The excel file is a normal excel created in MS office  2007. The error is
caused when read using 
inputStream = ClassPathResource.class.getResourceAsStream(filePath);  In
this case the file is located in classpath. 

But if I give an absolute path to the file  and try reading like this,
java.net.URI uri = new URI(filePath);
File file = new File(uri);
inputStream = new FileInputStream(file); In this case I don't get any
exception.

The wonderign part is that it works with a tomcat & fails in one jboss
server. 
Can I know When is this particular  error supposed to be thrown...



MSB wrote:
> 
> Have you tried to open the file directly - creating a simplt
> FileInputStream attached directly to the file for example - to see whether
> POI responds in the same way or if it opens the file? What is the source
> of the file - was it generated by Excel or some other piece of software?
> 

-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p29169246.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by MSB <ma...@tiscali.co.uk>.
Hello,

Not to my knowledge no because the original poster of the question never
submitted a further reply.

Have you tried to open the file directly - creating a simplt FileInputStream
attached directly to the file for example - to see whether POI responds in
the same way or if it opens the file? What is the source of the file - was
it generated by Excel or some other piece of software?

Yours

Mark B


anjsag wrote:
> 
> Well, I am also getting an exception like this with jboss-4.2.2.GA
> ,poi-3.5-beta6  , jdk1.5.0_14
> 
> Where u able to figure out the reason ? Any answer for this solution
> 
> stack trace 
> 
> 10:58:25,544 ERROR [STDERR] Caused by: java.io.IOException: block[ 10 ]
> already
> removed - does your POIFS have circular or duplicate block references?
> 10:58:25,544 ERROR [STDERR]     at
> org.apache.poi.poifs.storage.BlockListImpl.re
> move(BlockListImpl.java:105)
> 10:58:25,544 ERROR [STDERR]     at
> org.apache.poi.poifs.storage.RawDataBlockList
> .remove(RawDataBlockList.java:32)
> 10:58:25,544 ERROR [STDERR]     at
> org.apache.poi.poifs.storage.BlockAllocationT
> ableReader.fetchBlocks(BlockAllocationTableReader.java:198)
> 10:58:25,544 ERROR [STDERR]     at
> org.apache.poi.poifs.storage.BlockListImpl.fe
> tchBlocks(BlockListImpl.java:140)
> 10:58:25,544 ERROR [STDERR]     at
> org.apache.poi.poifs.storage.RawDataBlockList
> .fetchBlocks(RawDataBlockList.java:32)
> 10:58:25,544 ERROR [STDERR]     at
> org.apache.poi.poifs.filesystem.POIFSFileSyst
> em.processProperties(POIFSFileSystem.java:541)
> 10:58:25,544 ERROR [STDERR]     at
> org.apache.poi.poifs.filesystem.POIFSFileSyst
> em.<init>(POIFSFileSystem.java:176)
> 10:58:25,544 ERROR [STDERR]     at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:318)
> 
> Anjsag
> 

-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p29163211.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by anjsag <an...@ibsplc.com>.
Well, I am also getting an exception like this with jboss-4.2.2.GA
,poi-3.5-beta6  , jdk1.5.0_14

Where u able to figure out the reason ? Any answer for this solution

stack trace 

10:58:25,544 ERROR [STDERR] Caused by: java.io.IOException: block[ 10 ]
already
removed - does your POIFS have circular or duplicate block references?
10:58:25,544 ERROR [STDERR]     at
org.apache.poi.poifs.storage.BlockListImpl.re
move(BlockListImpl.java:105)
10:58:25,544 ERROR [STDERR]     at
org.apache.poi.poifs.storage.RawDataBlockList
.remove(RawDataBlockList.java:32)
10:58:25,544 ERROR [STDERR]     at
org.apache.poi.poifs.storage.BlockAllocationT
ableReader.fetchBlocks(BlockAllocationTableReader.java:198)
10:58:25,544 ERROR [STDERR]     at
org.apache.poi.poifs.storage.BlockListImpl.fe
tchBlocks(BlockListImpl.java:140)
10:58:25,544 ERROR [STDERR]     at
org.apache.poi.poifs.storage.RawDataBlockList
.fetchBlocks(RawDataBlockList.java:32)
10:58:25,544 ERROR [STDERR]     at
org.apache.poi.poifs.filesystem.POIFSFileSyst
em.processProperties(POIFSFileSystem.java:541)
10:58:25,544 ERROR [STDERR]     at
org.apache.poi.poifs.filesystem.POIFSFileSyst
em.(POIFSFileSystem.java:176)
10:58:25,544 ERROR [STDERR]     at
org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:318)

Anjsag
-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p29158913.html
Sent from the POI - User mailing list archive at Nabble.com.

Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by MSB <ma...@tiscali.co.uk>.
Well, we know that you are getting a BufferedInputStream from the call to the
getResourceAsStream() method thanks to this in the log;

> log:
> java.io.BufferedInputStream

But, it almost seems as if the file has been truncated in some way so that
data is missing if I am interpreting the stack trace correctly. The only
thing I can now think to do is to identify what is missing somehow and so
would suggest that you write a simple loop to dump the streams returned by
both methods so that you can look to see what is missing. That should also
give you the chance to see if the total numbers of bytes read from both
differ, if so by how much and it may point us in the right direction.

Yours

Mark B


individuodk wrote:
> 
> Hi,
> 
> version poi: 3.5-FINAL
> jdk: 1.5.0_02
> 
> the file is the same file that works with FileInputStream("path");
> Also, it happens with blank excel file.
> 
> thanksss!
> 
> 
> 
> David Fisher wrote:
>> 
>> Hi -
>> 
>> Have you confirmed that the stream you are getting is a valid file?  
>> Could there be another non-xls or damaged file hiding somewhere on  
>> your classpath with your resource name?
>> 
>> Try simply writing out the stream you have to the filesystem and see  
>> if it is an actual XLS file.
>> 
>> Also, it could be helpful if you tell us which versions of POI and  
>> Java you are using.
>> 
>> Regards,
>> Dave
>> 
>> On Nov 18, 2009, at 10:15 AM, individuodk wrote:
>> 
>>>
>>> Hi,
>>>
>>> System.out.println(inputStream.getClass().getName());
>>> is a curiusious solution, but unfortunatelly it doesn´t work.
>>>
>>> log:
>>> java.io.BufferedInputStream
>>> [ java.io.IOException ] block[ 63 ] already removed - does your  
>>> POIFS have
>>> circular or duplicate block references?java.io.IOException:  
>>> block[ 63 ]
>>> 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:32)
>>> 	at
>>> org 
>>> .apache 
>>> .poi 
>>> .poifs 
>>> .storage 
>>> .BlockAllocationTableReader 
>>> .fetchBlocks(BlockAllocationTableReader.java:187)
>>> 	at
>>> org 
>>> .apache 
>>> .poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>>> 	at
>>> org 
>>> .apache 
>>> .poi 
>>> .poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:32)
>>> 	at
>>> org 
>>> .apache 
>>> .poi 
>>> .poifs 
>>> .filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java: 
>>> 541)
>>> 	at
>>> org 
>>> .apache 
>>> .poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)
>>> 	at  
>>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>> 316)
>>> 	at  
>>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>> 297)
>>> 	at
>>> org 
>>> .apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java: 
>>> 60)
>>>
>>> very thanks MSB,
>>> has anybody another idea?
>>>
>>>
>>> MSB wrote:
>>>>
>>>> I do not know the answer to your question but I would like to  
>>>> discover
>>>> just what type of stream you are getting back when you call the
>>>> getResourceAsStream() method. If you have the time, it may be worth  
>>>> adding
>>>> a System.out.println(inputStream.getClass().getName()); statement  
>>>> just to
>>>> see what you are actually getting back; something like;
>>>>
>>>> if (sourcePath == null){
>>>>    inputStream =
>>>> getClass().getClassLoader().getResourceAsStream("file.xls");
>>>>    System.out.println(inputStream.getClass().getName());
>>>>    workbook = WorkbookFactory.create(inputStream);
>>>> }
>>>>
>>>> Also - and I admit that there is no reason why you would need to do  
>>>> this -
>>>> you could try wrapping up that input stream into a FileInputStream  
>>>> just,
>>>> again, to see what happens.
>>>>
>>>> Yours
>>>>
>>>> Mark B
>>>>
>>>>
>>>> individuodk wrote:
>>>>>
>>>>> hi!!
>>>>> poi-3.5-FINAL.jar
>>>>>
>>>>>
>>>>> 			if (sourcePath == null){
>>>>> 				inputStream =
>>>>> getClass().getClassLoader().getResourceAsStream("file.xls");
>>>>> 				workbook = WorkbookFactory.create(inputStream);
>>>>> 			}
>>>>> 			else{
>>>>> 				inputStream = new FileInputStream(sourcePath);
>>>>> 				workbook = WorkbookFactory.create(inputStream);
>>>>> 			}
>>>>>
>>>>> When i read excel file from FileInputStream to modify it, all  
>>>>> works fine.
>>>>> When i read excel file (SAME excel file) from
>>>>> getClass().getClassLoader().getResourceAsStream..., all are  
>>>>> exceptions
>>>>> like next:
>>>>>
>>>>> convertPOIOutputStream|null|Exception||4|5|N|  
>>>>> [ java.io.IOException ]
>>>>> block[ 63 ] already removed -
>>>>> does your POIFS have circular or duplicate block
>>>>> references?java.io.IOException: block[ 63 ] 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:32)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi 
>>>>> .poifs 
>>>>> .storage 
>>>>> .BlockAllocationTableReader.fetchBlocks(BlockAllocationTableR
>>>>> eader.java:187)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi 
>>>>> .poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java: 
>>>>> 32)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi 
>>>>> .poifs 
>>>>> .filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java: 
>>>>> 54
>>>>> 1)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java: 
>>>>> 176)
>>>>>
>>>>>
>>>>> or
>>>>>
>>>>> convertPOIOutputStream|null|Exception||4|5|N| [
>>>>> org.apache.poi.hssf.record.RecordFormatException ] U
>>>>> nable to construct record
>>>>> instanceorg.apache.poi.hssf.record.RecordFormatException: Unable to
>>>>> constr
>>>>> uct record instance
>>>>>        at
>>>>> org.apache.poi.hssf.record.RecordFactory 
>>>>> $ReflectionRecordCreator.create(RecordFactory.jav
>>>>> a:64)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi 
>>>>> .hssf.record.RecordFactory.createSingleRecord(RecordFactory.java: 
>>>>> 263)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi 
>>>>> .hssf 
>>>>> .record 
>>>>> .RecordFactoryInputStream.readNextRecord(RecordFactoryInputStre
>>>>> am.java:270)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi 
>>>>> .hssf 
>>>>> .record 
>>>>> .RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.j
>>>>> ava:236)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:377)
>>>>>        at
>>>>> org 
>>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>>>> 275)
>>>>>        at
>>>>> org 
>>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>>>> 200)
>>>>>        at
>>>>> org 
>>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>>>> 316)
>>>>>        at
>>>>> org 
>>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>>>> 297)
>>>>>        at
>>>>> org 
>>>>> .apache 
>>>>> .poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)
>>>>>
>>>>>
>>>>> any idea about how to input file to resource? why does it happen ???
>>>>> thanks!
>>>>>
>>>>
>>>>
>>>
>>> -- 
>>> View this message in context:
>>> http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26412919.html
>>> Sent from the POI - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26421223.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by David Fisher <df...@jmlafferty.com>.
You might take a look at http://mindprod.com/jgloss/getresourceasstream.html

See if it helps you out.

Also, you might try to update to the latest jdk 1.5.0_xx

Regards,
Dave

On Nov 18, 2009, at 11:10 AM, individuodk wrote:

>
> Hi,
>
> version poi: 3.5-FINAL
> jdk: 1.5.0_02
>
> the file is the same file that works with FileInputStream("path");
> Also, it happens with blank excel file.
>
> thanksss!
>
>
>
> David Fisher wrote:
>>
>> Hi -
>>
>> Have you confirmed that the stream you are getting is a valid file?
>> Could there be another non-xls or damaged file hiding somewhere on
>> your classpath with your resource name?
>>
>> Try simply writing out the stream you have to the filesystem and see
>> if it is an actual XLS file.
>>
>> Also, it could be helpful if you tell us which versions of POI and
>> Java you are using.
>>
>> Regards,
>> Dave
>>
>> On Nov 18, 2009, at 10:15 AM, individuodk wrote:
>>
>>>
>>> Hi,
>>>
>>> System.out.println(inputStream.getClass().getName());
>>> is a curiusious solution, but unfortunatelly it doesn´t work.
>>>
>>> log:
>>> java.io.BufferedInputStream
>>> [ java.io.IOException ] block[ 63 ] already removed - does your
>>> POIFS have
>>> circular or duplicate block references?java.io.IOException:
>>> block[ 63 ]
>>> 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:32)
>>> 	at
>>> org
>>> .apache
>>> .poi
>>> .poifs
>>> .storage
>>> .BlockAllocationTableReader
>>> .fetchBlocks(BlockAllocationTableReader.java:187)
>>> 	at
>>> org
>>> .apache
>>> .poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>>> 	at
>>> org
>>> .apache
>>> .poi
>>> .poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java: 
>>> 32)
>>> 	at
>>> org
>>> .apache
>>> .poi
>>> .poifs
>>> .filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:
>>> 541)
>>> 	at
>>> org
>>> .apache
>>> .poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java: 
>>> 176)
>>> 	at
>>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:
>>> 316)
>>> 	at
>>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:
>>> 297)
>>> 	at
>>> org
>>> .apache 
>>> .poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:
>>> 60)
>>>
>>> very thanks MSB,
>>> has anybody another idea?
>>>
>>>
>>> MSB wrote:
>>>>
>>>> I do not know the answer to your question but I would like to
>>>> discover
>>>> just what type of stream you are getting back when you call the
>>>> getResourceAsStream() method. If you have the time, it may be worth
>>>> adding
>>>> a System.out.println(inputStream.getClass().getName()); statement
>>>> just to
>>>> see what you are actually getting back; something like;
>>>>
>>>> if (sourcePath == null){
>>>>   inputStream =
>>>> getClass().getClassLoader().getResourceAsStream("file.xls");
>>>>   System.out.println(inputStream.getClass().getName());
>>>>   workbook = WorkbookFactory.create(inputStream);
>>>> }
>>>>
>>>> Also - and I admit that there is no reason why you would need to do
>>>> this -
>>>> you could try wrapping up that input stream into a FileInputStream
>>>> just,
>>>> again, to see what happens.
>>>>
>>>> Yours
>>>>
>>>> Mark B
>>>>
>>>>
>>>> individuodk wrote:
>>>>>
>>>>> hi!!
>>>>> poi-3.5-FINAL.jar
>>>>>
>>>>>
>>>>> 			if (sourcePath == null){
>>>>> 				inputStream =
>>>>> getClass().getClassLoader().getResourceAsStream("file.xls");
>>>>> 				workbook = WorkbookFactory.create(inputStream);
>>>>> 			}
>>>>> 			else{
>>>>> 				inputStream = new FileInputStream(sourcePath);
>>>>> 				workbook = WorkbookFactory.create(inputStream);
>>>>> 			}
>>>>>
>>>>> When i read excel file from FileInputStream to modify it, all
>>>>> works fine.
>>>>> When i read excel file (SAME excel file) from
>>>>> getClass().getClassLoader().getResourceAsStream..., all are
>>>>> exceptions
>>>>> like next:
>>>>>
>>>>> convertPOIOutputStream|null|Exception||4|5|N|
>>>>> [ java.io.IOException ]
>>>>> block[ 63 ] already removed -
>>>>> does your POIFS have circular or duplicate block
>>>>> references?java.io.IOException: block[ 63 ] 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: 
>>>>> 32)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi
>>>>> .poifs
>>>>> .storage
>>>>> .BlockAllocationTableReader.fetchBlocks(BlockAllocationTableR
>>>>> eader.java:187)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java: 
>>>>> 123)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi
>>>>> .poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:
>>>>> 32)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi
>>>>> .poifs
>>>>> .filesystem 
>>>>> .POIFSFileSystem.processProperties(POIFSFileSystem.java:
>>>>> 54
>>>>> 1)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:
>>>>> 176)
>>>>>
>>>>>
>>>>> or
>>>>>
>>>>> convertPOIOutputStream|null|Exception||4|5|N| [
>>>>> org.apache.poi.hssf.record.RecordFormatException ] U
>>>>> nable to construct record
>>>>> instanceorg.apache.poi.hssf.record.RecordFormatException: Unable  
>>>>> to
>>>>> constr
>>>>> uct record instance
>>>>>       at
>>>>> org.apache.poi.hssf.record.RecordFactory
>>>>> $ReflectionRecordCreator.create(RecordFactory.jav
>>>>> a:64)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi
>>>>> .hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:
>>>>> 263)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi
>>>>> .hssf
>>>>> .record
>>>>> .RecordFactoryInputStream.readNextRecord(RecordFactoryInputStre
>>>>> am.java:270)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi
>>>>> .hssf
>>>>> .record
>>>>> .RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.j
>>>>> ava:236)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi.hssf.record.RecordFactory.createRecords(RecordFactory.java: 
>>>>> 377)
>>>>>       at
>>>>> org
>>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:
>>>>> 275)
>>>>>       at
>>>>> org
>>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:
>>>>> 200)
>>>>>       at
>>>>> org
>>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:
>>>>> 316)
>>>>>       at
>>>>> org
>>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:
>>>>> 297)
>>>>>       at
>>>>> org
>>>>> .apache
>>>>> .poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)
>>>>>
>>>>>
>>>>> any idea about how to input file to resource? why does it  
>>>>> happen ???
>>>>> thanks!
>>>>>
>>>>
>>>>
>>>
>>> -- 
>>> View this message in context:
>>> http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26412919.html
>>> Sent from the POI - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>>
>
> -- 
> View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26413812.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by individuodk <in...@gmail.com>.
Hi,

version poi: 3.5-FINAL
jdk: 1.5.0_02

the file is the same file that works with FileInputStream("path");
Also, it happens with blank excel file.

thanksss!



David Fisher wrote:
> 
> Hi -
> 
> Have you confirmed that the stream you are getting is a valid file?  
> Could there be another non-xls or damaged file hiding somewhere on  
> your classpath with your resource name?
> 
> Try simply writing out the stream you have to the filesystem and see  
> if it is an actual XLS file.
> 
> Also, it could be helpful if you tell us which versions of POI and  
> Java you are using.
> 
> Regards,
> Dave
> 
> On Nov 18, 2009, at 10:15 AM, individuodk wrote:
> 
>>
>> Hi,
>>
>> System.out.println(inputStream.getClass().getName());
>> is a curiusious solution, but unfortunatelly it doesn´t work.
>>
>> log:
>> java.io.BufferedInputStream
>> [ java.io.IOException ] block[ 63 ] already removed - does your  
>> POIFS have
>> circular or duplicate block references?java.io.IOException:  
>> block[ 63 ]
>> 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:32)
>> 	at
>> org 
>> .apache 
>> .poi 
>> .poifs 
>> .storage 
>> .BlockAllocationTableReader 
>> .fetchBlocks(BlockAllocationTableReader.java:187)
>> 	at
>> org 
>> .apache 
>> .poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>> 	at
>> org 
>> .apache 
>> .poi 
>> .poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:32)
>> 	at
>> org 
>> .apache 
>> .poi 
>> .poifs 
>> .filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java: 
>> 541)
>> 	at
>> org 
>> .apache 
>> .poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)
>> 	at  
>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>> 316)
>> 	at  
>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>> 297)
>> 	at
>> org 
>> .apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java: 
>> 60)
>>
>> very thanks MSB,
>> has anybody another idea?
>>
>>
>> MSB wrote:
>>>
>>> I do not know the answer to your question but I would like to  
>>> discover
>>> just what type of stream you are getting back when you call the
>>> getResourceAsStream() method. If you have the time, it may be worth  
>>> adding
>>> a System.out.println(inputStream.getClass().getName()); statement  
>>> just to
>>> see what you are actually getting back; something like;
>>>
>>> if (sourcePath == null){
>>>    inputStream =
>>> getClass().getClassLoader().getResourceAsStream("file.xls");
>>>    System.out.println(inputStream.getClass().getName());
>>>    workbook = WorkbookFactory.create(inputStream);
>>> }
>>>
>>> Also - and I admit that there is no reason why you would need to do  
>>> this -
>>> you could try wrapping up that input stream into a FileInputStream  
>>> just,
>>> again, to see what happens.
>>>
>>> Yours
>>>
>>> Mark B
>>>
>>>
>>> individuodk wrote:
>>>>
>>>> hi!!
>>>> poi-3.5-FINAL.jar
>>>>
>>>>
>>>> 			if (sourcePath == null){
>>>> 				inputStream =
>>>> getClass().getClassLoader().getResourceAsStream("file.xls");
>>>> 				workbook = WorkbookFactory.create(inputStream);
>>>> 			}
>>>> 			else{
>>>> 				inputStream = new FileInputStream(sourcePath);
>>>> 				workbook = WorkbookFactory.create(inputStream);
>>>> 			}
>>>>
>>>> When i read excel file from FileInputStream to modify it, all  
>>>> works fine.
>>>> When i read excel file (SAME excel file) from
>>>> getClass().getClassLoader().getResourceAsStream..., all are  
>>>> exceptions
>>>> like next:
>>>>
>>>> convertPOIOutputStream|null|Exception||4|5|N|  
>>>> [ java.io.IOException ]
>>>> block[ 63 ] already removed -
>>>> does your POIFS have circular or duplicate block
>>>> references?java.io.IOException: block[ 63 ] 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:32)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi 
>>>> .poifs 
>>>> .storage 
>>>> .BlockAllocationTableReader.fetchBlocks(BlockAllocationTableR
>>>> eader.java:187)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi 
>>>> .poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java: 
>>>> 32)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi 
>>>> .poifs 
>>>> .filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java: 
>>>> 54
>>>> 1)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java: 
>>>> 176)
>>>>
>>>>
>>>> or
>>>>
>>>> convertPOIOutputStream|null|Exception||4|5|N| [
>>>> org.apache.poi.hssf.record.RecordFormatException ] U
>>>> nable to construct record
>>>> instanceorg.apache.poi.hssf.record.RecordFormatException: Unable to
>>>> constr
>>>> uct record instance
>>>>        at
>>>> org.apache.poi.hssf.record.RecordFactory 
>>>> $ReflectionRecordCreator.create(RecordFactory.jav
>>>> a:64)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi 
>>>> .hssf.record.RecordFactory.createSingleRecord(RecordFactory.java: 
>>>> 263)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi 
>>>> .hssf 
>>>> .record 
>>>> .RecordFactoryInputStream.readNextRecord(RecordFactoryInputStre
>>>> am.java:270)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi 
>>>> .hssf 
>>>> .record 
>>>> .RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.j
>>>> ava:236)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:377)
>>>>        at
>>>> org 
>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>>> 275)
>>>>        at
>>>> org 
>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>>> 200)
>>>>        at
>>>> org 
>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>>> 316)
>>>>        at
>>>> org 
>>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>>> 297)
>>>>        at
>>>> org 
>>>> .apache 
>>>> .poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)
>>>>
>>>>
>>>> any idea about how to input file to resource? why does it happen ???
>>>> thanks!
>>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26412919.html
>> Sent from the POI - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26413812.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by David Fisher <df...@jmlafferty.com>.
Hi -

Have you confirmed that the stream you are getting is a valid file?  
Could there be another non-xls or damaged file hiding somewhere on  
your classpath with your resource name?

Try simply writing out the stream you have to the filesystem and see  
if it is an actual XLS file.

Also, it could be helpful if you tell us which versions of POI and  
Java you are using.

Regards,
Dave

On Nov 18, 2009, at 10:15 AM, individuodk wrote:

>
> Hi,
>
> System.out.println(inputStream.getClass().getName());
> is a curiusious solution, but unfortunatelly it doesn´t work.
>
> log:
> java.io.BufferedInputStream
> [ java.io.IOException ] block[ 63 ] already removed - does your  
> POIFS have
> circular or duplicate block references?java.io.IOException:  
> block[ 63 ]
> 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:32)
> 	at
> org 
> .apache 
> .poi 
> .poifs 
> .storage 
> .BlockAllocationTableReader 
> .fetchBlocks(BlockAllocationTableReader.java:187)
> 	at
> org 
> .apache 
> .poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
> 	at
> org 
> .apache 
> .poi 
> .poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:32)
> 	at
> org 
> .apache 
> .poi 
> .poifs 
> .filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java: 
> 541)
> 	at
> org 
> .apache 
> .poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)
> 	at  
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
> 316)
> 	at  
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
> 297)
> 	at
> org 
> .apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java: 
> 60)
>
> very thanks MSB,
> has anybody another idea?
>
>
> MSB wrote:
>>
>> I do not know the answer to your question but I would like to  
>> discover
>> just what type of stream you are getting back when you call the
>> getResourceAsStream() method. If you have the time, it may be worth  
>> adding
>> a System.out.println(inputStream.getClass().getName()); statement  
>> just to
>> see what you are actually getting back; something like;
>>
>> if (sourcePath == null){
>>    inputStream =
>> getClass().getClassLoader().getResourceAsStream("file.xls");
>>    System.out.println(inputStream.getClass().getName());
>>    workbook = WorkbookFactory.create(inputStream);
>> }
>>
>> Also - and I admit that there is no reason why you would need to do  
>> this -
>> you could try wrapping up that input stream into a FileInputStream  
>> just,
>> again, to see what happens.
>>
>> Yours
>>
>> Mark B
>>
>>
>> individuodk wrote:
>>>
>>> hi!!
>>> poi-3.5-FINAL.jar
>>>
>>>
>>> 			if (sourcePath == null){
>>> 				inputStream =
>>> getClass().getClassLoader().getResourceAsStream("file.xls");
>>> 				workbook = WorkbookFactory.create(inputStream);
>>> 			}
>>> 			else{
>>> 				inputStream = new FileInputStream(sourcePath);
>>> 				workbook = WorkbookFactory.create(inputStream);
>>> 			}
>>>
>>> When i read excel file from FileInputStream to modify it, all  
>>> works fine.
>>> When i read excel file (SAME excel file) from
>>> getClass().getClassLoader().getResourceAsStream..., all are  
>>> exceptions
>>> like next:
>>>
>>> convertPOIOutputStream|null|Exception||4|5|N|  
>>> [ java.io.IOException ]
>>> block[ 63 ] already removed -
>>> does your POIFS have circular or duplicate block
>>> references?java.io.IOException: block[ 63 ] 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:32)
>>>        at
>>> org 
>>> .apache 
>>> .poi 
>>> .poifs 
>>> .storage 
>>> .BlockAllocationTableReader.fetchBlocks(BlockAllocationTableR
>>> eader.java:187)
>>>        at
>>> org 
>>> .apache 
>>> .poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>>>        at
>>> org 
>>> .apache 
>>> .poi 
>>> .poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java: 
>>> 32)
>>>        at
>>> org 
>>> .apache 
>>> .poi 
>>> .poifs 
>>> .filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java: 
>>> 54
>>> 1)
>>>        at
>>> org 
>>> .apache 
>>> .poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java: 
>>> 176)
>>>
>>>
>>> or
>>>
>>> convertPOIOutputStream|null|Exception||4|5|N| [
>>> org.apache.poi.hssf.record.RecordFormatException ] U
>>> nable to construct record
>>> instanceorg.apache.poi.hssf.record.RecordFormatException: Unable to
>>> constr
>>> uct record instance
>>>        at
>>> org.apache.poi.hssf.record.RecordFactory 
>>> $ReflectionRecordCreator.create(RecordFactory.jav
>>> a:64)
>>>        at
>>> org 
>>> .apache 
>>> .poi 
>>> .hssf.record.RecordFactory.createSingleRecord(RecordFactory.java: 
>>> 263)
>>>        at
>>> org 
>>> .apache 
>>> .poi 
>>> .hssf 
>>> .record 
>>> .RecordFactoryInputStream.readNextRecord(RecordFactoryInputStre
>>> am.java:270)
>>>        at
>>> org 
>>> .apache 
>>> .poi 
>>> .hssf 
>>> .record 
>>> .RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.j
>>> ava:236)
>>>        at
>>> org 
>>> .apache 
>>> .poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:377)
>>>        at
>>> org 
>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>> 275)
>>>        at
>>> org 
>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>> 200)
>>>        at
>>> org 
>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>> 316)
>>>        at
>>> org 
>>> .apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java: 
>>> 297)
>>>        at
>>> org 
>>> .apache 
>>> .poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)
>>>
>>>
>>> any idea about how to input file to resource? why does it happen ???
>>> thanks!
>>>
>>
>>
>
> -- 
> View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26412919.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by individuodk <in...@gmail.com>.
Hi,

System.out.println(inputStream.getClass().getName());
is a curiusious solution, but unfortunatelly it doesn´t work.

log:
java.io.BufferedInputStream
[ java.io.IOException ] block[ 63 ] already removed - does your POIFS have
circular or duplicate block references?java.io.IOException: block[ 63 ]
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:32)
	at
org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableReader.java:187)
	at
org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
	at
org.apache.poi.poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:32)
	at
org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:541)
	at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:316)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:297)
	at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)

very thanks MSB,
has anybody another idea?


MSB wrote:
> 
> I do not know the answer to your question but I would like to discover
> just what type of stream you are getting back when you call the
> getResourceAsStream() method. If you have the time, it may be worth adding
> a System.out.println(inputStream.getClass().getName()); statement just to
> see what you are actually getting back; something like;
> 
> if (sourcePath == null){
>     inputStream =
> getClass().getClassLoader().getResourceAsStream("file.xls");
>     System.out.println(inputStream.getClass().getName());
>     workbook = WorkbookFactory.create(inputStream);
> }
> 
> Also - and I admit that there is no reason why you would need to do this -
> you could try wrapping up that input stream into a FileInputStream just,
> again, to see what happens.
> 
> Yours
> 
> Mark B
> 
> 
> individuodk wrote:
>> 
>> hi!!
>> poi-3.5-FINAL.jar
>> 
>> 
>> 			if (sourcePath == null){
>> 				inputStream =
>> getClass().getClassLoader().getResourceAsStream("file.xls");
>> 				workbook = WorkbookFactory.create(inputStream);
>> 			}
>> 			else{
>> 				inputStream = new FileInputStream(sourcePath);
>> 				workbook = WorkbookFactory.create(inputStream);
>> 			}
>> 
>> When i read excel file from FileInputStream to modify it, all works fine.
>> When i read excel file (SAME excel file) from
>> getClass().getClassLoader().getResourceAsStream..., all are exceptions
>> like next:
>> 
>> convertPOIOutputStream|null|Exception||4|5|N| [ java.io.IOException ]
>> block[ 63 ] already removed -
>> does your POIFS have circular or duplicate block
>> references?java.io.IOException: block[ 63 ] 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:32)
>>         at
>> org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableR
>> eader.java:187)
>>         at
>> org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>>         at
>> org.apache.poi.poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:32)
>>         at
>> org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:54
>> 1)
>>         at
>> org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)
>> 
>> 
>> or
>> 
>> convertPOIOutputStream|null|Exception||4|5|N| [
>> org.apache.poi.hssf.record.RecordFormatException ] U
>> nable to construct record
>> instanceorg.apache.poi.hssf.record.RecordFormatException: Unable to
>> constr
>> uct record instance
>>         at
>> org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.jav
>> a:64)
>>         at
>> org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:263)
>>         at
>> org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStre
>> am.java:270)
>>         at
>> org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.j
>> ava:236)
>>         at
>> org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:377)
>>         at
>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:275)
>>         at
>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:200)
>>         at
>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:316)
>>         at
>> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:297)
>>         at
>> org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)
>> 
>> 
>> any idea about how to input file to resource? why does it happen ???
>> thanks!
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26412919.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: exception when inputstream is read from getClass().getClassLoader().getResourceAsStream("file.xls")

Posted by MSB <ma...@tiscali.co.uk>.
I do not know the answer to your question but I would like to discover just
what type of stream you are getting back when you call the
getResourceAsStream() method. If you have the time, it may be worth adding a
System.out.println(inputStream.getClass().getName()); statement just to see
what you are actually getting back; something like;

if (sourcePath == null){
    inputStream =
getClass().getClassLoader().getResourceAsStream("file.xls");
    System.out.println(inputStream.getClass().getName());
    workbook = WorkbookFactory.create(inputStream);
}

Also - and I admit that there is no reason why you would need to do this -
you could try wrapping up that input stream into a FileInputStream just,
again, to see what happens.

Yours

Mark B


individuodk wrote:
> 
> hi!!
> poi-3.5-FINAL.jar
> 
> 
> 			if (sourcePath == null){
> 				inputStream =
> getClass().getClassLoader().getResourceAsStream("file.xls");
> 				workbook = WorkbookFactory.create(inputStream);
> 			}
> 			else{
> 				inputStream = new FileInputStream(sourcePath);
> 				workbook = WorkbookFactory.create(inputStream);
> 			}
> 
> When i read excel file from FileInputStream to modify it, all works fine.
> When i read excel file (SAME excel file) from
> getClass().getClassLoader().getResourceAsStream..., all are exceptions
> like next:
> 
> convertPOIOutputStream|null|Exception||4|5|N| [ java.io.IOException ]
> block[ 63 ] already removed -
> does your POIFS have circular or duplicate block
> references?java.io.IOException: block[ 63 ] 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:32)
>         at
> org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableR
> eader.java:187)
>         at
> org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:123)
>         at
> org.apache.poi.poifs.storage.RawDataBlockList.fetchBlocks(RawDataBlockList.java:32)
>         at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:54
> 1)
>         at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)
> 
> 
> or
> 
> convertPOIOutputStream|null|Exception||4|5|N| [
> org.apache.poi.hssf.record.RecordFormatException ] U
> nable to construct record
> instanceorg.apache.poi.hssf.record.RecordFormatException: Unable to constr
> uct record instance
>         at
> org.apache.poi.hssf.record.RecordFactory$ReflectionRecordCreator.create(RecordFactory.jav
> a:64)
>         at
> org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:263)
>         at
> org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStre
> am.java:270)
>         at
> org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.j
> ava:236)
>         at
> org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:377)
>         at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:275)
>         at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:200)
>         at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:316)
>         at
> org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:297)
>         at
> org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:60)
> 
> 
> any idea about how to input file to resource? why does it happen ???
> thanks!
> 

-- 
View this message in context: http://old.nabble.com/exception-when-inputstream-is-read-from-getClass%28%29.getClassLoader%28%29.getResourceAsStream%28%22file.xls%22%29-tp26406348p26410285.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org