public TopicId topic(String topic) { return new TopicId(namespace, topic); }
public TopicId topic(String topic) { return new TopicId(namespace, topic); }
/** * Convert byte array encoded with the {@link #toMetadataRowKey(TopicId)} method back to the {@link TopicId} * * @param topicBytes byte array which contains the representation of the topic id * @param offset offset to start decoding * @param length number of bytes to decode * @return {@link TopicId} */ public static TopicId toTopicId(byte[] topicBytes, int offset, int length) { String topic = Bytes.toString(topicBytes, offset, length); int firstSeparator = topic.indexOf(":", offset); String ns = topic.substring(offset, firstSeparator); String topicId = topic.substring(firstSeparator + 1, topic.length() - 1); return new TopicId(ns, topicId); }
/** * Convert byte array encoded with the {@link #toMetadataRowKey(TopicId)} method back to the {@link TopicId} * * @param topicBytes byte array which contains the representation of the topic id * @param offset offset to start decoding * @param length number of bytes to decode * @return {@link TopicId} */ public static TopicId toTopicId(byte[] topicBytes, int offset, int length) { String topic = Bytes.toString(topicBytes, offset, length); int firstSeparator = topic.indexOf(":", offset); String ns = topic.substring(offset, firstSeparator); String topicId = topic.substring(firstSeparator + 1, topic.length() - 1); return new TopicId(ns, topicId); }
@SuppressWarnings("unused") public static TopicId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new TopicId(next(iterator, "namespace"), nextAndEnd(iterator, "topic")); }
@SuppressWarnings("unused") public static TopicId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new TopicId(next(iterator, "namespace"), nextAndEnd(iterator, "topic")); }
@Test public void testTopicConversion() throws Exception { TopicId id = new TopicId("n1", "t1"); byte[] topicBytes = MessagingUtils.toMetadataRowKey(id); TopicId topicId = MessagingUtils.toTopicId(topicBytes); Assert.assertEquals(id, topicId); }