mal
mal

Reputation: 3204

Will this InputStream be closed properly if an IOException occurs?

I'm trying to properly handle an IOException without having to resort to a tonne of nested try/catch statements. From reading online I've gathered that this might be the correct way to handle it. but I'm not 100% sure. Is this right?

    try (InputStream in = blob.getBinaryStream()) { 
            while (in.read(bytesRead) != -1) {
                byteStream.write(bytesRead);
            }   
    }catch(IOException e){
        logger.error("An IOException occurred while streaming a blob from the database", e);
    }

Upvotes: 0

Views: 46

Answers (1)

lexicore
lexicore

Reputation: 43651

The InputStream in will be closed, byteStream not.

Upvotes: 1

Related Questions