/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.reactivex.core.file;
import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
Represents a file on the file-system which can be read from, or written to asynchronously.
This class also implements ReadStream
and WriteStream
. This allows the data to be pumped to and from other streams, e.g. an HttpClientRequest
instance, using the Pump
class
NOTE: This class has been automatically generated from the original
non RX-ified interface using Vert.x codegen. /**
* Represents a file on the file-system which can be read from, or written to asynchronously.
* <p>
* This class also implements {@link io.vertx.reactivex.core.streams.ReadStream} and
* {@link io.vertx.reactivex.core.streams.WriteStream}. This allows the data to be pumped to and from
* other streams, e.g. an {@link io.vertx.reactivex.core.http.HttpClientRequest} instance,
* using the {@link io.vertx.reactivex.core.streams.Pump} class
*
* <p/>
* NOTE: This class has been automatically generated from the {@link io.vertx.core.file.AsyncFile original} non RX-ified interface using Vert.x codegen.
*/
@io.vertx.lang.rx.RxGen(io.vertx.core.file.AsyncFile.class)
public class AsyncFile implements io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.buffer.Buffer>, io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> {
@Override
public String toString() {
return delegate.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AsyncFile that = (AsyncFile) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
public static final io.vertx.lang.rx.TypeArg<AsyncFile> __TYPE_ARG = new io.vertx.lang.rx.TypeArg<>( obj -> new AsyncFile((io.vertx.core.file.AsyncFile) obj),
AsyncFile::getDelegate
);
private final io.vertx.core.file.AsyncFile delegate;
public AsyncFile(io.vertx.core.file.AsyncFile delegate) {
this.delegate = delegate;
}
public io.vertx.core.file.AsyncFile getDelegate() {
return delegate;
}
private io.reactivex.Observable<io.vertx.reactivex.core.buffer.Buffer> observable;
private io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> flowable;
public synchronized io.reactivex.Observable<io.vertx.reactivex.core.buffer.Buffer> toObservable() {
if (observable == null) {
java.util.function.Function<io.vertx.core.buffer.Buffer, io.vertx.reactivex.core.buffer.Buffer> conv = io.vertx.reactivex.core.buffer.Buffer::newInstance;
observable = io.vertx.reactivex.ObservableHelper.toObservable(delegate, conv);
}
return observable;
}
public synchronized io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> toFlowable() {
if (flowable == null) {
java.util.function.Function<io.vertx.core.buffer.Buffer, io.vertx.reactivex.core.buffer.Buffer> conv = io.vertx.reactivex.core.buffer.Buffer::newInstance;
flowable = io.vertx.reactivex.FlowableHelper.toFlowable(delegate, conv);
}
return flowable;
}
private io.vertx.reactivex.WriteStreamObserver<io.vertx.reactivex.core.buffer.Buffer> observer;
private io.vertx.reactivex.WriteStreamSubscriber<io.vertx.reactivex.core.buffer.Buffer> subscriber;
public synchronized io.vertx.reactivex.WriteStreamObserver<io.vertx.reactivex.core.buffer.Buffer> toObserver() {
if (observer == null) {
java.util.function.Function<io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.buffer.Buffer> conv = io.vertx.reactivex.core.buffer.Buffer::getDelegate;
observer = io.vertx.reactivex.RxHelper.toObserver(getDelegate(), conv);
}
return observer;
}
public synchronized io.vertx.reactivex.WriteStreamSubscriber<io.vertx.reactivex.core.buffer.Buffer> toSubscriber() {
if (subscriber == null) {
java.util.function.Function<io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.buffer.Buffer> conv = io.vertx.reactivex.core.buffer.Buffer::getDelegate;
subscriber = io.vertx.reactivex.RxHelper.toSubscriber(getDelegate(), conv);
}
return subscriber;
}
Same as end
but writes some data to the stream before ending. Params: - data – the data to write
/**
* Same as {@link io.vertx.reactivex.core.file.AsyncFile#end} but writes some data to the stream before ending.
* @param data the data to write
*/
public void end(io.vertx.reactivex.core.buffer.Buffer data) {
delegate.end(data.getDelegate());
}
Same as but with an handler
called when the operation completes
Params: - data –
- handler –
/**
* Same as but with an <code>handler</code> called when the operation completes
* @param data
* @param handler
*/
public void end(io.vertx.reactivex.core.buffer.Buffer data, Handler<AsyncResult<Void>> handler) {
delegate.end(data.getDelegate(), handler);
}
Same as but with an handler
called when the operation completes
Params: - data –
Returns:
/**
* Same as but with an <code>handler</code> called when the operation completes
* @param data
* @return
*/
public Completable rxEnd(io.vertx.reactivex.core.buffer.Buffer data) {
return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> {
end(data, handler);
});
}
This will return true
if there are more bytes in the write queue than the value set using setWriteQueueMaxSize
Returns: true if write queue is full
/**
* This will return <code>true</code> if there are more bytes in the write queue than the value set using {@link io.vertx.reactivex.core.file.AsyncFile#setWriteQueueMaxSize}
* @return true if write queue is full
*/
public boolean writeQueueFull() {
boolean ret = delegate.writeQueueFull();
return ret;
}
Pause this stream and return a to transfer the elements of this stream to a destination .
The stream will be resumed when the pipe will be wired to a WriteStream
.
Returns: a pipe
/**
* Pause this stream and return a to transfer the elements of this stream to a destination .
* <p/>
* The stream will be resumed when the pipe will be wired to a <code>WriteStream</code>.
* @return a pipe
*/
public io.vertx.reactivex.core.streams.Pipe<io.vertx.reactivex.core.buffer.Buffer> pipe() {
io.vertx.reactivex.core.streams.Pipe<io.vertx.reactivex.core.buffer.Buffer> ret = io.vertx.reactivex.core.streams.Pipe.newInstance(delegate.pipe(), (io.vertx.lang.rx.TypeArg)io.vertx.reactivex.core.buffer.Buffer.__TYPE_ARG);
return ret;
}
Like ReadStream.pipeTo
but with no completion handler. Params: - dst –
/**
* Like {@link io.vertx.reactivex.core.streams.ReadStream#pipeTo} but with no completion handler.
* @param dst
*/
public void pipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> dst) {
delegate.pipeTo(dst.getDelegate());
}
Pipe this ReadStream
to the WriteStream
.
Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Once this stream has ended or failed, the write stream will be ended and the handler
will be
called with the result.
Params: - dst – the destination write stream
- handler –
/**
* Pipe this <code>ReadStream</code> to the <code>WriteStream</code>.
* <p>
* Elements emitted by this stream will be written to the write stream until this stream ends or fails.
* <p>
* Once this stream has ended or failed, the write stream will be ended and the <code>handler</code> will be
* called with the result.
* @param dst the destination write stream
* @param handler
*/
public void pipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> dst, Handler<AsyncResult<Void>> handler) {
delegate.pipeTo(dst.getDelegate(), handler);
}
Pipe this ReadStream
to the WriteStream
.
Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Once this stream has ended or failed, the write stream will be ended and the handler
will be
called with the result.
Params: - dst – the destination write stream
Returns:
/**
* Pipe this <code>ReadStream</code> to the <code>WriteStream</code>.
* <p>
* Elements emitted by this stream will be written to the write stream until this stream ends or fails.
* <p>
* Once this stream has ended or failed, the write stream will be ended and the <code>handler</code> will be
* called with the result.
* @param dst the destination write stream
* @return
*/
public Completable rxPipeTo(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> dst) {
return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> {
pipeTo(dst, handler);
});
}
public io.vertx.reactivex.core.file.AsyncFile handler(Handler<io.vertx.reactivex.core.buffer.Buffer> handler) {
delegate.handler(new Handler<io.vertx.core.buffer.Buffer>() {
public void handle(io.vertx.core.buffer.Buffer event) {
handler.handle(io.vertx.reactivex.core.buffer.Buffer.newInstance(event));
}
});
return this;
}
public io.vertx.reactivex.core.file.AsyncFile pause() {
delegate.pause();
return this;
}
public io.vertx.reactivex.core.file.AsyncFile resume() {
delegate.resume();
return this;
}
public io.vertx.reactivex.core.file.AsyncFile endHandler(Handler<Void> endHandler) {
delegate.endHandler(endHandler);
return this;
}
public io.vertx.reactivex.core.file.AsyncFile write(io.vertx.reactivex.core.buffer.Buffer data) {
delegate.write(data.getDelegate());
return this;
}
Same as write
but with an handler
called when the operation completes
Params: - data –
- handler –
Returns:
/**
* Same as {@link io.vertx.reactivex.core.file.AsyncFile#write} but with an <code>handler</code> called when the operation completes
* @param data
* @param handler
* @return
*/
public io.vertx.reactivex.core.file.AsyncFile write(io.vertx.reactivex.core.buffer.Buffer data, Handler<AsyncResult<Void>> handler) {
delegate.write(data.getDelegate(), handler);
return this;
}
Same as write
but with an handler
called when the operation completes
Params: - data –
Returns:
/**
* Same as {@link io.vertx.reactivex.core.file.AsyncFile#write} but with an <code>handler</code> called when the operation completes
* @param data
* @return
*/
public Completable rxWrite(io.vertx.reactivex.core.buffer.Buffer data) {
return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> {
write(data, handler);
});
}
public io.vertx.reactivex.core.file.AsyncFile setWriteQueueMaxSize(int maxSize) {
delegate.setWriteQueueMaxSize(maxSize);
return this;
}
public io.vertx.reactivex.core.file.AsyncFile drainHandler(Handler<Void> handler) {
delegate.drainHandler(handler);
return this;
}
public io.vertx.reactivex.core.file.AsyncFile exceptionHandler(Handler<Throwable> handler) {
delegate.exceptionHandler(handler);
return this;
}
public io.vertx.reactivex.core.file.AsyncFile fetch(long amount) {
delegate.fetch(amount);
return this;
}
Close the file, see close
. /**
* Close the file, see {@link io.vertx.reactivex.core.file.AsyncFile#close}.
*/
public void end() {
delegate.end();
}
Close the file, see close
. Params: - handler –
/**
* Close the file, see {@link io.vertx.reactivex.core.file.AsyncFile#close}.
* @param handler
*/
public void end(Handler<AsyncResult<Void>> handler) {
delegate.end(handler);
}
Close the file, see close
. Returns:
/**
* Close the file, see {@link io.vertx.reactivex.core.file.AsyncFile#close}.
* @return
*/
public Completable rxEnd() {
return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> {
end(handler);
});
}
Close the file. The actual close happens asynchronously.
/**
* Close the file. The actual close happens asynchronously.
*/
public void close() {
delegate.close();
}
Close the file. The actual close happens asynchronously.
The handler will be called when the close is complete, or an error occurs.
Params: - handler – the handler
/**
* Close the file. The actual close happens asynchronously.
* The handler will be called when the close is complete, or an error occurs.
* @param handler the handler
*/
public void close(Handler<AsyncResult<Void>> handler) {
delegate.close(handler);
}
Close the file. The actual close happens asynchronously.
The handler will be called when the close is complete, or an error occurs.
Returns:
/**
* Close the file. The actual close happens asynchronously.
* The handler will be called when the close is complete, or an error occurs.
* @return
*/
public Completable rxClose() {
return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> {
close(handler);
});
}
Write a Buffer
to the file at position position
in the file, asynchronously.
If position
lies outside of the current size
of the file, the file will be enlarged to encompass it.
When multiple writes are invoked on the same file
there are no guarantees as to order in which those writes actually occur
The handler will be called when the write is complete, or if an error occurs.
Params: - buffer – the buffer to write
- position – the position in the file to write it at
- handler – the handler to call when the write is complete
Returns: a reference to this, so the API can be used fluently
/**
* Write a {@link io.vertx.reactivex.core.buffer.Buffer} to the file at position <code>position</code> in the file, asynchronously.
* <p>
* If <code>position</code> lies outside of the current size
* of the file, the file will be enlarged to encompass it.
* <p>
* When multiple writes are invoked on the same file
* there are no guarantees as to order in which those writes actually occur
* <p>
* The handler will be called when the write is complete, or if an error occurs.
* @param buffer the buffer to write
* @param position the position in the file to write it at
* @param handler the handler to call when the write is complete
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.reactivex.core.file.AsyncFile write(io.vertx.reactivex.core.buffer.Buffer buffer, long position, Handler<AsyncResult<Void>> handler) {
delegate.write(buffer.getDelegate(), position, handler);
return this;
}
Write a Buffer
to the file at position position
in the file, asynchronously.
If position
lies outside of the current size
of the file, the file will be enlarged to encompass it.
When multiple writes are invoked on the same file
there are no guarantees as to order in which those writes actually occur
The handler will be called when the write is complete, or if an error occurs.
Params: - buffer – the buffer to write
- position – the position in the file to write it at
Returns: a reference to this, so the API can be used fluently
/**
* Write a {@link io.vertx.reactivex.core.buffer.Buffer} to the file at position <code>position</code> in the file, asynchronously.
* <p>
* If <code>position</code> lies outside of the current size
* of the file, the file will be enlarged to encompass it.
* <p>
* When multiple writes are invoked on the same file
* there are no guarantees as to order in which those writes actually occur
* <p>
* The handler will be called when the write is complete, or if an error occurs.
* @param buffer the buffer to write
* @param position the position in the file to write it at
* @return a reference to this, so the API can be used fluently
*/
public Completable rxWrite(io.vertx.reactivex.core.buffer.Buffer buffer, long position) {
return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> {
write(buffer, position, handler);
});
}
Reads length
bytes of data from the file at position position
in the file, asynchronously.
The read data will be written into the specified Buffer buffer
at position offset
.
If data is read past the end of the file then zero bytes will be read.
When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.
The handler will be called when the close is complete, or if an error occurs.
Params: - buffer – the buffer to read into
- offset – the offset into the buffer where the data will be read
- position – the position in the file where to start reading
- length – the number of bytes to read
- handler – the handler to call when the write is complete
Returns: a reference to this, so the API can be used fluently
/**
* Reads <code>length</code> bytes of data from the file at position <code>position</code> in the file, asynchronously.
* <p>
* The read data will be written into the specified <code>Buffer buffer</code> at position <code>offset</code>.
* <p>
* If data is read past the end of the file then zero bytes will be read.<p>
* When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.
* <p>
* The handler will be called when the close is complete, or if an error occurs.
* @param buffer the buffer to read into
* @param offset the offset into the buffer where the data will be read
* @param position the position in the file where to start reading
* @param length the number of bytes to read
* @param handler the handler to call when the write is complete
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.reactivex.core.file.AsyncFile read(io.vertx.reactivex.core.buffer.Buffer buffer, int offset, long position, int length, Handler<AsyncResult<io.vertx.reactivex.core.buffer.Buffer>> handler) {
delegate.read(buffer.getDelegate(), offset, position, length, new Handler<AsyncResult<io.vertx.core.buffer.Buffer>>() {
public void handle(AsyncResult<io.vertx.core.buffer.Buffer> ar) {
if (ar.succeeded()) {
handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.reactivex.core.buffer.Buffer.newInstance(ar.result())));
} else {
handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
Reads length
bytes of data from the file at position position
in the file, asynchronously.
The read data will be written into the specified Buffer buffer
at position offset
.
If data is read past the end of the file then zero bytes will be read.
When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.
The handler will be called when the close is complete, or if an error occurs.
Params: - buffer – the buffer to read into
- offset – the offset into the buffer where the data will be read
- position – the position in the file where to start reading
- length – the number of bytes to read
Returns: a reference to this, so the API can be used fluently
/**
* Reads <code>length</code> bytes of data from the file at position <code>position</code> in the file, asynchronously.
* <p>
* The read data will be written into the specified <code>Buffer buffer</code> at position <code>offset</code>.
* <p>
* If data is read past the end of the file then zero bytes will be read.<p>
* When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.
* <p>
* The handler will be called when the close is complete, or if an error occurs.
* @param buffer the buffer to read into
* @param offset the offset into the buffer where the data will be read
* @param position the position in the file where to start reading
* @param length the number of bytes to read
* @return a reference to this, so the API can be used fluently
*/
public Single<io.vertx.reactivex.core.buffer.Buffer> rxRead(io.vertx.reactivex.core.buffer.Buffer buffer, int offset, long position, int length) {
return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> {
read(buffer, offset, position, length, handler);
});
}
Flush any writes made to this file to underlying persistent storage.
If the file was opened with flush
set to true
then calling this method will have no effect.
The actual flush will happen asynchronously.
Returns: a reference to this, so the API can be used fluently
/**
* Flush any writes made to this file to underlying persistent storage.
* <p>
* If the file was opened with <code>flush</code> set to <code>true</code> then calling this method will have no effect.
* <p>
* The actual flush will happen asynchronously.
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.reactivex.core.file.AsyncFile flush() {
delegate.flush();
return this;
}
Same as flush
but the handler will be called when the flush is complete or if an error occurs Params: - handler –
Returns:
/**
* Same as {@link io.vertx.reactivex.core.file.AsyncFile#flush} but the handler will be called when the flush is complete or if an error occurs
* @param handler
* @return
*/
public io.vertx.reactivex.core.file.AsyncFile flush(Handler<AsyncResult<Void>> handler) {
delegate.flush(handler);
return this;
}
Same as flush
but the handler will be called when the flush is complete or if an error occurs Returns:
/**
* Same as {@link io.vertx.reactivex.core.file.AsyncFile#flush} but the handler will be called when the flush is complete or if an error occurs
* @return
*/
public Completable rxFlush() {
return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> {
flush(handler);
});
}
Sets the position from which data will be read from when using the file as a ReadStream
. Params: - readPos – the position in the file
Returns: a reference to this, so the API can be used fluently
/**
* Sets the position from which data will be read from when using the file as a {@link io.vertx.reactivex.core.streams.ReadStream}.
* @param readPos the position in the file
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.reactivex.core.file.AsyncFile setReadPos(long readPos) {
delegate.setReadPos(readPos);
return this;
}
Sets the position from which data will be written when using the file as a WriteStream
. Params: - writePos – the position in the file
Returns: a reference to this, so the API can be used fluently
/**
* Sets the position from which data will be written when using the file as a {@link io.vertx.reactivex.core.streams.WriteStream}.
* @param writePos the position in the file
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.reactivex.core.file.AsyncFile setWritePos(long writePos) {
delegate.setWritePos(writePos);
return this;
}
Returns: the current write position the file is at
/**
* @return the current write position the file is at
*/
public long getWritePos() {
long ret = delegate.getWritePos();
return ret;
}
Sets the buffer size that will be used to read the data from the file. Changing this value will impact how much
the data will be read at a time from the file system.
Params: - readBufferSize – the buffer size
Returns: a reference to this, so the API can be used fluently
/**
* Sets the buffer size that will be used to read the data from the file. Changing this value will impact how much
* the data will be read at a time from the file system.
* @param readBufferSize the buffer size
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.reactivex.core.file.AsyncFile setReadBufferSize(int readBufferSize) {
delegate.setReadBufferSize(readBufferSize);
return this;
}
public static AsyncFile newInstance(io.vertx.core.file.AsyncFile arg) {
return arg != null ? new AsyncFile(arg) : null;
}
}