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:br.edimarmanica.trinity.intrasitemapping.auto.MergeOffsets.java

private void executeOffset(int indexOffset) {
    File dir = new File(Paths.PATH_TRINITY + site.getPath() + "/offset");
    try (Reader in = new FileReader(dir.getAbsoluteFile() + "/result_" + indexOffset + ".csv")) {
        List<List<String>> lines = new ArrayList<>();
        try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL)) {

            int indexRegistro = 0;
            for (CSVRecord record : parser) {
                if (indexOffset != 0 && indexRegistro < Extract.NR_SHARED_PAGES) { //seno vai extrair repetido
                    indexRegistro++;/*from  w  ww  .  j av  a2  s . c  om*/
                    continue;
                }
                List<String> line = new ArrayList<>();
                for (int nrRegra = 0; nrRegra < record.size(); nrRegra++) {
                    try {
                        line.add(Preprocessing.filter(record.get(nrRegra)));
                    } catch (InvalidValue ex) {
                        line.add("");
                    }
                }
                lines.add(line);
                indexRegistro++;
            }

            print(indexOffset, lines);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MergeOffsets.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MergeOffsets.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:br.edimarmanica.trinity.check.CheckOffsetRule.java

public void execute() {

    File dir = new File(Paths.PATH_TRINITY + site.getPath() + "/offset");

    List<List<String>> offset = new ArrayList<>(); //cada arquivo  um offset

    try (Reader in = new FileReader(dir.getAbsoluteFile() + "/result_" + indexOffset + ".csv")) {
        try (CSVParser parser = new CSVParser(in, CSVFormat.EXCEL)) {
            int nrRegistro = 0;
            for (CSVRecord record : parser) {
                if (nrRegistro >= nrRegistros) {
                    break;
                }//from  w  w w  .  j  av  a 2  s  . co m

                System.out.println(record.get(0) + ";" + record.get(indexRule));
                nrRegistro++;
            }
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(CheckOffsetRule.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(CheckOffsetRule.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.meltmedia.cadmium.deployer.UndeployCommandAction.java

@Override
public boolean execute(CommandContext<UndeployRequest> ctx) throws Exception {
    log.info("Beginning Undeploy Command, started by {}", ctx.getSource());
    UndeployRequest request = ctx.getMessage().getBody();

    String warName = request.getWarName();
    log.debug("Undeploying war {}", warName);
    if (warName.isEmpty() && !jbossUtil
            .isCadmiumWar(new File(System.getProperty(JBossUtil.JBOSS_SERVER_HOME_PROP), warName))) {
        log.info("Invalid undeployment request!");
        return false;
    }//from   ww  w  . j a  va 2 s. c o  m
    jbossUtil.undeploy(warName);

    File contentDir = new File(contentRoot, warName);
    if (contentDir.exists()) {
        log.info("Deleting content directory: {}", contentDir.getAbsoluteFile().getAbsolutePath());
        try {
            FileUtils.deleteDirectory(contentDir);
        } catch (IOException ioe) {
            log.error("Failed to delete content directory for war " + warName, ioe);
            return false;
        }
    }

    return true;
}

From source file:com.lxd.server.dao.impl.QiNiuFileDao.java

@Override
public void addFile(File file) {
    try {//from   ww w.ja  v a 2  s. co m
        String uptoken = QiNiuUtil.getPutString();
        PutExtra extra = new PutExtra();
        IoApi.putFile(uptoken, file.getName(), file.getAbsoluteFile(), extra);
        log.info("" + file.getAbsolutePath() + "??");
    } catch (Exception e) {
        e.printStackTrace();
        log.info("" + file.getAbsolutePath() + "?, :"
                + e.getMessage());
    }
}

From source file:com.anjlab.tapestry5.services.ConfigHelper.java

private ConfigHelper(File configFile) throws IOException {
    logger.info("Reading config from file: {}", configFile.getAbsoluteFile());
    readProperties(configFile);//from w w w.j a  va2s .c om
}

From source file:com.javacreed.apps.mail.Model.java

public void setCurrentDataFile(final File currentDataFile) {
    this.currentDataFile = currentDataFile.getAbsoluteFile();
}

From source file:com.github.ukase.service.BulkRenderer.java

private byte[] getFileData(String id) {
    File pdf = getPdfFile(id);
    Path pdfPath = pdf.getAbsoluteFile().toPath();
    try {//from   w  ww .ja  v  a 2 s .com
        return Files.readAllBytes(pdfPath);
    } catch (IOException e) {
        log.error("Cannot read pdf file data " + pdf.getAbsolutePath());
        return null;
    }
}

From source file:localization.split.java

public static boolean checkLPU(String filepath, String passoloPath) {
    File logfile = new File(filepath.substring(0, filepath.lastIndexOf("\\") + 1) + "error.log");
    try {/* w w w.j a  va2  s.  c  om*/
        String cmd = "cmd.exe /c " + passoloPath + " /openproject:" + filepath;
        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec(cmd);
        InputStreamReader isr = new InputStreamReader(proc.getInputStream());
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        while ((line = br.readLine()) != null) {
            if (line.contains("Opening in read-only mode")) {
                if (!logfile.exists()) {
                    logfile.createNewFile();
                }
                String content = filepath
                        + " is not able to process because it is a type of Passolo 2011. Please process it with Passolo 2011."
                        + "\n";
                FileWriter fw = new FileWriter(logfile.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(content);
                bw.close();
                return false;
            }
        }
        int exitVal = proc.waitFor();
        if (exitVal == 10) {
            if (!logfile.exists()) {
                logfile.createNewFile();
            }
            String content = filepath
                    + " is not able to process because it is a type of Passolo 2011. Please process it with Passolo 2015."
                    + "\n";
            FileWriter fw = new FileWriter(logfile.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();
            return false;
        }

    } catch (Exception e) {
        try {
            String content = e.getMessage();
            FileWriter fw = new FileWriter(logfile.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();
        } catch (Exception e1) {

        }

        return false;
    }
    return true;
}

From source file:adams.core.io.ZipUtils.java

/**
 * Unzips the specified file from a ZIP file.
 *
 * @param input   the ZIP file to unzip/*from   www  . ja  v  a 2  s  . c o m*/
 * @param archiveFile   the file from the archive to extract
 * @param output   the name of the output file
 * @param createDirs   whether to create the directory structure represented
 *          by output file
 * @param bufferSize   the buffer size to use
 * @param errors   for storing potential errors
 * @return      whether file was successfully extracted
 */
public static boolean decompress(File input, String archiveFile, File output, boolean createDirs,
        int bufferSize, StringBuilder errors) {
    boolean result;
    ZipFile zipfile;
    Enumeration<ZipArchiveEntry> enm;
    ZipArchiveEntry entry;
    File outFile;
    String outName;
    byte[] buffer;
    BufferedInputStream in;
    BufferedOutputStream out;
    FileOutputStream fos;
    int len;
    String error;
    long read;

    result = false;
    zipfile = null;
    try {
        // unzip archive
        buffer = new byte[bufferSize];
        zipfile = new ZipFile(input.getAbsoluteFile());
        enm = zipfile.getEntries();
        while (enm.hasMoreElements()) {
            entry = enm.nextElement();

            if (entry.isDirectory())
                continue;
            if (!entry.getName().equals(archiveFile))
                continue;

            in = null;
            out = null;
            fos = null;
            outName = null;
            try {
                // output name
                outName = output.getAbsolutePath();

                // create directory, if necessary
                outFile = new File(outName).getParentFile();
                if (!outFile.exists()) {
                    if (!createDirs) {
                        error = "Output directory '" + outFile.getAbsolutePath() + " does not exist', "
                                + "skipping extraction of '" + outName + "'!";
                        System.err.println(error);
                        errors.append(error + "\n");
                        break;
                    } else {
                        if (!outFile.mkdirs()) {
                            error = "Failed to create directory '" + outFile.getAbsolutePath() + "', "
                                    + "skipping extraction of '" + outName + "'!";
                            System.err.println(error);
                            errors.append(error + "\n");
                            break;
                        }
                    }
                }

                // extract data
                in = new BufferedInputStream(zipfile.getInputStream(entry));
                fos = new FileOutputStream(outName);
                out = new BufferedOutputStream(fos, bufferSize);
                read = 0;
                while (read < entry.getSize()) {
                    len = in.read(buffer);
                    read += len;
                    out.write(buffer, 0, len);
                }

                result = true;
                break;
            } catch (Exception e) {
                result = false;
                error = "Error extracting '" + entry.getName() + "' to '" + outName + "': " + e;
                System.err.println(error);
                errors.append(error + "\n");
            } finally {
                FileUtils.closeQuietly(in);
                FileUtils.closeQuietly(out);
                FileUtils.closeQuietly(fos);
            }
        }
    } catch (Exception e) {
        result = false;
        e.printStackTrace();
        errors.append("Error occurred: " + e + "\n");
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (Exception e) {
                // ignored
            }
        }
    }

    return result;
}

From source file:com.meltmedia.cadmium.servlets.shiro.PersistablePropertiesRealm.java

/**
 * loads a properties file named {@link REALM_FILE_NAME} in the directory passed in.
 *///from w w w .j av  a 2s  . c  om
public void loadProperties(File contentDir) {
    String resourceFile = null;
    if (contentDir.exists() && contentDir.isDirectory()) {
        File propFile = new File(contentDir, REALM_FILE_NAME);
        if (propFile.exists() && propFile.canRead()) {
            resourceFile = propFile.getAbsoluteFile().getAbsolutePath();
        }
    } else if (contentDir.exists() && contentDir.isFile() && contentDir.canRead()) {
        resourceFile = contentDir.getAbsoluteFile().getAbsolutePath();
    }
    if (StringUtils.isNotBlank(resourceFile)) {
        this.setResourcePath("file:" + resourceFile);
        this.destroy();
        this.init();
    }
}