use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class DisplayFacesFrame method displayAllFaces.
// snippet-start:[rekognition.java2.display_faces.main]
public static void displayAllFaces(S3Client s3, RekognitionClient rekClient, String sourceImage, String bucketName) {
int height = 0;
int width = 0;
byte[] data = getObjectBytes(s3, bucketName, sourceImage);
InputStream is = new ByteArrayInputStream(data);
try {
SdkBytes sourceBytes = SdkBytes.fromInputStream(is);
image = ImageIO.read(sourceBytes.asInputStream());
width = image.getWidth();
height = image.getHeight();
// Create an Image object for the source image
software.amazon.awssdk.services.rekognition.model.Image souImage = Image.builder().bytes(sourceBytes).build();
DetectFacesRequest facesRequest = DetectFacesRequest.builder().attributes(Attribute.ALL).image(souImage).build();
result = rekClient.detectFaces(facesRequest);
// Show the bounding box info for each face.
List<FaceDetail> faceDetails = result.faceDetails();
for (FaceDetail face : faceDetails) {
BoundingBox box = face.boundingBox();
float left = width * box.left();
float top = height * box.top();
System.out.println("Face:");
System.out.println("Left: " + (int) left);
System.out.println("Top: " + (int) top);
System.out.println("Face Width: " + (int) (width * box.width()));
System.out.println("Face Height: " + (int) (height * box.height()));
System.out.println();
}
// Create the frame and panel.
JFrame frame = new JFrame("RotateImage");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DisplayFacesFrame panel = new DisplayFacesFrame(image);
panel.setPreferredSize(new Dimension(image.getWidth() / scale, image.getHeight() / scale));
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
} catch (RekognitionException | FileNotFoundException e) {
System.out.println(e.getMessage());
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class DeleteWebsiteConfiguration method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage: " + " <bucketName>\n\n" + "Where:\n" + " bucketName - the Amazon S3 bucket to delete the website configuration from.\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String bucketName = args[0];
System.out.format("Deleting website configuration for Amazon S3 bucket: %s\n", bucketName);
Region region = Region.US_WEST_2;
S3Client s3 = S3Client.builder().region(region).build();
deleteBucketWebsiteConfig(s3, bucketName);
System.out.println("Done!");
s3.close();
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class MovieLensDatasetProvider method getObjectBytes.
// Checks to see if the dataset is already uploaded to s3.
public static boolean getObjectBytes(S3Client s3Client, String bucketName, String keyName) {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(keyName).bucket(bucketName).build();
ResponseBytes<GetObjectResponse> objectBytes = s3Client.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
return data.length > 0;
} catch (NoSuchKeyException | NoSuchBucketException ex) {
return false;
} catch (S3Exception s3Exception) {
System.err.println(s3Exception.awsErrorDetails().errorMessage());
System.exit(1);
}
return false;
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class MovieLensDatasetProvider method uploadMovieLensDatasetToS3.
public static void uploadMovieLensDatasetToS3(S3Client s3Client, String bucket, DatasetType type, String path) throws IOException {
CSVReader reader = new CSVReader(new BufferedReader(new InputStreamReader(new FileInputStream("./movie-lens-ds/ml-100k/u.data"))), '\t');
StringWriter sw = new StringWriter();
CSVWriter pw = new CSVWriter(sw);
pw.writeNext(new String[] { "USER_ID", "ITEM_ID", "TIMESTAMP" });
String[] row = null;
while ((row = reader.readNext()) != null) {
int rating = Integer.parseInt(row[2]);
if (rating > 3) {
pw.writeNext(new String[] { row[0], row[1], row[3] });
}
}
reader.close();
pw.close();
String data = sw.toString();
try {
PutObjectRequest objectRequest = PutObjectRequest.builder().bucket(bucket).key(path).build();
s3Client.putObject(objectRequest, RequestBody.fromBytes(data.getBytes()));
} catch (S3Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class DemoUtils method ensurePersonalizePermissionsOnS3Bucket.
public static void ensurePersonalizePermissionsOnS3Bucket(S3Client s3, String bucket) {
final String bucketPolicy = BUCKET_POLICY_TEMPLATE.replace("{bucket}", bucket);
// System.out.println("Bucket policy: " + bucketPolicy);
PutBucketPolicyRequest policyRequest = PutBucketPolicyRequest.builder().bucket(bucket).policy(bucketPolicy).build();
s3.putBucketPolicy(policyRequest);
}
Aggregations