Skip to content

Overload for put() OutputStream or allowing us to pass a Consumer<OutputStream> #192

@hakanai

Description

@hakanai

Many APIs don't give back an InputStream for streaming serialisation, but instead ask me to pass an OutputStream. For instance, [GSON.toJson](https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html#toJson%28java.lang.Object, java.lang.Appendable%29) does this, GZIPOutputStream does as well, but all the custom filesystem APIs we use at work do the same thing, because it's more flexible.

So I would like an overload to put where I can either do this:

    getSardine().put(childUri.toString(), stream -> {
        // I write to stream
    });

or this:

    try (OutputStream stream = getSardine().put(childUri.toString())) {
        // I write to stream
    }

My workaround for the lack of it will be to create a Pipe and spin up an additional thread to do the copy, which is a little awkward.

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