Here you can find the source of getJagexString(ByteBuffer buf)
Parameter | Description |
---|---|
buf | The buffer. |
public static String getJagexString(ByteBuffer buf)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { /**/*from ww w. j a v a 2 s. co m*/ * The modified set of 'extended ASCII' characters used by the client. */ private static char CHARACTERS[] = { '\u20AC', '\0', '\u201A', '\u0192', '\u201E', '\u2026', '\u2020', '\u2021', '\u02C6', '\u2030', '\u0160', '\u2039', '\u0152', '\0', '\u017D', '\0', '\0', '\u2018', '\u2019', '\u201C', '\u201D', '\u2022', '\u2013', '\u2014', '\u02DC', '\u2122', '\u0161', '\u203A', '\u0153', '\0', '\u017E', '\u0178' }; /** * Gets a null-terminated string from the specified buffer, using a * modified ISO-8859-1 character set. * @param buf The buffer. * @return The decoded string. */ public static String getJagexString(ByteBuffer buf) { StringBuilder bldr = new StringBuilder(); int b; while ((b = (buf.get() & 0xFF)) != 0) { if (b >= 127 && b < 160) { char curChar = CHARACTERS[b - 128]; if (curChar != 0) { bldr.append(curChar); } } else { bldr.append((char) b); } } return bldr.toString(); } /** * Converts the contents of the specified byte buffer to a string, which is * formatted similarly to the output of the {@link Arrays#toString()} * method. * @param buffer The buffer. * @return The string. */ public static String toString(ByteBuffer buffer) { StringBuilder builder = new StringBuilder("["); for (int i = 0; i < buffer.limit(); i++) { String hex = Integer.toHexString(buffer.get(i) & 0xFF) .toUpperCase(); if (hex.length() == 1) hex = "0" + hex; builder.append("0x").append(hex); if (i != buffer.limit() - 1) { builder.append(", "); } } builder.append("]"); return builder.toString(); } }