use of com.koushikdutta.async.parser.StringParser 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.parser.StringParser 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.parser.StringParser in project AndroidAsync by koush.
the class FileTests method testFileDataEmitter.
public void testFileDataEmitter() throws Exception {
final Semaphore semaphore = new Semaphore(0);
File f = getContext().getFileStreamPath("test.txt");
StreamUtility.writeFile(f, "hello world");
FileDataEmitter fdm = new FileDataEmitter(AsyncServer.getDefault(), f);
final Md5 md5 = Md5.createInstance();
Future<String> stringBody = new StringParser().parse(fdm).setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
semaphore.release();
}
});
fdm.resume();
assertTrue("timeout", semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS));
assertEquals("hello world", stringBody.get());
}
Aggregations