public static void main(String[] args) throws Exception { String className; BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); while ((className = stdIn.readLine()) != null) { ProcessOneClass(className); } }
/** * Gets the DTD for the specified doctype file name. * * @param doctype the doctype file name (e.g., "osp10.dtd") * @return the DTD as a string */ public static String getDTD(String doctype) { if (dtdName != doctype) { // set to defaults in case doctype is not found dtdName = defaultName; try { String dtdPath = "/org/opensourcephysics/resources/controls/doctypes/"; // $NON-NLS-1$ java.net.URL url = XML.class.getResource(dtdPath + doctype); if (url == null) { return dtd; } Object content = url.getContent(); if (content instanceof InputStream) { BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) content)); StringBuffer buffer = new StringBuffer(0); String line; while ((line = reader.readLine()) != null) { buffer.append(line + NEW_LINE); } dtd = buffer.toString(); dtdName = doctype; } } catch (IOException ex) { ex.printStackTrace(); } } return dtd; }
/** * Test that <code>Clob.getCharacterStream(long,long)</code> works on CLOBs that are streamed from * store. (DERBY-2891) */ public void testGetCharacterStreamLongOnLargeClob() throws Exception { getConnection().setAutoCommit(false); // create large (>32k) clob that can be read from store final int size = 33000; StringBuilder sb = new StringBuilder(size); for (int i = 0; i < size; i += 10) { sb.append("1234567890"); } final int id = BlobClobTestSetup.getID(); PreparedStatement ps = prepareStatement("insert into blobclob(id, clobdata) values (?,cast(? as clob))"); ps.setInt(1, id); ps.setString(2, sb.toString()); ps.executeUpdate(); ps.close(); Statement s = createStatement(); ResultSet rs = s.executeQuery("select clobdata from blobclob where id = " + id); assertTrue(rs.next()); Clob c = rs.getClob(1); // request a small region of the clob BufferedReader r = new BufferedReader(c.getCharacterStream(4L, 3L)); assertEquals("456", r.readLine()); r.close(); c.free(); rs.close(); s.close(); rollback(); }
private String readUpdateStatus(File statusFile) { String status = ""; try { BufferedReader reader = new BufferedReader(new FileReader(statusFile)); status = reader.readLine(); reader.close(); } catch (Exception e) { Log.i(LOG_FILE_NAME, "error reading update status", e); } return status; }
void removeFiles() throws IOException { BufferedReader reader = new BufferedReader(new FileReader(new File(sGREDir, "removed-files"))); try { for (String removedFileName = reader.readLine(); removedFileName != null; removedFileName = reader.readLine()) { File removedFile = new File(sGREDir, removedFileName); if (removedFile.exists()) removedFile.delete(); } } finally { reader.close(); } }
/** Execute the system command 'cmd' and fill an ArrayList with the results. */ public static ArrayList<String> executeSystemCommand(String cmd) { if (debug) System.out.println("cmd: " + cmd); ArrayList<String> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader( new InputStreamReader(RUNTIME.exec(/*comSpec +*/ cmd).getInputStream()))) { for (String line = null; (line = br.readLine()) != null; ) { if (debug) System.out.println(line); list.add(line); } } catch (IOException e) { e.printStackTrace(); } return list; }
public static String ping(String address) { String reply = "Request timed out"; try (BufferedReader br = new BufferedReader( new InputStreamReader(RUNTIME.exec("ping " + address).getInputStream()))) { for (String line = null; (line = br.readLine()) != null; ) { if (line.trim().startsWith("Reply ")) { reply = line; break; } } } catch (IOException e) { e.printStackTrace(); } return reply; }
String openUrlAsString(String address, int maxLines) { StringBuffer sb; try { URL url = new URL(address); InputStream in = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); sb = new StringBuffer(); int count = 0; String line; while ((line = br.readLine()) != null && count++ < maxLines) sb.append(line + "\n"); in.close(); } catch (IOException e) { sb = null; } return sb != null ? new String(sb) : null; }
public Configuration(File file, String string) throws IOException { if (file.exists()) { BufferedReader in = new BufferedReader(new FileReader(file)); while (true) { String line = in.readLine(); if (line == null) { break; } line = line.trim(); if (line.startsWith(COMMENT)) { continue; } applyString(line); } } applyString(string); seal(); }
private CIJob getJob(ApplicationInfo appInfo) throws PhrescoException { Gson gson = new Gson(); try { BufferedReader br = new BufferedReader(new FileReader(getCIJobPath(appInfo))); CIJob job = gson.fromJson(br, CIJob.class); br.close(); return job; } catch (FileNotFoundException e) { S_LOGGER.debug(e.getLocalizedMessage()); return null; } catch (com.google.gson.JsonParseException e) { S_LOGGER.debug("it is already adpted project !!!!! " + e.getLocalizedMessage()); return null; } catch (IOException e) { S_LOGGER.debug(e.getLocalizedMessage()); return null; } }
public static Properties getEnvironmentVariables() { synchronized (cygstartPath) { if (envVars != null) return envVars; envVars = new Properties(); try (BufferedReader br = new BufferedReader( new InputStreamReader(RUNTIME.exec(comSpec + "env").getInputStream()))) { for (String line = null; (line = br.readLine()) != null; ) { // if (debug) System.out.println("getEnvironmentVariables(): line=" + line); int idx = line.indexOf('='); if (idx > 0) envVars.put(line.substring(0, idx), line.substring(idx + 1)); } } catch (IOException e) { e.printStackTrace(); } return envVars; } }
String[] openUrlAsList(String address) { Vector v = new Vector(); try { URL url = new URL(address); InputStream in = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; while (true) { line = br.readLine(); if (line == null) break; if (!line.equals("")) v.addElement(line); } br.close(); } catch (Exception e) { } String[] lines = new String[v.size()]; v.copyInto((String[]) lines); return lines; }
public List<CIJob> getJobs(ApplicationInfo appInfo) throws PhrescoException { S_LOGGER.debug("GetJobs Called!"); try { boolean adaptedProject = adaptExistingJobs(appInfo); S_LOGGER.debug("Project adapted for new feature => " + adaptedProject); Gson gson = new Gson(); BufferedReader br = new BufferedReader(new FileReader(getCIJobPath(appInfo))); Type type = new TypeToken<List<CIJob>>() {}.getType(); List<CIJob> jobs = gson.fromJson(br, type); br.close(); return jobs; } catch (FileNotFoundException e) { S_LOGGER.debug("FileNotFoundException"); return null; } catch (IOException e) { S_LOGGER.debug("IOException"); throw new PhrescoException(e); } }
private void handleRequest() throws IOException { String line = in.readLine(); if (line == null || line.length() == 0) { Log.warn(Thread.currentThread().getName() + ": ignoring empty request."); return; } if (handleCommand(line, out) == false) { out.println( Thread.currentThread().getName() + ": didn't understand request \"" + line + "\"."); } }
public static void main(String[] args) throws IOException { Card card = new Card(Card.DIAMOND, Card.ACE); reflect(card); // Create object using reflection // Class name is specified in a document(test.txt) FileInputStream fis = new FileInputStream("test.txt"); InputStreamReader reader = new InputStreamReader(fis, "utf8"); BufferedReader br = new BufferedReader(reader); String filename = br.readLine(); Object obj = create(filename); print("Object created: " + obj); // Get field value Object p1 = new Pipe(20, "Rubber"); print("length by getFieldValue: " + getFieldValue("length", p1)); print("type by getFieldValue: " + getFieldValue("type", p1)); // Call method // If parameters required, type: new Class[0], // value: new Object[0] call("repair", p1, new Class[0], new Object[0]); call("repair", p1, new Class[] {int.class, String.class}, new Object[] {11, "Metal"}); }
public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int num = Integer.parseInt(br.readLine().trim()); Object o; // Solution starts here if (num < 1 || num > Math.pow(2, 30)) throw new Exception(); Solution ob = new Solution(); Class<?> c = Class.forName("Solution$Private"); Constructor<?> constructor = c.getDeclaredConstructor(Solution.class); constructor.setAccessible(true); o = constructor.newInstance(ob); Method m = c.getDeclaredMethod("powerof2", new Class[] {int.class}); m.setAccessible(true); String ans = (String) m.invoke(o, num); System.out.println(num + " is " + ans); // ends here System.out.println( "An instance of class: " + o.getClass().getSimpleName() + " has been created"); } // end of main
public void run() { System.out.println("starting " + threadname + " run method on port " + SudokuServer.PORT); System.out.flush(); try { Socket sock = new Socket(hostname, SudokuServer.PORT); PrintWriter dos = new PrintWriter(sock.getOutputStream()); BufferedReader dis = new BufferedReader(new InputStreamReader(sock.getInputStream())); dos.println(testcase); dos.flush(); String response = dis.readLine(); System.out.println( "Client " + threadname + " sent: " + testcase + " received response:" + response); dos.close(); dis.close(); synchronized (sc) { sc.result = response; } } catch (Exception e) { e.printStackTrace(); } System.out.println("finishing " + threadname + " run method"); }
/** * Returns the next non-comment, non-whitespace line of the input buffer. * * @param input the input buffer * @return the next non-comment, non-whitespace line of the input buffer or null if the end of the * buffer is reached before such a line can be found */ static /*@Nullable*/ String getNextRealLine(BufferedReader input) { String currentLine = ""; try { while (currentLine != null) { currentLine = input.readLine(); if (currentLine != null && !isComment(currentLine) && !isWhitespace(currentLine)) return currentLine; } } catch (IOException e) { throw new RuntimeException(e.toString()); } return null; }
private boolean authenticateClient() throws IOException { String line = in.readLine(); if (line == null || line.equals(secret) == false) { Log.warn( Thread.currentThread().getName() + ": failed authentication attempt with \"" + line + "\"."); out.println("Authentication failed"); return false; } writeNewSecret(); out.println("Authentication OK"); return true; }
private void handleClient() { try { this.in = new BufferedReader(new InputStreamReader(client.getInputStream())); this.out = new PrintWriter(new OutputStreamWriter(client.getOutputStream())); if (authenticateClient()) { handleRequest(); } out.flush(); out.close(); in.close(); } catch (Exception ex) { Log.warn(Thread.currentThread().getName() + ": failure handling client request.", ex); } finally { closeClientSocket(); } }
protected void getDimensionsFromLogFile(BufferedReader reader, PicText text) { if (reader == null) { return; } String line = ""; // il rale si j'initialise pas ... boolean finished = false; while (!finished) { try { line = reader.readLine(); } catch (IOException ioex) { ioex.printStackTrace(); return; } if (line == null) { System.out.println("Size of text not found in log file..."); return; } System.out.println(line); Matcher matcher = LogFilePattern.matcher(line); if (line != null && matcher.find()) { System.out.println("FOUND :" + line); finished = true; try { text.setDimensions( 0.3515 * Double.parseDouble(matcher.group(1)), // height, pt->mm (1pt=0.3515 mm) 0.3515 * Double.parseDouble(matcher.group(2)), // width 0.3515 * Double.parseDouble(matcher.group(3))); // depth areDimensionsComputed = true; } catch (NumberFormatException e) { System.out.println("Logfile number format problem: $line" + e.getMessage()); } catch (IndexOutOfBoundsException e) { System.out.println("Logfile regexp problem: $line" + e.getMessage()); } } } return; }
/** * Reads the configuration file and initializes the project properties. The file is located in the * project home directory. * * @param prop property file extension */ protected synchronized void read(final String prop) { file = new IOFile(HOME + IO.BASEXSUFFIX + prop); final StringList read = new StringList(); final TokenBuilder err = new TokenBuilder(); if (!file.exists()) { err.addExt("Saving properties in \"%\"..." + NL, file); } else { BufferedReader br = null; try { br = new BufferedReader(new FileReader(file.file())); for (String line; (line = br.readLine()) != null; ) { line = line.trim(); if (line.isEmpty() || line.charAt(0) == '#') continue; final int d = line.indexOf('='); if (d < 0) { err.addExt("%: \"%\" ignored. " + NL, file, line); continue; } final String val = line.substring(d + 1).trim(); String key = line.substring(0, d).trim(); // extract numeric value in key int num = 0; final int ss = key.length(); for (int s = 0; s < ss; ++s) { if (Character.isDigit(key.charAt(s))) { num = Integer.parseInt(key.substring(s)); key = key.substring(0, s); break; } } read.add(key); final Object entry = props.get(key); if (entry == null) { err.addExt("%: \"%\" not found. " + NL, file, key); } else if (entry instanceof String) { props.put(key, val); } else if (entry instanceof Integer) { props.put(key, Integer.parseInt(val)); } else if (entry instanceof Boolean) { props.put(key, Boolean.parseBoolean(val)); } else if (entry instanceof String[]) { if (num == 0) { props.put(key, new String[Integer.parseInt(val)]); } else { ((String[]) entry)[num - 1] = val; } } else if (entry instanceof int[]) { ((int[]) entry)[num] = Integer.parseInt(val); } } } catch (final Exception ex) { err.addExt("% could not be parsed." + NL, file); Util.debug(ex); } finally { if (br != null) try { br.close(); } catch (final IOException ex) { } } } // check if all mandatory files have been read try { if (err.isEmpty()) { boolean ok = true; for (final Field f : getClass().getFields()) { final Object obj = f.get(null); if (!(obj instanceof Object[])) continue; final String key = ((Object[]) obj)[0].toString(); ok &= read.contains(key); } if (!ok) err.addExt("Saving properties in \"%\"..." + NL, file); } } catch (final IllegalAccessException ex) { Util.notexpected(ex); } if (!err.isEmpty()) { Util.err(err.toString()); write(); } }
/** * Add at least the first sentence from a doc block for a package to the API. This is used by the * report generator if no comment is provided. The default source tree may not include the * package.html files, so this may be unavailable in many cases. Need to make sure that HTML tags * are not confused with XML tags. This could be done by stuffing the < character to another * string or by handling HTML in the parser. This second option is neater. Note that XML expects * all element tags to have either a closing "/>" or a matching end element tag. Due to the * difficulties of converting incorrect HTML to XHTML, the first option is used. */ public void addPkgDocumentation(RootDoc root, PackageDoc pd, int indent) { String rct = null; String filename = pd.name(); try { // See if the source path was specified as part of the // options and prepend it if it was. String srcLocation = null; String[][] options = root.options(); for (int opt = 0; opt < options.length; opt++) { if ((options[opt][0]).compareTo("-sourcepath") == 0) { srcLocation = options[opt][1]; break; } } filename = filename.replace('.', JDiff.DIR_SEP.charAt(0)); if (srcLocation != null) { // Make a relative location absolute if (srcLocation.startsWith("..")) { String curDir = System.getProperty("user.dir"); while (srcLocation.startsWith("..")) { srcLocation = srcLocation.substring(3); int idx = curDir.lastIndexOf(JDiff.DIR_SEP); curDir = curDir.substring(0, idx + 1); } srcLocation = curDir + srcLocation; } filename = srcLocation + JDiff.DIR_SEP + filename; } // Try both ".htm" and ".html" filename += JDiff.DIR_SEP + "package.htm"; File f2 = new File(filename); if (!f2.exists()) { filename += "l"; } FileInputStream f = new FileInputStream(filename); BufferedReader d = new BufferedReader(new InputStreamReader(f)); String str = d.readLine(); // Ignore everything except the lines between <body> elements boolean inBody = false; while (str != null) { if (!inBody) { if (str.toLowerCase().trim().startsWith("<body")) { inBody = true; } str = d.readLine(); // Get the next line continue; // Ignore the line } else { if (str.toLowerCase().trim().startsWith("</body")) { inBody = false; continue; // Ignore the line } } if (rct == null) rct = str + "\n"; else rct += str + "\n"; str = d.readLine(); } } catch (java.io.FileNotFoundException e) { // If it doesn't exist, that's fine if (trace) System.out.println("No package level documentation file at '" + filename + "'"); } catch (java.io.IOException e) { System.out.println("Error reading file \"" + filename + "\": " + e.getMessage()); System.exit(5); } if (rct != null) { rct = stripNonPrintingChars(rct, (Doc) pd); rct = rct.trim(); if (rct.compareTo("") != 0 && rct.indexOf(Comments.placeHolderText) == -1 && rct.indexOf("InsertOtherCommentsHere") == -1) { int idx = endOfFirstSentence(rct); if (idx == 0) return; for (int i = 0; i < indent; i++) outputFile.print(" "); outputFile.println("<doc>"); for (int i = 0; i < indent; i++) outputFile.print(" "); String firstSentence = null; if (idx == -1) firstSentence = rct; else firstSentence = rct.substring(0, idx + 1); String firstSentenceNoTags = API.stuffHTMLTags(firstSentence); outputFile.println(firstSentenceNoTags); for (int i = 0; i < indent; i++) outputFile.print(" "); outputFile.println("</doc>"); } } }
public Graph(String file) throws IOException { org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger("it.unimi.dsi.webgraph.ImmutableGraph"); logger.setLevel(org.apache.log4j.Level.FATAL); try { File auxFile = File.createTempFile("graph-maps-" + System.currentTimeMillis(), "aux"); auxFile.deleteOnExit(); RecordManager recMan = RecordManagerFactory.createRecordManager(auxFile.getAbsolutePath()); nodes = recMan.hashMap("nodes"); nodesReverse = recMan.hashMap("nodesReverse"); } catch (IOException ex) { throw new Error(ex); } nodes.clear(); nodesReverse.clear(); Constructor[] cons = WeightedArc.class.getDeclaredConstructors(); for (int i = 0; i < cons.length; i++) cons[i].setAccessible(true); String aux = null; Float weight = (float) 1.0; WeightedArcSet list = new WeightedArcSet(); BufferedReader br; try { br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)))); } catch (Exception ex) { br = new BufferedReader(new FileReader(file)); } while ((aux = br.readLine()) != null) try { if (commit++ % COMMIT_SIZE == 0) { commit(); list.commit(); } String parts[] = aux.split("\t"); String l1 = new String(parts[0]); String l2 = new String(parts[1]); if (!nodesReverse.containsKey(l1)) { nodesReverse.put(l1, nodesReverse.size()); nodes.put(nodes.size(), l1); } if (!nodesReverse.containsKey(l2)) { nodesReverse.put(l2, nodesReverse.size()); nodes.put(nodes.size(), l2); } if (parts.length == 3) weight = new Float(parts[2]); list.add( (WeightedArc) cons[0].newInstance(nodesReverse.get(l1), nodesReverse.get(l2), weight)); } catch (Exception ex) { throw new Error(ex); } this.graph = new WeightedBVGraph(list.toArray(new WeightedArc[0])); br.close(); list = new WeightedArcSet(); br = new BufferedReader(new FileReader(file)); while ((aux = br.readLine()) != null) try { if (commit++ % COMMIT_SIZE == 0) { commit(); list.commit(); } String parts[] = aux.split("\t"); String l1 = new String(parts[0]); String l2 = new String(parts[1]); if (parts.length == 3) weight = new Float(parts[2]); list.add( (WeightedArc) cons[0].newInstance(nodesReverse.get(l2), nodesReverse.get(l1), weight)); } catch (Exception ex) { throw new Error(ex); } br.close(); this.reverse = new WeightedBVGraph(list.toArray(new WeightedArc[0])); numArcs = list.size(); iterator = nodeIterator(); try { File auxFile = File.createTempFile("graph" + System.currentTimeMillis(), "aux"); auxFile.deleteOnExit(); String basename = auxFile.getAbsolutePath(); store(basename); } catch (IOException ex) { throw new Error(ex); } commit(); }
/** Submits POST command to the server, and reads the reply. */ public boolean post( String url, String fileName, String cryptToken, String type, String path, String content, String comment) throws IOException { String sep = "89692781418184"; while (content.indexOf(sep) != -1) sep += "x"; String message = makeMimeForm(fileName, cryptToken, type, path, content, comment, sep); // for test // URL server = new URL("http", "localhost", 80, savePath); URL server = new URL(getCodeBase().getProtocol(), getCodeBase().getHost(), getCodeBase().getPort(), url); URLConnection connection = server.openConnection(); connection.setAllowUserInteraction(false); connection.setDoOutput(true); // connection.setDoInput(true); connection.setUseCaches(false); connection.setRequestProperty("Content-type", "multipart/form-data; boundary=" + sep); connection.setRequestProperty("Content-length", Integer.toString(message.length())); // System.out.println(url); String replyString = null; try { DataOutputStream out = new DataOutputStream(connection.getOutputStream()); out.writeBytes(message); out.close(); // System.out.println("Wrote " + message.length() + // " bytes to\n" + connection); try { BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String reply = null; while ((reply = in.readLine()) != null) { if (reply.startsWith("ERROR ")) { replyString = reply.substring("ERROR ".length()); } } in.close(); } catch (IOException ioe) { replyString = ioe.toString(); } } catch (UnknownServiceException use) { replyString = use.getMessage(); System.out.println(message); } if (replyString != null) { // System.out.println("---- Reply " + replyString); if (replyString.startsWith("URL ")) { URL eurl = getURL(replyString.substring("URL ".length())); getAppletContext().showDocument(eurl); } else if (replyString.startsWith("java.io.FileNotFoundException")) { // debug; when run from appletviewer, the http connection // is not available so write the file content if (path.endsWith(".draw") || path.endsWith(".map")) System.out.println(content); } else showStatus(replyString); return false; } else { showStatus(url + " saved"); return true; } }
/** Writes the properties to disk. */ public final synchronized void write() { final StringBuilder user = new StringBuilder(); BufferedReader br = null; try { // caches options specified by the user if (file.exists()) { br = new BufferedReader(new FileReader(file.file())); for (String line; (line = br.readLine()) != null; ) { if (line.equals(PROPUSER)) break; } for (String line; (line = br.readLine()) != null; ) { user.append(line).append(NL); } } } catch (final Exception ex) { Util.debug(ex); } finally { if (br != null) try { br.close(); } catch (final IOException e) { } } BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(file.file())); bw.write(PROPHEADER + NL); for (final Field f : getClass().getFields()) { final Object obj = f.get(null); if (!(obj instanceof Object[])) continue; final String key = ((Object[]) obj)[0].toString(); final Object val = props.get(key); if (val instanceof String[]) { final String[] str = (String[]) val; bw.write(key + " = " + str.length + NL); final int is = str.length; for (int i = 0; i < is; ++i) { if (str[i] != null) bw.write(key + (i + 1) + " = " + str[i] + NL); } } else if (val instanceof int[]) { final int[] num = (int[]) val; final int ns = num.length; for (int i = 0; i < ns; ++i) { bw.write(key + i + " = " + num[i] + NL); } } else { bw.write(key + " = " + val + NL); } } bw.write(NL + PROPUSER + NL); bw.write(user.toString()); } catch (final Exception ex) { Util.errln("% could not be written.", file); Util.debug(ex); } finally { if (bw != null) try { bw.close(); } catch (final IOException e) { } } }
/** * Try to determine whether this application is running under Windows or some other platform by * examining the "os.name" property. */ static { String os = System.getProperty("os.name"); // String version = System.getProperty("os.version"); // for Win7, reports "6.0" on JDK7, should // be "6.1"; for Win8, reports "6.2" as of JDK7u17 if (SystemUtils.startsWithIgnoreCase(os, "windows 7")) isWin7 = true; // reports "Windows Vista" on JDK7 else if (SystemUtils.startsWithIgnoreCase(os, "windows 8")) isWin7 = true; // reports "Windows 8" as of JDK7u17 else if (SystemUtils.startsWithIgnoreCase(os, "windows vista")) isVista = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows xp")) isWinXP = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows 2000")) isWin2k = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows nt")) isWinNT = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows")) isWin9X = true; // win95 or win98 (what about WinME?) else if (SystemUtils.startsWithIgnoreCase(os, "mac")) isMac = true; else if (SystemUtils.startsWithIgnoreCase(os, "so")) isSolaris = true; // sunos or solaris else if (os.equalsIgnoreCase("linux")) isLinux = true; else isUnix = true; // assume UNIX, e.g. AIX, HP-UX, IRIX String osarch = System.getProperty("os.arch"); String arch = (osarch != null && osarch.contains("64")) ? "_x64" /* eg. 'amd64' */ : "_x32"; String syslib = SYSLIB + arch; try { // loading a native lib in a static initializer ensures that it is available before any // method in this class is called: System.loadLibrary(syslib); System.out.println( "Done loading '" + System.mapLibraryName(syslib) + "', PID=" + getProcessID()); } catch (Error e) { System.err.println( "Native library '" + System.mapLibraryName(syslib) + "' not found in 'java.library.path': " + System.getProperty("java.library.path")); throw e; // re-throw } if (isWinPlatform()) { System.setProperty( "line.separator", "\n"); // so we won't have to mess with DOS line endings ever again comSpec = getEnv( "comSpec"); // use native method here since getEnvironmentVariable() needs to know // comSpec comSpec = (comSpec != null) ? comSpec + " /c " : ""; try (BufferedReader br = new BufferedReader( new InputStreamReader( RUNTIME.exec(comSpec + "ver").getInputStream()))) { // fix for Win7,8 for (String line = null; (line = br.readLine()) != null; ) { if (isVista && (line.contains("6.1" /*Win7*/) || line.contains("6.2" /*Win8*/))) { isVista = false; isWin7 = true; } } } catch (IOException e) { e.printStackTrace(); } String cygdir = getEnv("cygdir"); // this is set during CygWin install to "?:/cygwin/bin" isCygWin = (cygdir != null && !cygdir.equals("%cygdir%")); cygstartPath = cygdir + "/cygstart.exe"; // path to CygWin's cygutils' "cygstart" binary if (getDebug() && Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); for (Desktop.Action action : Desktop.Action.values()) System.out.println( "Desktop action " + action + " supported? " + desktop.isSupported(action)); } } }