org.apache.avro.Protocol.parse()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中org.apache.avro.Protocol.parse()方法的一些代码示例,展示了Protocol.parse()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Protocol.parse()方法的具体详情如下:
包路径:org.apache.avro.Protocol
类名称:Protocol
方法名:parse

Protocol.parse介绍

[英]Read a protocol from a Json file.
[中]从Json文件中读取协议。

代码示例

代码示例来源:origin: apache/avro

/** Read a protocol from a Json file. */
public static Protocol parse(File file) throws IOException {
 return parse(Schema.FACTORY.createParser(file));
}

代码示例来源:origin: apache/avro

/** Read a protocol from a Json stream. */
public static Protocol parse(InputStream stream) throws IOException {
 return parse(Schema.FACTORY.createParser(stream));
}

代码示例来源:origin: apache/avro

/** Read a protocol from one or more json strings */
public static Protocol parse(String string, String... more) {
 StringBuilder b = new StringBuilder(string);
 for (String part : more)
  b.append(part);
 return parse(b.toString());
}

代码示例来源:origin: apache/avro

public static void main(String[] args) throws Exception {
 System.out.println(Protocol.parse(new File(args[0])));
}

代码示例来源:origin: org.apache.avro/avro

public static void main(String[] args) throws Exception {
 System.out.println(Protocol.parse(new File(args[0])));
}

代码示例来源:origin: apache/avro

/** Read a protocol from a Json string. */
public static Protocol parse(String string) {
 try {
  return parse(Schema.FACTORY.createParser
         (new ByteArrayInputStream(string.getBytes("UTF-8"))));
 } catch (IOException e) {
  throw new AvroRuntimeException(e);
 }
}

代码示例来源:origin: org.apache.avro/avro

/** Read a protocol from one or more json strings */
public static Protocol parse(String string, String... more) {
 StringBuilder b = new StringBuilder(string);
 for (String part : more)
  b.append(part);
 return parse(b.toString());
}

代码示例来源:origin: org.apache.avro/avro

/** Read a protocol from a Json string. */
public static Protocol parse(String string) {
 try {
  return parse(Schema.FACTORY.createJsonParser
         (new ByteArrayInputStream(string.getBytes("UTF-8"))));
 } catch (IOException e) {
  throw new AvroRuntimeException(e);
 }
}

代码示例来源:origin: apache/avro

private void setRemote(HandshakeResponse handshake) throws IOException {
 remote = Protocol.parse(handshake.serverProtocol.toString());
 MD5 remoteHash = (MD5)handshake.serverHash;
 REMOTE_HASHES.put(transceiver.getRemoteName(), remoteHash);
 REMOTE_PROTOCOLS.putIfAbsent(remoteHash, remote);
}

代码示例来源:origin: org.apache.avro/avro

/** Read a protocol from a Json stream. */
public static Protocol parse(InputStream stream) throws IOException {
 return parse(Schema.FACTORY.createJsonParser(stream));
}

代码示例来源:origin: apache/avro

private static Protocol parse(JsonParser parser) {
 try {
  Protocol protocol = new Protocol();
  protocol.parse((JsonNode)Schema.MAPPER.readTree(parser));
  return protocol;
 } catch (IOException e) {
  throw new SchemaParseException(e);
 }
}

代码示例来源:origin: apache/avro

public static Protocol getSimpleProtocol() throws IOException {
 File file = new File("../../../share/test/schemas/simple.avpr");
 return Protocol.parse(file);
}

代码示例来源:origin: apache/avro

/**
 * Generates Java interface and classes for a number of protocol files.
 * @param srcFiles the source Avro protocol files
 * @param dest the directory to place generated files in
 */
public static void compileProtocol(File[] srcFiles, File dest) throws IOException {
 for (File src : srcFiles) {
  Protocol protocol = Protocol.parse(src);
  SpecificCompiler compiler = new SpecificCompiler(protocol);
  compiler.compileToDestination(src, dest);
 }
}

代码示例来源:origin: apache/avro

private static Message parseMessage(String message) throws Exception {
 return Protocol.parse("{\"protocol\": \"org.foo.Bar\","
            +"\"types\": [],"
            +"\"messages\": {"
            + message
            + "}}").getMessages().values().iterator().next();
}

代码示例来源:origin: org.apache.avro/avro

private static Protocol parse(JsonParser parser) {
 try {
  Protocol protocol = new Protocol();
  protocol.parse(Schema.MAPPER.readTree(parser));
  return protocol;
 } catch (IOException e) {
  throw new SchemaParseException(e);
 }
}

代码示例来源:origin: apache/avro

protected void doCompile(File src, File dir) throws IOException {
 Protocol protocol = Protocol.parse(src);
 SpecificCompiler compiler = new SpecificCompiler(protocol, getDateTimeLogicalTypeImplementation());
 compiler.setStringType(getStringType());
 compiler.compileToDestination(src, dest);
}

代码示例来源:origin: apache/avro

@Test
 public void testRpcProtocol() throws Exception {

  // run the actual test
  ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
  PrintStream p2 = new PrintStream(baos2, true, "UTF-8");
  RpcProtocolTool testObject = new RpcProtocolTool();

  testObject.run(null, p2, System.err,
    Arrays.asList(uriScheme + "://127.0.0.1:" + receive.server.getPort() + "/"));

  p2.flush();

  assertEquals("Expected the simple.avpr protocol to be echoed to standout",
    simpleProtocol, Protocol.parse(baos2.toString("UTF-8")));

 }
}

代码示例来源:origin: apache/avro

@Test
public void testManglingForProtocols() throws IOException {
 Collection<OutputFile> outputs = new SpecificCompiler(Protocol.parse(PROTOCOL)).compile();
 Iterator<OutputFile> i = outputs.iterator();
 String errType = i.next().contents;
 String protocol = i.next().contents;
 assertTrue(errType.contains("public class finally$ extends org.apache.avro.specific.SpecificExceptionBase"));
 assertTrue(errType.contains("public boolean catch$;"));
 assertTrue(protocol.contains("java.lang.CharSequence goto$(java.lang.CharSequence break$)"));
 assertTrue(protocol.contains("public interface default$"));
 assertTrue(protocol.contains("throws org.apache.avro.AvroRemoteException, finally$"));
 assertCompilesWithJavaCompiler(new File(INPUT_DIR.getRoot(), name.getMethodName()), outputs);
}

代码示例来源:origin: apache/avro

@Test
public void testProtocolSplit() throws IOException {
 SpecificCompiler compiler = new SpecificCompiler(Protocol.parse(PROTOCOL));
 compiler.maxStringChars = 10;
 Collection<OutputFile> files = compiler.compile();
 assertCompilesWithJavaCompiler(new File(INPUT_DIR.getRoot(), name.getMethodName()), files);
}

代码示例来源:origin: apache/avro

@Test
public void testForwardReference() {
 ReflectData data = ReflectData.get();
 Protocol reflected = data.getProtocol(C.class);
 Protocol reparsed = Protocol.parse(reflected.toString());
 assertEquals(reflected, reparsed);
 assert(reparsed.getTypes().contains(data.getSchema(A.class)));
 assert(reparsed.getTypes().contains(data.getSchema(B1.class)));
 assert(reparsed.getTypes().contains(data.getSchema(B2.class)));
 assert(reparsed.getTypes().contains(data.getSchema(X.class)));
}

相关文章