PktUtils .java

net.minecraft.server.rcon.PktUtils (class, 36 lines): members: intFromNetworkByteArray, stringFromByteArray, intFromByteArray, MAX_PACKET_SIZE, HEX_CHAR.

net.minecraft.server.rconclass36 linesserver1.2 KB

API Surface (5)

String stringFromByteArray(final byte[] b, final int offset, final int length)
int intFromByteArray(final byte[] b, final int offset)
int intFromByteArray(final byte[] b, final int offset, final int length)
int intFromNetworkByteArray(final byte[] b, final int offset, final int length)
String toHexString(final byte b)

Fields & Constants (2)

MAX_PACKET_SIZE
HEX_CHAR

Full Source

PktUtils.java36 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.rcon;
2
3
import java.nio.charset.StandardCharsets;
4
5
public class PktUtils {
6
	public static final int MAX_PACKET_SIZE = 1460;
7
	public static final char[] HEX_CHAR = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
8
9
	public static String stringFromByteArray(final byte[] b, final int offset, final int length) {
10
		int max = length - 1;
11
		int i = offset > max ? max : offset;
12
13
		while (0 != b[i] && i < max) {
14
			i++;
15
		}
16
17
		return new String(b, offset, i - offset, StandardCharsets.UTF_8);
18
	}
19
20
	public static int intFromByteArray(final byte[] b, final int offset) {
21
		return intFromByteArray(b, offset, b.length);
22
	}
23
24
	public static int intFromByteArray(final byte[] b, final int offset, final int length) {
25
		return 0 > length - offset - 4 ? 0 : b[offset + 3] << 24 | (b[offset + 2] & 0xFF) << 16 | (b[offset + 1] & 0xFF) << 8 | b[offset] & 0xFF;
26
	}
27
28
	public static int intFromNetworkByteArray(final byte[] b, final int offset, final int length) {
29
		return 0 > length - offset - 4 ? 0 : b[offset] << 24 | (b[offset + 1] & 0xFF) << 16 | (b[offset + 2] & 0xFF) << 8 | b[offset + 3] & 0xFF;
30
	}
31
32
	public static String toHexString(final byte b) {
33
		return "" + HEX_CHAR[(b & 240) >>> 4] + HEX_CHAR[b & 15];
34
	}
35
}
36

Decompiled Minecraft 26.3 source of PktUtils (net/minecraft/server/rcon/PktUtils.java) with Mojang official mappings, stored verbatim on the site.