Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

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

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:dk.netarkivet.common.utils.ZipUtils.java

/** Unzip a zipFile into a directory.  This will create subdirectories
 * as needed.//from w w w  . j  a va  2s . com
 *
 * @param zipFile The file to unzip
 * @param toDir The directory to create the files under.  This directory
 * will be created if necessary.  Files in it will be overwritten if the
 * filenames match.
 */
public static void unzip(File zipFile, File toDir) {
    ArgumentNotValid.checkNotNull(zipFile, "File zipFile");
    ArgumentNotValid.checkNotNull(toDir, "File toDir");
    ArgumentNotValid.checkTrue(toDir.getAbsoluteFile().getParentFile().canWrite(),
            "can't write to '" + toDir + "'");
    ArgumentNotValid.checkTrue(zipFile.canRead(), "can't read '" + zipFile + "'");
    InputStream inputStream = null;
    ZipFile unzipper = null;
    try {
        try {
            unzipper = new ZipFile(zipFile);
            Enumeration<? extends ZipEntry> entries = unzipper.entries();
            while (entries.hasMoreElements()) {
                ZipEntry ze = entries.nextElement();
                File target = new File(toDir, ze.getName());
                // Ensure that its dir exists
                FileUtils.createDir(target.getCanonicalFile().getParentFile());
                if (ze.isDirectory()) {
                    target.mkdir();
                } else {
                    inputStream = unzipper.getInputStream(ze);
                    FileUtils.writeStreamToFile(inputStream, target);
                    inputStream.close();
                }
            }
        } finally {
            if (unzipper != null) {
                unzipper.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
        }
    } catch (IOException e) {
        throw new IOFailure("Failed to unzip '" + zipFile + "'", e);
    }
}

From source file:Main.java

public static boolean isSymlink(File file) throws IOException {
    if (file == null) {
        throw new NullPointerException("File must not be null");
    }/*w  w w  .  ja  va2 s .c o  m*/
    if (isSystemWindows()) {
        return false;
    }
    File fileInCanonicalDir = null;
    if (file.getParent() == null) {
        fileInCanonicalDir = file;
    } else {
        File canonicalDir = file.getParentFile().getCanonicalFile();
        fileInCanonicalDir = new File(canonicalDir, file.getName());
    }

    return !fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile());
}

From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java

public static File getDigitvWorkOutputFile(TranscodeRequest request, ServletConfig config) {
    File rootDir = getBaseOutputDir(request, config);
    log.trace("Output directory is: '" + rootDir + "'");
    String filename = getDigitvProgramFilename(request);
    File result = new File(rootDir, filename);
    log.trace("Resulting filename: " + result.getAbsoluteFile());
    return result;
}

From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java

public static File getDigitvDoneFile(TranscodeRequest request, ServletConfig config) {
    String rootDir = Util.getInitParameter(config, Constants.DIGITV_FINAL_DIR_INIT_PARAM);
    log.trace("Output directory is: '" + rootDir + "'");
    String filename = getDigitvProgramFilename(request);
    File result = new File(rootDir, filename);
    log.trace("Resulting filename: " + result.getAbsoluteFile());
    return result;
}

From source file:de.uzk.hki.da.utils.FolderUtils.java

public static List<String> listFolderContents(File folder) {
    String[] fileNames = folder.list();

    List<String> fileList = new ArrayList<String>();

    for (String fileName : fileNames) {
        if (new File(folder.getAbsolutePath() + "/" + fileName).isDirectory()) {
            List<String> folderFileNames = listFolderContents(
                    new File(folder.getAbsoluteFile() + "/" + fileName));
            for (String folderFileName : folderFileNames)
                fileList.add(fileName + "/" + folderFileName);
        } else//from   ww  w. ja v a  2 s  . c  o m
            fileList.add(fileName);
    }

    return fileList;
}

From source file:media_organizer.MediaInspector.java

private static boolean symbolicLink(File file) throws IOException {
    if (file == null) {
        throw new NullPointerException("NULL file object!");
    }// w ww  .  j  a v a2 s  . co  m
    File canonicalFile;
    if (file.getParent() == null) {
        canonicalFile = file;
    } else {
        File canonicalDir = file.getParentFile().getCanonicalFile();
        canonicalFile = new File(canonicalDir, file.getName());
    }
    return !canonicalFile.getCanonicalFile().equals(canonicalFile.getAbsoluteFile());
}

From source file:mitm.common.tools.SendMail.java

private static MimeMessage loadMessage(String filename) throws FileNotFoundException, MessagingException {
    File mail = new File(filename);

    mail = mail.getAbsoluteFile();

    MimeMessage message = MailUtils.loadMessage(mail);

    return message;
}

From source file:de.upb.wdqa.wdvd.FeatureExtractor.java

public static int main2(String[] args) {
    int result = 0;

    try {/*from w  w  w  .  j a  va  2s .c  o  m*/
        FeatureExtractorConfiguration config = new FeatureExtractorConfiguration(args);

        File featureFile = config.getFeatureFile();
        initLogger(featureFile.getAbsoluteFile() + ".log");
        logConfiguration(config);

        executePipeline(config);

        logger.info("Feature Extraction finished!");

        if (ErrorFlagAppender.hasErrorOccured()) {
            result = 1;

            logger.error("##################################################");
            logger.error("# AN ERROR HAS OCCURED DURING FEATURE EXTRACTION #");
            logger.error("##################################################");
        }

    } catch (Throwable t) {
        logger.error("", t);
        result = 1;
    } finally {
        try {
            closeLogger();
        } catch (Throwable t) {
            System.err.println(t);
        }
    }

    return result;
}

From source file:test.org.tradex.camel.TestCaseAppContextBuilder.java

/**
 * Creates a new application context using the file found at <code>ROOT_RESOURCE_DIR + clazz.getPackageName + fileName</code>
 * @param fileName The filename in the calculated directory
 * @param clazz The clazz we're launching the app context for
 * @return the app context/*from  w w w. j av  a2  s  . c o  m*/
 */
public static GenericXmlApplicationContext buildFor(String fileName, Class<?> clazz) {
    if (clazz == null)
        throw new IllegalArgumentException("Passed class was null", new Throwable());
    File springXml = new File(
            ROOT_RESOURCE_DIR + clazz.getPackage().getName().replace('.', '/') + "/" + fileName);
    if (!springXml.canRead()) {
        throw new RuntimeException("Failed to read Spring XML file at [" + springXml + "]", new Throwable());
    }
    return service(new GenericXmlApplicationContext(
            new FileSystemResource[] { new FileSystemResource(springXml.getAbsoluteFile()) }));
}

From source file:com.meltmedia.cadmium.core.FileSystemManager.java

public static String getFileIfCanRead(String path, String file) {
    File fileObj = new File(path, file);
    if (fileObj.canRead()) {
        return fileObj.getAbsoluteFile().getAbsolutePath();
    }/*from w w w .  j  a v a  2s .c  o  m*/
    return null;
}