List of usage examples for java.io File getCanonicalFile
public File getCanonicalFile() throws IOException
From source file:com.asakusafw.operation.tools.hadoop.fs.CleanTest.java
private File touch(String path, double day) throws IOException { File file = file(path);//from w w w .j a va 2 s . c om if (file.exists() == false) { file.getParentFile().mkdirs(); try { file.createNewFile(); } catch (IOException e) { throw new AssertionError(e); } } File root = folder.getRoot().getCanonicalFile(); File current = file; while (true) { current = current.getCanonicalFile(); if (root.equals(current)) { break; } boolean succeed = current.setLastModified((long) (day * TimeUnit.DAYS.toMillis(1))); if (succeed == false) { break; } current = current.getParentFile(); if (current == null) { break; } } return file; }
From source file:edu.harvard.med.iccbl.screensaver.io.AdminEmailApplication.java
public final EmailService getEmailServiceBasedOnCommandLineOption() { EmailService emailService = null;/*from www . j ava 2 s .c om*/ if (isCommandLineFlagSet(NO_NOTIFY_OPTION[SHORT_OPTION_INDEX])) { emailService = new EmailService() { public void send(String subject, String message, InternetAddress from, InternetAddress[] recipients, InternetAddress[] cclist) throws MessagingException { try { send(subject, message, from, recipients, cclist, null); } catch (IOException e) { // this shall never happen e.printStackTrace(); } } public void send(String subject, String message, InternetAddress from, InternetAddress[] recipients, InternetAddress[] cclist, File attachedFile) throws MessagingException, IOException { log.info("Mock Email (Not Sent):\n" + SmtpEmailService.printEmail(subject, message, from, null, recipients, cclist, (attachedFile == null ? "" : "" + attachedFile.getCanonicalFile()))); } }; } else if (isCommandLineFlagSet(TEST_EMAIL_ONLY[SHORT_OPTION_INDEX])) { InternetAddress adminEmail = null; try { adminEmail = new InternetAddress(findAdministratorUser().getEmail()); } catch (AddressException e) { String msg = "Admin account used has an email problem: " + printUserInformation(findAdministratorUser()); throw new IllegalArgumentException(msg, e); } final InternetAddress finalAdminEmail = adminEmail; final EmailService wrappedEmailService = (EmailService) getSpringBean("emailService"); emailService = new EmailService() { public void send(String subject, String message, InternetAddress from, InternetAddress[] recipients, InternetAddress[] cclist) throws MessagingException { try { send(subject, message, from, recipients, cclist, null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void send(String subject, String message, InternetAddress from, InternetAddress[] recipients, InternetAddress[] ccrecipients, File attachedFile) throws MessagingException, IOException { message = "Testing Email Wrapper: redirect email to admin, original email to be sent to:\n" + Arrays.asList(recipients) + "\n=======message=========\n" + message; wrappedEmailService.send("Redirected to: " + finalAdminEmail + ", Subject: " + subject, message, finalAdminEmail, new InternetAddress[] { finalAdminEmail }, null, attachedFile); } }; } else { emailService = (EmailService) getSpringBean("emailService"); } return emailService; }
From source file:dk.netarkivet.archive.bitarchive.BitarchiveAdmin.java
/** * Checks whether a directory is one of the known bitarchive directories. * * @param theDir The dir to check//from w w w .ja v a2 s. c om * @return true If it is a valid archive directory; otherwise returns false. * @throws IOFailure if theDir or one of the valid archive directories * does not exist * @throws ArgumentNotValid if theDir is null */ protected boolean isBitarchiveDirectory(File theDir) throws ArgumentNotValid, IOFailure { ArgumentNotValid.checkNotNull(theDir, "File theDir"); try { return archivedFiles.containsKey(theDir.getCanonicalFile()); } catch (IOException e) { throw new IOFailure("Could not retrieve the canonical file for '" + theDir + "'.", e); } }
From source file:org.sonar.dotnet.tools.commons.visualstudio.VisualStudioProject.java
/** * Gets the relative path of a file contained in the project. <br> * For example, if the visual studio project is C:/MySolution/MyProject/MyProject.csProj and the file is * C:/MySolution/MyProject/Dummy/Foo.cs, then the result is Dummy/Foo.cs * // w ww. ja v a2s .c om * @param file * the file whose relative path is to be computed * @return the relative path, or <code>null</code> if the file is not in the project subdirectories */ public String getRelativePath(File file) { File canonicalDirectory; try { canonicalDirectory = directory.getCanonicalFile(); File canonicalFile = file.getCanonicalFile(); String filePath = canonicalFile.getPath(); String directoryPath = canonicalDirectory.getPath(); if (!filePath.startsWith(directoryPath)) { // The file is not in the directory return null; } return StringUtils.removeStart(StringUtils.removeStart(filePath, directoryPath), "\\"); } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("io exception with file " + file, e); } return null; } }
From source file:org.jfrog.build.extractor.maven.BuildDeploymentHelper.java
private File saveBuildInfoToFile(Build build, ArtifactoryClientConfiguration clientConf, File basedir) { String outputFile = clientConf.getExportFile(); File buildInfoFile = StringUtils.isBlank(outputFile) ? new File(basedir, "target/build-info.json") : new File(outputFile); logger.debug("Build Info Recorder: " + BuildInfoConfigProperties.EXPORT_FILE + " = " + outputFile); logger.info("Artifactory Build Info Recorder: Saving Build Info to '" + buildInfoFile + "'"); try {/*from w w w. j av a 2 s.c o m*/ BuildInfoExtractorUtils.saveBuildInfoToFile(build, buildInfoFile.getCanonicalFile()); } catch (IOException e) { throw new RuntimeException("Error occurred while persisting Build Info to '" + buildInfoFile + "'", e); } return buildInfoFile; }
From source file:org.apache.hadoop.security.KerberosDiags.java
/** * Dump a keytab: list all principals./* ww w . j ava2 s. com*/ * @param keytabFile the keytab file * @throws IOException IO problems */ public void dumpKeytab(File keytabFile) throws IOException { title("Examining keytab %s", keytabFile); File kt = keytabFile.getCanonicalFile(); failif(!kt.exists(), CAT_CONFIG, "Keytab not found: %s", kt); failif(!kt.isFile(), CAT_CONFIG, "Keytab is not a valid file: %s", kt); String[] names = getPrincipalNames(keytabFile.getCanonicalPath(), Pattern.compile(".*")); println("keytab entry count: %d", names.length); for (String name : names) { println(" %s", name); } println("-----"); }
From source file:com.redhat.rcm.version.mgr.VersionManager.java
public Set<File> modifyVersions(File pom, final List<String> boms, final String toolchain, final VersionManagerSession session) throws VManException { try {//ww w . j a va 2 s.c o m pom = pom.getCanonicalFile(); } catch (final IOException e) { pom = pom.getAbsoluteFile(); } configureSession(boms, toolchain, session, pom); final Set<File> result = modVersions(pom.getParentFile(), session, true, pom); if (!result.isEmpty()) { final File out = result.iterator().next(); logger.info("Modified POM versions.\n\n\tTop POM: " + out + "\n\tBOMs:\t" + (boms == null ? "-NONE-" : StringUtils.join(boms.iterator(), "\n\t\t")) + "\n\tPOM Backups: " + session.getBackups() + "\n\n"); } return result; }
From source file:org.apache.servicemix.jbi.deployer.impl.ComponentInstaller.java
protected ClassLoader createClassLoader(Bundle bundle, String name, String[] classPathNames, boolean parentFirst, SharedLibrary[] sharedLibs) { // Create parents classloaders ClassLoader[] parents;/*from ww w. j av a2 s . c om*/ if (sharedLibs != null) { parents = new ClassLoader[sharedLibs.length + 2]; for (int i = 0; i < sharedLibs.length; i++) { parents[i] = sharedLibs[i].getClassLoader(); } } else { parents = new ClassLoader[2]; } parents[parents.length - 2] = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle, getClass().getClassLoader()); parents[parents.length - 1] = BundleDelegatingClassLoader .createBundleClassLoaderFor(getBundleContext().getBundle(0)); // Create urls List<URL> urls = new ArrayList<URL>(); for (int i = 0; i < classPathNames.length; i++) { File f = new File(installRoot, classPathNames[i]); if (!f.exists()) { LOGGER.warn("Component classpath entry not found: '" + classPathNames[i] + "'"); } try { urls.add(f.getCanonicalFile().toURL()); } catch (IOException e) { throw new IllegalArgumentException( "Component classpath entry not found: '" + classPathNames[i] + "'"); } } // Create classloader return new MultiParentClassLoader(name, urls.toArray(new URL[urls.size()]), parents, !parentFirst, new String[0], new String[] { "java.", "javax." }); }
From source file:com.opengamma.engine.position.csv.CSVPositionSource.java
/** * Creates a CSV position source using the specified directory. * @param baseDirectory the directory, not null *//* w w w.j av a 2s .c o m*/ public CSVPositionSource(File baseDirectory) { ArgumentChecker.notNull(baseDirectory, "base directory"); if (baseDirectory.exists() == false) { throw new IllegalArgumentException("Base directory must exist: " + baseDirectory); } if (baseDirectory.isDirectory() == false) { throw new IllegalArgumentException("Base directory must be a directory: " + baseDirectory); } try { _baseDirectory = baseDirectory.getCanonicalFile(); } catch (IOException ex) { throw new OpenGammaRuntimeException( "Base directory must resolve to a canonical reference: " + baseDirectory, ex); } populatePortfolioIds(); }