List of usage examples for java.io File separatorChar
char separatorChar
To view the source code for java.io File separatorChar.
Click Source Link
From source file:com.comcast.oscar.examples.InsertDigitMapToConfigurationBinaryTest.java
/** * @param args//from w ww .ja v a2 s . c om */ @SuppressWarnings("deprecation") public static void main(String[] args) { boolean debug = Boolean.FALSE; File fDigitMap = null; File fPacketCableTxt = null; File fPacketCableBin = null; //Get DigitMap try { fDigitMap = new File(new java.io.File(".").getCanonicalPath() + File.separatorChar + "testfiles" + File.separatorChar + "digitMap.txt"); } catch (IOException e) { e.printStackTrace(); } //OID String sOID = "enterprises.4491.2.2.8.2.1.1.3.1.1.2.1"; //Convert File to ByteArray byte[] bDigitMap = HexString.fileToByteArray(fDigitMap); //Need to get the JSON Dictionary Object, in this case, we need to use Snmp64 DictionarySQLQueries dsqSnmp64 = new DictionarySQLQueries( DictionarySQLQueries.PACKET_CABLE_DICTIONARY_TABLE_NAME); //Get JSON Dictionary Object JSONObject joDictSnmp64 = dsqSnmp64.getTlvDictionary(64); //Create JSON ARRAY for JSON Snmp64 Dictionary OIDToJSONArray otjoSnmp64 = new OIDToJSONArray(sOID, bDigitMap); try { joDictSnmp64 = otjoSnmp64.updateSnmpJsonObject(joDictSnmp64); } catch (JSONException e) { e.printStackTrace(); } // Validate: http://www.jsoneditoronline.org/ if (debug) System.out.println("Snmp64 - JSON-DICTIONARY: " + joDictSnmp64); /* Convert to TLV */ //Create a TlvAssembler for the JSON Dictionary TlvAssembler taSnmp64 = null; //Create an JSONArray Object - Need to make this more clean JSONArray jaSnmp64 = new JSONArray(); //Add JSONObject to JSONArray for TlvAssembler jaSnmp64.put(joDictSnmp64); //Get TlvAssembler() with Snmp64 TLV Encoding taSnmp64 = new TlvAssembler(jaSnmp64); //Display JSONObject if (debug) System.out.println("Snmp64: " + taSnmp64.toString()); /*Insert into Configuration File*/ /******************************** * Text To Binary ********************************/ try { fPacketCableTxt = new File(new java.io.File(".").getCanonicalPath() + File.separatorChar + "testfiles" + File.separatorChar + "IMS-PKT-CABLE-CONFIG-NO-DIGITMAP.txt"); } catch (IOException e) { e.printStackTrace(); } ConfigurationFileImport cfiPacketCable = null; try { try { cfiPacketCable = new ConfigurationFileImport(fPacketCableTxt); } catch (ConfigurationFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } ConfigurationFile cfSnmp64 = new ConfigurationFile(ConfigurationFile.PKT_CBL_VER_20, cfiPacketCable.getTlvBuilder()); //Add DigitMap cfSnmp64.add(taSnmp64); ConfigurationFile cfPacketCAble = new ConfigurationFile(ConfigurationFile.PKT_CBL_VER_20, cfiPacketCable.getTlvBuilder()); cfPacketCAble.commit(); try { fPacketCableBin = new File(new java.io.File(".").getCanonicalPath() + File.separatorChar + "testfiles" + File.separatorChar + File.separatorChar + "output" + File.separatorChar + "IMS-PKT-CABLE-CONFIG-WITH-DIGIT-MAP.bin"); } catch (IOException e) { e.printStackTrace(); } cfPacketCAble.setConfigurationFileName(fPacketCableBin); if (cfPacketCAble.writeToDisk()) { System.out.println("Write to File: "); } else { System.out.println("Write to File FAILED: "); } /******************************** * Binary To Text ********************************/ System.out.println( "+========================================================================================================================+"); try { fPacketCableBin = new File(new java.io.File(".").getCanonicalPath() + File.separatorChar + "testfiles" + File.separatorChar + "IMS-PKT-CABLE-CONFIG-NO-DIGITMAP.bin"); } catch (IOException e) { e.printStackTrace(); } ConfigurationFileExport cfePacketCable = new ConfigurationFileExport(fPacketCableBin); try { cfSnmp64 = new ConfigurationFile(ConfigurationFile.PKT_CBL_VER_20, cfePacketCable.getTlvBuilder()); } catch (TlvException e) { e.printStackTrace(); } //Add Snmp64 DigitMap cfSnmp64.add(taSnmp64); ConfigurationFileExport cfeSnmp64Insert = new ConfigurationFileExport(cfSnmp64); System.out.println(cfeSnmp64Insert.toPrettyPrint(0)); }
From source file:net.minecraftforge.fml.common.patcher.GenDiffSet.java
public static void main(String[] args) throws IOException { String sourceJar = args[0]; //Clean Vanilla jar minecraft.jar or minecraft_server.jar String targetDir = args[1]; //Directory containing obfed output classes, typically mcp/reobf/minecraft String deobfData = args[2]; //Path to FML's deobfusication_data.lzma String outputDir = args[3]; //Path to place generated .binpatch String killTarget = args[4]; //"true" if we should destroy the target file if it generated a successful .binpatch LogManager.getLogger("GENDIFF").log(Level.INFO, String.format("Creating patches at %s for %s from %s", outputDir, sourceJar, targetDir)); Delta delta = new Delta(); FMLDeobfuscatingRemapper remapper = FMLDeobfuscatingRemapper.INSTANCE; remapper.setupLoadOnly(deobfData, false); JarFile sourceZip = new JarFile(sourceJar); boolean kill = killTarget.equalsIgnoreCase("true"); File f = new File(outputDir); f.mkdirs();/*from ww w . ja v a 2 s . c o m*/ for (String name : remapper.getObfedClasses()) { // Logger.getLogger("GENDIFF").info(String.format("Evaluating path for data :%s",name)); String fileName = name; String jarName = name; if (RESERVED_NAMES.contains(name.toUpperCase(Locale.ENGLISH))) { fileName = "_" + name; } File targetFile = new File(targetDir, fileName.replace('/', File.separatorChar) + ".class"); jarName = jarName + ".class"; if (targetFile.exists()) { String sourceClassName = name.replace('/', '.'); String targetClassName = remapper.map(name).replace('/', '.'); JarEntry entry = sourceZip.getJarEntry(jarName); byte[] vanillaBytes = toByteArray(sourceZip, entry); byte[] patchedBytes = Files.toByteArray(targetFile); byte[] diff = delta.compute(vanillaBytes, patchedBytes); ByteArrayDataOutput diffOut = ByteStreams.newDataOutput(diff.length + 50); // Original name diffOut.writeUTF(name); // Source name diffOut.writeUTF(sourceClassName); // Target name diffOut.writeUTF(targetClassName); // exists at original diffOut.writeBoolean(entry != null); if (entry != null) { diffOut.writeInt(Hashing.adler32().hashBytes(vanillaBytes).asInt()); } // length of patch diffOut.writeInt(diff.length); // patch diffOut.write(diff); File target = new File(outputDir, targetClassName + ".binpatch"); target.getParentFile().mkdirs(); Files.write(diffOut.toByteArray(), target); Logger.getLogger("GENDIFF").info(String.format("Wrote patch for %s (%s) at %s", name, targetClassName, target.getAbsolutePath())); if (kill) { targetFile.delete(); Logger.getLogger("GENDIFF").info(String.format(" Deleted target: %s", targetFile.toString())); } } } sourceZip.close(); }
From source file:de.tu_dortmund.ub.data.dswarm.TaskProcessingUnit.java
public static void main(final String[] args) throws Exception { // default config String configFile = DEFAULT_CONF_FOLDER_NAME + File.separatorChar + DEFAULT_CONFIG_PROPERTIES_FILE_NAME; // read program parameters if (args.length > 0) { for (final String arg : args) { LOG.info("arg = " + arg); if (arg.startsWith("-conf=")) { configFile = arg.split("=")[1]; }/*from w ww . j av a 2 s . c om*/ } } final Properties config; // Init properties try { try (final InputStream inputStream = new FileInputStream(configFile)) { try (final BufferedReader reader = new BufferedReader( new InputStreamReader(inputStream, TPUUtil.UTF_8))) { config = new Properties(); config.load(reader); } } } catch (final IOException e) { LOG.error("something went wrong", e); LOG.error(String.format("FATAL ERROR: Could not read '%s'!", configFile)); throw e; } startTPU(configFile, config); }
From source file:jhc.redsniff.generation.PackageScanningGenerator.java
public static void main(String[] args) throws Exception { if (args.length != 5) { System.err.println("Args: source-dir package-class-filter parent-class generated-class output-dir"); System.err.println(""); System.err.println(" source-dir : Path to Java source containing matchers to generate sugar for."); System.err.println(" May contain multiple paths, separated by commas."); System.err.println(" e.g. src/java,src/more-java"); System.err.println(/*ww w .j a v a2 s. co m*/ " package-class-filter : base of package to look for classes with methods, eg jhc.selenium.matchers"); System.err.println(""); System.err.println( "parent-class : Full name of parent class type to examine - eg org.hamcrest.Matcher, jhc.selenium.seeker.Seeker"); System.err.println(" e.g. org.myproject.MyMatchers"); System.err.println("generated-class : Full name of class to generate."); System.err.println(" e.g. org.myproject.MyMatchers"); System.err.println(""); System.err.println(" output-dir : Where to output generated code (package subdirs will be"); System.err.println(" automatically created)."); System.err.println(" e.g. build/generated-code"); System.exit(-1); } String srcDirs = args[0]; String package_name_prefix = args[1]; String parentClassName = args[2]; String fullClassName = args[3]; File outputDir = new File(args[4]); String fileName = fullClassName.replace('.', File.separatorChar) + ".java"; int dotIndex = fullClassName.lastIndexOf("."); String packageName = dotIndex == -1 ? "" : fullClassName.substring(0, dotIndex); String shortClassName = fullClassName.substring(dotIndex + 1); if (!outputDir.isDirectory()) { System.err.println("Output directory not found : " + outputDir.getAbsolutePath()); System.exit(-1); } Class<?> parentClass = Class.forName(parentClassName); File outputFile = new File(outputDir, fileName); outputFile.getParentFile().mkdirs(); File tmpFile = new File(outputDir, fileName + ".tmp"); SugarGenerator sugarGenerator = new SugarGenerator(); try { sugarGenerator .addWriter(new SeleniumFactoryWriter(packageName, shortClassName, new FileWriter(tmpFile))); sugarGenerator.addWriter(new QuickReferenceWriter(System.out)); PackageScanningGenerator pkgScanningGenerator = new PackageScanningGenerator(sugarGenerator, PackageScanningGenerator.class.getClassLoader(), parentClass); if (srcDirs.trim().length() > 0) { for (String srcDir : srcDirs.split(",")) { pkgScanningGenerator.addSourceDir(new File(srcDir)); } } // could add use of xml just to list filter expressions // pkgScanningGenerator.load(new InputSource(configFile)); pkgScanningGenerator.addClasses(package_name_prefix); System.out.println("Generating " + fullClassName); sugarGenerator.generate(); sugarGenerator.close(); outputFile.delete(); FileUtils.moveFile(tmpFile, outputFile); } finally { tmpFile.delete(); sugarGenerator.close(); } }
From source file:com.ibm.replication.iidr.utils.Bookmarks.java
public static void main(String[] args) throws ConfigurationException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IOException { System.setProperty("log4j.configurationFile", System.getProperty("user.dir") + File.separatorChar + "conf" + File.separatorChar + "log4j2.xml"); LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig("com.ibm.replication.iidr.utils.Bookmarks"); loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers();/*from w w w.j a va 2 s .co m*/ new Bookmarks("EventLogBookmarks.properties"); }
From source file:org.apache.s4.adapter.Adapter.java
public static void main(String args[]) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(// ww w . j a v a2 s . c o m OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); options.addOption(OptionBuilder.withArgName("userconfig").hasArg() .withDescription("user-defined legacy data adapter configuration file").create("d")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } String userConfigFilename = null; if (commandLine.hasOption("d")) { userConfigFilename = commandLine.getOptionValue("d"); } File userConfigFile = new File(userConfigFilename); if (!userConfigFile.isFile()) { System.err.println("Bad user configuration file: " + userConfigFilename); System.exit(1); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = configBase + File.separatorChar + "adapter-conf.xml"; File configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("adapter config file %s does not exist\n", configPath); System.exit(1); } // load adapter config xml ApplicationContext coreContext; coreContext = new FileSystemXmlApplicationContext("file:" + configPath); ApplicationContext context = coreContext; Adapter adapter = (Adapter) context.getBean("adapter"); ApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { "file:" + userConfigFilename }, context); Map listenerBeanMap = appContext.getBeansOfType(EventProducer.class); if (listenerBeanMap.size() == 0) { System.err.println("No user-defined listener beans"); System.exit(1); } EventProducer[] eventListeners = new EventProducer[listenerBeanMap.size()]; int index = 0; for (Iterator it = listenerBeanMap.keySet().iterator(); it.hasNext(); index++) { String beanName = (String) it.next(); System.out.println("Adding producer " + beanName); eventListeners[index] = (EventProducer) listenerBeanMap.get(beanName); } adapter.setEventListeners(eventListeners); }
From source file:io.s4.MainApp.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(//ww w . j a va 2s. co m OptionBuilder.withArgName("appshome").hasArg().withDescription("applications home").create("a")); options.addOption(OptionBuilder.withArgName("s4clock").hasArg().withDescription("s4 clock").create("d")); options.addOption(OptionBuilder.withArgName("seedtime").hasArg() .withDescription("event clock initialization time").create("s")); options.addOption( OptionBuilder.withArgName("extshome").hasArg().withDescription("extensions home").create("e")); options.addOption( OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; String clockType = "wall"; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } if (commandLine.hasOption("a")) { appsHome = commandLine.getOptionValue("a"); } if (commandLine.hasOption("d")) { clockType = commandLine.getOptionValue("d"); } if (commandLine.hasOption("e")) { extsHome = commandLine.getOptionValue("e"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } long seedTime = 0; if (commandLine.hasOption("s")) { seedTime = Long.parseLong(commandLine.getOptionValue("s")); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } File appsHomeFile = new File(appsHome); if (!appsHomeFile.isDirectory()) { System.err.println("Bad applications home: " + appsHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } List loArgs = commandLine.getArgList(); if (loArgs.size() < 1) { // System.err.println("No bean configuration file specified"); // System.exit(1); } // String s4ConfigXml = (String) loArgs.get(0); // System.out.println("s4ConfigXml is " + s4ConfigXml); ClassPathResource propResource = new ClassPathResource("s4-core.properties"); Properties prop = new Properties(); if (propResource.exists()) { prop.load(propResource.getInputStream()); } else { System.err.println("Unable to find s4-core.properties. It must be available in classpath"); System.exit(1); } ApplicationContext coreContext = null; String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = ""; List<String> coreConfigUrls = new ArrayList<String>(); File configFile = null; // load clock configuration configPath = configBase + File.separatorChar + clockType + "-clock.xml"; coreConfigUrls.add(configPath); // load core config xml configPath = configBase + File.separatorChar + "s4-core-conf.xml"; configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("S4 core config file %s does not exist\n", configPath); System.exit(1); } coreConfigUrls.add(configPath); String[] coreConfigFiles = new String[coreConfigUrls.size()]; coreConfigUrls.toArray(coreConfigFiles); String[] coreConfigFileUrls = new String[coreConfigFiles.length]; for (int i = 0; i < coreConfigFiles.length; i++) { coreConfigFileUrls[i] = "file:" + coreConfigFiles[i]; } coreContext = new FileSystemXmlApplicationContext(coreConfigFileUrls, coreContext); ApplicationContext context = coreContext; Clock s4Clock = (Clock) context.getBean("clock"); if (s4Clock instanceof EventClock && seedTime > 0) { EventClock s4EventClock = (EventClock) s4Clock; s4EventClock.updateTime(seedTime); System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime()); } PEContainer peContainer = (PEContainer) context.getBean("peContainer"); Watcher w = (Watcher) context.getBean("watcher"); w.setConfigFilename(configPath); // load extension modules String[] configFileNames = getModuleConfigFiles(extsHome, prop); if (configFileNames.length > 0) { String[] configFileUrls = new String[configFileNames.length]; for (int i = 0; i < configFileNames.length; i++) { configFileUrls[i] = "file:" + configFileNames[i]; } context = new FileSystemXmlApplicationContext(configFileUrls, context); } // load application modules configFileNames = getModuleConfigFiles(appsHome, prop); if (configFileNames.length > 0) { String[] configFileUrls = new String[configFileNames.length]; for (int i = 0; i < configFileNames.length; i++) { configFileUrls[i] = "file:" + configFileNames[i]; } context = new FileSystemXmlApplicationContext(configFileUrls, context); // attach any beans that implement ProcessingElement to the PE // Container String[] processingElementBeanNames = context.getBeanNamesForType(ProcessingElement.class); for (String processingElementBeanName : processingElementBeanNames) { Object bean = context.getBean(processingElementBeanName); try { Method getS4ClockMethod = bean.getClass().getMethod("getS4Clock"); if (getS4ClockMethod.getReturnType().equals(Clock.class)) { if (getS4ClockMethod.invoke(bean) == null) { Method setS4ClockMethod = bean.getClass().getMethod("setS4Clock", Clock.class); setS4ClockMethod.invoke(bean, coreContext.getBean("clock")); } } } catch (NoSuchMethodException mnfe) { // acceptable } System.out.println("Adding processing element with bean name " + processingElementBeanName + ", id " + ((ProcessingElement) bean).getId()); peContainer.addProcessor((ProcessingElement) bean, processingElementBeanName); } } }
From source file:net.sf.jsignpdf.InstallCert.java
/** * The main - whole logic of Install Cert Tool. * //from w w w.j a va2s. co m * @param args * @throws Exception */ public static void main(String[] args) { String host; int port; char[] passphrase; System.out.println("InstallCert - Install CA certificate to Java Keystore"); System.out.println("====================================================="); final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { if ((args.length == 1) || (args.length == 2)) { String[] c = args[0].split(":"); host = c[0]; port = (c.length == 1) ? 443 : Integer.parseInt(c[1]); String p = (args.length == 1) ? "changeit" : args[1]; passphrase = p.toCharArray(); } else { String tmpStr; do { System.out.print("Enter hostname or IP address: "); tmpStr = StringUtils.defaultIfEmpty(reader.readLine(), null); } while (tmpStr == null); host = tmpStr; System.out.print("Enter port number [443]: "); tmpStr = StringUtils.defaultIfEmpty(reader.readLine(), null); port = tmpStr == null ? 443 : Integer.parseInt(tmpStr); System.out.print("Enter keystore password [changeit]: "); tmpStr = reader.readLine(); String p = "".equals(tmpStr) ? "changeit" : tmpStr; passphrase = p.toCharArray(); } char SEP = File.separatorChar; final File dir = new File(System.getProperty("java.home") + SEP + "lib" + SEP + "security"); final File file = new File(dir, "cacerts"); System.out.println("Loading KeyStore " + file + "..."); InputStream in = new FileInputStream(file); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(in, passphrase); in.close(); SSLContext context = SSLContext.getInstance("TLS"); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(ks); X509TrustManager defaultTrustManager = (X509TrustManager) tmf.getTrustManagers()[0]; SavingTrustManager tm = new SavingTrustManager(defaultTrustManager); context.init(null, new TrustManager[] { tm }, null); SSLSocketFactory factory = context.getSocketFactory(); System.out.println("Opening connection to " + host + ":" + port + "..."); SSLSocket socket = (SSLSocket) factory.createSocket(host, port); socket.setSoTimeout(10000); try { System.out.println("Starting SSL handshake..."); socket.startHandshake(); socket.close(); System.out.println(); System.out.println("No errors, certificate is already trusted"); } catch (SSLException e) { System.out.println(); System.out.println("Certificate is not yet trusted."); // e.printStackTrace(System.out); } X509Certificate[] chain = tm.chain; if (chain == null) { System.out.println("Could not obtain server certificate chain"); return; } System.out.println(); System.out.println("Server sent " + chain.length + " certificate(s):"); System.out.println(); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); MessageDigest md5 = MessageDigest.getInstance("MD5"); for (int i = 0; i < chain.length; i++) { X509Certificate cert = chain[i]; System.out.println(" " + (i + 1) + " Subject " + cert.getSubjectDN()); System.out.println(" Issuer " + cert.getIssuerDN()); sha1.update(cert.getEncoded()); System.out.println(" sha1 " + toHexString(sha1.digest())); md5.update(cert.getEncoded()); System.out.println(" md5 " + toHexString(md5.digest())); System.out.println(); } System.out.print("Enter certificate to add to trusted keystore or 'q' to quit [1]: "); String line = reader.readLine().trim(); int k = -1; try { k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1; } catch (NumberFormatException e) { } if (k < 0 || k >= chain.length) { System.out.println("KeyStore not changed"); } else { try { System.out.println("Creating keystore backup"); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); final File backupFile = new File(dir, CACERTS_KEYSTORE + "." + dateFormat.format(new java.util.Date())); final FileInputStream fis = new FileInputStream(file); final FileOutputStream fos = new FileOutputStream(backupFile); IOUtils.copy(fis, fos); fis.close(); fos.close(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Installing certificate..."); X509Certificate cert = chain[k]; String alias = host + "-" + (k + 1); ks.setCertificateEntry(alias, cert); OutputStream out = new FileOutputStream(file); ks.store(out, passphrase); out.close(); System.out.println(); System.out.println(cert); System.out.println(); System.out.println("Added certificate to keystore '" + file + "' using alias '" + alias + "'"); } } catch (Exception e) { System.out.println(); System.out.println("----------------------------------------------"); System.out.println("Problem occured during installing certificate:"); e.printStackTrace(); System.out.println("----------------------------------------------"); } System.out.println("Press Enter to finish..."); try { reader.readLine(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.apache.s4.MainApp.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(/*from www .j a v a 2 s . co m*/ OptionBuilder.withArgName("appshome").hasArg().withDescription("applications home").create("a")); options.addOption(OptionBuilder.withArgName("s4clock").hasArg().withDescription("s4 clock").create("d")); options.addOption(OptionBuilder.withArgName("seedtime").hasArg() .withDescription("event clock initialization time").create("s")); options.addOption( OptionBuilder.withArgName("extshome").hasArg().withDescription("extensions home").create("e")); options.addOption( OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; String clockType = "wall"; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } if (commandLine.hasOption("a")) { appsHome = commandLine.getOptionValue("a"); } if (commandLine.hasOption("d")) { clockType = commandLine.getOptionValue("d"); } if (commandLine.hasOption("e")) { extsHome = commandLine.getOptionValue("e"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } long seedTime = 0; if (commandLine.hasOption("s")) { seedTime = Long.parseLong(commandLine.getOptionValue("s")); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } File appsHomeFile = new File(appsHome); if (!appsHomeFile.isDirectory()) { System.err.println("Bad applications home: " + appsHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } List loArgs = commandLine.getArgList(); if (loArgs.size() < 1) { // System.err.println("No bean configuration file specified"); // System.exit(1); } // String s4ConfigXml = (String) loArgs.get(0); // System.out.println("s4ConfigXml is " + s4ConfigXml); ClassPathResource propResource = new ClassPathResource("s4-core.properties"); Properties prop = new Properties(); if (propResource.exists()) { prop.load(propResource.getInputStream()); } else { System.err.println("Unable to find s4-core.properties. It must be available in classpath"); System.exit(1); } ApplicationContext coreContext = null; String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = ""; List<String> coreConfigUrls = new ArrayList<String>(); File configFile = null; // load clock configuration configPath = configBase + File.separatorChar + clockType + "-clock.xml"; coreConfigUrls.add(configPath); // load core config xml configPath = configBase + File.separatorChar + "s4-core-conf.xml"; configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("S4 core config file %s does not exist\n", configPath); System.exit(1); } coreConfigUrls.add(configPath); String[] coreConfigFiles = new String[coreConfigUrls.size()]; coreConfigUrls.toArray(coreConfigFiles); String[] coreConfigFileUrls = new String[coreConfigFiles.length]; for (int i = 0; i < coreConfigFiles.length; i++) { coreConfigFileUrls[i] = "file:" + coreConfigFiles[i]; } coreContext = new FileSystemXmlApplicationContext(coreConfigFileUrls, coreContext); ApplicationContext context = coreContext; Clock clock = (Clock) context.getBean("clock"); if (clock instanceof EventClock && seedTime > 0) { EventClock s4EventClock = (EventClock) clock; s4EventClock.updateTime(seedTime); System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime()); } PEContainer peContainer = (PEContainer) context.getBean("peContainer"); Watcher w = (Watcher) context.getBean("watcher"); w.setConfigFilename(configPath); // load extension modules String[] configFileNames = getModuleConfigFiles(extsHome, prop); if (configFileNames.length > 0) { String[] configFileUrls = new String[configFileNames.length]; for (int i = 0; i < configFileNames.length; i++) { configFileUrls[i] = "file:" + configFileNames[i]; } context = new FileSystemXmlApplicationContext(configFileUrls, context); } // load application modules configFileNames = getModuleConfigFiles(appsHome, prop); if (configFileNames.length > 0) { String[] configFileUrls = new String[configFileNames.length]; for (int i = 0; i < configFileNames.length; i++) { configFileUrls[i] = "file:" + configFileNames[i]; } context = new FileSystemXmlApplicationContext(configFileUrls, context); // attach any beans that implement ProcessingElement to the PE // Container String[] processingElementBeanNames = context.getBeanNamesForType(AbstractPE.class); for (String processingElementBeanName : processingElementBeanNames) { AbstractPE bean = (AbstractPE) context.getBean(processingElementBeanName); bean.setClock(clock); try { bean.setSafeKeeper((SafeKeeper) context.getBean("safeKeeper")); } catch (NoSuchBeanDefinitionException ignored) { // no safe keeper = no checkpointing / recovery } // if the application did not specify an id, use the Spring bean name if (bean.getId() == null) { bean.setId(processingElementBeanName); } System.out.println("Adding processing element with bean name " + processingElementBeanName + ", id " + ((AbstractPE) bean).getId()); peContainer.addProcessor((AbstractPE) bean); } } }
From source file:com.ibm.replication.iidr.utils.Settings.java
public static void main(String[] args) throws ConfigurationException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IOException { System.setProperty("log4j.configurationFile", System.getProperty("user.dir") + File.separatorChar + "conf" + File.separatorChar + "log4j2.xml"); LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig("com.ibm.replication.iidr.utils.Settings"); loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers();/* w w w . ja v a2 s .c o m*/ new Settings("CollectCDCStats.properties"); }