Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public boolean createFolder(String path) {
    try {
        // create meta-data for your folder and set content-length to 0
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(0);
        // create empty content
        InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
        // create a PutObjectRequest passing the folder name suffixed by /
        PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucketName, path + SUFFIX, emptyContent,
                metadata);
        // send request to S3 to create folder
        boolean doesObjectExist = this.s3client.doesObjectExist(bucketName, path);
        if (!doesObjectExist) {
            this.s3client.putObject(putObjectRequest);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}


What I have tried:

code refactoring in the aws s3 client to refactor the code for to reduce the complexity
Posted
Updated 23-May-19 7:34am
Comments
Richard MacCutchan 23-May-19 9:51am    
What is the problem?
OriginalGriff 23-May-19 10:13am    
Commented student style, swallowed exceptions, copied from internet and doesn't want tutor to know, ... :laugh:
Member 14364887 23-May-19 13:05pm    
i want decrease the code in short form how do i that???
Richard MacCutchan 24-May-19 3:29am    
Start by analysing what the code is doing, and remove any redundant elements of it. At a quick glance there is nothing that stands out, apart from the fact that there is a missing return statement at the end.
Member 14364887 23-May-19 13:06pm    
i want the code in short form how i do that??

1 solution

public boolean createFolder(String path) {
    return true;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900