Skip to content

Commit

Permalink
Close streams when reading the manifest
Browse files Browse the repository at this point in the history
Signed-off-by: Clement Escoffier <clement.escoffier@gmail.com>
  • Loading branch information
cescoffier committed Oct 1, 2015
1 parent adab820 commit 85ea227
Showing 1 changed file with 9 additions and 2 deletions.
Expand Up @@ -24,6 +24,7 @@
import io.vertx.core.spi.launcher.ExecutionContext;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.util.*;
Expand Down Expand Up @@ -384,15 +385,18 @@ protected String getDefaultCommand() {
try {
Enumeration<URL> resources = RunCommand.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
InputStream stream = resources.nextElement().openStream();
Manifest manifest = new Manifest(stream);
Attributes attributes = manifest.getMainAttributes();
String mainClass = attributes.getValue("Main-Class");
if (main.getClass().getName().equals(mainClass)) {
String command = attributes.getValue("Main-Command");
if (command != null) {
stream.close();
return command;
}
}
stream.close();
}
} catch (IOException e) {
throw new IllegalStateException(e.getMessage());
Expand All @@ -414,15 +418,18 @@ protected String getMainVerticle() {
try {
Enumeration<URL> resources = RunCommand.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
InputStream stream = resources.nextElement().openStream();
Manifest manifest = new Manifest(stream);
Attributes attributes = manifest.getMainAttributes();
String mainClass = attributes.getValue("Main-Class");
if (main != null && main.getClass().getName().equals(mainClass)) {
String theMainVerticle = attributes.getValue("Main-Verticle");
if (theMainVerticle != null) {
stream.close();
return theMainVerticle;
}
}
stream.close();
}
} catch (IOException e) {
throw new IllegalStateException(e.getMessage());
Expand Down

0 comments on commit 85ea227

Please sign in to comment.