Search in sources :

Example 1 with ByteArrayContent

use of com.google.api.client.http.ByteArrayContent in project pentaho-kettle by pentaho.

the class GoogleDriveFileObject method doGetOutputStream.

protected OutputStream doGetOutputStream(boolean append) throws Exception {
    final File parent = getName().getParent() != null ? searchFile(getName().getParent().getBaseName(), null) : null;
    ByteArrayOutputStream out = new ByteArrayOutputStream() {

        public void close() throws IOException {
            File file = new File();
            file.setName(getName().getBaseName());
            if (parent != null) {
                file.setParents(Collections.singletonList(parent.getId()));
            }
            ByteArrayContent fileContent = new ByteArrayContent("application/octet-stream", toByteArray());
            if (count > 0) {
                driveService.files().create(file, fileContent).execute();
                ((GoogleDriveFileSystem) getFileSystem()).clearFileFromCache(getName());
            }
        }
    };
    return out;
}
Also used : ByteArrayContent(com.google.api.client.http.ByteArrayContent) File(com.google.api.services.drive.model.File)

Example 2 with ByteArrayContent

use of com.google.api.client.http.ByteArrayContent in project google-cloud-java by GoogleCloudPlatform.

the class HttpBigQueryRpc method write.

@Override
public Job write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, boolean last) {
    try {
        GenericUrl url = new GenericUrl(uploadId);
        HttpRequest httpRequest = bigquery.getRequestFactory().buildPutRequest(url, new ByteArrayContent(null, toWrite, toWriteOffset, length));
        httpRequest.setParser(bigquery.getObjectParser());
        long limit = destOffset + length;
        StringBuilder range = new StringBuilder("bytes ");
        range.append(destOffset).append('-').append(limit - 1).append('/');
        if (last) {
            range.append(limit);
        } else {
            range.append('*');
        }
        httpRequest.getHeaders().setContentRange(range.toString());
        int code;
        String message;
        IOException exception = null;
        HttpResponse response = null;
        try {
            response = httpRequest.execute();
            code = response.getStatusCode();
            message = response.getStatusMessage();
        } catch (HttpResponseException ex) {
            exception = ex;
            code = ex.getStatusCode();
            message = ex.getStatusMessage();
        }
        if (!last && code != HTTP_RESUME_INCOMPLETE || last && !(code == HTTP_OK || code == HTTP_CREATED)) {
            if (exception != null) {
                throw exception;
            }
            throw new BigQueryException(code, message);
        }
        return last && response != null ? response.parseAs(Job.class) : null;
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) HttpResponse(com.google.api.client.http.HttpResponse) HttpResponseException(com.google.api.client.http.HttpResponseException) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) BigQueryException(com.google.cloud.bigquery.BigQueryException) ByteArrayContent(com.google.api.client.http.ByteArrayContent) Job(com.google.api.services.bigquery.model.Job)

Example 3 with ByteArrayContent

use of com.google.api.client.http.ByteArrayContent in project java-docs-samples by GoogleCloudPlatform.

the class FirebaseChannel method firebasePost.

public HttpResponse firebasePost(String path, Object object) throws IOException {
    // Make requests auth'ed using Application Default Credentials
    Credential credential = GoogleCredential.getApplicationDefault().createScoped(FIREBASE_SCOPES);
    HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
    String json = new Gson().toJson(object);
    GenericUrl url = new GenericUrl(path);
    return requestFactory.buildPostRequest(url, new ByteArrayContent("application/json", json.getBytes())).execute();
}
Also used : GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) Credential(com.google.api.client.auth.oauth2.Credential) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) Gson(com.google.gson.Gson) GenericUrl(com.google.api.client.http.GenericUrl) ByteArrayContent(com.google.api.client.http.ByteArrayContent)

Example 4 with ByteArrayContent

use of com.google.api.client.http.ByteArrayContent in project java-docs-samples by GoogleCloudPlatform.

the class FirebaseChannel method firebasePut.

// The following methods are to illustrate making various calls to Firebase from App Engine
// Standard
public HttpResponse firebasePut(String path, Object object) throws IOException {
    // Make requests auth'ed using Application Default Credentials
    Credential credential = GoogleCredential.getApplicationDefault().createScoped(FIREBASE_SCOPES);
    HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
    String json = new Gson().toJson(object);
    GenericUrl url = new GenericUrl(path);
    return requestFactory.buildPutRequest(url, new ByteArrayContent("application/json", json.getBytes())).execute();
}
Also used : GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) Credential(com.google.api.client.auth.oauth2.Credential) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) Gson(com.google.gson.Gson) GenericUrl(com.google.api.client.http.GenericUrl) ByteArrayContent(com.google.api.client.http.ByteArrayContent)

Example 5 with ByteArrayContent

use of com.google.api.client.http.ByteArrayContent in project halyard by spinnaker.

the class GoogleStorage method writeBytes.

void writeBytes(String name, byte[] contents) {
    name = String.join("/", rootFolder, name);
    try {
        StorageObject object = new StorageObject().setBucket(bucketId).setName(name);
        ByteArrayContent content = new ByteArrayContent("application/text", contents);
        storage.objects().insert(bucketId, object, content).execute();
    } catch (IOException e) {
        throw new HalException(Problem.Severity.FATAL, "Failed to write to " + name + ": " + e.getMessage(), e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException) ByteArrayContent(com.google.api.client.http.ByteArrayContent)

Aggregations

ByteArrayContent (com.google.api.client.http.ByteArrayContent)25 GenericUrl (com.google.api.client.http.GenericUrl)16 HttpRequest (com.google.api.client.http.HttpRequest)9 IOException (java.io.IOException)9 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)6 Gson (com.google.gson.Gson)6 HttpResponse (com.google.api.client.http.HttpResponse)5 File (com.google.api.services.drive.model.File)4 Credential (com.google.api.client.auth.oauth2.Credential)3 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)3 HttpHeaders (com.google.api.client.http.HttpHeaders)3 AbstractInputStreamContent (com.google.api.client.http.AbstractInputStreamContent)2 HttpContent (com.google.api.client.http.HttpContent)2 HttpResponseException (com.google.api.client.http.HttpResponseException)2 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)2 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)2 StorageObject (com.google.api.services.storage.model.StorageObject)2 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)2 EpicAuthorization (com.xilixir.fortniteapi.v2.Epic.EpicAuthorization)2 HashMap (java.util.HashMap)2