// Path: src/main/java/com/socrata/datasync/config/userpreferences/UserPreferences.java
// public interface UserPreferences {
//     public static final String[] DEFAULT_TIME_FORMATS = new String[] {
//         "ISO8601", "MM/dd/yy", "MM/dd/yyyy", "dd-MMM-yyyy","MM/dd/yyyy hh:mm:ss a Z","MM/dd/yyyy hh:mm:ss a"
//     };
// 
//     public String getDomain();
// 
//     public String getHost();
// 
//     public String getUsername();
// 
//     public String getPassword();
// 
//     public String getProxyHost();
// 
//     public String getProxyPort();
// 
//     public String getProxyPassword();
// 
//     public String getProxyUsername();
// 
//     public String getAdminEmail();
// 
//     public boolean emailUponError();
// 
//     public String getLogDatasetID();
// 
//     public String getOutgoingMailServer();
// 
//     public String getSmtpPort();
// 
//     public String getSslPort();
// 
//     public String getSmtpUsername();
// 
//     public String getSmtpPassword();
// 
//     public String getFilesizeChunkingCutoffMB();
// 
//     public String getNumRowsPerChunk();
// 
//     public SocrataConnectionInfo getConnectionInfo();
// 
//     public void setProxyPassword(String password);
// 
//     public void setProxyUsername(String username);
// 
//     public List<String> getDefaultTimeFormats();
// }


import au.com.bytecode.opencsv.CSVReader;
import com.socrata.datasync.config.userpreferences.UserPreferences;
import com.socrata.model.importer.Column;
import com.socrata.model.importer.Dataset;
import com.socrata.model.importer.GeoDataset;
import com.socrata.model.importer.DatasetInfo;
import org.apache.http.HttpException;
import org.apache.http.HttpStatus;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.utils.URIBuilder;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
        List<List<String>> results = new ArrayList<>();

        Set<String> expectedFieldNames = new HashSet<String>();
        for(Column c : dataset.getColumns()) {
            expectedFieldNames.add(c.getFieldName());
        }
        String[] row = reader.readNext();
        boolean[] keep = new boolean[row.length];
        for(int i = 0; i != row.length; ++i) {
            keep[i] = expectedFieldNames.contains(row[i]);
        }
        results.add(filter(keep, row));

        while((row = reader.readNext()) != null) {
            results.add(filter(keep, row));
        }

        return results;
    }

    private static List<String> filter(boolean[] filter, String[] elems) {
        List<String> result = new ArrayList<>();

        for(int i = 0; i != elems.length; ++i) {
            if(filter[i]) result.add(elems[i]);
        }

        return result;
    }

// Path: src/main/java/com/socrata/datasync/config/userpreferences/UserPreferences.java
// public interface UserPreferences {
//     public static final String[] DEFAULT_TIME_FORMATS = new String[] {
//         "ISO8601", "MM/dd/yy", "MM/dd/yyyy", "dd-MMM-yyyy","MM/dd/yyyy hh:mm:ss a Z","MM/dd/yyyy hh:mm:ss a"
//     };
// 
//     public String getDomain();
// 
//     public String getHost();
// 
//     public String getUsername();
// 
//     public String getPassword();
// 
//     public String getProxyHost();
// 
//     public String getProxyPort();
// 
//     public String getProxyPassword();
// 
//     public String getProxyUsername();
// 
//     public String getAdminEmail();
// 
//     public boolean emailUponError();
// 
//     public String getLogDatasetID();
// 
//     public String getOutgoingMailServer();
// 
//     public String getSmtpPort();
// 
//     public String getSslPort();
// 
//     public String getSmtpUsername();
// 
//     public String getSmtpPassword();
// 
//     public String getFilesizeChunkingCutoffMB();
// 
//     public String getNumRowsPerChunk();
// 
//     public SocrataConnectionInfo getConnectionInfo();
// 
//     public void setProxyPassword(String password);
// 
//     public void setProxyUsername(String username);
// 
//     public List<String> getDefaultTimeFormats();
// }


// Path: src/main/java/com/socrata/datasync/DatasetUtils.java
import au.com.bytecode.opencsv.CSVReader;
import com.socrata.datasync.config.userpreferences.UserPreferences;
import com.socrata.model.importer.Column;
import com.socrata.model.importer.Dataset;
import com.socrata.model.importer.GeoDataset;
import com.socrata.model.importer.DatasetInfo;
import org.apache.http.HttpException;
import org.apache.http.HttpStatus;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.utils.URIBuilder;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

        List<List<String>> results = new ArrayList<>();

        Set<String> expectedFieldNames = new HashSet<String>();
        for(Column c : dataset.getColumns()) {
            expectedFieldNames.add(c.getFieldName());
        }
        String[] row = reader.readNext();
        boolean[] keep = new boolean[row.length];
        for(int i = 0; i != row.length; ++i) {
            keep[i] = expectedFieldNames.contains(row[i]);
        }
        results.add(filter(keep, row));

        while((row = reader.readNext()) != null) {
            results.add(filter(keep, row));
        }

        return results;
    }

    private static List<String> filter(boolean[] filter, String[] elems) {
        List<String> result = new ArrayList<>();

        for(int i = 0; i != elems.length; ++i) {
            if(filter[i]) result.add(elems[i]);
        }

        return result;
    }

    public static String getDomainWithoutScheme(UserPreferences userPrefs){