Skip to content

Clear up InputStream ownership #8

@hakanai

Description

@hakanai

I found that the COPY method wasn't closing file streams.

The servlet calls this to get the source data:

    InputStream getResourceContent(ITransaction transaction, String resourceUri);

Then it does the copy by passing it to:

    long setResourceContent(ITransaction transaction, String resourceUri,
            InputStream content, String contentType, String characterEncoding);

But after doing the copy, it doesn't close the stream.

On further investigation, I found that LocalFileSystemStore was handling this by closing the stream inside its implementation of setResourceContent. This seems odd to me, because the stream is passed from the outside, which implies that the caller owns it, and thus the caller should surely be responsible for closing it.

Maybe this could be cleared up, either by flipping the responsibilities around to close it from the caller, or by clearly documenting on setResourceContent the contract that the implementation is expected to close the stream. (The caveat of the latter being that if there was an issue calling the method, the code which closes the stream might not be called, i.e., the only really safe place to have the closing code is at the caller.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions