[Simple-support] Bug in Persister
Brought to you by:
niallg
|
From: Mike Q. <mik...@su...> - 2007-05-08 16:08:13
|
Hi all,
=20
Think I have found a bug in the implementation of Persister where it
leaves Input/Output streams open.
=20
This method opens a stream but never closes it.
=20
public void write(Object source, File out) throws Exception {
write(source, new FileOutputStream(out));
}
=20
Probably needs to be something like..
=20
public void write(Object source, File out) throws Exception {
OutputStream outputStream =3D new FileOutputStream(out);
try {
write(source, outputStream);
}
finally {
try {
outputStream.close();
}
catch (Exception e) {
// ignore close error
}
}
}
=20
Similar problem in the read() method.
=20
public <T> T read(Class<? extends T> type, File source) throws
Exception {
return (T)read(type, new FileInputStream(source)); =20
}
=20
For completeness this StringReader should also be closed after use.
=20
public <T> T read(Class<? extends T> type, String source) throws
Exception {
return (T)read(type, new StringReader(source)); =20
}
=20
Cheers.
=20
Mike.
This e-mail is bound by the terms and conditions described at http://www=
=2Esubexazure.com/mail-disclaimer.html
=0D |