• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you adding "hidden data"? What is that in the context of a Word document?
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok Let me try and in any case i found the same I will contact you.
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok let me check I will update you in case of any issue.

Thanks
Kushagra
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic