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


Java JsonFormat.printToString方法代码示例

本文整理汇总了Java中com.googlecode.protobuf.format.JsonFormat.printToString方法的典型用法代码示例。如果您正苦于以下问题:Java JsonFormat.printToString方法的具体用法?Java JsonFormat.printToString怎么用?Java JsonFormat.printToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.googlecode.protobuf.format.JsonFormat的用法示例。


在下文中一共展示了JsonFormat.printToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
/**
 * Writes as a string using the format specified the FileTrackingStatus
 * 
 * @param format
 * @param file
 * @return
 */
public String write(FORMAT format, FileStatus.FileTrackingStatus file) {
	String ret = null;

	if (format.equals(FORMAT.JSON)) {
		try {
			ret = JsonFormat.printToString(file);
		} catch (Exception excp) {
			RuntimeException rte = new RuntimeException(excp.toString(),
					excp);
			rte.setStackTrace(excp.getStackTrace());
			throw rte;
		}
	} else {
		ret = toTXT(file);
	}

	return ret;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:26,代码来源:FileTrackingStatusFormatter.java

示例2: parseJava

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
protected static String parseJava(final String content) {
	final ASTParser parser = ASTParser.newParser(astLevel);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setSource(content.toCharArray());

	final Map options = JavaCore.getOptions();
	JavaCore.setComplianceOptions(javaVersion, options);
	parser.setCompilerOptions(options);

	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);

	final ASTRoot.Builder ast = ASTRoot.newBuilder();
	try {
		ast.addNamespaces(visitor.getNamespaces(cu));
		for (final String s : visitor.getImports())
			ast.addImports(s);
	} catch (final Exception e) {
		System.err.println(e);
		e.printStackTrace();
		return "";
	}

	return JsonFormat.printToString(ast.build());
}
 
开发者ID:boalang,项目名称:compiler,代码行数:25,代码来源:Java7BaseTest.java

示例3: testReduceResultBelowTrustLevelThreshold

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
@Test
public void testReduceResultBelowTrustLevelThreshold() throws Exception {
    // given
    Configuration conf = setOutputDirs(new Configuration());
    conf.set(IMPORT_TRUST_LEVEL_THRESHOLD, "0.8");
    doReturn(conf).when(context).getConfiguration();

    reducer.setup(context);
    
    String resultId = "resultId";
    String id = InfoSpaceConstants.ROW_PREFIX_RESULT + resultId;
    Text key = new Text(id);
    InfoSpaceRecord bodyRecord = new InfoSpaceRecord(
            new Text(Type.result.name()),
            new Text(OafBodyWithOrderedUpdates.BODY_QUALIFIER_NAME),
            new Text(JsonFormat.printToString(buildResultEntity(resultId))));
    
    List<InfoSpaceRecord> values = Lists.newArrayList(bodyRecord);
    
    // execute
    reducer.reduce(key, values, context);
    
    // assert
    verify(context, never()).write(any(), any());
    verify(multipleOutputs, never()).write(any(), any());
}
 
开发者ID:openaire,项目名称:iis,代码行数:27,代码来源:ImportInformationSpaceReducerTest.java

示例4: testReduceResultWithProvenanceBlacklist

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
@Test
public void testReduceResultWithProvenanceBlacklist() throws Exception {
    // given
    Configuration conf = setOutputDirs(new Configuration());
    conf.set(IMPORT_INFERENCE_PROVENANCE_BLACKLIST, INFERENCE_PROVENANCE_DEFAULT);
    doReturn(conf).when(context).getConfiguration();

    reducer.setup(context);
    
    String resultId = "resultId";
    String id = InfoSpaceConstants.ROW_PREFIX_RESULT + resultId;
    Text key = new Text(id);
    InfoSpaceRecord bodyRecord = new InfoSpaceRecord(
            new Text(Type.result.name()),
            new Text(OafBodyWithOrderedUpdates.BODY_QUALIFIER_NAME),
            new Text(JsonFormat.printToString(buildResultEntity(resultId))));
    
    List<InfoSpaceRecord> values = Lists.newArrayList(bodyRecord);
    
    // execute
    reducer.reduce(key, values, context);
    
    // assert
    verify(context, never()).write(any(), any());
    verify(multipleOutputs, never()).write(any(), any());
}
 
开发者ID:openaire,项目名称:iis,代码行数:27,代码来源:ImportInformationSpaceReducerTest.java

示例5: testReduceResultDeletedByInference

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
@Test
public void testReduceResultDeletedByInference() throws Exception {
    // given
    Configuration conf = setOutputDirs(new Configuration());
    conf.set(IMPORT_SKIP_DELETED_BY_INFERENCE, "true");
    doReturn(conf).when(context).getConfiguration();

    reducer.setup(context);
    
    String resultId = "resultId";
    String id = InfoSpaceConstants.ROW_PREFIX_RESULT + resultId;
    Text key = new Text(id);
    InfoSpaceRecord bodyRecord = new InfoSpaceRecord(
            new Text(Type.result.name()),
            new Text(OafBodyWithOrderedUpdates.BODY_QUALIFIER_NAME),
            new Text(JsonFormat.printToString(buildResultEntity(resultId, true))));
    
    List<InfoSpaceRecord> values = Lists.newArrayList(bodyRecord);
    
    // execute
    reducer.reduce(key, values, context);
    
    // assert
    verify(context, never()).write(any(), any());
    verify(multipleOutputs, never()).write(any(), any());
}
 
开发者ID:openaire,项目名称:iis,代码行数:27,代码来源:ImportInformationSpaceReducerTest.java

示例6: encode

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
@Override
public byte[] encode(Message message) {
	if (message == null)
		return new byte[0];
	
	String json = JsonFormat.printToString(message);
	return json.getBytes(charset);
}
 
开发者ID:ugcs,项目名称:ugcs-java-sdk,代码行数:9,代码来源:ProtoJsonEncoder.java

示例7: testReduceResultWithMergedBodyUpdates

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
@Test
public void testReduceResultWithMergedBodyUpdates() throws Exception {
    // given
    Configuration conf = setOutputDirs(new Configuration());
    conf.set(IMPORT_MERGE_BODY_WITH_UPDATES, "true");
    doReturn(conf).when(context).getConfiguration();

    reducer.setup(context);
    
    String resultId = "resultId";
    String id = InfoSpaceConstants.ROW_PREFIX_RESULT + resultId;
    Text key = new Text(id);
    InfoSpaceRecord bodyRecord = new InfoSpaceRecord(
            new Text(Type.result.name()),
            new Text(OafBodyWithOrderedUpdates.BODY_QUALIFIER_NAME),
            new Text(JsonFormat.printToString(buildResultEntity(resultId))));
    
    String updatedPublisher = "updated publisher";
    InfoSpaceRecord updateRecord = new InfoSpaceRecord(
            new Text(Type.result.name()),
            new Text("update"),
            new Text(JsonFormat.printToString(buildResultEntity(resultId, updatedPublisher, false))));
    
    List<InfoSpaceRecord> values = Lists.newArrayList(
            bodyRecord, updateRecord);
    
    // execute
    reducer.reduce(key, values, context);
    
    // assert
    verify(context, never()).write(any(), any());
    verify(multipleOutputs, times(1)).write(mosKeyCaptor.capture(), mosValueCaptor.capture());
    // doc meta
    assertEquals(conf.get(OUTPUT_NAME_DOCUMENT_META), mosKeyCaptor.getValue());
    DocumentMetadata docMeta = (DocumentMetadata) mosValueCaptor.getValue().datum();
    assertNotNull(docMeta);
    assertEquals(resultId, docMeta.getId());
    assertEquals(updatedPublisher, docMeta.getPublisher());
}
 
开发者ID:openaire,项目名称:iis,代码行数:40,代码来源:ImportInformationSpaceReducerTest.java

示例8: testReduceResultAcceptingDeletedByInference

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
@Test
public void testReduceResultAcceptingDeletedByInference() throws Exception {
 // given
    Configuration conf = setOutputDirs(new Configuration());
    conf.set(IMPORT_SKIP_DELETED_BY_INFERENCE, "false");
    doReturn(conf).when(context).getConfiguration();

    reducer.setup(context);
    
    String resultId = "resultId";
    String id = InfoSpaceConstants.ROW_PREFIX_RESULT + resultId;
    Text key = new Text(id);
    InfoSpaceRecord bodyRecord = new InfoSpaceRecord(
            new Text(Type.result.name()),
            new Text(OafBodyWithOrderedUpdates.BODY_QUALIFIER_NAME),
            new Text(JsonFormat.printToString(buildResultEntity(resultId, true))));
    
    List<InfoSpaceRecord> values = Lists.newArrayList(bodyRecord);
    
    // execute
    reducer.reduce(key, values, context);
    
    // assert
    verify(context, never()).write(any(), any());
    verify(multipleOutputs, times(1)).write(mosKeyCaptor.capture(), mosValueCaptor.capture());
    // doc meta
    assertEquals(conf.get(OUTPUT_NAME_DOCUMENT_META), mosKeyCaptor.getValue());
    DocumentMetadata docMeta = (DocumentMetadata) mosValueCaptor.getValue().datum();
    assertNotNull(docMeta);
    assertEquals(resultId, docMeta.getId());
}
 
开发者ID:openaire,项目名称:iis,代码行数:32,代码来源:ImportInformationSpaceReducerTest.java

示例9: printToJson

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
private String printToJson(Message message) {
    if (message instanceof StringListPB) {
        StringListPB list = (StringListPB) message;
        return Joiner.on("\",\"")
                .appendTo(new StringBuilder("\""), list.getValuesList())
                .append("\"")
                .toString();
    }
    return JsonFormat.printToString(message);
}
 
开发者ID:rhlabs,项目名称:louie,代码行数:11,代码来源:JsonProcessor.java

示例10: testReduceResultWithRelations

import com.googlecode.protobuf.format.JsonFormat; //导入方法依赖的package包/类
@Test
public void testReduceResultWithRelations() throws Exception {
    // given
    Configuration conf = setOutputDirs(new Configuration());
    doReturn(conf).when(context).getConfiguration();

    reducer.setup(context);
    
    String resultId = "resultId";
    String id = InfoSpaceConstants.ROW_PREFIX_RESULT + resultId;
    Text key = new Text(id);
    InfoSpaceRecord bodyRecord = new InfoSpaceRecord(
            new Text(Type.result.name()),
            new Text(OafBodyWithOrderedUpdates.BODY_QUALIFIER_NAME),
            new Text(JsonFormat.printToString(buildResultEntity(resultId))));
    
    String updatedPublisher = "updated publisher";
    InfoSpaceRecord updateRecord = new InfoSpaceRecord(
            new Text(Type.result.name()),
            new Text("update"),
            new Text(JsonFormat.printToString(buildResultEntity(resultId, updatedPublisher, false))));
    
    String projectId = "projectId";
    InfoSpaceRecord resProjRelRecord = new InfoSpaceRecord(
            new Text(reducer.resProjColumnFamily),
            new Text("resProjQualifier"),
            new Text(JsonFormat.printToString(buildRel(resultId, projectId))));
    
    String dedupedId = "dedupedId";
    InfoSpaceRecord dedupMappingRelRecord = new InfoSpaceRecord(
            new Text(reducer.dedupMappingColumnFamily),
            new Text("dedupQualifier"),
            new Text(JsonFormat.printToString(buildRel(resultId, dedupedId))));
    
    List<InfoSpaceRecord> values = Lists.newArrayList(
            bodyRecord, updateRecord, resProjRelRecord, dedupMappingRelRecord);
    
    // execute
    reducer.reduce(key, values, context);
    
    // assert
    verify(context, never()).write(any(), any());
    verify(multipleOutputs, times(3)).write(mosKeyCaptor.capture(), mosValueCaptor.capture());
    // doc meta
    assertEquals(conf.get(OUTPUT_NAME_DOCUMENT_META), mosKeyCaptor.getAllValues().get(0));
    DocumentMetadata docMeta = (DocumentMetadata) mosValueCaptor.getAllValues().get(0).datum();
    assertNotNull(docMeta);
    assertEquals(resultId, docMeta.getId());
    assertEquals(PUBLISHER_DEFAULT, docMeta.getPublisher());
    
    // result project rel
    assertEquals(conf.get(OUTPUT_NAME_DOCUMENT_PROJECT), mosKeyCaptor.getAllValues().get(1));
    DocumentToProject docProjRel = (DocumentToProject) mosValueCaptor.getAllValues().get(1).datum();
    assertNotNull(docProjRel);
    assertEquals(resultId, docProjRel.getDocumentId());
    assertEquals(projectId, docProjRel.getProjectId());
    // dedup mapping rel
    assertEquals(conf.get(OUTPUT_NAME_DEDUP_MAPPING), mosKeyCaptor.getAllValues().get(2));
    IdentifierMapping dedupMappingRel = (IdentifierMapping) mosValueCaptor.getAllValues().get(2).datum();
    assertNotNull(dedupMappingRel);
    assertEquals(dedupedId, dedupMappingRel.getOriginalId());
    assertEquals(resultId, dedupMappingRel.getNewId());
}
 
开发者ID:openaire,项目名称:iis,代码行数:64,代码来源:ImportInformationSpaceReducerTest.java


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