javax.json.JsonException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中javax.json.JsonException.<init>()方法的一些代码示例,展示了JsonException.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonException.<init>()方法的具体详情如下:
包路径:javax.json.JsonException
类名称:JsonException
方法名:<init>

JsonException.<init>介绍

[英]Constructs a new runtime exception with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to #initCause.
[中]使用指定的详细信息构造新的运行时异常。原因未初始化,随后可通过调用#initCause进行初始化。

代码示例

代码示例来源:origin: wildfly/wildfly

void flushBuffer() {
  try {
    if (len > 0) {
      writer.write(buf, 0, len);
      len = 0;
    }
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.GENERATOR_WRITE_IO_ERR(), ioe);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonStructure remove() {
  throw new JsonException(JsonMessages.NODEREF_VALUE_CANNOT_REMOVE());
}

代码示例来源:origin: wildfly/wildfly

private void missingMember(String op, String  member) {
  throw new JsonException(JsonMessages.PATCH_MEMBER_MISSING(op, member));
}

代码示例来源:origin: wildfly/wildfly

@Override
public void flush() {
  flushBuffer();
  try {
    writer.flush();
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.GENERATOR_FLUSH_IO_ERR(), ioe);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public void close() {
  try {
    tokenizer.close();
  } catch (IOException e) {
    throw new JsonException(JsonMessages.PARSER_TOKENIZER_CLOSE_IO(), e);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonStructure add(JsonValue value) {
  switch (value.getValueType() ) {
    case OBJECT:
    case ARRAY:
      this.root = (JsonStructure) value;
      break;
    default:
      throw new JsonException(JsonMessages.NODEREF_VALUE_ADD_ERR());
  }
  return root;
}

代码示例来源:origin: wildfly/wildfly

/**
   * Returns the enum constant with the specified name.
   *
   * @param operationName {@code operationName} to convert to the enum constant.
   * @return the enum constant for given {@code operationName}
   * @throws JsonException if given {@code operationName} is not recognized
   */
  public static Operation fromOperationName(String operationName) {
    for (Operation op : values()) {
      if (op.operationName().equalsIgnoreCase(operationName)) {
        return op;
      }
    }
    throw new JsonException("Illegal value for the operationName of the JSON patch operation: " + operationName);
  }
}

代码示例来源:origin: wildfly/wildfly

private int peek() {
  try {
    if (readBegin == readEnd) {     // need to fill the buffer
      int len = fillBuf();
      if (len == -1) {
        return -1;
      }
      assert len != 0;
      readBegin = storeEnd;
      readEnd = readBegin+len;
    }
    return buf[readBegin];
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe);
  }
}

代码示例来源:origin: wildfly/wildfly

private int read() {
  try {
    if (readBegin == readEnd) {     // need to fill the buffer
      int len = fillBuf();
      if (len == -1) {
        return -1;
      }
      assert len != 0;
      readBegin = storeEnd;
      readEnd = readBegin+len;
    }
    return buf[readBegin++];
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe);
  }
}

代码示例来源:origin: wildfly/wildfly

static Scope createScope(JsonValue value) {
    if (value instanceof JsonArray) {
      return new ArrayScope((JsonArray)value);
    } else if (value instanceof JsonObject) {
      return new ObjectScope((JsonObject)value);
    }
    throw new JsonException(JsonMessages.PARSER_SCOPE_ERR(value));
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
  public JsonObject replace(JsonValue value) {
    if (!contains()) {
      throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key));
    }
    return add(value);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonObject remove() {
  if (!contains()) {
    throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key));
  }
  return Json.createObjectBuilder(object).remove(key).build();
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonValue get() {
  if (!contains()) {
    throw new JsonException(JsonMessages.NODEREF_OBJECT_MISSING(key));
  }
  return object.get(key);
}

代码示例来源:origin: wildfly/wildfly

@Override
public void close() {
  if (currentContext.scope != Scope.IN_NONE || currentContext.first) {
    throw new JsonGenerationException(JsonMessages.GENERATOR_INCOMPLETE_JSON());
  }
  flushBuffer();
  try {
    writer.close();
  } catch (IOException ioe) {
    throw new JsonException(JsonMessages.GENERATOR_CLOSE_IO_ERR(), ioe);
  }
  bufferPool.recycle(buf);
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonValue get() {
  if (!contains()) {
    throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size()));
  }
  return array.get(index);
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonArray readArray() {
  if (readDone) {
    throw new IllegalStateException(JsonMessages.READER_READ_ALREADY_CALLED());
  }
  readDone = true;
  if (parser.hasNext()) {
    try {
      parser.next();
      return parser.getArray();
    } catch (IllegalStateException ise) {
      throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation());
    }
  }
  throw new JsonException(JsonMessages.INTERNAL_ERROR());
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonValue readValue() {
  if (readDone) {
    throw new IllegalStateException(JsonMessages.READER_READ_ALREADY_CALLED());
  }
  readDone = true;
  if (parser.hasNext()) {
    try {
      parser.next();
      return parser.getValue();
    } catch (IllegalStateException ise) {
      throw new JsonParsingException(ise.getMessage(), ise, parser.getLastCharLocation());
    }
  }
  throw new JsonException(JsonMessages.INTERNAL_ERROR());
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonArray remove() {
  if (!contains()) {
    throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size()));
  }
  JsonArrayBuilder builder = Json.createArrayBuilder(this.array);
  return builder.remove(index).build();
}

代码示例来源:origin: wildfly/wildfly

@Override
  public JsonArray replace(JsonValue value) {
    if (!contains()) {
      throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size()));
    }
    JsonArrayBuilder builder = Json.createArrayBuilder(this.array);
    return builder.set(index, value).build();
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public JsonArray add(JsonValue value) {
  //TODO should we check for arrayoutofbounds?
  // The spec seems to say index = array.size() is allowed. This is handled as append
  JsonArrayBuilder builder = Json.createArrayBuilder(this.array);
  if (index == -1 || index == array.size()) {
    builder.add(value);
  } else {
    if(index < array.size()) {
      builder.add(index, value);
    } else {
      throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size()));
    }
  }
  return builder.build();
}

相关文章

微信公众号

最新文章

更多