forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Souvik Bose <[email protected]>
- Loading branch information
Showing
12 changed files
with
394 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...a/org/opensearch/dataprepper/plugins/kinesis/source/converter/KinesisRecordConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.kinesis.source.converter; | ||
|
||
import org.opensearch.dataprepper.model.codec.InputCodec; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import software.amazon.kinesis.retrieval.KinesisClientRecord; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class KinesisRecordConverter { | ||
|
||
private final InputCodec codec; | ||
|
||
public KinesisRecordConverter(final InputCodec codec) { | ||
this.codec = codec; | ||
} | ||
|
||
public List<Record<Event>> convert(List<KinesisClientRecord> kinesisClientRecords) throws IOException { | ||
List<Record<Event>> records = new ArrayList<>(); | ||
for (KinesisClientRecord record : kinesisClientRecords) { | ||
processRecord(record, records::add); | ||
} | ||
return records; | ||
} | ||
|
||
private void processRecord(KinesisClientRecord record, Consumer<Record<Event>> eventConsumer) throws IOException { | ||
// Read bytebuffer | ||
byte[] arr = new byte[record.data().remaining()]; | ||
record.data().get(arr); | ||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(arr); | ||
codec.parse(byteArrayInputStream, eventConsumer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.