List of usage examples for java.io File getCanonicalFile
public File getCanonicalFile() throws IOException
From source file:com.cloudera.recordbreaker.analyzer.FSAnalyzer.java
/** * Inits (and optionally creates) a new <code>FSAnalyzer</code> instance. *///from w w w .j a va2 s . co m public FSAnalyzer(File metadataStore, File schemaDir) throws IOException, SQLiteException { boolean isNew = false; metadataStore = metadataStore.getCanonicalFile(); if (!metadataStore.exists()) { isNew = true; } this.dbQueue = new SQLiteQueue(metadataStore); this.dbQueue.start(); if (isNew) { createTables(); } this.formatAnalyzer = new FormatAnalyzer(schemaDir); FSAnalyzer.fsaInstance = this; }
From source file:org.ow2.mind.unit.Launcher.java
/** * Inspired by Mindoc's DocumentationIndexGenerator. * @throws IOException/* w ww . j a v a 2s. c om*/ */ protected void listTestFolderADLs() { logger.info("Searching for .adl files in the target directories..."); for (final File directory : validTestFoldersList) { try { exploreDirectory(directory.getCanonicalFile(), null); } catch (IOException e) { logger.severe(String.format("Cannot find directory '%s' - skipped.", directory.getPath())); } } }
From source file:org.apache.maven.cli.MavenCli.java
void initialize(CliRequest cliRequest) throws ExitException { if (cliRequest.workingDirectory == null) { cliRequest.workingDirectory = System.getProperty("user.dir"); }//from w w w. j a va 2 s . c o m if (cliRequest.multiModuleProjectDirectory == null) { String basedirProperty = System.getProperty(MULTIMODULE_PROJECT_DIRECTORY); if (basedirProperty == null) { System.err.format( "-D%s system property is not set." + " Check $M2_HOME environment variable and mvn script match.", MULTIMODULE_PROJECT_DIRECTORY); throw new ExitException(1); } File basedir = basedirProperty != null ? new File(basedirProperty) : new File(""); try { cliRequest.multiModuleProjectDirectory = basedir.getCanonicalFile(); } catch (IOException e) { cliRequest.multiModuleProjectDirectory = basedir.getAbsoluteFile(); } } // // Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative // Windows paths. // String mavenHome = System.getProperty("maven.home"); if (mavenHome != null) { System.setProperty("maven.home", new File(mavenHome).getAbsolutePath()); } }
From source file:org.apache.hadoop.hive.ql.QTestUtil.java
public static void addTestsToSuiteFromQfileNames(String qFileNamesFile, Set<String> qFilesToExecute, TestSuite suite, Object setup, SuiteAddTestFunctor suiteAddTestCallback) { try {/*w w w .j a v a 2s.c om*/ File qFileNames = new File(qFileNamesFile); FileReader fr = new FileReader(qFileNames.getCanonicalFile()); BufferedReader br = new BufferedReader(fr); String fName = null; while ((fName = br.readLine()) != null) { if (fName.isEmpty() || fName.trim().equals("")) { continue; } int eIdx = fName.indexOf('.'); if (eIdx == -1) { continue; } String tName = fName.substring(0, eIdx); if (qFilesToExecute.isEmpty() || qFilesToExecute.contains(fName)) { suiteAddTestCallback.addTestToSuite(suite, setup, tName); } } br.close(); } catch (Exception e) { Assert.fail("Unexpected exception " + org.apache.hadoop.util.StringUtils.stringifyException(e)); } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.AbstractWarPackagingTask.java
/** * Copy file from source to destination. The directories up to <code>destination</code> will be created if they * don't already exist. if the <code>onlyIfModified</code> flag is <tt>false</tt>, <code>destination</code> will be * overwritten if it already exists. If the flag is <tt>true</tt> destination will be overwritten if it's not up to * date./*w w w.j a va 2 s.c om*/ * <p/> * * @param context the packaging context * @param source an existing non-directory <code>File</code> to copy bytes from * @param destination a non-directory <code>File</code> to write bytes to (possibly overwriting). * @param targetFilename the relative path of the file from the webapp root directory * @param onlyIfModified if true, copy the file only if the source has changed, always copy otherwise * @return true if the file has been copied/updated, false otherwise * @throws IOException if <code>source</code> does not exist, <code>destination</code> cannot be written to, or an * IO error occurs during copying */ protected boolean copyFile(WarPackagingContext context, File source, File destination, String targetFilename, boolean onlyIfModified) throws IOException { if (onlyIfModified && destination.lastModified() >= source.lastModified()) { context.getLog().debug(" * " + targetFilename + " is up to date."); return false; } else { if (source.isDirectory()) { context.getLog().warn(" + " + targetFilename + " is packaged from the source folder"); try { JarArchiver archiver = context.getJarArchiver(); archiver.addDirectory(source); archiver.setDestFile(destination); archiver.createArchive(); } catch (ArchiverException e) { String msg = "Failed to create " + targetFilename; context.getLog().error(msg, e); IOException ioe = new IOException(msg); ioe.initCause(e); throw ioe; } } else { FileUtils.copyFile(source.getCanonicalFile(), destination); // preserve timestamp destination.setLastModified(source.lastModified()); context.getLog().debug(" + " + targetFilename + " has been copied."); } return true; } }
From source file:cn.com.sinosoft.util.io.FileUtils.java
/** * Compares the contents of two files to determine if they are equal or not. * <p>//from w w w . j a v a 2 s . co m * This method checks to see if the two files are different lengths * or if they point to the same file, before resorting to byte-by-byte * comparison of the contents. * <p> * Code origin: Avalon * * @param file1 the first file * @param file2 the second file * @return true if the content of the files are equal or they both don't * exist, false otherwise * @throws IOException in case of an I/O error */ public static boolean contentEquals(File file1, File file2) throws IOException { boolean file1Exists = file1.exists(); if (file1Exists != file2.exists()) { return false; } if (!file1Exists) { // two not existing files are equal return true; } if (file1.isDirectory() || file2.isDirectory()) { // don't want to compare directory contents throw new IOException("Can't compare directories, only files"); } if (file1.length() != file2.length()) { // lengths differ, cannot be equal return false; } if (file1.getCanonicalFile().equals(file2.getCanonicalFile())) { // same file return true; } InputStream input1 = null; InputStream input2 = null; try { input1 = new FileInputStream(file1); input2 = new FileInputStream(file2); return IOUtils.contentEquals(input1, input2); } finally { IOUtils.closeQuietly(input1); IOUtils.closeQuietly(input2); } }
From source file:edu.ku.brc.specify.tools.FormDisplayer.java
/** * Creates an HTML file listing all the forms/Views. *///from www .ja v a 2 s . c o m public void createViewListing(final String path, final boolean doShowInBrowser) { String fullPath = (path != null ? path + File.separator : "") + "views.html"; //$NON-NLS-1$ //$NON-NLS-2$ createHTMLFile(fullPath, getResourceString("FormDisplayer.VIEWS")); //$NON-NLS-1$ processDir("Common", XMLHelper.getConfigDir("common")); //$NON-NLS-1$ //$NON-NLS-2$ processDir("Backstop", XMLHelper.getConfigDir("backstop")); //$NON-NLS-1$ //$NON-NLS-2$ for (File file : new File(XMLHelper.getConfigDirPath(".")).listFiles()) //$NON-NLS-1$ { if (file.isDirectory() && !file.getName().equals("common") && //$NON-NLS-1$ !file.getName().equals("backstop") && //$NON-NLS-1$ !file.getName().startsWith(".")) //$NON-NLS-1$ { processDir(file.getName(), XMLHelper.getConfigDir(file.getName())); } } pw.println("</body><html>"); //$NON-NLS-1$ pw.flush(); pw.close(); try { if (doShowInBrowser) { AttachmentUtils.openURI(file.toURI()); } else { JOptionPane.showMessageDialog(getTopWindow(), String.format(getResourceString("FormDisplayer.OUTPUT"), file.getCanonicalFile())); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.agnitas.util.AgnUtils.java
public static String getHelpURL(HttpServletRequest req) { String base = "help_" + getAdmin(req).getAdminLang().toLowerCase(); String name = req.getServletPath(); String path = null;/*from w w w .j a va2 s. c o m*/ File rel = null; File file = null; name = name.substring(0, name.length() - 4); rel = new File(name); while (rel.getParent() != null) { path = req.getSession().getServletContext().getRealPath(base + rel.getAbsoluteFile() + ".htm"); file = new File(path); if (file.exists()) { try { return base + rel.getCanonicalFile() + ".htm"; } catch (Exception e) { logger.error("getHelpURL", e); } } rel = new File(rel.getParent()); } return base + "/index.jsp"; }
From source file:com.symbian.driver.core.controller.tasks.ExecuteTransferSet.java
/** * Installs a SIS file to the Symbian device. Use if Platform Security * (PlatSec) is on./* w w w . j a v a2 s .c om*/ * * @param aSisFile * The sis file to set the package to. * @return * @throws IOException * If the SIS file location on the PC is invalid. * @throws JStatException * If the transfering/installing of the SIS file causes an * exception. * @throws TimeLimitExceededException * If the aTimeOut is exceeded. * @throws JStatException */ public void installSis(final File aSisFile) throws IOException, TimeLimitExceededException { LOGGER.fine("Setting SIS file to: " + aSisFile.getAbsolutePath()); String lSisName = aSisFile.getName().toLowerCase(); iUid = lSisName.substring(lSisName.indexOf("0x"), lSisName.indexOf(".sis")); String lSymbianSisFile = getSymbianSisFile(); if (aSisFile.isFile()) { // Sending SIS file LOGGER.fine("Sending file: " + aSisFile + " to " + lSymbianSisFile); DeviceCommsProxy lDeviceProxy = null; try { lDeviceProxy = DeviceCommsProxy.getInstance(); } catch (Exception lException) { throw new IOException("Could not load comms proxy." + lException.getMessage()); } if (lDeviceProxy.createSymbianTransfer().send(aSisFile.getCanonicalFile(), new File(lSymbianSisFile))) { // Install SIS file LOGGER.fine("Installing sis file: " + lSymbianSisFile); if (!lDeviceProxy.createSymbianProcess().install(new File(lSymbianSisFile), iPkgFile)) { throw new IOException("Failed to install SIS file: " + aSisFile); } } else { throw new IOException("Failed to transfer SIS file: " + aSisFile); } } else { throw new IOException("Incorrect SIS file: " + aSisFile); } }
From source file:de.ailis.xadrian.frames.MainFrame.java
/** * Returns the complex editor for the specified file. If no complex editor * is open for this file then null is returned. * * @param file/*from w w w .ja v a 2 s .c o m*/ * The file * @return The complex editor or null if none is open for this file. */ public ComplexEditor getEditor(final File file) { for (int i = this.tabs.getTabCount() - 1; i >= 0; i -= 1) { final Component component = this.tabs.getComponentAt(i); if (!(component instanceof ComplexEditor)) continue; final ComplexEditor editor = (ComplexEditor) component; final File editorFile = editor.getFile(); if (editorFile == null) continue; try { if (file.getCanonicalFile().equals(editorFile.getCanonicalFile())) return editor; } catch (final IOException e) { if (file.equals(editorFile)) return editor; } } return null; }