
stream.urls.HdfsConnection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of streams-hdfs Show documentation
Show all versions of streams-hdfs Show documentation
A streams SourceURL connection handler for HDFS filesystems.
/**
*
*/
package stream.urls;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import stream.io.SourceURL;
/**
* @author chris
*
*/
public class HdfsConnection extends Connection {
InputStream stream;
/**
* @param url
*/
public HdfsConnection(SourceURL url) {
super(url);
}
/**
* @see stream.urls.Connection#getSupportedProtocols()
*/
@Override
public String[] getSupportedProtocols() {
return new String[] { "hdfs" };
}
/**
* @see stream.urls.Connection#connect()
*/
@Override
public InputStream connect() throws IOException {
if (stream == null) {
Configuration config = new Configuration();
FileSystem fs = FileSystem.get(URI.create(url.toString()), config);
stream = fs.open(new Path(url.toString()));
}
return stream;
}
/**
* @see stream.urls.Connection#disconnect()
*/
@Override
public void disconnect() throws IOException {
if (stream != null) {
stream.close();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy