2626import org .junit .Test ;
2727import org .junit .rules .TemporaryFolder ;
2828
29- import java .io .*;
29+ import java .io .ByteArrayInputStream ;
30+ import java .io .DataInput ;
31+ import java .io .DataInputStream ;
32+ import java .io .File ;
33+ import java .io .FileOutputStream ;
3034import java .math .BigInteger ;
3135import java .nio .ByteBuffer ;
3236import java .nio .ByteOrder ;
37+ import java .nio .CharBuffer ;
38+ import java .nio .IntBuffer ;
3339import java .nio .charset .Charset ;
3440import java .nio .charset .StandardCharsets ;
3541import java .text .Normalizer ;
@@ -188,6 +194,13 @@ public void fromIntArray() {
188194 assertArrayEquals (new byte []{0 , 11 , 30 , 55 , 0 , 0 , 35 , 53 , 0 , 0 , 0 , 0 , 0 , 0 , 56 , -70 }, Bytes .from (728631 , 9013 , 0 , 14522 ).array ());
189195 }
190196
197+ @ Test
198+ public void fromIntBuffer () {
199+ assertArrayEquals (new byte []{0 , 0 , 0 , 1 , 0 , 0 , 0 , 2 }, Bytes .from (IntBuffer .wrap (new int []{1 , 2 })).array ());
200+ assertArrayEquals (Bytes .from (Bytes .from (871193 ), Bytes .from (6761 ), Bytes .from (-917656 )).array (), Bytes .from (IntBuffer .wrap (new int []{871193 , 6761 , -917656 })).array ());
201+ assertArrayEquals (Bytes .empty ().array (), Bytes .from (IntBuffer .allocate (0 )).array ());
202+ }
203+
191204 @ Test
192205 public void fromLong () {
193206 long test = 172283719283L ;
@@ -281,6 +294,7 @@ public void fromCharArray() {
281294 assertArrayEquals (String .valueOf (s1 .toCharArray ()).getBytes (StandardCharsets .ISO_8859_1 ), Bytes .from (s1 .toCharArray (), StandardCharsets .ISO_8859_1 ).array ());
282295 assertArrayEquals (String .valueOf (s1 .toCharArray ()).getBytes (StandardCharsets .UTF_16 ), Bytes .from (s1 .toCharArray (), StandardCharsets .UTF_16 ).array ());
283296 assertArrayEquals (String .valueOf (s1 .toCharArray ()).getBytes (StandardCharsets .UTF_8 ), Bytes .from (s1 .toCharArray (), StandardCharsets .UTF_8 ).array ());
297+ assertArrayEquals (Bytes .empty ().array (), Bytes .from (CharBuffer .allocate (0 )).array ());
284298 }
285299
286300 @ Test
@@ -306,8 +320,10 @@ private void checkString(String string, Charset charset) {
306320 private void checkCharArray (String s ) {
307321 Bytes b1 = Bytes .from (s .toCharArray ());
308322 Bytes b2 = Bytes .from (s .toCharArray (), StandardCharsets .UTF_8 );
323+ Bytes b3 = Bytes .from (CharBuffer .wrap (s .toCharArray ()));
309324 assertArrayEquals (String .valueOf (s .toCharArray ()).getBytes (StandardCharsets .UTF_8 ), b1 .array ());
310325 assertArrayEquals (String .valueOf (s .toCharArray ()).getBytes (StandardCharsets .UTF_8 ), b2 .array ());
326+ assertArrayEquals (String .valueOf (s .toCharArray ()).getBytes (StandardCharsets .UTF_8 ), b3 .array ());
311327 }
312328
313329 @ Test
0 commit comments