HHH-6120 - Configuration addCacheableFile doesn't close input and output streams

This commit is contained in:
Sanne Grinovero 2011-04-12 23:37:58 +01:00 committed by Hardy Ferentschik
parent f24b9829c8
commit 8a4b5ccbfc
1 changed files with 37 additions and 10 deletions

View File

@ -568,27 +568,54 @@ public class Configuration implements Serializable {
} }
final String name = xmlFile.getAbsolutePath(); final String name = xmlFile.getAbsolutePath();
final InputSource inputSource; final FileInputStream fileInputStream;
try { try {
inputSource = new InputSource( new FileInputStream( xmlFile ) ); fileInputStream = new FileInputStream( xmlFile );
} }
catch ( FileNotFoundException e ) { catch ( FileNotFoundException e ) {
throw new MappingNotFoundException( "file", xmlFile.toString() ); throw new MappingNotFoundException( "file", xmlFile.toString() );
} }
final XmlDocument metadataXml;
log.info( "Reading mappings from file: " + xmlFile );
XmlDocument metadataXml = add( inputSource, "file", name );
try { try {
log.debug( "Writing cache file for: " + xmlFile + " to: " + cachedFile ); final InputSource inputSource = new InputSource( fileInputStream );
SerializationHelper.serialize( ( Serializable ) metadataXml.getDocumentTree(), new FileOutputStream( cachedFile ) ); log.info( "Reading mappings from file: " + xmlFile );
metadataXml = add( inputSource, "file", name );
} }
catch ( SerializationException e ) { finally {
log.warn( "Could not write cached file: " + cachedFile, e ); try {
fileInputStream.close();
}
catch ( IOException e ) {
log.warn( "I/O exception while closing mapping file : " + cachedFile.getPath() + " : " + e );
}
}
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream( cachedFile );
} }
catch ( FileNotFoundException e ) { catch ( FileNotFoundException e ) {
log.warn( "I/O reported error writing cached file : " + cachedFile.getPath(), e ); log.warn( "I/O reported error writing cached file : " + cachedFile.getPath(), e );
} }
if ( fileInputStream != null ) {
try {
if ( log.isDebugEnabled() ) {
log.debug( "Writing cache file for: " + xmlFile + " to: " + cachedFile );
}
SerializationHelper.serialize( ( Serializable ) metadataXml.getDocumentTree(), fileOutputStream );
}
catch ( SerializationException e ) {
log.warn( "Could not write cached file: " + cachedFile, e );
}
finally {
try {
fileInputStream.close();
}
catch ( IOException e ) {
log.warn( "I/O exception while closing cache for mapping file : " + cachedFile + " : " + e );
}
}
}
return this; return this;
} }