googleapis / googleapis/google-http-java-client

GZipEncoding should throw IOException from close

Aperta
#868 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
type: cleanup
Lingua principale
Java
Stelle
1.4k
Fork
473
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.