List of usage examples for com.amazonaws.services.s3.model S3ObjectId S3ObjectId
public S3ObjectId(String bucket, String key)
From source file:com.atlantbh.jmeter.plugins.aws.s3.AWSS3Downloader.java
License:Apache License
@Override public SampleResult sample(Entry arg0) { LOGGER.info("Download started...."); SampleResult result = new SampleResult(); result.setSampleLabel(getName());/*www . j av a2 s . co m*/ result.setDataType(SampleResult.TEXT); result.sampleStart(); try { BasicAWSCredentials creds = new BasicAWSCredentials(getKey(), getSecret()); AmazonS3 client = new AmazonS3Client(creds); S3Object s3Object = client.getObject(new GetObjectRequest(new S3ObjectId(getBucket(), getObject()))); InputStream is = s3Object.getObjectContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File(getDestination()))); char[] buffer = new char[1024 * 1024]; while (true) { int c = reader.read(buffer); if (c == -1) { break; } bufferedWriter.write(buffer); } reader.close(); bufferedWriter.close(); LOGGER.info("Download finished."); result.setResponseData("Download finished".getBytes()); result.setSuccessful(!false); result.setResponseCode("200"); result.setResponseMessage("Downloaded"); } catch (Exception e) { LOGGER.info("Download error."); result.setResponseData(("Download error: " + e.getMessage()).getBytes()); result.setSuccessful(false); result.setResponseCode("500"); result.setResponseMessage("Error"); } result.sampleEnd(); return result; }
From source file:com.atlantbh.jmeter.plugins.aws.s3.AWSS3Reader.java
License:Apache License
@Override public SampleResult sample(Entry arg0) { LOGGER.info("Read started...."); SampleResult result = new SampleResult(); result.setSampleLabel(getName());//from ww w . j a v a2 s .c o m result.setDataType(SampleResult.TEXT); result.sampleStart(); try { BasicAWSCredentials creds = new BasicAWSCredentials(getKey(), getSecret()); AmazonS3 client = new AmazonS3Client(creds); S3Object s3Object = client.getObject(new GetObjectRequest(new S3ObjectId(getBucket(), getObject()))); InputStream is = s3Object.getObjectContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line); } result.setResponseData(sb.toString().getBytes()); reader.close(); LOGGER.info("Read finished."); result.setSuccessful(!false); result.setResponseCode("200"); result.setResponseMessage("Read done"); result.setContentType("text/plain"); } catch (Exception e) { LOGGER.info("Read error."); result.setResponseData(("Read error: " + e.getMessage()).getBytes()); result.setSuccessful(false); result.setResponseCode("500"); result.setResponseMessage("Error"); } result.sampleEnd(); return result; }
From source file:com.upplication.s3fs.S3Path.java
License:Open Source License
public S3ObjectId toS3ObjectId() { return new S3ObjectId(bucket, getKey()); }
From source file:org.mule.module.s3.S3Connector.java
License:Open Source License
/** * Uploads an object to S3. Supported contents are InputStreams, Strings, byte * arrays and Files.// www . ja va 2 s. c o m * * {@sample.xml ../../../doc/mule-module-s3.xml.sample s3:create-object} * * @param bucketName the object's bucket * @param key the object's key * @param content the content to be uploaded to S3, capable of creating a {@link PutObjectRequest}. * @param contentLength the content length. If content is a InputStream, * this parameter should be specified, as not doing so will * introduce a performance loss as the contents will have to be persisted on disk before being uploaded. * Otherwise, it is ignored. An exception to this * rule are InputStreams returned by Mule Http Connector: if stream has Content-Length * information, it will be used. * In any case a content length of 0 is interpreted as an unspecified content length * @param contentMd5 the content md5, encoded in base 64. If content is a file, * it is ignored. * @param contentType the content type of the new object. * @param contentDisposition the content disposition of the new object. * @param acl the access control list of the new object * @param storageClass the storage class of the new object * @param encryption Encryption method for server-side encryption. Supported value AES256. * @param userMetadata a map of arbitrary object properties keys and values * @return the id of the created object, or null, if versioning is not enabled * @throws IOException if there are problems manipulating the File or InputStream content */ @Processor public String createObject(String bucketName, String key, @Default("#[payload]") Object content, @Optional Long contentLength, @Optional String contentMd5, @Optional String contentType, @Optional String contentDisposition, @Default("PRIVATE") AccessControlList acl, @Default("STANDARD") StorageClass storageClass, @Optional Map<String, String> userMetadata, @Optional String encryption) throws IOException { S3ObjectContent s3Content = S3ContentUtils.createContent(content, contentLength, contentMd5); String response = client.createObject(new S3ObjectId(bucketName, key), s3Content, contentType, contentDisposition, acl.toS3Equivalent(), storageClass.toS3Equivalent(), userMetadata, encryption); if (s3Content instanceof TempFileS3ObjectContent) { ((TempFileS3ObjectContent) s3Content).delete(); } return response; }
From source file:org.mule.module.s3.S3Connector.java
License:Open Source License
/** * Sets the Amazon S3 storage class for the given object. Changing the storage * class of an object in a bucket that has enabled versioning creates a new * version of the object with the new storage class. The existing version of the * object preservers the previous storage class. * * {@sample.xml ../../../doc/mule-module-s3.xml.sample s3:set-object-storage-class} * //from w w w. j a va2 s.c o m * @param bucketName the object's bucket name * @param key the object's key * @param storageClass the storage class to set */ @Processor public void setObjectStorageClass(String bucketName, String key, StorageClass storageClass) { Validate.notNull(storageClass); client.setObjectStorageClass(new S3ObjectId(bucketName, key), storageClass.toS3Equivalent()); }
From source file:org.mule.module.s3.S3Connector.java
License:Open Source License
/** * Creates an http URI for the given object id. The useDefaultServer option * enables using default US Amazon server subdomain in the URI regardless of the * region. The main benefit of such feature is that this operation does not need * to hit the Amazon servers, but the drawback is that using the given URI as an * URL to the resource have unnecessary latency penalties for standard regions * other than US_STANDARD.// ww w. jav a2s . co m * * {@sample.xml ../../../doc/mule-module-s3.xml.sample s3:create-object-uri} * * @param bucketName the object's bucket * @param key the object's key * @param useDefaultServer if the default US Amazon server subdomain should be * used in the URI regardless of the region. * @param secure whether to use http or https * @return a non secure http URI to the object. Unlike the presigned URI, object * must have PUBLIC_READ or PUBLIC_READ_WRITE permission */ @Processor public URI createObjectUri(String bucketName, String key, @Default("false") boolean useDefaultServer, @Default("false") boolean secure) { if (useDefaultServer) { return client.createObjectUriUsingDefaultServer(new S3ObjectId(bucketName, key), secure); } else { return client.createObjectUri(new S3ObjectId(bucketName, key), secure); } }