public class FileIo
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static Promise<java.nio.channels.AsynchronousFileChannel> |
open(java.nio.file.Path file,
java.nio.file.OpenOption... options)
Creates a promise for an (open) async file channel.
|
static Promise<java.nio.channels.AsynchronousFileChannel> |
open(java.nio.file.Path file,
java.util.Set<? extends java.nio.file.OpenOption> options,
java.nio.file.attribute.FileAttribute<?>... attrs)
Creates a promise for an (open) async file channel.
|
static Promise<io.netty.buffer.CompositeByteBuf> |
read(Promise<? extends java.nio.channels.AsynchronousFileChannel> file,
io.netty.buffer.ByteBufAllocator allocator,
int bufferSize)
Read the contents of a file from the given start until the given stop.
|
static Promise<io.netty.buffer.CompositeByteBuf> |
read(Promise<? extends java.nio.channels.AsynchronousFileChannel> file,
io.netty.buffer.ByteBufAllocator allocator,
int bufferSize,
long start,
long stop)
Read the contents of a file.
|
static TransformablePublisher<io.netty.buffer.ByteBuf> |
readStream(Promise<? extends java.nio.channels.AsynchronousFileChannel> file,
io.netty.buffer.ByteBufAllocator allocator,
int bufferSize)
Streams the entire contents of a file.
|
static TransformablePublisher<io.netty.buffer.ByteBuf> |
readStream(Promise<? extends java.nio.channels.AsynchronousFileChannel> file,
io.netty.buffer.ByteBufAllocator allocator,
int bufferSize,
long start,
long stop)
Streams the contents of a file.
|
static Operation |
write(io.netty.buffer.ByteBuf bytes,
long position,
Promise<? extends java.nio.channels.AsynchronousFileChannel> file)
Writes the given bytes to the given file, starting at the given position.
|
static Operation |
write(io.netty.buffer.ByteBuf bytes,
Promise<? extends java.nio.channels.AsynchronousFileChannel> file)
Writes the given bytes to the given file, starting at the start.
|
static Promise<java.lang.Long> |
write(Publisher<? extends io.netty.buffer.ByteBuf> publisher,
long position,
Promise<? extends java.nio.channels.AsynchronousFileChannel> file)
Writes the bytes of the given publisher to the given file, returning the number of bytes written.
|
static Promise<java.lang.Long> |
write(Publisher<? extends io.netty.buffer.ByteBuf> publisher,
Promise<? extends java.nio.channels.AsynchronousFileChannel> file)
Writes the bytes of the given publisher to the given file starting at the start, returning the number of bytes written.
|
public static Promise<java.nio.channels.AsynchronousFileChannel> open(java.nio.file.Path file, java.nio.file.OpenOption... options)
Uses AsynchronousFileChannel.open(Path, Set, ExecutorService, FileAttribute[])
,
but uses the current execution's event loop as the executor service and no file attributes.
file
- The path of the file to open or createoptions
- Options specifying how the file is openedAsynchronousFileChannel.open(Path, Set, ExecutorService, FileAttribute[])
,
open(Path, Set, FileAttribute[])
public static Promise<java.nio.channels.AsynchronousFileChannel> open(java.nio.file.Path file, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs)
Uses AsynchronousFileChannel.open(Path, Set, ExecutorService, FileAttribute[])
,
but uses the current execution's event loop as the executor service.
file
- The path of the file to open or createoptions
- Options specifying how the file is openedattrs
- An optional list of file attributes to set atomically when creating the fileAsynchronousFileChannel.open(Path, Set, ExecutorService, FileAttribute[])
,
open(Path, OpenOption...)
public static Promise<java.lang.Long> write(Publisher<? extends io.netty.buffer.ByteBuf> publisher, Promise<? extends java.nio.channels.AsynchronousFileChannel> file)
Use open(Path, Set, FileAttribute[])
to create a file promise.
The file channel is closed on success or failure.
As file system writes are expensive,
you may want to consider using ByteBufStreams.buffer(Publisher, long, int, ByteBufAllocator)
to “buffer” the data in memory before writing to disk.
publisher
- the bytes to writefile
- a promise for the file to write topublic static Promise<java.lang.Long> write(Publisher<? extends io.netty.buffer.ByteBuf> publisher, long position, Promise<? extends java.nio.channels.AsynchronousFileChannel> file)
Use open(Path, Set, FileAttribute[])
to create a file promise.
The file channel is closed on success or failure.
As file system writes are expensive,
you may want to consider using ByteBufStreams.buffer(Publisher, long, int, ByteBufAllocator)
to “buffer” the data in memory before writing to disk.
publisher
- the bytes to writeposition
- the position in the file to start writing (must be >= 0)file
- a promise for the file to write topublic static Operation write(io.netty.buffer.ByteBuf bytes, Promise<? extends java.nio.channels.AsynchronousFileChannel> file)
open(Path, Set, FileAttribute[])
to create a file promise.
The file channel is closed on success or failure.
bytes
- the bytes to writefile
- the file to write topublic static Operation write(io.netty.buffer.ByteBuf bytes, long position, Promise<? extends java.nio.channels.AsynchronousFileChannel> file)
open(Path, Set, FileAttribute[])
to create a file promise.
The file channel is closed on success or failure.
bytes
- the bytes to writeposition
- the position in the file to start writingfile
- the file to write topublic static TransformablePublisher<io.netty.buffer.ByteBuf> readStream(Promise<? extends java.nio.channels.AsynchronousFileChannel> file, io.netty.buffer.ByteBufAllocator allocator, int bufferSize, long start, long stop)
Use open(Path, Set, FileAttribute[])
to create a file promise.
The file channel is closed on success or failure.
file
- a promise for the file to write toallocator
- the allocator of byte bufsbufferSize
- the read buffer size (i.e. the size of each emitted buffer)start
- the position in the file to start reading from (must be >= 0)stop
- the position in the file to read up to (any value < 1 is treated as EOF)readStream(Promise, ByteBufAllocator, int)
public static TransformablePublisher<io.netty.buffer.ByteBuf> readStream(Promise<? extends java.nio.channels.AsynchronousFileChannel> file, io.netty.buffer.ByteBufAllocator allocator, int bufferSize)
Use open(Path, Set, FileAttribute[])
to create a file promise.
The file channel is closed on success or failure.
file
- a promise for the file to write toallocator
- the allocator of byte bufsbufferSize
- the read buffer size (i.e. the size of each emitted buffer)readStream(Promise, ByteBufAllocator, int, long, long)
public static Promise<io.netty.buffer.CompositeByteBuf> read(Promise<? extends java.nio.channels.AsynchronousFileChannel> file, io.netty.buffer.ByteBufAllocator allocator, int bufferSize, long start, long stop)
Use open(Path, Set, FileAttribute[])
to create a file promise.
The file channel is closed on success or failure.
file
- a promise for the file to write toallocator
- the allocator of byte bufsbufferSize
- the read buffer size (i.e. the size of buffer used for each read operation)readStream(Promise, ByteBufAllocator, int)
,
read(Promise, ByteBufAllocator, int)
public static Promise<io.netty.buffer.CompositeByteBuf> read(Promise<? extends java.nio.channels.AsynchronousFileChannel> file, io.netty.buffer.ByteBufAllocator allocator, int bufferSize)
Use open(Path, Set, FileAttribute[])
to create a file promise.
The file channel is closed on success or failure.
file
- a promise for the file to write toallocator
- the allocator of byte bufsbufferSize
- the read buffer size (i.e. the size of buffer used for each read operation)readStream(Promise, ByteBufAllocator, int, long, long)
,
read(Promise, ByteBufAllocator, int, long, long)