setLicence() in a single class for all products, throwing error in 2nd licence

import java.io.InputStream;

public class AppLicense {

com.aspose.slides.License slidesLicense;
com.aspose.words.License wordsLicense;

public AppLicense(InputStream inputStream) throws Exception {
    setSlidesLicense(inputStream);
    setCellsLicense(inputStream);
    setPDFLicense(inputStream);
    setWordsLicense(inputStream);
}

private void setPDFLicense(InputStream inputStream) throws Exception {
    com.aspose.pdf.License pdfLicense = new com.aspose.pdf.License();
    pdfLicense.setLicense(inputStream);
}

private void setCellsLicense(InputStream inputStream) throws Exception {
    com.aspose.cells.License cellsLicense = new com.aspose.cells.License();
    cellsLicense.setLicense(inputStream);
}

private void setSlidesLicense(InputStream inputStream) throws Exception {
    slidesLicense = new com.aspose.slides.License();
    slidesLicense.setLicense(inputStream);
}

private void setWordsLicense(InputStream inputStream) throws Exception {
    wordsLicense = new com.aspose.words.License();
    wordsLicense.setLicense(inputStream);
}

public boolean isPDFLicensed(){
    return com.aspose.pdf.Document.isLicensed();
}

public boolean isCellsLicensed(){
    return com.aspose.cells.License.isLicenseSet();
}

public boolean isSlidesLicensed(){
    return slidesLicense.isLicensed();
}

public boolean isWordsLicensed(){
    return wordsLicense.isLicensed();
}

}

When I call AppLicense(getResources().openRawResource(R.raw.license)) method, I get various types of errors which i am trying to explain using following cases:-

1st Case
setWordsLicense(inputStream);
setPDFLicense(inputStream); //Error in this line
setCellsLicense(inputStream);
setSlidesLicense(inputStream);
Error - java.lang.NullPointerException: asset

2nd Case
setPDFLicense(inputStream);
setWordsLicense(inputStream); //Error in this line
setCellsLicense(inputStream);
setSlidesLicense(inputStream);
Error - org.xml.sax.SAXParseException: Unexpected end of document

3rd Case
setCellsLicense(inputStream);
setPDFLicense(inputStream); //Error in this line
setWordsLicense(inputStream);
setSlidesLicense(inputStream);
Error - java.lang.NullPointerException: asset

@MathiasT

Thank you for contacting support.

We are afraid this may not be a limitation of Aspose APIs but Java because problems can occur while reading same InputStream several times. Therefore, you would need to use some workaround approach where one of the possible solution is shared below and you may modify or enhance as per your requirements.

public AppLicense(InputStream inputStream) throws Exception {
    byte[] bytes = org.apache.commons.io.IOUtils.toByteArray(inputStream);
    InputStream first = new java.io.ByteArrayInputStream(bytes);
    setSlidesLicense(first);
    InputStream second = new java.io.ByteArrayInputStream(bytes);
    setCellsLicense(second);
    InputStream third = new java.io.ByteArrayInputStream(bytes);
    setPDFLicense(third);
}

We hope this information will be helpful. Please feel free to contact us if you need any further assistance.

Yes, its working. :slightly_smiling_face:
Thanks for the help.