/** Read a protocol from a Json file. */ public static Protocol parse(File file) throws IOException { return parse(Schema.FACTORY.createParser(file)); }
/** Read a protocol from a Json stream. */ public static Protocol parse(InputStream stream) throws IOException { return parse(Schema.FACTORY.createParser(stream)); }
/** 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()); }
public static void main(String[] args) throws Exception { System.out.println(Protocol.parse(new File(args[0]))); }
public static void main(String[] args) throws Exception { System.out.println(Protocol.parse(new File(args[0]))); }
/** 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); } }
/** 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()); }
/** 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); } }
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); }
/** Read a protocol from a Json stream. */ public static Protocol parse(InputStream stream) throws IOException { return parse(Schema.FACTORY.createJsonParser(stream)); }
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); } }
public static Protocol getSimpleProtocol() throws IOException { File file = new File("../../../share/test/schemas/simple.avpr"); return Protocol.parse(file); }
/** * 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); } }
private static Message parseMessage(String message) throws Exception { return Protocol.parse("{\"protocol\": \"org.foo.Bar\"," +"\"types\": []," +"\"messages\": {" + message + "}}").getMessages().values().iterator().next(); }
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); } }
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); }
@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"))); } }
@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); }
@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); }
@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))); }