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

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

Introduction

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

Prototype

public GetObjectMetadataRequest(String bucketName, String key) 

Source Link

Document

Constructs a new GetObjectMetadataRequest used to retrieve a specified object's metadata.

Usage

From source file:cloudExplorer.RestoreObject.java

License:Open Source License

public void run() {
    String message = null;/*from  w  ww.ja  v  a 2s.  c  om*/
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    File file = new File(what);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);

    try {
        GetObjectMetadataRequest request = new GetObjectMetadataRequest(bucket, what);
        ObjectMetadata response = s3Client.getObjectMetadata(request);
        response.getOngoingRestore();

        mainFrame.jTextArea1.append("\nRestored operation ran for Object: " + what
                + ". Please examiene this window for any errors.");
        mainFrame.calibrateTextArea();

    } catch (Exception get) {
        //  mainFrame.jTextArea1.append("\n\nError Message: " + get.getMessage());
    }

    calibrate();
}

From source file:com.amediamanager.service.VideoServiceImpl.java

License:Apache License

@Override
public Video save(String bucket, String videoKey) throws ParseException {

    // From bucket and key, get metadata from video that was just uploaded
    GetObjectMetadataRequest metadataReq = new GetObjectMetadataRequest(bucket, videoKey);
    ObjectMetadata metadata = s3Client.getObjectMetadata(metadataReq);
    Map<String, String> userMetadata = metadata.getUserMetadata();

    Video video = new Video();

    video.setDescription(userMetadata.get("description"));
    video.setOwner(userMetadata.get("owner"));
    video.setId(userMetadata.get("uuid"));
    video.setTitle(userMetadata.get("title"));
    video.setPrivacy(Privacy.fromName(userMetadata.get("privacy")));
    video.setCreatedDate(new SimpleDateFormat("MM/dd/yyyy").parse(userMetadata.get("createddate")));
    video.setOriginalKey(videoKey);/*  ww  w  . j  ava2  s  . co m*/
    video.setBucket(userMetadata.get("bucket"));
    video.setUploadedDate(new Date());

    Set<Tag> tags = new HashSet<Tag>();
    for (String tag : userMetadata.get("tags").split(",")) {
        tags.add(new Tag(tag.trim()));
    }
    video.setTags(tags);

    save(video);

    return video;
}

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

License:Open Source License

@Override
public void start() {
    setState(BotState.STARTING);/*ww w.j  a va 2 s.com*/

    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.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public HeadObjectResponseType headObject(final HeadObjectType request) throws S3Exception {
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    GetObjectMetadataRequest getMetadataRequest = new GetObjectMetadataRequest(request.getBucket(),
            request.getKey());//from   w w w . j  a  v a  2s  . c o  m
    getMetadataRequest.setVersionId(request.getVersionId());
    try {
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        ObjectMetadata metadata;
        metadata = s3Client.getObjectMetadata(getMetadataRequest);

        HeadObjectResponseType reply = request.getReply();
        populateResponseMetadata(reply, metadata);
        return reply;
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }

}

From source file:com.ikanow.infinit.e.harvest.extraction.document.file.AwsInfiniteFile.java

License:Open Source License

@Override
public void rename(String newPathName) throws IOException {
    try {/*from w w  w.jav a2 s  .c  o  m*/
        String oldBucket = _awsBucketName;
        String oldName = _awsObjectName;
        getBucketAndObjectName(newPathName, true); // (renames self)
        _awsObjectName = new URI("").resolve(_awsObjectName).getPath(); // (resolve relative paths)

        // Check parent directory exists:
        int index = _awsObjectName.lastIndexOf('/');
        if (index > 0) {
            String oldParentDir = _awsObjectName.substring(0, 1 + index); // (don't include the "/" so will try to create)

            GetObjectMetadataRequest objMetaRequest = new GetObjectMetadataRequest(_awsBucketName,
                    oldParentDir);
            ((AmazonS3Client) _awsClient).getObjectMetadata(objMetaRequest);
        }
        // Create actual file:

        ((AmazonS3Client) _awsClient).copyObject(oldBucket, oldName, _awsBucketName, _awsObjectName);

        _awsBucketName = oldBucket;
        _awsObjectName = oldName; // (copy back again before deleting)
        delete(); // (original, only gets this far if the copyObject succeeds, else it exceptions out)
    } catch (AmazonS3Exception e) {
        throw new IOException(e.getMessage());
    } catch (URISyntaxException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.liferay.portal.store.s3.S3Store.java

License:Open Source License

@Override
public long getFileSize(long companyId, long repositoryId, String fileName) throws PortalException {

    String headVersionLabel = getHeadVersionLabel(companyId, repositoryId, fileName);

    String key = _s3KeyTransformer.getFileVersionKey(companyId, repositoryId, fileName, headVersionLabel);

    GetObjectMetadataRequest getObjectMetadataRequest = new GetObjectMetadataRequest(_bucketName, key);

    ObjectMetadata objectMetadata = _amazonS3.getObjectMetadata(getObjectMetadataRequest);

    if (objectMetadata == null) {
        throw new NoSuchFileException(companyId, repositoryId, fileName);
    }/*from   w w  w. j  a va2s.  co  m*/

    return objectMetadata.getContentLength();
}

From source file:com.upplication.s3fs.AmazonS3Client.java

License:Open Source License

public void multipartCopyObject(S3Path s3Source, S3Path s3Target, Long objectSize, S3MultipartOptions opts) {

    final String sourceBucketName = s3Source.getBucket();
    final String sourceObjectKey = s3Source.getKey();
    final String targetBucketName = s3Target.getBucket();
    final String targetObjectKey = s3Target.getKey();

    // Step 2: Initialize
    InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest(targetBucketName,
            targetObjectKey);//from   w  w w. ja  v  a 2s  .co m

    InitiateMultipartUploadResult initResult = client.initiateMultipartUpload(initiateRequest);

    // Step 3: Save upload Id.
    String uploadId = initResult.getUploadId();

    // Get object size.
    if (objectSize == null) {
        GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(sourceBucketName,
                sourceObjectKey);
        ObjectMetadata metadataResult = client.getObjectMetadata(metadataRequest);
        objectSize = metadataResult.getContentLength(); // in bytes
    }

    final int partSize = opts.getChunkSize(objectSize);
    ExecutorService executor = S3OutputStream.getOrCreateExecutor(opts.getMaxThreads());
    List<Callable<CopyPartResult>> copyPartRequests = new ArrayList<>();

    // Step 4. create copy part requests
    long bytePosition = 0;
    for (int i = 1; bytePosition < objectSize; i++) {
        long lastPosition = bytePosition + partSize - 1 >= objectSize ? objectSize - 1
                : bytePosition + partSize - 1;

        CopyPartRequest copyRequest = new CopyPartRequest().withDestinationBucketName(targetBucketName)
                .withDestinationKey(targetObjectKey).withSourceBucketName(sourceBucketName)
                .withSourceKey(sourceObjectKey).withUploadId(uploadId).withFirstByte(bytePosition)
                .withLastByte(lastPosition).withPartNumber(i);

        copyPartRequests.add(copyPart(client, copyRequest, opts));
        bytePosition += partSize;
    }

    log.trace(
            "Starting multipart copy from: {} to {} -- uploadId={}; objectSize={}; chunkSize={}; numOfChunks={}",
            s3Source, s3Target, uploadId, objectSize, partSize, copyPartRequests.size());

    List<PartETag> etags = new ArrayList<>();
    List<Future<CopyPartResult>> responses;
    try {
        // Step 5. Start parallel parts copy
        responses = executor.invokeAll(copyPartRequests);

        // Step 6. Fetch all results
        for (Future<CopyPartResult> response : responses) {
            CopyPartResult result = response.get();
            etags.add(new PartETag(result.getPartNumber(), result.getETag()));
        }
    } catch (Exception e) {
        throw new IllegalStateException("Multipart copy reported an unexpected error -- uploadId=" + uploadId,
                e);
    }

    // Step 7. Complete copy operation
    CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest(targetBucketName,
            targetObjectKey, initResult.getUploadId(), etags);

    log.trace("Completing multipart copy uploadId={}", uploadId);
    client.completeMultipartUpload(completeRequest);
}

From source file:com.yahoo.ycsb.db.S3Client.java

License:Open Source License

private Map.Entry<S3Object, ObjectMetadata> getS3ObjectAndMetadata(String bucket, String key,
        SSECustomerKey ssecLocal) {/*from ww  w .  jav  a 2  s  .  c  o m*/
    GetObjectRequest getObjectRequest;
    GetObjectMetadataRequest getObjectMetadataRequest;
    if (ssecLocal != null) {
        getObjectRequest = new GetObjectRequest(bucket, key).withSSECustomerKey(ssecLocal);
        getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key).withSSECustomerKey(ssecLocal);
    } else {
        getObjectRequest = new GetObjectRequest(bucket, key);
        getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key);
    }

    return new AbstractMap.SimpleEntry<>(s3Client.getObject(getObjectRequest),
            s3Client.getObjectMetadata(getObjectMetadataRequest));
}

From source file:com.yahoo.ycsb.utils.connection.S3Connection.java

License:Open Source License

public byte[] read(String key) throws InterruptedException {
    //long starttime = System.currentTimeMillis();
    byte[] bytes = null;
    try {/*from   w w  w.  ja v  a2s.c om*/
        GetObjectRequest getObjectRequest = null;
        GetObjectMetadataRequest getObjectMetadataRequest = null;
        if (ssecKey != null) {
            getObjectRequest = new GetObjectRequest(bucket, key).withSSECustomerKey(ssecKey);
            getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key).withSSECustomerKey(ssecKey);
        } else {
            getObjectRequest = new GetObjectRequest(bucket, key);
            getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key);
        }
        //System.out.println("Get object " + key + " from " + bucket);
        S3Object object = awsClient.getObject(getObjectRequest);
        ObjectMetadata objectMetadata = awsClient.getObjectMetadata(getObjectMetadataRequest);
        //System.out.println("Get object " + key + " from " + bucket + " OK");
        InputStream objectData = object.getObjectContent(); //consuming the stream
        // writing the stream to bytes and to results
        int sizeOfFile = (int) objectMetadata.getContentLength();
        bytes = new byte[sizeOfFile];
        int offset = 0;
        while (offset < sizeOfFile) {
            int chunk_size;

            //read in 4k chunks
            chunk_size = sizeOfFile - offset > 4096 ? 4096 : sizeOfFile - offset;

            int nr_bytes_read = objectData.read(bytes, offset, sizeOfFile - offset);
            offset = offset + nr_bytes_read;

            if (Thread.interrupted()) {
                //System.out.println("interrupt " + key);
                objectData.close();
                throw new InterruptedException();
            }
        }
        //int nr_bytes_read = objectData.read(bytes, 0, sizeOfFile);
        objectData.close();
    } catch (IOException e) {
        logger.warn("Not possible to get the object " + key);
    }
    //long endtime = System.currentTimeMillis();
    //System.out.println("ReadS3: " + key + " " + (endtime - starttime) + " " + region);
    return bytes;
}

From source file:io.druid.storage.s3.ServerSideEncryptingAmazonS3.java

License:Apache License

public ObjectMetadata getObjectMetadata(String bucket, String key) {
    final GetObjectMetadataRequest getObjectMetadataRequest = serverSideEncryption
            .decorate(new GetObjectMetadataRequest(bucket, key));
    return amazonS3.getObjectMetadata(getObjectMetadataRequest);
}