use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project adeptj-modules by AdeptJ.
the class AwsS3Service method createFolder.
/**
* {@inheritDoc}
*/
@Override
public S3Response createFolder(String bucketName, String folderName) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(0);
try {
return new S3Response().withPutObjectResult(this.s3Client.putObject(new PutObjectRequest(bucketName, folderName + PATH_SEPARATOR, new ByteArrayInputStream(new byte[0]), objectMetadata)));
} catch (RuntimeException ex) {
LOGGER.error("Exception while creating folder!!", ex);
throw new AwsException(ex.getMessage(), ex);
}
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project sandbox by irof.
the class S3MultipartUploadTest method 比較用の通常のputObject.
@Ignore
@Test
public void 比較用の通常のputObject() throws Exception {
byte[] bytes = new byte[5 * Constants.MB + 1];
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(bytes.length);
PutObjectRequest putObjectRequest = new PutObjectRequest("irof-sandbox", "S3MultipartUpload/basic-5MB.dat", new ByteArrayInputStream(bytes), meta);
PutObjectResult result = new AmazonS3Client().putObject(putObjectRequest);
logger.info(result.getETag());
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project sandbox by irof.
the class S3Test method putWithInputStream.
@Test
public void putWithInputStream() throws Exception {
try (InputStream input = new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8))) {
ObjectMetadata metaData = new ObjectMetadata();
// 可能なら設定する。設定しなかったらデフォルト値が使われる。
metaData.setContentType("text/plain");
// 設定しなくても計算されるぽいのでスルーでよさげ
// metaData.setContentMD5("CY9rzUYh03PK3k6DJie09g==");
// オプションだけど、できるかぎり設定する。
// 設定しないとWARNログ出ちゃうし、違う値を設定すると例外出る。
// metaData.setContentLength(3);
PutObjectRequest request = new PutObjectRequest("irof-sandbox", "byteFile.txt", input, metaData);
PutObjectResult result = s3.putObject(request);
assertThat(result.getETag(), is("098f6bcd4621d373cade4e832627b4f6"));
}
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project stocator by CODAIT.
the class COSAPIClient method isSparkOrigin.
/**
* Checks if container/object exists and verifies that it contains
* Data-Origin=stocator metadata If so, object was created by Spark.
*
* @param objectKey the key of the object
* @param path the object path
* @return boolean if object was created by Spark
*/
private boolean isSparkOrigin(String objectKey, String path) {
LOG.debug("check spark origin for {}", objectKey);
if (!objectKey.endsWith("/")) {
LOG.debug("Key {} has no slash. Return false", objectKey);
return false;
} else {
objectKey = objectKey.substring(0, objectKey.length() - 1);
}
if (mCachedSparkOriginated.containsKey(objectKey)) {
boolean res = mCachedSparkOriginated.get(objectKey).booleanValue();
LOG.debug("found cached for spark origin for {}. Status {}", objectKey, res);
return res;
}
String key = getRealKey(objectKey);
Boolean sparkOriginated = Boolean.FALSE;
ObjectMetadata objMetadata = getObjectMetadata(key);
if (objMetadata != null) {
Object sparkOrigin = objMetadata.getUserMetaDataOf("data-origin");
if (sparkOrigin != null) {
String tmp = (String) sparkOrigin;
if (tmp.equals("stocator")) {
sparkOriginated = Boolean.TRUE;
}
}
}
mCachedSparkOriginated.put(key, sparkOriginated);
LOG.debug("spark origin for {} is {} non cached", objectKey, sparkOriginated.booleanValue());
return sparkOriginated.booleanValue();
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project stocator by CODAIT.
the class COSAPIClient method createObject.
@Override
public FSDataOutputStream createObject(String objName, String contentType, Map<String, String> metadata, Statistics statistics) throws IOException {
LOG.debug("Create object {}", objName);
try {
String objNameWithoutBuket = objName;
if (objName.startsWith(mBucket + "/")) {
objNameWithoutBuket = objName.substring(mBucket.length() + 1);
}
if (blockUploadEnabled) {
return new FSDataOutputStream(new COSBlockOutputStream(this, objNameWithoutBuket, new SemaphoredDelegatingExecutor(threadPoolExecutor, blockOutputActiveBlocks, true), partSize, blockFactory, contentType, new WriteOperationHelper(objNameWithoutBuket), metadata), null);
}
if (!contentType.equals(Constants.APPLICATION_DIRECTORY)) {
return new FSDataOutputStream(new COSOutputStream(mBucket, objName, mClient, contentType, metadata, transfers, this), statistics);
} else {
final InputStream im = new InputStream() {
@Override
public int read() throws IOException {
return -1;
}
};
final ObjectMetadata om = new ObjectMetadata();
om.setContentLength(0L);
om.setContentType(contentType);
om.setUserMetadata(metadata);
// Remove the bucket name prefix from key path
if (objName.startsWith(mBucket + "/")) {
objName = objName.substring(mBucket.length() + 1);
}
/*
if (!objName.endsWith("/")) {
objName = objName + "/";
}*/
LOG.debug("bucket: {}, key {}", mBucket, objName);
PutObjectRequest putObjectRequest = new PutObjectRequest(mBucket, objName, im, om);
Upload upload = transfers.upload(putObjectRequest);
upload.waitForUploadResult();
OutputStream fakeStream = new OutputStream() {
@Override
public void write(int b) throws IOException {
}
@Override
public void close() throws IOException {
super.close();
}
};
return new FSDataOutputStream(fakeStream, statistics);
}
} catch (InterruptedException e) {
throw new InterruptedIOException("Interrupted creating " + objName);
} catch (IOException e) {
LOG.error(e.getMessage());
throw e;
}
}
Aggregations