From 89ded96336264f48f199aa1580f300ff07115624 Mon Sep 17 00:00:00 2001 From: LamGC Date: Wed, 10 Jun 2020 10:17:05 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=20=E6=9B=B4=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=89=80=E4=BD=BF=E7=94=A8=E7=9A=84=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/net/lamgc/cgj/Main.java | 8 ++++---- .../java/net/lamgc/cgj/bot/cache/ImageCacheHandler.java | 6 +++--- .../java/net/lamgc/cgj/bot/framework/mirai/MiraiMain.java | 5 +++-- src/main/java/net/lamgc/cgj/pixiv/PixivUgoiraBuilder.java | 4 ++-- src/test/java/net/lamgc/cgj/pixiv/PixivDownloadTest.java | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/lamgc/cgj/Main.java b/src/main/java/net/lamgc/cgj/Main.java index 05d7c3a..39651ac 100644 --- a/src/main/java/net/lamgc/cgj/Main.java +++ b/src/main/java/net/lamgc/cgj/Main.java @@ -19,12 +19,12 @@ import net.lamgc.plps.PixivLoginProxyServer; import net.lamgc.utils.base.runner.Argument; import net.lamgc.utils.base.runner.ArgumentsRunner; import net.lamgc.utils.base.runner.Command; -import org.apache.commons.io.IOUtils; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.CookieStore; import org.apache.http.client.methods.HttpGet; import org.apache.http.util.EntityUtils; +import org.apache.tomcat.util.http.fileupload.util.Streams; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; @@ -127,7 +127,7 @@ public class Main { ZipEntry entry = new ZipEntry(link.substring(link.lastIndexOf("/") + 1)); log.info("正在写入: " + entry.getName()); zos.putNextEntry(entry); - IOUtils.copy(inputStream, zos); + Streams.copy(inputStream, zos, false); zos.flush(); } catch (IOException e) { log.error("写入文件项时发生异常", e); @@ -159,7 +159,7 @@ public class Main { ZipEntry entry = new ZipEntry(link.substring(link.lastIndexOf("/") + 1)); log.info("正在写入: " + entry.getName()); zos.putNextEntry(entry); - IOUtils.copy(inputStream, zos); + Streams.copy(inputStream, zos, false); zos.flush(); log.info("已成功写入 {}", entry.getName()); } catch (IOException e) { @@ -230,7 +230,7 @@ public class Main { entry.setComment(rankInfo.toString()); log.info("正在写入: " + entry.getName()); zos.putNextEntry(entry); - IOUtils.copy(inputStream, zos); + Streams.copy(inputStream, zos, false); zos.flush(); log.info("已成功写入 {}", entry.getName()); } catch (IOException e) { diff --git a/src/main/java/net/lamgc/cgj/bot/cache/ImageCacheHandler.java b/src/main/java/net/lamgc/cgj/bot/cache/ImageCacheHandler.java index 4813c38..c2b092b 100644 --- a/src/main/java/net/lamgc/cgj/bot/cache/ImageCacheHandler.java +++ b/src/main/java/net/lamgc/cgj/bot/cache/ImageCacheHandler.java @@ -5,11 +5,11 @@ import net.lamgc.cgj.bot.cache.exception.HttpRequestException; import net.lamgc.cgj.pixiv.PixivURL; import net.lamgc.cgj.util.URLs; import net.lamgc.utils.event.EventHandler; -import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.tomcat.util.http.fileupload.util.Streams; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,7 +69,7 @@ public class ImageCacheHandler implements EventHandler { log.debug("正在下载...(Content-Length: {}KB)", response.getEntity().getContentLength() / 1024); ByteArrayOutputStream bufferOutputStream = new ByteArrayOutputStream(); try(FileOutputStream fileOutputStream = new FileOutputStream(storeFile)) { - IOUtils.copy(response.getEntity().getContent(), bufferOutputStream); + Streams.copy(response.getEntity().getContent(), bufferOutputStream, false); ByteArrayInputStream bufferInputStream = new ByteArrayInputStream(bufferOutputStream.toByteArray()); CacheStoreCentral.ImageChecksum imageChecksum = CacheStoreCentral.ImageChecksum .buildImageChecksumFromStream( @@ -79,7 +79,7 @@ public class ImageCacheHandler implements EventHandler { bufferInputStream ); bufferInputStream.reset(); - IOUtils.copy(bufferInputStream, fileOutputStream); + Streams.copy(bufferInputStream, fileOutputStream, false); CacheStoreCentral.setImageChecksum(imageChecksum); } catch (IOException e) { log.error("下载图片时发生异常", e); diff --git a/src/main/java/net/lamgc/cgj/bot/framework/mirai/MiraiMain.java b/src/main/java/net/lamgc/cgj/bot/framework/mirai/MiraiMain.java index a97c36e..0ebe822 100644 --- a/src/main/java/net/lamgc/cgj/bot/framework/mirai/MiraiMain.java +++ b/src/main/java/net/lamgc/cgj/bot/framework/mirai/MiraiMain.java @@ -17,11 +17,11 @@ import net.mamoe.mirai.message.MessageEvent; import net.mamoe.mirai.message.TempMessageEvent; import net.mamoe.mirai.utils.BotConfiguration; import net.mamoe.mirai.utils.Utils; -import org.apache.commons.net.util.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; +import java.util.Base64; import java.util.Properties; public class MiraiMain implements Closeable { @@ -52,7 +52,8 @@ public class MiraiMain implements Closeable { Utils.setDefaultLogger(MiraiToSlf4jLoggerAdapter::new); BotConfiguration configuration = new BotConfiguration(); configuration.setProtocol(BotConfiguration.MiraiProtocol.ANDROID_PAD); - bot = BotFactoryJvm.newBot(Long.parseLong(botProperties.getProperty("bot.qq", "0")), Base64.decodeBase64(botProperties.getProperty("bot.password", "")), configuration); + bot = BotFactoryJvm.newBot(Long.parseLong(botProperties.getProperty("bot.qq", "0")), + Base64.getDecoder().decode(botProperties.getProperty("bot.password", "")), configuration); Events.subscribeAlways(GroupMessageEvent.class, this::executeMessageEvent); Events.subscribeAlways(FriendMessageEvent.class, this::executeMessageEvent); Events.subscribeAlways(TempMessageEvent.class, this::executeMessageEvent); diff --git a/src/main/java/net/lamgc/cgj/pixiv/PixivUgoiraBuilder.java b/src/main/java/net/lamgc/cgj/pixiv/PixivUgoiraBuilder.java index 125b10d..04805fa 100644 --- a/src/main/java/net/lamgc/cgj/pixiv/PixivUgoiraBuilder.java +++ b/src/main/java/net/lamgc/cgj/pixiv/PixivUgoiraBuilder.java @@ -7,11 +7,11 @@ import com.squareup.gifencoder.GifEncoder; import com.squareup.gifencoder.Image; import com.squareup.gifencoder.ImageOptions; import io.netty.handler.codec.http.HttpHeaderNames; -import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.util.EntityUtils; +import org.apache.tomcat.util.http.fileupload.util.Streams; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -126,7 +126,7 @@ public final class PixivUgoiraBuilder { HashMap frameMap = new HashMap<>(frames.size()); while((entry = zipInputStream.getNextEntry()) != null) { log.trace("ZipEntry {} 正在接收...", entry); - IOUtils.copy(zipInputStream, cacheOutputStream); + Streams.copy(zipInputStream, cacheOutputStream, false); frameMap.put(entry.getName(), new ByteArrayInputStream(cacheOutputStream.toByteArray())); log.trace("ZipEntry {} 已接收完成.", entry); cacheOutputStream.reset(); diff --git a/src/test/java/net/lamgc/cgj/pixiv/PixivDownloadTest.java b/src/test/java/net/lamgc/cgj/pixiv/PixivDownloadTest.java index eb37785..cf5d29a 100644 --- a/src/test/java/net/lamgc/cgj/pixiv/PixivDownloadTest.java +++ b/src/test/java/net/lamgc/cgj/pixiv/PixivDownloadTest.java @@ -2,7 +2,6 @@ package net.lamgc.cgj.pixiv; import com.google.gson.Gson; import com.google.gson.JsonObject; -import org.apache.commons.io.IOUtils; import org.apache.http.HttpHost; import org.apache.http.client.CookieStore; import org.apache.http.client.methods.CloseableHttpResponse; @@ -10,6 +9,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; +import org.apache.tomcat.util.http.fileupload.util.Streams; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Ignore; @@ -64,7 +64,7 @@ public class PixivDownloadTest { ZipEntry entry = new ZipEntry(link.substring(link.lastIndexOf("/") + 1)); log.info("正在写入: " + entry.getName()); zos.putNextEntry(entry); - IOUtils.copy(inputStream, zos); + Streams.copy(inputStream, zos, false); zos.flush(); } catch (IOException e) { log.error("写入文件项时发生异常", e); @@ -96,7 +96,7 @@ public class PixivDownloadTest { ZipEntry entry = new ZipEntry(link.substring(link.lastIndexOf("/") + 1)); log.info("正在写入: " + entry.getName()); zos.putNextEntry(entry); - IOUtils.copy(inputStream, zos); + Streams.copy(inputStream, zos, false); zos.flush(); log.info("已成功写入 {}", entry.getName()); } catch (IOException e) { @@ -139,7 +139,7 @@ public class PixivDownloadTest { entry.setComment(rankInfo.toString()); log.info("正在写入: " + entry.getName()); zos.putNextEntry(entry); - IOUtils.copy(inputStream, zos); + Streams.copy(inputStream, zos, false); zos.flush(); log.info("已成功写入 {}", entry.getName()); } catch (IOException e) {