All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mozafaq.extmergesort.InputStreamFactory Maven / Gradle / Ivy

There is a newer version: 2.0.4.RELEASE
Show newest version
package com.mozafaq.extmergesort;

import com.amazonaws.auth.AWSCredentials;

import java.util.Objects;

/**
 * @author Mozaffar Afaque
 */
public class InputStreamFactory {

    public static StreamReader newStreamReader(IOLocation location) {
        Objects.requireNonNull(location);
        Objects.requireNonNull(location.getIoType());

        switch (location.getIoType()) {
            case AWS_S3_BUCKET:
                Objects.requireNonNull(location.getS3Path());
                Objects.requireNonNull(location.getObjectName());

                AWSS3BucketStreamReader awsS3BucketStreamReader =
                        new AWSS3BucketStreamReader(location);
                AWSCredentials awsCredentials =
                        AWSUtils.createAWSCredentials(AWSUtils.AWS_PROFILE_DEFAULT);
                awsS3BucketStreamReader.setAwsCredsAwsCredentials(awsCredentials);
                awsS3BucketStreamReader.create();
                return awsS3BucketStreamReader;
            case FILE_SYSTEM:
                Objects.requireNonNull(location.getFileSystemPath());
                Objects.requireNonNull(location.getObjectName());

                return new FileSystemStreamReader(
                        String.format("%s/%s",
                                location.getFileSystemPath(),
                                location.getObjectName())
                );
        }

        throw new IllegalStateException(location.getIoType() + " case is not implemented");
    }

    public static StreamReader getTempStreamReader(String fileLocation) {
        Objects.requireNonNull(fileLocation);
        return new FileSystemStreamReader(fileLocation);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy