Java Code Examples for com.google.api.services.storage.model.StorageObject#getSize()
The following examples show how to use
com.google.api.services.storage.model.StorageObject#getSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoogleStorageAttributesFinderFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
protected PathAttributes toAttributes(final StorageObject object) { final PathAttributes attributes = new PathAttributes(); if(object.getSize() != null) { attributes.setSize(object.getSize().longValue()); } final DateTime lastmodified = object.getTimeCreated(); if(lastmodified != null) { attributes.setModificationDate(lastmodified.getValue()); } attributes.setStorageClass(object.getStorageClass()); if(StringUtils.isNotBlank(object.getEtag())) { attributes.setETag(object.getEtag()); } // The content generation of this object. Used for object versioning. // attributes.setVersionId(String.valueOf(object.getGeneration())); // Archived versions of objects have a `timeDeleted` property. // attributes.setDuplicate(object.getTimeDeleted() != null); // if(object.getTimeDeleted() != null) { // attributes.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); // } if(object.getKmsKeyName() != null) { attributes.setEncryption(new Encryption.Algorithm("AES256", object.getKmsKeyName()) { @Override public String getDescription() { return String.format("SSE-KMS (%s)", key); } }); } attributes.setChecksum(Checksum.parse(object.getMd5Hash())); if(object.getMetadata() != null) { attributes.setMetadata(object.getMetadata()); } return attributes; }
Example 2
Source File: GCSHelper.java From dataflow-java with Apache License 2.0 | 5 votes |
/** * @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(); }
Example 3
Source File: LoadReadsToBigQuery.java From dataflow-java with Apache License 2.0 | 5 votes |
private static void checkGcsUrlExists(String url) throws IOException { // Ensure data is accessible. // 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(); }
Example 4
Source File: CountReads.java From dataflow-java with Apache License 2.0 | 5 votes |
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; } }