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));
}
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"));
}
}
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();
}
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();
}
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();
}
Aggregations