@@ -129,6 +129,18 @@ public static Bytes wrap(byte[] array, ByteOrder byteOrder) {
129129 return new Bytes (array , byteOrder );
130130 }
131131
132+ /**
133+ * Creates a new instance from given collections of single bytes.
134+ * This will create a copy of given bytes and will not directly use given bytes or byte array.
135+ *
136+ * @param byteArrayToCopy must not be null and will not be used directly, but a copy
137+ * @return new instance
138+ */
139+ public static Bytes from (byte [] byteArrayToCopy ) {
140+ Objects .requireNonNull (byteArrayToCopy , "must at least pass a single byte" );
141+ return wrap (Arrays .copyOf (byteArrayToCopy , byteArrayToCopy .length ));
142+ }
143+
132144 /**
133145 * Creates a new instance from a slice of given array
134146 *
@@ -181,25 +193,23 @@ public static Bytes from(Collection<Byte> bytesCollection) {
181193 }
182194
183195 /**
184- * Creates a new single array element array instance from given byte
196+ * Creates a new instance from given object byte array. Will copy and unbox every element.
185197 *
186- * @param singleByte to create from
198+ * @param objectArray to create from
187199 * @return new instance
188200 */
189- public static Bytes from (byte singleByte ) {
190- return wrap (new byte []{ singleByte } );
201+ public static Bytes from (Byte [] objectArray ) {
202+ return wrap (Util . toPrimitiveArray ( objectArray ) );
191203 }
192204
193205 /**
194- * Creates a new instance from given collections of single bytes.
195- * This will create a copy of given bytes and will not directly use given bytes or byte array.
206+ * Creates a new single array element array instance from given byte
196207 *
197- * @param byteArrayToCopy must not be null and will not be used directly, but a copy
208+ * @param singleByte to create from
198209 * @return new instance
199210 */
200- public static Bytes from (byte [] byteArrayToCopy ) {
201- Objects .requireNonNull (byteArrayToCopy , "must at least pass a single byte" );
202- return wrap (Arrays .copyOf (byteArrayToCopy , byteArrayToCopy .length ));
211+ public static Bytes from (byte singleByte ) {
212+ return wrap (new byte []{singleByte });
203213 }
204214
205215 /**
@@ -244,6 +254,17 @@ public static Bytes from(int integer4byte) {
244254 return wrap (ByteBuffer .allocate (4 ).putInt (integer4byte ).array ());
245255 }
246256
257+ /**
258+ * Creates a new instance from given 4 byte integer array.
259+ *
260+ * @param intArray to create from
261+ * @return new instance
262+ */
263+ public static Bytes from (int ... intArray ) {
264+ Objects .requireNonNull (intArray , "must provide at least a single int" );
265+ return wrap (Util .toByteArray (intArray ));
266+ }
267+
247268 /**
248269 * Creates a new instance from given 8 byte long.
249270 *
@@ -254,6 +275,17 @@ public static Bytes from(long long8byte) {
254275 return wrap (ByteBuffer .allocate (8 ).putLong (long8byte ).array ());
255276 }
256277
278+ /**
279+ * Creates a new instance from given 8 byte long array.
280+ *
281+ * @param longArray to create from
282+ * @return new instance
283+ */
284+ public static Bytes from (long ... longArray ) {
285+ Objects .requireNonNull (longArray , "must provide at least a single long" );
286+ return wrap (Util .toByteArray (longArray ));
287+ }
288+
257289 /**
258290 * Creates a new instance from given ByteBuffer.
259291 * Will use the same backing byte array and honour the buffer's byte order.
@@ -677,7 +709,7 @@ public Bytes copy(int offset, int length) {
677709 }
678710
679711 /**
680- * Reverses the internal byte array.
712+ * Reverses the internal bytes in the array (not bits in each byte)
681713 * <p>
682714 * See the considerations about possible in-place operation in {@link #transform(BytesTransformer)}.
683715 *
@@ -1359,6 +1391,9 @@ public String toString() {
13591391 return length () + " bytes " + preview ;
13601392 }
13611393
1394+ /**
1395+ * Internal factory for {@link Bytes} instances
1396+ */
13621397 private static class Factory implements BytesFactory {
13631398 @ Override
13641399 public Bytes wrap (byte [] array , ByteOrder byteOrder ) {
0 commit comments