Path: blob/master/external/source/msfJavaToolkit/javaCompile/SignJar.java
24755 views
// Based on the example from http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm12package javaCompile;34import java.io.PrintStream;5import java.io.FilterOutputStream;6import java.io.ByteArrayOutputStream;7import java.io.OutputStream;8import java.io.IOException;9import sun.security.tools.KeyTool;10import sun.security.tools.JarSigner;1112public class SignJar {1314static PrintStream filteredstream =15new PrintStream(16new FilteredStream(17new ByteArrayOutputStream()));1819public static void KeyToolMSF( String[] args ) {20try {21RedirectStd();22KeyTool.main( args );23} catch( Exception ex ) { ex.printStackTrace(); }24}2526public static void JarSignerMSF( String[] args ) {27try {28RedirectStd();29JarSigner.main( args );30} catch( Exception ex ) { ex.printStackTrace(); }31}3233private static void RedirectStd() {34try {35System.setOut( filteredstream );36System.setErr( filteredstream );37} catch( Exception ex ) { ex.printStackTrace(); }38}3940static class FilteredStream extends FilterOutputStream {41public FilteredStream( OutputStream aStream ) { super ( aStream ); }4243public void write( byte b[] ) throws IOException {44String aString = new String( b );45// Do stuff with the output.46}4748public void write( byte b[], int off, int len) throws IOException {49String aString = new String( b, off, len );50// Do stuff with the output.51}52}53}545556