Search in sources :

Example 6 with JsonWriter

use of com.google.gson.stream.JsonWriter in project buck by facebook.

the class WorkerProcessProtocolZeroTest method testSendHandshake.

@Test
public void testSendHandshake() throws IOException {
    StringWriter jsonSentToWorkerProcess = new StringWriter();
    WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, new JsonWriter(jsonSentToWorkerProcess), dummyJsonReader, newTempFile());
    int handshakeID = 123;
    protocol.sendHandshake(handshakeID);
    String expectedJson = String.format("[{\"id\":%d,\"type\":\"handshake\",\"protocol_version\":\"0\",\"capabilities\":[]}", handshakeID);
    assertThat(jsonSentToWorkerProcess.toString(), Matchers.containsString(expectedJson));
}
Also used : StringWriter(java.io.StringWriter) JsonWriter(com.google.gson.stream.JsonWriter) Test(org.junit.Test)

Example 7 with JsonWriter

use of com.google.gson.stream.JsonWriter in project buck by facebook.

the class WorkerProcessProtocolZeroTest method testSendCommandResponseWithWrongType.

@Test
public void testSendCommandResponseWithWrongType() throws IOException {
    StringWriter jsonSentToWorkerProcess = new StringWriter();
    WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, new JsonWriter(jsonSentToWorkerProcess), dummyJsonReader, newTempFile());
    try {
        protocol.sendCommandResponse(123, "WRONG_TYPE", 1);
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), Matchers.containsString("Expected response's \"type\" to be one of"));
    }
}
Also used : StringWriter(java.io.StringWriter) HumanReadableException(com.facebook.buck.util.HumanReadableException) JsonWriter(com.google.gson.stream.JsonWriter) Test(org.junit.Test)

Example 8 with JsonWriter

use of com.google.gson.stream.JsonWriter in project SeriesGuide by UweTrottmann.

the class JsonExportTask method writeJsonStreamMovies.

private void writeJsonStreamMovies(OutputStream out, Cursor movies) throws IOException {
    int numTotal = movies.getCount();
    int numExported = 0;
    Gson gson = new Gson();
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.beginArray();
    while (movies.moveToNext()) {
        if (isCancelled()) {
            break;
        }
        Movie movie = new Movie();
        movie.tmdbId = movies.getInt(MoviesQuery.TMDB_ID);
        movie.imdbId = movies.getString(MoviesQuery.IMDB_ID);
        movie.title = movies.getString(MoviesQuery.TITLE);
        movie.releasedUtcMs = movies.getLong(MoviesQuery.RELEASED_UTC_MS);
        movie.runtimeMin = movies.getInt(MoviesQuery.RUNTIME_MIN);
        movie.poster = movies.getString(MoviesQuery.POSTER);
        movie.inCollection = movies.getInt(MoviesQuery.IN_COLLECTION) == 1;
        movie.inWatchlist = movies.getInt(MoviesQuery.IN_WATCHLIST) == 1;
        movie.watched = movies.getInt(MoviesQuery.WATCHED) == 1;
        if (isFullDump) {
            movie.overview = movies.getString(MoviesQuery.OVERVIEW);
        }
        gson.toJson(movie, Movie.class, writer);
        publishProgress(numTotal, ++numExported);
    }
    writer.endArray();
    writer.close();
}
Also used : Movie(com.battlelancer.seriesguide.dataliberation.model.Movie) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(com.google.gson.stream.JsonWriter) SuppressLint(android.annotation.SuppressLint)

Example 9 with JsonWriter

use of com.google.gson.stream.JsonWriter in project SeriesGuide by UweTrottmann.

the class JsonExportTask method writeJsonStreamShows.

private void writeJsonStreamShows(OutputStream out, Cursor shows) throws IOException {
    int numTotal = shows.getCount();
    int numExported = 0;
    Gson gson = new Gson();
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.beginArray();
    while (shows.moveToNext()) {
        if (isCancelled()) {
            break;
        }
        Show show = new Show();
        show.tvdb_id = shows.getInt(ShowsQuery.ID);
        show.title = shows.getString(ShowsQuery.TITLE);
        show.favorite = shows.getInt(ShowsQuery.FAVORITE) == 1;
        show.hidden = shows.getInt(ShowsQuery.HIDDEN) == 1;
        show.language = shows.getString(ShowsQuery.LANGUAGE);
        show.release_time = shows.getInt(ShowsQuery.RELEASE_TIME);
        show.release_weekday = shows.getInt(ShowsQuery.RELEASE_WEEKDAY);
        show.release_timezone = shows.getString(ShowsQuery.RELEASE_TIMEZONE);
        show.country = shows.getString(ShowsQuery.RELEASE_COUNTRY);
        show.last_watched_episode = shows.getInt(ShowsQuery.LASTWATCHEDID);
        show.last_watched_ms = shows.getLong(ShowsQuery.LASTWATCHED_MS);
        show.poster = shows.getString(ShowsQuery.POSTER);
        show.content_rating = shows.getString(ShowsQuery.CONTENTRATING);
        show.status = DataLiberationTools.decodeShowStatus(shows.getInt(ShowsQuery.STATUS));
        show.runtime = shows.getInt(ShowsQuery.RUNTIME);
        show.network = shows.getString(ShowsQuery.NETWORK);
        show.imdb_id = shows.getString(ShowsQuery.IMDBID);
        show.trakt_id = shows.getInt(ShowsQuery.TRAKT_ID);
        show.first_aired = shows.getString(ShowsQuery.FIRSTAIRED);
        show.rating_user = shows.getInt(ShowsQuery.RATING_USER);
        if (isFullDump) {
            show.overview = shows.getString(ShowsQuery.OVERVIEW);
            show.rating = shows.getDouble(ShowsQuery.RATING_GLOBAL);
            show.rating_votes = shows.getInt(ShowsQuery.RATING_VOTES);
            show.genres = shows.getString(ShowsQuery.GENRES);
            show.last_updated = shows.getLong(ShowsQuery.LAST_UPDATED);
            show.last_edited = shows.getLong(ShowsQuery.LAST_EDITED);
        }
        addSeasons(show);
        gson.toJson(show, Show.class, writer);
        publishProgress(numTotal, ++numExported);
    }
    writer.endArray();
    writer.close();
}
Also used : Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) Show(com.battlelancer.seriesguide.dataliberation.model.Show) JsonWriter(com.google.gson.stream.JsonWriter) SuppressLint(android.annotation.SuppressLint)

Example 10 with JsonWriter

use of com.google.gson.stream.JsonWriter in project SeriesGuide by UweTrottmann.

the class JsonExportTask method writeJsonStreamLists.

private void writeJsonStreamLists(OutputStream out, Cursor lists) throws IOException {
    int numTotal = lists.getCount();
    int numExported = 0;
    Gson gson = new Gson();
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.beginArray();
    while (lists.moveToNext()) {
        if (isCancelled()) {
            break;
        }
        List list = new List();
        list.listId = lists.getString(ListsQuery.ID);
        list.name = lists.getString(ListsQuery.NAME);
        list.order = lists.getInt(ListsQuery.ORDER);
        addListItems(list);
        gson.toJson(list, List.class, writer);
        publishProgress(numTotal, ++numExported);
    }
    writer.endArray();
    writer.close();
}
Also used : Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) ArrayList(java.util.ArrayList) List(com.battlelancer.seriesguide.dataliberation.model.List) JsonWriter(com.google.gson.stream.JsonWriter) SuppressLint(android.annotation.SuppressLint)

Aggregations

JsonWriter (com.google.gson.stream.JsonWriter)38 StringWriter (java.io.StringWriter)16 OutputStreamWriter (java.io.OutputStreamWriter)11 Gson (com.google.gson.Gson)9 IOException (java.io.IOException)9 Test (org.junit.Test)9 JsonReader (com.google.gson.stream.JsonReader)8 Writer (java.io.Writer)7 StringReader (java.io.StringReader)5 SuppressLint (android.annotation.SuppressLint)3 JsonObject (com.google.gson.JsonObject)3 JsonDataSources (com.google.samples.apps.iosched.server.schedule.model.JsonDataSources)3 Map (java.util.Map)3 JsonElement (com.google.gson.JsonElement)2 TypeAdapter (com.google.gson.TypeAdapter)2 DataExtractor (com.google.samples.apps.iosched.server.schedule.model.DataExtractor)2 CloudFileManager (com.google.samples.apps.iosched.server.schedule.server.cloudstorage.CloudFileManager)2 ExtraInput (com.google.samples.apps.iosched.server.schedule.server.input.ExtraInput)2 VendorDynamicInput (com.google.samples.apps.iosched.server.schedule.server.input.VendorDynamicInput)2 BufferedWriter (java.io.BufferedWriter)2