Search in sources :

Example 6 with GSObject

use of org.jets3t.service.model.GSObject in project alluxio by Alluxio.

the class GCSOutputStream method close.

@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);
    } catch (ServiceException e) {
        LOG.error("Failed to upload {}.", mKey);
        throw new IOException(e);
    } finally {
        // upload or if the upload failed.
        if (!mFile.delete()) {
            LOG.error("Failed to delete temporary file @ {}", mFile.getPath());
        }
    }
}
Also used : ServiceException(org.jets3t.service.ServiceException) GSObject(org.jets3t.service.model.GSObject) IOException(java.io.IOException)

Aggregations

GSObject (org.jets3t.service.model.GSObject)6 ServiceException (org.jets3t.service.ServiceException)4 File (java.io.File)2 IOException (java.io.IOException)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1