java.io.IOException: Too many open files && how to release a BufferedImage

P

_pr0p

Hi,

my program is throwing this exception:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException:
javax.imageio.IIOException: Can't create cache file!
at org.ordanomade.interfaccia.ImageKit.read(ImageKit.java:30)
..........
Caused by:
at javax.imageio.ImageIO.createImageInputStream(ImageIO.java:335)
at javax.imageio.ImageIO.read(ImageIO.java:1325)

and next:

Caused by: java.io.IOException: Too many open files
at java.io.UnixFileSystem.createFileExclusively(Native Method)


The piece of code interested is this:
....
byte[] bytes = ImageKit.getBytes(chunkImage, quality/100f);
BufferedImage chunkImage = ImageKit.read(bytes);
.....
//this is ImageKit file where the exception is thrown
public static BufferedImage read(byte[] bytes) {
try {
return ImageIO.read(new ByteArrayInputStream(bytes));
} catch(IOException e) {
throw new RuntimeException(e);
}
}

I have to open many times different part of an image (I asked here before
about how to do this).
The question is:
how can I release (close) resources allocated by that BufferedImage? I
didn't find
a suitable method to do this.

Thank you in advance!
Have a nice day,

Gabriele
 
D

Dave Miller

_pr0p said:
Hi,

my program is throwing this exception:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException:
javax.imageio.IIOException: Can't create cache file!
at org.ordanomade.interfaccia.ImageKit.read(ImageKit.java:30)
.........
Caused by:
at javax.imageio.ImageIO.createImageInputStream(ImageIO.java:335)
at javax.imageio.ImageIO.read(ImageIO.java:1325)

and next:

Caused by: java.io.IOException: Too many open files
at java.io.UnixFileSystem.createFileExclusively(Native Method)


The piece of code interested is this:
...
byte[] bytes = ImageKit.getBytes(chunkImage, quality/100f);
BufferedImage chunkImage = ImageKit.read(bytes);
....
//this is ImageKit file where the exception is thrown
public static BufferedImage read(byte[] bytes) {
try {
return ImageIO.read(new ByteArrayInputStream(bytes));
} catch(IOException e) {
throw new RuntimeException(e);
}
}

I have to open many times different part of an image (I asked here before
about how to do this).
The question is:
how can I release (close) resources allocated by that BufferedImage? I
didn't find
a suitable method to do this.

Thank you in advance!
Have a nice day,

Gabriele
Look at flush();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top