Java File Read via ByteBuffer readFromBuffer(byte[] buffer, int start, int end)

Here you can find the source of readFromBuffer(byte[] buffer, int start, int end)

Description

Returns a string read from a buffer of bytes after replacing null character by the empty string.

License

Open Source License

Parameter

Parameter Description
buffer the byte buffer
start the index from which to start reading
end the index at which to stop reading

Return

a string read from a buffer of bytes after replacing null character by the empty string

Declaration

public static String readFromBuffer(byte[] buffer, int start, int end) 

Method Source Code


//package com.java2s;
// https://github.com/Talend/data-prep/blob/master/LICENSE

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

public class Main {
    /**/*from  w  w w  . j  av a2  s. c  o  m*/
     * ASCII charset used to detect CSV and Html formats
     */
    public static final Charset ASCII = Charset.forName("US-ASCII");

    /**
     * Returns a string read from a buffer of bytes after replacing null character by the empty string.
     * 
     * @param buffer the byte buffer
     * @param start the index from which to start reading
     * @param end the index at which to stop reading
     * @return a string read from a buffer of bytes after replacing null character by the empty string
     */
    public static String readFromBuffer(byte[] buffer, int start, int end) {
        String result = ASCII.decode(ByteBuffer.wrap(buffer, start, end)).toString();
        Character c = Character.MIN_CODE_POINT;
        result = result.replaceAll(c.toString(), "");
        return result;
    }
}

Related

  1. readFileToString(String path)
  2. readFileToString(String path)
  3. readFlashString(DataInputStream s)
  4. readFloat(BufferedReader br)
  5. ReadFloat(InputStream is)
  6. readFromFile(Path path)
  7. readFromFile(String fileName)
  8. readFromSocket(SocketChannel channel)
  9. readFull(Reader in)