Here you can find the source of load(InputStream inputStream, Class
public static <T> T load(InputStream inputStream, Class<T> type) throws IOException
//package com.java2s; //License from project: Apache License import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.io.*; public class Main { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static <T> T load(InputStream inputStream, Class<T> type) throws IOException { String json = new String(readStream(inputStream)); return GSON.fromJson(json, type); }/*from w w w . j a v a 2 s . c o m*/ public static byte[] readStream(InputStream inputStream) throws IOException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); final int bufferSize = 16384; try { final BufferedInputStream bIn = new BufferedInputStream(inputStream); int length; byte[] buffer = new byte[bufferSize]; byte[] bufferCopy; while ((length = bIn.read(buffer, 0, bufferSize)) != -1) { bufferCopy = new byte[length]; System.arraycopy(buffer, 0, bufferCopy, 0, length); output.write(bufferCopy); } bIn.close(); } finally { output.close(); } return output.toByteArray(); } }