googleapis / googleapis/google-http-java-client

GZipEncoding should throw IOException from close

Offen
#868 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
type: cleanup
Vorherrschende Sprache
Java
Sterne
1.4k
Forks
473
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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();
}
}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.