-
Notifications
You must be signed in to change notification settings - Fork 75
[JENKINS-64261] BaseFileContent.InputStreamSupplier #649
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
Conversation
IOUtils.copy(new TruncatedInputStream(is, maxSize), os); | ||
} | ||
void writeTo(OutputStream os) throws IOException { | ||
try (InputStream is = inputStreamSupplier.get()) { |
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.
(ignore ws)
try { | ||
try (InputStream is = inputStreamSupplier.get()) { | ||
if (maxSize == -1) { | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, ENCODING))) { | ||
String s; | ||
while ((s = reader.readLine()) != null) { | ||
String filtered = ContentFilter.filter(filter, secretsFilterFunction.apply(s)) + "\n"; | ||
IOUtils.write(filtered, os, ENCODING); | ||
} | ||
try (InputStream is = inputStreamSupplier.get()) { |
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.
Double try
block seems unnecessary. Dates to #206.
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.
Correct, could just be included down in the try
s in each conditions.
return getInputStream(); | ||
} catch (IOException e) { | ||
LOGGER.log(Level.WARNING, "Error opening file " + file, e); | ||
return null; |
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.
Bug dates to #174.
|
||
/** | ||
* Utility class with the common logic to FileContent and UnfilteredFileContent. | ||
* | ||
* @author Stephen Connolly, M Ramón León | ||
*/ | ||
@Restricted(NoExternalUse.class) |
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.
Why was this ever restricted in #174? It was never public
.
@@ -67,27 +69,9 @@ class BaseFileContent { | |||
|
|||
private static final String ENCODING = "UTF-8"; | |||
|
|||
/** | |||
* @deprecated (as it is placed in the api package we keep backward compatibility, no relevant usage was found) |
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.
Why was this left in place in c6d20da? The class was not exposed outside the package.
|
||
@FunctionalInterface | ||
interface InputStreamSupplier { | ||
InputStream get() throws IOException; |
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.
Letting the caller handle the IOException
. #174 appears to have been catching FileNotFoundException
for this reason, but that could not actually have been thrown from the body of the try
block: other IOException
s from handling OutputStream
, perhaps, but the Supplier
permitted no IOException
so FileNotFoundException
was being caught earlier.
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.
Thanks Jesse. I think this is https://issues.jenkins.io/browse/JENKINS-64261.
Overall looks good to me.
BaseFileContent.InputStreamSupplier
Noticed in a support bundle several exceptions of the form
This seems to be due to a
Supplier<InputStream>
returningnull
, which was not expected by the caller. #190 fixed this forFileContent
but notUnfilteredFileContent
.