You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Jari Niskala <ja...@gmail.com> on 2008/02/17 08:00:03 UTC
Read->Modify->Write
Hi,
First of all, let me just thank all the contributors to this wonderful
project!
My problem scenario occurs when I'm trying to read a MS Project file, then
modify it and finally write its contents to another file using the
POIFSFileSystem.
However, even with just reading, then writing the contents I am getting this
exception:
java.io.IOException: block[ 0 ] already removed
at
org.apache.poi.poifs.storage.BlockListImpl.remove(BlockListImpl.java:97)
at
org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAll
ocationTableReader.java:190)
at
org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:12
9)
at
org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileS
ystem.java:404)
at
org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileS
ystem.java:392)
at
org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileS
ystem.java:392)
at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:
103)
Here is the code that is causing this problem:
// Read the file
FileInputStream is = new FileInputStream (input);
POIFSFileSystem fs = new POIFSFileSystem (is);
// Write the file
FileOutputStream os = new FileOutputStream(output);
fs.writeFilesystem(os);
os.flush();
os.close();
is.close();
// Read the file again
is = new FileInputStream (output);
fs = new POIFSFileSystem (is);
I've also tried to do this more manually, creating a separate
POIFSFileSystem and iterating through the original filesystem, creating
documents and directories. Same result.
If you have any ideas on this let me know. Thank you for your time.
Best regards,
Jari Niskala
RE: Read->Modify->Write
Posted by Nick Burch <ni...@torchbox.com>.
On Mon, 18 Feb 2008, Jari Niskala wrote:
> This works with the 3.0.2 Final release. Thank you for your help on
> this!!!
Excellent, glad the fix was that easy :)
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: Read->Modify->Write
Posted by Jari Niskala <ja...@gmail.com>.
Hi Nick,
This works with the 3.0.2 Final release. Thank you for your help on this!!!
(aye, what a rookie mistake on my part... should have verified with the
latest...)
BR,
Jari Niskala
Get a FREE Microsoft Project Viewer at http://www.kadonk.com
-----Original Message-----
From: Jari Niskala [mailto:jariniskala@gmail.com]
Sent: Monday, February 18, 2008 10:41 AM
To: 'Nick Burch'; 'POI Users List'
Cc: 'Jari Niskala'
Subject: RE: Read->Modify->Write
Hi Nick,
Using the 3.0.1 FINAL release. I'll try with 3.0.2...
BR,
Jari Niskala
Get a FREE Microsoft Project Viewer at http://www.kadonk.com
-----Original Message-----
From: Nick Burch [mailto:nick@torchbox.com]
Sent: Monday, February 18, 2008 10:35 AM
To: POI Users List
Cc: 'Jari Niskala'
Subject: RE: Read->Modify->Write
On Mon, 18 Feb 2008, Jari Niskala wrote:
> What we're trying to accomplish is to be able to take a project file,
> make some modifications to it and then save it, all using the
> POIFSFileSystem.
>
> However, the problem below occurs if I merely open the Project with
> POIFS, write it to another file with POIFS without any modifications and
> then try to re-open the file using POIFS.
Hmm, that's quite odd. You ought to be able to do that without problems.
Can you confirm it's happening with 3.0.2 final?
If so, your best bet is to upload the problem file to bugzilla. I'll
happily then wrap it in a quick failing unit test, then we just need one
of our resident ole2 experts to take a look and spot what's wrong...
> Here is the code that causes the problem... is there something I should
> be doing differently? I've tried a more manual read/write approach as
> well with the same results...
Your code does look fine to me
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: Read->Modify->Write
Posted by Jari Niskala <ja...@gmail.com>.
Hi Nick,
Using the 3.0.1 FINAL release. I'll try with 3.0.2...
BR,
Jari Niskala
Get a FREE Microsoft Project Viewer at http://www.kadonk.com
-----Original Message-----
From: Nick Burch [mailto:nick@torchbox.com]
Sent: Monday, February 18, 2008 10:35 AM
To: POI Users List
Cc: 'Jari Niskala'
Subject: RE: Read->Modify->Write
On Mon, 18 Feb 2008, Jari Niskala wrote:
> What we're trying to accomplish is to be able to take a project file,
> make some modifications to it and then save it, all using the
> POIFSFileSystem.
>
> However, the problem below occurs if I merely open the Project with
> POIFS, write it to another file with POIFS without any modifications and
> then try to re-open the file using POIFS.
Hmm, that's quite odd. You ought to be able to do that without problems.
Can you confirm it's happening with 3.0.2 final?
If so, your best bet is to upload the problem file to bugzilla. I'll
happily then wrap it in a quick failing unit test, then we just need one
of our resident ole2 experts to take a look and spot what's wrong...
> Here is the code that causes the problem... is there something I should
> be doing differently? I've tried a more manual read/write approach as
> well with the same results...
Your code does look fine to me
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: Read->Modify->Write
Posted by Nick Burch <ni...@torchbox.com>.
On Mon, 18 Feb 2008, Jari Niskala wrote:
> What we're trying to accomplish is to be able to take a project file,
> make some modifications to it and then save it, all using the
> POIFSFileSystem.
>
> However, the problem below occurs if I merely open the Project with
> POIFS, write it to another file with POIFS without any modifications and
> then try to re-open the file using POIFS.
Hmm, that's quite odd. You ought to be able to do that without problems.
Can you confirm it's happening with 3.0.2 final?
If so, your best bet is to upload the problem file to bugzilla. I'll
happily then wrap it in a quick failing unit test, then we just need one
of our resident ole2 experts to take a look and spot what's wrong...
> Here is the code that causes the problem... is there something I should
> be doing differently? I've tried a more manual read/write approach as
> well with the same results...
Your code does look fine to me
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: Read->Modify->Write
Posted by Jari Niskala <ja...@gmail.com>.
Hi Nick,
Thanks for getting back to me. I am in fact working on MPXJ at the moment, I
help contribute to it as we use it for our product.
What we're trying to accomplish is to be able to take a project file, make
some modifications to it and then save it, all using the POIFSFileSystem.
However, the problem below occurs if I merely open the Project with POIFS,
write it to another file with POIFS without any modifications and then try
to re-open the file using POIFS.
Also the file is a valid file (seems to happen with all files) and it can be
opened with POIFS and MS Project prior to it being written to another file.
Here is the code that causes the problem... is there something I should be
doing differently? I've tried a more manual read/write approach as well with
the same results...
// Read the file
FileInputStream is = new FileInputStream (input);
POIFSFileSystem fs = new POIFSFileSystem (is);
// Write the file
FileOutputStream os = new FileOutputStream(output);
fs.writeFilesystem(os);
os.flush();
os.close();
is.close();
// Read the file again
is = new FileInputStream (output);
fs = new POIFSFileSystem (is);
Strangely, the file size remains exactly the same and the new file can in
fact be opened using MS Project and if saved using MS Project it opens as
expected using POIFS.
Thanks for your help!
BR,
Jari Niskala
Get a FREE Microsoft Project Viewer at http://www.kadonk.com
-----Original Message-----
From: Nick Burch [mailto:nick@torchbox.com]
Sent: Monday, February 18, 2008 5:07 AM
To: POI Users List
Cc: 'Jari Niskala'
Subject: Re: Read->Modify->Write
On Sat, 16 Feb 2008, Jari Niskala wrote:
> My problem scenario occurs when I'm trying to read a MS Project file, then
> modify it and finally write its contents to another file using the
> POIFSFileSystem.
>
> However, even with just reading, then writing the contents I am getting
> this exception:
> java.io.IOException: block[ 0 ] already removed
Looks like your file might be corrupt. You shouldn't be seeing an error
like that with a valid file. I'd suggest opening it up in project, and
doing a "save as" to force a full write, and see if that fixes it
Also, have you come across MPXJ [1]? It's an open source project for
handling project files, which uses POI for the low level manipulation
Nick
[1] http://mpxj.sourceforge.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Read->Modify->Write
Posted by Nick Burch <ni...@torchbox.com>.
On Sat, 16 Feb 2008, Jari Niskala wrote:
> My problem scenario occurs when I'm trying to read a MS Project file, then
> modify it and finally write its contents to another file using the
> POIFSFileSystem.
>
> However, even with just reading, then writing the contents I am getting
> this exception:
> java.io.IOException: block[ 0 ] already removed
Looks like your file might be corrupt. You shouldn't be seeing an error
like that with a valid file. I'd suggest opening it up in project, and
doing a "save as" to force a full write, and see if that fixes it
Also, have you come across MPXJ [1]? It's an open source project for
handling project files, which uses POI for the low level manipulation
Nick
[1] http://mpxj.sourceforge.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Read->Modify->Write
Posted by Narasimha Bhat <nb...@gmail.com>.
I am also facing a similar problem ... But I am trying to read Outlook 2007
pst file which is not supported. Actually 3.0.2 scratchpad throws invalid
header, for experimentation I hard coded the value found in pst files as one
of the allowed header values. I wonder if this is due to the fact that 2007
onwards MS is storing values as unicode. I have not gone too far with the
debugging yet.
On Feb 17, 2008 12:30 PM, Jari Niskala <ja...@gmail.com> wrote:
> Hi,
>
>
>
> First of all, let me just thank all the contributors to this wonderful
> project!
>
>
>
> My problem scenario occurs when I'm trying to read a MS Project file, then
> modify it and finally write its contents to another file using the
> POIFSFileSystem.
>
>
>
> However, even with just reading, then writing the contents I am getting
> this
> exception:
>
>
>
> java.io.IOException: block[ 0 ] already removed
>
> at
> org.apache.poi.poifs.storage.BlockListImpl.remove(BlockListImpl.java:97)
>
> at
> org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks
> (BlockAll
> ocationTableReader.java:190)
>
> at
> org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java
> :12
> 9)
>
> at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties
> (POIFSFileS
> ystem.java:404)
>
> at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties
> (POIFSFileS
> ystem.java:392)
>
> at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties
> (POIFSFileS
> ystem.java:392)
>
> at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(
> POIFSFileSystem.java:
> 103)
>
>
>
>
>
> Here is the code that is causing this problem:
>
>
>
> // Read the file
>
> FileInputStream is = new FileInputStream (input);
>
> POIFSFileSystem fs = new POIFSFileSystem (is);
>
> // Write the file
>
> FileOutputStream os = new FileOutputStream(output);
>
> fs.writeFilesystem(os);
>
> os.flush();
>
> os.close();
>
> is.close();
>
> // Read the file again
>
> is = new FileInputStream (output);
>
> fs = new POIFSFileSystem (is);
>
>
>
>
>
> I've also tried to do this more manually, creating a separate
> POIFSFileSystem and iterating through the original filesystem, creating
> documents and directories. Same result.
>
>
>
> If you have any ideas on this let me know. Thank you for your time.
>
>
>
> Best regards,
>
> Jari Niskala
>
>
>
>