PktUtils.java

net.minecraft.server.rcon.PktUtils

信息

  • 全限定名:net.minecraft.server.rcon.PktUtils
  • 类型:public class
  • 包:net.minecraft.server.rcon
  • 源码路径:src/main/java/net/minecraft/server/rcon/PktUtils.java
  • 起始行号:L5
  • 职责:

    TODO

字段/常量

  • MAX_PACKET_SIZE

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L6
    • 说明:

      TODO

  • HEX_CHAR

    • 类型: char[]
    • 修饰符: public static final
    • 源码定位: L7
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

public static String stringFromByteArray(byte[] b, int offset, int length) @ L9

  • 方法名:stringFromByteArray
  • 源码定位:L9
  • 返回类型:String
  • 修饰符:public static

参数:

  • b: byte[]
  • offset: int
  • length: int

说明:

TODO

public static int intFromByteArray(byte[] b, int offset) @ L20

  • 方法名:intFromByteArray
  • 源码定位:L20
  • 返回类型:int
  • 修饰符:public static

参数:

  • b: byte[]
  • offset: int

说明:

TODO

public static int intFromByteArray(byte[] b, int offset, int length) @ L24

  • 方法名:intFromByteArray
  • 源码定位:L24
  • 返回类型:int
  • 修饰符:public static

参数:

  • b: byte[]
  • offset: int
  • length: int

说明:

TODO

public static int intFromNetworkByteArray(byte[] b, int offset, int length) @ L28

  • 方法名:intFromNetworkByteArray
  • 源码定位:L28
  • 返回类型:int
  • 修饰符:public static

参数:

  • b: byte[]
  • offset: int
  • length: int

说明:

TODO

public static String toHexString(byte b) @ L32

  • 方法名:toHexString
  • 源码定位:L32
  • 返回类型:String
  • 修饰符:public static

参数:

  • b: byte

说明:

TODO

代码

public class PktUtils {
    public static final int MAX_PACKET_SIZE = 1460;
    public static final char[] HEX_CHAR = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
 
    public static String stringFromByteArray(byte[] b, int offset, int length) {
        int max = length - 1;
        int i = offset > max ? max : offset;
 
        while (0 != b[i] && i < max) {
            i++;
        }
 
        return new String(b, offset, i - offset, StandardCharsets.UTF_8);
    }
 
    public static int intFromByteArray(byte[] b, int offset) {
        return intFromByteArray(b, offset, b.length);
    }
 
    public static int intFromByteArray(byte[] b, int offset, int length) {
        return 0 > length - offset - 4 ? 0 : b[offset + 3] << 24 | (b[offset + 2] & 0xFF) << 16 | (b[offset + 1] & 0xFF) << 8 | b[offset] & 0xFF;
    }
 
    public static int intFromNetworkByteArray(byte[] b, int offset, int length) {
        return 0 > length - offset - 4 ? 0 : b[offset] << 24 | (b[offset + 1] & 0xFF) << 16 | (b[offset + 2] & 0xFF) << 8 | b[offset + 3] & 0xFF;
    }
 
    public static String toHexString(byte b) {
        return "" + HEX_CHAR[(b & 240) >>> 4] + HEX_CHAR[b & 15];
    }
}

引用的其他类