HHH-6120 - Configuration addCacheableFile doesn't close input and output streams
This commit is contained in:
parent
f24b9829c8
commit
8a4b5ccbfc
|
@ -568,26 +568,53 @@ 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 {
|
||||||
|
final InputSource inputSource = new InputSource( fileInputStream );
|
||||||
|
log.info( "Reading mappings from file: " + xmlFile );
|
||||||
|
metadataXml = add( inputSource, "file", name );
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
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 ) {
|
||||||
|
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 );
|
log.debug( "Writing cache file for: " + xmlFile + " to: " + cachedFile );
|
||||||
SerializationHelper.serialize( ( Serializable ) metadataXml.getDocumentTree(), new FileOutputStream( cachedFile ) );
|
}
|
||||||
|
SerializationHelper.serialize( ( Serializable ) metadataXml.getDocumentTree(), fileOutputStream );
|
||||||
}
|
}
|
||||||
catch ( SerializationException e ) {
|
catch ( SerializationException e ) {
|
||||||
log.warn( "Could not write cached file: " + cachedFile, e );
|
log.warn( "Could not write cached file: " + cachedFile, e );
|
||||||
}
|
}
|
||||||
catch ( FileNotFoundException e ) {
|
finally {
|
||||||
log.warn( "I/O reported error writing cached file : " + cachedFile.getPath(), e );
|
try {
|
||||||
|
fileInputStream.close();
|
||||||
|
}
|
||||||
|
catch ( IOException e ) {
|
||||||
|
log.warn( "I/O exception while closing cache for mapping file : " + cachedFile + " : " + e );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in New Issue