Java Utililty Methods ReadableByteChannel Read

List of utility methods to do ReadableByteChannel Read

Description

The list of methods to do ReadableByteChannel Read are organized into topic(s).

Method

intreadAll(ReadableByteChannel ch, ByteBuffer dst)
Read channel until dst has remaining or eof.
int count = 0;
while (dst.hasRemaining()) {
    int rc = ch.read(dst);
    if (rc == -1) {
        if (count > 0) {
            return count;
        return -1;
...
booleanreadAllBytesOrNone(ReadableByteChannel channel, ByteBuffer buffer, int numBytes)
read All Bytes Or None
buffer.rewind();
buffer.limit(numBytes);
int totalBytesRead = 0;
int bytesRead = channel.read(buffer);
if (bytesRead <= 0) {
    return false;
totalBytesRead += bytesRead;
...
intreadAnerisHeader(ReadableByteChannel from, ByteBuffer buffer)

Reads a header from the given channel connected to the Aneris service using the provided buffer.

int headerLength = 0;
int trialNo = 1;
do {
    buffer.position(headerLength);
    headerLength++;
    buffer.limit(headerLength);
    while (buffer.hasRemaining()) {
        int bytesRead = from.read(buffer);
...
voidreadBuffer(ReadableByteChannel chan, ByteBuffer buf)
Read a buffer completely from a channel.
while (buf.hasRemaining()) {
    chan.read(buf);
char[]readCharArray(ReadableByteChannel channel, ByteBuffer buffer, char[] charArray)
read Char Array
buffer.clear();
int charsLeft = charArray.length;
int maxSize = buffer.capacity() / 2;
int offset = 0; 
while (charsLeft > 0) {
    if (charsLeft > maxSize) {
        buffer.limit(maxSize * 2);
        charsLeft -= maxSize;
...
StringreadFromAnerisChannel(ReadableByteChannel chan, ByteBuffer buffer)

Reads the next Aneris message from this channel and returns it in String form.

int nbBytes = readAnerisHeader(chan, buffer);
if (nbBytes != ERROR_HEADER_INT) {
    buffer.position(0);
    buffer.limit(nbBytes);
    int trialNo = 1;
    while (buffer.hasRemaining()) {
        int bytesRead = chan.read(buffer);
        if (bytesRead == 0) {
...
intreadFromChannel(ReadableByteChannel channel, ByteBuffer buffer)
read From Channel
int rem = buffer.position();
while (channel.read(buffer) != -1 && buffer.hasRemaining())
    ;
return buffer.position() - rem;
voidreadFull(ReadableByteChannel ch, ByteBuffer dst)
read Full
int read = 0;
do {
    read = ch.read(dst);
} while (-1 != read && dst.remaining() > 0);
voidreadFully(final ReadableByteChannel channel, final ByteBuffer buf)
read Fully
readFully(channel, buf, buf.remaining());
intreadFully(final ReadableByteChannel channel, final ByteBuffer buf)
read Fully
return readFully(channel, buf, buf.remaining());