當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonIOException類代碼示例

本文整理匯總了Java中com.google.gson.JsonIOException的典型用法代碼示例。如果您正苦於以下問題:Java JsonIOException類的具體用法?Java JsonIOException怎麽用?Java JsonIOException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonIOException類屬於com.google.gson包,在下文中一共展示了JsonIOException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readGeneric

import com.google.gson.JsonIOException; //導入依賴的package包/類
public static int readGeneric(File f) {
    int count = 0;
    Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Location.class, new LocationAdapter()).create();
    try (FileReader reader = new FileReader(f)) {
        GenericNPC[] vils = gson.fromJson(reader, GenericNPC[].class);
        for (GenericNPC gv : vils) {
            if (gv == null)
                continue;
            NPCManager.register(gv);
            genericVillagers.add(gv);
        }
        count += vils.length;
    } catch (JsonSyntaxException | JsonIOException | IOException e) {
        System.err.println("Error reading NPC in " + f.getName() + ".");
        e.printStackTrace();
    }
    return count;
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:19,代碼來源:GenericNPCManager.java

示例2: handleResponseError

import com.google.gson.JsonIOException; //導入依賴的package包/類
@Override
public void handleResponseError(Context context, Throwable t) {
    Timber.tag("Catch-Error").w(t.getMessage());
    //這裏不光是隻能打印錯誤,還可以根據不同的錯誤作出不同的邏輯處理
    String msg = "未知錯誤";
    if (t instanceof UnknownHostException) {
        msg = "網絡不可用";
    } else if (t instanceof SocketTimeoutException) {
        msg = "請求網絡超時";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
        msg = "數據解析錯誤";
    }
    ArmsUtils.snackbarText(msg);
}
 
開發者ID:Superingxz,項目名稱:MoligyMvpArms,代碼行數:18,代碼來源:ResponseErrorListenerImpl.java

示例3: writeInternal

import com.google.gson.JsonIOException; //導入依賴的package包/類
protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
  
  
  Charset charset = this.getCharset(outputMessage.getHeaders());
  OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset);
  
  try {
    if(this.jsonPrefix != null) {
      writer.append(this.jsonPrefix);
    }
    
    this.gson.toJson(o, writer);
    
    writer.close();
  } catch (JsonIOException var7) {
    throw new HttpMessageNotWritableException("Could not write JSON: " + var7.getMessage(), var7);
  }
}
 
開發者ID:Huawei,項目名稱:Server_Management_Common_eSightApi,代碼行數:19,代碼來源:GsonHttpMessageConverter.java

示例4: createJsonArrayFromString

import com.google.gson.JsonIOException; //導入依賴的package包/類
/**
 * Creates a {@link JsonArray} from the given json string.
 * 
 * @param jsonString the json string to parse
 * @return the {@link JsonArray} received while parsing the given json string
 * @throws JsonParsingFailedException if any exception occurred at runtime
 */
public static JsonArray createJsonArrayFromString(final String jsonString) throws JsonParsingFailedException {
   InputStream stream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8));
   Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);

   JsonArray readJsonArray = null;
   try {
      readJsonArray = new Gson().fromJson(reader, JsonArray.class);
   } catch (JsonSyntaxException jsonSyntaxException) {
      throw new JsonParsingFailedException(jsonSyntaxException);
   } catch (JsonIOException jsonIoException) {
      throw new JsonParsingFailedException(jsonIoException);
   }

   return readJsonArray;
}
 
開發者ID:Intelligent-Systems-Group,項目名稱:jpl-framework,代碼行數:23,代碼來源:JsonUtils.java

示例5: createJsonObjectFromString

import com.google.gson.JsonIOException; //導入依賴的package包/類
/**
 * Creates a {@link JsonObject} from the given json string.
 * 
 * @param jsonString the json string to parse
 * @return the {@link JsonObject} received while parsing the given json string
 * @throws JsonParsingFailedException if any exception occurred at runtime
 */
public static JsonObject createJsonObjectFromString(final String jsonString) throws JsonParsingFailedException {
   InputStream stream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8));
   Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);

   JsonObject readJsonObject = null;
   try {
      readJsonObject = new Gson().fromJson(reader, JsonObject.class);
   } catch (JsonSyntaxException jsonSyntaxException) {
      throw new JsonParsingFailedException(jsonSyntaxException);
   } catch (JsonIOException jsonIoException) {
      throw new JsonParsingFailedException(jsonIoException);
   }

   return readJsonObject;
}
 
開發者ID:Intelligent-Systems-Group,項目名稱:jpl-framework,代碼行數:23,代碼來源:JsonUtils.java

示例6: createJsonObjectFromFilePath

import com.google.gson.JsonIOException; //導入依賴的package包/類
/**
 * Creates a {@link JsonObject} from the json file which can be found at the given path.
 * 
 * Note that this method should only be used with a jsonFilePath starting at folders inside the
 * resource directory, e.g. algorithm/baselearner/... . Otherwise it will result in a
 * {@link NullPointerException}. For accessing {@link JsonObject}s with a more detailed path, use
 * {@link #createJsonObjectFromFile(File)}.
 * 
 * @param jsonFilePath the path of the json file
 * @return the {@link JsonObject} received while parsing the json file
 * @throws JsonParsingFailedException if any exception occurred at runtime
 * @throws NullPointerException if the given file path does not start with a folder or file
 *            inside the resource directory
 */
public static JsonObject createJsonObjectFromFilePath(final String jsonFilePath) throws JsonParsingFailedException {
   JsonObject readJsonObject = null;
   InputStream inputStream = JsonUtils.class.getResourceAsStream(jsonFilePath);
   InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
   try (Reader reader = new BufferedReader(inputStreamReader)) {
      readJsonObject = new Gson().fromJson(reader, JsonObject.class);
   } catch (JsonSyntaxException jsonSyntaxException) {
      throw new JsonParsingFailedException(jsonSyntaxException);
   } catch (JsonIOException jsonIoException) {
      throw new JsonParsingFailedException(jsonIoException);
   } catch (FileNotFoundException fileNotFoundException) {
      throw new JsonParsingFailedException(fileNotFoundException);
   } catch (IOException ioException) {
      throw new JsonParsingFailedException(ioException);
   }
   return readJsonObject;
}
 
開發者ID:Intelligent-Systems-Group,項目名稱:jpl-framework,代碼行數:32,代碼來源:JsonUtils.java

示例7: createJsonObjectFromFile

import com.google.gson.JsonIOException; //導入依賴的package包/類
/**
 * Creates a {@link JsonObject} from the given json file.
 * 
 * @param jsonFile the json filet to read
 * @return the {@link JsonObject} received while parsing the json file
 * @throws JsonParsingFailedException if any exception occurred at runtime
 */
public static JsonObject createJsonObjectFromFile(final File jsonFile) throws JsonParsingFailedException {
   JsonObject readJsonObject = null;
   try (Reader reader = new FileReader(jsonFile)) {
      readJsonObject = new Gson().fromJson(reader, JsonObject.class);
   } catch (JsonSyntaxException jsonSyntaxException) {
      throw new JsonParsingFailedException(jsonSyntaxException);
   } catch (JsonIOException jsonIoException) {
      throw new JsonParsingFailedException(jsonIoException);
   } catch (FileNotFoundException fileNotFoundException) {
      throw new JsonParsingFailedException(fileNotFoundException);
   } catch (IOException ioException) {
      throw new JsonParsingFailedException(ioException);
   }
   return readJsonObject;
}
 
開發者ID:Intelligent-Systems-Group,項目名稱:jpl-framework,代碼行數:23,代碼來源:JsonUtils.java

示例8: parse

import com.google.gson.JsonIOException; //導入依賴的package包/類
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonIOException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:20,代碼來源:Streams.java

示例9: decode

import com.google.gson.JsonIOException; //導入依賴的package包/類
@Override
public Object decode(Response response, Type type) throws IOException {
  if (response.status() == 404) return Util.emptyValueOf(type);
  if (response.body() == null) return null;
  Reader reader = response.body().asReader();
  try {
    return gson.fromJson(reader, type);
  } catch (JsonIOException e) {
    if (e.getCause() != null && e.getCause() instanceof IOException) {
      throw IOException.class.cast(e.getCause());
    }
    throw e;
  } finally {
    ensureClosed(reader);
  }
}
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:17,代碼來源:GsonDecoder.java

示例10: decode

import com.google.gson.JsonIOException; //導入依賴的package包/類
@Override
public Object decode(Response response, Type type) throws IOException {
  if (void.class == type || response.body() == null) {
    return null;
  }
  Reader reader = response.body().asReader();
  try {
    return gson.fromJson(reader, type);
  } catch (JsonIOException e) {
    if (e.getCause() != null && e.getCause() instanceof IOException) {
      throw IOException.class.cast(e.getCause());
    }
    throw e;
  } finally {
    ensureClosed(reader);
  }
}
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:18,代碼來源:GitHubExample.java

示例11: writeInternal

import com.google.gson.JsonIOException; //導入依賴的package包/類
@Override
protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessage)
    throws IOException, HttpMessageNotWritableException {
    Charset charset = getCharset(outputMessage.getHeaders());

    try (OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset)) {
        if (ignoreType) {
            gsonForWriter.toJson(o, writer);
            return;
        }

        if (type != null) {
            gsonForWriter.toJson(o, type, writer);
            return;
        }

        gsonForWriter.toJson(o, writer);
    } catch (JsonIOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:22,代碼來源:RawGsonMessageConverter.java

示例12: parse

import com.google.gson.JsonIOException; //導入依賴的package包/類
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonSyntaxException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:Streams.java

示例13: fetchUserAccounts

import com.google.gson.JsonIOException; //導入依賴的package包/類
private void fetchUserAccounts() {
    NetworkManager.Get(requestUrl, new HttpResponse() {
        @Override
        public void success(String response) {
            try {
                Type listType = new TypeToken<ArrayList<NRAccount>>() {
                }.getType();
                List<NRAccount> accounts = new Gson().fromJson(response, listType);
                initRecyclerView(accounts);
            }
            catch(JsonSyntaxException | JsonIOException jioe) {
                Log.i("gson", "parse failed");
            }
        }

        @Override
        public void error() {

        }
    });
}
 
開發者ID:nanorepsdk,項目名稱:ConversationDemoAndroid,代碼行數:22,代碼來源:AccountsListFragment.java

示例14: handleResponseError

import com.google.gson.JsonIOException; //導入依賴的package包/類
@Override
public void handleResponseError(Context context, Throwable t) {
    //Used to provide a monitor for handling all errors
    //rxjava need to use ErrorHandleSubscriber (the default implementation of Subscriber's onError method), this monitor to take effect
    Timber.tag("Catch-Error").w(t.getMessage());
    //Here is not only print errors, but also according to different errors to make different logical processing
    String msg = "Unknown";
    if (t instanceof UnknownHostException) {
        msg = "The network is not available";
    } else if (t instanceof SocketTimeoutException) {
        msg = "Network timeout";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
        msg = "Data parsing error";
    }
    UiUtils.snackbarText(msg);
}
 
開發者ID:goutham106,項目名稱:GmArchMvvm,代碼行數:20,代碼來源:ResponseErrorListenerImpl.java

示例15: LoadRecipes

import com.google.gson.JsonIOException; //導入依賴的package包/類
public List<Recipe> LoadRecipes() {
	Gson gson = new Gson();
	List<Recipe> recipes = new ArrayList<>();

	for (File file : getRecipesFolder().listFiles()) {
		if (!file.getName().endsWith(".json"))
			continue;

		try {
			JsonReader reader = new JsonReader(new FileReader(file));
			Recipe recipe = gson.fromJson(reader, Recipe.class);
			recipes.add(recipe);
		} catch (FileNotFoundException | JsonSyntaxException | JsonIOException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
	}
	return recipes;
}
 
開發者ID:NMSU-SIC-Club,項目名稱:JavaFX_Tutorial,代碼行數:20,代碼來源:RecipeLoaderService.java


注:本文中的com.google.gson.JsonIOException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。