Created
April 11, 2023 14:26
-
-
Save apoorvparijat/8a2c6c7d0ffe08d931630202b2c5942a to your computer and use it in GitHub Desktop.
Completion handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.asynchttpclient.*; | |
| import org.asynchttpclient.AsyncHandler; | |
| import org.asynchttpclient.HttpResponseBodyPart; | |
| import org.asynchttpclient.HttpResponseHeaders; | |
| import org.asynchttpclient.HttpResponseStatus; | |
| public class MyAsyncHandler implements AsyncHandler<String> { | |
| private final StringBuilder responseBodyBuilder = new StringBuilder(); | |
| @Override | |
| public State onStatusReceived(HttpResponseStatus status) throws Exception { | |
| return State.CONTINUE; | |
| } | |
| @Override | |
| public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { | |
| return State.CONTINUE; | |
| } | |
| @Override | |
| public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { | |
| responseBodyBuilder.append(new String(bodyPart.getBodyPartBytes())); | |
| return State.CONTINUE; | |
| } | |
| @Override | |
| public String onCompleted() throws Exception { | |
| return responseBodyBuilder.toString(); | |
| } | |
| @Override | |
| public void onThrowable(Throwable t) { | |
| t.printStackTrace(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment