mirror of https://github.com/apache/jclouds.git
Preventing a resource leak of an output stream for the jclouds.properties itest file
This commit is contained in:
parent
15a157a163
commit
2f5f0b3474
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.demo.tweetstore.integration;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.io.Closeables.closeQuietly;
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -45,7 +46,7 @@ public class GoogleDevServer {
|
|||
String filename = String.format(
|
||||
"%1$s/WEB-INF/jclouds.properties", warfile);
|
||||
System.err.println("file: " + filename);
|
||||
props.store(new FileOutputStream(filename), "test");
|
||||
storeProperties(filename, props);
|
||||
assert new File(filename).exists();
|
||||
this.server = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
|
@ -64,6 +65,15 @@ public class GoogleDevServer {
|
|||
TimeUnit.SECONDS.sleep(30);
|
||||
}
|
||||
|
||||
private static void storeProperties(String filename, Properties props) throws IOException {
|
||||
FileOutputStream targetFile = new FileOutputStream(filename);
|
||||
try {
|
||||
props.store(targetFile, "test");
|
||||
} finally {
|
||||
closeQuietly(targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() throws Exception {
|
||||
// KickStart.main opens a process and calls process.waitFor(), which is interruptable
|
||||
server.interrupt();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.demo.tweetstore.integration;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.io.Closeables.closeQuietly;
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -45,7 +46,7 @@ public class GoogleDevServer {
|
|||
String filename = String.format(
|
||||
"%1$s/WEB-INF/jclouds.properties", warfile);
|
||||
System.err.println("file: " + filename);
|
||||
props.store(new FileOutputStream(filename), "test");
|
||||
storeProperties(filename, props);
|
||||
assert new File(filename).exists();
|
||||
this.server = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
|
@ -64,6 +65,15 @@ public class GoogleDevServer {
|
|||
TimeUnit.SECONDS.sleep(30);
|
||||
}
|
||||
|
||||
private static void storeProperties(String filename, Properties props) throws IOException {
|
||||
FileOutputStream targetFile = new FileOutputStream(filename);
|
||||
try {
|
||||
props.store(targetFile, "test");
|
||||
} finally {
|
||||
closeQuietly(targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() throws Exception {
|
||||
// KickStart.main opens a process and calls process.waitFor(), which is interruptable
|
||||
server.interrupt();
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.demo.tweetstore.integration;
|
||||
|
||||
import static com.google.common.io.Closeables.closeQuietly;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -29,9 +31,9 @@ import javax.servlet.ServletException;
|
|||
import org.apache.commons.cli.ParseException;
|
||||
|
||||
/**
|
||||
* Basic functionality to start a local google app engine instance.
|
||||
* Basic functionality to start a local RUN@cloud instance.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Andrew Phillips
|
||||
*/
|
||||
public class RunAtCloudServer {
|
||||
protected StaxSdkAppServer2 server;
|
||||
|
@ -42,7 +44,7 @@ public class RunAtCloudServer {
|
|||
String filename = String.format(
|
||||
"%1$s/WEB-INF/jclouds.properties", warfile);
|
||||
System.err.println("file: " + filename);
|
||||
props.store(new FileOutputStream(filename), "test");
|
||||
storeProperties(filename, props);
|
||||
assert new File(filename).exists();
|
||||
server = StaxSdkAppServer2.createServer(new String[] { "-web", warfile, "-port", port, "-env", environments,
|
||||
"-dir", serverBaseDirectory }, new String[0], Thread.currentThread().getContextClassLoader());
|
||||
|
@ -50,6 +52,15 @@ public class RunAtCloudServer {
|
|||
TimeUnit.SECONDS.sleep(30);
|
||||
}
|
||||
|
||||
private static void storeProperties(String filename, Properties props) throws IOException {
|
||||
FileOutputStream targetFile = new FileOutputStream(filename);
|
||||
try {
|
||||
props.store(targetFile, "test");
|
||||
} finally {
|
||||
closeQuietly(targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() throws Exception {
|
||||
server.stop();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue