/** * This function has only debug purposes and is used to print the contents of a buffer to the * output log. This is used for the debug output when debugging the protocol. The bytes that are * written are all remaining bytes of the buffer. Also the position of the buffer with point at * the end after this function was called. * * @param prefix The prefix that shall be written first to the log * @param buffer The buffer that contains the values that shall be written */ static void dump(final String prefix, @Nonnull final ByteBuffer buffer) { final TextBuilder builder = TextBuilder.newInstance(); final TextBuilder builderText = TextBuilder.newInstance(); builder.append(prefix); builder.append(' '); int bytes = 0; while (buffer.hasRemaining()) { final byte bufferValue = buffer.get(); builder.append(String.format(DUMP_FORMAT_BYTES, bufferValue)); final char c = (char) ((bufferValue + CHAR_MOD) % CHAR_MOD); if (c >= FIRST_PRINT_CHAR) { builderText.append(c); } else { builderText.append('.'); } ++bytes; } builder.append(' '); builder.append(String.format(DUMP_FORMAT_TOTAL, bytes)); builder.append(' '); builder.append('<'); builder.append(builderText); builder.append('>'); LOGGER.debug(builder.toString()); TextBuilder.recycle(builder); TextBuilder.recycle(builderText); }
/** * Get the simple name of this class along with the parameters of the command. * * @param param the parameters of the command that shall be displayed along with the class name of * the command * @return the string that contains the simple class name and the parameters */ protected final String toString(final String param) { final TextBuilder builder = TextBuilder.newInstance(); builder.append(getClass().getSimpleName()); builder.append('('); builder.append(param); builder.append(')'); final String retString = builder.toString(); TextBuilder.recycle(builder); return retString; }
/** * (Based on implode() in PHP) * * @param strArray - an array of strings to concatenate * @param strDelim - the delimiter to put between the strings * @return a delimited string for a given array of string elements. */ public static String implodeString(Iterable<String> strArray, String strDelim) { final TextBuilder sbString = TextBuilder.newInstance(); for (String strValue : strArray) { sbString.append(strValue); sbString.append(strDelim); } String result = sbString.toString(); TextBuilder.recycle(sbString); return result; }
/** * Get the name of the character. Returns the last known name or someone along with the ID of the * character, in case its set that the IDs shall be shown. * * @param id ID of the character who's name is wanted * @return the name of the character or null */ @SuppressWarnings("nls") private String getName(final CharacterId id) { String name = null; if (names != null) { name = names.getName(id); } if (name == null) { if (showIDs) { final TextBuilder buildName = TextBuilder.newInstance(); buildName.setLength(0); buildName.append(Lang.getMsg("someone")); buildName.append(' '); buildName.append('('); buildName.append(id); buildName.append(')'); name = buildName.toString(); TextBuilder.recycle(buildName); } } return name; }