// Path: force-update/src/main/java/net/skoumal/forceupdate/VersionResult.java
// public class VersionResult {
// 
//     private List<Version> versionList = new ArrayList<>(1);
// 
//     private List<String> payloadList = new ArrayList<>(1);
// 
//     private boolean isError = false;
// 
//     private String errorMessage = null;
// 
//     private Exception errorException = null;
// 
//     public VersionResult(Version gVersion, String gPayload) {
//         versionList.add(gVersion);
//         payloadList.add(gPayload);
//     }
// 
//     public VersionResult(String gErrorMessage, Exception gErrorException) {
//         errorMessage = gErrorMessage;
//         errorException = gErrorException;
//         isError = true;
//     }
// 
//     public VersionResult(List<Version> gVersionList, List<String> gPayloadList) {
//         versionList = gVersionList;
//         payloadList = gPayloadList;
//     }
// 
//     public Version getVersion() {
//         if(isError || versionList.size() < 1) {
//             return null;
//         } else {
//             return versionList.get(0);
//         }
//     }
// 
//     public String getPayload() {
//         if(isError || payloadList.size() < 1) {
//             return null;
//         } else {
//             return payloadList.get(0);
//         }
//     }
// 
//     public List<Version> getVersionList() {
//         return versionList;
//     }
// 
//     public List<String> getPayloadList() {
//         return payloadList;
//     }
// 
//     public String getErrorMessage() {
//         return errorMessage;
//     }
// 
//     public Exception getErrorException() {
//         return errorException;
//     }
// 
//     public boolean isError() {
//         return isError;
//     }
// }
// 
// Path: force-update/src/main/java/net/skoumal/forceupdate/util/Http.java
// public class Http {
// 
//     private static final int HTTP_TIMEOUT = 10 * 1000;
// 
//     public static String loadString(URL gUrl) throws IOException {
//         HttpURLConnection urlConnection = null;
//         try {
// 
//             urlConnection = (HttpURLConnection) gUrl.openConnection();
//             urlConnection.setRequestMethod("GET");
//             urlConnection.setUseCaches(false);
//             urlConnection.setConnectTimeout(HTTP_TIMEOUT);
//             urlConnection.setReadTimeout(HTTP_TIMEOUT);
//             urlConnection.connect();
// 
//             int status = urlConnection.getResponseCode();
//             if(status >= 200 && status < 300) {
// 
//                 //TODO [1] fix this to not add new line sign to last line
//                 InputStream inputStream = urlConnection.getInputStream();
//                 BufferedReader responseReader = new BufferedReader(new InputStreamReader(inputStream));
//                 StringBuilder response = new StringBuilder();
//                 String line;
//                 boolean firstLine = true;
//                 while ((line = responseReader.readLine()) != null) {
//                     if(firstLine) {
//                         firstLine = false;
//                     } else {
//                         response.append('\n');
//                     }
//                     response.append(line);
//                 }
// 
//                 return response.toString();
//             } else {
//                 throw new IOException("HTTP status code " + status + " returned.");
//             }
// 
//         } finally {
//             if(urlConnection != null) {
//                 urlConnection.disconnect();
//             }
//         }
//     }
// 
// }


import net.skoumal.forceupdate.VersionResult;
import net.skoumal.forceupdate.util.Http;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

package net.skoumal.forceupdate.provider;



/**
 * Created by gingo on 6.10.2016.
 */
public abstract class AbstractHttpMasterVersionProvider extends MasterVersionProvider {

    private URL url;

    public AbstractHttpMasterVersionProvider(String gUrl) {

        try {
            url = new URL(gUrl);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    public String getUrl() {
        return url.toString();
    }

    protected abstract void processHttpResponseAndPutVersions(String gResponseString);

    @Override
    protected void fetchAndPutVersions() {
        try {

// Path: force-update/src/main/java/net/skoumal/forceupdate/VersionResult.java
// public class VersionResult {
// 
//     private List<Version> versionList = new ArrayList<>(1);
// 
//     private List<String> payloadList = new ArrayList<>(1);
// 
//     private boolean isError = false;
// 
//     private String errorMessage = null;
// 
//     private Exception errorException = null;
// 
//     public VersionResult(Version gVersion, String gPayload) {
//         versionList.add(gVersion);
//         payloadList.add(gPayload);
//     }
// 
//     public VersionResult(String gErrorMessage, Exception gErrorException) {
//         errorMessage = gErrorMessage;
//         errorException = gErrorException;
//         isError = true;
//     }
// 
//     public VersionResult(List<Version> gVersionList, List<String> gPayloadList) {
//         versionList = gVersionList;
//         payloadList = gPayloadList;
//     }
// 
//     public Version getVersion() {
//         if(isError || versionList.size() < 1) {
//             return null;
//         } else {
//             return versionList.get(0);
//         }
//     }
// 
//     public String getPayload() {
//         if(isError || payloadList.size() < 1) {
//             return null;
//         } else {
//             return payloadList.get(0);
//         }
//     }
// 
//     public List<Version> getVersionList() {
//         return versionList;
//     }
// 
//     public List<String> getPayloadList() {
//         return payloadList;
//     }
// 
//     public String getErrorMessage() {
//         return errorMessage;
//     }
// 
//     public Exception getErrorException() {
//         return errorException;
//     }
// 
//     public boolean isError() {
//         return isError;
//     }
// }
// 
// Path: force-update/src/main/java/net/skoumal/forceupdate/util/Http.java
// public class Http {
// 
//     private static final int HTTP_TIMEOUT = 10 * 1000;
// 
//     public static String loadString(URL gUrl) throws IOException {
//         HttpURLConnection urlConnection = null;
//         try {
// 
//             urlConnection = (HttpURLConnection) gUrl.openConnection();
//             urlConnection.setRequestMethod("GET");
//             urlConnection.setUseCaches(false);
//             urlConnection.setConnectTimeout(HTTP_TIMEOUT);
//             urlConnection.setReadTimeout(HTTP_TIMEOUT);
//             urlConnection.connect();
// 
//             int status = urlConnection.getResponseCode();
//             if(status >= 200 && status < 300) {
// 
//                 //TODO [1] fix this to not add new line sign to last line
//                 InputStream inputStream = urlConnection.getInputStream();
//                 BufferedReader responseReader = new BufferedReader(new InputStreamReader(inputStream));
//                 StringBuilder response = new StringBuilder();
//                 String line;
//                 boolean firstLine = true;
//                 while ((line = responseReader.readLine()) != null) {
//                     if(firstLine) {
//                         firstLine = false;
//                     } else {
//                         response.append('\n');
//                     }
//                     response.append(line);
//                 }
// 
//                 return response.toString();
//             } else {
//                 throw new IOException("HTTP status code " + status + " returned.");
//             }
// 
//         } finally {
//             if(urlConnection != null) {
//                 urlConnection.disconnect();
//             }
//         }
//     }
// 
// }


// Path: force-update/src/main/java/net/skoumal/forceupdate/provider/AbstractHttpMasterVersionProvider.java
import net.skoumal.forceupdate.VersionResult;
import net.skoumal.forceupdate.util.Http;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

package net.skoumal.forceupdate.provider;



/**
 * Created by gingo on 6.10.2016.
 */
public abstract class AbstractHttpMasterVersionProvider extends MasterVersionProvider {

    private URL url;

    public AbstractHttpMasterVersionProvider(String gUrl) {

        try {
            url = new URL(gUrl);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    public String getUrl() {
        return url.toString();
    }

    protected abstract void processHttpResponseAndPutVersions(String gResponseString);

    @Override
    protected void fetchAndPutVersions() {
        try {

            String stringResponse = Http.loadString(url);
