0

我正在尝试使用 image4j 0.7 库来解码 .ico 文件。
我的代码在这里:

    //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.");

我的问题是:
   当我直接从文件中解码图像时,该方法效果很好;
   但是当我从字节缓冲区解码图像时,有时(有些文件可以,有些文件不行)该方法永远不会返回。
任何人都可以帮助我吗?谢谢。

4

0 回答 0