'Using Custom Encoder for extracting the required information from Event in Stream File Sink

//Code Snippet for sinking data into s3 using stream file sink with custom encoder //Event consists of two objects but I need to sink only one object from the Event.

StreamingFileSink<Event> sink = StreamingFileSink
                .forRowFormat(new Path(s3SinkPath), new CustomEncoder<Event>("UTF-8") )
                .withBucketAssigner(new CustomBucketAssigner())
                .withRollingPolicy(DefaultRollingPolicy.builder().build())
                .build();

//Encoder overriden function

@Override
    public void encode(Event element, OutputStream stream) throws IOException {
        if (charset == null) {
            charset = Charset.forName(charsetName);
        }

        stream.write(element.toString().getBytes(charset));
        stream.write('\n');
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source