Skip to content

Commit

Permalink
handle errors in makeBucket, removeBucket and DeleteObject examples. (#…
Browse files Browse the repository at this point in the history
…386)

* examples/MakeBucket: create bucket if it doesn't exist.

* examples/RemoveBucket: remove bucket if it exists.

* example/RemoveObject: handle MinioException when removing object.
  • Loading branch information
balamurugana authored and harshavardhana committed May 28, 2016
1 parent d707f43 commit dd57cd0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
12 changes: 9 additions & 3 deletions examples/MakeBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public static void main(String[] args)
// Set s3 endpoint, region is calculated automatically
MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");

// Create bucket 'my-bucketname'.
s3Client.makeBucket("my-bucketname");
System.out.println("my-bucketname is created successfully");
// Create bucket if it doesn't exist.
boolean found = s3Client.bucketExists("my-bucketname");
if (found) {
System.out.println("my-bucketname already exists");
} else {
// Create bucket 'my-bucketname'.
s3Client.makeBucket("my-bucketname");
System.out.println("my-bucketname is created successfully");
}
}
}
11 changes: 8 additions & 3 deletions examples/RemoveBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ public static void main(String[] args)
// Set s3 endpoint, region is calculated automatically
MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");

// Remove bucket 'my-bucketname'.
// Remove bucket 'my-bucketname' if it exists.
// This operation will only work if your bucket is empty.
s3Client.removeBucket("my-bucketname");
System.out.println("my-bucketname is removed successfully");
boolean found = s3Client.bucketExists("my-bucketname");
if (found) {
s3Client.removeBucket("my-bucketname");
System.out.println("my-bucketname is removed successfully");
} else {
System.out.println("my-bucketname does not exist");
}
}
}
9 changes: 7 additions & 2 deletions examples/RemoveObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public static void main(String[] args)
MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");

// Remove object 'my-objectname' in 'my-bucketname'.
s3Client.removeObject("my-bucketname", "my-objectname");
System.out.println("successfully removed my-bucketname/my-objectname");
try {
s3Client.removeObject("my-bucketname", "my-objectname");
System.out.println("successfully removed my-bucketname/my-objectname");
} catch (MinioException e) {
System.out.println("Failed to remove object");
System.out.println("Error: " + e);
}
}
}

0 comments on commit dd57cd0

Please sign in to comment.