Java
Chilkat2 Java
Clear a REST Response Body Stream Destination
See more REST Examples
Demonstrates Rest.ClearResponseBodyStream, which removes a response-stream destination previously configured with SetResponseBodyStream.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. Clearing the destination restores normal behavior, in which the full-request convenience methods return the response body rather than streaming it.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.Stream;
public class ChilkatExample {
public static void main(String[] args) {
Rest rest = new Rest();
boolean bTls = true;
boolean bAutoReconnect = true;
try {
rest.connect("example.com", 443, bTls, bAutoReconnect);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// The file paths are relative to the application's current working directory. Absolute paths
// may also be used. Supply the paths appropriate to your own environment.
Stream respStream = new Stream();
respStream.setSinkFile("qa_output/response_body.dat");
boolean bAutoSetCharset = true;
int expectedStatus = 200;
try {
rest.setResponseBodyStream(expectedStatus, bAutoSetCharset, respStream);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Clear the response-stream destination previously configured, so subsequent full-request calls
// return the response body normally instead of streaming it.
rest.clearResponseBodyStream();
System.out.println("Response body streaming cleared.");
}
}