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

com.nytimes.android.external.fs.SourceFileReader Maven / Gradle / Ivy

There is a newer version: 3.0.0-alpha
Show newest version
package com.nytimes.android.external.fs;

import com.nytimes.android.external.fs.filesystem.FileSystem;
import com.nytimes.android.external.store.base.DiskRead;
import com.nytimes.android.external.store.base.impl.BarCode;

import org.jetbrains.annotations.NotNull;

import java.io.FileNotFoundException;
import java.util.concurrent.Callable;

import javax.inject.Inject;

import okio.BufferedSource;
import rx.Observable;

import static com.nytimes.android.external.fs.SourcePersister.pathForBarcode;

public class SourceFileReader implements DiskRead {

    final FileSystem fileSystem;

    @Inject
    public SourceFileReader(FileSystem fileSystem) {
        this.fileSystem = fileSystem;
    }

    @NotNull
    @Override
    public Observable read(@NotNull final BarCode barCode) {
        return Observable.fromCallable(new Callable() {
            @NotNull
            @Override
            public BufferedSource call() throws FileNotFoundException {
                return fileSystem.read(pathForBarcode(barCode));
            }
        });
    }

    public boolean exists(@NotNull BarCode barCode) {
        return fileSystem.exists(pathForBarcode(barCode));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy