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


Java MappingIterator.close方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.MappingIterator.close方法的典型用法代碼示例。如果您正苦於以下問題:Java MappingIterator.close方法的具體用法?Java MappingIterator.close怎麽用?Java MappingIterator.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.MappingIterator的用法示例。


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

示例1: doProcess

import com.fasterxml.jackson.databind.MappingIterator; //導入方法依賴的package包/類
@Override
protected boolean doProcess(Record inputRecord, InputStream in) throws IOException {
  MappingIterator iter = reader.readValues(in);
  try {
    while (iter.hasNextValue()) {
      Object rootNode = iter.nextValue();
      incrementNumRecords();
      LOG.debug("jsonObject: {}", rootNode);
      
      Record outputRecord = inputRecord.copy();
      removeAttachments(outputRecord);
      outputRecord.put(Fields.ATTACHMENT_BODY, rootNode);
      outputRecord.put(Fields.ATTACHMENT_MIME_TYPE, MIME_TYPE);
  
      // pass record to next command in chain:
      if (!getChild().process(outputRecord)) {
        return false;
      }
    }
    return true;
  } finally {
    iter.close();
  }
}
 
開發者ID:cloudera,項目名稱:cdk,代碼行數:25,代碼來源:ReadJsonBuilder.java

示例2: testJsonOutput

import com.fasterxml.jackson.databind.MappingIterator; //導入方法依賴的package包/類
@Test
public void testJsonOutput() throws IOException {
	String[] args = new String[] { "-a", "json", "-o",
			"/path/to/output.json" };

	DirectoryManagerFactory
			.setDirectoryManagerClass(MockDirectoryManager.class);

	ClientConfiguration config = new ClientConfiguration(args);
	JsonSerializationAction jsa = (JsonSerializationAction) config
			.getActions().get(0);

	ItemIdValue subject1 = Datamodel.makeWikidataItemIdValue("Q42");
	ItemIdValue subject2 = Datamodel.makeWikidataItemIdValue("Q43");
	MonolingualTextValue mtv1 = Datamodel.makeMonolingualTextValue("Test1",
			"en");
	MonolingualTextValue mtv2 = Datamodel.makeMonolingualTextValue("Test2",
			"fr");

	ItemDocument id1 = Datamodel.makeItemDocument(subject1,
			Arrays.asList(mtv1, mtv2), Arrays.asList(mtv1),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<StatementGroup> emptyList(),
			Collections.<String, SiteLink> emptyMap());

	ItemDocument id2 = Datamodel.makeItemDocument(subject2,
			Collections.<MonolingualTextValue> emptyList(),
			Arrays.asList(mtv2),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<StatementGroup> emptyList(),
			Collections.<String, SiteLink> emptyMap());

	PropertyDocument pd1 = Datamodel
			.makePropertyDocument(
					Datamodel.makeWikidataPropertyIdValue("P31"),
					Arrays.asList(mtv1),
					Collections.<MonolingualTextValue> emptyList(),
					Arrays.asList(mtv1),
					Datamodel
							.makeDatatypeIdValue(DatatypeIdValue.DT_MONOLINGUAL_TEXT));

	jsa.open();
	jsa.processItemDocument(id1);
	jsa.processPropertyDocument(pd1);
	jsa.processItemDocument(id2);
	jsa.close();

	MockDirectoryManager mdm = new MockDirectoryManager(
			Paths.get("/path/to/"), false);

	ObjectMapper mapper = new ObjectMapper();
	ObjectReader documentReader = mapper
			.reader(JacksonTermedStatementDocument.class);
	MappingIterator<JacksonTermedStatementDocument> documentIterator = documentReader
			.readValues(mdm.getInputStreamForFile("output.json",
					CompressionType.NONE));

	List<EntityDocument> results = new ArrayList<>();
	while (documentIterator.hasNextValue()) {
		JacksonTermedStatementDocument document = documentIterator
				.nextValue();
		document.setSiteIri(Datamodel.SITE_WIKIDATA);
		results.add(document);
	}
	documentIterator.close();

	assertEquals(3, results.size());
	assertEquals(id1, results.get(0));
	assertEquals(pd1, results.get(1));
	assertEquals(id2, results.get(2));

}
 
開發者ID:Wikidata,項目名稱:Wikidata-Toolkit,代碼行數:73,代碼來源:JsonSerializationActionTest.java

示例3: testJsonGzipOutput

import com.fasterxml.jackson.databind.MappingIterator; //導入方法依賴的package包/類
@Test
public void testJsonGzipOutput() throws IOException {
	String[] args = new String[] { "-a", "json", "-o",
			"/path/to/output.json", "-z", "gz" };

	DirectoryManagerFactory
			.setDirectoryManagerClass(MockDirectoryManager.class);

	ClientConfiguration config = new ClientConfiguration(args);
	JsonSerializationAction jsa = (JsonSerializationAction) config
			.getActions().get(0);

	ItemIdValue subject1 = Datamodel.makeWikidataItemIdValue("Q42");
	MonolingualTextValue mtv1 = Datamodel.makeMonolingualTextValue("Test1",
			"en");
	MonolingualTextValue mtv2 = Datamodel.makeMonolingualTextValue("Test2",
			"fr");

	ItemDocument id1 = Datamodel.makeItemDocument(subject1,
			Arrays.asList(mtv1, mtv2), Arrays.asList(mtv1),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<StatementGroup> emptyList(),
			Collections.<String, SiteLink> emptyMap());

	jsa.open();
	jsa.processItemDocument(id1);
	jsa.close();

	MockDirectoryManager mdm = new MockDirectoryManager(
			Paths.get("/path/to/"), false);

	ObjectMapper mapper = new ObjectMapper();
	ObjectReader documentReader = mapper
			.reader(JacksonTermedStatementDocument.class);
	MappingIterator<JacksonTermedStatementDocument> documentIterator = documentReader
			.readValues(mdm.getInputStreamForFile("output.json.gz",
					CompressionType.GZIP));

	List<EntityDocument> results = new ArrayList<>();
	while (documentIterator.hasNextValue()) {
		JacksonTermedStatementDocument document = documentIterator
				.nextValue();
		document.setSiteIri(Datamodel.SITE_WIKIDATA);
		results.add(document);
	}
	documentIterator.close();

	assertEquals(1, results.size());
	assertEquals(id1, results.get(0));
}
 
開發者ID:Wikidata,項目名稱:Wikidata-Toolkit,代碼行數:51,代碼來源:JsonSerializationActionTest.java

示例4: testJsonBz2Output

import com.fasterxml.jackson.databind.MappingIterator; //導入方法依賴的package包/類
@Test
public void testJsonBz2Output() throws IOException {
	String[] args = new String[] { "-a", "json", "-o", "output.json", "-z",
			"bz2" };

	DirectoryManagerFactory
			.setDirectoryManagerClass(MockDirectoryManager.class);

	ClientConfiguration config = new ClientConfiguration(args);
	JsonSerializationAction jsa = (JsonSerializationAction) config
			.getActions().get(0);

	ItemIdValue subject1 = Datamodel.makeWikidataItemIdValue("Q42");
	MonolingualTextValue mtv1 = Datamodel.makeMonolingualTextValue("Test1",
			"en");
	MonolingualTextValue mtv2 = Datamodel.makeMonolingualTextValue("Test2",
			"fr");

	ItemDocument id1 = Datamodel.makeItemDocument(subject1,
			Arrays.asList(mtv1, mtv2), Arrays.asList(mtv1),
			Collections.<MonolingualTextValue> emptyList(),
			Collections.<StatementGroup> emptyList(),
			Collections.<String, SiteLink> emptyMap());

	jsa.open();
	jsa.processItemDocument(id1);
	jsa.close();

	MockDirectoryManager mdm = new MockDirectoryManager(Paths.get("."),
			false);

	ObjectMapper mapper = new ObjectMapper();
	ObjectReader documentReader = mapper
			.reader(JacksonTermedStatementDocument.class);
	MappingIterator<JacksonTermedStatementDocument> documentIterator = documentReader
			.readValues(mdm.getInputStreamForFile("output.json.bz2",
					CompressionType.BZ2));

	List<EntityDocument> results = new ArrayList<>();
	while (documentIterator.hasNextValue()) {
		JacksonTermedStatementDocument document = documentIterator
				.nextValue();
		document.setSiteIri(Datamodel.SITE_WIKIDATA);
		results.add(document);
	}
	documentIterator.close();

	assertEquals(1, results.size());
	assertEquals(id1, results.get(0));
}
 
開發者ID:Wikidata,項目名稱:Wikidata-Toolkit,代碼行數:51,代碼來源:JsonSerializationActionTest.java

示例5: testSerializer

import com.fasterxml.jackson.databind.MappingIterator; //導入方法依賴的package包/類
@Test
public void testSerializer() throws IOException {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	JsonSerializer serializer = new JsonSerializer(out);

	ItemDocument id1 = Datamodel.makeItemDocument(DataObjectFactoryImplTest
			.getTestItemIdValue(1), Collections
			.singletonList(Datamodel
					.makeMonolingualTextValue("Label1", "lang1")),
			Collections.<MonolingualTextValue> emptyList(), Collections
					.<MonolingualTextValue> emptyList(),
			DataObjectFactoryImplTest.getTestStatementGroups(1, 24, 1,
					EntityIdValue.ET_ITEM), Collections
					.<String, SiteLink> emptyMap(), 1234);
	ItemDocument id2 = Datamodel.makeItemDocument(DataObjectFactoryImplTest
			.getTestItemIdValue(2), Collections
			.<MonolingualTextValue> emptyList(), Collections
			.<MonolingualTextValue> emptyList(), Collections
			.<MonolingualTextValue> emptyList(), DataObjectFactoryImplTest
			.getTestStatementGroups(2, 23, 1, EntityIdValue.ET_ITEM),
			Collections.singletonMap(
					"enwiki",
					Datamodel.makeSiteLink("Title2", "enwiki",
							Collections.<String>emptyList())), 0);
	PropertyDocument pd1 = Datamodel.makePropertyDocument(
			DataObjectFactoryImplTest.getTestPropertyIdValue(1),
			Collections.<MonolingualTextValue> emptyList(), Collections
					.<MonolingualTextValue> emptyList(), Collections
					.singletonList(Datamodel
							.makeMonolingualTextValue("Alias1", "lang1")),
			Collections.<StatementGroup> emptyList(), Datamodel
					.makeDatatypeIdValue(DatatypeIdValue.DT_COMMONS_MEDIA),
			3456);

	serializer.open();
	serializer.processItemDocument(id1);
	serializer.processItemDocument(id2);
	serializer.processPropertyDocument(pd1);
	serializer.close();

	ArrayList<EntityDocument> inputDocuments = new ArrayList<>();
	inputDocuments.add(id1);
	inputDocuments.add(id2);
	inputDocuments.add(pd1);

	ArrayList<EntityDocument> outputDocuments = new ArrayList<>();

	ObjectMapper mapper = new ObjectMapper();
	ObjectReader documentReader = mapper
			.reader(JacksonTermedStatementDocument.class);

	MappingIterator<JacksonTermedStatementDocument> documentIterator = documentReader
			.readValues(out.toString());
	while (documentIterator.hasNextValue()) {
		JacksonTermedStatementDocument document = documentIterator
				.nextValue();
		document.setSiteIri("foo:");
		outputDocuments.add(document);
	}
	documentIterator.close();

	for (int i = 0; i < outputDocuments.size(); i++) {
		assertEquals(inputDocuments.get(i), outputDocuments.get(i));
	}
	assertEquals(serializer.getEntityDocumentCount(), 3);
}
 
開發者ID:Wikidata,項目名稱:Wikidata-Toolkit,代碼行數:67,代碼來源:JsonSerializerTest.java

示例6: doProcess

import com.fasterxml.jackson.databind.MappingIterator; //導入方法依賴的package包/類
@Override
protected boolean doProcess(Record record, InputStream in) throws IOException {
  String name = (String) record.getFirstValue(Fields.ATTACHMENT_NAME);
  if (name != null && name.endsWith(".gz")) {
    in = new GZIPInputStream(in, 64 * 1024);
  }
  long numRecords = 0;
  BufferedReader bufferedReader = null;
  MappingIterator<JsonNode> iter = null;
  if (isLengthDelimited) {
    bufferedReader = new BufferedReader(new InputStreamReader(in, "UTF-8"));        
  } else {
    iter = reader.readValues(in);
  }
  
  try {
    while (true) {
      JsonNode rootNode;
      if (isLengthDelimited) {
        String json = nextLine(bufferedReader);
        if (json == null) {
          break;
        }
  
        try {
          // src can be a File, URL, InputStream, etc
          rootNode = reader.readValue(json); 
        } catch (JsonParseException e) {
          LOG.info("json parse exception after " + numRecords + " records");
          LOG.debug("json parse exception after " + numRecords + " records", e);
          break;
        }
      } else {
        if (!iter.hasNext()) {
          break;
        }
        rootNode = iter.next();
      }
    
      Record doc = new Record();
      JsonNode user = rootNode.get("user");
      JsonNode idNode = rootNode.get("id_str");
      if (idNode == null || idNode.textValue() == null) {
        continue; // skip
      }
  
      doc.put("id", idPrefix + idNode.textValue());
      tryAddDate(doc, "created_at", rootNode.get("created_at"));          
      tryAddString(doc, "source", rootNode.get("source"));
      tryAddString(doc, "text", rootNode.get("text"));
      tryAddInt(doc, "retweet_count", rootNode.get("retweet_count"));
      tryAddBool(doc, "retweeted", rootNode.get("retweeted"));
      tryAddLong(doc, "in_reply_to_user_id", rootNode.get("in_reply_to_user_id"));
      tryAddLong(doc, "in_reply_to_status_id", rootNode.get("in_reply_to_status_id"));
      tryAddString(doc, "media_url_https", rootNode.get("media_url_https"));
      tryAddString(doc, "expanded_url", rootNode.get("expanded_url"));
  
      tryAddInt(doc, "user_friends_count", user.get("friends_count"));
      tryAddString(doc, "user_location", user.get("location"));
      tryAddString(doc, "user_description", user.get("description"));
      tryAddInt(doc, "user_statuses_count", user.get("statuses_count"));
      tryAddInt(doc, "user_followers_count", user.get("followers_count"));
      tryAddString(doc, "user_screen_name", user.get("screen_name"));
      tryAddString(doc, "user_name", user.get("name"));
      
      incrementNumRecords();
      LOG.debug("tweetdoc: {}", doc);
      if (!getChild().process(doc)) {
        return false;
      }
      numRecords++;
    }
  } finally {
    if (iter != null) {
      iter.close();
    }
    LOG.debug("processed {} records", numRecords);
  }
  return true;
}
 
開發者ID:cloudera,項目名稱:cdk,代碼行數:81,代碼來源:ReadJsonTestTweetsBuilder.java


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