Am I closing my input stream correctly in Java?

前端 未结 2 1498
感情败类
感情败类 2021-01-25 17:29

I created a class that extends InputStream so that I can keep count of the number of bytes being read and throw an exception if it exceeds a max limit that I define.

Her

2条回答
  •  独厮守ぢ
    2021-01-25 17:43

    The try-with-resources only closes the declared resource. So will only close metadataStream.

    You should implement the close method in LimitedSizeInputStream to close the original stream.

    @Override
    public void close() throws IOException {
        original.close();
    }
    

提交回复
热议问题