本文整理汇总了Java中org.codehaus.jackson.JsonParser.close方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.close方法的具体用法?Java JsonParser.close怎么用?Java JsonParser.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.JsonParser
的用法示例。
在下文中一共展示了JsonParser.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private void read(DataInput in) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(
DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
// define a module
SimpleModule module = new SimpleModule("State Serializer",
new Version(0, 1, 1, "FINAL"));
// add the state deserializer
module.addDeserializer(StatePair.class, new StateDeserializer());
// register the module with the object-mapper
mapper.registerModule(module);
JsonParser parser =
mapper.getJsonFactory().createJsonParser((DataInputStream)in);
StatePool statePool = mapper.readValue(parser, StatePool.class);
this.setStates(statePool.getStates());
parser.close();
}
示例2: _convert
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
protected Object _convert(Object paramObject, JavaType paramJavaType)
throws IllegalArgumentException
{
if (paramObject == null)
return null;
TokenBuffer localTokenBuffer = new TokenBuffer(this);
try
{
writeValue(localTokenBuffer, paramObject);
JsonParser localJsonParser = localTokenBuffer.asParser();
Object localObject = readValue(localJsonParser, paramJavaType);
localJsonParser.close();
return localObject;
}
catch (IOException localIOException)
{
}
throw new IllegalArgumentException(localIOException.getMessage(), localIOException);
}
示例3: valueToTree
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
public <T extends JsonNode> T valueToTree(Object paramObject)
throws IllegalArgumentException
{
if (paramObject == null)
return null;
TokenBuffer localTokenBuffer = new TokenBuffer(this);
try
{
writeValue(localTokenBuffer, paramObject);
JsonParser localJsonParser = localTokenBuffer.asParser();
JsonNode localJsonNode = readTree(localJsonParser);
localJsonParser.close();
return localJsonNode;
}
catch (IOException localIOException)
{
}
throw new IllegalArgumentException(localIOException.getMessage(), localIOException);
}
示例4: jsonToHostDefinition
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
protected void jsonToHostDefinition(String json, HostDefinition host) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
else if (n.equals("attachment")) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String field = jp.getCurrentName();
if (field.equals("id")) {
host.attachment = jp.getText();
} else if (field.equals("mac")) {
host.mac = jp.getText();
}
}
}
}
jp.close();
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:39,代码来源:HostResource.java
示例5: exec
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
@Override
public Tuple exec(Tuple input) throws IOException {
if (input == null || input.size() == 0) {
return null;
}
try {
String jsonStr = (String) input.get(0);
JsonParser p = jsonFactory.createJsonParser(jsonStr);
Tuple t = tupleFactory.newTuple(resourceSchemaFields.length);
// Create a map of field names to ResourceFieldSchema's,
// and create a map of field names to positions in the tuple.
// These are used during parsing to handle extra, missing, and/or out-of-order
// fields properly.
Map<String, ResourceFieldSchema> schemaMap = new HashMap<String, ResourceFieldSchema>();
Map<String, Integer> schemaPositionMap = new HashMap<String, Integer>();
for (int i = 0; i < resourceSchemaFields.length; i++) {
schemaMap.put(resourceSchemaFields[i].getName(), resourceSchemaFields[i]);
schemaPositionMap.put(resourceSchemaFields[i].getName(), i);
}
try {
p.nextToken(); // move to start of object
JsonLoader.parseObjectIntoTuple(jsonStr, p, schemaMap, schemaPositionMap, t);
} catch (JsonParseException jpe) {
// If the line doesn't parse as a valid JSON object, log an error and move on
log.error("Error parsing input: " + jsonStr + ": " + jpe.toString());
}
p.close();
return t;
} catch (ExecException e) {
warn("Error reading input: " + e.getMessage(), PigWarning.UDF_WARNING_1);
return null;
}
}
示例6: exec
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
@Override
public Map exec(Tuple input) throws IOException {
if (input == null || input.size() == 0) {
return null;
}
try {
String jsonStr = (String) input.get(0);
String schemaStr = "object: map[]";
ResourceSchema schema = new ResourceSchema(Utils.getSchemaFromString(schemaStr));
ResourceFieldSchema[] fields = schema.getFields();
JsonParser p = jsonFactory.createJsonParser(jsonStr);
Tuple t = tupleFactory.newTuple(1);
try {
p.nextToken(); // move to start of object
t.set(0, JsonLoader.readField(jsonStr, p, fields[0]));
} catch (JsonParseException jpe) {
log.error("Error parsing input: " + jsonStr + ": " + jpe.toString());
}
p.close();
return (Map) t.get(0);
} catch (ExecException e) {
warn("Error reading input: " + e.getMessage(), PigWarning.UDF_WARNING_1);
return null;
}
}
示例7: test2
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
@Test
public void test2() throws JsonParseException, IOException {
JsonFactory f = new JsonFactory();
JsonParser jp = f.createJsonParser(new File("src/main/resources/user6.json"));
User user = new User();
jp.nextToken(); // will return JsonToken.START_OBJECT (verify?)
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldname = jp.getCurrentName();
jp.nextToken(); // move to value, or START_OBJECT/START_ARRAY
if ("name".equals(fieldname)) { // contains an object
Name name = new Name();
while (jp.nextToken() != JsonToken.END_OBJECT) {
String namefield = jp.getCurrentName();
jp.nextToken(); // move to value
if ("first".equals(namefield)) {
name.setFirst(jp.getText());
} else if ("last".equals(namefield)) {
name.setLast(jp.getText());
} else {
throw new IllegalStateException("Unrecognized field '"
+ fieldname + "'!");
}
}
user.setName(name);
} else if ("gender".equals(fieldname)) {
user.setGender(User.Gender.valueOf(jp.getText()));
} else if ("verified".equals(fieldname)) {
user.setVerified(jp.getCurrentToken() == JsonToken.VALUE_TRUE);
} else if ("userImage".equals(fieldname)) {
user.setUserImage(jp.getBinaryValue());
} else {
throw new IllegalStateException("Unrecognized field '"
+ fieldname + "'!");
}
}
System.out.println(user);
jp.close(); // ensure resources get cleaned up timely and properly
}
示例8: deserialize
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
public final MediaContent deserialize(byte[] array) throws Exception
{
JsonParser parser = constructParser(array);
MediaContent mc = readMediaContent(parser);
parser.close();
return mc;
}
示例9: processJSON
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
/**
* Parse JSON-encoded event body and write the row to NoSQL.
*
* @param tableName the name of the table
* @param jsonBody the operation we are processing encoded as JSON
*/
public void processJSON(String tableName, byte[] jsonBody) {
Table table;
Row row;
String columnName;
JsonParser parser;
table = getTable(tableName);
row = table.createRow();
try {
parser = factory.createJsonParser(jsonBody);
while (parser.nextToken() != JsonToken.END_OBJECT) {
// This approach does not support arrays and other
// complex types. Shouldn't be an issue in this case.
if (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
parser.nextToken();
columnName = parser.getCurrentName();
switch (parser.getCurrentToken()) {
case VALUE_TRUE:
row.put(columnName, true);
break;
case VALUE_FALSE:
row.put(columnName, false);
break;
case VALUE_NULL:
// not sure how to handle null ...
//row.put(columnName, null);
break;
case VALUE_NUMBER_FLOAT:
// TODO: perhaps need to worry about
// double, float, Decimal???
row.put(columnName, parser.getFloatValue());
break;
case VALUE_NUMBER_INT:
// TODO: perhaps need to worry about
// int, long, etc.?
row.put(columnName, parser.getIntValue());
break;
case VALUE_STRING:
row.put(columnName, parser.getText());
break;
default:
// not a token we care about right now
LOG.error("Unhandled Json value type encountered during parsing");
throw new RuntimeException("Unrecognized JSON value type");
}
}
}
parser.close();
} catch (IOException e) {
LOG.error("process() exception:", e.getMessage());
throw new RuntimeException("Json parsing error");
}
tableHandle.put(row, null, null);
}
示例10: jsonToNetworkDefinition
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
protected void jsonToNetworkDefinition(String json, NetworkDefinition network) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
else if (n.equals("network")) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String field = jp.getCurrentName();
if (field.equals("name")) {
network.name = jp.getText();
} else if (field.equals("gateway")) {
String gw = jp.getText();
if ((gw != null) && (!gw.equals("null")))
network.gateway = gw;
} else if (field.equals("id")) {
network.guid = jp.getText();
} else {
log.warn("Unrecognized field {} in " +
"parsing network definition",
jp.getText());
}
}
}
}
jp.close();
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:47,代码来源:NetworkResource.java
示例11: processFile
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private void processFile(InputStream in, Extractor tokens) throws IOException {
JsonFactory jfactory = new JsonFactory();
JsonParser jParser = jfactory.createJsonParser(in);
String hash = "";
if (jParser.nextToken() != JsonToken.START_ARRAY) {
emitError("Expected a JSON array Unexpected token " + jParser.getText());
}
while (jParser.nextToken() != JsonToken.END_ARRAY) {
if (jParser.getCurrentToken() == JsonToken.START_OBJECT) {
jParser.nextToken();
if (jParser.getCurrentName().equals("inputhash")) {
jParser.nextToken();
hash = jParser.getText();
jParser.nextToken();
} else {
emitError("Missing inputhash " + jParser.getText());
}
} else {
emitError("Unexpected token " + jParser.getText());
}
switch (jParser.getCurrentName()) {
case "tokens":
case "texvcinfo":
if (jParser.nextToken() == JsonToken.START_ARRAY) {
while (jParser.nextToken() != JsonToken.END_ARRAY) {
tokens.addFromJson(jParser);
}
} else if ((jParser.nextToken() == JsonToken.START_OBJECT)) {
if (jParser.nextToken() != JsonToken.END_OBJECT) {
//noinspection StatementWithEmptyBody
do {
} while (jParser.nextToken() != JsonToken.END_OBJECT);
}
} else {
emitError("[ after texvcinfo expected in " + hash + " but got " + jParser.getText());
}
break;
default:
emitError("Unexpected token" + jParser.getText());
}
if (jParser.nextToken() != JsonToken.END_OBJECT) {
emitError("Missing object end");
}
}
jParser.close();
}
示例12: parsePostedResp
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
public List<AttestationValue> parsePostedResp(String str)
throws JsonParseException, IOException {
JsonFactory jfactory = new JsonFactory();
List<AttestationValue> values = new ArrayList<AttestationValue>();
JsonParser jParser = jfactory.createJsonParser(str);
try {
jParser.nextToken();
while (jParser.nextToken() != JsonToken.END_OBJECT) {
if (jParser.getCurrentName().equalsIgnoreCase(HEADER_HOSTS)) {
while (jParser.nextToken() != JsonToken.END_ARRAY
&& jParser.getCurrentToken() != JsonToken.END_OBJECT) {
AttestationValue value = new AttestationValue();
if (jParser.getCurrentName().equalsIgnoreCase(
HEADER_HOST_NAME)) {
jParser.nextToken();
value.setHostName(jParser.getText());
jParser.nextToken();
}
if (jParser.getCurrentName().equalsIgnoreCase(
HEADER_RESULT)) {
jParser.nextToken();
value.setTrustLevel(AttestationResultEnum
.valueOf(jParser.getText().toUpperCase()));
jParser.nextToken();
}
if (jParser.getCurrentName().equalsIgnoreCase(
HEADER_VTIME)) {
jParser.nextToken();
jParser.nextToken();
}
if (value.getHostName() != null) {
log.debug("host_name:" + value.getHostName()
+ ", trustLevel:" + value.getTrustLevel());
values.add(value);
}
jParser.nextToken();
}
break;
}
}
} finally {
jParser.close();
}
return values;
}
示例13: getNext
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
public Tuple getNext() throws IOException {
Text val = null;
try {
// Read the next key value pair from the record reader. If it's
// finished, return null
if (!reader.nextKeyValue()) return null;
// Get the current value. We don't use the key.
val = (Text)reader.getCurrentValue();
} catch (InterruptedException ie) {
throw new IOException(ie);
}
// Create a parser specific for this input line. This may not be the
// most efficient approach.
byte[] newBytes = new byte[val.getLength()];
System.arraycopy(val.getBytes(), 0, newBytes, 0, val.getLength());
ByteArrayInputStream bais = new ByteArrayInputStream(newBytes);
JsonParser p = jsonFactory.createJsonParser(bais);
// Create the tuple we will be returning. We create it with the right
// number of fields, as the Tuple object is optimized for this case.
ResourceFieldSchema[] fields = schema.getFields();
Tuple t = tupleFactory.newTuple(fields.length);
// Read the start object marker. Throughout this file if the parsing
// isn't what we expect we return a tuple with null fields rather than
// throwing an exception. That way a few mangled lines don't fail the
// job.
if (p.nextToken() != JsonToken.START_OBJECT) {
warn("Bad record, could not find start of record " +
val.toString(), PigWarning.UDF_WARNING_1);
return t;
}
// Read each field in the record
for (int i = 0; i < fields.length; i++) {
t.set(i, readField(p, fields[i], i));
}
if (p.nextToken() != JsonToken.END_OBJECT) {
warn("Bad record, could not find end of record " +
val.toString(), PigWarning.UDF_WARNING_1);
return t;
}
p.close();
return t;
}
示例14: getNext
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
public Tuple getNext() throws IOException {
Text val = null;
try {
// Read the next key value pair from the record reader. If it's
// finished, return null
if (!reader.nextKeyValue()) return null;
// Get the current value. We don't use the key.
val = (Text)reader.getCurrentValue();
} catch (InterruptedException ie) {
throw new IOException(ie);
}
// Create a parser specific for this input line. This may not be the
// most efficient approach.
byte[] newBytes = new byte[val.getLength()];
System.arraycopy(val.getBytes(), 0, newBytes, 0, val.getLength());
ByteArrayInputStream bais = new ByteArrayInputStream(newBytes);
JsonParser p = jsonFactory.createJsonParser(bais);
// Create the tuple we will be returning. We create it with the right
// number of fields, as the Tuple object is optimized for this case.
ResourceFieldSchema[] fields = schema.getFields();
Tuple t = tupleFactory.newTuple(fields.length);
// Read the start object marker. Throughout this file if the parsing
// isn't what we expect we return a tuple with null fields rather than
// throwing an exception. That way a few mangled lines don't fail the
// job.
try {
if (p.nextToken() != JsonToken.START_OBJECT) {
warn("Bad record, could not find start of record " +
val.toString(), PigWarning.UDF_WARNING_1);
return t;
}
// Read each field in the record
for (int i = 0; i < fields.length; i++) {
t.set(i, readField(p, fields[i], i));
}
if (p.nextToken() != JsonToken.END_OBJECT) {
warn("Bad record, could not find end of record " +
val.toString(), PigWarning.UDF_WARNING_1);
return t;
}
} catch (JsonParseException jpe) {
warn("Bad record, returning null for " + val, PigWarning.UDF_WARNING_1);
} finally {
p.close();
}
return t;
}
示例15: jsonToVip
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
protected LBVip jsonToVip(String json) throws IOException {
if (json==null) return null;
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
LBVip vip = new LBVip();
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n.equals("id")) {
vip.id = jp.getText();
continue;
}
if (n.equals("tenant_id")) {
vip.tenantId = jp.getText();
continue;
}
if (n.equals("name")) {
vip.name = jp.getText();
continue;
}
if (n.equals("network_id")) {
vip.netId = jp.getText();
continue;
}
if (n.equals("protocol")) {
String tmp = jp.getText();
if (tmp.equalsIgnoreCase("TCP")) {
vip.protocol = IPv4.PROTOCOL_TCP;
} else if (tmp.equalsIgnoreCase("UDP")) {
vip.protocol = IPv4.PROTOCOL_UDP;
} else if (tmp.equalsIgnoreCase("ICMP")) {
vip.protocol = IPv4.PROTOCOL_ICMP;
}
continue;
}
if (n.equals("address")) {
vip.address = IPv4.toIPv4Address(jp.getText());
continue;
}
if (n.equals("port")) {
vip.port = Short.parseShort(jp.getText());
continue;
}
if (n.equals("pool_id")) {
vip.pools.add(jp.getText());
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Vips",
jp.getText());
}
jp.close();
return vip;
}