0

While I am reading a 25 MB file it's throwing an Java heap space. It can read 20 MB file but it's unable to read 25 MB file.

InputStream is = new ByteArrayInputStream(bean.getFile());
BufferedImage img = ImageIO.read(is);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
venkatesh
  • 1
  • 2
  • 1
    try to increase the heap size – Maurice Perry Jun 29 '18 at 13:16
  • Maybe this article would help you someway.. http://worksheetsoftware.com/index.php/software/blog/29-effective-handling-of-big-images-in-java – Madushan Perera Jun 29 '18 at 13:20
  • Try using `FileInputStream` instead of `ByteArrayInputStream` – user11153 Jun 29 '18 at 13:27
  • the input file is byte[] . – venkatesh Jun 29 '18 at 13:39
  • using sts 3.8.1 with jdk 8 – venkatesh Jun 29 '18 at 13:40
  • Check this https://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error-64mb-heap – Victor Gubin Jun 29 '18 at 13:43
  • Do you get an exception then? – Herr Derb Jun 29 '18 at 14:00
  • java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferByte.(DataBufferByte.java:92) at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:445) at java.awt.image.Raster.createWritableRaster(Raster.java:941) at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1074) at javax.imageio.ImageReader.getDestination(ImageReader.java:2892) at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1071) at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.jav – venkatesh Jun 29 '18 at 14:08
  • Ignore the file size for the moment, how big are the two files in pixels and bit depth (number of possible colors)? Given the clever nature of image compression algorithms, an image file size says little about how big it will be once loaded. – Andrew Thompson Jun 29 '18 at 16:54

0 Answers0