aspose file tools*
The moose likes Other Open Source Projects and the fly likes java.io.IOException: Unable to read entire block; 493 bytes read before EOF; expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "java.io.IOException: Unable to read entire block; 493 bytes read before EOF; expected" Watch "java.io.IOException: Unable to read entire block; 493 bytes read before EOF; expected" New topic
Author

java.io.IOException: Unable to read entire block; 493 bytes read before EOF; expected

Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,

I am using third party API poi to read my ms-word document.
And by doing so I am getting the following exception.
java.io.IOException: Unable to read entire block; 493 bytes read before EOF; expected 512 bytes
at org.apache.poi.poifs.storage.RawDataBlock.<init>(R awDataBlock.java:78)
at org.apache.poi.poifs.storage.RawDataBlock.<init>(R awDataBlock.java:50)
at org.apache.poi.poifs.storage.RawDataBlockList.<ini t>(RawDataBlockList.java:52)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<i nit>(POIFSFileSystem.java:93)
at org.apache.poi.hwpf.HWPFDocument.verifyAndBuildPOI FS(HWPFDocument.java:120)
at org.apache.poi.hwpf.extractor.WordExtractor.<init> (WordExtractor.java:49)




Can any body please tell me the possible solution for that. As I have used the following code.


String data = null;
InputStream objInputStream = new FileInputStream("inputDocs/Performance Management Resources.doc");
WordExtractor extractor = new WordExtractor(objInputStream);
bjInputStream.close();
data = extractor.getText();
System.out.println(data);
int wordCount=(data.split(" ")).length;
System.out.println(wordCount);

Please suggest me the solution as I am in urgent need of some solution.

Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
What is "bjInputStream", and why are you closing it? Or did you mean "objInputStream"? If so, I wouldn't think that it's a good idea to close it when later on you're making more calls to the extractor. Close it when you're sure that it's not needed any more.


Ping & DNS - my free Android networking tools app
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi ,

This is objInputStream. Sorry for that.

But as you can see that I have already extract the stream. And in the next lines of code I haven't used that starem. So better I closed the stream. And by the exception is coming on the line just above this line.


WordExtractor extractor = new WordExtractor(objInputStream);


At this line it is giving the same exception as I have mentioned above.

Please give me some solution of that. If any one of you is having.


Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
But as you can see that I have already extract the stream. And in the next lines of code I haven't used that starem. So better I closed the stream.

Actually, I don't see that. I'm fairly certain that the WordExtractor constructor does not perform the actual text extraction, but that that's done by subsequent calls to its methods, like getText. (In general, it's rare for constructors to do much actual work.) So the input stream better stay open.

And by the exception is coming on the line just above this line.
WordExtractor extractor = new WordExtractor(objInputStream);

OK, the last line of the stack trace indicates that the exception happens in the constructor.

So, is the file in question OK, meaning not corrupt? Can you open it with other applications?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Hi,

I have faced this error once, I vaguely remember this error when trying to access documents created using open office writer. Is this your case?

Regards
Ananth Chellathurai


Ananth Chellathurai [Walk on software]
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi
My problem is with MsWord.
And this is coming when I am adding some hidden data in the word document.


Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
How are you adding "hidden data"? What is that in the context of a Word document?
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
I am simply adding the xml tags by appending them in the file. And by that they are simply get appended in the file but not visible to the MsWord user.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
You can't change a structured file format like DOC by appending data to it using the file.io classes. That will result in invalid files, as you have found out. Any changes need to be made using a library that understand the DOC format, like POI.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Ok so can you please tell me that how can we add the hidden parameter in the word doc so that it can be read further in the near futre when it is required.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
What are "hidden parameters" in a Word document? Actually, what are "parameters" in general? How do you add those using Word?
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Actually I just want to make an application that will calculate the word count from the doc file and after that I have to put some processing on that word count and then again attached the new count in the docs in any way and after that read the same new word count by another application running on C++.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Oh, so you're talking about document properties? Please be sure to use the correct terminology, lest you confuse people. POI's DocumentProperties object has methods to set properties as well as read them.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
ok Let me try and in any case i found the same I will contact you.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,
I just want to add one new property with a new name in the Document. So is it possible to add the new property in the word document.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Have a look at the CustomProperties object that you can get from the DocumentSummaryInformation object, which in turn you can get from the HWPFDocument object.

Note that HWPF does not currently save custom properties correctly; see this how to trivially patch POI to do that.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Ok let me check I will update you in case of any issue.

Thanks
Kushagra
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,
On the link that you have given to me is not giving the solution for writing the custom properties in the document of my own custom name. Is there a way where I can add new custom properties in the word doc.

Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
On the link that you have given to me is not giving the solution for writing the custom properties in the document of my own custom name.


My last post described how to set custom properties. It also linked to an article describing how the current POI version needs to be patched (trivially) to make this work. What else are you looking for?

You may have noticed that here at JavaRanch we don't like to give out ready-made solutions, but instead give the information needed to find a solution. That way people can learn something along the way.
[ October 16, 2008: Message edited by: Ulf Dittmer ]
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,

I am still stuck with the same exception. As I am doing the followig things.

CustomProperties cus=new CustomProperties();
cus.put("Test","1000");
DocumentSummaryInformation docSum=new DocumentSummaryInformation(new PropertySet(new FileInputStream("inputDocs/sample.doc")));
docSum.setCustomProperties((CustomProperties)cus);


I have got the following exception.


org.apache.poi.hpsf.MarkUnsupportedException: java.io.FileInputStream
at org.apache.poi.hpsf.PropertySet.isPropertySetStream(PropertySet.java:332)
at org.apache.poi.hpsf.PropertySet.<init>(PropertySet.java:244)
at com.pearson.pcs.Test.main(Test.java:210)






Here sample.doc is the document in which I want to add the custom properties. And Test.java is my test java class.

Please help me if any one having the solution for that.


Thanks
Kushagra
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,

As I done some work on that I found that the propblemis basically from PropertySet class this class will check the stream's marsupported() method and if found false then throw the exception. So how can I overcome from this problem.

Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Not sure if you're still interested in this, but the latest beta version of POI fixes the problem of Word Document Properties not getting saved.
 
Don't get me started about those stupid light bulbs.
 
subject: java.io.IOException: Unable to read entire block; 493 bytes read before EOF; expected