AkServerUtil { static String decodeString(ByteBuffer buffer, String charset) { if (buffer == null) { return null; } if (charset == null) { throw new IllegalArgumentException("charset"); } try { return new String(buffer.array(), buffer.position(), buffer.limit() - buffer.position(), charset); } catch(UnsupportedEncodingException e) { throw new RuntimeException(e); } }  static long getSignedIntegerByWidth(final byte[] bytes, final int index, final int width); static long getUnsignedIntegerByWidth(final byte[] bytes, final int index, final int width); static int putIntegerByWidth(byte[] destination, int destinationIndex, int width, long value); static byte getByte(byte[] bytes, int index); static short getUByte(byte[] bytes, int index); static short getShort(byte[] bytes, int index); static int getUShort(byte[] bytes, int index); static int getMediumInt(byte[] bytes, int index); static int getUMediumInt(byte[] bytes, int index); static int getInt(byte[] bytes, int index); static long getUInt(byte[] bytes, int index); static long getLong(byte[] bytes, int index); static BigInteger getULong(byte[] bytes, int index); static void putByte(byte[] bytes, int index, int value); static void putShort(byte[] bytes, int index, int value); static void putMediumInt(byte[] bytes, int index, int value); static void putInt(byte[] bytes, int index, int value); static void putLong(byte[] bytes, int index, long value); static String dump(byte[] b, int offset, int size); static String hex(byte[] bytes, int start, int length); static StringBuilder hex(StringBuilder sb, long value, int length); static void hex(AkibanAppender sb, byte[] bytes, int start,
            int length); static void printRuntimeInfo(); final static boolean cleanUpDirectory(final File file); final static boolean cleanUpFiles(final File[] files); static String decodeMySQLString(byte[] bytes, final int offset,
            final int width, final FieldDef fieldDef); static ByteSource byteSourceForMySQLString(byte[] bytes, final int offset,
                                                      final int width, final FieldDef fieldDef); static ByteBuffer byteBufferForMySQLString(byte[] bytes, final int offset,
                                           final int width, final FieldDef fieldDef); static int varWidth(final int length); static boolean equals(final Object a, final Object b); static int hashCode(final Object o); final static String NEW_LINE; }
@Test public void decodeNullByteBuffer() { String shouldBeNull = AkServerUtil.decodeString(null, null); assertNull("null byte buffer", shouldBeNull); }
@Test(expected=IllegalArgumentException.class) public void decodeNullCharset() { final byte[] someBytes; someBytes = "some bytes".getBytes(); assertTrue("someBytes was empty!", someBytes.length > 0); AkServerUtil.decodeString(ByteBuffer.wrap(someBytes), null); }