Java ByteBuffer Set redString(ByteBuffer buffer, int offset, Charset charset)

Here you can find the source of redString(ByteBuffer buffer, int offset, Charset charset)

Description

red String

License

Open Source License

Declaration

public static String redString(ByteBuffer buffer, int offset,
            Charset charset) throws IOException 

Method Source Code

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

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;

public class Main {
    public static String redString(ByteBuffer buffer, int offset,
            Charset charset) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        for (int i = offset; i < buffer.limit(); i++) {
            if (((char) buffer.get(i)) == '\0') {
                break;
            }//from   w w  w . j a v a2  s .  c  om
            out.write(new byte[] { buffer.get(i) });
        }
        return new String(out.toByteArray(), charset);
    }
}

Related

  1. readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num)
  2. readKey(ByteBuffer index, int indexByteOffset, byte[] foundKey)
  3. readPackageName(ByteBuffer buffer, int offset)
  4. redByteArray(ByteBuffer buffer, int offset, int length)
  5. redInteger1(ByteBuffer buffer, int _offset)
  6. releaseTemporaryDirectBuffer(ByteBuffer buf)
  7. reset(int offset, ByteBuffer b)
  8. resetBit(ByteBuffer in, int pos)
  9. set0byte(MappedByteBuffer mem, byte value)