Skip to content

Commit

Permalink
Minor improvements over the last FileInputStream enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
vy committed Oct 23, 2023
1 parent 0a1b336 commit 0fa934f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

### (????-??-??) v0.9.6

- Avoid using `FileInputStream`, since it requires a full-GC for clean-up. (#174, #175)

### (2022-06-02) v0.9.5

- Guard against I/O failures while reading file length. (#70)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ methods.
thread-safety improvements)
- [Lukas Bradley](https://github.com/lukasbradley/)
- [Liran Mendelovich](https://github.com/liran2000/) (rolling via `maxBackupCount`)
- [Nicolas Clemeur](https://github.com/nclemeur) (avoiding `FileInputStream`)

# License

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/vlkan/rfos/RotatingFileOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ private void startPolicies() {

private ByteCountingOutputStream open(RotationPolicy policy, Instant instant) {
try {
OpenOption[] openOptions = { StandardOpenOption.CREATE,
this.config.isAppend() ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING };
OutputStream fileOutputStream = Files.newOutputStream(this.config.getFile().toPath(), openOptions);
invokeCallbacks(callback -> callback.onOpen(policy, instant, fileOutputStream));
OpenOption[] openOptions = {
StandardOpenOption.CREATE,
this.config.isAppend() ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING
};
OutputStream outputStream = Files.newOutputStream(this.config.getFile().toPath(), openOptions);
invokeCallbacks(callback -> callback.onOpen(policy, instant, outputStream));
long size = config.isAppend() ? readFileLength() : 0;
return new ByteCountingOutputStream(fileOutputStream, size);
return new ByteCountingOutputStream(outputStream, size);
} catch (IOException error) {
String message = String.format("file open failure {file=%s}", config.getFile());
throw new RuntimeException(message, error);
Expand Down

0 comments on commit 0fa934f

Please sign in to comment.