Free Support Forum - aspose.com

Loading .dot file from database BLOB

Hi,

I am trying to load .dot file from database BLOB in web application. However, i am getting the following error

Caused by: java.lang.IllegalStateException: XMLStreamException: Unexpected EOF in prolog

when i try to load the same document from file system using file input stream it is working fine.

Here is the code that i tried to load. Please advice.

InputStream in = new BufferedInputStream(getLtrHeadBlb().getBinaryStream());
LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(LoadFormat.DOT);

//Get document bytes
byte[] docBytes = getBytesFromInputStream(in);

InputStream docStream = new ByteArrayInputStream(docBytes);

Document doc = new Document(docStream,loadOptions);

ByteArrayOutputStream str = new ByteArrayOutputStream();
doc.save(str,SaveFormat.DOC);

Hello

Thanks for your request. Which version of Aspose.Words for Java are you using? Could you please try using the latest version of Aspose.Words for Java (10.5.0) and let me know how it goes on you side. You can download this version from here:

http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/category1378.aspx

Best regards,

Hi,

I am using the latest version Aspose.Words for Java (10.5.0).

Thanks,

Rama.

Hello

Thanks for your inquiry. Could you please attach your input document here for testing? I will check the problem on my side and provide you more information.

Best regards,

Hi,

Attached is the sample .dot file uploaded in database as BLOB.

Thanks

Hello

Thank you for additional information. I cannot reproduce the problem on my side using the following code:

InputStream originalDocStream = new FileInputStream("C:\\Temp\\lttr_head.dot");

InputStream inputStream = new BufferedInputStream(originalDocStream);

ByteArrayOutputStream tempStream = new ByteArrayOutputStream();

byte[] buf = new byte[4096];

while (true)

{

int bytesRead = inputStream.read(buf, 0, buf.length);

// InputStream returns -1 when end of stream is reached.

if (bytesRead <= 0)

break;

else

tempStream.write(buf, 0, bytesRead);

}

byte[] dataBytes = tempStream.toByteArray();

// Wrap the bytes representing the document in memory into a stream object.

ByteArrayInputStream byteStream = new ByteArrayInputStream(dataBytes);

LoadOptions loadOptions = new LoadOptions();

loadOptions.setLoadFormat(LoadFormat.DOT);

Document doc = new Document(byteStream, loadOptions);

ByteArrayOutputStream str = new ByteArrayOutputStream();

doc.save(str, SaveFormat.DOC);

doc.save("C:\\Temp\\out.doc");

Best regards,

Hi,

Using the file input stream it is working fine but reading it from BLOB is the problem. When i try it with .doc file reading from BLOB with the same code it is also working fine. Any suggestion would be greatly appreciated.

Thanks

Hi

Thanks for your request. Maybe the problem is in the way how the document is stored in your database. Have you tried to save BLOB directly to file? Is the produced file valid?

Here is simple code that shows how to open document from byte array I used for testing on my side.

// Get document's byte array

byte fileContent[] = getBytesFromFile(new File("C:\\Temp\\lttr_head.dot"));

// Create a byte array inout stream.

ByteArrayInputStream docStream = new ByteArrayInputStream(fileContent);

// Create document from stream.

Document doc = new Document(docStream);

// Do something with document.

// ...............

// Save output.

doc.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards,

Hi,

I download the file from the blob and it is showing up correctly . I did the same test case with .doc file and it is working fine with aspose word. The problem is with .dot file only. I tried with the code that you suggested and it is working with .doc file but not .dot file loading from the blob. Both files are valid and are opening fine when downloaded to the disk. I am waiting on this problem to be fixed to buy the product. Thank you for your assistance .

Hi

Thank you for additional information. But unfortunately, I still cannot reproduce the problem on my side. Have you tried reading file bytes from the downloaded file, creating stream and opening the document from stream? Does the exception still occur in this case?

It would be great if you create a small application that will allow us to reproduce the problem.

Best regards,

Hi,

Is there any library that Aspose is using while loading .dot files for xml parsing? I created sample application with just aspose.word library and my test case is working fine but when i incorporate in my project it's not working. There are many libraries associated with the project regarding xml parser and xstream. Does Aspose uses any of these that is creating conflict in some of the methods? I am trying to figure out which library is causing problem as it is working in sample web application with just aspose library.

Thanks

Hi

Thank you for additional information. No, Aspose.Words does not use any external libraries. Also, DOT and DOC files are actually the same format, but in DOT file a flag that indicates that the document is template is set. This is the only difference between these formats. So it is quite strange that you can successfully load DOC files, but cannot load DOT.

Best regards,