@Override protected boolean createEmptyObject(String key) { try { GSObject obj = new GSObject(key); obj.setDataInputStream(new ByteArrayInputStream(new byte[0])); obj.setContentLength(0); obj.setMd5Hash(DIR_HASH); obj.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM); mClient.putObject(mBucketName, obj); return true; } catch (ServiceException e) { LOG.error("Failed to create directory: {}", key, e); return false; } }
@Override public ObjectStatus[] getObjectStatuses() { StorageObject[] objects = mChunk.getObjects(); ObjectStatus[] ret = new ObjectStatus[objects.length]; for (int i = 0; i < ret.length; ++i) { ret[i] = new ObjectStatus(objects[i].getKey(), objects[i].getMd5HashAsBase64(), objects[i].getContentLength(), objects[i].getLastModifiedDate().getTime()); } return ret; }
@Override protected ObjectStatus getObjectStatus(String key) { try { GSObject meta = mClient.getObjectDetails(mBucketName, key); if (meta == null) { return null; } return new ObjectStatus(key, meta.getMd5HashAsBase64(), meta.getContentLength(), meta.getLastModifiedDate().getTime()); } catch (ServiceException e) { return null; } }
@Override public void close() throws IOException { if (mClosed.getAndSet(true)) { return; } mLocalOutputStream.close(); try { GSObject obj = new GSObject(mKey); obj.setBucketName(mBucketName); obj.setDataInputFile(mFile); obj.setContentLength(mFile.length()); obj.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM); if (mHash != null) { obj.setMd5Hash(mHash.digest()); } else { LOG.warn("MD5 was not computed for: {}", mKey); } mClient.putObject(mBucketName, obj); if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath()); } } catch (ServiceException e) { LOG.error("Failed to upload {}. Temporary file @ {}", mKey, mFile.getPath()); throw new IOException(e); } } }
S3Object object = s3Service.getObject(awsBucketName, key); InputStream istream = object.getDataInputStream(); FileOutputStream ostream = new FileOutputStream(path);
String accountOwner = "unknown"; if (storageOwner != null) { accountOwnerId = storageOwner.getId(); owner = storageOwner.getDisplayName();
@Override protected boolean copyObject(String src, String dst) { LOG.debug("Copying {} to {}", src, dst); GSObject obj = new GSObject(dst); // Retry copy for a few times, in case some Jets3t or GCS internal errors happened during copy. int retries = 3; for (int i = 0; i < retries; i++) { try { mClient.copyObject(mBucketName, src, mBucketName, obj, false); return true; } catch (ServiceException e) { LOG.error("Failed to copy file {} to {}", src, dst, e); if (i != retries - 1) { LOG.error("Retrying copying file {} to {}", src, dst); } } } LOG.error("Failed to copy file {} to {}, after {} retries", src, dst, retries); return false; }
/** * Creates a new instance of {@link GCSInputStream}, at a specific position. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the client for GCS * @param pos the position to start * @throws ServiceException if a service exception occurs */ GCSInputStream(String bucketName, String key, GoogleStorageService client, long pos) throws ServiceException { mBucketName = bucketName; mKey = key; mClient = client; mPos = pos; // For an empty file setting start pos = 0 will throw a ServiceException if (mPos > 0) { mObject = mClient.getObject(mBucketName, mKey, null, null, null, null, mPos, null); } else { mObject = mClient.getObject(mBucketName, mKey); } mInputStream = new BufferedInputStream(mObject.getDataInputStream()); }
public void startExpiration() { latestTimeEvent = config.new Expiration(); latestRule.setExpiration(((Expiration)latestTimeEvent)); }
public void startTransition() { latestTimeEvent = config.new Transition(); latestRule.setTransition(((Transition)latestTimeEvent)); }
/** * This method leverages the ability to open a stream from GCS from a given offset. When the * underlying stream has fewer bytes buffered than the skip request, the stream is closed, and * a new stream is opened starting at the requested offset. * * @param n number of bytes to skip * @return the number of bytes skipped */ @Override public long skip(long n) throws IOException { if (mInputStream.available() >= n) { return mInputStream.skip(n); } // The number of bytes to skip is possibly large, open a new stream from GCS. mInputStream.close(); mPos += n; try { mObject = mClient.getObject(mBucketName, mKey, null /* ignore ModifiedSince */, null /* ignore UnmodifiedSince */, null /* ignore MatchTags */, null /* ignore NoneMatchTags */, mPos /* byteRangeStart */, null /* ignore byteRangeEnd */); mInputStream = new BufferedInputStream(mObject.getDataInputStream()); } catch (ServiceException e) { throw new IOException(e); } return n; } }
public void startExpiration() { latestTimeEvent = config.new Expiration(); latestRule.setExpiration(((Expiration)latestTimeEvent)); }