本文整理汇总了Java中com.google.api.services.storage.model.StorageObject.setName方法的典型用法代码示例。如果您正苦于以下问题:Java StorageObject.setName方法的具体用法?Java StorageObject.setName怎么用?Java StorageObject.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.services.storage.model.StorageObject
的用法示例。
在下文中一共展示了StorageObject.setName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBuild
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
@Test
public void testBuild() throws Exception {
MockUploadModule module = new MockUploadModule(executor);
DownloadStep step = new DownloadStep(CREDENTIALS_ID,
"gs://bucket/path/to/object.txt",
"", module);
FreeStyleProject project = jenkins.createFreeStyleProject("testBuild");
// Set up mock to retrieve the object
StorageObject objToGet = new StorageObject();
objToGet.setBucket("bucket");
objToGet.setName("path/to/obj.txt");
executor.when(Storage.Objects.Get.class, objToGet,
MockUploadModule.checkGetObject("path/to/object.txt"));
module.addNextMedia(IOUtils.toInputStream("test", "UTF-8"));
project.getBuildersList().add(step);
FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
FilePath result = build.getWorkspace().withSuffix("/path/to/obj.txt");
assertTrue(result.exists());
assertEquals("test", result.readToString());
}
示例2: testBuildPrefix
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
@Test
public void testBuildPrefix() throws Exception {
MockUploadModule module = new MockUploadModule(executor);
DownloadStep step = new DownloadStep(CREDENTIALS_ID,
"gs://bucket/path/to/object.txt",
"subPath", module);
step.setPathPrefix("path/to/");
FreeStyleProject project = jenkins.createFreeStyleProject("testBuild");
// Set up mock to retrieve the object
StorageObject objToGet = new StorageObject();
objToGet.setBucket("bucket");
objToGet.setName("path/to/obj.txt");
executor.when(Storage.Objects.Get.class, objToGet,
MockUploadModule.checkGetObject("path/to/object.txt"));
module.addNextMedia(IOUtils.toInputStream("test", "UTF-8"));
project.getBuildersList().add(step);
FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
FilePath result = build.getWorkspace().withSuffix("/subPath/obj.txt");
assertTrue(result.exists());
assertEquals("test", result.readToString());
}
示例3: testBuildMoreComplex
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
@Test
public void testBuildMoreComplex() throws Exception {
MockUploadModule module = new MockUploadModule(executor);
DownloadStep step = new DownloadStep(CREDENTIALS_ID,
"gs://bucket/download/$BUILD_ID/path/$BUILD_ID/test_$BUILD_ID.txt",
"output", module);
step.setPathPrefix("download/$BUILD_ID/");
FreeStyleProject project = jenkins.createFreeStyleProject("testBuild");
// Set up mock to retrieve the object
StorageObject objToGet = new StorageObject();
objToGet.setBucket("bucket");
objToGet.setName("download/1/path/1/test_1.txt");
executor.when(Storage.Objects.Get.class, objToGet,
MockUploadModule.checkGetObject("download/1/path/1/test_1.txt"));
module.addNextMedia(IOUtils.toInputStream("contents 1", "UTF-8"));
project.getBuildersList().add(step);
FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
FilePath result = build.getWorkspace()
.withSuffix("/output/path/1/test_1.txt");
assertTrue(result.exists());
assertEquals("contents 1", result.readToString());
}
示例4: createObjects
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
/**
* Create the Objects object that would have been returned from the Cloud.
*
* @param prefix the requested object prefix
* @param names a list of object names that are available
*/
private Objects createObjects(String prefix, List<String> names) {
Objects o = new Objects();
List<StorageObject> items = new ArrayList<StorageObject>();
Set<String> prefixes = new HashSet<String>();
for (String s : names) {
if (!s.startsWith(prefix)) {
continue;
}
String subdirectory[] = s.substring(prefix.length()).split("/");
if (subdirectory.length > 1) {
// This object is nested deeper. Add a subdirectory
prefixes.add(prefix + subdirectory[0]);
} else {
// Add the object
StorageObject objToGet = new StorageObject();
objToGet.setBucket("bucket");
objToGet.setName(s);
items.add(objToGet);
}
}
o.setItems(items);
o.setPrefixes(new ArrayList<String>(prefixes));
return o;
}
示例5: prepareEmptyInsert
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
/**
* Helper for creating a Storage.Objects.Copy object ready for dispatch given a bucket and
* object for an empty object to be created. Caller must already verify that {@code resourceId}
* represents a StorageObject and not a bucket.
*/
private Storage.Objects.Insert prepareEmptyInsert(StorageResourceId resourceId,
CreateObjectOptions createObjectOptions) throws IOException {
StorageObject object = new StorageObject();
object.setName(resourceId.getObjectName());
Map<String, String> rewrittenMetadata = encodeMetadata(createObjectOptions.getMetadata());
object.setMetadata(rewrittenMetadata);
// Ideally we'd use EmptyContent, but Storage requires an AbstractInputStreamContent and not
// just an HttpContent, so we'll just use the next easiest thing.
ByteArrayContent emptyContent =
new ByteArrayContent(createObjectOptions.getContentType(), new byte[0]);
Storage.Objects.Insert insertObject = gcs.objects().insert(
resourceId.getBucketName(), object, emptyContent);
insertObject.setDisableGZipContent(true);
clientRequestHelper.setDirectUploadEnabled(insertObject, true);
if (resourceId.hasGenerationId()) {
insertObject.setIfGenerationMatch(resourceId.getGenerationId());
} else if (!createObjectOptions.overwriteExisting()) {
insertObject.setIfGenerationMatch(0L);
}
return insertObject;
}
示例6: uriToStorageObject
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
private static StorageObject uriToStorageObject(String uri) throws IOException {
StorageObject object = new StorageObject();
if (uri.startsWith(GCS_PREFIX)) {
uri = uri.substring(GCS_PREFIX.length());
} else {
throw new IOException("Invalid GCS path (does not start with gs://): " + uri);
}
int slashPos = uri.indexOf("/");
if (slashPos > 0) {
object.setBucket(uri.substring(0, slashPos));
object.setName(uri.substring(slashPos + 1));
LOG.info("uriToStorageObject " + uri + "=" + object.getBucket() + ":" + object.getName());
} else {
throw new IOException("Invalid GCS path (does not have bucket/name form): " + uri);
}
return object;
}
示例7: insertCloudImage
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
/**
* Attempts to insert the image in the given Bitmap into the given GoogleStorage, at the given
* imageFullPath with the given format.
*
* All parameters are mandatory.
* <p/>
* NOTE: See full path explanation:
* https://github.com/Mithrandir21/GoogleCloudStorage#object-full-path
*
* @param googleStorage
* @param imageFullPath
* @param image
* @param format
* @return
* @throws IOException
*/
public static boolean insertCloudImage(GoogleStorage googleStorage, String imageFullPath, Bitmap image,
MediaManipulation.SupportedImageFormats format)
throws IOException
{
if( googleStorage == null )
{
throw new IllegalArgumentException("Given GoogleStorage was null!");
}
if( (imageFullPath == null || imageFullPath.length() < 1) )
{
throw new IllegalArgumentException("Given imageFullPath was null or empty!");
}
if( image == null )
{
throw new IllegalArgumentException("Given image was null!");
}
if( format == null )
{
throw new IllegalArgumentException("Given format was null!");
}
Log.d(TAG, "Attempting upload " + imageFullPath);
Bitmap.CompressFormat compressFormat = MediaManipulation.getCompressFormat(format);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(compressFormat, 100, stream);
byte[] byteArray = stream.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(byteArray);
Log.d(TAG, "Created InputStream for Bitmap.");
InputStreamContent mediaContent = new InputStreamContent("image/" + format, bs);
Log.d(TAG, "Created InputStreamContent for upload.");
Storage storage = googleStorage.getStorage();
StorageObject storageObject = new StorageObject();
storageObject.setBucket(googleStorage.getBucketName());
storageObject.setName(imageFullPath);
Log.d(TAG, "Create StorageObject to be inserted.");
Storage.Objects.Insert insert = storage.objects().insert(googleStorage.getBucketName(), storageObject, mediaContent);
Log.d(TAG, "Create insert request with StorageObject and InputStreamContent.");
insert.execute();
Log.d(TAG, "Executed upload.");
return true;
}
示例8: createStorageObject
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
private StorageObject createStorageObject(String name) {
final StorageObject storageObject = new StorageObject();
storageObject.setName(name);
return storageObject;
}
示例9: testSimpleDelete
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
@Test
public void testSimpleDelete() throws Exception {
main = new MirrorMain(new String[]{OPT_VERBOSE,
OPT_DELETE_REMOVED, OPT_SOURCE_BUCKET, SOURCE, OPT_DESTINATION_BUCKET, DESTINATION, OPT_DEST_STORE, "GCS", OPT_GCS_APPLICAION_NAME, "TangoMe"});
main.parseArguments();
main.setSourceClient(s3);
main.setDestClient(gcs);
MirrorOptions options = main.getOptions();
MirrorContext context = new MirrorContext(options);
main.setContext(context);
MirrorMaster master = new MirrorMaster(s3, gcs, context);
main.setMaster(master);
//set up
Storage.Objects objects = PowerMockito.mock(Storage.Objects.class);
Storage.Objects.List listObjects = PowerMockito.mock(Storage.Objects.List.class);
//create StorageObject and add it to return list of objects
StorageObject object = new StorageObject();
object.setBucket(DESTINATION);
object.setEtag("etag");
String key = "test_file";
object.setName(key);
object.setSize(BigInteger.valueOf(10));
List<StorageObject> listOfObjects = new ArrayList<StorageObject>();
listOfObjects.add(object);
Objects mockobjects = PowerMockito.mock(Objects.class);
List<S3ObjectSummary> objectSummaries = new ArrayList<S3ObjectSummary>();
AmazonS3Exception e = new AmazonS3Exception("Key not found");
e.setStatusCode(404);
Storage.Objects.Delete result = PowerMockito.mock(Storage.Objects.Delete.class);
PowerMockito.when(gcs.objects()).thenReturn(objects);
PowerMockito.when(gcs.objects().list(DESTINATION)).thenReturn(listObjects);
PowerMockito.when(gcs.objects().list(DESTINATION).setMaxResults(any(Long.class))).thenReturn(listObjects);
PowerMockito.when(gcs.objects().list(DESTINATION).setMaxResults(any(Long.class)).setPrefix(any(String.class))).thenReturn(listObjects);
PowerMockito.when(listObjects.execute()).thenReturn(mockobjects);
PowerMockito.when(mockobjects.getItems()).thenReturn(listOfObjects);
PowerMockito.when(s3.listObjects(Mockito.any(ListObjectsRequest.class))).thenReturn(listing);
PowerMockito.when(listing.getObjectSummaries()).thenReturn(objectSummaries);
PowerMockito.when(s3.getObjectMetadata(SOURCE, key)).thenThrow(e);
PowerMockito.when(gcs.objects().delete(DESTINATION, key)).thenReturn(result);
main.init();
main.run();
//number of deleted files
assertEquals(1, main.getContext().getStats().objectsDeleted.get());
}