File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
src/main/java/com/worksap/nlp/sudachi Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 29
29
import java .lang .reflect .InvocationTargetException ;
30
30
import java .net .URL ;
31
31
import java .nio .ByteBuffer ;
32
+ import java .nio .ByteOrder ;
32
33
import java .nio .file .Files ;
33
34
import java .nio .file .Path ;
34
35
import java .util .*;
@@ -866,7 +867,8 @@ public InputStream asInputStream() throws IOException {
866
867
/**
867
868
* Get view of this resource as a ByteBuffer. When it is possible, the data will
868
869
* be memory mapped, if it is not possible, it will be fully read into the
869
- * memory. Will not work for files more than 2^31 bytes (2 GB) in size.
870
+ * memory. Will not work for files more than 2^31 bytes (2 GB) in size. The
871
+ * ByteOrder is set to little endian.
870
872
*
871
873
* @return ByteBuffer containing the whole contents of the file
872
874
* @throws IOException
Original file line number Diff line number Diff line change 21
21
import java .io .InputStreamReader ;
22
22
import java .net .URL ;
23
23
import java .nio .ByteBuffer ;
24
+ import java .nio .ByteOrder ;
24
25
import java .nio .CharBuffer ;
25
26
import java .nio .charset .StandardCharsets ;
26
27
import java .nio .file .Files ;
@@ -56,12 +57,20 @@ public static String readFully(InputStream stream) throws IOException {
56
57
}
57
58
58
59
public static ByteBuffer readAllBytes (URL url ) throws IOException {
60
+ return readAllBytes (url , ByteOrder .LITTLE_ENDIAN );
61
+ }
62
+
63
+ public static ByteBuffer readAllBytes (URL url , ByteOrder order ) throws IOException {
59
64
try (InputStream is = url .openStream ()) {
60
- return readAllBytes (is );
65
+ return readAllBytes (is , order );
61
66
}
62
67
}
63
68
64
69
public static ByteBuffer readAllBytes (InputStream inputStream ) throws IOException {
70
+ return readAllBytes (inputStream , ByteOrder .LITTLE_ENDIAN );
71
+ }
72
+
73
+ public static ByteBuffer readAllBytes (InputStream inputStream , ByteOrder order ) throws IOException {
65
74
byte [] buffer = new byte [inputStream .available () + 1024 ];
66
75
int offset = 0 ;
67
76
@@ -78,6 +87,7 @@ public static ByteBuffer readAllBytes(InputStream inputStream) throws IOExceptio
78
87
}
79
88
ByteBuffer bbuf = ByteBuffer .wrap (buffer );
80
89
bbuf .limit (offset );
90
+ bbuf .order (order );
81
91
return bbuf ;
82
92
}
83
93
}
You can’t perform that action at this time.
0 commit comments