use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project alluxio by Alluxio.
the class S3AOutputStream method close.
@Override
public void close() throws IOException {
if (mClosed) {
return;
}
mLocalOutputStream.close();
String path = getUploadPath();
try {
// Generate the object metadata by setting server side encryption, md5 checksum, the file
// length, and encoding as octet stream since no assumptions are made about the file type
ObjectMetadata meta = new ObjectMetadata();
if (mSseEnabled) {
meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
}
if (mHash != null) {
meta.setContentMD5(new String(Base64.encode(mHash.digest())));
}
meta.setContentLength(mFile.length());
meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
// Generate the put request and wait for the transfer manager to complete the upload
PutObjectRequest putReq = new PutObjectRequest(mBucketName, path, mFile).withMetadata(meta);
getTransferManager().upload(putReq).waitForUploadResult();
} catch (Exception e) {
LOG.error("Failed to upload {}", path, e);
throw new IOException(e);
} finally {
// upload or if the upload failed.
if (!mFile.delete()) {
LOG.error("Failed to delete temporary file @ {}", mFile.getPath());
}
// Set the closed flag, close can be retried until mFile.delete is called successfully
mClosed = true;
}
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project ats-framework by Axway.
the class S3Operations method getFileMetadata.
/**
* Get MD5, size, owner, storage class and last modification time for a desired file in the pointed bucket
*
* @param fileName the file name
*/
@PublicAtsApi
public S3ObjectInfo getFileMetadata(String fileName) {
try {
S3Object element = s3Client.getObject(bucketName, fileName);
if (element != null) {
ObjectMetadata metaData = element.getObjectMetadata();
S3ObjectInfo s3Info = new S3ObjectInfo();
s3Info.setBucketName(fileName);
s3Info.setLastModified(metaData.getLastModified());
s3Info.setMd5(metaData.getETag());
s3Info.setName(element.getKey());
s3Info.setSize(metaData.getContentLength());
return s3Info;
} else {
throw new NoSuchElementException("File with name '" + fileName + "' does not exist!");
}
} catch (Exception e) {
handleExeption(e, "Could not retrieve metadata for S3 object with key '" + fileName + "'");
}
return null;
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project emodb by bazaarvoice.
the class StashReaderTest method testUTF8ClientDecoding.
/**
* Note: This test depends on the default character set to be US-ASCII
*/
@Test
public void testUTF8ClientDecoding() throws Exception {
if (!Charset.defaultCharset().equals(Charsets.US_ASCII)) {
throw new SkipException("testUTF8ClientDecoding() requires default charset to be US-ASCII");
}
String utf8Text = "ชิงรางวัลกันจ้า";
ByteArrayOutputStream splitOut = new ByteArrayOutputStream();
try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(splitOut), Charsets.UTF_8))) {
Map<String, Object> value = ImmutableMap.<String, Object>builder().put("~id", "1").put("~table", "test:table").put("~version", 1).put("~signature", "3a0da59fabf298d389b7b0b59728e887").put("~lastUpdateAt", "2014-08-28T21:24:36.440Z").put("~firstUpdateAt", "2014-06-07T09:51:40.077Z").put("text", utf8Text).build();
String json = JsonHelper.asJson(value);
out.write(json);
out.write("\n");
}
splitOut.close();
S3Object s3Object = new S3Object();
s3Object.setObjectContent(new ByteArrayInputStream(splitOut.toByteArray(), 0, splitOut.size()));
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(splitOut.size());
s3Object.setObjectMetadata(objectMetadata);
AmazonS3 s3 = mock(AmazonS3.class);
when(s3.getObject(argThat(getsObject("stash-bucket", "stash/test/2015-01-01-00-00-00/test-table/split0.gz")))).thenReturn(s3Object);
StashSplit stashSplit = new StashSplit("test:table", "2015-01-01-00-00-00/test-table/split0.gz", splitOut.size());
StandardStashReader reader = new StandardStashReader(URI.create("s3://stash-bucket/stash/test"), s3, 0);
try (StashRowIterator rowIter = reader.getSplit(stashSplit)) {
assertTrue(rowIter.hasNext());
Map<String, Object> row = rowIter.next();
assertEquals(row.get("text"), utf8Text);
}
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project emodb by bazaarvoice.
the class StashReaderTest method getSplit.
@Test
public void getSplit() throws Exception {
// Intentionally create the gzip file as concatenated gzip files to verify the Java bug involving reading
// concatenated gzip files is resolved.
List<Map<String, Object>> expected = Lists.newArrayListWithCapacity(4);
ByteArrayOutputStream splitOut = new ByteArrayOutputStream();
for (int p = 0; p < 2; p++) {
for (int i = 0; i < 2; i++) {
ByteArrayOutputStream partialOut = new ByteArrayOutputStream();
try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(partialOut)))) {
Map<String, Object> value = ImmutableMap.<String, Object>builder().put("~id", "row" + (p * 2 + i)).put("~table", "test:table").put("~version", 1).put("~signature", "3a0da59fabf298d389b7b0b59728e887").put("~lastUpdateAt", "2014-08-28T21:24:36.440Z").put("~firstUpdateAt", "2014-06-07T09:51:40.077Z").build();
String json = JsonHelper.asJson(value);
out.write(json);
out.write("\n");
expected.add(value);
}
partialOut.writeTo(splitOut);
}
}
splitOut.close();
S3Object s3Object = new S3Object();
s3Object.setObjectContent(new ByteArrayInputStream(splitOut.toByteArray(), 0, splitOut.size()));
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(splitOut.size());
s3Object.setObjectMetadata(objectMetadata);
AmazonS3 s3 = mock(AmazonS3.class);
when(s3.getObject(argThat(getsObject("stash-bucket", "stash/test/2015-01-01-00-00-00/test-table/split0.gz")))).thenReturn(s3Object);
StashSplit stashSplit = new StashSplit("test:table", "2015-01-01-00-00-00/test-table/split0.gz", splitOut.size());
StandardStashReader reader = new StandardStashReader(URI.create("s3://stash-bucket/stash/test"), s3, 0);
StashRowIterator contentIter = reader.getSplit(stashSplit);
List<Map<String, Object>> content = ImmutableList.copyOf(contentIter);
assertEquals(content, expected);
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project digitraffic-road by tmfg.
the class CameraImageS3Writer method writeVersionedImage.
/**
* Writes image version for given image
* @param versionedImageData image bytes to write
* @param imageKey current image s3 key. Key will be appended with version suffix.
* @param timestampEpochMillis image timestamp
* @return s3 version id
*/
private String writeVersionedImage(final byte[] versionedImageData, final String imageKey, final long timestampEpochMillis) {
final String versionedKey = getVersionedKey(imageKey);
try {
checkS3KeyFormat(imageKey);
final ObjectMetadata metadata = createS3Metadata(timestampEpochMillis, versionedImageData.length);
// Put versions image
final PutObjectResult result = amazonS3Client.putObject(weathercamS3Properties.getS3WeathercamBucketName(), versionedKey, new ByteArrayInputStream(versionedImageData), metadata);
if (log.isDebugEnabled()) {
log.debug("method=writeVersionedImage s3Key={} lastModified: {} s3VersionId={}", versionedKey, metadata.getUserMetaDataOf(LAST_MODIFIED_USER_METADATA_HEADER), result.getVersionId());
}
return result.getVersionId();
} catch (final Exception e) {
throw new RuntimeException(String.format("method=writeVersionedImage Failed to write image to S3 s3Key=%s", versionedKey), e);
}
}
Aggregations