//# 1 errors, 194 messages
//#
/*
    //#Downloader.java:1:1: class: com.dmdirc.util.Downloader
    //#Downloader.java:1:1: method: com.dmdirc.util.Downloader.com.dmdirc.util.Downloader__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.util;

import com.dmdirc.logger.ErrorLevel;
import com.dmdirc.logger.Logger;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Allows easy downloading of files from HTTP sites.
 *
 * @author Chris
 */
public final class Downloader {
    
    /** Creates a new instance of Downloader. */
    private Downloader() {
    //#Downloader.java:52: method: void com.dmdirc.util.Downloader.com.dmdirc.util.Downloader()
        // Shouldn't be used
    }
    //#Downloader.java:54: end of method: void com.dmdirc.util.Downloader.com.dmdirc.util.Downloader()
    
    /**
     * Retrieves the specified page.
     * 
     * @param url The URL to retrieve
     * @return A list of lines received from the server
     * @throws java.net.MalformedURLException If the URL is malformed
     * @throws java.io.IOException If there's an I/O error while downloading
     */
    public static List<String> getPage(final String url)
            throws MalformedURLException, IOException {
        
        return getPage(url, "");
    //#Downloader.java:67: method: List com.dmdirc.util.Downloader.getPage(String)
    //#input(List getPage(String)): url
    //#output(List getPage(String)): new ArrayList(getPage#1*) num objects
    //#output(List getPage(String)): return_value
    //#new obj(List getPage(String)): new ArrayList(getPage#1*)
    //#post(List getPage(String)): return_value == &new ArrayList(getPage#1*)
    //#post(List getPage(String)): new ArrayList(getPage#1*) num objects == 1
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URL
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URL:openConnection
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URLConnection:setUseCaches
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URLConnection:setDoInput
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.lang.String:length
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URLConnection:setDoOutput
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URLConnection:setConnectTimeout
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URLConnection:setRequestProperty
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URLConnection:getOutputStream
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.io.DataOutputStream
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.io.DataOutputStream:writeBytes
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.io.DataOutputStream:flush
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.io.DataOutputStream:close
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.net.URLConnection:getInputStream
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.io.InputStreamReader
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.io.BufferedReader
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.io.BufferedReader:readLine
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.util.List:add
    //#unanalyzed(List getPage(String)): Effects-of-calling:java.io.BufferedReader:close
    //#Downloader.java:67: end of method: List com.dmdirc.util.Downloader.getPage(String)
    }

    /**
     * Retrieves the specified page, sending the specified post data.
     * 
     * @param url The URL to retrieve
     * @param postData The raw POST data to send
     * @return A list of lines received from the server
     * @throws java.net.MalformedURLException If the URL is malformed
     * @throws java.io.IOException If there's an I/O error while downloading
     */    
    public static List<String> getPage(final String url, final String postData)
            throws MalformedURLException, IOException {
        
        final List<String> res = new ArrayList<String>();
    //#Downloader.java:82: method: List com.dmdirc.util.Downloader.getPage(String, String)
    //#input(List getPage(String, String)): postData
    //#input(List getPage(String, String)): url
    //#output(List getPage(String, String)): new ArrayList(getPage#1) num objects
    //#output(List getPage(String, String)): return_value
    //#new obj(List getPage(String, String)): new ArrayList(getPage#1)
    //#pre[1] (List getPage(String, String)): postData != null
    //#post(List getPage(String, String)): return_value == &new ArrayList(getPage#1)
    //#post(List getPage(String, String)): new ArrayList(getPage#1) num objects == 1
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.net.URL
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.net.URL:openConnection
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.net.URLConnection:setUseCaches
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.net.URLConnection:setDoInput
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.lang.String:length
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.net.URLConnection:setDoOutput
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.net.URLConnection:setConnectTimeout
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.net.URLConnection:setRequestProperty
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.net.URLConnection:getOutputStream
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.io.DataOutputStream
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.io.DataOutputStream:writeBytes
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.io.DataOutputStream:flush
    //#unanalyzed(List getPage(String, String)): Effects-of-calling:java.io.DataOutputStream:close
    //#test_vector(List getPage(String, String)): java.io.BufferedReader:readLine(...)@92: Addr_Set{null}, Inverse{null}
        
        final URLConnection urlConn = getConnection(url, postData);
        
        final BufferedReader in = new BufferedReader(
                new InputStreamReader(urlConn.getInputStream()));
        
        String line;
        
        do {
            line = in.readLine();
            
            if (line != null) {
                res.add(line);
            }
        } while (line != null);
        
        in.close();
        
        return res;
    //#Downloader.java:101: end of method: List com.dmdirc.util.Downloader.getPage(String, String)
    }
    
    /**
     * Retrieves the specified page, sending the specified post data.
     * 
     * @param url The URL to retrieve
     * @param postData A map of post data that should be sent
     * @return A list of lines received from the server
     * @throws java.net.MalformedURLException If the URL is malformed
     * @throws java.io.IOException If there's an I/O error while downloading
     */    
    public static List<String> getPage(final String url, final Map<String, String> postData)
            throws MalformedURLException, IOException {
        
        final StringBuilder data = new StringBuilder();
    //#Downloader.java:116: method: List com.dmdirc.util.Downloader.getPage(String, Map)
    //#input(List getPage(String, Map)): com.dmdirc.logger.ErrorLevel.MEDIUM
    //#input(List getPage(String, Map)): postData
    //#input(List getPage(String, Map)): url
    //#output(List getPage(String, Map)): new ArrayList(getPage#1*) num objects
    //#output(List getPage(String, Map)): return_value
    //#new obj(List getPage(String, Map)): new ArrayList(getPage#1*)
    //#pre[1] (List getPage(String, Map)): (soft) postData != null
    //#presumption(List getPage(String, Map)): init'ed(com.dmdirc.logger.ErrorLevel.MEDIUM)
    //#presumption(List getPage(String, Map)): java.util.Iterator:next(...)@119 != null
    //#presumption(List getPage(String, Map)): java.util.Map:entrySet(...)@119 != null
    //#post(List getPage(String, Map)): return_value == &new ArrayList(getPage#1*)
    //#post(List getPage(String, Map)): new ArrayList(getPage#1*) num objects == 1
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URL
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URL:openConnection
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URLConnection:setUseCaches
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URLConnection:setDoInput
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.lang.String:length
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URLConnection:setDoOutput
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URLConnection:setConnectTimeout
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URLConnection:setRequestProperty
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URLConnection:getOutputStream
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.io.DataOutputStream
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.io.DataOutputStream:writeBytes
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.io.DataOutputStream:flush
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.io.DataOutputStream:close
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.net.URLConnection:getInputStream
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.io.InputStreamReader
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.io.BufferedReader
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.io.BufferedReader:readLine
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.util.List:add
    //#unanalyzed(List getPage(String, Map)): Effects-of-calling:java.io.BufferedReader:close
        
        try {
            for (Map.Entry<String, String> entry : postData.entrySet()) {
                data.append('&');
                data.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
                data.append('=');
                data.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
            }
        } catch (UnsupportedEncodingException ex) {
            Logger.appError(ErrorLevel.MEDIUM, "URLEncoder doesn't support UTF-8", ex);
    //#Downloader.java:126: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.logger.Logger:appError(ErrorLevel, String, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.util.Downloader
    //#    method: List getPage(String, Map)
    //#    unanalyzed callee: void com.dmdirc.logger.Logger:appError(ErrorLevel, String, Throwable)
        }
        
        return getPage(url, data.length() == 0 ? "" : data.substring(1));
    //#Downloader.java:129: end of method: List com.dmdirc.util.Downloader.getPage(String, Map)
    }
    
    /**
     * Downloads the specified page to disk.
     * 
     * @param url The URL to retrieve
     * @param file The file to save the page to
     * @throws java.io.IOException If there's an I/O error while downloading
     */    
    public static void downloadPage(final String url, final String file)
            throws IOException {    
        downloadPage(url, file, null);
    //#Downloader.java:141: method: void com.dmdirc.util.Downloader.downloadPage(String, String)
    //#input(void downloadPage(String, String)): com/dmdirc/updater/Update.__Dispatch_Table.downloadProgress(F)V
    //#input(void downloadPage(String, String)): com/dmdirc/updater/Update.__Dispatch_Table.setIndeterminate(Z)V
    //#input(void downloadPage(String, String)): com/dmdirc/updater/UpdateChecker$1.__Dispatch_Table.updateProgressChange(Lcom/dmdirc/updater/Update;F)V
    //#input(void downloadPage(String, String)): com/dmdirc/updater/UpdateListener.__Descendant_Table[com/dmdirc/updater/UpdateChecker$1]
    //#input(void downloadPage(String, String)): com/dmdirc/updater/UpdateListener.__Descendant_Table[com/dmdirc/updater/UpdateListener]
    //#input(void downloadPage(String, String)): com/dmdirc/updater/UpdateListener.__Descendant_Table[others]
    //#input(void downloadPage(String, String)): com/dmdirc/updater/UpdateListener.__Dispatch_Table.updateProgressChange(Lcom/dmdirc/updater/Update;F)V
    //#input(void downloadPage(String, String)): com/dmdirc/util/DownloadListener.__Descendant_Table[com/dmdirc/updater/Update]
    //#input(void downloadPage(String, String)): com/dmdirc/util/DownloadListener.__Descendant_Table[com/dmdirc/util/DownloadListener]
    //#input(void downloadPage(String, String)): com/dmdirc/util/DownloadListener.__Descendant_Table[others]
    //#input(void downloadPage(String, String)): com/dmdirc/util/DownloadListener.__Dispatch_Table.downloadProgress(F)V
    //#input(void downloadPage(String, String)): com/dmdirc/util/DownloadListener.__Dispatch_Table.setIndeterminate(Z)V
    //#input(void downloadPage(String, String)): file
    //#input(void downloadPage(String, String)): url
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URL
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URL:openConnection
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URLConnection:setUseCaches
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URLConnection:setDoInput
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.lang.String:length
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URLConnection:setDoOutput
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URLConnection:setConnectTimeout
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URLConnection:setRequestProperty
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URLConnection:getOutputStream
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.DataOutputStream
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.DataOutputStream:writeBytes
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.DataOutputStream:flush
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.DataOutputStream:close
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URLConnection:getInputStream
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.File
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.FileOutputStream
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.net.URLConnection:getContentLength
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:setIndeterminate
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.InputStream:read
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.FileOutputStream:write
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:downloadProgress
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.InputStream:close
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.io.FileOutputStream:close
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void downloadPage(String, String)): Effects-of-calling:updateProgressChange
    }
    //#Downloader.java:142: end of method: void com.dmdirc.util.Downloader.downloadPage(String, String)
    
    /**
     * Downloads the specified page to disk.
     * 
     * @param url The URL to retrieve
     * @param file The file to save the page to
     * @param listener The progress listener for this download
     * @throws java.io.IOException If there's an I/O error while downloading
     */    
    public static void downloadPage(final String url, final String file,
            final DownloadListener listener) throws IOException {
                
        final URLConnection urlConn = getConnection(url, "");
    //#Downloader.java:155: method: void com.dmdirc.util.Downloader.downloadPage(String, String, DownloadListener)
    //#Downloader.java:155: Warning: suspicious precondition
    //#    The precondition for listener.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.util.Downloader
    //#    method: void downloadPage(String, String, DownloadListener)
    //#    suspicious precondition index: [3]
    //#    Attribs:  Soft
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/updater/Update.__Dispatch_Table.downloadProgress(F)V
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/updater/Update.__Dispatch_Table.setIndeterminate(Z)V
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/updater/UpdateChecker$1.__Dispatch_Table.updateProgressChange(Lcom/dmdirc/updater/Update;F)V
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/updater/UpdateListener.__Descendant_Table[com/dmdirc/updater/UpdateChecker$1]
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/updater/UpdateListener.__Descendant_Table[com/dmdirc/updater/UpdateListener]
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/updater/UpdateListener.__Descendant_Table[others]
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/updater/UpdateListener.__Dispatch_Table.updateProgressChange(Lcom/dmdirc/updater/Update;F)V
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/util/DownloadListener.__Descendant_Table[com/dmdirc/updater/Update]
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/util/DownloadListener.__Descendant_Table[com/dmdirc/util/DownloadListener]
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/util/DownloadListener.__Descendant_Table[others]
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/util/DownloadListener.__Dispatch_Table.downloadProgress(F)V
    //#input(void downloadPage(String, String, DownloadListener)): com/dmdirc/util/DownloadListener.__Dispatch_Table.setIndeterminate(Z)V
    //#input(void downloadPage(String, String, DownloadListener)): file
    //#input(void downloadPage(String, String, DownloadListener)): listener
    //#input(void downloadPage(String, String, DownloadListener)): listener.__Tag
    //#input(void downloadPage(String, String, DownloadListener)): listener.listeners
    //#input(void downloadPage(String, String, DownloadListener)): url
    //#output(void downloadPage(String, String, DownloadListener)): listener.progress
    //#pre[3] (void downloadPage(String, String, DownloadListener)): (soft) listener.__Tag in {com/dmdirc/updater/Update, com/dmdirc/util/DownloadListener}
    //#pre[4] (void downloadPage(String, String, DownloadListener)): (soft) listener.listeners != null
    //#presumption(void downloadPage(String, String, DownloadListener)): (float) (java.net.URLConnection:getContentLength(...)@160) != +0
    //#presumption(void downloadPage(String, String, DownloadListener)): java.net.URLConnection:getInputStream(...)@159 != null
    //#post(void downloadPage(String, String, DownloadListener)): possibly_updated(listener.progress)
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.net.URL
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.net.URL:openConnection
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.net.URLConnection:setUseCaches
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.net.URLConnection:setDoInput
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.lang.String:length
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.net.URLConnection:setDoOutput
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.net.URLConnection:setConnectTimeout
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.net.URLConnection:setRequestProperty
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.net.URLConnection:getOutputStream
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.io.DataOutputStream
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.io.DataOutputStream:writeBytes
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.io.DataOutputStream:flush
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.io.DataOutputStream:close
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void downloadPage(String, String, DownloadListener)): Effects-of-calling:updateProgressChange
    //#test_vector(void downloadPage(String, String, DownloadListener)): listener: Addr_Set{null}, Inverse{null}
    //#test_vector(void downloadPage(String, String, DownloadListener)): java.io.InputStream:read(...)@171: {-2_147_483_648..0}, {1..4_294_967_295}
    //#test_vector(void downloadPage(String, String, DownloadListener)): java.net.URLConnection:getContentLength(...)@160: {-1}, {-2_147_483_648..-2, 0..4_294_967_295}
        final File myFile = new File(file);
        
        final FileOutputStream output = new FileOutputStream(myFile);
        final InputStream input = urlConn.getInputStream();
        final int length = urlConn.getContentLength();
        int current = 0;

        if (listener != null) {
            listener.setIndeterminate(length == -1);
        }
        
        final byte[] buffer = new byte[512];
        int count;
        
        do {
            count = input.read(buffer);
            
            if (count > 0) {
                current += count;
    //#Downloader.java:174: ?overflow
    //#    current + count in {-2_147_483_648..4_294_967_295}
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.util.Downloader
    //#    method: void downloadPage(String, String, DownloadListener)
    //#    basic block: bb_8
    //#    assertion: current + count in {-2_147_483_648..4_294_967_295}
    //#    VN: java.io.InputStream:read(...)@171 + current
    //#    Expected: {-2_147_483_648..4_294_967_295, Invalid}
    //#    Bad: {4_294_967_296..8_589_934_590}
    //#    Attribs:  Int  Bad > Exp
                output.write(buffer, 0, count);
                
                if (listener != null && length != -1) {
                    listener.downloadProgress(100 * (float) current / length);
                }
            }
        } while (count > 0);

        input.close();
        output.close();
    }    
    //#Downloader.java:185: end of method: void com.dmdirc.util.Downloader.downloadPage(String, String, DownloadListener)
    
    /**
     * Creates an URL connection for the specified URL and data.
     * 
     * @param url The URL to connect to
     * @param postData The POST data to pass to the URL
     * @return An URLConnection for the specified URL/data
     * @throws java.net.MalformedURLException If the specified URL is malformed
     * @throws java.io.IOException If an I/O exception occurs while connecting
     */
    private static URLConnection getConnection(final String url, final String postData)
            throws MalformedURLException, IOException {
        final URL myUrl = new URL(url);
    //#Downloader.java:198: method: URLConnection com.dmdirc.util.Downloader.getConnection(String, String)
    //#input(URLConnection getConnection(String, String)): postData
    //#input(URLConnection getConnection(String, String)): url
    //#output(URLConnection getConnection(String, String)): return_value
    //#pre[1] (URLConnection getConnection(String, String)): postData != null
    //#presumption(URLConnection getConnection(String, String)): java.net.URL:openConnection(...)@199 != null
    //#post(URLConnection getConnection(String, String)): return_value != null
    //#test_vector(URLConnection getConnection(String, String)): java.lang.String:length(...)@206: {0}, {1..4_294_967_295}
        final URLConnection urlConn = myUrl.openConnection();
        
        urlConn.setUseCaches(false);
        urlConn.setDoInput(true);
        urlConn.setDoOutput(postData.length() > 0);
        urlConn.setConnectTimeout(10000);
        
        if (postData.length() > 0) {
            urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            
            final DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
            out.writeBytes(postData);
            out.flush();
            out.close();
        }
        
        return urlConn;
    //#Downloader.java:215: end of method: URLConnection com.dmdirc.util.Downloader.getConnection(String, String)
    }
    
}    //#output(com.dmdirc.util.Downloader__static_init): __Descendant_Table[com/dmdirc/util/Downloader]
    //#post(com.dmdirc.util.Downloader__static_init): __Descendant_Table[com/dmdirc/util/Downloader] == &__Dispatch_Table
    //#Downloader.java:: end of method: com.dmdirc.util.Downloader.com.dmdirc.util.Downloader__static_init
    //#Downloader.java:: end of class: com.dmdirc.util.Downloader
