|
1 | 1 | package io.sentry; |
2 | 2 |
|
| 3 | +import static io.sentry.util.FileUtils.readBytesFromFile; |
3 | 4 | import static io.sentry.vendor.Base64.NO_PADDING; |
4 | 5 | import static io.sentry.vendor.Base64.NO_WRAP; |
5 | 6 |
|
|
9 | 10 | import io.sentry.util.JsonSerializationUtils; |
10 | 11 | import io.sentry.util.Objects; |
11 | 12 | import io.sentry.vendor.Base64; |
12 | | -import java.io.BufferedInputStream; |
13 | 13 | import java.io.BufferedReader; |
14 | 14 | import java.io.BufferedWriter; |
15 | 15 | import java.io.ByteArrayInputStream; |
16 | 16 | import java.io.ByteArrayOutputStream; |
17 | 17 | import java.io.File; |
18 | | -import java.io.FileInputStream; |
19 | 18 | import java.io.IOException; |
20 | 19 | import java.io.InputStreamReader; |
21 | 20 | import java.io.OutputStreamWriter; |
@@ -304,48 +303,6 @@ private static void ensureAttachmentSizeLimit( |
304 | 303 | return new SentryEnvelopeItem(itemHeader, () -> cachedItem.getBytes()); |
305 | 304 | } |
306 | 305 |
|
307 | | - private static byte[] readBytesFromFile(String pathname, long maxFileLength) |
308 | | - throws SentryEnvelopeException { |
309 | | - try { |
310 | | - File file = new File(pathname); |
311 | | - |
312 | | - if (!file.isFile()) { |
313 | | - throw new SentryEnvelopeException( |
314 | | - String.format( |
315 | | - "Reading the item %s failed, because the file located at the path is not a file.", |
316 | | - pathname)); |
317 | | - } |
318 | | - |
319 | | - if (!file.canRead()) { |
320 | | - throw new SentryEnvelopeException( |
321 | | - String.format("Reading the item %s failed, because can't read the file.", pathname)); |
322 | | - } |
323 | | - |
324 | | - if (file.length() > maxFileLength) { |
325 | | - throw new SentryEnvelopeException( |
326 | | - String.format( |
327 | | - "Dropping item, because its size located at '%s' with %d bytes is bigger " |
328 | | - + "than the maximum allowed size of %d bytes.", |
329 | | - pathname, file.length(), maxFileLength)); |
330 | | - } |
331 | | - |
332 | | - try (FileInputStream fileInputStream = new FileInputStream(pathname); |
333 | | - BufferedInputStream inputStream = new BufferedInputStream(fileInputStream); |
334 | | - ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { |
335 | | - byte[] bytes = new byte[1024]; |
336 | | - int length; |
337 | | - int offset = 0; |
338 | | - while ((length = inputStream.read(bytes)) != -1) { |
339 | | - outputStream.write(bytes, offset, length); |
340 | | - } |
341 | | - return outputStream.toByteArray(); |
342 | | - } |
343 | | - } catch (IOException | SecurityException exception) { |
344 | | - throw new SentryEnvelopeException( |
345 | | - String.format("Reading the item %s failed.\n%s", pathname, exception.getMessage())); |
346 | | - } |
347 | | - } |
348 | | - |
349 | 306 | public static @NotNull SentryEnvelopeItem fromClientReport( |
350 | 307 | final @NotNull ISerializer serializer, final @NotNull ClientReport clientReport) |
351 | 308 | throws IOException { |
|
0 commit comments