[Fix] PixivUgoiraBuilder 修复ZipInputStream在读取完第一帧图像后被意外关闭的问题;

This commit is contained in:
LamGC 2020-07-10 09:53:41 +08:00
parent d1c7f6f973
commit 6d55325fc7

View File

@ -1,5 +1,6 @@
package net.lamgc.cgj.pixiv; package net.lamgc.cgj.pixiv;
import com.google.common.io.ByteStreams;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -12,7 +13,6 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.apache.tomcat.util.http.fileupload.util.Streams;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -127,14 +127,13 @@ public final class PixivUgoiraBuilder {
HashMap<String, InputStream> frameMap = new HashMap<>(frames.size()); HashMap<String, InputStream> frameMap = new HashMap<>(frames.size());
while((entry = zipInputStream.getNextEntry()) != null) { while((entry = zipInputStream.getNextEntry()) != null) {
log.trace("ZipEntry {} 正在接收...", entry); log.trace("ZipEntry {} 正在接收...", entry);
Streams.copy(zipInputStream, cacheOutputStream, false); ByteStreams.copy(zipInputStream, cacheOutputStream);
frameMap.put(entry.getName(), new ByteArrayInputStream(cacheOutputStream.toByteArray())); frameMap.put(entry.getName(), new ByteArrayInputStream(cacheOutputStream.toByteArray()));
log.trace("ZipEntry {} 已接收完成.", entry); log.trace("ZipEntry {} 已接收完成.", entry);
cacheOutputStream.reset(); cacheOutputStream.reset();
} }
InputStream firstFrameInput = frameMap.get(frames.get(0).getAsJsonObject().get("file").getAsString());
InputStream firstFrameInput = frameMap.get("000000.jpg");
BufferedImage firstFrame = ImageIO.read(firstFrameInput); BufferedImage firstFrame = ImageIO.read(firstFrameInput);
firstFrameInput.reset(); firstFrameInput.reset();
if(width != firstFrame.getWidth() || height != firstFrame.getHeight()) { if(width != firstFrame.getWidth() || height != firstFrame.getHeight()) {