Skip to content

Commit

Permalink
Fixed checkstyle error and addressed comments
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Kondaka <[email protected]>
  • Loading branch information
Krishna Kondaka committed Feb 28, 2024
1 parent cb3cabe commit 0be7f01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@ public class JsonDecoder implements ByteDecoder {
private final ObjectMapper objectMapper = new ObjectMapper();
private final JsonFactory jsonFactory = new JsonFactory();

public void parse(InputStream inputStream, Instant timeReceivedMs, Consumer<Record<Event>> eventConsumer) throws IOException {
public void parse(InputStream inputStream, Instant timeReceived, Consumer<Record<Event>> eventConsumer) throws IOException {
Objects.requireNonNull(inputStream);
Objects.requireNonNull(eventConsumer);

final JsonParser jsonParser = jsonFactory.createParser(inputStream);

while (!jsonParser.isClosed() && jsonParser.nextToken() != JsonToken.END_OBJECT) {
if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
parseRecordsArray(jsonParser, timeReceivedMs, eventConsumer);
parseRecordsArray(jsonParser, timeReceived, eventConsumer);
}
}
}

private void parseRecordsArray(final JsonParser jsonParser, final Instant timeReceivedMs, final Consumer<Record<Event>> eventConsumer) throws IOException {
private void parseRecordsArray(final JsonParser jsonParser, final Instant timeReceived, final Consumer<Record<Event>> eventConsumer) throws IOException {
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
final Map<String, Object> innerJson = objectMapper.readValue(jsonParser, Map.class);

final Record<Event> record = createRecord(innerJson, timeReceivedMs);
final Record<Event> record = createRecord(innerJson, timeReceived);
eventConsumer.accept(record);
}
}

private Record<Event> createRecord(final Map<String, Object> json, final Instant timeReceivedMs) {
private Record<Event> createRecord(final Map<String, Object> json, final Instant timeReceived) {
final JacksonLog.Builder logBuilder = JacksonLog.builder()
.withData(json)
.getThis();
if (timeReceivedMs != null) {
logBuilder.withTimeReceived(timeReceivedMs);
if (timeReceived != null) {
logBuilder.withTimeReceived(timeReceived);
}
final JacksonEvent event = (JacksonEvent)logBuilder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Future;
Expand Down

0 comments on commit 0be7f01

Please sign in to comment.