All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.ytsaurus.client.FileReaderImpl Maven / Gradle / Ivy

The newest version!
package tech.ytsaurus.client;

import java.util.concurrent.CompletableFuture;

import com.google.protobuf.Parser;
import tech.ytsaurus.client.rpc.Compression;
import tech.ytsaurus.client.rpc.RpcUtil;
import tech.ytsaurus.rpcproxy.TReadFileMeta;
import tech.ytsaurus.rpcproxy.TRspReadFile;

class FileReaderImpl extends StreamReaderImpl implements FileReader {
    private long revision = -1;

    FileReaderImpl() {
    }

    @Override
    protected Parser responseParser() {
        return TRspReadFile.parser();
    }

    @Override
    public long revision() {
        return this.revision;
    }

    public CompletableFuture waitMetadata() {
        FileReaderImpl self = this;
        return readHead().thenApply((data) -> {
            TReadFileMeta meta = RpcUtil.parseMessageBodyWithCompression(
                    data,
                    TReadFileMeta.parser(),
                    Compression.None
            );
            self.revision = meta.getRevision();
            return self;
        });
    }

    @Override
    public boolean canRead() {
        return doCanRead();
    }

    @Override
    public byte[] read() throws Exception {
        return doRead();
    }

    @Override
    public CompletableFuture close() {
        return doClose();
    }

    @Override
    public CompletableFuture readyEvent() {
        return getReadyEvent();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy