/** Render this as <a href="http://json.org/">JSON</a>.*/ @Override public String toString() { return toString(false); }
/** Render this as <a href="http://json.org/">JSON</a>.*/ @Override public String toString() { return toString(false); }
/** Return the MD5 hash of the text of this protocol. */ public byte[] getMD5() { if (md5 == null) try { md5 = MessageDigest.getInstance("MD5") .digest(this.toString().getBytes("UTF-8")); } catch (Exception e) { throw new AvroRuntimeException(e); } return md5; }
/** Return the MD5 hash of the text of this protocol. */ public byte[] getMD5() { if (md5 == null) try { md5 = MessageDigest.getInstance("MD5") .digest(this.toString().getBytes("UTF-8")); } catch (Exception e) { throw new AvroRuntimeException(e); } return md5; }
/** Return the protocol for a Java interface. */ public Protocol getProtocol(Class iface) { try { Protocol p = (Protocol)(iface.getDeclaredField("PROTOCOL").get(null)); if (!p.getNamespace().equals(iface.getPackage().getName())) // HACK: protocol mismatches iface. maven shade plugin? try replacing. p = Protocol.parse(p.toString().replace(p.getNamespace(), iface.getPackage().getName())); return p; } catch (NoSuchFieldException e) { throw new AvroRuntimeException("Not a Specific protocol: "+iface); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
/** Return the protocol for a Java interface. */ public Protocol getProtocol(Class iface) { try { Protocol p = (Protocol)(iface.getDeclaredField("PROTOCOL").get(null)); if (!p.getNamespace().equals(iface.getPackage().getName())) // HACK: protocol mismatches iface. maven shade plugin? try replacing. p = Protocol.parse(p.toString().replace(p.getNamespace(), iface.getPackage().getName())); return p; } catch (NoSuchFieldException e) { throw new AvroRuntimeException("Not a Specific protocol: "+iface); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
parseOut.print(p.toString(true)); } finally { if (parseOut != out) // Close only the newly created FileOutputStream
System.out.println(ReflectData.get().getProtocol(klass).toString(true)); } else { System.out.println(ReflectData.get().getSchema(klass).toString(true));
public void execute() throws MojoExecutionException { ClassLoader classLoader = getClassLoader(); for(File inputFile : sourceDirectory.listFiles()) { String className = parseClassName(inputFile.getPath()); Class<?> klass = loadClass(classLoader, className); String fileName = outputDirectory.getPath() + "/" + parseFileName(klass); File outputFile = new File(fileName); outputFile.getParentFile().mkdirs(); try { PrintWriter writer = new PrintWriter(fileName, "UTF-8"); if(klass.isInterface()) { writer.println(ReflectData.get().getProtocol(klass).toString(true)); } else { writer.println(ReflectData.get().getSchema(klass).toString(true)); } writer.close(); } catch(Exception e) { e.printStackTrace(); } } }
String json = p.toString(true); Protocol protocol = Protocol.parse(json); SpecificCompiler compiler = new SpecificCompiler(protocol, getDateTimeLogicalTypeImplementation());
@Test public void testSplitProtocolBuild() { Protocol p = new Protocol("P", null, "foo"); p.addProp("property", "some value"); String protocolString = p.toString(); final int mid = protocolString.length() / 2; String[] parts = { protocolString.substring(0, mid), protocolString.substring(mid), }; Protocol parsedStringProtocol = org.apache.avro.Protocol.parse(protocolString); Protocol parsedArrayOfStringProtocol = org.apache.avro.Protocol.parse(protocolString.substring(0, mid), protocolString.substring(mid)); assertNotNull(parsedStringProtocol); assertNotNull(parsedArrayOfStringProtocol); assertEquals(parsedStringProtocol.toString(), parsedArrayOfStringProtocol.toString()); } }
out.println(p.toString(true));
response.serverProtocol = local.toString(); response.serverHash = localHash;
private void writeHandshake(Encoder out) throws IOException { if (getTransceiver().isConnected()) return; MD5 localHash = new MD5(); localHash.bytes(local.getMD5()); String remoteName = transceiver.getRemoteName(); MD5 remoteHash = REMOTE_HASHES.get(remoteName); if (remoteHash == null) { // guess remote is local remoteHash = localHash; remote = local; } else { remote = REMOTE_PROTOCOLS.get(remoteHash); } HandshakeRequest handshake = new HandshakeRequest(); handshake.clientHash = localHash; handshake.serverHash = remoteHash; if (sendLocalText) handshake.clientProtocol = local.toString(); RPCContext context = new RPCContext(); context.setHandshakeRequest(handshake); for (RPCPlugin plugin : rpcMetaPlugins) { plugin.clientStartConnect(context); } handshake.meta = context.requestHandshakeMeta(); HANDSHAKE_WRITER.write(handshake, out); }
@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))); }
/** Render this as <a href="http://json.org/">JSON</a>.*/ @Override public String toString() { return toString(false); }
/** Return the MD5 hash of the text of this protocol. */ public byte[] getMD5() { if (md5 == null) try { md5 = MessageDigest.getInstance("MD5") .digest(this.toString().getBytes("UTF-8")); } catch (Exception e) { throw new AvroRuntimeException(e); } return md5; }
/** Return the MD5 hash of the text of this protocol. */ public byte[] getMD5() { if (md5 == null) try { md5 = MessageDigest.getInstance("MD5") .digest(this.toString().getBytes("UTF-8")); } catch (Exception e) { throw new AvroRuntimeException(e); } return md5; }
/** Return the MD5 hash of the text of this protocol. */ public byte[] getMD5() { if (md5 == null) try { md5 = MessageDigest.getInstance("MD5") .digest(this.toString().getBytes("UTF-8")); } catch (Exception e) { throw new AvroRuntimeException(e); } return md5; }
/** Return the MD5 hash of the text of this protocol. */ public byte[] getMD5() { if (md5 == null) try { md5 = MessageDigest.getInstance("MD5") .digest(this.toString().getBytes("UTF-8")); } catch (Exception e) { throw new AvroRuntimeException(e); } return md5; }