List of usage examples for com.amazonaws.services.s3.transfer TransferManager TransferManager
protected TransferManager(TransferManagerBuilder builder)
From source file:ecplugins.s3.S3Util.java
License:Apache License
public static boolean isValidFile(String bucketName, String path) throws AmazonClientException, AmazonServiceException, Exception { boolean isValidFile = true; Properties props = TestUtils.getProperties(); BasicAWSCredentials credentials = new BasicAWSCredentials(props.getProperty(StringConstants.ACCESS_ID), props.getProperty(StringConstants.SECRET_ACCESS_ID)); // Create TransferManager TransferManager tx = new TransferManager(credentials); // Get S3 Client AmazonS3 s3 = tx.getAmazonS3Client(); try {//from w w w . j a va 2 s .c om ObjectMetadata objectMetadata = s3.getObjectMetadata(bucketName, path); } catch (AmazonS3Exception s3e) { if (s3e.getStatusCode() == 404) { // i.e. 404: NoSuchKey - The specified key does not exist isValidFile = false; } else { throw s3e; // rethrow all S3 exceptions other than 404 } } return isValidFile; }
From source file:edu.sjsu.cmpe.dropbox.api.resources.S3TransferProgress.java
License:Open Source License
public S3TransferProgress(String Name, AmazonS3 s3Client, MongoTest mongo) { frame = new JFrame("Amazon S3 File Upload"); button = new JButton("Choose File..."); button.addActionListener(new ButtonListener()); this.mongo = mongo; System.out.println("Mongo is" + mongo); System.out.println("this.Mongo is" + this.mongo); pb = new JProgressBar(0, 100); pb.setStringPainted(true);/* w w w. j ava2s . co m*/ frame.setContentPane(createContentPane()); frame.pack(); frame.setVisible(true); s3Client.setEndpoint("http://s3-us-west-1.amazonaws.com"); tx = new TransferManager(s3Client); bucketName = Name; System.out.print("Bucket is" + bucketName); System.out.print("Bucket1 is" + Name); }
From source file:fr.ens.biologie.genomique.eoulsan.data.protocols.S3DataProtocol.java
License:LGPL
/** * Get the AmazonS3 object.// w w w.java 2 s .co m * @return an AmazonS3 */ private AmazonS3 getS3() { if (this.s3 == null) { final Settings settings = EoulsanRuntime.getSettings(); this.s3 = new AmazonS3Client( new BasicAWSCredentials(settings.getAWSAccessKey(), settings.getAWSSecretKey())); getLogger().info("AWS S3 account owner: " + this.s3.getS3AccountOwner()); this.tx = new TransferManager(this.s3); } return this.s3; }
From source file:fr.ens.biologie.genomique.eoulsan.data.protocols.S3DataProtocol.java
License:LGPL
/** * Get transfer manager.//from ww w . j a va 2s . co m * @return the transfer manager */ private TransferManager getTransferManager() { if (this.tx == null) { this.tx = new TransferManager(getS3()); } return this.tx; }
From source file:fr.eurecom.hybris.kvs.drivers.AmazonKvs.java
License:Apache License
public AmazonKvs(String id, final String accessKey, final String secretKey, String container, boolean enabled, int cost) throws IOException { super(id, container, enabled, cost); BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); this.s3 = new AmazonS3Client(credentials); this.tm = new TransferManager(credentials); TransferManagerConfiguration tmc = new TransferManagerConfiguration(); tmc.setMultipartUploadThreshold(30000000L); // 30 MB tmc.setMinimumUploadPartSize(10000000); // 10 MB this.tm.setConfiguration(tmc); this.createContainer(); }
From source file:hu.mta.sztaki.lpds.cloud.entice.imageoptimizer.iaashandler.amazontarget.Storage.java
License:Apache License
/** * @param file Local file to upload//from w ww . j ava 2 s . c om * @param endpoint S3 endpoint URL * @param accessKey Access key * @param secretKey Secret key * @param bucket Bucket name * @param path Key name (path + file name) * @throws Exception On any error */ public static void upload(File file, String endpoint, String accessKey, String secretKey, String bucket, String path) throws Exception { AmazonS3Client amazonS3Client = null; try { AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setMaxConnections(MAX_CONNECTIONS); clientConfiguration.setMaxErrorRetry(PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY); clientConfiguration.setConnectionTimeout(ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT); amazonS3Client = new AmazonS3Client(awsCredentials, clientConfiguration); S3ClientOptions clientOptions = new S3ClientOptions().withPathStyleAccess(true); amazonS3Client.setS3ClientOptions(clientOptions); amazonS3Client.setEndpoint(endpoint); // amazonS3Client.putObject(new PutObjectRequest(bucket, path, file)); // up to 5GB TransferManager tm = new TransferManager(amazonS3Client); // up to 5TB Upload upload = tm.upload(bucket, path, file); // while (!upload.isDone()) { upload.getProgress().getBytesTransferred(); Thread.sleep(1000); } // to get progress upload.waitForCompletion(); tm.shutdownNow(); } catch (AmazonServiceException x) { Shrinker.myLogger.info("upload error: " + x.getMessage()); throw new Exception("upload exception", x); } catch (AmazonClientException x) { Shrinker.myLogger.info("upload error: " + x.getMessage()); throw new Exception("upload exception", x); } finally { if (amazonS3Client != null) { try { amazonS3Client.shutdown(); } catch (Exception e) { } } } }
From source file:it.openutils.mgnlaws.magnolia.datastore.S3DataStore.java
License:Open Source License
/** * {@inheritDoc}/*from ww w . j a v a 2 s . c om*/ */ public void init(String homeDir) throws RepositoryException { // init S3 client amazonS3 = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey)); // set endpoint if (StringUtils.isNotBlank(endpoint)) { amazonS3.setEndpoint(endpoint); } // init transfer manager transferManager = new TransferManager(amazonS3); // initialize tmp directory if (StringUtils.isNotBlank(tmpPath)) { tmpDirectory = new File(tmpPath); if (!tmpDirectory.exists()) { tmpDirectory.mkdirs(); } } if (tmpDirectory == null || !tmpDirectory.isDirectory()) { tmpDirectory = new File(System.getProperty("java.io.tmpdir")); } if (useCache) { // initialize cache directory if (StringUtils.isNotBlank(cacheDirectoryPath)) { cacheDirectory = new File(cacheDirectoryPath); if (!cacheDirectory.exists()) { cacheDirectory.mkdirs(); } } if (cacheDirectory == null || !cacheDirectory.isDirectory()) { cacheDirectory = new File(System.getProperty("java.io.tmpdir"), cacheName); if (!cacheDirectory.exists()) { cacheDirectory.mkdirs(); } } // create cache manager CacheManager cacheManager; if (StringUtils.startsWith(cacheConfigFile, "classpath:")) { URL configurationFileURL = getClass() .getResource(StringUtils.substringAfter(cacheConfigFile, "classpath:")); cacheManager = CacheManager.newInstance(configurationFileURL); } else { cacheManager = CacheManager.newInstance(cacheConfigFile); } // get cache cache = cacheManager.getCache(cacheName); // register cache listener cache.getCacheEventNotificationService().registerListener(new S3CacheListener(cacheDirectory)); } }
From source file:jenkins.plugins.itemstorage.s3.S3Callable.java
License:Open Source License
/** * Override this if you don't want a transfer manager *//* w w w. j av a 2 s .c o m*/ @Override public T invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { TransferManager transferManager = new TransferManager(helper.client()); try { return invoke(transferManager, f, channel); } finally { transferManager.shutdownNow(); } }
From source file:jp.dqneo.amazons3.sample.S3TransferProgressSample.java
License:Open Source License
public static void main(String[] args) throws Exception { credentials = new PropertiesCredentials( S3TransferProgressSample.class.getResourceAsStream("AwsCredentials.properties")); // TransferManager manages a pool of threads, so we create a // single instance and share it throughout our application. tx = new TransferManager(credentials); bucketName = "s3-transfer-progress-jp.dqneo.amazons3.sample-" + credentials.getAWSAccessKeyId().toLowerCase(); new S3TransferProgressSample(); }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
@Override public F.Promise<Void> store(Path path, String key, String name) { Promise<Void> promise = Futures.promise(); TransferManager transferManager = new TransferManager(credentials); try {//from w ww . j a v a 2s .c o m Upload upload = transferManager.upload(bucketName, key, path.toFile()); upload.addProgressListener((ProgressListener) progressEvent -> { if (progressEvent.getEventType().isTransferEvent()) { if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_COMPLETED_EVENT)) { transferManager.shutdownNow(); promise.success(null); } else if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_FAILED_EVENT)) { transferManager.shutdownNow(); logger.error(progressEvent.toString()); promise.failure(new Exception(progressEvent.toString())); } } }); } catch (AmazonServiceException ase) { logAmazonServiceException(ase); } catch (AmazonClientException ace) { logAmazonClientException(ace); } return F.Promise.wrap(promise.future()); }