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

no.ks.fiks.dokumentlager.klient.model.LazyDokumentlagerInputStream Maven / Gradle / Ivy

Go to download

Klient for opplasting, sletting og nedlasting av dokumenter fra Fiks Dokumentlager

The newest version!
package no.ks.fiks.dokumentlager.klient.model;

import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicReference;

public class LazyDokumentlagerInputStream extends InputStream {

    private final DokumentlagerResponseRunner dokumentlagerResponseRunner;
    private final AtomicReference> dokumentlagerResponse;

    public LazyDokumentlagerInputStream(DokumentlagerResponseRunner dokumentlagerResponseRunner, AtomicReference> dokumentlagerResponse) {
        this.dokumentlagerResponseRunner = dokumentlagerResponseRunner;
        this.dokumentlagerResponse = dokumentlagerResponse;
    }


    @Override
    public int read() throws IOException {
        if(dokumentlagerResponse.get() == null) {
            dokumentlagerResponse.set(dokumentlagerResponseRunner.run());
        }
        return dokumentlagerResponse.get().getResult().read();
    }

    @Override
    public int read(byte[] bytes, int i, int i1) throws IOException {
        if(dokumentlagerResponse.get() == null) {
            dokumentlagerResponse.set(dokumentlagerResponseRunner.run());
        }
        return dokumentlagerResponse.get().getResult().read(bytes, i, i1);
    }

    @Override
    public long skip(long l) throws IOException {
        if(dokumentlagerResponse.get() == null) {
            dokumentlagerResponse.set(dokumentlagerResponseRunner.run());
        }
        return dokumentlagerResponse.get().getResult().skip(l);
    }

    @Override
    public int available() throws IOException {
        if(dokumentlagerResponse.get() == null) {
            dokumentlagerResponse.set(dokumentlagerResponseRunner.run());
        }
        return dokumentlagerResponse.get().getResult().available();
    }

    @Override
    public void close() throws IOException {
        if(dokumentlagerResponse.get() != null) {
            dokumentlagerResponse.get().getResult().close();
        }
    }

    @Override
    public synchronized void mark(int i) {
        if(dokumentlagerResponse.get() == null) {
            dokumentlagerResponse.set(dokumentlagerResponseRunner.run());
        }
        dokumentlagerResponse.get().getResult().mark(i);
    }

    @Override
    public synchronized void reset() throws IOException {
        if(dokumentlagerResponse.get() == null) {
            dokumentlagerResponse.set(dokumentlagerResponseRunner.run());
        }
        dokumentlagerResponse.get().getResult().reset();
    }

    @Override
    public boolean markSupported() {
        if(dokumentlagerResponse.get() == null) {
            dokumentlagerResponse.set(dokumentlagerResponseRunner.run());
        }
        return dokumentlagerResponse.get().getResult().markSupported();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy