public boolean createS3Object()

in src/main/java/com/amazonaws/gdcreplication/util/S3Util.java [44:71]


	public boolean createS3Object(String region, String bucket, String objectKey, String content) {
		boolean objectCreated = false;
		AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(region).build();

		byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
		InputStream inputStream = new ByteArrayInputStream(contentBytes);

		ObjectMetadata metadata = new ObjectMetadata();
		metadata.setContentLength(contentBytes.length);
		PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, objectKey, inputStream, metadata);
		// send request to S3 to create an object with the content
		try {
			s3.putObject(putObjectRequest);
			objectCreated = true;
			System.out.println("Partition Object uploaded to S3. Object key: " + objectKey);
		} catch (AmazonServiceException e) {
			System.err.println(e.getErrorMessage());
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			inputStream.close();
		} catch(Exception e) {
			e.printStackTrace();
			System.out.println("Exception thrown while closing InputStream.");
		}
		return objectCreated;
	}