java.lang.Object
org.elasticsearch.common.io.Channels
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum chunk size for writes in bytes -
Method Summary
Modifier and TypeMethodDescriptionstatic intreadFromFileChannel(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) read length bytes from position of a file channel.static byte[]readFromFileChannel(FileChannel channel, long position, int length) read length bytes from position of a file channelstatic intreadFromFileChannel(FileChannel channel, long channelPosition, ByteBuffer dest) read from a file channel into a byte buffer, starting at a certain position.static voidreadFromFileChannelWithEofException(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) read length bytes from position of a file channel.static intreadFromFileChannelWithEofException(FileChannel channel, long channelPosition, ByteBuffer dest) read from a file channel into a byte buffer, starting at a certain position.static voidwriteToChannel(byte[] source, int offset, int length, FileChannel channel, long channelPosition) Writes part of a byte array to aWritableByteChannelat the provided position.static voidwriteToChannel(byte[] source, int offset, int length, WritableByteChannel channel) Writes part of a byte array to aWritableByteChannelstatic voidwriteToChannel(byte[] source, FileChannel channel, long channelPosition) Writes part of a byte array to aWritableByteChannelat the provided position.static voidwriteToChannel(byte[] source, WritableByteChannel channel) Writes part of a byte array to aWritableByteChannelstatic voidwriteToChannel(ByteBuffer byteBuffer, WritableByteChannel channel) Writes aByteBufferto aWritableByteChannel
-
Field Details
-
WRITE_CHUNK_SIZE
public static final int WRITE_CHUNK_SIZEThe maximum chunk size for writes in bytes- See Also:
-
-
Method Details
-
readFromFileChannel
public static byte[] readFromFileChannel(FileChannel channel, long position, int length) throws IOException read length bytes from position of a file channel- Throws:
IOException
-
readFromFileChannelWithEofException
public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws 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 fromchannelPosition- position to read fromdest- destination byte array to put data indestOffset- offset in dest to read intolength- number of bytes to read- Throws:
IOException
-
readFromFileChannel
public static int readFromFileChannel(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException read length bytes from position of a file channel.- Parameters:
channel- channel to read fromchannelPosition- position to read fromdest- destination byte array to put data indestOffset- offset in dest to read intolength- 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:
IOException
-
readFromFileChannelWithEofException
public static int readFromFileChannelWithEofException(FileChannel channel, long channelPosition, ByteBuffer dest) throws 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 fromchannelPosition- position to read fromdest- destinationByteBufferto put data in- Returns:
- total bytes read
- Throws:
IOException
-
readFromFileChannel
public static int readFromFileChannel(FileChannel channel, long channelPosition, ByteBuffer dest) throws IOException read from a file channel into a byte buffer, starting at a certain position.- Parameters:
channel- channel to read fromchannelPosition- position to read fromdest- destinationByteBufferto 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:
IOException
-
writeToChannel
Writes part of a byte array to aWritableByteChannel- Parameters:
source- byte array to copy fromchannel- target WritableByteChannel- Throws:
IOException
-
writeToChannel
public static void writeToChannel(byte[] source, int offset, int length, WritableByteChannel channel) throws IOException Writes part of a byte array to aWritableByteChannel- Parameters:
source- byte array to copy fromoffset- start copying from this offsetlength- how many bytes to copychannel- target WritableByteChannel- Throws:
IOException
-
writeToChannel
public static void writeToChannel(byte[] source, FileChannel channel, long channelPosition) throws IOException Writes part of a byte array to aWritableByteChannelat the provided position.- Parameters:
source- byte array to copy fromchannel- target WritableByteChannelchannelPosition- position to write at- Throws:
IOException
-
writeToChannel
public static void writeToChannel(byte[] source, int offset, int length, FileChannel channel, long channelPosition) throws IOException Writes part of a byte array to aWritableByteChannelat the provided position.- Parameters:
source- byte array to copy fromoffset- start copying from this offsetlength- how many bytes to copychannel- target WritableByteChannelchannelPosition- position to write at- Throws:
IOException
-
writeToChannel
public static void writeToChannel(ByteBuffer byteBuffer, WritableByteChannel channel) throws IOException Writes aByteBufferto aWritableByteChannel- Parameters:
byteBuffer- source bufferchannel- channel to write to- Throws:
IOException
-