Package com.carrotsearch.ant.tasks.junit4.events

Source Code of com.carrotsearch.ant.tasks.junit4.events.Deserializer

package com.carrotsearch.ant.tasks.junit4.events;

import java.io.*;

import com.google.common.base.Charsets;
import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;

/**
* Event deserializer.
*/
public class Deserializer {
  private JsonReader input;
  private Gson gson;

  public Deserializer(InputStream is, ClassLoader refLoader) throws IOException {
    input = new JsonReader(new InputStreamReader(is, Charsets.UTF_8));
    input.setLenient(true);

    gson = Serializer.createGSon(refLoader);
  }

  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 = gson.fromJson(input, type.eventClass);
    input.endArray();
    return event;
  }
}
TOP

Related Classes of com.carrotsearch.ant.tasks.junit4.events.Deserializer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.