本文整理汇总了Java中com.google.api.services.storage.model.StorageObject.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java StorageObject.getSize方法的具体用法?Java StorageObject.getSize怎么用?Java StorageObject.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.services.storage.model.StorageObject
的用法示例。
在下文中一共展示了StorageObject.getSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileSize
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
/**
* @param name of the file we're interested in
* @return size of the file, in bytes
* @throws IOException
*/
public long getFileSize(String bucket, String name) throws IOException {
Storage.Objects.Get getObject = storage.objects().get(bucket, name);
StorageObject object = getObject.execute();
BigInteger size = object.getSize();
if (size.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
throw new RuntimeException("File size is too big for a long!");
}
return size.longValue();
}
示例2: GCSURLExists
import com.google.api.services.storage.model.StorageObject; //导入方法依赖的package包/类
private static boolean GCSURLExists(String url) {
// ensure data is accessible
try {
// if we can read the size, then surely we can read the file
GcsPath fn = GcsPath.fromUri(url);
Storage.Objects storageClient = GCSOptions.Methods.createStorageClient(pipelineOptions, auth);
Storage.Objects.Get getter = storageClient.get(fn.getBucket(), fn.getObject());
StorageObject object = getter.execute();
BigInteger size = object.getSize();
return true;
} catch (Exception x) {
return false;
}
}