From 319e82391bfb8822fd75684f17ae28b26c1e3b0c Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:49:40 +0200 Subject: Initial commit --- src/com/encrox/twitchbot/client/Utils.java | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 src/com/encrox/twitchbot/client/Utils.java (limited to 'src/com/encrox/twitchbot/client/Utils.java') 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