Skip to content

Commit

Permalink
review and refactor according to github security scans
Browse files Browse the repository at this point in the history
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
  • Loading branch information
neowu committed Nov 8, 2024
1 parent 47876cc commit b6e0a1b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
40 changes: 20 additions & 20 deletions core-ng/src/main/java/core/framework/http/EventSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @author neo
*/
public final class EventSource implements AutoCloseable, Iterable<EventSource.Event>, Iterator<EventSource.Event> {
public final class EventSource implements AutoCloseable, Iterable<EventSource.Event> {
private static final Logger LOGGER = LoggerFactory.getLogger(EventSource.class);
public final int statusCode;
public final Map<String, String> headers; // headers key is case insensitive
Expand Down Expand Up @@ -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<Event> 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) {
Expand Down
6 changes: 3 additions & 3 deletions core-ng/src/main/java/core/framework/util/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit b6e0a1b

Please sign in to comment.