importjava.io.BufferedReader;importjava.io.File;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.OutputStreamWriter;importjava.io.Writer;importjava.util.UUID;importcom.amazonaws.AmazonClientException;importcom.amazonaws.AmazonServiceException;importcom.amazonaws.auth.AWSCredentials;importcom.amazonaws.auth.BasicAWSCredentials;importcom.amazonaws.services.s3.AmazonS3;importcom.amazonaws.services.s3.AmazonS3Client;importcom.amazonaws.services.s3.model.GetObjectRequest;importcom.amazonaws.services.s3.model.ListObjectsRequest;importcom.amazonaws.services.s3.model.PutObjectRequest;importcom.amazonaws.services.s3.model.Bucket;importcom.amazonaws.services.s3.model.S3Object;importcom.amazonaws.services.s3.model.ObjectListing;importcom.amazonaws.services.s3.model.S3ObjectSummary;importcom.amazonaws.ClientConfiguration;importcom.amazonaws.Protocol;publicclassLeoFSSample{publicstaticvoidmain(String[]args)throwsIOException{/* --------------------------------------------------------- * You need to set 'Proxy host', 'Proxy port' and 'Protocol' * --------------------------------------------------------- */ClientConfigurationconfig=newClientConfiguration();config.setProxyHost("localhost");// LeoFS Gateway's Hostconfig.setProxyPort(8080);// LeoFS Gateway's Portconfig.withProtocol(Protocol.HTTP);finalStringaccessKeyId="YOUR_ACCESS_KEY_ID";finalStringsecretAccessKey="YOUR_SECRET_ACCESS_KEY";AWSCredentialscredentials=newBasicAWSCredentials(accessKeyId,secretAccessKey);AmazonS3s3=newAmazonS3Client(credentials,config);finalStringbucketName="test-bucket-"+UUID.randomUUID();finalStringkey="test-key";try{// Create a buckets3.createBucket(bucketName);// Retrieve list of bucketsfor(Bucketbucket:s3.listBuckets()){System.out.println("Bucket:"+bucket.getName());}// PUT an object into the LeoFSs3.putObject(newPutObjectRequest(bucketName,key,createFile()));// GET an object from the LeoFSS3Objectobject=s3.getObject(newGetObjectRequest(bucketName,key));dumpInputStream(object.getObjectContent());// Retrieve list of objects from the LeoFSObjectListingobjectListing=s3.listObjects(newListObjectsRequest().withBucketName(bucketName));for(S3ObjectSummaryobjectSummary:objectListing.getObjectSummaries()){System.out.println(objectSummary.getKey()+"Size:"+objectSummary.getSize());}// DELETE an object from the LeoFSs3.deleteObject(bucketName,key);// DELETE a bucket from the LeoFSs3.deleteBucket(bucketName);}catch(AmazonServiceExceptionase){System.out.println(ase.getMessage());System.out.println(ase.getStatusCode());}catch(AmazonClientExceptionace){System.out.println(ace.getMessage());}}privatestaticFilecreateFile()throwsIOException{Filefile=File.createTempFile("leofs_test",".txt");file.deleteOnExit();Writerwriter=newOutputStreamWriter(newFileOutputStream(file));writer.write("Hello, world!\n");writer.close();returnfile;}privatestaticvoiddumpInputStream(InputStreaminput)throwsIOException{BufferedReaderreader=newBufferedReader(newInputStreamReader(input));while(true){Stringline=reader.readLine();if(line==null)break;System.out.println(line);}}}