From 8cd71889e56409c3b9eb63a1cb280459aee870f3 Mon Sep 17 00:00:00 2001 From: neo <1100909+neowu@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:51:44 -0500 Subject: [PATCH] review and refactor according to github security scans Signed-off-by: neo <1100909+neowu@users.noreply.github.com> --- .../java/core/framework/http/EventSource.java | 40 ++++++++++--------- .../main/java/core/framework/util/Files.java | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/core-ng/src/main/java/core/framework/http/EventSource.java b/core-ng/src/main/java/core/framework/http/EventSource.java index a9da6f135..0734cb7be 100644 --- a/core-ng/src/main/java/core/framework/http/EventSource.java +++ b/core-ng/src/main/java/core/framework/http/EventSource.java @@ -45,25 +45,7 @@ public void close() { @Override public Iterator iterator() { - return new Iterator<>() { - @Override - public boolean hasNext() { - if (nextEvent != null) return true; - nextEvent = parseResponse(body.source()); - return nextEvent != null; - } - - @Override - public Event next() { - if (nextEvent != null || hasNext()) { - var event = nextEvent; - nextEvent = null; - return event; - } else { - throw new NoSuchElementException(); - } - } - }; + return new EventIterator(); } private Event parseResponse(BufferedSource source) { @@ -103,4 +85,24 @@ private Event parseResponse(BufferedSource source) { public record Event(String id, String data) { } + + private class EventIterator implements Iterator { + @Override + public boolean hasNext() { + if (nextEvent != null) return true; + nextEvent = parseResponse(body.source()); + return nextEvent != null; + } + + @Override + public Event next() { + if (nextEvent != null || hasNext()) { + var event = nextEvent; + nextEvent = null; + return event; + } else { + throw new NoSuchElementException(); + } + } + } } diff --git a/core-ng/src/main/java/core/framework/util/Files.java b/core-ng/src/main/java/core/framework/util/Files.java index 63ea6cd5c..6fb44f653 100644 --- a/core-ng/src/main/java/core/framework/util/Files.java +++ b/core-ng/src/main/java/core/framework/util/Files.java @@ -36,7 +36,7 @@ public static byte[] bytes(Path file) { } catch (IOException e) { throw new UncheckedIOException(e); } finally { - LOGGER.debug("bytes, file={}, elapsed={}", file.toString(), watch.elapsed()); + LOGGER.debug("bytes, file={}, elapsed={}", file, watch.elapsed()); } }