Could not able to load InputStream

Hi Team

We are facing issue with the Image.load(Java.io.InputStream) with below exception com.aspose.imaging.coreexceptions.ImageLoadException: Cannot open an image. The image file format may be not supported at the moment.

Where as the same stream when we write to file and try to load using the Image.load(“filePath”) it is working as expected .

Hi, @veera1208.
We appreciate your interest in Aspose.Imaging.
Please, clarify how can you save to file the Java.io.InputStream ? Since InputStream is a read-only stream.
Could you provide a piece of code where you initialize the InputStream?
Based on your information I may suppose that a position in InputStream is not equal to 0, that is why Image.load can’t read it correctly.
Please, let me know if this information helps you.

Below is the CodeSnippet we are trying to read the InputStream and send it to Image.laod() method

for(InputStream inst : pagegroup) {
try {
Image img = Image.load(inst);
if (img instanceof IMultipageImage) {
int streamPages = ((IMultipageImage) img).getPageCount();
tcount = tcount + streamPages;
Image[] imagearr = ((IMultipageImage) img).getPages();
for (int i = 0; i < streamPages; i++) {
images.add(imagearr[i]);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@veera1208
Excuse me, please for the late response. As I see the problem appears at the line Image img = Image.load(inst);? Am I right?
Let me know where you get pagegroup from. Is it a list/array of FileInputStream? Or something else?
Could you provide me the code you use for saving these InputStrream to files and later loading from them?

Yes Image.load() is the method that is causing the issue and yes the pageGroup is the List of Streams .
We tried writing to the Stream to file to check on the stream is valid or not .Below is the snippet we tried

FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(“I:\Veera\AddDoc\test\test”);
fileOutputStream.write(inst.readAllBytes());
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}

Image.load(“I:\Veera\AddDoc\test\test”) --able to load the Image

@veera1208
It is so strange… Could not understand what is wrong…
Could you test this code:

for(InputStream inst : pagegroup) {
	try {
		Image img = Image.load(new ByteArrayInputStream(inst.readAllBytes()));
		if (img instanceof IMultipageImage) {
			int streamPages = ((IMultipageImage) img).getPageCount();
			tcount = tcount + streamPages;
			Image[] imagearr = ((IMultipageImage) img).getPages();
			for (int i = 0; i < streamPages; i++) {
				images.add(imagearr[i]);
			}
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}