File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
yubico-util/src/main/java/com/yubico/internal/util Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,37 @@ public static byte[] copy(byte[] bytes) {
36
36
return Arrays .copyOf (bytes , bytes .length );
37
37
}
38
38
39
+ /**
40
+ * Copy <code>src</code> into <code>dest</code> beginning at the offset <code>destFrom</code>,
41
+ * then return the modified <code>dest</code>.
42
+ */
43
+ public static byte [] copyInto (byte [] src , byte [] dest , int destFrom ) {
44
+ if (dest .length - destFrom < src .length ) {
45
+ throw new IllegalArgumentException ("Source array will not fit in destination array" );
46
+ }
47
+ if (destFrom < 0 ) {
48
+ throw new IllegalArgumentException ("Invalid destination range" );
49
+ }
50
+
51
+ for (int i = 0 ; i < src .length ; ++i ) {
52
+ dest [destFrom + i ] = src [i ];
53
+ }
54
+
55
+ return dest ;
56
+ }
57
+
58
+ /** Return a new array containing the concatenation of the argument <code>arrays</code>. */
59
+ public static byte [] concat (byte []... arrays ) {
60
+ final int len = Arrays .stream (arrays ).map (a -> a .length ).reduce (0 , Integer ::sum );
61
+ byte [] result = new byte [len ];
62
+ int i = 0 ;
63
+ for (byte [] src : arrays ) {
64
+ copyInto (src , result , i );
65
+ i += src .length ;
66
+ }
67
+ return result ;
68
+ }
69
+
39
70
/**
40
71
* @param bytes Bytes to encode
41
72
*/
You can’t perform that action at this time.
0 commit comments