Search in sources :

Example 1 with StreamConnection

use of apoc.util.StreamConnection in project neo4j-apoc-procedures by neo4j-contrib.

the class S3Aws method getS3AwsInputStream.

public StreamConnection getS3AwsInputStream(S3Params s3Params) {
    S3Object s3Object = s3Client.getObject(s3Params.getBucket(), s3Params.getKey());
    ObjectMetadata metadata = s3Object.getObjectMetadata();
    return new StreamConnection() {

        @Override
        public InputStream getInputStream() throws IOException {
            return s3Object.getObjectContent();
        }

        @Override
        public String getEncoding() {
            return metadata.getContentEncoding();
        }

        @Override
        public long getLength() {
            return metadata.getContentLength();
        }
    };
}
Also used : S3Object(com.amazonaws.services.s3.model.S3Object) StreamConnection(apoc.util.StreamConnection) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 2 with StreamConnection

use of apoc.util.StreamConnection in project neo4j-apoc-procedures by neo4j-contrib.

the class HDFSUtils method readFile.

public static StreamConnection readFile(String fileName) throws IOException {
    FileSystem hdfs = getFileSystem(fileName);
    Path file = getPath(fileName);
    FileStatus fileStatus = hdfs.getFileStatus(file);
    return new StreamConnection() {

        @Override
        public InputStream getInputStream() throws IOException {
            return hdfs.open(file);
        }

        @Override
        public String getEncoding() {
            return "";
        }

        @Override
        public long getLength() {
            return fileStatus.getLen();
        }
    };
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) StreamConnection(apoc.util.StreamConnection)

Aggregations

StreamConnection (apoc.util.StreamConnection)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 S3Object (com.amazonaws.services.s3.model.S3Object)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1