diff --git a/src/main/java/org/jboss/jandex/JarIndexer.java b/src/main/java/org/jboss/jandex/JarIndexer.java
index f658fbb2..916b43d0 100644
--- a/src/main/java/org/jboss/jandex/JarIndexer.java
+++ b/src/main/java/org/jboss/jandex/JarIndexer.java
@@ -68,6 +68,24 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
return createJarIndex(jarFile, indexer, modify, newJar, verbose, System.out, System.err);
}
+ /**
+ * Indexes a jar file and saves the result. If the modify flag is set, index is saved to META-INF/jandex.idx.
+ * Otherwise an external file is created with a similar name to the original file,
+ * concatenating .idx
suffix.
+ *
+ * @param jarFile The file to index
+ * @param indexer The indexer to use
+ * @param outputFile The index file to write to
+ * @param modify If the original jar should be modified
+ * @param newJar If the new jar should be created
+ * @param verbose If we should print what we are doing to standard out
+ * @return indexing result
+ * @throws IOException for any I/o error
+ */
+ public static Result createJarIndex(File jarFile, Indexer indexer, File outputFile, boolean modify, boolean newJar, boolean verbose) throws IOException {
+ return createJarIndex(jarFile, indexer, outputFile, modify, newJar, verbose, System.out, System.err);
+ }
+
/**
* Indexes a jar file and saves the result. If the modify flag is set, index is saved to META-INF/jandex.idx.
* Otherwise an external file is created with a similar name to the original file,
@@ -85,10 +103,30 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
* @throws IOException for any I/o error
*/
public static Result createJarIndex(File jarFile, Indexer indexer, boolean modify, boolean newJar, boolean verbose, PrintStream infoStream, PrintStream errStream) throws IOException {
+ return createJarIndex(jarFile, indexer, null, modify, newJar, verbose, infoStream, errStream);
+ }
+
+ /**
+ * Indexes a jar file and saves the result. If the modify flag is set, index is saved to META-INF/jandex.idx.
+ * Otherwise an external file is created with a similar name to the original file,
+ * concatenating .idx
suffix.
+ *
+ * @param jarFile The file to index
+ * @param indexer The indexer to use
+ * @param outputFile The index file to write to
+ * @param modify If the original jar should be modified
+ * @param newJar If the new jar should be created
+ * @param verbose If we should print what we are doing to the specified info stream
+ * @param infoStream A print stream which will record verbose info, may be null 1
+ * @param errStream A print stream to print errors, must not be null
+ *
+ * @return indexing result
+ * @throws IOException for any I/o error
+ */
+ public static Result createJarIndex(File jarFile, Indexer indexer, File outputFile, boolean modify, boolean newJar, boolean verbose, PrintStream infoStream, PrintStream errStream) throws IOException {
File tmpCopy = null;
ZipOutputStream zo = null;
OutputStream out;
- File outputFile = null;
JarFile jar = new JarFile(jarFile);
@@ -100,7 +138,9 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
outputFile = getIndexFile(jarFile, newJar);
out = zo = new ZipOutputStream(new FileOutputStream(outputFile));
} else {
- outputFile = getIndexFile(jarFile, newJar);
+ if (outputFile == null) {
+ outputFile = getIndexFile(jarFile, newJar);
+ }
out = new FileOutputStream(outputFile);
}
diff --git a/src/main/java/org/jboss/jandex/Main.java b/src/main/java/org/jboss/jandex/Main.java
index 3f3f472b..aa6702c7 100644
--- a/src/main/java/org/jboss/jandex/Main.java
+++ b/src/main/java/org/jboss/jandex/Main.java
@@ -84,7 +84,8 @@ private void execute(String[] args) {
private Index getIndex(long start) throws IOException {
Indexer indexer = new Indexer();
- Result result = (source.isDirectory()) ? indexDirectory(source, indexer) : JarIndexer.createJarIndex(source, indexer, modify, jarFile, verbose);
+ Result result = (source.isDirectory()) ? indexDirectory(source, indexer) : JarIndexer.createJarIndex(source, indexer, outputFile, modify, jarFile, verbose);
+
double time = (System.currentTimeMillis() - start) / 1000.00;
System.out.printf("Wrote %s in %.4f seconds (%d classes, %d annotations, %d instances, %d bytes)\n", result.getName(), time, result.getClasses(), result.getAnnotations(), result.getInstances(), result.getBytes());
return result.getIndex();
@@ -222,11 +223,11 @@ private void parseOptions(String[] args) {
break;
case 'o':
if (i >= args.length)
- throw new IllegalArgumentException("-o reuires an output file name");
+ throw new IllegalArgumentException("-o requires an output file name");
String name = args[++i];
if (name.length() < 1)
- throw new IllegalArgumentException("-o reuires an output file name");
+ throw new IllegalArgumentException("-o requires an output file name");
outputFile = new File(name);
optionCount++;