From 0cf077e73c646d4a2562717a67a41c52d4cb673d Mon Sep 17 00:00:00 2001 From: Yixian Date: Wed, 23 Feb 2022 11:55:35 +0800 Subject: [PATCH] aggregate poster log --- .../core/impls/ClientManagerImpl.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index 80a971ad0..8f672722b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -2705,13 +2705,22 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid HttpRequestResult boardBackgroundResult = new HttpRequestGenerator( url, RequestMethod.GET).execute(); if (boardBackgroundResult.isSuccess()) { - InputStream ins = boardBackgroundResult.getResponseContentStream(); - BufferedImage background = ImageIO.read(ins); - logger.debug("aggregate image size {}x{}", background.getWidth(), background.getHeight()); - IOUtils.closeQuietly(ins); - ImageIO.write(background, "jpeg", ous); - ous.flush(); - IOUtils.closeQuietly(ous); + try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { + InputStream ins = boardBackgroundResult.getResponseContentStream(); + BufferedImage background = ImageIO.read(ins); + IOUtils.closeQuietly(ins); + logger.debug("aggregate image size {}x{}", background.getWidth(), background.getHeight()); + BufferedImage img = new BufferedImage(background.getWidth(), background.getHeight(), BufferedImage.TYPE_3BYTE_BGR); + Graphics g = img.getGraphics(); + g.drawImage(background, 0, 0, null); + g.dispose(); + ImageIO.write(img, "jpeg", bos); + bos.flush(); + byte[] imageBytes = bos.toByteArray(); + logger.debug("aggregate image length {}", imageBytes.length); + ous.write(imageBytes); + IOUtils.closeQuietly(ous); + } } else { logger.error("get aggregate poster file failed:[{}]-{}", boardBackgroundResult.getStatusCode(), boardBackgroundResult.getResponseContentString(), boardBackgroundResult.getException());