2
2
3
3
import io .sentry .protocol .ViewHierarchy ;
4
4
import java .io .File ;
5
+ import java .util .concurrent .Callable ;
5
6
import org .jetbrains .annotations .NotNull ;
6
7
import org .jetbrains .annotations .Nullable ;
7
8
@@ -10,6 +11,7 @@ public final class Attachment {
10
11
11
12
private @ Nullable byte [] bytes ;
12
13
private final @ Nullable JsonSerializable serializable ;
14
+ private final @ Nullable Callable <byte []> byteProvider ;
13
15
private @ Nullable String pathname ;
14
16
private final @ NotNull String filename ;
15
17
private final @ Nullable String contentType ;
@@ -84,6 +86,7 @@ public Attachment(
84
86
final boolean addToTransactions ) {
85
87
this .bytes = bytes ;
86
88
this .serializable = null ;
89
+ this .byteProvider = null ;
87
90
this .filename = filename ;
88
91
this .contentType = contentType ;
89
92
this .attachmentType = attachmentType ;
@@ -109,6 +112,33 @@ public Attachment(
109
112
final boolean addToTransactions ) {
110
113
this .bytes = null ;
111
114
this .serializable = serializable ;
115
+ this .byteProvider = null ;
116
+ this .filename = filename ;
117
+ this .contentType = contentType ;
118
+ this .attachmentType = attachmentType ;
119
+ this .addToTransactions = addToTransactions ;
120
+ }
121
+
122
+ /**
123
+ * Initializes an Attachment with bytes factory, a filename, a content type, and
124
+ * addToTransactions.
125
+ *
126
+ * @param byteProvider A provider holding the attachment payload
127
+ * @param filename The name of the attachment to display in Sentry.
128
+ * @param contentType The content type of the attachment.
129
+ * @param attachmentType the attachment type.
130
+ * @param addToTransactions <code>true</code> if the SDK should add this attachment to every
131
+ * {@link ITransaction} or set to <code>false</code> if it shouldn't.
132
+ */
133
+ public Attachment (
134
+ final @ NotNull Callable <byte []> byteProvider ,
135
+ final @ NotNull String filename ,
136
+ final @ Nullable String contentType ,
137
+ final @ Nullable String attachmentType ,
138
+ final boolean addToTransactions ) {
139
+ this .bytes = null ;
140
+ this .serializable = null ;
141
+ this .byteProvider = byteProvider ;
112
142
this .filename = filename ;
113
143
this .contentType = contentType ;
114
144
this .attachmentType = attachmentType ;
@@ -186,6 +216,7 @@ public Attachment(
186
216
this .pathname = pathname ;
187
217
this .filename = filename ;
188
218
this .serializable = null ;
219
+ this .byteProvider = null ;
189
220
this .contentType = contentType ;
190
221
this .attachmentType = attachmentType ;
191
222
this .addToTransactions = addToTransactions ;
@@ -212,6 +243,7 @@ public Attachment(
212
243
this .pathname = pathname ;
213
244
this .filename = filename ;
214
245
this .serializable = null ;
246
+ this .byteProvider = null ;
215
247
this .contentType = contentType ;
216
248
this .addToTransactions = addToTransactions ;
217
249
}
@@ -240,6 +272,7 @@ public Attachment(
240
272
this .pathname = pathname ;
241
273
this .filename = filename ;
242
274
this .serializable = null ;
275
+ this .byteProvider = null ;
243
276
this .contentType = contentType ;
244
277
this .addToTransactions = addToTransactions ;
245
278
this .attachmentType = attachmentType ;
@@ -310,16 +343,35 @@ boolean isAddToTransactions() {
310
343
return attachmentType ;
311
344
}
312
345
346
+ public @ Nullable Callable <byte []> getByteProvider () {
347
+ return byteProvider ;
348
+ }
349
+
313
350
/**
314
351
* Creates a new Screenshot Attachment
315
352
*
316
- * @param screenshotBytes the array bytes
353
+ * @param screenshotBytes the array bytes of the PNG screenshot
317
354
* @return the Attachment
318
355
*/
319
356
public static @ NotNull Attachment fromScreenshot (final byte [] screenshotBytes ) {
320
357
return new Attachment (screenshotBytes , "screenshot.png" , "image/png" , false );
321
358
}
322
359
360
+ /**
361
+ * Creates a new Screenshot Attachment
362
+ *
363
+ * @param provider the mechanism providing the screenshot payload
364
+ * @return the Attachment
365
+ */
366
+ public static @ NotNull Attachment fromByteProvider (
367
+ final @ NotNull Callable <byte []> provider ,
368
+ final @ NotNull String filename ,
369
+ final @ Nullable String contentType ,
370
+ final boolean addToTransactions ) {
371
+ return new Attachment (
372
+ provider , filename , contentType , DEFAULT_ATTACHMENT_TYPE , addToTransactions );
373
+ }
374
+
323
375
/**
324
376
* Creates a new View Hierarchy Attachment
325
377
*
0 commit comments