Skip to content

GZipEncoding should throw IOException from close #868

@elharo

Description

@elharo

The close method below swallows IOExceptions. That seems unnecessary and dangerous.

public class GZipEncoding implements HttpEncoding {

  public String getName() {
    return "gzip";
  }

  public void encode(StreamingContent content, OutputStream out) throws IOException {
    // must not close the underlying output stream
    OutputStream out2 =
        new BufferedOutputStream(out) {
          @Override
          public void close() throws IOException {
            // copy implementation of super.close(), except do not close the underlying output
            // stream
            try {
              flush();
            } catch (IOException ignored) {
                // Nothing else we can do here
            }
          }
        };
    GZIPOutputStream zipper = new GZIPOutputStream(out2);
    content.writeTo(zipper);
    // cannot call just zipper.finish() because that would cause a severe memory leak
    zipper.close();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: cleanupAn internal cleanup or hygiene concern.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions