public static String SHAsum(byte[] convertme) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-1"); return byteArray2Hex(md.digest(convertme)); }
@Override public S getSchemaByID(String topic, String id) { File file = getSchemaPath(topic, id, false); if (!file.exists()) { file = getSchemaPath(topic, id, true); } if (!file.exists()) { throw new SchemaNotFoundException("No matching schema found for topic " + topic + " and id " + id + "."); } return serde.fromBytes(readBytes(file)); }
private File getSchemaPath(String topic, String id, boolean latest) { return new File(getTopicPath(topic), id + ".schema" + ((latest) ? ".latest" : "")); }
FileOutputStream out = null; File topicDir = getTopicPath(topic); String id = SHAsum(bytes); File file = getSchemaPath(topic, id, true); out = new FileOutputStream(file); out.write(bytes);
@Override public SchemaDetails<S> getLatestSchemaByTopic(String topicName) { File topicDir = getTopicPath(topicName); if (topicDir.exists()) { for (File file : topicDir.listFiles()) { if (file.getName().endsWith(".latest")) { String id = file.getName().replace(".schema.latest", ""); return new SchemaDetails<S>(topicName, id, serde.fromBytes(readBytes(file))); } } } throw new SchemaNotFoundException("Unable to find a latest schema for topic " + topicName + "."); }
@Parameters public static Collection data() { File tmpDir = new File("/tmp/test-" + System.currentTimeMillis()); SchemaRegistry<String> fileRegistry = new FileSchemaRegistry<String>(tmpDir, new StringSerde()); SchemaRegistry<String> memoryRegistry = new MemorySchemaRegistry<String>(); Object[][] data = new Object[][] { { fileRegistry }, { memoryRegistry } }; return Arrays.asList(data); }
FileOutputStream out = null; File topicDir = getTopicPath(topic); String id = SHAsum(bytes); File file = getSchemaPath(topic, id, true); out = new FileOutputStream(file); out.write(bytes);
@Override public SchemaDetails<S> getLatestSchemaByTopic(String topicName) { File topicDir = getTopicPath(topicName); if (topicDir.exists()) { for (File file : topicDir.listFiles()) { if (file.getName().endsWith(".latest")) { String id = file.getName().replace(".schema.latest", ""); return new SchemaDetails<S>(topicName, id, serde.fromBytes(readBytes(file))); } } } throw new SchemaNotFoundException("Unable to find a latest schema for topic " + topicName + "."); }
@Override public S getSchemaByID(String topic, String id) { File file = getSchemaPath(topic, id, false); if (!file.exists()) { file = getSchemaPath(topic, id, true); } if (!file.exists()) { throw new SchemaNotFoundException("No matching schema found for topic " + topic + " and id " + id + "."); } return serde.fromBytes(readBytes(file)); }
private File getSchemaPath(String topic, String id, boolean latest) { return new File(getTopicPath(topic), id + ".schema" + ((latest) ? ".latest" : "")); }
public static String SHAsum(byte[] convertme) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-1"); return byteArray2Hex(md.digest(convertme)); }