// Path: kbox.core/src/main/java/org/aksw/kbox/InputStreamFactory.java
// public interface InputStreamFactory {
// 	public InputStream get(URL url) throws Exception;
// }
// 
// Path: kbox.apple/src/main/java/org/aksw/kbox/apple/stream/DefaultInputStreamFactory.java
// public class DefaultInputStreamFactory implements InputStreamFactory {
// 
// 	@Override
// 	public InputStream get(URL url) throws IOException {
// 		return url.openStream();
// 	}
// 
// }
// 
// 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.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.security.InvalidParameterException;
import org.aksw.kbox.InputStreamFactory;
import org.aksw.kbox.apple.stream.DefaultInputStreamFactory;
import org.aksw.kbox.utils.URLUtils;
import org.apache.commons.compress.utils.IOUtils;
package org.aksw.kbox.apple;



/**
 * 
 * @author {@linkplain http://emarx.org}
 *
 */
public abstract class AbstractAppInstall extends AppPathBinder implements AppInstall, PathBinder {
	
	public void install(URL[] resources, URL dest, String format, String version)
			throws Exception {		
		install(resources, dest, format, version, new DefaultInputStreamFactory());
	}

	@Override
	public void install(URL resource, URL dest, String format, String version)
			throws Exception {		
		install(resource, dest, format, version, new DefaultInputStreamFactory());
	}

	@Override
	public void install(URL resource, URL dest, String format, String version, InputStreamFactory isFactory) throws Exception {
		URL forwardURL = URLUtils.getURLForward(resource);
		try(InputStream is = isFactory.get(forwardURL)) {
			install(is, dest, format, version);
		}
	}
	
	public void install(URL[] resources, URL dest, String format, String version, InputStreamFactory isFactory) throws Exception {
		for(URL resource : resources) {
			install(resource, dest, format, version, isFactory);
		}
	}
	
	public void install(URL source, File dest, InputStreamFactory isFactory) throws Exception {
		try(FileOutputStream out = new FileOutputStream(dest)) {
			install(source, out, isFactory);
		}
	}
	
	public void install(URL source, OutputStream dest, InputStreamFactory isFactory) throws Exception {
// Path: kbox.core/src/main/java/org/aksw/kbox/InputStreamFactory.java
// public interface InputStreamFactory {
// 	public InputStream get(URL url) throws Exception;
// }
// 
// Path: kbox.apple/src/main/java/org/aksw/kbox/apple/stream/DefaultInputStreamFactory.java
// public class DefaultInputStreamFactory implements InputStreamFactory {
// 
// 	@Override
// 	public InputStream get(URL url) throws IOException {
// 		return url.openStream();
// 	}
// 
// }
// 
// 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.apple/src/main/java/org/aksw/kbox/apple/AbstractAppInstall.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.security.InvalidParameterException;
import org.aksw.kbox.InputStreamFactory;
import org.aksw.kbox.apple.stream.DefaultInputStreamFactory;
import org.aksw.kbox.utils.URLUtils;
import org.apache.commons.compress.utils.IOUtils;

package org.aksw.kbox.apple;



/**
 * 
 * @author {@linkplain http://emarx.org}
 *
 */
public abstract class AbstractAppInstall extends AppPathBinder implements AppInstall, PathBinder {
	
	public void install(URL[] resources, URL dest, String format, String version)
			throws Exception {		
		install(resources, dest, format, version, new DefaultInputStreamFactory());
	}

	@Override
	public void install(URL resource, URL dest, String format, String version)
			throws Exception {		
		install(resource, dest, format, version, new DefaultInputStreamFactory());
	}

	@Override
	public void install(URL resource, URL dest, String format, String version, InputStreamFactory isFactory) throws Exception {
		URL forwardURL = URLUtils.getURLForward(resource);
		try(InputStream is = isFactory.get(forwardURL)) {
			install(is, dest, format, version);
		}
	}
	
	public void install(URL[] resources, URL dest, String format, String version, InputStreamFactory isFactory) throws Exception {
		for(URL resource : resources) {
			install(resource, dest, format, version, isFactory);
		}
	}
	
	public void install(URL source, File dest, InputStreamFactory isFactory) throws Exception {
		try(FileOutputStream out = new FileOutputStream(dest)) {
			install(source, out, isFactory);
		}
	}
	
	public void install(URL source, OutputStream dest, InputStreamFactory isFactory) throws Exception {
		URL forwardURL = URLUtils.getURLForward(source);