Example usage for com.amazonaws.services.s3.model GetObjectRequest GetObjectRequest

List of usage examples for com.amazonaws.services.s3.model GetObjectRequest GetObjectRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model GetObjectRequest GetObjectRequest.

Prototype

public GetObjectRequest(String bucketName, String key) 

Source Link

Document

Constructs a new GetObjectRequest with all the required parameters.

Usage

From source file:com.davidsoergel.s3napback.StreamingTransferManager.java

License:Apache License

public Download download(String bucket, String key, final BufferedOutputStream os) {
    return download(new GetObjectRequest(bucket, key), os);
}

From source file:com.digitaslbi.helios.mock.utils.ConnectionHelper.java

public static InputStream getObject(String key) {
    try {//from  w  w  w .j  a  v a  2 s.  c o  m
        log.debug("Downloading an object");

        S3Object s3object = s3Client.getObject(
                new GetObjectRequest(prop.getProperty(MocksConstants.AWS_BUCKET_NAME.getValue()), key));

        log.debug("Content-Type: " + s3object.getObjectMetadata().getContentType());
        //displayTextInputStream(s3object.getObjectContent());

        return s3object.getObjectContent();
    } catch (AmazonServiceException ase) {
        log.error("Caught an AmazonServiceException, which" + " means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        log.error("Error Message:    " + ase.getMessage());
        log.error("HTTP Status Code: " + ase.getStatusCode());
        log.error("AWS Error Code:   " + ase.getErrorCode());
        log.error("Error Type:       " + ase.getErrorType());
        log.error("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        log.error("Caught an AmazonClientException, which means" + " the client encountered "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        log.error("Error Message: " + ace.getMessage());
    }

    return null;
}

From source file:com.digitaslbi.helios.utils.S3Helper.java

public static File getObject(String key) {
    connect();/*  w  ww  .  ja  v  a2  s .co  m*/

    try {
        log.info("[S3Helper][getObject] Downloading an object");

        S3Object s3object = s3Client
                .getObject(new GetObjectRequest(S3Properties.getInstance().getBucketName(), key));
        byte[] contentBytes = IOUtils.toByteArray(s3object.getObjectContent());

        log.info("Content-Type: " + s3object.getObjectMetadata().getContentType());

        File aux = new File();
        aux.setPath(s3object.getKey());
        aux.setIsFile(true);
        aux.setContent(new String(Base64.encodeBase64String(contentBytes)));

        return aux;
    } catch (AmazonServiceException ase) {
        log.error(
                "[S3Helper][getObject] Caught an AmazonServiceException, which" + " means your request made it "
                        + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        log.error("Error Message:    " + ase.getMessage());
        log.error("HTTP Status Code: " + ase.getStatusCode());
        log.error("AWS Error Code:   " + ase.getErrorCode());
        log.error("Error Type:       " + ase.getErrorType());
        log.error("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        log.error("[S3Helper][getObject] Caught an AmazonClientException, which means"
                + " the client encountered " + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        log.error("Error Message: " + ace.getMessage());
    } catch (IOException e) {
        log.error("[S3Helper][getObject] Error: " + e);
    }

    return null;
}

From source file:com.dongli.model.MyJSONData.java

License:Open Source License

public static MyJSONObject queryObject(String uid) throws MyRESTException {

    String jsonStr = "";
    MyJSONObject myJSONObject = new MyJSONObject();

    try {/*  w  w w .  ja v a  2  s. c o m*/
        // send query command to AWS S3
        S3Object s3object = MyAWSStorage.getInstance().s3client
                .getObject(new GetObjectRequest(MyConfiguration.getInstance().bucket, uid));
        jsonStr = displayTextInputStream(s3object.getObjectContent());
        // convert the object file to JSON object
        myJSONObject.setJSONObjectFromString(jsonStr);
    } catch (AmazonServiceException ase) {
        throw new MyRESTException("Failed to query the object " + uid + ".");
    } catch (AmazonClientException ace) {
        throw new MyRESTException("Failed to query the object " + uid + ".");
    } catch (IOException e) {
        throw new MyRESTException("Failed to query the object " + uid + ".");
    }

    return myJSONObject;

}

From source file:com.dragovorn.dragonbot.DragonBot.java

License:Open Source License

@Override
public void start() {
    setState(BotState.STARTING);// w  ww .ja  v  a 2 s.c  o  m

    AmazonS3 client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
    this.transferManager = TransferManagerBuilder.standard().withS3Client(client).build();

    UpdatePanel update = new UpdatePanel();

    new MainWindow(update);

    if (Bot.getInstance().getConfiguration().getCheckForUpdates()) {
        getLogger().info("Checking for newer version of the updater...");

        try {
            if (client
                    .getObjectMetadata(
                            new GetObjectMetadataRequest("dl.dragovorn.com", "DragonBot/updater.jar"))
                    .getLastModified().getTime() > FileManager.getUpdater().lastModified()) {
                getLogger().info("Found a newer version of the updater, downloading it now...");

                FileManager.getUpdater().delete();

                GetObjectRequest request = new GetObjectRequest("dl.dragovorn.com", "DragonBot/updater.jar");

                try {
                    this.transferManager.download(request, FileManager.getUpdater()).waitForCompletion();
                } catch (InterruptedException exception) {
                    /* Shouldn't happen */ }
            }
        } catch (Throwable throwable) {
            getLogger().info("Unable to connect to the internet!");
        }

        getLogger().info("Checking for updates...");
        update.update();

        if (update.shouldStop()) {
            stop();
            return;
        }
    }

    getLogger().info("Initializing Dragon Bot v" + getVersion() + "!");

    this.name = this.config.getName();
    this.auth = this.config.getAuth();

    this.commandManager.registerCommand(new Github());
    this.commandManager.registerCommand(new VersionCmd());

    this.pluginManager.enablePlugins();

    if (!this.name.equals("") && !this.config.getAuth().equals("")) {
        getLogger().info("Connecting to twitch!");

        try {
            connect();
        } catch (ConnectionException | IOException exception) {
            getLogger().info("Unable to connect!");
        }

        if (this.config.getAutoConnect() && !this.config.getChannel().equals("")) {
            getLogger().info("Automatically connected to " + this.config.getChannel());

            connectTo("#" + this.config.getChannel());
        }
    } else {
        String buttons[] = { "Ok" };

        JOptionPane.showOptionDialog(null,
                "You don't have a twitch account configured! Please set the bot's twitch account in the options menu!",
                "Twitch Account", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, buttons,
                buttons[0]);

        getLogger().info("No twitch account detected.");
    }

    if (!this.isConnected()) {
        MainWindow.getInstance().getChannelButton().setEnabled(false);
        MainWindow.getInstance().getChannelButton()
                .setToolTipText("The current account was unable to connect!");
    }

    setState(BotState.RUNNING);

    MainWindow.getInstance().setContentPane(MainWindow.getInstance().getPanel());
    MainWindow.getInstance().pack();
    MainWindow.getInstance().center();

    getLogger().info("Dragon Bot v" + getVersion() + " initialized!");
}

From source file:com.eBilling.util.S3Example.java

void downloadfile(AWSCredentials credentials2) throws IOException {
    AmazonS3 s3client = new AmazonS3Client(credentials2);
    try {// www .  j a v  a2  s  .c  o m
        System.out.println("Downloading an object");
        S3Object s3object = s3client.getObject(new GetObjectRequest(bucketName, keyName));
        System.out.println("Content-Type: " + s3object.getObjectMetadata().getContentType());
        InputStream input = s3object.getObjectContent();

        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        while (true) {
            String line = reader.readLine();
            if (line == null)
                break;

            System.out.println("    " + line);
        }
        System.out.println();
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which" + " means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means" + " the client encountered "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:com.epam.dlab.module.aws.AdapterS3File.java

License:Apache License

/**
 * Open the source file and return reader.
 *
 * @throws AdapterException// www . j ava2 s.c  om
 */
private InputStream getFileStream() throws AdapterException {
    try {
        GetObjectRequest request = new GetObjectRequest(bucket, getCurrentFileName());
        S3Object object = clientS3.getObject(request);
        lastModificationDate = object.getObjectMetadata().getLastModified();
        return object.getObjectContent();
    } catch (Exception e) {
        throw new AdapterException("Cannot open file " + bucket + DELIMITER + getCurrentFileName() + ". "
                + e.getLocalizedMessage(), e);
    }
}

From source file:com.eucalyptus.blockstorage.S3SnapshotTransfer.java

License:Open Source License

/**
 * Downloads the compressed snapshot from objectstorage gateway to the filesystem
 *//*from   w w w .  j  a  v  a  2  s.  c om*/
@Override
public void download(final String destinationFileName) throws SnapshotTransferException {
    LOG.debug("Downloading snapshot from objectstorage: snapshotId=" + snapshotId + ", bucket=" + bucketName
            + ", key=" + keyName + ", destinationFile=" + destinationFileName);
    validateInput();
    try {
        retryAfterRefresh(new Function<GetObjectRequest, ObjectMetadata>() {

            @Override
            @Nullable
            public ObjectMetadata apply(@Nullable GetObjectRequest arg0) {
                eucaS3Client.refreshEndpoint();
                return eucaS3Client.getObject(arg0, new File(destinationFileName));
            }

        }, new GetObjectRequest(bucketName, keyName), REFRESH_TOKEN_RETRIES);
    } catch (Exception e) {
        LOG.warn("Failed to download snapshot from objectstorage: snapshotId=" + snapshotId + ", bucket="
                + bucketName + ", key=" + keyName);
        throw new SnapshotTransferException("Failed to download snapshot from objectstorage: snapshotId="
                + snapshotId + ", bucket=" + bucketName + ", key=" + keyName, e);
    }
}

From source file:com.eucalyptus.blockstorage.SnapshotObjectOps.java

License:Open Source License

public void downloadSnapshot(String snapshotBucket, String snapshotLocation, File tmpCompressedFile)
        throws EucalyptusCloudException {
    GetObjectRequest getObjectRequest = new GetObjectRequest(snapshotBucket, snapshotLocation);
    try {/*  ww  w  . j  av a2 s. com*/
        long startTime = System.currentTimeMillis();
        s3Client.getS3Client().getObject(getObjectRequest, tmpCompressedFile);
        LOG.info("Snapshot " + snapshotBucket + "/" + snapshotLocation + " download took "
                + Long.toString(System.currentTimeMillis() - startTime) + "ms");
    } catch (Exception ex) {
        LOG.error("Snapshot download failed for: " + snapshotLocation, ex);
        throw new EucalyptusCloudException(ex);
    }
}

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public GetObjectResponseType getObject(final GetObjectType request) throws S3Exception {
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;
    GetObjectRequest getRequest = new GetObjectRequest(request.getBucket(), request.getKey());
    try {/*from   w ww. j av  a2s.com*/
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        GetObjectResponseType reply = request.getReply();
        S3Object response;
        response = s3Client.getObject(getRequest);
        populateResponseMetadata(reply, response.getObjectMetadata());
        reply.setDataInputStream(response.getObjectContent());
        return reply;
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }
}