Examples of ReadableByteChannel


Examples of java.nio.channels.ReadableByteChannel

        int preReadInputBBPos = byteBuffer.position();
        Selector readSelector = null;
        SelectionKey tmpKey = null;

        try {
            ReadableByteChannel readableChannel = (ReadableByteChannel) channel;
            while(count > 0) {
                count = readableChannel.read(byteBuffer);
                if(count > -1) {
                    byteRead += count;
                } else {
                    byteRead = count;
                }
            }

            if(byteRead == 0 && byteBuffer.position() == preReadInputBBPos) {
                readSelector = selectorFactory.getSelector();

                if(readSelector == null) {
                    return 0;
                }
                count = 1;

                tmpKey = channel.register(readSelector, SelectionKey.OP_READ);
                tmpKey.interestOps(tmpKey.interestOps() | SelectionKey.OP_READ);
                int code = readSelector.select(readTimeout);
                tmpKey.interestOps(tmpKey.interestOps() & (~SelectionKey.OP_READ));

                if(code == 0) {
                    return 0; // Return on the main Selector and try again.
                }

                while(count > 0) {
                    count = readableChannel.read(byteBuffer);
                    if(count > -1) {
                        byteRead += count;
                    } else {
                        byteRead = count;
                    }
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

        int byteRead = 0;
        Selector readSelector = null;
        SelectionKey tmpKey = null;

        try {
            ReadableByteChannel readableChannel = (ReadableByteChannel) channel;
            int count = 1;
            while(count > 0) {
                count = readableChannel.read(byteBuffer);
                if(count > -1) {
                    byteRead += count;
                } else {
                    byteRead = count;
                }
            }

            if(byteRead == 0 && byteBuffer.position() == preBufPos) {
                readSelector = selectorPool.getSelector();
                if(readSelector == null) {
                    return 0;
                }
                count = 1;

                tmpKey = channel.register(readSelector, SelectionKey.OP_READ);
                tmpKey.interestOps(tmpKey.interestOps() | SelectionKey.OP_READ);
                int code = readSelector.select(readTimeout);
                tmpKey.interestOps(tmpKey.interestOps() & (~SelectionKey.OP_READ));

                if(code == 0) {
                    return 0; // Return on the main Selector and try again.
                }

                while(count > 0) {
                    count = readableChannel.read(byteBuffer);
                    if(count > -1) {
                        byteRead += count;
                    } else {
                        byteRead = count;
                    }
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    }

    /*
     * Now try InputCapture which may also yield a known format
     */
    ReadableByteChannel channel = new RandomAccessFile(file, "r").getChannel();
    FormatType type = formatType(channel);
    channel.close();

    if (logger.isTraceEnabled()) {
      logger.trace(file.getName() + ", type=" + FormatType.Pcap);
    }

View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    }

    /*
     * Now try InputCapture which may also yield a known format
     */
    ReadableByteChannel channel = new RandomAccessFile(file, "r").getChannel();
    FormatType.Detail detail = formatTypeDetail(channel);
    channel.close();

    if (logger.isTraceEnabled()) {
      logger.trace(file.getName() + ", type=" + FormatType.Pcap + ", detail="
          + detail);
    }
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    final long count;

    switch (type) {
      case Other:
        final ReadableByteChannel channel =
            new RandomAccessFile(dst, "r").getChannel();
        final InputCapture<? extends CapturePacket> input =
            newInput(channel, null);
        count = Captures.count(input.getPacketIterator());
        input.close();
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

  }

  public static ReadableByteChannel asReadableByteChannel(
      final ByteBuffer buffer) {

    return new ReadableByteChannel() {

      private boolean open = true;

      public int read(ByteBuffer dst) throws IOException {
        if (open == false) {
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    System.out.println("write to file " + file.getAbsolutePath());
     
    FileChannel fc = new RandomAccessFile(file, "rw").getChannel();

    Assert.assertEquals(200, response.getStatus());
    ReadableByteChannel bodyChannel= response.getBody();
     
    ByteBuffer transferBuffer = ByteBuffer.allocateDirect(8192);
           
    while (bodyChannel.read(transferBuffer) != -1) {
      transferBuffer.flip();
     
      while (transferBuffer.hasRemaining()) {
        fc.write(transferBuffer);
        }
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    System.out.println("write to file " + file.getAbsolutePath());
     
    FileChannel fc = new RandomAccessFile(file, "rw").getChannel();

    Assert.assertEquals(200, response.getStatus());
    ReadableByteChannel bodyChannel= response.getBlockingBody();
     
    ByteBuffer transferBuffer = ByteBuffer.allocateDirect(8192);
           
    while (bodyChannel.read(transferBuffer) != -1) {
      transferBuffer.flip();
     
      while (transferBuffer.hasRemaining()) {
        fc.write(transferBuffer);
        }
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    System.out.println("write to file " + file.getAbsolutePath());
     
    FileChannel fc = new RandomAccessFile(file, "rw").getChannel();

    Assert.assertEquals(200, response.getStatus());
    ReadableByteChannel bodyChannel= response.getBlockingBody();
     
    ByteBuffer transferBuffer = ByteBuffer.allocateDirect(8192);
           
    while (bodyChannel.read(transferBuffer) != -1) {
      transferBuffer.flip();
     
      while (transferBuffer.hasRemaining()) {
        fc.write(transferBuffer);
        }
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    System.out.println("write to file " + file.getAbsolutePath());
     
    FileChannel fc = new RandomAccessFile(file, "rw").getChannel();

    Assert.assertEquals(200, response.getStatus());
    ReadableByteChannel bodyChannel= response.getBlockingBody();
     
    ByteBuffer transferBuffer = ByteBuffer.allocateDirect(8192);
           
    while (bodyChannel.read(transferBuffer) != -1) {
      transferBuffer.flip();
     
      while (transferBuffer.hasRemaining()) {
        fc.write(transferBuffer);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.