New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-42934] Avoid using new FileInputStream / new FileOutputStream #2816
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0cd7ae
[JENKINS-42934] Avoid using new FileInputStream / new FileOutputStream
stephenc a7fc570
[JENKINS-42934] Need to catch a different exception
stephenc 211bb29
[JENKINS-42934] When you specify options you need to include CREATE o…
stephenc 218d0a5
[JENKINS-42934] Actually use Java's file locking API to lock the file…
stephenc e603b10
[JENKINS-42934] A couple of places where FileNotFoundException may be…
stephenc 568772c
[JENKINS-42934] Some unit tests need side-effects of FileInputStream
stephenc File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,7 @@ public static String loadFile(@Nonnull File logfile, @Nonnull Charset charset) t | |
|
||
StringBuilder str = new StringBuilder((int)logfile.length()); | ||
|
||
try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(logfile), charset))) { | ||
try (BufferedReader r = new BufferedReader(new InputStreamReader(Files.newInputStream(logfile.toPath()), charset))) { | ||
char[] buf = new char[1024]; | ||
int len; | ||
while ((len = r.read(buf, 0, buf.length)) > 0) | ||
|
@@ -800,7 +800,7 @@ public static String getDigestOf(@Nonnull String text) { | |
*/ | ||
@Nonnull | ||
public static String getDigestOf(@Nonnull File file) throws IOException { | ||
try (InputStream is = new FileInputStream(file)) { | ||
try (InputStream is = Files.newInputStream(file.toPath())) { | ||
return getDigestOf(new BufferedInputStream(is)); | ||
} | ||
} | ||
|
@@ -1134,7 +1134,7 @@ public static String xmlEscape(@Nonnull String text) { | |
* Creates an empty file. | ||
*/ | ||
public static void touch(@Nonnull File file) throws IOException { | ||
new FileOutputStream(file).close(); | ||
Files.newOutputStream(file.toPath()).close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stephenc Why not use Files.createFile() with an exists check? |
||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're no longer closing quietly here...