1package com.runehive.fs.util;
3import java.io.ByteArrayOutputStream;
4import java.nio.ByteBuffer;
34 return (buffer.getShort() & 0xFFFF) << 8 | buffer.get() & 0xFF;
58 int var1 = buffer.position();
60 buffer.position(buffer.position() + 1);
61 byte b = buffer.get(buffer.position() - 1);
65 int var2 =buffer.position() - var1 - 1;
70 char[] var3 =
new char[var2];
73 for(
int var5 = 0; var5 < var2; ++var5) {
74 int var6 = buffer.get(var5 + var1) & 255;
76 if (var6 >= 128 && var6 < 160) {
85 var3[var4++] = (char)var6;
89 return new String(var3, 0, var4);
92 public static final char[]
cp1252AsciiExtension =
new char[]{
'€',
'\u0000',
'‚',
'ƒ',
'„',
'…',
'†',
'‡',
'ˆ',
'‰',
'Š',
'‹',
'Œ',
'\u0000',
'Ž',
'\u0000',
'\u0000',
'‘',
'’',
'“',
'”',
'•',
'–',
'—',
'˜',
'™',
'š',
'›',
'œ',
'\u0000',
'ž',
'Ÿ'};
102 public static byte[]
get(ByteBuffer buffer,
int length) {
103 byte[] data =
new byte[length];
119 public static String
getString(ByteBuffer buffer,
char terminator) {
120 ByteArrayOutputStream os =
new ByteArrayOutputStream();
122 int read = buffer.get() & 0xFF;
123 if (read == terminator) {
128 return new String(os.toByteArray());
138 public static int getSmart(
final ByteBuffer buffer) {
139 final int position = buffer.position();
140 if (position >= buffer.limit()) {
143 final int peek = buffer.get(position) & 0xFF;
145 return buffer.get() & 0xFF;
147 return (buffer.getShort() & 0xFFFF) - 32768;
156 public static void putSmart(ByteBuffer buffer,
int value) {
158 buffer.put((
byte) value);
161 buffer.put((
byte) (value >> 8));
162 buffer.put((
byte) value);
static String getString(ByteBuffer buffer, char terminator)
Gets a String from the specified ByteBuffer, the ByteBuffer will continue to get until the specified ...
static final char J_STRING_TERMINATOR
The terminator used within the client, equal to 10 and otherwise know as the Jagex String terminator.
static String readStringCp1252NullTerminated(ByteBuffer buffer)
static void putSmart(ByteBuffer buffer, int value)
Puts a 'smart' (either a byte or short.
static final char[] cp1252AsciiExtension
ByteBufferUtil()
Sole private constructor to discourage instantiation of this class.
static int getMedium(ByteBuffer buffer)
Gets a 24-bit medium integer from the specified ByteBuffer, this method does not mark the ByteBuffers...
static String getString(ByteBuffer buffer)
Gets a null-terminated String from the specified ByteBuffer.
static final char DEFAULT_STRING_TERMINATOR
The default String terminator, equal to 0 and otherwise known as the 'null' String terminator.
static int getSmart(final ByteBuffer buffer)
Reads a 'smart' (either a byte or short depending on the value) from the specified buffer.
static String getJString(ByteBuffer buffer)
Gets a newline-terminated String from the specified ByteBuffer.
static String decodeStringCp1252(ByteBuffer buffer, int var1, int var2)