public static ObjectListing listObjects(String bucketName, String dirName, int max) throws SAWSException {

        //Fixing dirName if doesn't end with a slash
        if(dirName!=null && !dirName.endsWith("/")) {
            dirName += "/";
        }

        List<S3ObjectPojo> result = new ArrayList<S3ObjectPojo>();

        try {
            System.out.println("Downloading an object");
            ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName, dirName,"","/",max);
            ObjectListing objectListing = getS3Client().listObjects(listObjectsRequest);

            for(String folder : objectListing.getCommonPrefixes()) {
                S3ObjectPojo s3Object = new S3ObjectPojo();
                s3Object.setBucketName(bucketName);
                s3Object.setKey(folder);
                s3Object.setFolder(true);
                try {
                    ObjectMetadata objectMetadata = getS3Client().getObjectMetadata(bucketName, folder + "$dir$");
                    String realName = (String) objectMetadata.getRawMetadata().get("realname");
                    s3Object.setRealName(realName);
                } catch (AmazonServiceException ase) {
                }
                result.add(s3Object);
            }

            for(S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                if(mustListObject(objectSummary)) {
                    S3ObjectPojo s3Object = new S3ObjectPojo();
                    s3Object.setBucketName(bucketName);
                    s3Object.setKey(objectSummary.getKey());
                    s3Object.setFolder(false);
                    result.add(s3Object);
                }
            }

        } catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, which" +
                    " means your request made it " +
                    "to Amazon S3, but was rejected with an error response" +
                    " for some reason.");
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Error Type:       " + ase.getErrorType());
            System.out.println("Request ID:       " + ase.getRequestId());
            ase.printStackTrace();
        } catch (AmazonClientException ace) {
            System.out.println("Caught an AmazonClientException, which means"+
                    " the client encountered " +
                    "an internal error while trying to " +
                    "communicate with S3, " +
                    "such as not being able to access the network.");
            System.out.println("Error Message: " + ace.getMessage());
            ace.printStackTrace();
        }
        return null;
    }