Search in sources :

Example 1 with StatObjectResponse

use of io.minio.StatObjectResponse in project yyl_example by Relucent.

the class MinioExample method main.

public static void main(String[] args) throws Exception {
    try {
        String endpoint = "http://localhost:9000";
        String accessKey = "minioadmin";
        String secretKey = "minioadmin";
        String bucketName = "test" + System.currentTimeMillis();
        MinioClient client = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
        boolean exists = client.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
        if (!exists) {
            client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
        }
        String objectName = "hello.txt";
        byte[] content = "hello".getBytes();
        String contentType = "text/plain";
        try (InputStream input = new ByteArrayInputStream(content)) {
            int length = content.length;
            Map<String, String> headers = new HashMap<>();
            client.putObject(// 
            PutObjectArgs.builder().bucket(// 
            bucketName).object(// 
            objectName).stream(input, length, // 
            -1).contentType(// 
            contentType).headers(// 
            headers).build());
        }
        StatObjectResponse stat = client.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build());
        System.out.println(stat);
        try (InputStream input = client.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).build())) {
            byte[] data = IOUtils.toByteArray(input);
            System.out.println(new String(data));
        }
        client.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
        if (!exists) {
            client.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
        }
    } catch (MinioException e) {
        e.printStackTrace();
    }
}
Also used : MinioClient(io.minio.MinioClient) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StatObjectResponse(io.minio.StatObjectResponse) MinioException(io.minio.errors.MinioException)

Aggregations

MinioClient (io.minio.MinioClient)1 StatObjectResponse (io.minio.StatObjectResponse)1 MinioException (io.minio.errors.MinioException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1