public List getPartitionsFromS3()

in src/main/java/com/amazonaws/gdcreplication/util/S3Util.java [201:236]


	public List<Partition> getPartitionsFromS3(String region, String bucket, String key) {

		String contentType = "";
		Gson gson = new Gson();
		S3Object fullObject = null;
		AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(region).build();
		System.out.printf("Bucket Name: %s, Object Key: %s \n", bucket, key);
		
		try {
			fullObject = s3.getObject(new GetObjectRequest(bucket, key));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("Exception thrown while reading object from S3");	
		}
		
		InputStream input = fullObject.getObjectContent();
		contentType = fullObject.getObjectMetadata().getContentType();
		System.out.println("CONTENT TYPE: " + contentType);

		// Read the text input stream one line at a time and display each line.
		List<Partition> partitionList = new ArrayList<Partition>();

		BufferedReader reader = new BufferedReader(new InputStreamReader(input));
		String line = null;
		try {
			while ((line = reader.readLine()) != null) {
				Partition partition = gson.fromJson(line, Partition.class);
				partitionList.add(partition);
			}
		} catch (JsonSyntaxException | IOException e) {
			System.out.println("Exception occured while reading partition information from S3 object.");
			e.printStackTrace();
		}
		System.out.println("Number of partitions read from S3: " + partitionList.size());
		return partitionList;
	}