git://git.nikiroo.be
/
fanfix.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
76c54ef
)
fix forceResetableStream
author
Niki Roo
<niki@nikiroo.be>
Mon, 15 Apr 2019 21:28:35 +0000
(23:28 +0200)
committer
Niki Roo
<niki@nikiroo.be>
Mon, 15 Apr 2019 21:28:35 +0000
(23:28 +0200)
src/be/nikiroo/utils/IOUtils.java
patch
|
blob
|
blame
|
history
diff --git
a/src/be/nikiroo/utils/IOUtils.java
b/src/be/nikiroo/utils/IOUtils.java
index e9a378c0fd6e279c1568afb848808ab83f9cdf5e..c7cbe259b5abab2e0d65d7639b83641eddd7a357 100644
(file)
--- 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 {
*/
public static InputStream forceResetableStream(InputStream in)
throws IOException {
- MarkableFileInputStream tmpIn = null;
- File tmp = null;
-
boolean resetable = in.markSupported();
if (resetable) {
try {
boolean resetable = in.markSupported();
if (resetable) {
try {
@@
-412,19
+409,32
@@
public class IOUtils {
return in;
}
return in;
}
-
tmp = File.createTempFile(".tmp-stream
", ".tmp");
+
final File tmp = File.createTempFile(".tmp-stream.
", ".tmp");
try {
write(in, 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;
}
}
}
}