
stream.io.SourceURL Maven / Gradle / Ivy
The newest version!
/**
*
*/
package stream.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import stream.urls.Connection;
import stream.urls.SSLConnection;
import stream.urls.TcpConnection;
import stream.util.parser.Parser;
import stream.util.parser.ParserGenerator;
/**
*
* This URL encapsulates the definition of URLs for resources. It introduces a
* thin layer of abstraction for providing support for more than the existing
* protocol types in Java. The reason for introducing this SourceURL class is
* that we do not want to register a custom protocol handler, which might
* destroy some existing applications that also require a custom protocol
* handler. Java only allows to register a single custom protocol handler.
*
*
* @author Christian Bockermann <[email protected]>
*
*/
public class SourceURL implements Serializable {
/** The unique class ID */
private static final long serialVersionUID = -7992522266824113404L;
static Logger log = LoggerFactory.getLogger(SourceURL.class);
final static Map> urlProvider = new LinkedHashMap>();
static {
urlProvider.put("ssl", stream.urls.SSLConnection.class);
urlProvider.put("tcp", stream.urls.TcpConnection.class);
urlProvider.put("fifo", stream.urls.FIFOConnection.class);
}
final static String FILE_GRAMMAR = "%(protocol):%(path)";
final static String JDBC_GRAMMAR = "jdbc:%(driver):%(target)/%(path)";
final static String GRAMMAR = "%(protocol)://%(address)/%(path)";
final URL url;
final String urlString;
final String protocol;
final String host;
final int port;
final String path;
final String username;
final String password;
final Map parameters = new LinkedHashMap();
protected SourceURL() {
this.url = null;
this.urlString = "";
protocol = "unknown";
host = "";
port = 0;
path = "";
username = null;
password = null;
}
public SourceURL(URL url) {
this.url = url;
this.urlString = url.toString();
protocol = url.getProtocol();
host = url.getHost();
port = url.getPort();
path = url.getPath();
username = null;
password = null;
}
public SourceURL(String urlString) throws Exception {
this.url = null;
this.urlString = urlString;
if (urlString.toLowerCase().startsWith("file:")
|| urlString.toLowerCase().startsWith("classpath")
|| urlString.toLowerCase().startsWith("fifo")) {
ParserGenerator gen = new ParserGenerator(FILE_GRAMMAR);
Parser
© 2015 - 2025 Weber Informatics LLC | Privacy Policy