File tree 2 files changed +21
-0
lines changed
src/main/java/com/networknt/utility
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 54
54
<groupId >org.owasp.encoder</groupId >
55
55
<artifactId >encoder</artifactId >
56
56
</dependency >
57
+ <dependency >
58
+ <groupId >commons-io</groupId >
59
+ <artifactId >commons-io</artifactId >
60
+ </dependency >
57
61
58
62
<dependency >
59
63
<groupId >ch.qos.logback</groupId >
Original file line number Diff line number Diff line change 1
1
package com .networknt .utility ;
2
2
3
+ import org .apache .commons .io .IOUtils ;
3
4
import org .slf4j .Logger ;
4
5
import org .slf4j .LoggerFactory ;
5
6
@@ -238,6 +239,22 @@ public static ByteBuffer toByteBuffer(String s) {
238
239
return buffer ;
239
240
}
240
241
242
+ /**
243
+ * Convert a File into a ByteBuffer
244
+ * @param file File to be converted
245
+ * @return ByteBuffer containing the file
246
+ */
247
+ public static ByteBuffer toByteBuffer (File file ) {
248
+ ByteBuffer buffer = ByteBuffer .allocateDirect ((int ) file .length ());
249
+ try {
250
+ buffer .put (IOUtils .toByteArray (new FileInputStream (file )));
251
+ } catch (IOException e ) {
252
+ logger .error ("Failed to write file to byte array: " + e .getMessage ());
253
+ }
254
+ buffer .flip ();
255
+ return buffer ;
256
+ }
257
+
241
258
/**
242
259
* get temp dir from OS.
243
260
*
You can’t perform that action at this time.
0 commit comments