Sample code for 30+ languages & platforms
Java

Example: Http.ResumeDownloadBd method

Demonstrates the ResumeDownloadBd method.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;

public class ChilkatExample {

    public static void main(String[] args) {
        boolean success = false;

        Http http = new Http();
        http.setKeepResponseBody(true);

        // To demonstrate resuming a download, we've created a file on the chilkatsoft.com
        // web server that contains the first 82,379 bytes of the full  279,658 bytes of the hamlet.xml file.

        // We'll first download the partial file, and pretend it was a previous incomplete attempt to download the entire file.
        BinData bd = new BinData();
        try {
            http.downloadBd("https://www.chilkatsoft.com/testData/hamlet_partial.xml", bd);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Download the remainder of hamlet.xml.
        try {
            http.resumeDownloadBd("https://www.chilkatsoft.com/testData/hamlet.xml", bd);
            success = true;
        } catch (ChilkatException e) {
            success = false;
        }
        int statusCode = http.getLastStatus();
        if (!success) {
            if (statusCode == 0) {
                // Unable to either send the request or get the response.
                System.out.println(http.getLastErrorText());
            } else {
                // We got a response, but the status code was not in the 200s
                System.out.println("Response status code: " + statusCode);
                // Examine the response body.
                System.out.println("Response body:");
                System.out.println(http.getLastResponseBody());
            }

            System.out.println("Download failed.");
        } else {
            System.out.println("Download success, response status = " + statusCode);
        }

        // The hamlet.xml file should be 279,658 bytes
        System.out.println("size of hamlet.xml: " + bd.getNumBytes());

        System.out.println("Success.");
    }
}