[patch] FileUtil nitpicking on safeClose
Eckenfels. Bernd
B.Eckenfels at seeburger.de
Fri May 1 01:11:42 UTC 2015
safeClose(OutputStream) should really be called unsafeClose() :)
While reading JMH sources to learn some new coding tricks I noticed that FileUtil.extractFromResource() is using Buffered streams with no real reason (when you use a buffer for read/write). So I removed those streams and used the same pattern as used in #copy().
While doing so however I noticed that both places use safeClose(OutputStream) in the normal case (i.e. not only in finally to rollback). This is somewhat unsafe as it might lead to data loss. Some file systems (like NFS) might actually signal write errors only on close.
So I added a "normal" throwing close for the output stream (flush is not needed). I did not inspect other users of safeClose().
Please find attached my proposed patch. Let me know if you would prefer to actually null the output stream (as it is a bit strange to flush() a closed stream even when the exceptions are suppressed).
NB: there are some pathetic conditions where copying with larger buffers and bufferedoutputstream helps (if the input does not take advantage of those large read buffers), but I dont think it is the case here.
Gruss
Bernd
PS: the unit tests did not run (they failed before, have'nt yet checked if it is a windows, i18n, java 8 or maven 3.2.5 problem, will let you know)
PPS: posting from my mail address which should be on-file for contributions
SEEBURGER AG Vorstand/SEEBURGER Executive Board:
Sitz der Gesellschaft/Registered Office: Bernd Seeburger, Axel Haas, Michael Kleeberg, Friedemann Heinz, Dr. Martin Kuntz, Matthias Feßenbecker
Edisonstr. 1
D-75015 Bretten Vorsitzender des Aufsichtsrats/Chairperson of the SEEBURGER Supervisory Board:
Tel.: 07252 / 96 - 0 Dr. Franz Scherer
Fax: 07252 / 96 - 2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info at seeburger.de HRB 240708 Mannheim
Dieses E-Mail ist nur für den Empfänger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungsäußerung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empfänger, so haben Sie diese E-Mail irrtümlich erhalten und jegliche Verwendung, Veröffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender (Eckenfels. Bernd) übernehmen die Haftung für Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anhänge auf Viren zu prüfen.
This email is intended only for the recipient(s) to whom it is addressed. This email may contain confidential material that may be protected by professional secrecy. Any fact or opinion contained, or expression of the material herein, does not necessarily reflect that of SEEBURGER AG. If you are not the addressee or if you have received this email in error, any use, publication or distribution including forwarding, copying or printing is strictly prohibited. Neither SEEBURGER AG, nor the sender (Eckenfels. Bernd) accept liability for viruses; it is your responsibility to check this email and its attachments for viruses.
More information about the jmh-dev
mailing list