當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。