summaryrefslogtreecommitdiff
path: root/src/com/encrox/twitchbot/client/Utils.java
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2022-04-25 18:49:40 +0200
committerLeonard Kugis <leonard@kug.is>2022-04-25 18:49:40 +0200
commit319e82391bfb8822fd75684f17ae28b26c1e3b0c (patch)
treeccdb434f57e486871f5603d3235003bfe0162161 /src/com/encrox/twitchbot/client/Utils.java
Initial commitHEADmaster
Diffstat (limited to 'src/com/encrox/twitchbot/client/Utils.java')
-rwxr-xr-xsrc/com/encrox/twitchbot/client/Utils.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/com/encrox/twitchbot/client/Utils.java b/src/com/encrox/twitchbot/client/Utils.java
new file mode 100755
index 0000000..dccb4ce
--- /dev/null
+++ b/src/com/encrox/twitchbot/client/Utils.java
@@ -0,0 +1,48 @@
+package com.encrox.twitchbot.client;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+public class Utils {
+
+ public static int ba_to_int(byte[] arr) {
+ return ByteBuffer.wrap(arr).getInt();
+ }
+
+ public static byte[] int_to_ba(int integer) {
+ return ByteBuffer.allocate(4).putInt(integer).array();
+ }
+
+ public static short ba_to_short(byte[] arr) {
+ return ByteBuffer.wrap(arr).getShort();
+ }
+
+ public static byte[] short_to_ba(short s) {
+ return ByteBuffer.allocate(2).putShort(s).array();
+ }
+
+ public static byte[] fill(byte[] arr, int length) {
+ if(length <= arr.length)
+ return arr;
+ byte[] output = new byte[length];
+ for(int i = 0; i<arr.length; i++)
+ output[i] = arr[i];
+ for(int i = arr.length; i<length; i++)
+ output[i] = (byte) 0x00;
+ return output;
+ }
+
+ public static byte[] crop(byte[] arr) {
+ byte[] swap = new byte[arr.length];
+ for(int i = 0; i<swap.length; i++) {
+ if(arr[i] != (byte) 0x00)
+ swap[i] = arr[i];
+ else {
+ arr = Arrays.copyOfRange(swap, 0, i);
+ break;
+ }
+ }
+ return arr;
+ }
+
+}