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

com.nytimes.android.external.fs.SourceFileWriter 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.DiskWrite;
import com.nytimes.android.external.store.base.impl.BarCode;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.Callable;

import javax.inject.Inject;

import okio.BufferedSource;
import rx.Observable;

import static com.nytimes.android.external.fs.SourcePersister.pathForBarcode;
import static okio.Okio.buffer;

public class SourceFileWriter implements DiskWrite {

    final FileSystem fileSystem;

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


    @NotNull
    @Override
    public Observable write(@NotNull final BarCode barCode, @NotNull final BufferedSource data) {
        return Observable.fromCallable(new Callable() {
            @NotNull
            @Override
            @SuppressWarnings("PMD.SignatureDeclareThrowsException")
            public Boolean call() throws Exception {
                fileSystem.write(pathForBarcode(barCode), buffer(data));
                return true;
            }
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy