Do I need to close InputStream for setLicense(InputStream) and safe to call once in Static block?

I can’t find the Java API, the current code I inherited is adding the license key as…


com.aspose.cells.License lc = new com.aspose.cells.License();
InputStream licIs = DostSpreadSheet.class.getClass().getResourceAsStream("/Aspose.Cells.lic");
lc.setLicense(licIs);

He’s never closing the InputStream though. Does your setter “setLicense” end up closing the stream automatically? (It can’t hurt for us to try to close it, but was curious.)

Also, in a web application am I ok just loading this license one time in a static block?

Thanks

Hi,

Thanks for your posting and using Aspose.Cells for Java

You do not need to close the license stream. You need to set license only once.

Hmm, I’m not noticing the same behavior as “set once.”


I’m not aware of how the internals are working of the License object, but I seem to have to set it each time before starting the work (maybe only once per thread - but I don’t want to have to load in the license file for each user thread.) Apparently just setting it once in a static block isn’t enough?

Are you setting the license on a static or are you doing something with putting it on ThreadLocale maybe?
Hi,

1. For the InputStream when using setLicense(InputStream), you have to close it by yourself. For all IO related APIs, we do not close the user provided streams. However, if you use file name as parameter for IO operation, we will surely close the file related streams that built by our component internally. It is also the common programming practice for Java program.
2. We set the license in a “static” way, so it should be needed only once for all threads run in one application. If you get problem for setting license, please create one simple console application and test whether setting license only once can work for multiple threads. If the console application can work, please check your server configuration and application, such as classloader used by different threads, code executing order, ...etc. If the console application cannot work, please send us the console application so we can test and figure the issue out.