Java ReadableByteChannel Read retryRead(ReadableByteChannel channel, ByteBuffer buffer)

Here you can find the source of retryRead(ReadableByteChannel channel, ByteBuffer buffer)

Description

retry Read

License

Open Source License

Declaration

static int retryRead(ReadableByteChannel channel, ByteBuffer buffer) throws IOException 

Method Source Code


//package com.java2s;
// This software, the RabbitMQ Java client library, is triple-licensed under the

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;

public class Main {
    static int retryRead(ReadableByteChannel channel, ByteBuffer buffer) throws IOException {
        int attempt = 0;
        int read = 0;
        while (attempt < 3) {
            try {
                Thread.sleep(100L);
            } catch (InterruptedException e) {
                // ignore
            }/*ww  w  .  ja va  2  s . c  o  m*/
            read = read(channel, buffer);
            if (read > 0) {
                break;
            }
            attempt++;
        }
        return read;
    }

    static int read(ReadableByteChannel channel, ByteBuffer buffer) throws IOException {
        int read = channel.read(buffer);
        if (read < 0) {
            throw new IOException("I/O thread: reached EOF");
        }
        return read;
    }
}

Related

  1. readFully(ReadableByteChannel channel, ByteBuffer buffer)
  2. readLengthAndString(ReadableByteChannel channel, ByteBuffer buffer)
  3. readMap(ReadableByteChannel channel, ByteBuffer buffer)
  4. readObjFromChannel(ReadableByteChannel chan, ByteBuffer buffer, AtomicBoolean endPointCrashed)
  5. readToBuffer(ReadableByteChannel src, ByteBuffer dst)
  6. transfer(final ReadableByteChannel source, final long count, final ByteBuffer throughBuffer, final WritableByteChannel sink)
  7. transfer(final ReadableByteChannel source, final long count, final ByteBuffer throughBuffer, final WritableByteChannel sink)
  8. writeEntryToTemp(File tempDir, ByteBuffer buffer, ReadableByteChannel channel)