Example usage for java.io File getCanonicalFile

List of usage examples for java.io File getCanonicalFile

Introduction

In this page you can find the example usage for java.io File getCanonicalFile.

Prototype

public File getCanonicalFile() throws IOException 

Source Link

Document

Returns the canonical form of this abstract pathname.

Usage

From source file:hudson.Util.java

/**
 * Checks if the given file represents a symlink.
 *//*from w w w .j a  v a 2s.c o  m*/
//Taken from http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?view=markup
public static boolean isSymlink(File file) throws IOException {
    String name = file.getName();
    if (name.equals(".") || name.equals(".."))
        return false;

    File fileInCanonicalParent = null;
    File parentDir = file.getParentFile();
    if (parentDir == null) {
        fileInCanonicalParent = file;
    } else {
        fileInCanonicalParent = new File(parentDir.getCanonicalPath(), name);
    }
    return !fileInCanonicalParent.getCanonicalFile().equals(fileInCanonicalParent.getAbsoluteFile());
}

From source file:info.fetter.logstashforwarder.FileState.java

public FileState(File file) throws IOException {
    this.file = file;
    directory = file.getCanonicalFile().getParent();
    fileName = file.getName();//from w w w  . ja va  2 s.  c o m
    randomAccessFile = new RandomAccessFile(file.getPath(), "r");
    lastModified = file.lastModified();
    size = file.length();
}

From source file:org.walkmod.util.FileResource.java

public void setFile(File file) throws Exception {
    this.file = file.getCanonicalFile();
}

From source file:com.heliosdecompiler.helios.tasks.AddFilesTask.java

@Override
public void run() {
    try {//www  .  j a va  2s .  c o m
        for (File file : files) {
            if (file != null && file.exists()) {
                try {
                    file = file.getCanonicalFile();
                } catch (IOException ignored) {
                }
                if (addToRecentFiles)
                    Helios.addRecentFile(file);
                try {
                    handle(file);
                } catch (IOException e) {
                    ExceptionHandler.handle(e);
                }
            }
        }
    } finally {
        Events.callEvent(new TreeUpdateRequest());
    }
}

From source file:org.jresponder.standalone.JrContextLoaderListener.java

/**
 * Finds the external configuration file and sets it so that
 * getExternalConfigFile() will return it.  If found it also sets
 * the system property jresponder.basedir so this can be used in
 * the Spring configuration./* w w  w  .j  ava 2s. co m*/
 */
@Override
public void contextInitialized(ServletContextEvent aServletContextEvent) {

    File myDir = new File(aServletContextEvent.getServletContext().getRealPath("/"));
    try {
        for (int i = 0; i < 20; i++) {
            File myConfFile = new File(myDir, "conf/jresponder.xml");
            if (myConfFile.exists()) {
                externalConfigFile = myConfFile.getCanonicalFile();
                System.setProperty("jresponder.basedir", myDir.getCanonicalPath());
                standaloneMode = true;

                File myLog4jPropertiesFile = new File(myDir, "conf/log4j.properties");
                if (myLog4jPropertiesFile.exists()) {
                    Log4jConfigurer.initLogging(myLog4jPropertiesFile.getCanonicalPath(), 1000);
                    didStartLogging = true;
                }

                break;
            }
            myDir = new File(myDir, "..");
        }
    } catch (IOException e) {
        // should not happen
        e.printStackTrace();
    }

    // the rest is over to the Spring default
    super.contextInitialized(aServletContextEvent);

}

From source file:unUtils.WikittyPublication.java

/**
 * Relocate the default url of the wikitty service
 *//*w  w  w .j a  v a2s .  co m*/
static public void relocateWikitty() throws Exception {

    /*
     * log.info("checkout : wikittyservice: " + wikittyService +
     * " noresursion=" + noRecur + " directory= " + dir.getAbsolutePath()
     * +"Label a checkout " +label+ "HessianProtocol="+hessianProtocole);
     */

    File dir = applicationConfig.getOptionAsFile(WikittyPublication.DIRECTORY_KEY);
    String wikittyService = applicationConfig.getOption(WikittyPublication.WITTY_SERVICE_KEY);
    boolean hessianProtocole = applicationConfig.getOptionAsBoolean(WikittyPublication.HESSIAN_PROTOCOL_KEY);

    File wpHomeDir;

    System.out.println("search the directory of .wp file to write new properties file");
    // search for the home directory
    if (null == dir || !dir.exists()) {
        wpHomeDir = WikittyPublicationFileSystem.searchWikittyPublicationHomeDir(new File("."));
    } else {
        wpHomeDir = new File(
                dir.getCanonicalFile() + File.separator + WikittyPublicationFileSystem.PROPERTY_DIRECTORY);
    }

    Properties oldProperties = new Properties();

    //  mfortun-2011-04-06 catch exception instead of throws
    File propertiesFile = new File(
            wpHomeDir + File.separator + WikittyPublicationFileSystem.WIKITTYPUBLICATION_PROPERTIES_FILE);
    // load the old file just for loggin
    oldProperties.load(new FileReader(propertiesFile));

    log.info("Try relocate :" + "wikitty service:"
            + oldProperties.getProperty(WikittyPublication.WITTY_SERVICE_KEY) + " by " + wikittyService
            + " HessianProtocol: " + hessianProtocole + " File : " + propertiesFile.getCanonicalPath());

    // Creation of the new properties file
    Properties props = new Properties();
    props.put(WikittyPublication.WITTY_SERVICE_KEY, wikittyService);
    if (hessianProtocole) {
        props.put("wikitty.WikittyService.components",
                "org.nuiton.wikitty.services.WikittyServiceHessianClient");
    } else {
        props.put("wikitty.WikittyService.components", "org.nuiton.wikitty.services.WikittyServiceCajoClient");
    }

    // save the new property file
    props.store(new FileWriter(propertiesFile), "");

    /*
     * on va commencer par vrifier les arguments ''wp relocate [nouvelle
     * url du WikittyService par defaut] [directory a relocaliser]'' on doit
     * avoir trois string dans le unparsed: url et directory
     */

}

From source file:org.wso2.codegen.service.WSDLMetaDataFactory.java

protected String getBaseURI(String currentURI) {
    try {//from   w w w.j  a va 2 s  .  c  o  m
        File file = new File(currentURI);
        if (file.exists()) {
            return file.getCanonicalFile().getParentFile().toURI().toString();
        }
        String uriFragment = currentURI.substring(0, currentURI.lastIndexOf("/"));
        return uriFragment + (uriFragment.endsWith("/") ? "" : "/");
    } catch (IOException e) {
        return null;
    }
}

From source file:com.izforge.izpack.event.AntActionLogBuildListener.java

public AntActionLogBuildListener(File logFile, boolean append, int level) {
    this.setMessageOutputLevel(level);
    if (logFile != null) {
        PrintStream printStream;/*from   www  .java 2 s.  com*/
        try {
            final File canonicalLogFile = logFile.getCanonicalFile();
            FileUtils.forceMkdir(canonicalLogFile.getParentFile());
            FileUtils.touch(canonicalLogFile);
            printStream = new PrintStream(new FileOutputStream(canonicalLogFile, append));
            this.setOutputPrintStream(printStream);
            this.setErrorPrintStream(printStream);
        } catch (IOException e) {
            logger.warning("Cannot log to file '" + logFile + "': " + e.getMessage());
            this.setOutputPrintStream(System.out);
            this.setErrorPrintStream(System.err);
        }
    } else {
        this.setOutputPrintStream(System.out);
        this.setErrorPrintStream(System.err);
    }
}

From source file:org.apache.openejb.maven.plugin.customizer.monkey.jar.JarPatcher.java

private void jar(final int method, final JarArchiveOutputStream jar, final File f, final String prefix)
        throws IOException {
    final String path = f.getPath().replace(prefix, "").replace(File.separator, "/");
    final ZipArchiveEntry zip = new ZipArchiveEntry(f, path);
    zip.setMethod(method);/* w w w  .  j  a va  2s.  c  om*/
    final JarArchiveEntry archiveEntry = new JarArchiveEntry(zip);
    jar.putArchiveEntry(archiveEntry);
    if (f.isDirectory()) {
        jar.closeArchiveEntry();
        final File[] files = f.listFiles();
        if (files != null) {
            for (final File child : files) {
                jar(method, jar, child.getCanonicalFile(), prefix);
            }
        }
    } else {
        final InputStream is = new FileInputStream(f);
        IOUtils.copy(is, jar);
        is.close();
        jar.closeArchiveEntry();
    }
}

From source file:org.app.enjoy.musicplayer.FileExplorerActivity.java

@Subscribe
public void onClickFile(FileExplorerEvents.OnClickFile event) {
    File f = event.mFile;
    try {/*  w w w.j  av a  2 s. c  o m*/
        f = f.getAbsoluteFile();
        f = f.getCanonicalFile();
        if (TextUtils.isEmpty(f.toString()))
            f = new File("/");
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (f.isDirectory()) {
        String path = f.toString();
        //            mSettings.setLastDirectory(path);
        doOpenDirectory(path, true);
    } else if (f.exists()) {
        if (f.getPath().toLowerCase().endsWith(".iso")) {
            List<MusicData> list = MusicUtil.parseISO(f.getPath());
            if (list != null && list.size() > 0) {
                getPopupWindow(list);
                popupWindow.showAtLocation(this.getCurrentFocus(), Gravity.CENTER, 0, 0);
            } else {
                Toast.makeText(FileExplorerActivity.this, "ISO ??", Toast.LENGTH_SHORT);
            }
        }
    }
}