java - ImageIO when reading GIF image throws IndexOutOfBoundsException: off < 0 || len < 0 || off+len > b.length || off+len < 0 -


when reading gif images using imageio library, getting exception:

java.lang.indexoutofboundsexception: off < 0 || len < 0 || off+len > b.length || off+len < 0!  @ javax.imageio.stream.filecacheimageinputstream.read(filecacheimageinputstream.java:157)  @ com.sun.imageio.plugins.gif.gifimagereader.getcode(gifimagereader.java:306)  @ com.sun.imageio.plugins.gif.gifimagereader.read(gifimagereader.java:909)  @ javax.imageio.imageio.read(imageio.java:1422)  @ javax.imageio.imageio.read(imageio.java:1326)  ... 

it seems internal bug gifimagereader. there way resolve this? code running under java 6.

edit: after debugging found, problem not in reading gif image, writing it.

my (reduced) code writing image:

// buffered image, using scalr resize bufferedimage resizedimage = scalr.resize(image, method.automatic, resizemode, maxwidth, maxheight);  bytearrayoutputstream tmp = new bytearrayoutputstream(); imageio.write(resizedimage, "gif", tmp); return new bytearrayinputstream(tmp.tobytearray()); // converted blob , persisted oracle db 

when blob in database using oracle sql developer, data text contains large (i.e ~4mb) binary data beginning with:

gif89a ÷ %*4?40<b=jcedkdsf:klkdltll 

in same tool (osd) when try view image, print me same string (why???):

off < 0 || len < 0 || off+len > b.length || off+len < 0 

it happens gif of files. seems of them converted format (jpg, png). files messed up, low level exception when reading cause me troubles. because when writing image blob, seems ok , getting exception while reading it.

for reading (when exception thrown) code simple:

byte[] imagedata = ...   bytearrayinputstream instream = new bytearrayinputstream(imagedata); bufferedimage img = imageio.read(instream); // indexoutofboundsexception 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -