List of usage examples for org.apache.commons.lang SystemUtils IS_OS_WINDOWS
boolean IS_OS_WINDOWS
To view the source code for org.apache.commons.lang SystemUtils IS_OS_WINDOWS.
Click Source Link
Is true
if this is Windows.
The field will return false
if OS_NAME
is null
.
From source file:org.openecomp.sdc.be.dao.es.ElasticSearchClient.java
@PostConstruct public void initialize() throws URISyntaxException { URL url = null;/*w w w .j a v a 2 s.com*/ Settings settings = null; URL systemResourceElasticsearchPath = ClassLoader.getSystemResource("elasticsearch.yml"); if (systemResourceElasticsearchPath != null) { log.debug("try to create URI for {}", systemResourceElasticsearchPath.toString()); Path classpathConfig = Paths.get(systemResourceElasticsearchPath.toURI()); settings = Settings.settingsBuilder().loadFromPath(classpathConfig).build(); } String configHome = System.getProperty("config.home"); if (configHome != null && false == configHome.isEmpty()) { try { if (SystemUtils.IS_OS_WINDOWS) { url = new URL("file:///" + configHome + "/elasticsearch.yml"); } else { url = new URL("file:" + configHome + "/elasticsearch.yml"); } log.debug("URL {}", url); settings = Settings.settingsBuilder().loadFromPath(Paths.get(url.toURI())).build(); } catch (MalformedURLException | URISyntaxException e1) { log.error("Failed to create URL in order to load elasticsearch yml"); System.err.println("Failed to create URL in order to load elasticsearch yml from " + configHome); } } if (settings == null) { log.error("Failed to find settings of elasticsearch yml"); System.err.println("Failed to create URL in order to load elasticsearch yml from " + configHome); } if (isTransportClient()) { log.info("******* ElasticSearchClient type is Transport Client *****"); TransportClient transportClient = TransportClient.builder().addPlugin(ShieldPlugin.class) .settings(settings).build(); String[] nodesArray = transportClient.settings().getAsArray("transport.client.initial_nodes"); for (String host : nodesArray) { int port = 9300; // or parse it from the host string... String[] splitHost = host.split(":", 2); if (splitHost.length == 2) { host = splitHost[0]; port = Integer.parseInt(splitHost[1]); } transportClient .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(host, port))); } this.client = transportClient; serverHost = Arrays.toString(nodesArray); } else { log.info("******* ElasticSearchClient type is Node Client *****"); this.node = NodeBuilder.nodeBuilder().settings(settings).client(!isLocal).clusterName(this.clusterName) .local(isLocal).node(); this.client = node.client(); serverHost = this.client.settings().get("discovery.zen.ping.unicast.hosts"); if (serverHost == null) { serverHost = "['localhost:9200']"; } } serverPort = this.client.settings().get("http.port"); if (serverPort == null) { serverPort = "9200"; } log.info("Initialized ElasticSearch client for cluster <{}> with nodes: {}", this.clusterName, serverHost); }
From source file:org.openehr.designer.util.WtUtils.java
public static String sanitizeFilename(String filename) { StringBuilder result = new StringBuilder(); final int length = filename.length(); for (int i = 0; i < length; i++) { char c = filename.charAt(i); if (c != FILENAME_ESCAPE_CHAR && isValidFilenameChar(c)) { result.append(c);/* w w w . j a va 2 s . c o m*/ } else { result.append(FILENAME_ESCAPE_CHAR).append(toUnicodeString(c)); } } if (SystemUtils.IS_OS_WINDOWS) { if (ImmutableSet.of("con", "prn", "aux").contains(result.toString().toLowerCase())) { result.append(FILENAME_ESCAPE_CHAR); } } return result.toString(); }
From source file:org.openhab.binding.network.internal.utils.NetworkUtils.java
/** * Return the working method for the native system ping. If no native ping * works JavaPing is returned.//from w w w . j a v a 2 s .com */ public IpPingMethodEnum determinePingMethod() { IpPingMethodEnum method; if (SystemUtils.IS_OS_WINDOWS) { method = IpPingMethodEnum.WINDOWS_PING; } else if (SystemUtils.IS_OS_MAC) { method = IpPingMethodEnum.MAC_OS_PING; } else if (SystemUtils.IS_OS_UNIX) { method = IpPingMethodEnum.IPUTILS_LINUX_PING; } else { // We cannot estimate the command line for any other operating system and just return false return IpPingMethodEnum.JAVA_PING; } try { if (nativePing(method, "127.0.0.1", 1000)) { return method; } } catch (IOException ignored) { } catch (InterruptedException e) { Thread.currentThread().interrupt(); // Reset interrupt flag } return IpPingMethodEnum.JAVA_PING; }
From source file:org.openhab.binding.network.service.NetworkService.java
/** * Try's to reach the Device by Ping//from ww w.jav a 2s. c om */ private static double updateDeviceState(String hostname, int port, int timeout, boolean useSystemPing) throws InvalidConfigurationException { boolean success = false; double pingTime = -1; try { if (!useSystemPing) { pingTime = System.nanoTime(); success = Ping.checkVitality(hostname, port, timeout); pingTime = System.nanoTime() - pingTime; } else { Process proc; if (SystemUtils.IS_OS_UNIX) { pingTime = System.nanoTime(); proc = new ProcessBuilder("ping", "-t", String.valueOf(timeout / 1000), "-c", "1", hostname) .start(); } else if (SystemUtils.IS_OS_WINDOWS) { pingTime = System.nanoTime(); proc = new ProcessBuilder("ping", "-w", String.valueOf(timeout), "-n", "1", hostname).start(); } else { logger.error("The System Ping is not supported on this Operating System"); throw new InvalidConfigurationException("System Ping not supported"); } int exitValue = proc.waitFor(); pingTime = System.nanoTime() - pingTime; success = exitValue == 0; if (!success) { logger.debug("Ping stopped with Error Number: " + exitValue + " on Command :" + "ping" + (SystemUtils.IS_OS_UNIX ? " -t " : " -w ") + (SystemUtils.IS_OS_UNIX ? String.valueOf(timeout / 1000) : String.valueOf(timeout)) + (SystemUtils.IS_OS_UNIX ? " -c" : " -n") + " 1 " + hostname); } } logger.debug("established connection [host '{}' port '{}' timeout '{}']", new Object[] { hostname, port, timeout }); } catch (SocketTimeoutException se) { logger.debug("timed out while connecting to host '{}' port '{}' timeout '{}'", new Object[] { hostname, port, timeout }); } catch (IOException ioe) { logger.debug("couldn't establish network connection [host '{}' port '{}' timeout '{}']", new Object[] { hostname, port, timeout }); } catch (InterruptedException e) { logger.debug("ping program was interrupted"); } return success ? pingTime / 1000000.0f : -1; }
From source file:org.openhab.binding.network.service.NetworkUtils.java
public static boolean nativePing(String hostname, int port, int timeout) throws InvalidConfigurationException, IOException, InterruptedException { Process proc;//from w w w.j a v a 2 s. c o m if (SystemUtils.IS_OS_UNIX) { proc = new ProcessBuilder("ping", "-w", String.valueOf(timeout / 1000), "-c", "1", hostname).start(); } else if (SystemUtils.IS_OS_WINDOWS) { proc = new ProcessBuilder("ping", "-w", String.valueOf(timeout), "-n", "1", hostname).start(); } else { throw new InvalidConfigurationException("System Ping not supported"); } int exitValue = proc.waitFor(); if (exitValue != 0) { throw new IOException("Ping stopped with Error Number: " + exitValue + " on Command :" + "ping" + (SystemUtils.IS_OS_UNIX ? " -t " : " -w ") + (SystemUtils.IS_OS_UNIX ? String.valueOf(timeout / 1000) : String.valueOf(timeout)) + (SystemUtils.IS_OS_UNIX ? " -c" : " -n") + " 1 " + hostname); } return exitValue == 0; }
From source file:org.openhab.io.rest.internal.resources.ContextResource.java
@GET @Path("/{scriptfile: [a-zA-Z_0-9]*}/{arg1: [a-zA-Z_0-9]*}/{arg2: [a-zA-Z_0-9]*}") @Produces({ MediaType.WILDCARD })/* www .ja v a 2 s .c o m*/ public Response callShellScriptAndSendReturnValue(@PathParam("scriptfile") String scriptFile, @PathParam("arg1") @DefaultValue("0") String Arg1, @PathParam("arg2") @DefaultValue("0") String Arg2, @QueryParam("que1") @DefaultValue("0") String Que1, @QueryParam("que2") @DefaultValue("0") String Que2, @QueryParam("type") @DefaultValue("0") String Type, @CookieParam("uid") @DefaultValue("0") String UID, @HeaderParam("If-None-Match") @DefaultValue("0") String INM, @HeaderParam("Timeout") @DefaultValue("10000") Integer TimeOut, @Context HttpServletRequest request) { //logger.info("FYI: ContextResource - HeaderParam 'Timeout':" +TimeOut); if (Type.equals("")) Type = "0"; final String responseType = getResponseMediaType(Type); String uid = "0"; if (request.getRemoteUser() != null) uid = request.getRemoteUser(); else uid = UID; if (INM.equals("0")) INM = "0"; if (Arg1.equals("")) Arg1 = "0"; if (Arg2.equals("")) Arg2 = "0"; if (Que1.equals("")) Que1 = "0"; if (Que2.equals("")) Que2 = "0"; if (TimeOut.equals("")) TimeOut = 10000; else TimeOut = TimeOut - 500; //file extention according to Op.Sys. String ext = "sh"; if (SystemUtils.IS_OS_WINDOWS) ext = "bat"; String md5Hash = null; if (scriptFile.equals("")) scriptFile = "0"; String fileName = scriptFile + ".GET." + ext; File f = new File("contexts/" + fileName); //check if scriptfile exists if (f.exists() && !f.isDirectory()) { String command = "contexts/" + fileName + " " + uid + " " + Arg1 + " " + Arg2 + " " + Que1 + " " + Que2 + " " + Type; //logger.info("FYI: ContextResource - Command To Execute: "+command); String result = Exec.executeCommandLine(command, TimeOut); md5Hash = md5(result); //logger.info("FYI: ContextResource request '{}' md5 hash is: '{}'", uriInfo.getAbsolutePath(), md5Hash); EntityTag resultETag = new EntityTag(md5Hash); if (resultETag.toString().equals(INM)) return Response.notModified(resultETag).tag(resultETag).build(); else return Response.ok(result, responseType).tag(resultETag).build(); } else { logger.info("FYI: ContextResource request at '{}' was for scriptFile '{}' that does not exist", uriInfo.getPath(), fileName); return Response.status(404).build(); } }
From source file:org.openhab.io.rest.internal.resources.ContextResource.java
/*************************************************************************************** * //from www . jav a 2 s . c o m * PUT request on /rest/context/<scriptFile>/<arg1>/<arg2> * * will execute scriptFile.PUT.bat (Windows OS) OR scriptFile.PUT.sh (*NIX OS) * located at openhab runtime folder /contexts * * Arguments passed on to the script are (no spaces allowed): * a) Cookie Parameter "uid" value ("0" if missing) * b) Path Parameters "arg1" & "arg2" (required) * c) PayLoad of Request (in PLAIN TEXT, spaces allowed) * * Results printed to stdout are returned as PLAIN TEXT in response body. * *************************************************************************************/ @PUT @Path("/{scriptfile: [a-zA-Z_0-9]*}/{arg1: [a-zA-Z_0-9]*}/{arg2: [a-zA-Z_0-9]*}") @Consumes({ MediaType.TEXT_PLAIN }) @Produces({ MediaType.TEXT_PLAIN }) public Response callShellScriptWithDataAndSendReturnValue(@PathParam("scriptfile") String scriptFile, @PathParam("arg1") @DefaultValue("0") String Arg1, @PathParam("arg2") @DefaultValue("0") String Arg2, @QueryParam("que1") @DefaultValue("0") String Que1, @QueryParam("que2") @DefaultValue("0") String Que2, @QueryParam("type") @DefaultValue("0") String Type, @CookieParam("uid") @DefaultValue("0") String UID, @HeaderParam("If-None-Match") @DefaultValue("0") String INM, @HeaderParam("Timeout") @DefaultValue("10000") Integer TimeOut, @Context HttpServletRequest request, String value) { if (Type.equals("")) Type = "0"; // final String responseType = getResponseMediaType(Type); String uid = "0"; if (request.getRemoteUser() != null) uid = request.getRemoteUser(); else uid = UID; if (INM.equals("0")) INM = "0"; if (Arg1.equals("")) Arg1 = "0"; if (Arg2.equals("")) Arg2 = "0"; if (Que1.equals("")) Que1 = "0"; if (Que2.equals("")) Que2 = "0"; if (TimeOut.equals("")) TimeOut = 10000; else TimeOut = TimeOut - 500; //file extention according to Op.Sys. String ext = "sh"; if (SystemUtils.IS_OS_WINDOWS) ext = "bat"; if (scriptFile.equals("")) scriptFile = "0"; String fileName = scriptFile + ".PUT." + ext; File f = new File("contexts/" + fileName); //check if scriptfile exists if (f.exists() && !f.isDirectory()) { String result = Exec.executeCommandLine( "contexts/" + fileName + " " + uid + " " + Arg1 + " " + Arg2 + " " + value, TimeOut); if (result != null) { if (Type != "0") return Response.ok(result).build(); else return Response.status(201).build(); } else { logger.info("HTTP PUT request at '{}' for scriptFile '{}' returned null", uriInfo.getPath(), scriptFile); return Response.status(404).build(); } } else return Response.status(404).build(); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Returns <code>true</code> if the OS is Windows, <code>false</code> * otherwise./*from w w w .j av a 2 s .c om*/ * * @return See above. */ public static boolean isWindowsOS() { //String osName = System.getProperty("os.name").toLowerCase(); //return osName.startsWith("windows"); return (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_WINDOWS_2000 || SystemUtils.IS_OS_WINDOWS_7 || SystemUtils.IS_OS_WINDOWS_95 || SystemUtils.IS_OS_WINDOWS_98 || SystemUtils.IS_OS_WINDOWS_ME || SystemUtils.IS_OS_WINDOWS_NT || SystemUtils.IS_OS_WINDOWS_VISTA || SystemUtils.IS_OS_WINDOWS_XP); }
From source file:org.openoffice.maven.ConfigurationManager.java
/** * Returns the path to the SDK binaries depending on the OS and the * architecture.//from w w w . j av a 2s. c o m * * @param pHome * the OpenOffice.org SDK home * @return the full path to the SDK binaries */ private static String getSdkBinPath() { File sdkHome = Environment.getOoSdkHome(); // OOo SDK does not seem to include the target os in their packaging // anymore. Tested with 3.2.0 String path = "/bin"; if (new File(sdkHome, path).exists()) { return new File(sdkHome, path).getPath(); } // Get the Architecture properties String arch = System.getProperty("os.arch").toLowerCase(); if (SystemUtils.IS_OS_WINDOWS) { path = "/windows/bin/"; } else if (SystemUtils.IS_OS_SOLARIS) { if (arch.equals("sparc")) { path = "/solsparc/bin"; } else { path = "/solintel/bin"; } } else if (SystemUtils.IS_OS_MAC) { path = "/bin"; } else { path = "/linux/bin"; } return new File(sdkHome, path).getPath(); }
From source file:org.openoffice.maven.ConfigurationManager.java
private static void setUpEnvironmentFor(final Commandline cl) throws Exception { cl.addSystemEnvironment();/*from w w w.j a v a 2s . com*/ Properties envVars = cl.getSystemEnvVars(); String path = envVars.getProperty("PATH", ""); String pathSep = System.getProperty("path.separator", ":"); path = getSdkBinPath() + pathSep + getOOoBinPath() + pathSep + Environment.getOoSdkUreBinDir() + pathSep + path; cl.addEnvironment("PATH", path); //log.debug("PATH=" + path); String oooLibs = Environment.getOoSdkUreLibDir().getCanonicalPath(); if (SystemUtils.IS_OS_WINDOWS) { // I'm not sure if this works / is necessary cl.addEnvironment("DLLPATH", oooLibs); cl.addEnvironment("LIB", oooLibs); //log.debug("DLLPATH=" + oooLibs); } else if (SystemUtils.IS_OS_MAC) { cl.addEnvironment("DYLD_LIBRARY_PATH", oooLibs); //log.debug("DYLD_LIBRARY_PATH=" + oooLibs); } else { // *NIX environment cl.addEnvironment("LD_LIBRARY_PATH", oooLibs); //log.debug("LD_LIBRARY_PATH=" + oooLibs); } if (sJpdaAddress != null) { cl.addEnvironment("JAVA_TOOL_OPTIONS", "-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=" + sJpdaAddress); } if (sUserInstallation != null) { cl.addEnvironment("UserInstallation", "file://" + sUserInstallation.toURI().getRawPath()); } /*log.debug("Environment"); for (int i = 0; i < cl.getEnvironmentVariables().length; i++) { String string = cl.getEnvironmentVariables()[i]; log.debug(string); }*/ }