Search in sources :

Example 1 with JsonToken

use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonToken in project randomizedtesting by randomizedtesting.

the class DumpStreamsFromEventStream method main.

public static void main(String[] args) throws Exception {
    File inputFile;
    if (args.length != 1) {
        System.err.println("Usage: [input.events]");
        System.exit(1);
        return;
    } else {
        inputFile = new File(args[0]);
    }
    Closer closer = Closer.create();
    try {
        OutputStream sysout = new BufferedOutputStream(new FileOutputStream(new File(inputFile.getAbsolutePath() + ".sysout")));
        closer.register(sysout);
        OutputStream syserr = new BufferedOutputStream(new FileOutputStream(new File(inputFile.getAbsolutePath() + ".syserr")));
        closer.register(syserr);
        InputStream is = new BufferedInputStream(new FileInputStream(inputFile));
        closer.register(is);
        JsonReader input = new JsonReader(new InputStreamReader(is, Charsets.UTF_8));
        input.setLenient(true);
        JsonToken peek;
        while (true) {
            peek = input.peek();
            if (peek == JsonToken.END_DOCUMENT) {
                return;
            }
            input.beginArray();
            EventType type = EventType.valueOf(input.nextString());
            switch(type) {
                case APPEND_STDERR:
                    IStreamEvent.class.cast(type.deserialize(input)).copyTo(syserr);
                    break;
                case APPEND_STDOUT:
                    IStreamEvent.class.cast(type.deserialize(input)).copyTo(sysout);
                    break;
                default:
                    input.skipValue();
            }
            input.endArray();
        }
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) InputStreamReader(java.io.InputStreamReader) EventType(com.carrotsearch.ant.tasks.junit4.events.EventType) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileInputStream(java.io.FileInputStream) IStreamEvent(com.carrotsearch.ant.tasks.junit4.events.IStreamEvent) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) JsonReader(com.carrotsearch.ant.tasks.junit4.gson.stream.JsonReader) JsonToken(com.carrotsearch.ant.tasks.junit4.gson.stream.JsonToken) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with JsonToken

use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonToken in project randomizedtesting by randomizedtesting.

the class Deserializer method deserialize.

public IEvent deserialize() throws IOException {
    JsonToken peek = input.peek();
    if (peek == JsonToken.END_ARRAY)
        return null;
    input.beginArray();
    EventType type = EventType.valueOf(input.nextString());
    IEvent event = type.deserialize(input);
    input.endArray();
    return event;
}
Also used : JsonToken(com.carrotsearch.ant.tasks.junit4.gson.stream.JsonToken)

Aggregations

JsonToken (com.carrotsearch.ant.tasks.junit4.gson.stream.JsonToken)2 EventType (com.carrotsearch.ant.tasks.junit4.events.EventType)1 IStreamEvent (com.carrotsearch.ant.tasks.junit4.events.IStreamEvent)1 JsonReader (com.carrotsearch.ant.tasks.junit4.gson.stream.JsonReader)1 Closer (com.google.common.io.Closer)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1