use of com.koushikdutta.async.callback.CompletedCallback in project AndroidAsync by koush.
the class FilteredDataEmitter method setDataEmitter.
@Override
public void setDataEmitter(DataEmitter emitter) {
if (mEmitter != null) {
mEmitter.setDataCallback(null);
}
mEmitter = emitter;
mEmitter.setDataCallback(this);
mEmitter.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
report(ex);
}
});
}
use of com.koushikdutta.async.callback.CompletedCallback in project ion by koush.
the class Issues method testIssue312.
public void testIssue312() throws Exception {
String b64 = "SFRUUC8xLjAgMzAyIEZvdW5kDQpTZXQtQ29va2ll\n" + "OlNFU1NJT049NUJBRDlERTEwQjY0NjgwNDsKTG9j\n" + "YXRpb246IGhvbWUuY2dpCkNvbnRlbnQtdHlwZTog\n" + "dGV4dC9odG1sCgo8aHRtbD48aGVhZD48bWV0YSBo\n" + "dHRwLWVxdWl2PSdyZWZyZXNoJyBjb250ZW50PScw\n" + "OyB1cmw9aG9tZS5jZ2knPjwvbWV0YT48L2hlYWQ+\n" + "PGJvZHk+PC9ib2R5PjwvaHRtbD4K";
/*
HTTP/1.0 302 Found
Set-Cookie:SESSION=5BAD9DE10B646804;
Location: home.cgi
Content-type: text/html
<html><head><meta http-equiv='refresh' content='0; url=home.cgi'></meta></head><body></body></html>
*/
// the above is using newlines, and not CRLF.
final byte[] responseData = Base64.decode(b64, 0);
server = Ion.getDefault(getContext()).getServer().listen(null, 0, new ListenCallback() {
@Override
public void onAccepted(final AsyncSocket socket) {
Util.writeAll(socket, responseData, new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
socket.end();
server.stop();
}
});
}
@Override
public void onListening(AsyncServerSocket socket) {
}
@Override
public void onCompleted(Exception ex) {
}
});
Ion.with(getContext()).load("http://localhost:" + server.getLocalPort()).followRedirect(false).asString().get();
}
use of com.koushikdutta.async.callback.CompletedCallback in project ion by koush.
the class StreamTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
AsyncHttpServer server = new AsyncHttpServer();
port = server.listen(0).getLocalPort();
server.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
response.code(200);
ByteBuffer b = ByteBufferList.obtain(random.length);
b.put(random);
b.flip();
ByteBufferList list = new ByteBufferList(b);
Util.writeAll(response, list, new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
response.end();
}
});
}
});
}
use of com.koushikdutta.async.callback.CompletedCallback in project PushSms by koush.
the class MiddlewareService method findOrCreateGcmSocket.
// given a registration, find/create the gcm socket that manages
// the secure connection between the two devices.
private GcmSocket findOrCreateGcmSocket(Registration registration) {
GcmSocket ret = gcmConnectionManager.findGcmSocket(registration);
if (ret == null) {
final GcmSocket gcmSocket = ret = gcmConnectionManager.createGcmSocket(registration, getNumber());
// parse data from the gcm connection as we get it
ret.setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
parseGcmMessage(gcmSocket, bb);
// save the registration info (sequence numbers changed, etc)
registry.register(gcmSocket.registration.endpoint, gcmSocket.registration);
}
});
// on error, fail over any pending messages for this number
ret.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
for (String pending : new ArrayList<String>(messagesAwaitingAck.keySet())) {
String numberPart = pending.split(":")[0];
if (!PhoneNumberUtils.compare(MiddlewareService.this, numberPart, gcmSocket.getNumber()))
continue;
GcmText gcmText = messagesAwaitingAck.get(pending);
if (gcmText == null)
continue;
gcmText.manageFailure(handler, smsManager);
}
}
});
}
return ret;
}
use of com.koushikdutta.async.callback.CompletedCallback in project AndroidAsync by koush.
the class MultipartTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
httpServer = new AsyncHttpServer();
httpServer.setErrorCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
fail();
}
});
httpServer.listen(AsyncServer.getDefault(), 5000);
httpServer.post("/", new HttpServerRequestCallback() {
int gotten = 0;
@Override
public void onRequest(final AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
final MultipartFormDataBody body = (MultipartFormDataBody) request.getBody();
body.setMultipartCallback(new MultipartCallback() {
@Override
public void onPart(Part part) {
if (part.isFile()) {
body.setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
gotten += bb.remaining();
bb.recycle();
}
});
}
}
});
request.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
response.send(body.getField("baz") + gotten + body.getField("foo"));
}
});
}
});
}
Aggregations