RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.fs.util.ByteBufferUtil Class Reference

A static-utility class containing extension or helper methods for ByteBuffers. More...

Static Public Member Functions

static String decodeStringCp1252 (ByteBuffer buffer, int var1, int var2)
static byte[] get (ByteBuffer buffer, int length)
 Reads length bytes from the specified ByteBuffer.
static String getJString (ByteBuffer buffer)
 Gets a newline-terminated String from the specified ByteBuffer.
static int getMedium (ByteBuffer buffer)
 Gets a 24-bit medium integer from the specified ByteBuffer, this method does not mark the ByteBuffers current position.
static int getSmart (final ByteBuffer buffer)
 Reads a 'smart' (either a byte or short depending on the value) from the specified buffer.
static String getString (ByteBuffer buffer)
 Gets a null-terminated String from the specified ByteBuffer.
static String getString (ByteBuffer buffer, char terminator)
 Gets a String from the specified ByteBuffer, the ByteBuffer will continue to get until the specified terminator is reached.
static void putSmart (ByteBuffer buffer, int value)
 Puts a 'smart' (either a byte or short.
static String readStringCp1252NullTerminated (ByteBuffer buffer)

Static Public Attributes

static final char[] cp1252AsciiExtension = new char[]{'€', '\u0000', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '\u0000', 'Ž', '\u0000', '\u0000', '‘', '’', '“', '”', '•', '–', '—', '˜', '™', 'š', '›', 'œ', '\u0000', 'ž', 'Ÿ'}
static final char DEFAULT_STRING_TERMINATOR = '\0'
 The default String terminator, equal to 0 and otherwise known as the 'null' String terminator.
static final char J_STRING_TERMINATOR = '\n'
 The terminator used within the client, equal to 10 and otherwise know as the Jagex String terminator.

Private Member Functions

 ByteBufferUtil ()
 Sole private constructor to discourage instantiation of this class.

Detailed Description

A static-utility class containing extension or helper methods for ByteBuffers.

Author
Ryley Kimmel ryley.nosp@m..kim.nosp@m.mel@l.nosp@m.ive..nosp@m.com

Definition at line 12 of file ByteBufferUtil.java.

Constructor & Destructor Documentation

◆ ByteBufferUtil()

com.runehive.fs.util.ByteBufferUtil.ByteBufferUtil ( )
private

Sole private constructor to discourage instantiation of this class.

Definition at line 169 of file ByteBufferUtil.java.

169 {
170 }

Member Function Documentation

◆ decodeStringCp1252()

String com.runehive.fs.util.ByteBufferUtil.decodeStringCp1252 ( ByteBuffer buffer,
int var1,
int var2 )
static

Definition at line 69 of file ByteBufferUtil.java.

69 {
70 char[] var3 = new char[var2];
71 int var4 = 0;
72
73 for(int var5 = 0; var5 < var2; ++var5) {
74 int var6 = buffer.get(var5 + var1) & 255;
75 if (var6 != 0) {
76 if (var6 >= 128 && var6 < 160) {
77 char var7 = cp1252AsciiExtension[var6 - 128];
78 if (var7 == 0) {
79 var7 = '?';
80 }
81
82 var6 = var7;
83 }
84
85 var3[var4++] = (char)var6;
86 }
87 }
88
89 return new String(var3, 0, var4);
90 }

References cp1252AsciiExtension.

Referenced by readStringCp1252NullTerminated().

Here is the caller graph for this function:

◆ get()

byte[] com.runehive.fs.util.ByteBufferUtil.get ( ByteBuffer buffer,
int length )
static

Reads length bytes from the specified ByteBuffer.

Parameters
bufferThe ByteBuffer to read from.
lengthThe amount of bytes to read.
Returns
The read bytes.

Definition at line 102 of file ByteBufferUtil.java.

102 {
103 byte[] data = new byte[length];
104 buffer.get(data);
105 return data;
106 }

◆ getJString()

String com.runehive.fs.util.ByteBufferUtil.getJString ( ByteBuffer buffer)
static

Gets a newline-terminated String from the specified ByteBuffer.

Parameters
bufferThe ByteBuffer to read from.
Returns
The newline-terminated String.

Definition at line 53 of file ByteBufferUtil.java.

53 {
54 return getString(buffer, J_STRING_TERMINATOR);
55 }

References getString(), and J_STRING_TERMINATOR.

Here is the call graph for this function:

◆ getMedium()

int com.runehive.fs.util.ByteBufferUtil.getMedium ( ByteBuffer buffer)
static

Gets a 24-bit medium integer from the specified ByteBuffer, this method does not mark the ByteBuffers current position.

Parameters
bufferThe ByteBuffer to read from.
Returns
The read 24-bit medium integer.

Definition at line 33 of file ByteBufferUtil.java.

33 {
34 return (buffer.getShort() & 0xFFFF) << 8 | buffer.get() & 0xFF;
35 }

Referenced by com.runehive.fs.cache.archive.Archive.decode(), com.runehive.fs.cache.decoder.ObjectDefinitionDecoder.decode(), com.runehive.fs.cache.Index.decode(), and com.runehive.fs.cache.Sector.decode().

Here is the caller graph for this function:

◆ getSmart()

int com.runehive.fs.util.ByteBufferUtil.getSmart ( final ByteBuffer buffer)
static

Reads a 'smart' (either a byte or short depending on the value) from the specified buffer.

Parameters
bufferThe buffer.
Returns
The 'smart'.

Definition at line 138 of file ByteBufferUtil.java.

138 {
139 final int position = buffer.position();
140 if (position >= buffer.limit()) {
141 return 0;
142 }
143 final int peek = buffer.get(position) & 0xFF;
144 if (peek < 128) {
145 return buffer.get() & 0xFF;
146 }
147 return (buffer.getShort() & 0xFFFF) - 32768;
148 }

Referenced by com.runehive.fs.cache.decoder.RegionDecoder.parseGameObject().

Here is the caller graph for this function:

◆ getString() [1/2]

String com.runehive.fs.util.ByteBufferUtil.getString ( ByteBuffer buffer)
static

Gets a null-terminated String from the specified ByteBuffer.

Parameters
bufferThe ByteBuffer to read from.
Returns
The null-terminated String.

Definition at line 43 of file ByteBufferUtil.java.

43 {
44 return getString(buffer, DEFAULT_STRING_TERMINATOR);
45 }

References DEFAULT_STRING_TERMINATOR, and getString().

Referenced by getJString(), and getString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getString() [2/2]

String com.runehive.fs.util.ByteBufferUtil.getString ( ByteBuffer buffer,
char terminator )
static

Gets a String from the specified ByteBuffer, the ByteBuffer will continue to get until the specified terminator is reached.

We use a ByteArrayOutputStream as it is self expanding. We don't want to waste precious time determining a fixed length for the String.

Parameters
bufferThe ByteBuffer to read from.
terminatorThe terminator which denotes when to stop reading.
Returns
The read String.

Definition at line 119 of file ByteBufferUtil.java.

119 {
120 ByteArrayOutputStream os = new ByteArrayOutputStream();
121 for (; ; ) {
122 int read = buffer.get() & 0xFF;
123 if (read == terminator) {
124 break;
125 }
126 os.write(read);
127 }
128 return new String(os.toByteArray());
129 }

◆ putSmart()

void com.runehive.fs.util.ByteBufferUtil.putSmart ( ByteBuffer buffer,
int value )
static

Puts a 'smart' (either a byte or short.

Parameters
bufferThe buffer.
valueThe value to write.

Definition at line 156 of file ByteBufferUtil.java.

156 {
157 if (value < 128) {
158 buffer.put((byte) value);
159 } else {
160 value += 32768;
161 buffer.put((byte) (value >> 8));
162 buffer.put((byte) value);
163 }
164 }

◆ readStringCp1252NullTerminated()

String com.runehive.fs.util.ByteBufferUtil.readStringCp1252NullTerminated ( ByteBuffer buffer)
static

Definition at line 57 of file ByteBufferUtil.java.

57 {
58 int var1 = buffer.position();
59 while (true) {
60 buffer.position(buffer.position() + 1);
61 byte b = buffer.get(buffer.position() - 1);
62 if (b == 0) break;
63 }
64
65 int var2 =buffer.position() - var1 - 1;
66 return var2 == 0 ? "" : decodeStringCp1252(buffer, var1, var2);
67 }

References decodeStringCp1252().

Referenced by com.runehive.fs.cache.decoder.ObjectDefinitionDecoder.decode().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cp1252AsciiExtension

final char [] com.runehive.fs.util.ByteBufferUtil.cp1252AsciiExtension = new char[]{'€', '\u0000', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '\u0000', 'Ž', '\u0000', '\u0000', '‘', '’', '“', '”', '•', '–', '—', '˜', '™', 'š', '›', 'œ', '\u0000', 'ž', 'Ÿ'}
static

Definition at line 92 of file ByteBufferUtil.java.

92{'€', '\u0000', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '\u0000', 'Ž', '\u0000', '\u0000', '‘', '’', '“', '”', '•', '–', '—', '˜', '™', 'š', '›', 'œ', '\u0000', 'ž', 'Ÿ'};

Referenced by decodeStringCp1252().

◆ DEFAULT_STRING_TERMINATOR

final char com.runehive.fs.util.ByteBufferUtil.DEFAULT_STRING_TERMINATOR = '\0'
static

The default String terminator, equal to 0 and otherwise known as the 'null' String terminator.

Definition at line 24 of file ByteBufferUtil.java.

Referenced by getString().

◆ J_STRING_TERMINATOR

final char com.runehive.fs.util.ByteBufferUtil.J_STRING_TERMINATOR = '\n'
static

The terminator used within the client, equal to 10 and otherwise know as the Jagex String terminator.

Definition at line 18 of file ByteBufferUtil.java.

Referenced by getJString().


The documentation for this class was generated from the following file: