protected void initExtensions(ClassLoader extensionClassLoader) { /* We break the general rule that you shouldn't catch Throwable, because we don't want extensions to crash SoapUI. */ try { String extDir = System.getProperty("soapui.ext.listeners"); addExternalListeners( FilenameUtils.normalize( extDir != null ? extDir : root == null ? "listeners" : root + File.separatorChar + "listeners"), extensionClassLoader); } catch (Throwable e) { SoapUI.logError(e, "Couldn't load external listeners"); } try { String factoriesDir = System.getProperty("soapui.ext.factories"); addExternalFactories( FilenameUtils.normalize( factoriesDir != null ? factoriesDir : root == null ? "factories" : root + File.separatorChar + "factories"), extensionClassLoader); } catch (Throwable e) { SoapUI.logError(e, "Couldn't load external factories"); } }
private File findNativeLibrary() { // Resolve the library file name with a suffix (e.g., dll, .so, etc.) String nativeLibraryName = System.mapLibraryName(libName); // Load an OS-dependent native library inside a jar file String nativeLibraryPath = NATIVELIBDIR + "/" + OSInfo.getNativeLibFolderPath(); boolean hasNativeLib = NativeLibLoader.class.getResource(nativeLibraryPath + "/" + nativeLibraryName) != null; if (!hasNativeLib) { if (OSInfo.getOSName().equals("mac")) { // Fix for openjdk7+ for mac String altName = "lib" + libName + ".jnilib"; if (NativeLibLoader.class.getResource(nativeLibraryPath + "/" + altName) != null) { nativeLibraryName = altName; hasNativeLib = true; } } } if (!hasNativeLib) { throw new RuntimeException(); } // Temporary folder for the native lib. final String tempFolder = new File(System.getProperty(TEMPDIR, System.getProperty("java.io.tmpdir"))) .getAbsolutePath(); // Extracts and load a native library inside the jar file return extractLibraryFile(nativeLibraryPath, nativeLibraryName, tempFolder); }
public Config() { // config file name String folder = System.getProperty("user.home"); String os = System.getProperty("os.name"); String filesep = System.getProperty("file.separator"); if (os.indexOf("Windows") >= 0) { configFileName = folder + filesep + "arbaro.cfg"; } else { configFileName = folder + filesep + ".arbarorc"; } // load properties FileInputStream in = null; try { in = new FileInputStream(configFileName); load(in); } catch (java.io.FileNotFoundException e) { in = null; System.err.println( "Can't find config file. Please do setup Arbaro " + "using the setup dialog."); } catch (java.io.IOException e) { System.err.println("I/O Error. Can't read config file!"); } finally { if (in != null) { try { in.close(); } catch (java.io.IOException e) { } in = null; } } }
public static void testNSS(PKCS11Test test) throws Exception { if (!(new File(NSS_BASE)).exists()) return; String libdir = getNSSLibDir(); if (libdir == null) { return; } if (loadNSPR(libdir) == false) { return; } String libfile = libdir + System.mapLibraryName("softokn3"); String customDBdir = System.getProperty("CUSTOM_DB_DIR"); String dbdir = (customDBdir != null) ? customDBdir : NSS_BASE + SEP + "db"; // NSS always wants forward slashes for the config path dbdir = dbdir.replace('\\', '/'); String customConfig = System.getProperty("CUSTOM_P11_CONFIG"); String customConfigName = System.getProperty("CUSTOM_P11_CONFIG_NAME", "p11-nss.txt"); String p11config = (customConfig != null) ? customConfig : NSS_BASE + SEP + customConfigName; System.setProperty("pkcs11test.nss.lib", libfile); System.setProperty("pkcs11test.nss.db", dbdir); Provider p = getSunPKCS11(p11config); test.premain(p); }
// package-level visibility for testing purposes (just usage/errors at this stage) // TODO: should we have an 'err' printstream too for ParseException? static void processArgs(String[] args, final PrintStream out) { Options options = buildOptions(); try { CommandLine cmd = parseCommandLine(options, args); if (cmd.hasOption('h')) { printHelp(out, options); } else if (cmd.hasOption('v')) { String version = GroovySystem.getVersion(); out.println( "Groovy Version: " + version + " JVM: " + System.getProperty("java.version") + " Vendor: " + System.getProperty("java.vm.vendor") + " OS: " + System.getProperty("os.name")); } else { // If we fail, then exit with an error so scripting frameworks can catch it // TODO: pass printstream(s) down through process if (!process(cmd)) { System.exit(1); } } } catch (ParseException pe) { out.println("error: " + pe.getMessage()); printHelp(out, options); } }
/** Creates new form Eleminator */ public Eleminator() { getContentPane().add(MTP, BorderLayout.CENTER); try { String nativeLook = UIManager.getSystemLookAndFeelClassName(); UIManager.setLookAndFeel(nativeLook); SwingUtilities.updateComponentTreeUI(this); } catch (Exception e) { } try { File custDir = new File(System.getProperty("user.home") + "/" + "WorkSpace.dat"); ObjectInputStream In = new ObjectInputStream(new FileInputStream(custDir)); workingDirectory = new File(((WorkSpace) In.readObject()).getWorkSpace()); } catch (Exception ex) { workingDirectory = new File(System.getProperty("user.home")); } initComponents(); LookAndFeelInfo[] li = UIManager.getInstalledLookAndFeels(); for (int i = 0; li.length > i; i++) { // For more themes themeComboBox.addItem(new ThemeItem(li[i].getName(), li[i].getClassName())); } setBounds(0, 0, 640, 480); setTitle("eLEMinator"); URL imageURL = getClass().getClassLoader().getResource("verifier/lem.jpg"); Image lem = Toolkit.getDefaultToolkit().getImage(imageURL); setIconImage(lem); }
/** * This method will read the standard input and save the content to a temporary. source file since * the source file will be parsed mutiple times. The HTML source file is parsed and checked for * Charset in HTML tags at first time, then source file is parsed again for the converting The * temporary file is read from standard input and saved in current directory and will be deleted * after the conversion has completed. * * @return the vector of the converted temporary source file name */ public Vector getStandardInput() throws FileAccessException { byte[] buf = new byte[2048]; int len = 0; FileInputStream fis = null; FileOutputStream fos = null; File tempSourceFile; String tmpSourceName = ".tmpSource_stdin"; File outFile = new File(tmpSourceName); tempSourceFile = new File(System.getProperty("user.dir") + sep + tmpSourceName); if (!tempSourceFile.exists()) { try { fis = new FileInputStream(FileDescriptor.in); fos = new FileOutputStream(outFile); while ((len = fis.read(buf, 0, 2048)) != -1) fos.write(buf, 0, len); } catch (IOException e) { System.out.println(ResourceHandler.getMessage("plugin_converter.write_permission")); return null; } } else { throw new FileAccessException(ResourceHandler.getMessage("plugin_converter.overwrite")); } tempSourceFile = new File(System.getProperty("user.dir") + sep + tmpSourceName); if (tempSourceFile.exists()) { fileSpecs.add(tmpSourceName); return fileSpecs; } else { throw new FileAccessException( ResourceHandler.getMessage("plugin_converter.write_permission")); } }
void test(String[] opts, String className) throws Exception { count++; System.err.println("Test " + count + " " + Arrays.asList(opts) + " " + className); Path testSrcDir = Paths.get(System.getProperty("test.src")); Path testClassesDir = Paths.get(System.getProperty("test.classes")); Path classes = Paths.get("classes." + count); classes.createDirectory(); Context ctx = new Context(); PathFileManager fm = new JavacPathFileManager(ctx, true, null); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); List<String> options = new ArrayList<String>(); options.addAll(Arrays.asList(opts)); options.addAll(Arrays.asList("-verbose", "-XDverboseCompilePolicy", "-d", classes.toString())); Iterable<? extends JavaFileObject> compilationUnits = fm.getJavaFileObjects(testSrcDir.resolve(className + ".java")); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); JavaCompiler.CompilationTask t = compiler.getTask(out, fm, null, options, null, compilationUnits); boolean ok = t.call(); System.err.println(sw.toString()); if (!ok) { throw new Exception("compilation failed"); } File expect = new File("classes." + count + "/" + className + ".class"); if (!expect.exists()) throw new Exception("expected file not found: " + expect); long expectedSize = new File(testClassesDir.toString(), className + ".class").length(); long actualSize = expect.length(); if (expectedSize != actualSize) throw new Exception("wrong size found: " + actualSize + "; expected: " + expectedSize); }
public static void main(String... args) throws Exception { jtreg = (System.getProperty("test.src") != null); File tmpDir; if (jtreg) { // use standard jtreg scratch directory: the current directory tmpDir = new File(System.getProperty("user.dir")); } else { tmpDir = new File( System.getProperty("java.io.tmpdir"), MessageInfo.class.getName() + (new SimpleDateFormat("yyMMddHHmmss")).format(new Date())); } Example.setTempDir(tmpDir); Example.Compiler.factory = new ArgTypeCompilerFactory(); MessageInfo mi = new MessageInfo(); try { if (mi.run(args)) return; } finally { /* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the * jtreg scratch directory, which is the current directory. * In case someone is faking jtreg mode, make sure to only * clean tmpDir when it is reasonable to do so. */ if (tmpDir.isDirectory() && tmpDir.getName().startsWith(MessageInfo.class.getName())) { if (clean(tmpDir)) tmpDir.delete(); } } if (jtreg) throw new Exception(mi.errors + " errors occurred"); else System.exit(1); }
public TestInput( Iterable<? extends JavaFileObject> files, Iterable<String> processors, String[] options) { this.compiler = ToolProvider.getSystemJavaCompiler(); this.fileManager = compiler.getStandardFileManager(null, null, null); this.files = files; this.processors = processors; this.options = new LinkedList<String>(); String classpath = System.getProperty("tests.classpath", "tests" + File.separator + "build"); String globalclasspath = System.getProperty("java.class.path", ""); this.options.add("-Xmaxerrs"); this.options.add("9999"); this.options.add("-g"); this.options.add("-d"); this.options.add(OUTDIR); this.options.add("-classpath"); this.options.add( "build" + File.pathSeparator + "junit.jar" + File.pathSeparator + classpath + File.pathSeparator + globalclasspath); this.options.addAll(Arrays.asList(options)); }
private String parseLibrary(String keyword) throws IOException { checkDup(keyword); parseEquals(); String lib = parseLine(); lib = expand(lib); int i = lib.indexOf("/$ISA/"); if (i != -1) { // replace "/$ISA/" with "/sparcv9/" on 64-bit Solaris SPARC // and with "/amd64/" on Solaris AMD64. // On all other platforms, just turn it into a "/" String osName = System.getProperty("os.name", ""); String osArch = System.getProperty("os.arch", ""); String prefix = lib.substring(0, i); String suffix = lib.substring(i + 5); if (osName.equals("SunOS") && osArch.equals("sparcv9")) { lib = prefix + "/sparcv9" + suffix; } else if (osName.equals("SunOS") && osArch.equals("amd64")) { lib = prefix + "/amd64" + suffix; } else { lib = prefix + suffix; } } debug(keyword + ": " + lib); // Check to see if full path is specified to prevent the DLL // preloading attack if (!(new File(lib)).isAbsolute()) { throw new ConfigurationException("Absolute path required for library value: " + lib); } return lib; }
static { if (Util.checkForWindows()) { TMPFILE_NAME = System.getProperty("java.io.tmpdir") + "\\" + "tmp.txt"; } else { TMPFILE_NAME = System.getProperty("java.io.tmpdir") + "/" + "tmp.txt"; } }
public void openProfiles_old() { String saltData = ""; try { if (System.getProperty("saltData") != null) { saltData = System.getProperty("saltData"); } StringTokenizer fileTokens = new StringTokenizer(saltData, ","); while (fileTokens.hasMoreElements()) { String file = fileTokens.nextToken(); if (file != null && !file.equals("null") && !file.equals("")) { System.out.println("Built tab from list" + file); buildProfileTab(file); } } saltData = ""; } catch (Exception e) { System.out.println("Failed to open files "); } // just incase it was a signle node if (saltData != null && !saltData.equals("null") && !saltData.equals("")) { System.out.println("Built tab from single " + saltData); buildProfileTab(saltData); } System.setProperty("saltData", ""); }
public static void main(String... args) throws Throwable { String testSrcDir = System.getProperty("test.src"); String testClassDir = System.getProperty("test.classes"); String self = T6361619.class.getName(); JavacTool tool = JavacTool.create(); final PrintWriter out = new PrintWriter(System.err, true); Iterable<String> flags = Arrays.asList( "-processorpath", testClassDir, "-processor", self, "-d", "."); DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() { public void report(Diagnostic<? extends JavaFileObject> m) { out.println(m); } }; StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); Iterable<? extends JavaFileObject> f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); JavacTask task = tool.getTask(out, fm, dl, flags, null, f); MyTaskListener tl = new MyTaskListener(task); task.setTaskListener(tl); // should complete, without exceptions task.call(); }
public ArrayList parseData(String propName) { ArrayList<String> files = new ArrayList(); String saltData = ""; try { if (System.getProperty(propName) != null) { saltData = System.getProperty(propName); } StringTokenizer fileTokens = new StringTokenizer(saltData, ","); while (fileTokens.hasMoreElements()) { String file = fileTokens.nextToken(); if (file != null && !file.equals("null") && !file.equals("")) { System.out.println("Built tab from list" + file); files.add(file); } } saltData = ""; } catch (Exception e) { System.out.println("Failed to open files "); } // just incase it was a signle node if (saltData != null && !saltData.equals("null") && !saltData.equals("")) { System.out.println("Built tab from single " + saltData); files.add(saltData); } System.setProperty(propName, ""); return files; }
/** * Returns JPicEdt's install directory w/o trailing "/", provided the command line looks like : * * <p><code>java -classpath other-class-paths:jpicedt-install-dir/lib/jpicedt.jar jpicedt.JPicEdt * </code> (where <code>/</code> may be replaced by the actual respective separator for files on * the underlying platform). * * <p>For Windows platform, the install directory is tried to be detected 1st with the MSWindows * file-separator (<code>\</code>), and if this does not work, a subsequent trial is made with * <code>/</code>. * * <p>That is, the old way (java -jar jpicedt.jar) won't work. However, classpath can contain * relative pathname (then user.dir get prepended). * * <p>Code snippet was adapted from jEdit/JEdit.java (http://www.jedit.org). * * @return the value of the "user.dir" Java property if "lib/jpicedt.jar" wasn't found in the * command line. */ public static String getJPicEdtHome() { String classpath = System.getProperty("java.class.path"); // e.g. // "/usr/lib/java/jre/lib/rt.jar:/home/me/jpicedt/1.3.2/lib/jpicedt.jar" // File.separator = "/" on Unix, "\\" on Windows,... String fileSeparator = File.separator; int index; // File.pathSeparator = ":" on Unix/MacOS-X platforms, ";" on Windows // search ":" backward starting from // "/usr/lib/java/jre/lib/rt.jar:/home/me/jpicedt/1.3.2/^lib/jpicedt.jar" String homeDir = null; int trials = 2; do { index = classpath.toLowerCase().indexOf("lib" + fileSeparator + "jpicedt.jar"); int start = classpath.lastIndexOf(File.pathSeparator, index); if (start == -1) start = 0; // File.pathSeparator not found => lib/jpicedt.jar probably at beginning of classpath else start += File.pathSeparator.length(); // e.g. ":^/home..." if (index >= start) { homeDir = classpath.substring(start, index); if (homeDir.endsWith(fileSeparator)) homeDir = homeDir.substring(0, homeDir.length() - 1); } switch (trials) { case 2: if (File.pathSeparator.equals(";") && homeDir == null) { // MS-Windows case, this must work both with / and \ trials = 1; fileSeparator = "/"; } else trials = 0; break; case 1: if (homeDir != null && !fileSeparator.equals(File.separator)) { homeDir.replace(fileSeparator, File.separator); } trials = 0; break; default: trials = 0; break; } } while (trials != 0); if (homeDir != null) { if (homeDir.equals("")) homeDir = System.getProperty("user.dir"); else if (!new File(homeDir).isAbsolute()) homeDir = System.getProperty("user.dir") + File.separator + homeDir; } else { homeDir = System.getProperty("user.dir"); if (homeDir.endsWith( "lib")) // this is the case if jpicedt run as "java -jar jpicedt.jar" from inside lib/ dir homeDir = homeDir.substring(0, homeDir.lastIndexOf("lib")); } // System.out.println("JPicEdt's home = " + homeDir); return homeDir; }
/** * Constructor. * * @param rq request * @param rs response * @throws IOException I/O exception */ public HTTPContext(final HttpServletRequest rq, final HttpServletResponse rs) throws IOException { req = rq; res = rs; final String m = rq.getMethod(); method = HTTPMethod.get(m); final StringBuilder uri = new StringBuilder(req.getRequestURL()); final String qs = req.getQueryString(); if (qs != null) uri.append('?').append(qs); log(false, m, uri); // set UTF8 as default encoding (can be overwritten) res.setCharacterEncoding(UTF8); segments = toSegments(req.getPathInfo()); path = join(0); user = System.getProperty(DBUSER); pass = System.getProperty(DBPASS); // set session-specific credentials final String auth = req.getHeader(AUTHORIZATION); if (auth != null) { final String[] values = auth.split(" "); if (values[0].equals(BASIC)) { final String[] cred = Base64.decode(values[1]).split(":", 2); if (cred.length != 2) throw new LoginException(NOPASSWD); user = cred[0]; pass = cred[1]; } else { throw new LoginException(WHICHAUTH, values[0]); } } }
@Before public void dbInit() throws Exception { String configFileName = System.getProperty("user.home"); if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) { configFileName += "/.pokerth/config.xml"; } else { configFileName += "/AppData/Roaming/pokerth/config.xml"; } File file = new File(configFileName); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); doc.getDocumentElement().normalize(); Element configNode = (Element) doc.getElementsByTagName("Configuration").item(0); Element dbAddressNode = (Element) configNode.getElementsByTagName("DBServerAddress").item(0); String dbAddress = dbAddressNode.getAttribute("value"); Element dbUserNode = (Element) configNode.getElementsByTagName("DBServerUser").item(0); String dbUser = dbUserNode.getAttribute("value"); Element dbPasswordNode = (Element) configNode.getElementsByTagName("DBServerPassword").item(0); String dbPassword = dbPasswordNode.getAttribute("value"); Element dbNameNode = (Element) configNode.getElementsByTagName("DBServerDatabaseName").item(0); String dbName = dbNameNode.getAttribute("value"); final String dbUrl = "jdbc:mysql://" + dbAddress + ":3306/" + dbName; Class.forName("com.mysql.jdbc.Driver").newInstance(); dbConn = DriverManager.getConnection(dbUrl, dbUser, dbPassword); }
/** * Returns a new working directory (in temporary space). Ensures the directory exists. Any * directory levels that had to be created are marked for deletion on exit. * * @return working directory * @exception IOException * @since 2.0 */ public static synchronized File createWorkingDirectory() throws IOException { if (dirRoot == null) { dirRoot = System.getProperty("java.io.tmpdir"); // $NON-NLS-1$ // in Linux, returns '/tmp', we must add '/' if (!dirRoot.endsWith(File.separator)) dirRoot += File.separator; // on Unix/Linux, the temp dir is shared by many users, so we need to ensure // that the top working directory is different for each user if (!Platform.getOS().equals("win32")) { // $NON-NLS-1$ String home = System.getProperty("user.home"); // $NON-NLS-1$ home = Integer.toString(home.hashCode()); dirRoot += home + File.separator; } dirRoot += "eclipse" + File.separator + ".update" + File.separator + Long.toString(tmpseed) + File.separator; // $NON-NLS-1$ //$NON-NLS-2$ } String tmpName = dirRoot + Long.toString(++tmpseed) + File.separator; File tmpDir = new File(tmpName); verifyPath(tmpDir, false); if (!tmpDir.exists()) throw new FileNotFoundException(tmpName); return tmpDir; }
/** * Constructor. The first time an RJavaClassLoader is created, it is cached as the primary loader. * * @param path path of the rJava package * @param libpath lib sub directory of the rJava package */ public RJavaClassLoader(String path, String libpath) { super(new URL[] {}); // respect rJava.debug level String rjd = System.getProperty("rJava.debug"); if (rjd != null && rjd.length() > 0 && !rjd.equals("0")) verbose = true; if (verbose) System.out.println("RJavaClassLoader(\"" + path + "\",\"" + libpath + "\")"); if (primaryLoader == null) { primaryLoader = this; if (verbose) System.out.println(" - primary loader"); } else { if (verbose) System.out.println(" - NOT primrary (this=" + this + ", primary=" + primaryLoader + ")"); } libMap = new HashMap /*<String,UnixFile>*/(); classPath = new Vector /*<UnixFile>*/(); classPath.add(new UnixDirectory(path + "/java")); rJavaPath = path; rJavaLibPath = libpath; /* load the rJava library */ UnixFile so = new UnixFile(rJavaLibPath + "/rJava.so"); if (!so.exists()) so = new UnixFile(rJavaLibPath + "/rJava.dll"); if (so.exists()) libMap.put("rJava", so); /* load the jri library */ UnixFile jri = new UnixFile(path + "/jri/libjri.so"); String rarch = System.getProperty("r.arch"); if (rarch != null && rarch.length() > 0) { UnixFile af = new UnixFile(path + "/jri" + rarch + "/libjri.so"); if (af.exists()) jri = af; else { af = new UnixFile(path + "/jri" + rarch + "/jri.dll"); if (af.exists()) jri = af; } } if (!jri.exists()) jri = new UnixFile(path + "/jri/libjri.jnilib"); if (!jri.exists()) jri = new UnixFile(path + "/jri/jri.dll"); if (jri.exists()) { libMap.put("jri", jri); if (verbose) System.out.println(" - registered JRI: " + jri); } /* if we are the primary loader, make us the context loader so projects that rely on the context loader pick us */ if (primaryLoader == this) Thread.currentThread().setContextClassLoader(this); if (verbose) { System.out.println("RJavaClassLoader initialized.\n\nRegistered libraries:"); for (Iterator entries = libMap.keySet().iterator(); entries.hasNext(); ) { Object key = entries.next(); System.out.println(" " + key + ": '" + libMap.get(key) + "'"); } System.out.println("\nRegistered class paths:"); for (Enumeration e = classPath.elements(); e.hasMoreElements(); ) System.out.println(" '" + e.nextElement() + "'"); System.out.println("\n-- end of class loader report --"); } }
/** * main method * * <p>This uses the system properties: * * <ul> * <li><code>rjava.path</code> : path of the rJava package * <li><code>rjava.lib</code> : lib sub directory of the rJava package * <li><code>main.class</code> : main class to "boot", assumes Main if not specified * <li><code>rjava.class.path</code> : set of paths to populate the initiate the class path * </ul> * * <p>and boots the "main" method of the specified <code>main.class</code>, passing the args down * to the booted class * * <p>This makes sure R and rJava are known by the class loader */ public static void main(String[] args) { String rJavaPath = System.getProperty("rjava.path"); if (rJavaPath == null) { System.err.println("ERROR: rjava.path is not set"); System.exit(2); } String rJavaLib = System.getProperty("rjava.lib"); if (rJavaLib == null) { // it is not really used so far, just for rJava.so, so we can guess rJavaLib = rJavaPath + File.separator + "libs"; } RJavaClassLoader cl = new RJavaClassLoader(u2w(rJavaPath), u2w(rJavaLib)); String mainClass = System.getProperty("main.class"); if (mainClass == null || mainClass.length() < 1) { System.err.println("WARNING: main.class not specified, assuming 'Main'"); mainClass = "Main"; } String classPath = System.getProperty("rjava.class.path"); if (classPath != null) { StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator); while (st.hasMoreTokens()) { String dirname = u2w(st.nextToken()); cl.addClassPath(dirname); } } try { cl.bootClass(mainClass, "main", args); } catch (Exception ex) { System.err.println("ERROR: while running main method: " + ex); ex.printStackTrace(); } }
public void testCreateDir() { System.out.println("testCreateDir"); String fs, dir, path_synarcher, path, path_test_kleinberg; fs = System.getProperty("file.separator"); dir = System.getProperty("user.home") + fs; // creates ~/.synarcher/ path_synarcher = dir + ".synarcher" + fs; path = path_synarcher + "test.txt"; FileWriter.createDir(path); // creates ~/.synarcher/graphviz/ path = path_synarcher + "graphviz" + fs + "test.txt"; FileWriter.createDir(path); // creates ~/.synarcher/test_kleinberg/ path_test_kleinberg = path_synarcher + "test_kleinberg" + fs; path = path_test_kleinberg + "test.txt"; FileWriter.createDir(path); // creates ~/.synarcher/test_kleinberg/en/ path_test_kleinberg = path_synarcher + "test_kleinberg" + fs; path = path_test_kleinberg + "en" + fs + "test.txt"; FileWriter.createDir(path); // creates ~/.synarcher/test_kleinberg/ru/ path_test_kleinberg = path_synarcher + "test_kleinberg" + fs; path = path_test_kleinberg + "ru" + fs + "test.txt"; FileWriter.createDir(path); }
void loadRobot() { // Creates new ClassLoader for whenever the class needs to be reloaded. ClassLoader parentClassLoader = DynamicClassLoader.class.getClassLoader(); DynamicClassLoader newClassLoader = new DynamicClassLoader(parentClassLoader); String classFile = String.format(System.getProperty("user.dir") + "/" + robotName + "Robot.class"); // A new instance is created of the main Robot class in order to start the normal and hear // threads try { Class<? extends SyncRobot> sr = newClassLoader.loadClass(robotName + "Robot", classFile); classFile = String.format( System.getProperty("user.dir") + "/" + robotName + "Robot$" + robotName + "HearThread.class"); newClassLoader.loadClass(robotName + "Robot$" + robotName + "HearThread", classFile); sr.newInstance().StartThreads(); } catch (Exception e) { e.printStackTrace(); System.out.println("Failed to load Robot class"); } }
// Contructor that takes in the usernames of the users public ServerFileIO(String username1, String username2) throws IOException { // Sets the naming convention for the files // The convention is: // <Smaller Username><Larger Username>.txt user1 = username1; user2 = username2; if (username1.compareTo(username2) < 0) file = new File( System.getProperty("user.home") + "\\Server Message Files\\" + username1 + username2 + ".txt"); else if (username1.compareTo(username2) > 0) file = new File( System.getProperty("user.home") + "\\Server Message Files\\" + username2 + username1 + ".txt"); else { throw new IllegalArgumentException("Both usernames are the same"); } file.getParentFile().mkdirs(); file.createNewFile(); output = new PrintWriter(new FileWriter(file, true)); input = new Scanner(file); }
/** * Creates a java process that executes the given main class and waits for the process to * terminate. * * @return a {@link ProcessOutputReader} that can be used to get the exit code and stdout+stderr * of the terminated process. */ public static ProcessOutputReader fg(Class main, String[] vmArgs, String[] mainArgs) throws IOException { File javabindir = new File(System.getProperty("java.home"), "bin"); File javaexe = new File(javabindir, "java"); int bits = Integer.getInteger("sun.arch.data.model", 0).intValue(); String vmKindArg = (bits == 64) ? "-d64" : null; ArrayList argList = new ArrayList(); argList.add(javaexe.getPath()); if (vmKindArg != null) { argList.add(vmKindArg); } // argList.add("-Dgemfire.systemDirectory=" + // GemFireConnectionFactory.getDefaultSystemDirectory()); argList.add("-Djava.class.path=" + System.getProperty("java.class.path")); argList.add("-Djava.library.path=" + System.getProperty("java.library.path")); if (vmArgs != null) { argList.addAll(Arrays.asList(vmArgs)); } argList.add(main.getName()); if (mainArgs != null) { argList.addAll(Arrays.asList(mainArgs)); } String[] cmd = (String[]) argList.toArray(new String[argList.size()]); return new ProcessOutputReader(Runtime.getRuntime().exec(cmd)); }
/** * Returns the path of the installation of the directory server. Note that this method assumes * that this code is being run locally. * * @return the path of the installation of the directory server. */ static String getInstallPathFromClasspath() { String installPath = DirectoryServer.getServerRoot(); if (installPath != null) { return installPath; } /* Get the install path from the Class Path */ final String sep = System.getProperty("path.separator"); final String[] classPaths = System.getProperty("java.class.path").split(sep); String path = getInstallPath(classPaths); if (path != null) { final File f = new File(path).getAbsoluteFile(); final File librariesDir = f.getParentFile(); /* * Do a best effort to avoid having a relative representation (for * instance to avoid having ../../../). */ try { installPath = librariesDir.getParentFile().getCanonicalPath(); } catch (IOException ioe) { // Best effort installPath = librariesDir.getParent(); } } return installPath; }
public DefaultAuthenticator(@NotNull ErrorReceiver receiver, @NotNull File authfile) throws BadCommandLineException { this.errReceiver = receiver; this.proxyUser = System.getProperty("http.proxyUser"); this.proxyPasswd = System.getProperty("http.proxyPassword"); if (authfile != null) { this.authFile = authfile; this.giveError = true; } if (!authFile.exists()) { try { error( new SAXParseException( WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND( authFile.getCanonicalPath(), defaultAuthfile), null)); } catch (IOException e) { error( new SAXParseException( WscompileMessages.WSIMPORT_FAILED_TO_PARSE(authFile, e.getMessage()), null)); } return; } if (!authFile.canRead()) { error( new SAXParseException( "Authorization file: " + authFile + " does not have read permission!", null)); return; } parseAuth(); }
// Creates a new thread, runs the program in that thread, and reports any errors as needed. private void run(String clazz) { try { // Makes sure the JVM resets if it's already running. if (JVMrunning) kill(); // Some String constants for java path and OS-specific separators. String separator = System.getProperty("file.separator"); String path = System.getProperty("java.home") + separator + "bin" + separator + "java"; // Tries to run compiled code. ProcessBuilder builder = new ProcessBuilder(path, clazz); // Should be good now! Everything past this is on you. Don't mess it up. println( "Build succeeded on " + java.util.Calendar.getInstance().getTime().toString(), progErr); println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", progErr); JVM = builder.start(); // Note that as of right now, there is no support for input. Only output. Reader errorReader = new InputStreamReader(JVM.getErrorStream()); Reader outReader = new InputStreamReader(JVM.getInputStream()); // Writer inReader = new OutputStreamWriter(JVM.getOutputStream()); redirectErr = redirectIOStream(errorReader, err); redirectOut = redirectIOStream(outReader, out); // redirectIn = redirectIOStream(null, inReader); } catch (Exception e) { // This catches any other errors we might get. println("Some error thrown", progErr); logError(e.toString()); displayLog(); return; } }
public String getInfo() { return version() + System.getProperty("os.name") + " " + System.getProperty("os.version") + "; " + IJ.freeMemory(); }
public static String getSystemTempDir() { String tmp = System.getProperty("java.io.tmpdir"); String sep = System.getProperty("file.separator"); if (tmp.endsWith(sep)) { return tmp; } return tmp + sep; }