brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <>
Subject [GitHub] brooklyn-server pull request #196: Close streams after usage
Date Tue, 14 Jun 2016 17:41:28 GMT
Github user aledsage commented on a diff in the pull request:
    --- Diff: core/src/main/java/org/apache/brooklyn/util/core/crypto/ ---
    @@ -78,11 +78,11 @@ public static X509Principal getX509PrincipalWithCommonName(String
commonName) {
             return new X509Principal("" + "C=None," + "L=None," + "O=None," + "OU=None,"
+ "CN=" + commonName);
    -    /** reads RSA or DSA / pem style private key files (viz {@link #toPem(KeyPair)}),
extracting also the public key if possible
    +    /** reads RSA or DSA / pem style private key files (viz {@link #toPem(KeyPair)}),
extracting also the public key if possible. Closes the stream.
          * @throws IllegalStateException on errors, in particular {@link PassphraseProblem}
if that is the problem */
         public static KeyPair readPem(InputStream input, final String passphrase) {
             // TODO cache is only for fallback "reader" strategy (2015-01); delete when Parser
confirmed working
    -        byte[] cache = Streams.readFully(input);
    +        byte[] cache = Streams.readFullyAndClose(input);
    --- End diff --
    Feels like the responsibility of the caller to close the stream, rather than this method.
    Looking at things like Guava's `ByteStreams`, they've deprecated all the methods that
closed the stream that was passed in (and switched to a completely different pattern that
uses `ByteSource`).
    That makes me think it is the wrong thing to close the stream we are given.
    Are there any good examples of good modern APIs that close the stream that is passed in?

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

View raw message