Class Channels

java.lang.Object
org.elasticsearch.common.io.Channels

public final class Channels
extends java.lang.Object
  • Method Summary

    Modifier and Type Method Description
    static int readFromFileChannel​(java.nio.channels.FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length)
    read length bytes from position of a file channel.
    static byte[] readFromFileChannel​(java.nio.channels.FileChannel channel, long position, int length)
    read length bytes from position of a file channel
    static int readFromFileChannel​(java.nio.channels.FileChannel channel, long channelPosition, java.nio.ByteBuffer dest)
    read from a file channel into a byte buffer, starting at a certain position.
    static void readFromFileChannelWithEofException​(java.nio.channels.FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length)
    read length bytes from position of a file channel.
    static void readFromFileChannelWithEofException​(java.nio.channels.FileChannel channel, long channelPosition, java.nio.ByteBuffer dest)
    read from a file channel into a byte buffer, starting at a certain position.
    static void writeToChannel​(byte[] source, int offset, int length, java.nio.channels.WritableByteChannel channel)
    Writes part of a byte array to a WritableByteChannel
    static void writeToChannel​(byte[] source, java.nio.channels.WritableByteChannel channel)
    Writes part of a byte array to a WritableByteChannel
    static void writeToChannel​(java.nio.ByteBuffer byteBuffer, java.nio.channels.WritableByteChannel channel)
    Writes a ByteBuffer to a WritableByteChannel

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • readFromFileChannel

      public static byte[] readFromFileChannel​(java.nio.channels.FileChannel channel, long position, int length) throws java.io.IOException
      read length bytes from position of a file channel
      Throws:
      java.io.IOException
    • readFromFileChannelWithEofException

      public static void readFromFileChannelWithEofException​(java.nio.channels.FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws java.io.IOException
      read length bytes from position of a file channel. An EOFException will be thrown if you attempt to read beyond the end of file.
      Parameters:
      channel - channel to read from
      channelPosition - position to read from
      dest - destination byte array to put data in
      destOffset - offset in dest to read into
      length - number of bytes to read
      Throws:
      java.io.IOException
    • readFromFileChannel

      public static int readFromFileChannel​(java.nio.channels.FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws java.io.IOException
      read length bytes from position of a file channel.
      Parameters:
      channel - channel to read from
      channelPosition - position to read from
      dest - destination byte array to put data in
      destOffset - offset in dest to read into
      length - number of bytes to read
      Returns:
      total bytes read or -1 if an attempt was made to read past EOF. The method always tries to read all the bytes that will fit in the destination byte buffer.
      Throws:
      java.io.IOException
    • readFromFileChannelWithEofException

      public static void readFromFileChannelWithEofException​(java.nio.channels.FileChannel channel, long channelPosition, java.nio.ByteBuffer dest) throws java.io.IOException
      read from a file channel into a byte buffer, starting at a certain position. An EOFException will be thrown if you attempt to read beyond the end of file.
      Parameters:
      channel - channel to read from
      channelPosition - position to read from
      dest - destination ByteBuffer to put data in
      Throws:
      java.io.IOException
    • readFromFileChannel

      public static int readFromFileChannel​(java.nio.channels.FileChannel channel, long channelPosition, java.nio.ByteBuffer dest) throws java.io.IOException
      read from a file channel into a byte buffer, starting at a certain position.
      Parameters:
      channel - channel to read from
      channelPosition - position to read from
      dest - destination ByteBuffer to put data in
      Returns:
      total bytes read or -1 if an attempt was made to read past EOF. The method always tries to read all the bytes that will fit in the destination byte buffer.
      Throws:
      java.io.IOException
    • writeToChannel

      public static void writeToChannel​(byte[] source, java.nio.channels.WritableByteChannel channel) throws java.io.IOException
      Writes part of a byte array to a WritableByteChannel
      Parameters:
      source - byte array to copy from
      channel - target WritableByteChannel
      Throws:
      java.io.IOException
    • writeToChannel

      public static void writeToChannel​(byte[] source, int offset, int length, java.nio.channels.WritableByteChannel channel) throws java.io.IOException
      Writes part of a byte array to a WritableByteChannel
      Parameters:
      source - byte array to copy from
      offset - start copying from this offset
      length - how many bytes to copy
      channel - target WritableByteChannel
      Throws:
      java.io.IOException
    • writeToChannel

      public static void writeToChannel​(java.nio.ByteBuffer byteBuffer, java.nio.channels.WritableByteChannel channel) throws java.io.IOException
      Writes a ByteBuffer to a WritableByteChannel
      Parameters:
      byteBuffer - source buffer
      channel - channel to write to
      Throws:
      java.io.IOException