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

org.opentripplanner.ext.datastore.gs.GsOutFileDataSource Maven / Gradle / Ivy

package org.opentripplanner.ext.datastore.gs;

import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Storage;
import org.opentripplanner.datastore.DataSource;
import org.opentripplanner.datastore.FileType;
import org.opentripplanner.datastore.file.DirectoryDataSource;
import org.opentripplanner.datastore.file.ZipFileDataSource;

import java.io.OutputStream;

import static java.nio.channels.Channels.newOutputStream;

class GsOutFileDataSource extends AbstractGsDataSource implements DataSource {
    private final Storage storage;

    /**
     * Create a data source wrapper around a file. This wrapper handles GZIP(.gz) compressed files
     * as well as normal files. It does not handle directories({@link DirectoryDataSource}) or
     * zip-files {@link ZipFileDataSource} which contain multiple files.
     */
    GsOutFileDataSource(Storage storage, BlobId blobId, FileType type) {
        super(blobId, type);
        this.storage = storage;
    }

    @Override
    public boolean exists() {
        return false;
    }

    @Override
    public OutputStream asOutputStream() {
        BlobInfo blobInfo = BlobInfo.newBuilder(blobId()).build();
        return newOutputStream(storage.writer(blobInfo));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy