Search in sources :

Example 1 with RuntimeExecutionException

use of com.google.android.gms.tasks.RuntimeExecutionException in project android-diplicity by zond.

the class MessagingService method decodeDataPayload.

public static DiplicityJSON decodeDataPayload(String diplicityJSON) {
    if (diplicityJSON == null) {
        return null;
    }
    try {
        byte[] compressedJSON = Base64.decode(diplicityJSON, Base64.DEFAULT);
        Inflater decompresser = new Inflater();
        decompresser.setInput(compressedJSON, 0, compressedJSON.length);
        byte[] result = new byte[8192];
        int resultLength = decompresser.inflate(result);
        decompresser.end();
        byte[] actualResult = Arrays.copyOfRange(result, 0, resultLength);
        Gson gson = new GsonBuilder().registerTypeAdapter(Ticker.class, new TickerUnserializer()).create();
        return gson.fromJson(new String(actualResult, "UTF-8"), DiplicityJSON.class);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeExecutionException(e);
    } catch (DataFormatException e) {
        throw new RuntimeException(e);
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) GsonBuilder(com.google.gson.GsonBuilder) Ticker(se.oort.diplicity.apigen.Ticker) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Inflater(java.util.zip.Inflater) TickerUnserializer(se.oort.diplicity.apigen.TickerUnserializer) RuntimeExecutionException(com.google.android.gms.tasks.RuntimeExecutionException)

Aggregations

RuntimeExecutionException (com.google.android.gms.tasks.RuntimeExecutionException)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 DataFormatException (java.util.zip.DataFormatException)1 Inflater (java.util.zip.Inflater)1 Ticker (se.oort.diplicity.apigen.Ticker)1 TickerUnserializer (se.oort.diplicity.apigen.TickerUnserializer)1