List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:net.cliseau.composer.config.format.PropertiesConfig.java
/** * Make a path absolute with respect to a particular configuration. * * @param props Properties object holding the full configuration. * @param path Possibly relative path to be made absolute. *///from www .j a v a2 s . c om private static String makeAbsolute(final Properties props, final String path) throws MissingConfigurationException { File f = new File(path); if (f.isAbsolute()) // absolute paths are simply returned return f.getPath(); else { // relative paths must be made absolute using on a chosen base directory // note that the "basedir" property is set in the constructor // of the class return (new File((File) props.get("basedir"), f.getPath())).getPath(); } }
From source file:org.cloudifysource.dsl.internal.packaging.Packager.java
private static File locateServiceFile(final File recipeFile, final String extendedServicePath) { File extendedServiceFile = new File(extendedServicePath); if (!extendedServiceFile.isAbsolute()) { extendedServiceFile = new File(recipeFile.getParent() + "/" + extendedServicePath); }//from w w w .ja v a2 s . c om if (extendedServiceFile.isDirectory()) { extendedServiceFile = DSLReader.findDefaultDSLFile(DSLUtils.SERVICE_DSL_FILE_NAME_SUFFIX, extendedServiceFile); } return extendedServiceFile; }
From source file:org.colombbus.tangara.FileUtils.java
/** * Creates a BufferedImage from a file./* w ww . j av a 2s . c o m*/ * @param fileName * @return * @throws Exception */ public static File findFile(String fileName, String[] possibleExtensions) { int pointPosition = fileName.lastIndexOf('.'); boolean extensionFound = false; if (pointPosition > -1) { // dot Found String extension = fileName.substring(pointPosition + 1); if (extension.length() >= 0) { extensionFound = true; } } else { // no dot found fileName += "."; //$NON-NLS-1$ } if (extensionFound) { return findFile(fileName); } else { File file = new File(fileName); if (!file.isAbsolute()) { // the name does not contain any directory reference : add the current directory File currentDirectory = Program.instance().getCurrentDirectory(); for (String extension : possibleExtensions) { file = new File(currentDirectory, fileName + extension); if (file.exists()) return file; } File userHome = Configuration.instance().getUserHome(); LOG.debug("USER HOME : " + userHome); for (String extension : possibleExtensions) { file = new File(userHome, fileName + extension); if (file.exists()) return file; } } else { // File is absolute: we simply try to find the file with possible extensions for (String extension : possibleExtensions) { file = new File(fileName + extension); if (file.exists()) return file; } } } return null; }
From source file:net.i2p.util.I2PSSLSocketFactory.java
/** * Read in the country file and add all TLDs to the list. * It would almost be easier just to add all possible 26*26 two-letter codes. * * @param tlds out parameter// w w w . j a v a 2s .c o m * @since 0.9.20 adapted from GeoIP.loadCountryFile() */ private static void addCountries(I2PAppContext ctx, List<String> tlds) { Log log = ctx.logManager().getLog(I2PSSLSocketFactory.class); String geoDir = ctx.getProperty(PROP_GEOIP_DIR, GEOIP_DIR_DEFAULT); File geoFile = new File(geoDir); if (!geoFile.isAbsolute()) geoFile = new File(ctx.getBaseDir(), geoDir); geoFile = new File(geoFile, COUNTRY_FILE_DEFAULT); if (!geoFile.exists()) { if (log.shouldWarn()) log.warn("Country file not found: " + geoFile.getAbsolutePath()); return; } BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(new FileInputStream(geoFile), "UTF-8")); String line = null; int i = 0; while ((line = br.readLine()) != null) { try { if (line.charAt(0) == '#') continue; String[] s = DataHelper.split(line, ","); String lc = s[0].toLowerCase(Locale.US); tlds.add(lc); i++; } catch (IndexOutOfBoundsException ioobe) { } } if (log.shouldInfo()) log.info("Loaded " + i + " TLDs from " + geoFile.getAbsolutePath()); } catch (IOException ioe) { log.error("Error reading the Country File", ioe); } finally { if (br != null) try { br.close(); } catch (IOException ioe) { } } }
From source file:net.sf.sahi.util.Utils.java
public static File getRelativeFile(File parent, final String s2) { File sf2 = new File(s2); if (sf2.isAbsolute()) { return sf2; }//from www.j av a 2s .c o m if (!parent.isDirectory()) { parent = parent.getParentFile(); } File file = new File(parent, s2); return file; }
From source file:net.sf.sahi.util.Utils.java
public static String concatPaths(final String s1, final String s2, boolean returnRelative) { File sf2 = new File(s2); if (sf2.isAbsolute()) { return s2; }/*from w ww . j ava2 s . com*/ File parent = new File(s1); if (!parent.isDirectory()) { parent = parent.getParentFile(); } File file = new File(parent, s2); return returnRelative ? file.getPath() : getAbsolutePath(file); }
From source file:net.i2p.util.I2PSSLSocketFactory.java
/** * From Apache PublicSuffixMatcherLoader.getDefault() * * https://publicsuffix.org/list/effective_tld_names.dat * What does this get us?/*from w w w . ja va 2 s. c o m*/ * Deciding whether to issue or accept an SSL wildcard certificate for *.public.suffix. * * @return null on failure * @since 0.9.20 */ private static PublicSuffixMatcher getDefaultMatcher(I2PAppContext ctx) { synchronized (I2PSSLSocketFactory.class) { if (!_matcherLoaded) { String geoDir = ctx.getProperty(PROP_GEOIP_DIR, GEOIP_DIR_DEFAULT); File geoFile = new File(geoDir); if (!geoFile.isAbsolute()) geoFile = new File(ctx.getBaseDir(), geoDir); geoFile = new File(geoFile, PUBLIC_SUFFIX_LIST); Log log = ctx.logManager().getLog(I2PSSLSocketFactory.class); if (geoFile.exists()) { try { // we can't use PublicSuffixMatcherLoader.load() here because we // want to add some of our own and a PublicSuffixMatcher's // underlying PublicSuffixList is immutable and inaccessible long begin = System.currentTimeMillis(); InputStream in = null; PublicSuffixList list = new PublicSuffixList(Arrays.asList(ADDITIONAL_TLDS), Collections.<String>emptyList()); try { in = new FileInputStream(geoFile); PublicSuffixList list2 = new PublicSuffixListParser() .parse(new InputStreamReader(in, "UTF-8")); list = merge(list, list2); } finally { try { if (in != null) in.close(); } catch (IOException ioe) { } } DEFAULT_MATCHER = new PublicSuffixMatcher(list.getRules(), list.getExceptions()); if (log.shouldWarn()) log.warn("Loaded " + geoFile + " in " + (System.currentTimeMillis() - begin) + " ms and created list with " + list.getRules().size() + " entries and " + list.getExceptions().size() + " exceptions"); } catch (IOException ex) { log.error("Failure loading public suffix list from " + geoFile, ex); // DEFAULT_MATCHER remains null } } else { List<String> list = new ArrayList<String>(320); addCountries(ctx, list); list.addAll(Arrays.asList(DEFAULT_TLDS)); list.addAll(Arrays.asList(ADDITIONAL_TLDS)); DEFAULT_MATCHER = new PublicSuffixMatcher(list, null); if (log.shouldWarn()) log.warn("No public suffix list found at " + geoFile + " - created default with " + list.size() + " entries"); } } _matcherLoaded = true; } return DEFAULT_MATCHER; }
From source file:org.cloudifysource.esc.util.Utils.java
/************************* * Creates an Agentless Installer's InstallationDetails input object from a machine details object returned from a * provisioning implementation./*from w w w .j av a 2 s . c o m*/ * * @param md * the machine details. * @param cloud * The cloud configuration. * @param template * the cloud template used for this machine. * @param zones * the zones that the new machine should start in. * @param lookupLocatorsString * the lookup locators string to pass to the new machine. * @param admin * an admin object, may be null. * @param isManagement * true if this machine will be installed as a cloudify controller, false otherwise. * @param cloudFile * the cloud file, required only when isManagement == true. * @param reservationId * A unique identifier of the new agent to be created * @param templateName * The template of the machines to be created * @param securityProfile * set security profile (nonsecure/secure/ssl) * @param keystorePassword * The password to the keystore set on the rest server * @param authGroups * The authentication groups attached to the GSA as an environment variable * {@link CloudifyConstants#GIGASPACES_AUTH_GROUPS} * @param rebootstrapping * @return the installation details. * @throws FileNotFoundException * if a key file is specified and is not found. */ public static InstallationDetails createInstallationDetails(final MachineDetails md, final Cloud cloud, final ComputeTemplate template, final ExactZonesConfig zones, final String lookupLocatorsString, final Admin admin, final boolean isManagement, final File cloudFile, final GSAReservationId reservationId, final String templateName, final String securityProfile, final String keystorePassword, final String authGroups, final boolean rebootstrapping) throws FileNotFoundException { final InstallationDetails details = new InstallationDetails(); details.setBindToPrivateIp(cloud.getConfiguration().isConnectToPrivateIp()); details.setLocalDir(template.getAbsoluteUploadDir()); details.setRelativeLocalDir(template.getLocalDirectory()); details.setLocationId(md.getLocationId()); final String remoteDir = template.getRemoteDirectory(); details.setRemoteDir(remoteDir); // Create a copy of managementOnly files and mutate final List<String> managementOnlyFiles = new ArrayList<String>( cloud.getProvider().getManagementOnlyFiles()); if (template.getKeyFile() != null && isManagement) { // keyFile, if used, is always a management file. managementOnlyFiles.add(template.getKeyFile()); } details.setManagementOnlyFiles(managementOnlyFiles); details.setZones(StringUtils.collectionToCommaDelimitedString(zones.getZones())); details.setPrivateIp(md.getPrivateAddress()); details.setPublicIp(md.getPublicAddress()); details.setLocator(lookupLocatorsString); details.setCloudifyUrl(cloud.getProvider().getCloudifyUrl()); details.setOverridesUrl(cloud.getProvider().getCloudifyOverridesUrl()); details.setConnectedToPrivateIp(cloud.getConfiguration().isConnectToPrivateIp()); details.setAdmin(admin); details.setUsername(md.getRemoteUsername()); details.setPassword(md.getRemotePassword()); details.setRemoteExecutionMode(md.getRemoteExecutionMode()); details.setFileTransferMode(md.getFileTransferMode()); details.setScriptLanguage(md.getScriptLangeuage()); details.setCloudFile(cloudFile); details.setManagement(isManagement); final GridComponents componentsConfig = cloud.getConfiguration().getComponents(); GridCommandLineBuilder gridCommandBuilder = new GridCommandLineBuilder(); if (isManagement) { details.setConnectedToPrivateIp(!cloud.getConfiguration().isBootstrapManagementOnPublicIp()); details.setSecurityProfile(securityProfile); details.setKeystorePassword(keystorePassword); // setting management grid components command-line arguments final String esmCommandlineArgs = gridCommandBuilder .getEsmCommandlineArgs(componentsConfig.getOrchestrator(), rebootstrapping); final String lusCommandlineArgs = gridCommandBuilder .getLusCommandlineArgs(componentsConfig.getDiscovery(), lookupLocatorsString); final String gsmCommandlineArgs = gridCommandBuilder.getGsmCommandlineArgs(cloud, lookupLocatorsString, componentsConfig.getDeployer(), componentsConfig.getDiscovery()); details.setEsmCommandlineArgs(esmCommandlineArgs); details.setLusCommandlineArgs(lusCommandlineArgs); details.setGsmCommandlineArgs(gsmCommandlineArgs); // setting management services LRMI port range. details.setGscLrmiPortRange(componentsConfig.getUsm().getPortRange()); // setting web service ports and memory allocation details.setRestPort(componentsConfig.getRest().getPort()); details.setWebuiPort(componentsConfig.getWebui().getPort()); details.setRestMaxMemory(componentsConfig.getRest().getMaxMemory()); details.setWebuiMaxMemory(componentsConfig.getWebui().getMaxMemory()); } else { details.setConnectedToPrivateIp(cloud.getConfiguration().isConnectToPrivateIp()); } details.setGsaCommandlineArgs(gridCommandBuilder.getAgentCommandlineArgs(componentsConfig.getAgent(), details.isManagement() ? MANAGEMENT_ZONE : details.getZones())); // Add all template custom data fields starting with 'installer.' to the // installation details final Set<Entry<String, Object>> customEntries = template.getCustom().entrySet(); for (final Entry<String, Object> entry : customEntries) { if (entry.getKey().startsWith("installer.")) { details.getCustomData().put(entry.getKey(), entry.getValue()); } } // Handle key file if (md.getKeyFile() != null) { details.setKeyFile(md.getKeyFile().getAbsolutePath()); } else { final String keyFileName = template.getKeyFile(); if (!org.apache.commons.lang.StringUtils.isBlank(keyFileName)) { File keyFile = new File(keyFileName); if (!keyFile.isAbsolute()) { keyFile = new File(details.getLocalDir(), keyFileName); } if (!keyFile.isFile()) { throw new FileNotFoundException( "Could not find key file matching specified cloud configuration key file: " + template.getKeyFile() + ". Tried: " + keyFile + " but file does not exist"); } details.setKeyFile(keyFile.getAbsolutePath()); } } if (template.getHardwareId() != null) { details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_CLOUD_HARDWARE_ID, template.getHardwareId()); // maintain backwards for pre 2.3.0 details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.CLOUDIFY_CLOUD_HARDWARE_ID, template.getHardwareId()); } if (template.getImageId() != null) { details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_CLOUD_IMAGE_ID, template.getImageId()); // maintain backwards for pre 2.3.0 details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.CLOUDIFY_CLOUD_IMAGE_ID, template.getImageId()); } // Add the template privileged mode flag details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_AGENT_ENV_PRIVILEGED, Boolean.toString(template.isPrivileged())); // Add the template initialization command if (!org.apache.commons.lang.StringUtils.isBlank(template.getInitializationCommand())) { // the initialization command may include command separators (like // ';') so quote it final String command = template.getInitializationCommand(); final String quotedCommand = "\"" + command + "\""; details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_AGENT_ENV_INIT_COMMAND, quotedCommand); } // Add the template custom environment final Set<Entry<String, String>> entries = template.getEnv().entrySet(); for (final Entry<String, String> entry : entries) { details.getExtraRemoteEnvironmentVariables().put(entry.getKey(), entry.getValue()); } if (!org.apache.commons.lang.StringUtils.isBlank(template.getJavaUrl())) { details.getExtraRemoteEnvironmentVariables().put(CloudifyConstants.GIGASPACES_AGENT_ENV_JAVA_URL, template.getJavaUrl()); } details.setReservationId(reservationId); details.setTemplateName(templateName); details.setMachineId(md.getMachineId()); if (authGroups != null) { details.setAuthGroups(authGroups); } details.setDeleteRemoteDirectoryContents(md.isCleanRemoteDirectoryOnStart()); //add storage props that will be passed down to the bootstrap-management script. details.setPersistent(cloud.getConfiguration().getPersistentStoragePath() != null); if (md.getInstallerConfiguration() != null) { details.setInstallerConfiguration(md.getInstallerConfiguration()); } else { details.setInstallerConfiguration(template.getInstaller()); } logger.fine("Created InstallationDetails: " + details); return details; }
From source file:fr.landel.utils.io.FileSystemUtils.java
/** * To get the absolute path.//from w ww . j av a2 s . co m * * @param base * The base directory * @param filePath * The file to check * @return filePath, if it's absolute otherwise return 'base + filePath' */ public static String getAbsolutePath(final File base, final File filePath) { Assertor.that(base).isNotNull().and(filePath).isNotNull().orElseThrow(ERROR_PARAM_NULL); File file = filePath; if (!file.isAbsolute()) { file = new File(base, filePath.getPath()); } return file.getAbsolutePath(); }
From source file:org.apache.bookkeeper.util.Shell.java
/** Centralized logic to discover and validate the sanity of the Hadoop * home directory. Returns either NULL or a directory that exists and * was specified via either -Dhadoop.home.dir or the HADOOP_HOME ENV * variable. This does a lot of work so it should only be called * privately for initialization once per process. **///w w w . j a v a 2 s.c o m private static String checkHadoopHome() { // first check the Dflag hadoop.home.dir with JVM scope String home = System.getProperty("hadoop.home.dir"); // fall back to the system/user-global env variable if (home == null) { home = System.getenv("HADOOP_HOME"); } try { // couldn't find either setting for hadoop's home directory if (home == null) { throw new IOException("HADOOP_HOME or hadoop.home.dir are not set."); } if (home.startsWith("\"") && home.endsWith("\"")) { home = home.substring(1, home.length() - 1); } // check that the home setting is actually a directory that exists File homedir = new File(home); if (!homedir.isAbsolute() || !homedir.exists() || !homedir.isDirectory()) { throw new IOException("Hadoop home directory " + homedir + " does not exist, is not a directory, or is not an absolute path."); } home = homedir.getCanonicalPath(); } catch (IOException ioe) { LOG.error("Failed to detect a valid hadoop home directory", ioe); home = null; } return home; }