Skip to content

Commit 1ee7610

Browse files
committed
Revert
1 parent 5c28e42 commit 1ee7610

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

sentry/src/main/java/io/sentry/util/FileUtils.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package io.sentry.util;
22

33
import java.io.BufferedInputStream;
4+
import java.io.BufferedReader;
45
import java.io.ByteArrayOutputStream;
56
import java.io.File;
67
import java.io.FileInputStream;
78
import java.io.FileReader;
89
import java.io.IOException;
9-
import java.io.Reader;
1010
import org.jetbrains.annotations.ApiStatus;
1111
import org.jetbrains.annotations.Nullable;
1212

@@ -36,8 +36,6 @@ public static boolean deleteRecursively(@Nullable File file) {
3636
return file.delete();
3737
}
3838

39-
private static final ThreadLocal<char[]> sharedBuffer = new ThreadLocal<>();
40-
4139
/**
4240
* Reads the content of a File into a String. If the file does not exist or is not a file, null is
4341
* returned. Do not use with large files, as the String is kept in memory!
@@ -51,21 +49,19 @@ public static boolean deleteRecursively(@Nullable File file) {
5149
if (file == null || !file.exists() || !file.isFile() || !file.canRead()) {
5250
return null;
5351
}
52+
StringBuilder contentBuilder = new StringBuilder();
53+
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
5454

55-
try (Reader fr = new FileReader(file)) {
56-
StringBuilder sb = new StringBuilder();
57-
char[] buffer = sharedBuffer.get();
58-
if (buffer == null) {
59-
buffer = new char[8192];
60-
sharedBuffer.set(buffer);
55+
String line;
56+
// The first line doesn't need the leading \n
57+
if ((line = br.readLine()) != null) {
58+
contentBuilder.append(line);
6159
}
62-
63-
int len;
64-
while ((len = fr.read(buffer)) != -1) {
65-
sb.append(buffer, 0, len);
60+
while ((line = br.readLine()) != null) {
61+
contentBuilder.append("\n").append(line);
6662
}
67-
return sb.toString();
6863
}
64+
return contentBuilder.toString();
6965
}
7066

7167
/**

0 commit comments

Comments
 (0)