gpt4 book ai didi

java - 平放器输出流 : write beyond end of stream

转载 作者:行者123 更新时间:2023-12-03 02:23:17 42 4
gpt4 key购买 nike

我收到 deflaterstream 的“写入超出流末尾”错误。我跟踪了错误,它显示流显然已经完成。但是,在我的函数开始时,将流创建为全新的,并且在最后不要调用 close 或 finish ..

错误:

SEVERE: null
java.io.IOException: write beyond end of stream
at java.util.zip.DeflaterOutputStream.write(DeflaterOutputStream.java:102)
at evidence.SaveStateManager.saveIncremental(SaveStateManager.java:82)

代码:

public static void saveIncremental(int textureId, int layer, int shot) {
try {
bOut = new FileOutputStream("saves/p-" + layer + "-" + shot + ".gz");
gzipOut = new DeflaterOutputStream (bOut, deflater);

glPushAttrib(GL_ALL_ATTRIB_BITS);

glBindTexture(GL_TEXTURE_2D, textureId);

int bpp = 4;
ByteBuffer buffer = BufferUtils.createByteBuffer(SAVE_WIDTH * SAVE_HEIGHT * bpp);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer );

byte[] bytes = new byte[1024];
while (buffer.hasRemaining()) {
int len = Math.min(buffer.remaining(), bytes.length);
buffer.get(bytes, 0, len);
try {
gzipOut.write(bytes, 0, len);
} catch (IOException ex) {
Logger.getLogger(SaveStateManager.class.getName()).log(Level.SEVERE, null, ex);
}
}

glBindTexture(GL_TEXTURE_2D, 0);
glPopAttrib();

gzipOut.finish();
gzipOut.close();
bOut.close();
} catch (Exception ex) {
Logger.getLogger(SaveStateManager.class.getName()).log(Level.SEVERE, null, ex);
}
}

最佳答案

Deflator 是有状态的,您正在重用它。

gzipOut = new DeflaterOutputStream (bOut, deflater);

来自 DeflaterOutputStream 的来源

public void write(byte[] b, int off, int len) throws IOException {
if (def.finished()) {
throw new IOException("write beyond end of stream");

关于java - 平放器输出流 : write beyond end of stream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14237426/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com