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;
}
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);
}
}
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();
}
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();
}
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);
}
}
Aggregations