📄 bytereader.java
字号:
/* * JRemCntl - Copyright (C) 2007 Filippo Di Vattimo <fildiv@gmail.com> * See COPYING */package fildiv.jremcntl.common.proto;import java.io.UnsupportedEncodingException;import fildiv.jremcntl.common.core.JRemRuntimeException;public class ByteReader { private byte[] bytes; private int offset; public ByteReader() { } public ByteReader(byte[] bytes) { setBytes(bytes); } public void setBytes(byte[] bytes) { if (bytes == null) throw new IllegalArgumentException(); this.bytes = bytes; offset = 0; } public byte[] getBytes() { return bytes; } protected void safeOffsetAdd(int offset) { this.offset += offset; if(this.offset > bytes.length) throw new IndexOutOfBoundsException(); } public String getString() { int size = getInt(); String str = ""; try { str = new String(bytes, offset, size, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new JRemRuntimeException(e); } safeOffsetAdd(size); return str; } public int getInt() { int value = (((bytes[offset] & 0xff) << 24) | ((bytes[offset + 1] & 0xff) << 16) | ((bytes[offset + 2] & 0xff) << 8) | (bytes[offset + 3] & 0xff)); safeOffsetAdd(JRemAbstractProtocol.LENGHT_INT); return value; } public short getShort() { short value = (short) (((bytes[offset + 0] & 0xff) << 8) | (bytes[offset + 1] & 0xff)); safeOffsetAdd(JRemAbstractProtocol.LENGHT_SHORT); return value; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -