We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Avoid Java IO IOException Resetting to Invalid Mark during Loading Word Document using a BufferedInputStream

Wen I load a document with a BufferedInputStream an exception is thrown:

Caused by: java.io.IOException: Resetting to invalid mark
at java.io.BufferedInputStream.reset(BufferedInputStream.java:448)
at com.aspose.words.internal.zz14.zzm(Unknown Source)
at com.aspose.words.internal.zzUU.zzTc(Unknown Source)
at com.aspose.words.zz0F.zzY(Unknown Source)
at com.aspose.words.Document.zzY(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)

There are two attachment to this topic: a simple word document and a junit5 test with which the behaviour can be reproduced with Aspose.words 19.11.
Unfortunately the Class.getRessourceAsStream() method return a BufferedInputStream, so we cant load any word resource anymore.
input.doc.zip (6.5 KB)
@Test
public void testSimpleLoadDocumentWithBufferedStream() throws Exception {
File file = new File(“input.doc”);
try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(file))) {
Document document = new Document(is);
Assertions.fail(“Document can be read?”);
} catch (IOException e) {
Assertions.assertEquals(“Resetting to invalid mark”, e.getMessage());
e.printStackTrace();
}
try (FileInputStream is = new FileInputStream(file)) {
Document document = new Document(is);
Assertions.assertFalse(document.getText().isEmpty());
}
}

@ns1045,

Thanks for reporting this problem to us. We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSJAVA-2253. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Hi Awais,

thanks a lot! We are blocked by this issue, so we cant use the specially buyed licence. Can you estimate when the bug is fixed?

Cheers,
ns1045

@ns1045,

I am afraid, there are currently no estimates available at the moment. But, we have logged your concerns in our issue tracking system and will keep you posted on further updates.

The issues you have found earlier (filed as WORDSJAVA-2253) have been fixed in this Aspose.Words for .NET 19.12 update and this Aspose.Words for Java 19.12 update.

Hoi Awais,

I wish you a great new year 2020.
Unfortunately there is still another case of BufferedInputStreams with is not longer readable with Aspose 19.12. I would say that this is the case if the size of buffer is equals to the remaining bytes of the stream. This is the case because your class calls BufferedInputStream.mark with the available() result. The implementations of InputStream.available() is not verified to return the correct count of available bytes (see JavaDoc). In our case, the available() return any pseudo value due the original stream is compressed.

Caused by: java.io.IOException: Resetting to invalid mark
at java.io.BufferedInputStream.reset(BufferedInputStream.java:448)
at com.aspose.words.internal.zz12.zzm(Unknown Source)
at com.aspose.words.internal.zzUU.zzTc(Unknown Source)
at com.aspose.words.zz0F.zzY(Unknown Source)
at com.aspose.words.Document.zzY(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)

Cheers,
ns1045

@ns1045,

Thanks for your inquiry. Please upgrade to the latest version of Aspose.Words for Java i.e. 20.1 and see how it goes on your end? Hope, this helps.

In case the problem still remains, please ZIP and upload your input Word document you are getting this problem with here for testing. We will then investigate the scenario on our end and provide you more information.

Hi Awais,

thanks a lot. With 20.1 the problem is resolved!

Cheers,
ns1045