Java Image4j: method not return when decoding ico image

211 Views Asked by At

I'm trying to use image4j 0.7 library to decode .ico file.
My code is here:

    //File address
    String sourceAddress="/home/tojandro/Desktop/favicon.ico";

    //Read data
    InputStream inputStream=new FileInputStream(sourceAddress);
    ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
    byte[] buffer=new byte[0xfff];
    int length=-1;
    while( (length=inputStream.read(buffer))>0 )
        outputStream.write(buffer, 0, length);
    outputStream.flush();
    inputStream.close();
    ByteArrayInputStream dataBuffer=new ByteArrayInputStream(outputStream.toByteArray());

    //Try to decode
    System.out.println("Decode begin.");
    ICODecoder.read(dataBuffer);                        //This method could never been return.
    //ICODecoder.read(new File(sourceAddress));         //This method works well.
    System.out.println("Decode finished.");

My problem is:
   When I decode image from file directly, the method works well;
   But when I decode image from byte buffer, sometimes(some files ok and some files not) the method would never return.
Anybody could help me? Thanks.

0

There are 0 best solutions below