File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
main/java/at/favre/lib/bytes
test/java/at/favre/lib/bytes Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -278,8 +278,13 @@ static byte[] readFromStream(InputStream inputStream) {
278278 static byte [] readFromDataInput (DataInput dataInput , int length ) {
279279 ByteArrayOutputStream out = new ByteArrayOutputStream ();
280280 try {
281+ byte [] buf ;
282+ int remaining = length ;
281283 for (int i = 0 ; i < length ; i ++) {
282- out .write (dataInput .readUnsignedByte ());
284+ buf = new byte [Math .min (remaining , BUF_SIZE )];
285+ dataInput .readFully (buf );
286+ out .write (buf );
287+ remaining -= buf .length ;
283288 }
284289 return out .toByteArray ();
285290 } catch (Exception e ) {
Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ public void fromInputStream() throws Exception {
229229 checkInputStream (example_bytes_seven );
230230 checkInputStream (example_bytes_eight );
231231 checkInputStream (example_bytes_sixteen );
232+ checkInputStream (Bytes .random (32 * 987 ).array ());
232233 }
233234
234235 private void checkInputStream (byte [] array ) {
@@ -243,6 +244,7 @@ public void fromDataInput() throws Exception {
243244 checkDataInput (example_bytes_seven );
244245 checkDataInput (example_bytes_eight );
245246 checkDataInput (example_bytes_sixteen );
247+ checkDataInput (Bytes .random (32 * 987 ).array ());
246248 }
247249
248250 private void checkDataInput (byte [] array ) {
@@ -266,7 +268,7 @@ public void fromList() throws Exception {
266268
267269 private void checkList (byte [] array ) {
268270 Bytes bList = Bytes .from (Util .toList (array ));
269- Bytes bLinkedList = Bytes .from (new LinkedList <Byte >(Util .toList (array )));
271+ Bytes bLinkedList = Bytes .from (new LinkedList <>(Util .toList (array )));
270272 assertArrayEquals (array , bList .array ());
271273 assertArrayEquals (array , bLinkedList .array ());
272274 }
You can’t perform that action at this time.
0 commit comments