Author: [email protected]
Date: Thu Jan 26 17:52:54 2012
New Revision: 2008
Log:
AMDATU-507 Removed redundant lifecycle methods / Added explicit close to all
imputstreams
Modified:
trunk/amdatu-core/fileinstall-autoconf/src/main/java/org/amdatu/core/fileinstall/tenantconf/AutoConfArtifactInstaller.java
Modified:
trunk/amdatu-core/fileinstall-autoconf/src/main/java/org/amdatu/core/fileinstall/tenantconf/AutoConfArtifactInstaller.java
==============================================================================
---
trunk/amdatu-core/fileinstall-autoconf/src/main/java/org/amdatu/core/fileinstall/tenantconf/AutoConfArtifactInstaller.java
(original)
+++
trunk/amdatu-core/fileinstall-autoconf/src/main/java/org/amdatu/core/fileinstall/tenantconf/AutoConfArtifactInstaller.java
Thu Jan 26 17:52:54 2012
@@ -18,6 +18,7 @@
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import org.apache.felix.fileinstall.ArtifactInstaller;
@@ -33,6 +34,7 @@
* Apache Felix FileInstall extension that hands of metatype configuration
artifacts
* to a autoconf {@link ResourceProcessor}.
*
+ * @author <a href="mailto:[email protected]">Amdatu Project
Team</a>
*/
public final class AutoConfArtifactInstaller implements ArtifactInstaller {
@@ -54,14 +56,6 @@
private volatile ResourceProcessor m_autoConfProcessor;
private volatile LogService m_logService;
- public void start() {
- m_logService.log(LogService.LOG_DEBUG, "Starting");
- }
-
- public void stop() {
- m_logService.log(LogService.LOG_DEBUG, "Stopping");
- }
-
/**
* @see
org.apache.felix.fileinstall.ArtifactListener#canHandle(java.io.File)
*/
@@ -70,15 +64,27 @@
return false;
}
+ InputStream stream = null;
MetaData metaData = null;
try {
- InputStream stream = new BufferedInputStream(new
FileInputStream(artifact));
+ stream = new BufferedInputStream(new FileInputStream(artifact));
MetaDataReader reader = new MetaDataReader();
metaData = reader.parse(stream);
}
catch (Exception e) {
m_logService.log(LogService.LOG_DEBUG, "Unable to parse artifact
file " + artifact.getName(), e);
}
+ finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ }
+ catch (IOException e) {
+ m_logService.log(LogService.LOG_WARNING,
+ "Unable to close artifact inputstream " +
artifact.getName(), e);
+ }
+ }
+ }
return metaData != null;
}
@@ -90,26 +96,44 @@
m_logService.log(LogService.LOG_DEBUG,
"Installing metatype configuration file " + artifact.getName());
- synchronized (m_autoConfProcessor) {
- m_autoConfProcessor.begin(DUMMY_SESSION);
- m_autoConfProcessor.process(artifact.getName(), new
FileInputStream(artifact));
- m_autoConfProcessor.prepare();
- m_autoConfProcessor.commit();
+ InputStream stream = null;
+ try {
+ stream = new BufferedInputStream(new FileInputStream(artifact));
+ synchronized (m_autoConfProcessor) {
+ m_autoConfProcessor.begin(DUMMY_SESSION);
+ m_autoConfProcessor.process(artifact.getName(), stream);
+ m_autoConfProcessor.prepare();
+ m_autoConfProcessor.commit();
+ }
+ }
+ finally {
+ if (stream != null) {
+ stream.close();
+ }
}
}
/**
* @see org.apache.felix.fileinstall.ArtifactInstaller#update(java.io.File)
*/
- public synchronized void update(File artifact) throws Exception {
+ public void update(File artifact) throws Exception {
m_logService.log(LogService.LOG_DEBUG,
"Updating metatype configuration file " + artifact.getName());
- synchronized (m_autoConfProcessor) {
- m_autoConfProcessor.begin(DUMMY_SESSION);
- m_autoConfProcessor.process(artifact.getName(), new
FileInputStream(artifact));
- m_autoConfProcessor.prepare();
- m_autoConfProcessor.commit();
+ InputStream stream = null;
+ try {
+ stream = new BufferedInputStream(new FileInputStream(artifact));
+ synchronized (m_autoConfProcessor) {
+ m_autoConfProcessor.begin(DUMMY_SESSION);
+ m_autoConfProcessor.process(artifact.getName(), stream);
+ m_autoConfProcessor.prepare();
+ m_autoConfProcessor.commit();
+ }
+ }
+ finally {
+ if (stream != null) {
+ stream.close();
+ }
}
}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits