Java ByteBuffer to String readString(ByteBuffer buffer)

Here you can find the source of readString(ByteBuffer buffer)

Description

read String

License

Open Source License

Declaration

public static String readString(ByteBuffer buffer) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.nio.ByteBuffer;

public class Main {
    public static String readString(ByteBuffer buffer) throws IOException {
        byte[] data = new byte[256];
        int i = 0, value = 0;
        for (i = 0; (i < data.length) && ((value = buffer.get()) > 0); ++i) {
            data[i] = (byte) value;
        }/* www  .  jav a2  s .  co  m*/

        return new String(data, 0, i);
    }
}

Related

  1. readString(ByteBuffer buf)
  2. readString(ByteBuffer buf, int length)
  3. readString(ByteBuffer buff)
  4. readString(ByteBuffer buff, int len)
  5. readString(ByteBuffer buffer)
  6. readString(ByteBuffer byteBuffer)
  7. readString(ByteBuffer byteBuffer)
  8. readString(ByteBuffer logBuf)
  9. readString(final ByteBuffer buffer, final String encoding)