本文整理汇总了Java中com.google.api.client.http.ByteArrayContent.fromString方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayContent.fromString方法的具体用法?Java ByteArrayContent.fromString怎么用?Java ByteArrayContent.fromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.http.ByteArrayContent
的用法示例。
在下文中一共展示了ByteArrayContent.fromString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendPostMultipart
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
public static int sendPostMultipart(String urlString, Map<String, String> parameters)
throws IOException {
MultipartContent postBody = new MultipartContent()
.setMediaType(new HttpMediaType("multipart/form-data"));
postBody.setBoundary(MULTIPART_BOUNDARY);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
HttpContent partContent = ByteArrayContent.fromString( // uses UTF-8 internally
null /* part Content-Type */, entry.getValue());
HttpHeaders partHeaders = new HttpHeaders()
.set("Content-Disposition", "form-data; name=\"" + entry.getKey() + "\"");
postBody.addPart(new MultipartContent.Part(partHeaders, partContent));
}
GenericUrl url = new GenericUrl(new URL(urlString));
HttpRequest request = transport.createRequestFactory().buildPostRequest(url, postBody);
request.setHeaders(new HttpHeaders().setUserAgent(CloudToolsInfo.USER_AGENT));
request.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
request.setReadTimeout(DEFAULT_READ_TIMEOUT_MS);
HttpResponse response = request.execute();
return response.getStatusCode();
}
示例2: createNewLineString
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
/**
* Creates a new row in Google Fusion Tables representing the track as a line
* segment.
*
* @param fusiontables fusion tables
* @param tableId the table id
* @param track the track
*/
private void createNewLineString(Fusiontables fusiontables, String tableId, Track track)
throws IOException {
String values = SendFusionTablesUtils.formatSqlValues(track.getName(), track.getDescription(),
SendFusionTablesUtils.getKmlLineString(track.getLocations()));
String sql = "INSERT INTO " + tableId + " (name,description,geometry) VALUES " + values;
HttpContent content = ByteArrayContent.fromString(null, "sql=" + sql);
GoogleUrl url = new GoogleUrl("https://www.googleapis.com/fusiontables/v1/query");
fusiontables.getRequestFactory().buildPostRequest(url, content).execute();
}
示例3: writeFile
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
public void writeFile(String fileId, String folderId, String title, String mime, String content) throws Exception {
File body = new File();
body.setTitle(title);
body.setMimeType(mime);
body.setParents(Arrays.asList(new ParentReference().setId(folderId)));
ByteArrayContent bac = ByteArrayContent.fromString(MT.TEXT, content);
if (TextUtils.isEmpty(fileId)) {
File file = service.files().insert(body, bac).execute();
Log.i(TAG, title + " created, id " + file.getId());
} else {
service.files().update(fileId, body, bac).execute();
Log.i(TAG, title + " updated, id " + fileId);
}
}
示例4: insertPreferencesFile
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
/**
* Inserts preferences file into the appdata folder.
* @param content The application context.
* @return Inserted file.
* @throws IOException
*/
public File insertPreferencesFile(String content) throws IOException {
File metadata = new File();
metadata.setTitle(FILE_NAME);
metadata.setParents(Arrays.asList(new ParentReference().setId("appdata")));
ByteArrayContent c =
ByteArrayContent.fromString(FILE_MIME_TYPE, content);
return mDriveService.files().insert(metadata, c).execute();
}
示例5: updatePreferencesFile
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
/**
* Updates the preferences file with content.
* @param file File metadata.
* @param content File content in JSON.
* @return Updated file.
* @throws IOException
*/
public File updatePreferencesFile(File file, String content)
throws IOException {
Log.d(TAG, "Saving content to remote drive "+file.getId()+" : [" + content + "]");
ByteArrayContent c =
ByteArrayContent.fromString(FILE_MIME_TYPE, content);
return mDriveService.files().update(file.getId(), file, c).execute();
}
示例6: insertPreferencesFile
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
/**
* Inserts preferences file into the appdata folder.
* @param content The application context.
* @return Inserted file.
* @throws java.io.IOException
*/
public File insertPreferencesFile(String content) throws IOException {
File metadata = new File();
metadata.setTitle(FILE_NAME);
metadata.setParents(Arrays.asList(new ParentReference().setId("appdata")));
ByteArrayContent c =
ByteArrayContent.fromString(FILE_MIME_TYPE, content);
return mDriveService.files().insert(metadata, c).execute();
}
示例7: updatePreferencesFile
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
/**
* Updates the preferences file with content.
* @param file File metadata.
* @param content File content in JSON.
* @return Updated file.
* @throws java.io.IOException
*/
public File updatePreferencesFile(File file, String content)
throws IOException {
Log.d(TAG, "Saving content to remote drive "+file.getId()+" : [" + content + "]");
ByteArrayContent c =
ByteArrayContent.fromString(FILE_MIME_TYPE, content);
return mDriveService.files().update(file.getId(), file, c).execute();
}
示例8: insertPreferencesFile
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
/**
* Inserts preferences file into the appdata folder.
* @param content The application context.
* @return Inserted file.
* @throws IOException
*/
public File insertPreferencesFile(String content) throws IOException {
File metadata = new File();
metadata.setTitle(FILE_NAME);
metadata.setParents(Arrays.asList(new ParentReference().setId("appdata")));
ByteArrayContent c =
ByteArrayContent.fromString(FILE_MIME_TYPE, content);
return mDriveService.files().insert(metadata, c).execute();
}
示例9: execute
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
/**
* Executes the HTTP request for a temporary or long-lived token.
*
* @throws IOException
*/
public final HttpResponse execute() throws IOException {
ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder();
if(this.proxyEnabled) {
builder.setProxy(this.proxy);
}
transport = builder.build();
if(usePost && body != null){
requestBody = ByteArrayContent.fromString(null, body);
}
HttpHeaders headers = new HttpHeaders();
headers.setUserAgent(config.getUserAgent());
headers.setAccept(accept != null ? accept : config.getAccept());
headers.setContentType(contentType == null ? "application/xml" : contentType);
if(ifModifiedSince != null) {
//System.out.println("Set Header " + this.ifModifiedSince);
headers.setIfModifiedSince(this.ifModifiedSince);
}
HttpRequestFactory requestFactory = transport.createRequestFactory();
HttpRequest request;
HttpResponse response = null;
request = requestFactory.buildRequest(this.httpMethod, Url, requestBody);
request.setConnectTimeout(connectTimeout);
request.setReadTimeout(readTimeout);
request.setHeaders(headers);
createParameters().intercept(request);
response = request.execute();
response.setContentLoggingLimit(0);
return response;
}
示例10: updatePreferencesFile
import com.google.api.client.http.ByteArrayContent; //导入方法依赖的package包/类
/**
* Updates the preferences file with content.
* @param file File metadata.
* @param content File content in JSON.
* @return Updated file.
* @throws IOException
*/
public File updatePreferencesFile(File file, String content)
throws IOException {
ByteArrayContent c =
ByteArrayContent.fromString(FILE_MIME_TYPE, content);
return mDriveService.files().update(file.getId(), file, c).execute();
}