Package com.amazonaws.services.s3

Examples of com.amazonaws.services.s3.AmazonS3


        assert isNotBlank(bucketName);
        assert isNotBlank(key);
        assert targetDirectory != null && targetDirectory.isDirectory();
        assert namingStrategy != null;

        final AmazonS3 connection = acquireClient(clientOptions);

        File tempFile = null;
        try {

            tempFile = createTempFile(
                    join(asList(targetDirectory.getName(), currentTimeMillis(),
                            "part"), "-"), "tmp", targetDirectory);
            tempFile.deleteOnExit();

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format(
                        "Downloading object %1$s from bucket %2$s to temp file %3$s",
                        key, bucketName, tempFile.getName()));
            }

            connection.getObject(new GetObjectRequest(bucketName, key),
                    tempFile);

            final File targetFile = new File(targetDirectory,
                    namingStrategy.determineFileName(key));
            tempFile.renameTo(targetFile);
View Full Code Here


        assert clientOptions != null;
        assert isNotBlank(bucketName);
        assert isNotBlank(sourcePath);
        assert targetDirectory != null;

        final AmazonS3 connection = acquireClient(clientOptions);

        // List the objects in the source directory on S3
        final List<S3ObjectSummary> objectSummaries = listDirectory(bucketName,
                sourcePath, connection);
        final List<File> files = new ArrayList<File>();
View Full Code Here

        // Skip spinning up an S3 connection when no files will be sent ...
        if (isEmpty(files)) {
            return;
        }

        final AmazonS3 client = acquireClient(clientOptions);

        // Send the files to S3 using the passed ObjectNaming strategy to
        // determine the key ...
        for (final File file : files) {
            final String key = namingStrategy.determineKey(file);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format(
                        "Putting file %1$s into bucket %2$s with key %3$s.",
                        file.getAbsolutePath(), bucketName, key));
            }
            client.putObject(bucketName, key, file);
        }

    }
View Full Code Here

        assert clientOptions != null;
        assert isNotBlank(bucketName);
        assert isNotBlank(key);

        final AmazonS3 client = acquireClient(clientOptions);

        client.deleteObject(bucketName, key);

    }
View Full Code Here

        assert clientOptions != null;
        assert isNotBlank(bucketName);
        assert isNotBlank(directoryName);

        final AmazonS3 client = acquireClient(clientOptions);

        final List<S3ObjectSummary> objects = listDirectory(bucketName,
                directoryName, client);

        for (final S3ObjectSummary object : objects) {

            client.deleteObject(bucketName, object.getKey());

        }

        client.deleteObject(bucketName, directoryName);

    }
View Full Code Here

        assert clientOptions != null;
        assert isNotBlank(bucketName);

        try {

            final AmazonS3 client = acquireClient(clientOptions);

            final String fileContent = "testing put and delete";
            final InputStream inputStream = new ByteArrayInputStream(
                    fileContent.getBytes());
            final String key = UUID.randomUUID().toString() + ".txt";

            final ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentLength(fileContent.length());

            client.putObject(bucketName, key, inputStream, metadata);
            client.deleteObject(bucketName, key);

            return true;

        } catch (AmazonClientException e) {
View Full Code Here

        s3ClientHelper.client(new URI("s3://fo/o:inv%2Falid@baz"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNoCredentials() throws Exception {
        AmazonS3 s3Client = s3ClientHelper.client(new URI("s3://host/path/to/file"));

        // use this method without accessing the internet
        // should throw
        //     IllegalArgumentException: Access key cannot be null.
        // in BasicAWSCredentials
        s3Client.generatePresignedUrl("bucket", "key", new Date());
    }
View Full Code Here

        s3Client.generatePresignedUrl("bucket", "key", new Date());
    }

    @Test
    public void testWithCredentials() throws Exception {
        AmazonS3 s3Client = s3ClientHelper.client(new URI("s3://user:password@host/path"));
        URL url = s3Client.generatePresignedUrl("bucket", "key", new Date(0L));
        assertThat(url.toString(), is("http://bucket.s3.amazonaws.com/key?AWSAccessKeyId=user&Expires=0&Signature=o5V2voSQbVEErsUXId6SssCq9OY%3D"));
    }
View Full Code Here

                    @Override
                    public FileInput create() throws IOException {
                        return new S3FileInput(new S3ClientHelper() {
                            @Override
                            protected AmazonS3 initClient(String accessKey, String secretKey) throws IOException {
                                AmazonS3 client = mock(AmazonS3Client.class);
                                ObjectListing objectListing = mock(ObjectListing.class);
                                S3ObjectSummary summary = mock(S3ObjectSummary.class);
                                S3Object s3Object = mock(S3Object.class);

                                S3ObjectInputStream inputStream = mock(S3ObjectInputStream.class);

                                when(client.listObjects(anyString(), anyString())).thenReturn(objectListing);
                                when(objectListing.getObjectSummaries()).thenReturn(Arrays.asList(summary));
                                when(summary.getKey()).thenReturn("foo");
                                when(client.getObject("fakebucket", "foo")).thenReturn(s3Object);
                                when(s3Object.getObjectContent()).thenReturn(inputStream);
                                when(inputStream.read(new byte[anyInt()], anyInt(), anyByte())).thenReturn(-1);
                                when(client.listNextBatchOfObjects(any(ObjectListing.class))).thenReturn(objectListing);
                                when(objectListing.isTruncated()).thenReturn(false);
                                return client;
                            }
                        });
                    }
View Full Code Here

        return client(accessKey, secretKey);
    }

    private AmazonS3 client(@Nullable String accessKey, @Nullable String secretKey) throws IOException {
        int hash = hash(accessKey, secretKey);
        AmazonS3 client = clientMap.get(hash);
        if (client == null) {
            client = initClient(accessKey, secretKey);
            clientMap.put(hash, client);
        }
        return client;
View Full Code Here

TOP

Related Classes of com.amazonaws.services.s3.AmazonS3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.