Java ByteBuffer to String getStringRepresentation(ByteBuffer key)

Here you can find the source of getStringRepresentation(ByteBuffer key)

Description

get String Representation

License

Apache License

Declaration

public static String getStringRepresentation(ByteBuffer key) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

public class Main {
    public static String getStringRepresentation(ByteBuffer key) {
        Charset charset = Charset.forName("ISO-8859-1");
        CharsetDecoder decoder = charset.newDecoder();
        String keyName = null;/*from w w w  . ja v  a 2  s  .c  o m*/
        ByteBuffer keyNameByteBuffer = key.duplicate();
        CharBuffer keyNameCharBuffer;
        try {
            keyNameCharBuffer = decoder.decode(keyNameByteBuffer);
            keyName = keyNameCharBuffer.toString();
        } catch (CharacterCodingException e1) {
            e1.printStackTrace();
        }
        return keyName;
    }
}

Related

  1. getStringDTrimmed(ByteBuffer byteBuffer, int length)
  2. getStringFromBuffer(ByteBuffer buf, int len)
  3. getStringFromBuffer(ByteBuffer buffer, int length)
  4. getStringFromByteBuffer(ByteBuffer bb)
  5. getStringFromByteBuffer(ByteBuffer data)
  6. getStringTrimmed(ByteBuffer buffer, int size)
  7. getStringWOLength(ByteBuffer bb)
  8. readStr(ByteBuffer bb, int off, int len)
  9. readString(byte[] tmp, ByteBuffer in)