X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FIOUtils.java;h=c7cbe259b5abab2e0d65d7639b83641eddd7a357;hp=e9a378c0fd6e279c1568afb848808ab83f9cdf5e;hb=75712fb3f9e0b2605ddb50a156b0ff5a23bacef2;hpb=76c54eff86f51689ab73d1b53796206d139d6fc3 diff --git a/src/be/nikiroo/utils/IOUtils.java b/src/be/nikiroo/utils/IOUtils.java index e9a378c..c7cbe25 100644 --- a/src/be/nikiroo/utils/IOUtils.java +++ b/src/be/nikiroo/utils/IOUtils.java @@ -396,9 +396,6 @@ public class IOUtils { */ public static InputStream forceResetableStream(InputStream in) throws IOException { - MarkableFileInputStream tmpIn = null; - File tmp = null; - boolean resetable = in.markSupported(); if (resetable) { try { @@ -412,19 +409,32 @@ public class IOUtils { return in; } - tmp = File.createTempFile(".tmp-stream", ".tmp"); + final File tmp = File.createTempFile(".tmp-stream.", ".tmp"); try { write(in, tmp); - tmpIn = new MarkableFileInputStream(new FileInputStream(tmp)); - return tmpIn; - } finally { - try { - if (tmpIn != null) { - tmpIn.close(); + in.close(); + + final FileInputStream fis = new FileInputStream(tmp); + return new MarkableFileInputStream(fis) { + @Override + public void close() throws IOException { + try { + try { + super.close(); + } finally { + try { + fis.close(); + } catch (IOException e) { + } + } + } finally { + tmp.delete(); + } } - } finally { - tmp.delete(); - } + }; + } catch (IOException e) { + tmp.delete(); + throw e; } }