Search in sources :

Example 21 with AsyncResource

use of com.codename1.util.AsyncResource in project CodeRAD by shannah.

the class ParsingService method parseXML.

public AsyncResource<Element> parseXML(InputStream content, XMLParser parser) {
    AsyncResource<Element> out = new AsyncResource<Element>();
    start();
    thread.run(() -> {
        try {
            Element el = parser.parse(new InputStreamReader(content, "UTF-8"));
            if (autoCloseStreams)
                content.close();
            out.complete(el);
        } catch (Throwable ex) {
            out.error(ex);
        }
    });
    return out;
}
Also used : InputStreamReader(java.io.InputStreamReader) Element(com.codename1.xml.Element) AsyncResource(com.codename1.util.AsyncResource)

Example 22 with AsyncResource

use of com.codename1.util.AsyncResource in project CodeRAD by shannah.

the class ParsingService method parseJSON.

public AsyncResource<Map> parseJSON(String content, JSONParser parser) {
    AsyncResource<Map> out = new AsyncResource<Map>();
    start();
    thread.run(() -> {
        try {
            Map m = parser.parseJSON(new StringReader(content));
            out.complete(m);
        } catch (Throwable ex) {
            out.error(ex);
        }
    });
    return out;
}
Also used : StringReader(java.io.StringReader) AsyncResource(com.codename1.util.AsyncResource) Map(java.util.Map)

Aggregations

AsyncResource (com.codename1.util.AsyncResource)20 IOException (java.io.IOException)6 Timer (java.util.Timer)5 AbstractMedia (com.codename1.media.AbstractMedia)4 AsyncMedia (com.codename1.media.AsyncMedia)4 Media (com.codename1.media.Media)4 Map (java.util.Map)4 JFrame (javax.swing.JFrame)4 Element (com.codename1.xml.Element)3 InputStreamReader (java.io.InputStreamReader)3 Component (com.codename1.ui.Component)2 Form (com.codename1.ui.Form)2 Toolbar (com.codename1.ui.Toolbar)2 Motion (com.codename1.ui.animations.Motion)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 StringReader (java.io.StringReader)2 TimerTask (java.util.TimerTask)2 BillingResult (com.android.billingclient.api.BillingResult)1