Sample code for 30+ languages & platforms
Java

Setting a HTTP Max Response Size

Demonstrates the MaxResponseSize property.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

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

    CkHttp http = new CkHttp();

    int maxSz = 16384;
    http.put_MaxResponseSize(maxSz);

    //  Try to get something larger, such as hamlet.xml which is 279658 bytes
    String xmlStr = http.quickGetStr("https://chilkatsoft.com/hamlet.xml");
    if (http.get_LastMethodSuccess() == false) {
        //  If the LastErrorText contains the string "MaxResponseSize",
        //  then the HTTP request failed because the response body would've been larger than the max allowed response size.
        System.out.println(http.lastErrorText());
        return;
        }

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