com.nytimes.android.external.fs.SourceFileWriter Maven / Gradle / Ivy
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;
}
});
}
}