// Path: kbox.core/src/main/java/org/aksw/kbox/InputStreamFactory.java
// public interface InputStreamFactory {
// 	public InputStream get(URL url) throws Exception;
// }
// 
// Path: kbox.kibe/src/main/java/org/aksw/kbox/kibe/stream/InputStreamInstaller.java
// public class InputStreamInstaller extends InputStream {
// 	
// 	private InputStream inputStream = null;
// 	private InstallStreamListener listener = null;
// 	private boolean started = false;
// 	
// 	public InputStreamInstaller(InputStream inputStream, InstallStreamListener listener) {
// 		this.inputStream = inputStream;
// 		this.listener = listener;
// 	}
// 	
// 	@Override
// 	public void close() throws IOException {
// 		inputStream.close();
// 		listener.stop();
// 	}
// 	
// 	@Override
// 	public boolean markSupported() {
// 		return inputStream.markSupported();
// 	}
// 	
// 	@Override
// 	public int read(byte[] b) throws IOException {
// 		streaming();
// 		int read = inputStream.read(b);
// 		listener.update(read);
// 		return read;
// 	}
// 	
// 	@Override
// 	public synchronized void mark(int readlimit) {
// 		inputStream.mark(readlimit);
// 	}
// 	
// 	@Override
// 	public long skip(long n) throws IOException {
// 		return inputStream.skip(n);
// 	}
// 	
// 	@Override
// 	public int read(byte[] b, int off, int len) throws IOException {
// 		streaming();
// 		int read = inputStream.read(b, off, len);
// 		listener.update(read);
// 		return read;
// 	}
// 	
// 	@Override
// 	public synchronized void reset() throws IOException {
// 		inputStream.reset();
// 	}
// 	
// 	@Override
// 	public int available() throws IOException {
// 		return inputStream.available();
// 	}
// 
// 	@Override
// 	public int read() throws IOException {
// 		streaming();
// 		return inputStream.read();
// 	}
// 	
// 	private void streaming() {
// 		if(!started) {
// 			listener.start();
// 			started = true;
// 		}
// 	}
// 
// }
// 
// Path: kbox.core/src/main/java/org/aksw/kbox/utils/URLUtils.java
// public class URLUtils {
// 	
// 	private static Set<String> protocolsWithHost = new HashSet<String>( 
// 		      Arrays.asList( new String[]{ "file", "ftp", "http", "https" } ) 
// 		  );
// 	
// 	public static URL[] stringToURL(String... urls) throws Exception {
// 		URL[] urlArray = new URL[urls.length];
// 		for(int i=0; i < urls.length; i++) {
// 			urlArray[i]  = new URL(urls[i]);
// 		}
// 		return urlArray;
// 	}
// 	
// 	public static boolean checkStatus(URL url, int code) throws IOException {
// 		URLConnection conn = url.openConnection();
// 		if(conn instanceof HttpURLConnection) {
// 			HttpURLConnection huc =  (HttpURLConnection) conn;
// 			huc.setRequestMethod("HEAD");
// 			conn.connect();
// 			return huc.getResponseCode() == code;
// 		}
// 		return false;
// 	}
// 	
// 	public static URL[] fileToURL(File... files) throws MalformedURLException {
// 		URL[] urls = new URL[files.length];
// 		int i = 0;
// 		for(File file : files) {
// 			urls[i] = file.toURI().toURL();
// 			i++;
// 		}		
// 		return urls;
// 	}
// 	
// 	public static long getContentLength(URL url) throws IOException {
//         URLConnection conn = url.openConnection();
//         Long contentLength = conn.getContentLengthLong();
//         if(contentLength != null && contentLength >= 0) {
//         	return contentLength;
//         }
// 		String contentLengthValue = conn.getHeaderField("content-length");
// 		if(contentLengthValue != null) {
// 			return Long.valueOf(contentLengthValue);
// 		}
// 		return -1;
// 	}
// 	
// 	public static URL getURLForward(URL url) throws Exception {
// 		URLConnection con = url.openConnection();
// 		String location = con.getHeaderField("Location");
// 		if(location != null) {
// 			return new URL(location);
// 		}
// 		return url;
// 	}
// 	
// 	public static boolean hasValidURLHost(URI uri) {
// 		return protocolsWithHost.contains(uri.getScheme());
// 	}
// 	
// 	public static String getContentType(URL url) throws Exception {
// 		URL forwardURL = getURLForward(url);
// 		HttpURLConnection connection = (HttpURLConnection)  forwardURL.openConnection();
// 		connection.setRequestMethod("HEAD");
// 		connection.connect();
// 		return connection.getContentType();
// 	}
// }


import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.aksw.kbox.InputStreamFactory;
import org.aksw.kbox.kibe.stream.InputStreamInstaller;
import org.aksw.kbox.utils.URLUtils;
package org.aksw.kbox.kibe.console;



public class ConsoleInstallInputStreamFactory implements InputStreamFactory {
	
	private final static String MESSAGE = "Installing";

	@Override
	public InputStream get(URL url) throws IOException {
// Path: kbox.core/src/main/java/org/aksw/kbox/InputStreamFactory.java
// public interface InputStreamFactory {
// 	public InputStream get(URL url) throws Exception;
// }
// 
// Path: kbox.kibe/src/main/java/org/aksw/kbox/kibe/stream/InputStreamInstaller.java
// public class InputStreamInstaller extends InputStream {
// 	
// 	private InputStream inputStream = null;
// 	private InstallStreamListener listener = null;
// 	private boolean started = false;
// 	
// 	public InputStreamInstaller(InputStream inputStream, InstallStreamListener listener) {
// 		this.inputStream = inputStream;
// 		this.listener = listener;
// 	}
// 	
// 	@Override
// 	public void close() throws IOException {
// 		inputStream.close();
// 		listener.stop();
// 	}
// 	
// 	@Override
// 	public boolean markSupported() {
// 		return inputStream.markSupported();
// 	}
// 	
// 	@Override
// 	public int read(byte[] b) throws IOException {
// 		streaming();
// 		int read = inputStream.read(b);
// 		listener.update(read);
// 		return read;
// 	}
// 	
// 	@Override
// 	public synchronized void mark(int readlimit) {
// 		inputStream.mark(readlimit);
// 	}
// 	
// 	@Override
// 	public long skip(long n) throws IOException {
// 		return inputStream.skip(n);
// 	}
// 	
// 	@Override
// 	public int read(byte[] b, int off, int len) throws IOException {
// 		streaming();
// 		int read = inputStream.read(b, off, len);
// 		listener.update(read);
// 		return read;
// 	}
// 	
// 	@Override
// 	public synchronized void reset() throws IOException {
// 		inputStream.reset();
// 	}
// 	
// 	@Override
// 	public int available() throws IOException {
// 		return inputStream.available();
// 	}
// 
// 	@Override
// 	public int read() throws IOException {
// 		streaming();
// 		return inputStream.read();
// 	}
// 	
// 	private void streaming() {
// 		if(!started) {
// 			listener.start();
// 			started = true;
// 		}
// 	}
// 
// }
// 
// Path: kbox.core/src/main/java/org/aksw/kbox/utils/URLUtils.java
// public class URLUtils {
// 	
// 	private static Set<String> protocolsWithHost = new HashSet<String>( 
// 		      Arrays.asList( new String[]{ "file", "ftp", "http", "https" } ) 
// 		  );
// 	
// 	public static URL[] stringToURL(String... urls) throws Exception {
// 		URL[] urlArray = new URL[urls.length];
// 		for(int i=0; i < urls.length; i++) {
// 			urlArray[i]  = new URL(urls[i]);
// 		}
// 		return urlArray;
// 	}
// 	
// 	public static boolean checkStatus(URL url, int code) throws IOException {
// 		URLConnection conn = url.openConnection();
// 		if(conn instanceof HttpURLConnection) {
// 			HttpURLConnection huc =  (HttpURLConnection) conn;
// 			huc.setRequestMethod("HEAD");
// 			conn.connect();
// 			return huc.getResponseCode() == code;
// 		}
// 		return false;
// 	}
// 	
// 	public static URL[] fileToURL(File... files) throws MalformedURLException {
// 		URL[] urls = new URL[files.length];
// 		int i = 0;
// 		for(File file : files) {
// 			urls[i] = file.toURI().toURL();
// 			i++;
// 		}		
// 		return urls;
// 	}
// 	
// 	public static long getContentLength(URL url) throws IOException {
//         URLConnection conn = url.openConnection();
//         Long contentLength = conn.getContentLengthLong();
//         if(contentLength != null && contentLength >= 0) {
//         	return contentLength;
//         }
// 		String contentLengthValue = conn.getHeaderField("content-length");
// 		if(contentLengthValue != null) {
// 			return Long.valueOf(contentLengthValue);
// 		}
// 		return -1;
// 	}
// 	
// 	public static URL getURLForward(URL url) throws Exception {
// 		URLConnection con = url.openConnection();
// 		String location = con.getHeaderField("Location");
// 		if(location != null) {
// 			return new URL(location);
// 		}
// 		return url;
// 	}
// 	
// 	public static boolean hasValidURLHost(URI uri) {
// 		return protocolsWithHost.contains(uri.getScheme());
// 	}
// 	
// 	public static String getContentType(URL url) throws Exception {
// 		URL forwardURL = getURLForward(url);
// 		HttpURLConnection connection = (HttpURLConnection)  forwardURL.openConnection();
// 		connection.setRequestMethod("HEAD");
// 		connection.connect();
// 		return connection.getContentType();
// 	}
// }


// Path: kbox.kibe/src/main/java/org/aksw/kbox/kibe/console/ConsoleInstallInputStreamFactory.java
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.aksw.kbox.InputStreamFactory;
import org.aksw.kbox.kibe.stream.InputStreamInstaller;
import org.aksw.kbox.utils.URLUtils;

package org.aksw.kbox.kibe.console;



public class ConsoleInstallInputStreamFactory implements InputStreamFactory {
	
	private final static String MESSAGE = "Installing";

	@Override
	public InputStream get(URL url) throws IOException {
		ConsoleStreamListener listener = new ConsoleStreamListener(MESSAGE + " " + url, URLUtils.getContentLength(url));