Java Code Examples for com.amazonaws.services.s3.AmazonS3#getObjectMetadata()

The following examples show how to use com.amazonaws.services.s3.AmazonS3#getObjectMetadata() . 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: MultipartCopier.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void copy(final AmazonS3 s3, final String bucket, final String sourcePath, final String destinationPath) {
  ObjectMetadata metadataResult = s3.getObjectMetadata(bucket, sourcePath);
  long length = metadataResult.getContentLength();

  try {
    if (length < chunkSize) {
      copySinglePart(s3, bucket, sourcePath, destinationPath);
    }
    else {
      copyMultiPart(s3, bucket, sourcePath, destinationPath, length);
    }
  }
  catch(SdkClientException e) {
    throw new BlobStoreException("Error copying blob", e, null);
  }
}
 
Example 2
Source File: AmazonS3InstallationService.java    From java-slack-sdk with MIT License 5 votes vote down vote up
private ObjectMetadata getObjectMetadata(AmazonS3 s3, String fullKey) {
    try {
        return s3.getObjectMetadata(bucketName, fullKey);
    } catch (AmazonS3Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Amazon S3 object metadata not found (key: {}, AmazonS3Exception: {})", fullKey, e.toString(), e);
        } else {
            log.info("Amazon S3 object metadata not found (key: {}, AmazonS3Exception: {})", fullKey, e.toString());
        }
        return null;
    }
}
 
Example 3
Source File: PrimitiveS3OperationHandler.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ObjectMetadata getObjectMetadata(URI uri, AmazonS3 service) throws IOException {
	try {
		String[] path = getPath(uri);
		return service.getObjectMetadata(path[0], path[1]);
	} catch (Exception e) {
		throw S3Utils.getIOException(e);
	}
}
 
Example 4
Source File: S3OperationsImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectMetadata getObjectMetadata(String s3BucketName, String s3Key, AmazonS3 s3Client)
{
    return s3Client.getObjectMetadata(s3BucketName, s3Key);
}
 
Example 5
Source File: GetInfo.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
@Override
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{

	AmazonKey amazonKey	= getAmazonKey(_session, argStruct);
	AmazonS3 s3Client		= getAmazonS3(amazonKey);

		String bucket	= getNamedStringParam(argStruct, "bucket", null );
	if ( bucket == null )
		throwException(_session, "Please specify a bucket" );

		String key		= getNamedStringParam(argStruct, "key", null );
	if ( key == null )
		throwException(_session, "Please specify a key" );

	if ( key.charAt( 0 ) == '/' )
		key	= key.substring(1);


 	try {
 		GetObjectMetadataRequest g	= new GetObjectMetadataRequest(bucket, key);
 		
 		ObjectMetadata metadata = s3Client.getObjectMetadata( g );

 		cfStructData	s = new cfStructData();

 		s.setData("bucket", new cfStringData(bucket) );
 		s.setData("key", 		new cfStringData(key) );
 		s.setData("host", 	new cfStringData( amazonKey.getAmazonRegion().toAWSRegion().getDomain() ) );

 		Map m = metadata.getRawMetadata();
 		Iterator<String> it = m.keySet().iterator();
 		while ( it.hasNext() ){
 			String k = it.next();
 			s.setData(k, tagUtils.convertToCfData(m.get(k)) );
 		}

 		return s;
	} catch (Exception e) {
		throwException(_session, "AmazonS3: " + e.getMessage() );
		return cfBooleanData.FALSE;
	}
 }
 
Example 6
Source File: RestoreObject.java    From cloudExplorer with GNU General Public License v3.0 4 votes vote down vote up
public void run() {
    String message = null;
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    File file = new File(what);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration());
    if (endpoint.contains("amazonaws.com")) {
        String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket));
        if (aws_endpoint.contains("US")) {
            s3Client.setEndpoint("https://s3.amazonaws.com");
        } else if (aws_endpoint.contains("us-west")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("eu-west")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("ap-")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("sa-east-1")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else {
            s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com");
        }
    } else {
        s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build());
        s3Client.setEndpoint(endpoint);
    }

    try {
        RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucket, what, 2);
        s3Client.restoreObject(requestRestore);

        GetObjectMetadataRequest requestCheck = new GetObjectMetadataRequest(bucket, what);
        ObjectMetadata response = s3Client.getObjectMetadata(requestCheck);

        Boolean restoreFlag = response.getOngoingRestore();
        mainFrame.jTextArea1.append("\nRestoration in progress. Please try to access the file again in a few hours.");
        calibrate();
    } catch (AmazonS3Exception amazonS3Exception) {
        mainFrame.jTextArea1.append("\nAn Amazon S3 error occurred. Exception: %s" + amazonS3Exception.toString());
        calibrate();
    } catch (Exception ex) {
        mainFrame.jTextArea1.append("\nException: %s" + ex.toString());
        calibrate();
    }

    calibrate();
}