3

我有以下代码:

List<PDXObjectImage> list = new ArrayList<PDXObjectImage>(someValues);
CircularByteBuffer cbb = new CircularByteBuffer(CircularByteBuffer.INFINITE_SIZE);

for(int k=0;k<list.size();k++)
{
    list.get(k).write2OutputStream(cbb.getOutputStream());
    ImageInputStream iis = ImageIO.createImageInputStream(cbb.getInputStream());
    Iterator iter = ImageIO.getImageReaders(iis);
    if (iter.hasNext()) {
        ImageReader reader = (ImageReader) iter.next();
        reader.addIIOReadProgressListener(new IIOReadProgressListener(){...});
        reader.setInput(iis, true, true);

        System.out.println("Still okay");
        BufferedImage img = reader.read(0, null);
        System.out.println("Not okay");

        ImageIcon imageIcon = new ImageIcon(img);
        model.addRow(new Object[]{imageIcon});
    }
}

程序总是显示“还可以”,但从不显示“不行”。

IIOReadProgressListener表明阅读器在阻塞前读取了高达 82.4% 的图像。

在我开始使用之前CircularByteBuffer,我使用的是一系列的ByteArrayOutputStream, ByteArrayInputStream,OutputStreamInputStream,但由于OutOfMemoryError : Java Heap Space.

如果有人知道发生了什么,我将非常感谢一些帮助,

谢谢

编辑:

使用以下代码也会发生同样的事情:

List<PDXObjectImage> list = new ArrayList<PDXObjectImage>(someValues);

for(int k=0;k<list.size();k++)
{
    PipedOutputStream convertPipe = new PipedOutputStream();
    PipedInputStream dataPipe = new PipedInputStream(convertPipe,1000000);
    img.write2OutputStream(convertPipe);
    ImageInputStream iis = ImageIO.createImageInputStream(dataPipe);
    Iterator iter = ImageIO.getImageReaders(iis);
    if (iter.hasNext()) {
        ImageReader reader = (ImageReader) iter.next();
        reader.addIIOReadProgressListener(new IIOReadProgressListener(){...});
        reader.setInput(iis, true, true);

        System.out.println("Still okay");
        BufferedImage img = reader.read(0, null);
        System.out.println("Not okay");

        ImageIcon imageIcon = new ImageIcon(img);
        model.addRow(new Object[]{imageIcon});
    }
}
4

0 回答 0