/** * This method concerts the given path to a platform specific path, mainly * replacing the path separator accordingly. * * @param aPath The path to be converted. * @return The converted path. */ public static String toPlatformSpecificPath( String aPath ) { String theFileSeparator = SystemProperty.FILE_SEPARATOR.getValue(); if ( theFileSeparator != null && theFileSeparator.length() == 1 ) { // @formatter:off /* char theFileSeapratorChar = theFileSeparator.charAt( 0 ); String thePath = aPath.replace( RefcodesConstants.DEFAULT_PATH_DELIMITER, theFileSeapratorChar ); LOGGER.debug( "Converted to a platform specifc path \"" + thePath + "\" from the provided path \"" + aPath + "\"." ); */ // @formatter:on } else { // @formatter:off /* LOGGER.warn( "Left \"" + aPath + "\" unchanged as no (or an invalid) path separator was determined with the env property \"" + RefcodesConstants.ENV_FILE_DELIMITER + "\" from the system environment." ); */ // @formatter:on } return aPath; }
if ( aToSysHost.getValue() == null || aToSysHost.getValue().length() == 0 ) { String theHttpProxy = aFromEnvProxy.getValue(); if ( theHttpProxy != null ) { int ePort = Integer.valueOf( theHttpProxy.substring( index + 1 ) ); String eHost = theHttpProxy.substring( 0, index ); aToSysHost.setValue( eHost ); aToSysPort.setValue( ePort + "" ); aToSysHost.setValue( theHttpProxy ); aToSysHost.setValue( theHttpProxy );
/** * {@inheritDoc} */ @Override public void open( Url aBaseUrl, TrustStoreDescriptor aStoreDescriptor ) throws OpenException { if ( aStoreDescriptor == null ) { aStoreDescriptor = getTrustStoreDescriptor(); } else { _storeDescriptor = aStoreDescriptor; } if ( aBaseUrl == null ) { aBaseUrl = getBaseUrl(); } else { _baseUrl = aBaseUrl; } if ( _connectionStatus == ConnectionStatus.OPENED ) throw new OpenException( "The HTTP rest client is already open, close first before opening again!" ); _connectionStatus = ConnectionStatus.OPENED; if ( aStoreDescriptor != null ) { SystemProperty.TRUST_STORE_FILE.setValue( aStoreDescriptor.getStoreFile().getAbsolutePath() ); SystemProperty.TRUST_STORE_PASSWORD.setValue( aStoreDescriptor.getStorePassword() != null ? aStoreDescriptor.getStorePassword() : "" ); SystemProperty.TRUST_STORE_TYPE.setValue( aStoreDescriptor.getStoreType().name() ); } }
/** * Determines the user's home folder. * * @return The user's home folder or null if none was detected. */ static File toHomeFolder() { String theValue = SystemProperty.USER_HOME.getValue(); if ( theValue != null && theValue.length() != 0 ) { File theFolder = new File( theValue ); if ( theFolder.exists() && theFolder.isDirectory() && theFolder.canRead() ) { return theFolder; } } return null; }
/** * Bad hack to get the JVM's (process ID) PID of the process running your * JVM instance. * * @return The PID (process ID) of the JVM running your thread. * * @see "http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id" */ public static Long getPid() { Long thePid = null; try { thePid = Long.parseLong( SystemProperty.PROCESS_ID.getValue() ); } catch ( NumberFormatException e1 ) { String theJvmName = ManagementFactory.getRuntimeMXBean().getName(); if ( theJvmName.indexOf( '@' ) != -1 ) { try { thePid = Long.parseLong( theJvmName.substring( 0, theJvmName.indexOf( '@' ) ) ); } catch ( NumberFormatException e2 ) { // Unable to determine PID } } } return thePid; }
/** * Prints the usage of how to use this class to System.out */ private static void printUsage() { final String lineSeparator = SystemProperty.LINE_SEPARATOR.getValue(); final StringBuffer msg = new StringBuffer(); msg.append( Console.class.getCanonicalName() + " [options]" + lineSeparator ); msg.append( lineSeparator ); msg.append( "Options: " + lineSeparator ); msg.append( " -d or -double use Double evaluation mode" + lineSeparator ); msg.append( " -c or -complex use Complex evaluation mode" + lineSeparator ); msg.append( " -h or -help print this message" + lineSeparator ); msg.append( " -f or -file <filename> use given file as input" + lineSeparator ); msg.append( "To stop the program type: " + lineSeparator ); msg.append( "exit<RETURN-KEY>" + lineSeparator ); msg.append( "To switch between the evaluation modes type: " + lineSeparator ); msg.append( "complex<RETURN-KEY> or" + lineSeparator ); msg.append( "double<RETURN-KEY>" + lineSeparator ); msg.append( "To continue an input line type '\\' at the end of the line." + lineSeparator ); msg.append( "****+****+****+****+****+****+****+****+****+****+****+****+" ); System.out.println( msg.toString() ); }
String theOperationSystem = SystemProperty.OPERATING_SYSTEM_NAME.getValue(); if ( theOperationSystem != null ) { theOperationSystem = theOperationSystem.toLowerCase();
/** * Gets the value for the provided properties, if non was found then the * default value is taken. A {@link SystemProperty} elements wins over the * {@link EnvironmentVariable} elements. The preceding * {@link EnvironmentVariable} element wins over the succeeding * {@link EnvironmentVariable} element. The default value is taken if non * property had a value (a String with length > 0). * * @param aDefaultValue The default value to take when none other value was * set. * @param aSystemProperty The system-property passed via <code>java * -D<name>=<value></code> * @param aEnvironmentProperties The properties looked for in the system's * environment variables. * @return The best fitting value. */ public static String toPropertyValue( String aDefaultValue, SystemProperty aSystemProperty, EnvironmentVariable... aEnvironmentProperties ) { String theValue = aSystemProperty.getValue(); if ( theValue != null && theValue.length() > 0 ) return theValue; if ( aEnvironmentProperties != null ) { for ( EnvironmentVariable eProperty : aEnvironmentProperties ) { theValue = eProperty.getValue(); if ( theValue != null && theValue.length() > 0 ) return theValue; } } if ( theValue != null && theValue.length() > 0 ) return theValue; return aDefaultValue; }
/** * Gets the value for the provided properties, if non was found then null is * returned. A {@link SystemProperty} elements wins over the * {@link EnvironmentVariable} elements. The preceding * {@link EnvironmentVariable} element wins over the succeeding * {@link EnvironmentVariable} element. A null is taken if non property had * a value (a String with length > 0). * * @param aSystemProperty The system-property passed via <code>java * -D<name>=<value></code> * @param aEnvironmentProperties The properties looked for in the system's * environment variables. * @return The best fitting value or null if none was detected. */ public static String toPropertyValue( SystemProperty aSystemProperty, EnvironmentVariable... aEnvironmentProperties ) { String theValue = aSystemProperty.getValue(); if ( theValue != null && theValue.length() != 0 ) return theValue; if ( aEnvironmentProperties != null ) { for ( EnvironmentVariable eProperty : aEnvironmentProperties ) { theValue = eProperty.getValue(); if ( theValue != null && theValue.length() != 0 ) return theValue; } } if ( theValue != null && theValue.length() != 0 ) return theValue; return null; }
/** * Determines the operating system as of * {@link OperatingSystem#toOperatingSystem()} and in case a * {@link OperatingSystem#WINDOWS} is being detected, then \r\n" (CRLF) is * returned, else "\n" (LF) is returned. * * Can be overridden with the {@link SystemProperty#CONSOLE_LINE_BREAK} * (<code>java -Dconsole.lineBreak=...</code>) and the * {@link EnvironmentVariable#CONSOLE_LINE_BREAK} * ("<code>export CONSOLE_LINE_BREAK=...</code>). * * @return The operating system's specific line break; on Windows it is * "\r\n" (CRLF) and on all other operating systems it is "\n" (LF). */ public static String getLineBreak() { String theLineBreak = SystemProperty.CONSOLE_LINE_BREAK.getValue(); if ( theLineBreak == null || theLineBreak.length() == 0 ) { theLineBreak = EnvironmentVariable.CONSOLE_LINE_BREAK.getValue(); if ( theLineBreak == null || theLineBreak.length() == 0 ) { theLineBreak = System.lineSeparator(); } } if ( theLineBreak == null || theLineBreak.length() == 0 ) { theLineBreak = OperatingSystem.toOperatingSystem() == OperatingSystem.WINDOWS ? "\r\n" : "\n"; } return theLineBreak; }
String theUserHome = EnvironmentVariable.USER_HOME.getValue(); if ( theUserHome == null || theUserHome.length() == 0 ) { theUserHome = SystemProperty.USER_HOME.getValue();
theInfo.put( "systemConsole", (System.console() != null ? System.console().toString() : null) ); theInfo.put( "terminalEncoding", Terminal.getTerminalEncoding() ); theInfo.put( "tempDir", SystemProperty.TEMP_DIR.getValue() ); theInfo.put( "terminal", Terminal.toTerminal() + "" ); theInfo.put( "terminalHeight", Terminal.getTerminalHeight() + "" );
String theArch = SystemProperty.OS_ARCH.getValue(); if ( theArch == null || theArch.length() == 0 ) { theArch = EnvironmentVariable.PROCESSOR_ARCHITECTURE.getKey(); String theUserName = SystemProperty.USER_NAME.getValue(); if ( theUserName == null || theUserName.length() == 0 ) { theUserName = Text.ARECIBO_MESSAGE.getText().substring( 0, 16 ); String theUserHome = SystemProperty.USER_HOME.getValue(); if ( theUserHome == null || theUserHome.length() == 0 ) { theUserHome = Text.ARECIBO_MESSAGE.getText().substring( 16, 32 ); String theTemp = SystemProperty.TEMP_DIR.getValue(); if ( theTemp == null ) { theTemp = new String( Text.ARECIBO_MESSAGE.getText().substring( 48, 64 ) ); theBuffer.append( theSeed ); theSeed = SystemProperty.HOST_SEED.getValue(); if ( theSeed != null && theSeed.length() != 0 ) { if ( theBuffer.length() != 0 ) theBuffer.append( Delimiter.LIST.getChar() );
List<File> theFolders = new ArrayList<File>(); addFolder( toFolder( SystemProperty.CONFIG_DIR.getValue() ), theFolders );