From 6cb6a18f5dd64540bf1614ed063e55e3baa6fade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A1udio=20Gomes?= Date: Fri, 8 Mar 2024 11:12:18 -0300 Subject: [PATCH] fix performance file stream --- .../pirilampo/core/compilers/Compiler.java | 16 ++++++++++------ .../pirilampo/core/parsers/PdfImageProvider.java | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/Compiler.java b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/Compiler.java index 344d269..2ee00eb 100644 --- a/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/Compiler.java +++ b/core/src/main/java/com/github/clagomess/pirilampo/core/compilers/Compiler.java @@ -114,9 +114,11 @@ protected void writeResourceToOut(String resource, PrintWriter out) throws IOExc FileReader fr = new FileReader(url.getFile()); BufferedReader br = new BufferedReader(fr) ){ - int value; - while ((value = br.read()) != -1) { - out.print((char) value); + char[] buffer = new char[1024 * 4]; + int n; + + while ((n = br.read(buffer)) != -1) { + out.write(buffer, 0, n); } } } @@ -127,9 +129,11 @@ protected void writeFileToOut(File file, PrintWriter out) throws IOException { BOMInputStream bis = new BOMInputStream(fis); BufferedReader br = new BufferedReader(new InputStreamReader(bis, StandardCharsets.UTF_8)); ){ - int value; - while ((value = br.read()) != -1) { - out.print((char) value); + char[] buffer = new char[1024 * 4]; + int n; + + while ((n = br.read(buffer)) != -1) { + out.write(buffer, 0, n); } } } diff --git a/core/src/main/java/com/github/clagomess/pirilampo/core/parsers/PdfImageProvider.java b/core/src/main/java/com/github/clagomess/pirilampo/core/parsers/PdfImageProvider.java index e9336f4..72dda51 100644 --- a/core/src/main/java/com/github/clagomess/pirilampo/core/parsers/PdfImageProvider.java +++ b/core/src/main/java/com/github/clagomess/pirilampo/core/parsers/PdfImageProvider.java @@ -71,9 +71,11 @@ protected File downloadImageToCache(String src){ InputStream in = new BufferedInputStream(new URL(src).openStream()); FileOutputStream fos = new FileOutputStream(cacheImage); ) { - int value; - while ((value = in.read()) != -1) { - fos.write(value); + byte[] buffer = new byte[1024 * 4]; + int n; + + while ((n = in.read(buffer)) != -1) { + fos.write(buffer, 0, n); } }