googleapis / googleapis/google-http-java-client

GZipEncoding should throw IOException from close

Ouverte
#868 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
type: cleanup
Langage dominant
Java
Étoiles
1.4k
Forks
473
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.