Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* streams library
*
* Copyright (C) 2011-2014 by Christian Bockermann, Hendrik Blom
*
* streams is a library, API and runtime environment for processing high
* volume data streams. It is composed of three submodules "stream-api",
* "stream-core" and "stream-runtime".
*
* The streams library (and its submodules) is free software: you can
* redistribute it and/or modify it under the terms of the
* GNU Affero General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* The stream.ai library (and its submodules) is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package stream.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
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.FilesConnection;
import stream.urls.SSLConnection;
import stream.urls.TcpConnection;
import stream.urls.TcpListener;
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]>, Hendrik Blom
*
*/
public class SourceURL implements Serializable {
public final static String PROTOCOL_FILE = "file";
public final static String PROTOCOL_TCP = "tcp";
public final static String PROTOCOL_SSL = "ssl";
public final static String PROTOCOL_FIFO = "fifo";
public final static String PROTOCOL_CLASSPATH = "classpath";
public final static String PROTOCOL_JDBC = "jdbc";
public final static String PROTOCOL_HTTP = "http";
public final static String PROTOCOL_HTTPS = "https";
public final static String PROTOCOL_STDIN = "stdin";
protected final static String FILE_GRAMMAR = "%(protocol):%(path)";
protected final static String JDBC_GRAMMAR = "jdbc:%(driver):%(target)";
protected final static String GRAMMAR = "%(protocol)://%(address)/%(path)";
/** 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(PROTOCOL_SSL, stream.urls.SSLConnection.class);
urlProvider.put(PROTOCOL_TCP, stream.urls.TcpConnection.class);
urlProvider.put(PROTOCOL_FIFO, stream.urls.FIFOConnection.class);
registerUrlHandler("files", FilesConnection.class);
registerUrlHandler("tcpd", TcpListener.class);
try {
@SuppressWarnings("unchecked")
Class extends Connection> c = (Class extends Connection>) Class.forName("stream.urls.HdfsConnection");
if (c != null) {
registerUrlHandler("hdfs", c);
}
} catch (Exception e) {
// log.error("Failed to register handler for protocol '{}'",
// "hdfs");
if (log.isDebugEnabled()) {
e.printStackTrace();
}
}
}
public final static void registerUrlHandler(String protocol, Class extends Connection> clazz) {
if (urlProvider.containsKey(protocol)) {
log.warn("Overriding URL handler {} for protocol '{}'", urlProvider.get(protocol), protocol);
}
urlProvider.put(protocol, clazz);
}
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 String queryString;
final Map parameters = new LinkedHashMap();
protected SourceURL() {
this.url = null;
this.urlString = "";
protocol = "unknown";
host = "";
port = 0;
path = "";
queryString = "";
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();
queryString = url.getQuery();
username = null;
password = null;
}
public SourceURL(String urlString) throws Exception {
this.url = null;
this.urlString = urlString;
if (!hasProtocol(urlString))
throw new MalformedURLException("Missing Protocol in: " + urlString);
if (urlString.toLowerCase().startsWith(PROTOCOL_FILE) || urlString.toLowerCase().startsWith(PROTOCOL_CLASSPATH)
|| urlString.toLowerCase().startsWith(PROTOCOL_FIFO)) {
ParserGenerator gen = new ParserGenerator(FILE_GRAMMAR);
Parser