aspose-words / Aspose.Words-for-Java

Aspose.Words for Java examples, plugins and showcases
https://products.aspose.com/words/java
MIT License
404 stars 206 forks source link

Create document via inputstream results in blank page #59

Closed 1nutzername closed 4 years ago

1nutzername commented 5 years ago

I saved my docx documents temporarily as blob in a postgresql database using jdbc. After fetching and initializing them with help of the Document::constructor (Aspose 19.10) all of the created documents are blank.

Example code

List<Document> test(List<InputStream> streams) {
   List<Document> a = new LinkedList<>();
   for(InputStream stream: streams) {
      a.add(new Document(stream);
   }
   return a;
}

The cause

The Document::constructor for inputstreams calls zz51.zzY(stream) and this method contains the following lines:

if (var0 instanceof FileInputStream) {
    return new zz1K((FileInputStream)var0);
}
if (var0.markSupported()) {
    return new zz1J(var0);
}

return zzX(var0);

My InputStream isn't of type FileInputStream but it supports marks and in my case it jumps into zz1J. The following snipped is the cause of my blank documents:

this.zzSv = (long)var1.available();
this.zz2Y = false;
this.zz2Z.mark((int)this.zzSv);

According the official javadoc its not recommended to do that (Javadoc InputStream) because "some implementations of InputStream will return the total number of bytes in the stream, many will not". So doesn't the BlobInputStream of the Postgresql-jdbc implementation which returns the default value of InputStream::available (Postgresql BlobInputStream).

Solution/Workaround

My workaround is to wrap the InputStream into a class that extands from InputStream and override the methods returning false in the method markSupported to skip the jump into zz1J. Instead it reads the stream as it is in zzX.

br

AlexNosk commented 4 years ago

@i7i5 Thank you for reporting this to us. I logged the issue WORDSJAVA-2248 in our bug tracking system. We will let you know once it is resolved.

AlexNosk commented 4 years ago

@i7i5 The issue you have reported earlier is fixed. The fix is included into the latest 20.01 release of Aspose.Words for Java. You can download this version from here.