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:com.yoncabt.ebr.executor.jasper.JasperReport.java

private static File compile(File jrxmlFile) throws JRException {
    logManager.info(jrxmlFile + " compile");
    File jasperFile = new File(jrxmlFile.getAbsolutePath().replace(".jrxml", ".jasper"));
    jasperFile.getParentFile().mkdirs();
    if (jrxmlFile.lastModified() > jasperFile.lastModified()) {
        JasperDesign jasperDesign = JRXmlLoader.load(jrxmlFile.getAbsolutePath());
        net.sf.jasperreports.engine.JasperReport jasperReport = JasperCompileManager
                .compileReport(jasperDesign);
        JRSaver.saveObject(jasperReport, jasperFile.getAbsolutePath());
        //toLog("Saving compiled report to: " + jasperFile.getAbsolutePath());
        //Compile sub reports
        JRElementsVisitor.visitReport(jasperReport, new JRVisitor() {

            @Override//from   w  ww .  j a  v  a 2s .c  o m
            public void visitBreak(JRBreak breakElement) {
            }

            @Override
            public void visitChart(JRChart chart) {
            }

            @Override
            public void visitCrosstab(JRCrosstab crosstab) {
            }

            @Override
            public void visitElementGroup(JRElementGroup elementGroup) {
            }

            @Override
            public void visitEllipse(JREllipse ellipse) {
            }

            @Override
            public void visitFrame(JRFrame frame) {
            }

            @Override
            public void visitImage(JRImage image) {
            }

            @Override
            public void visitLine(JRLine line) {
            }

            @Override
            public void visitRectangle(JRRectangle rectangle) {
            }

            @Override
            public void visitStaticText(JRStaticText staticText) {
            }

            @Override
            public void visitSubreport(JRSubreport subreport) {
                String subReportName = subreport.getExpression().getText().replace("repo:", "");
                subReportName = StringUtils.strip(subReportName, "\"");
                //uzant jrxml olduuna emin olalm
                subReportName = FilenameUtils.removeExtension(subReportName) + ".jrxml";
                File subReportFile = new File(jrxmlFile.getParentFile(), subReportName);
                //Sometimes the same subreport can be used multiple times, but
                //there is no need to compile multiple times
                // burada tam path bulmak gerekebilir
                File compiledSubReportFile = compileIfRequired(subReportFile.getAbsoluteFile());
                File destSubReportFile = new File(
                        EBRConf.INSTANCE.getValue("report.subreport.path",
                                "/home/eastblue/apache-tomcat-8.0.28/webapps/ebr/WEB-INF/classes"),
                        compiledSubReportFile.getName());
                try {
                    // copy to classpoath
                    FileUtils.copyFile(compiledSubReportFile, destSubReportFile);
                } catch (IOException ex) {
                    throw new ReportException(ex);
                }
            }

            @Override
            public void visitTextField(JRTextField textField) {
            }

            @Override
            public void visitComponentElement(JRComponentElement componentElement) {
            }

            @Override
            public void visitGenericElement(JRGenericElement element) {
            }

        });
        JasperCompileManager.compileReportToFile(jrxmlFile.getAbsolutePath(), jasperFile.getAbsolutePath());
    }
    return jasperFile;
}

From source file:com.amazonaws.eclipse.core.regions.RegionUtils.java

/**
 * Caches flag icons as necessary, also registering images for them
 *//*from   w w  w. j av  a  2s .  c om*/
private static void cacheFlags(File regionsDir) throws ClientProtocolException, IOException {
    if (!regionsDir.exists()) {
        return;
    }

    for (Region r : regions) {
        if (r == LocalRegion.INSTANCE) {
            // Local region has no flag to initialize.
            continue;
        }

        File icon = new File(regionsDir, r.getFlagIconPath());
        if (icon.exists() == false) {
            icon.getParentFile().mkdirs();
            String iconUrl = CLOUDFRONT_DISTRO + r.getFlagIconPath();
            fetchFile(iconUrl, icon);
        }

        AwsToolkitCore.getDefault().getImageRegistry().put(AwsToolkitCore.IMAGE_FLAG_PREFIX + r.getId(),
                ImageDescriptor.createFromURL(icon.getAbsoluteFile().toURI().toURL()));
    }
}

From source file:data_gen.Data_gen.java

public static void generate_xml() {
    SchemaGenerator schema = new SchemaGenerator(schema_fields);
    try {// w  w  w  .j  a va2  s.com

        String content = schema.generateSchema();

        File file = new File(output_dir + "/" + "schema.xml");

        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(content);
        bw.close();

    } catch (IOException e) {
        System.out.println("There was an error writing to the xml file." + "\n");
    }

}

From source file:data_gen.Data_gen.java

public static void generate_field_map() {
    try {//from   www.j av  a 2s .c  om
        File file = new File(output_dir + "/" + "fieldMap.xml");

        if (!file.exists()) {
            file.createNewFile();
        }
        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "\n");
        bw.write("<fieldMap name=\"Default Field Map\" version=\"1.0\">" + "\n");
        bw.write("     <!--" + "\n");
        bw.write("     There are no field maps for the Law Exporter" + "\n");
        bw.write("     -->" + "\n");
        bw.write("</fieldMap>" + "\n");
        bw.close();

    } catch (IOException e) {
        System.out.println("There was an error writing to the xml file." + "\n");
    }

}

From source file:org.cloudifysource.azure.CliAzureDeploymentTest.java

public static String runCliCommands(File cliExecutablePath, List<List<String>> commands, boolean isDebug)
        throws IOException, InterruptedException {
    if (!cliExecutablePath.isFile()) {
        throw new IllegalArgumentException(cliExecutablePath + " is not a file");
    }/*from   ww w .  j  a va  2 s . c o  m*/

    File workingDirectory = cliExecutablePath.getAbsoluteFile().getParentFile();
    if (!workingDirectory.isDirectory()) {
        throw new IllegalArgumentException(workingDirectory + " is not a directory");
    }

    int argsCount = 0;
    for (List<String> command : commands) {
        argsCount += command.size();
    }

    // needed to properly intercept error return code
    String[] cmd = new String[(argsCount == 0 ? 0 : 1) + 4 /* cmd /c call cloudify.bat ["args"] */];
    int i = 0;
    cmd[i] = "cmd";
    i++;
    cmd[i] = "/c";
    i++;
    cmd[i] = "call";
    i++;
    cmd[i] = cliExecutablePath.getAbsolutePath();
    i++;
    if (argsCount > 0) {
        cmd[i] = "\"";
        //TODO: Use StringBuilder
        for (List<String> command : commands) {
            if (command.size() > 0) {
                for (String arg : command) {
                    if (cmd[i].length() > 0) {
                        cmd[i] += " ";
                    }
                    cmd[i] += arg;
                }
                cmd[i] += ";";
            }
        }
        cmd[i] += "\"";
    }
    final ProcessBuilder pb = new ProcessBuilder(cmd);
    pb.directory(workingDirectory);
    pb.redirectErrorStream(true);

    String extCloudifyJavaOptions = "";

    if (isDebug) {
        extCloudifyJavaOptions += "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9000 -Xnoagent -Djava.compiler=NONE";
    }

    pb.environment().put("EXT_CLOUDIFY_JAVA_OPTIONS", extCloudifyJavaOptions);
    final StringBuilder sb = new StringBuilder();

    logger.info("running: " + cliExecutablePath + " " + Arrays.toString(cmd));

    // log std output and redirected std error
    Process p = pb.start();
    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = reader.readLine();
    while (line != null) {
        sb.append(line).append("\n");
        line = reader.readLine();
        logger.info(line);
    }

    final String readResult = sb.toString();
    final int exitValue = p.waitFor();

    logger.info("Exit value = " + exitValue);
    if (exitValue != 0) {
        Assert.fail("Cli ended with error code: " + exitValue);
    }
    return readResult;
}

From source file:com.shenke.digest.db.Cache.java

public static Cache get(File cacheDir, long max_zise, int max_count) {
    Cache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new Cache(cacheDir, max_zise, max_count);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }//  w ww  . ja v a 2 s.  c  o  m
    return manager;
}

From source file:dk.statsbiblioteket.util.Files.java

private static void copyDirectory(File path, File toPath, boolean overwrite) throws IOException {
    log.trace("copyDirectory(" + path + ", " + toPath + ", " + overwrite + ") called");
    if (!toPath.exists()) {
        if (!toPath.mkdirs()) {
            throw new IOException("Unable to create or verify the existence" + " of the destination folder '"
                    + toPath.getAbsoluteFile() + "'");
        }//from   ww  w  .  jav  a 2  s  .c om
    }
    if (!toPath.canWrite()) {
        throw new IOException("The destination folder '" + toPath.getAbsoluteFile() + "' is not writable");
    }

    for (String filename : path.list()) {
        File in = new File(path, filename);
        File out = new File(toPath, filename);
        innerCopy(in, out, overwrite);
    }
}

From source file:com.parse.ParseFileUtils.java

/**
 * Determines whether the specified file is a Symbolic Link rather than an actual file.
 * <p>/*  w  w  w .  j  av a 2 s  . c om*/
 * Will not return true if there is a Symbolic Link anywhere in the path,
 * only if the specific file is.
 * <p>
 * <b>Note:</b> the current implementation always returns {@code false} if the system
 * is detected as Windows using {@link FilenameUtils#isSystemWindows()}
 * <p>
 * For code that runs on Java 1.7 or later, use the following method instead:
 * <br>
 * {@code boolean java.nio.file.Files.isSymbolicLink(Path path)}
 * @param file the file to check
 * @return true if the file is a Symbolic Link
 * @throws IOException if an IO error occurs while checking the file
 * @since 2.0
 */
public static boolean isSymlink(final File file) throws IOException {
    if (file == null) {
        throw new NullPointerException("File must not be null");
    }
    //    if (FilenameUtils.isSystemWindows()) {
    //      return false;
    //    }
    File fileInCanonicalDir = null;
    if (file.getParent() == null) {
        fileInCanonicalDir = file;
    } else {
        final File canonicalDir = file.getParentFile().getCanonicalFile();
        fileInCanonicalDir = new File(canonicalDir, file.getName());
    }

    if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())) {
        return false;
    } else {
        return true;
    }
}

From source file:adams.data.image.ImageMetaDataHelper.java

/**
 * Reads the meta-data from the file (using Sanselan).
 * //from   w  w w. j  a  va  2s  .c o m
 * @param file   the file to read the meta-data from
 * @return      the meta-data
 * @throws Exception   if failed to read meta-data
 */
public static SpreadSheet sanselan(File file) throws Exception {
    SpreadSheet sheet;
    Row row;
    org.apache.sanselan.common.IImageMetadata meta;
    String[] parts;
    String key;
    String value;
    org.apache.sanselan.ImageInfo info;
    String infoStr;
    String[] lines;
    HashSet<String> keys;

    sheet = new DefaultSpreadSheet();

    // header
    row = sheet.getHeaderRow();
    row.addCell("K").setContent("Key");
    row.addCell("V").setContent("Value");

    keys = new HashSet<String>();

    // meta-data
    meta = Sanselan.getMetadata(file.getAbsoluteFile());
    if (meta != null) {
        for (Object item : meta.getItems()) {
            key = null;
            value = null;
            if (item instanceof ImageMetadata.Item) {
                key = ((ImageMetadata.Item) item).getKeyword().trim();
                value = ((ImageMetadata.Item) item).getText().trim();
            } else {
                parts = item.toString().split(": ");
                if (parts.length == 2) {
                    key = parts[0].trim();
                    value = parts[1].trim();
                }
            }
            if (key != null) {
                if (!keys.contains(key)) {
                    keys.add(key);
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(fixDateTime(Utils.unquote(value)));
                }
            }
        }
    }

    // image info
    info = Sanselan.getImageInfo(file.getAbsoluteFile());
    if (info != null) {
        infoStr = info.toString();
        lines = infoStr.split(System.lineSeparator());
        for (String line : lines) {
            parts = line.split(": ");
            if (parts.length == 2) {
                key = parts[0].trim();
                value = parts[1].trim();
                if (!keys.contains(key)) {
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(Utils.unquote(value));
                    keys.add(key);
                }
            }
        }
    }

    return sheet;
}

From source file:edu.stanford.epad.common.util.EPADFileUtils.java

/**
 * User this instead of write when a file will be over-written often.
 * /*from w w w .j a  v  a  2 s . c  om*/
 * @param file File the file to over-write.
 * @param contents String
 * @return boolean
 */
public static boolean overwrite(File file, String contents) {
    String tempFilename = file.getAbsoluteFile() + "." + UUID.randomUUID().toString() + ".tmp";
    File tempFile = new File(tempFilename);

    return write(tempFile, contents) && tempFile.renameTo(file);
}