org.jets3t.service.utils.MultipartUtils Java Examples

The following examples show how to use org.jets3t.service.utils.MultipartUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Jets3tNativeFileSystemStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public void storeLargeFile(String key, File file, byte[] md5Hash)
    throws IOException {
  S3Object object = new S3Object(key);
  object.setDataInputFile(file);
  object.setContentType("binary/octet-stream");
  object.setContentLength(file.length());
  object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
  if (md5Hash != null) {
    object.setMd5Hash(md5Hash);
  }

  List<StorageObject> objectsToUploadAsMultipart =
      new ArrayList<StorageObject>();
  objectsToUploadAsMultipart.add(object);
  MultipartUtils mpUtils = new MultipartUtils(multipartBlockSize);

  try {
    mpUtils.uploadObjects(bucket.getName(), s3Service,
                          objectsToUploadAsMultipart, null);
  } catch (Exception e) {
    handleException(e, key);
  }
}
 
Example #2
Source File: Jets3tNativeFileSystemStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void storeLargeFile(String key, File file, byte[] md5Hash)
    throws IOException {
  S3Object object = new S3Object(key);
  object.setDataInputFile(file);
  object.setContentType("binary/octet-stream");
  object.setContentLength(file.length());
  object.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
  if (md5Hash != null) {
    object.setMd5Hash(md5Hash);
  }

  List<StorageObject> objectsToUploadAsMultipart =
      new ArrayList<StorageObject>();
  objectsToUploadAsMultipart.add(object);
  MultipartUtils mpUtils = new MultipartUtils(multipartBlockSize);

  try {
    mpUtils.uploadObjects(bucket.getName(), s3Service,
                          objectsToUploadAsMultipart, null);
  } catch (Exception e) {
    handleException(e, key);
  }
}
 
Example #3
Source File: S3FileSink.java    From suro with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public S3FileSink(
        @JsonProperty("localFileSink") LocalFileSink localFileSink,
        @JsonProperty("bucket") String bucket,
        @JsonProperty("s3Endpoint") String s3Endpoint,
        @JsonProperty("maxPartSize") long maxPartSize,
        @JsonProperty("concurrentUpload") int concurrentUpload,
        @JsonProperty("notice") Notice notice,
        @JsonProperty("prefixFormatter") RemotePrefixFormatter prefixFormatter,
        @JsonProperty("batchUpload") boolean batchUpload,
        @JsonProperty("s3Acl") String s3Acl,
        @JsonProperty("s3AclRetries") int s3AclRetries,
        @JacksonInject MultipartUtils mpUtils,
        @JacksonInject AWSCredentialsProvider credentialProvider) {
    super(localFileSink, prefixFormatter, concurrentUpload, batchUpload);

    this.bucket = bucket;
    this.s3Endpoint = s3Endpoint == null ? "s3.amazonaws.com" : s3Endpoint;
    this.maxPartSize = maxPartSize == 0 ? 20 * 1024 * 1024 : maxPartSize;
    this.notice = notice == null ? new QueueNotice<String>() : notice;

    this.mpUtils = mpUtils;
    this.credentialsProvider = credentialProvider;

    this.s3Acl = s3Acl;
    this.s3AclRetries = s3AclRetries > 0 ? s3AclRetries : 5;

    Preconditions.checkNotNull(bucket, "bucket is needed");
}
 
Example #4
Source File: TestS3FileSink.java    From suro with Apache License 2.0 4 votes vote down vote up
private Injector getInjector() {
    return Guice.createInjector(
        new SuroSinkPlugin(),
        new AbstractModule() {
                @Override
                protected void configure() {
                    bind(ObjectMapper.class).to(DefaultObjectMapper.class);
                    bind(AWSCredentialsProvider.class)
                        .toInstance(new AWSCredentialsProvider() {
                            @Override
                            public AWSCredentials getCredentials() {
                                return new AWSCredentials() {
                                    @Override
                                    public String getAWSAccessKeyId() {
                                        return "accessKey";
                                    }

                                    @Override
                                    public String getAWSSecretKey() {
                                        return "secretKey";
                                    }
                                };
                            }

                            @Override
                            public void refresh() {
                            }
                        });

                    MultipartUtils mpUtils = mock(MultipartUtils.class);
                    try {
                        doAnswer(new Answer() {
                            @Override
                            public Object answer(InvocationOnMock invocation) throws Throwable {
                                Thread.sleep(1000);
                                return null;
                            }
                        }).when(mpUtils).uploadObjects(
                            any(String.class),
                            any(RestS3Service.class),
                            any(List.class),
                            any(S3ServiceEventListener.class));

                        bind(MultipartUtils.class).toInstance(mpUtils);
                    } catch (Exception e) {
                        Assert.fail(e.getMessage());
                    }
                    bind(SpaceChecker.class).toInstance(mock(SpaceChecker.class));
                }
        }
    );
}