Class Printed<K,​V>

  • Type Parameters:
    K - key type
    V - value type
    Direct Known Subclasses:
    PrintedInternal

    public class Printed<K,​V>
    extends java.lang.Object
    An object to define the options used when printing a KStream.
    See Also:
    KStream.print(Printed)
    • Field Detail

      • outputStream

        protected final java.io.OutputStream outputStream
      • label

        protected java.lang.String label
      • mapper

        protected KeyValueMapper<? super K,​? super V,​java.lang.String> mapper
    • Constructor Detail

      • Printed

        protected Printed​(Printed<K,​V> printed)
        Copy constructor.
        Parameters:
        printed - instance of Printed to copy
    • Method Detail

      • toFile

        public static <K,​V> Printed<K,​V> toFile​(java.lang.String filePath)
        Print the records of a KStream to a file.
        Type Parameters:
        K - key type
        V - value type
        Parameters:
        filePath - path of the file
        Returns:
        a new Printed instance
      • toSysOut

        public static <K,​V> Printed<K,​V> toSysOut()
        Print the records of a KStream to system out.
        Type Parameters:
        K - key type
        V - value type
        Returns:
        a new Printed instance
      • withLabel

        public Printed<K,​V> withLabel​(java.lang.String label)
        Print the records of a KStream with the provided label.
        Parameters:
        label - label to use
        Returns:
        this
      • withKeyValueMapper

        public Printed<K,​V> withKeyValueMapper​(KeyValueMapper<? super K,​? super V,​java.lang.String> mapper)
        Print the records of a KStream with the provided KeyValueMapper The provided KeyValueMapper's mapped value type must be String.

        The example below shows how to customize output data.

        
         final KeyValueMapper<Integer, String, String> mapper = new KeyValueMapper<Integer, String, String>() {
             public String apply(Integer key, String value) {
                 return String.format("(%d, %s)", key, value);
             }
         };
         
        Implementors will need to override toString() for keys and values that are not of type String, Integer etc. to get meaningful information.
        Parameters:
        mapper - mapper to use
        Returns:
        this