我正在尝试使用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.");
我的问题是:
当我直接从文件解码图像时,该方法效果很好;
但是当我从字节缓冲区解码图像时,有时(某些文件正常,而某些文件没有),该方法永远不会返回。
有人可以帮帮我吗?感谢。