Search in sources :

Example 1 with LargeData

use of com.gpcoder.gson.object.LargeData in project Java-Tutorial by gpcodervn.

the class LargeDataTypeAdapterStreamingTest method main.

public static void main(final String[] args) throws IOException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    // Configure GSON
    final GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(LargeData.class, new LargeDataTypeAdapter());
    gsonBuilder.setPrettyPrinting();
    final Gson gson = gsonBuilder.create();
    final LargeData data = new LargeData();
    data.create(10485760);
    final File dir = new File("data");
    dir.mkdirs();
    try (OutputStream os = new FileOutputStream(new File(dir, "outputTypeAdapterStreaming.json"));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"))) {
        gson.toJson(data, out);
    }
    stopWatch.stop();
    System.out.println("Done in " + stopWatch.getTime());
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Gson(com.google.gson.Gson) LargeData(com.gpcoder.gson.object.LargeData) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) StopWatch(org.apache.commons.lang3.time.StopWatch) BufferedWriter(java.io.BufferedWriter)

Example 2 with LargeData

use of com.gpcoder.gson.object.LargeData in project Java-Tutorial by gpcodervn.

the class LargeDataSerializerStreamingTest method main.

public static void main(final String[] args) throws IOException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    // Configure GSON
    final GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(LargeData.class, new LargeDataSerializer());
    gsonBuilder.setPrettyPrinting();
    final Gson gson = gsonBuilder.create();
    final LargeData data = new LargeData();
    data.create(10485760);
    final File dir = new File("data");
    dir.mkdirs();
    try (OutputStream os = new FileOutputStream(new File(dir, "outputSerialiserStreaming.json"));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"))) {
        gson.toJson(data, out);
    }
    stopWatch.stop();
    System.out.println("Done in " + stopWatch.getTime());
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Gson(com.google.gson.Gson) LargeData(com.gpcoder.gson.object.LargeData) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) StopWatch(org.apache.commons.lang3.time.StopWatch) BufferedWriter(java.io.BufferedWriter)

Example 3 with LargeData

use of com.gpcoder.gson.object.LargeData in project Java-Tutorial by gpcodervn.

the class LargeDataSerializerTest method main.

public static void main(final String[] args) throws IOException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    // Configure GSON
    final GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(LargeData.class, new LargeDataSerializer());
    gsonBuilder.setPrettyPrinting();
    final Gson gson = gsonBuilder.create();
    final LargeData data = new LargeData();
    data.create(10485760);
    final String json = gson.toJson(data);
    final File dir = new File("data");
    dir.mkdirs();
    try (PrintStream out = new PrintStream(new File(dir, "outputSerialiser.json"), "UTF-8")) {
        out.println(json);
    }
    stopWatch.stop();
    System.out.println("Done in " + stopWatch.getTime());
}
Also used : PrintStream(java.io.PrintStream) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) LargeData(com.gpcoder.gson.object.LargeData) File(java.io.File) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 4 with LargeData

use of com.gpcoder.gson.object.LargeData in project Java-Tutorial by gpcodervn.

the class LargeDataTypeAdapterTest method main.

public static void main(final String[] args) throws IOException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    // Configure GSON
    final GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(LargeData.class, new LargeDataTypeAdapter());
    gsonBuilder.setPrettyPrinting();
    final Gson gson = gsonBuilder.create();
    final LargeData data = new LargeData();
    data.create(10485760);
    final String json = gson.toJson(data);
    final File dir = new File("data");
    dir.mkdirs();
    try (PrintStream out = new PrintStream(new File(dir, "outputTypeAdapter.json"), "UTF-8")) {
        out.println(json);
    }
    stopWatch.stop();
    System.out.println("Done in " + stopWatch.getTime());
}
Also used : PrintStream(java.io.PrintStream) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) LargeData(com.gpcoder.gson.object.LargeData) File(java.io.File) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 LargeData (com.gpcoder.gson.object.LargeData)4 File (java.io.File)4 StopWatch (org.apache.commons.lang3.time.StopWatch)4 BufferedWriter (java.io.BufferedWriter)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintStream (java.io.PrintStream)2