From b6e0a1b46e56216755dc4b818ae3af5256f44166 Mon Sep 17 00:00:00 2001 From: neo <1100909+neowu@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:18: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 | 6 +-- 2 files changed, 23 insertions(+), 23 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 31ed10828..a9da6f135 100644 --- a/core-ng/src/main/java/core/framework/http/EventSource.java +++ b/core-ng/src/main/java/core/framework/http/EventSource.java @@ -15,7 +15,7 @@ /** * @author neo */ -public final class EventSource implements AutoCloseable, Iterable, Iterator { +public final class EventSource implements AutoCloseable, Iterable { private static final Logger LOGGER = LoggerFactory.getLogger(EventSource.class); public final int statusCode; public final Map headers; // headers key is case insensitive @@ -43,27 +43,27 @@ public void close() { body.close(); } - @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(); - } - } - @Override public Iterator iterator() { - return this; + 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(); + } + } + }; } private Event parseResponse(BufferedSource source) { 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 25acf9a4a..63ea6cd5c 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, watch.elapsed()); + LOGGER.debug("bytes, file={}, elapsed={}", file.toString(), watch.elapsed()); } } @@ -73,12 +73,12 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) { public static Path tempFile() { String tempDir = System.getProperty("java.io.tmpdir"); - return Paths.get(tempDir + "/" + UUID.randomUUID().toString() + ".tmp"); + return Paths.get(tempDir + "/" + UUID.randomUUID() + ".tmp"); } public static Path tempDir() { String tempDir = System.getProperty("java.io.tmpdir"); - Path path = Paths.get(tempDir + "/" + UUID.randomUUID().toString()); + Path path = Paths.get(tempDir + "/" + UUID.randomUUID()); createDir(path); return path; }