Example usage for com.google.api.client.googleapis.media MediaHttpDownloader setContentRange

List of usage examples for com.google.api.client.googleapis.media MediaHttpDownloader setContentRange

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.media MediaHttpDownloader setContentRange.

Prototype

@Deprecated
public MediaHttpDownloader setContentRange(long firstBytePos, int lastBytePos) 

Source Link

Usage

From source file:com.google.gcloud.spi.DefaultStorageRpc.java

License:Open Source License

@Override
public byte[] read(StorageObject from, Map<Option, ?> options, long position, int bytes)
        throws StorageException {
    try {/*from  ww  w.  j  ava  2 s .  co m*/
        Get req = storage.objects().get(from.getBucket(), from.getName());
        req.setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(options))
                .setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(options))
                .setIfGenerationMatch(IF_GENERATION_MATCH.getLong(options))
                .setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options));
        MediaHttpDownloader downloader = req.getMediaHttpDownloader();
        // todo: Fix int casting (https://github.com/google/google-api-java-client/issues/937)
        downloader.setContentRange(position, (int) position + bytes);
        downloader.setDirectDownloadEnabled(true);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        req.executeMediaAndDownloadTo(output);
        return output.toByteArray();
    } catch (IOException ex) {
        throw translate(ex);
    }
}