当前位置: 首页>>代码示例>>Java>>正文


Java JsonParser.close方法代码示例

本文整理汇总了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();
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:21,代码来源:StatePool.java

示例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);
}
 
开发者ID:zhangjianying,项目名称:12306-android-Decompile,代码行数:20,代码来源:ObjectMapper.java

示例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);
}
 
开发者ID:zhangjianying,项目名称:12306-android-Decompile,代码行数:20,代码来源:ObjectMapper.java

示例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;
    }
}
 
开发者ID:mortardata,项目名称:pig-json,代码行数:38,代码来源:FromJsonWithSchema.java

示例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;
    }
}
 
开发者ID:mortardata,项目名称:pig-json,代码行数:30,代码来源:FromJsonInferSchema.java

示例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
}
 
开发者ID:liuxianqiang,项目名称:jackson-in-five-minutes,代码行数:39,代码来源:StreamAPI.java

示例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;
}
 
开发者ID:ppdai,项目名称:TripSerializer4J,代码行数:8,代码来源:JsonSerializer.java

示例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);
}
 
开发者ID:oracle,项目名称:bdglue,代码行数:67,代码来源:NoSQLTableHelper.java

示例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();
}
 
开发者ID:ag-gipp,项目名称:mathosphere,代码行数:48,代码来源:TokenCounter.java

示例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;
}
 
开发者ID:chendave,项目名称:hadoop-TCP,代码行数:46,代码来源:AttestationService.java

示例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;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:49,代码来源:JsonLoader.java

示例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;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:57,代码来源:JsonLoader.java

示例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;
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:78,代码来源:VipsResource.java


注:本文中的org.codehaus.jackson.JsonParser.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。