use of com.koushikdutta.async.FilteredDataEmitter in project ion by koush.
the class GsonTests method testParserCastingSuccess.
public void testParserCastingSuccess() throws Exception {
ByteBufferList b = new ByteBufferList(ByteBuffer.wrap("{}".getBytes()));
FilteredDataEmitter emitter = new FilteredDataEmitter() {
@Override
public boolean isPaused() {
return false;
}
};
GsonObjectParser g = new GsonObjectParser();
Future<JsonObject> ret = g.parse(emitter);
emitter.onDataAvailable(emitter, b);
emitter.getEndCallback().onCompleted(null);
JsonObject j = ret.get();
assertNotNull(j);
}
use of com.koushikdutta.async.FilteredDataEmitter in project AndroidAsync by koush.
the class ParserTests method testUtf8String.
public void testUtf8String() throws Exception {
StringParser p = new StringParser();
FilteredDataEmitter f = new FilteredDataEmitter() {
@Override
public String charset() {
return Charsets.UTF_8.name();
}
@Override
public boolean isPaused() {
return false;
}
};
Future<String> ret = p.parse(f);
ByteBufferList l = new ByteBufferList();
l.add(ByteBuffer.wrap("æææ".getBytes(Charsets.UTF_8.name())));
f.onDataAvailable(f, l);
f.getEndCallback().onCompleted(null);
String s = ret.get();
assertEquals(s, "æææ");
}
use of com.koushikdutta.async.FilteredDataEmitter in project AndroidAsync by koush.
the class ParserTests method testString.
public void testString() throws Exception {
StringParser p = new StringParser();
FilteredDataEmitter f = new FilteredDataEmitter() {
@Override
public boolean isPaused() {
return false;
}
};
Future<String> ret = p.parse(f);
ByteBufferList l = new ByteBufferList();
l.add(ByteBuffer.wrap("foo".getBytes(Charsets.US_ASCII.name())));
f.onDataAvailable(f, l);
f.getEndCallback().onCompleted(null);
String s = ret.get();
assertEquals(s, "foo");
}
use of com.koushikdutta.async.FilteredDataEmitter in project AndroidAsync by koush.
the class ByteUtilTests method testPushParserUntil.
public void testPushParserUntil() {
valRead = 0;
FilteredDataEmitter mock = new FilteredDataEmitter() {
@Override
public boolean isPaused() {
return false;
}
};
new PushParser(mock).until((byte) 0, new DataCallback.NullDataCallback()).readInt(new PushParser.ParseCallback<Integer>() {
public void parsed(Integer arg) {
valRead = arg;
}
});
byte[] bytes = new byte[] { 5, 5, 5, 5, 0, 10, 5, 5, 5 };
Util.emitAllData(mock, new ByteBufferList(bytes));
assertEquals(valRead, 0x0A050505);
}
use of com.koushikdutta.async.FilteredDataEmitter in project AndroidAsync by koush.
the class ByteUtilTests method testTapCallback.
public void testTapCallback() {
readInt = 0;
readByte = 0;
readString = "";
FilteredDataEmitter mock = new FilteredDataEmitter() {
@Override
public boolean isPaused() {
return false;
}
};
new PushParser(mock).readInt().readByte().readString().tap(new TapCallback() {
void tap(int i, byte b, String s) {
readInt = i;
readByte = b;
readString = s;
}
});
byte[] bytes = new byte[] { 10, 5, 5, 5, 3, 0, 0, 0, 4, 116, 101, 115, 116 };
Util.emitAllData(mock, new ByteBufferList(bytes));
assertEquals(readInt, 0x0A050505);
assertEquals(readByte, (byte) 3);
assertEquals(readString, "test");
}
Aggregations