Skip to content

Commit

Permalink
fix performance file stream
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 8, 2024
1 parent 010e40d commit 6cb6a18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 6cb6a18

Please sign in to comment.