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:mitm.common.tools.SMIME.java

private static MimeMessage loadp7m(String filename, boolean binary) throws Exception {
    File p7mFile = new File(filename);

    p7mFile = p7mFile.getAbsoluteFile();

    FileInputStream fis = new FileInputStream(p7mFile);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    OutputStreamWriter sw = new OutputStreamWriter(bos);

    sw.append("Content-Type: application/pkcs7-mime; name=\"smime.p7m\"\r\n");
    sw.append("Content-Transfer-Encoding: base64\r\n");
    sw.append("\r\n\r\n");

    byte[] content = IOUtils.toByteArray(fis);

    if (binary) {
        content = Base64.encodeBase64Chunked(content);
    }/* w ww  .  j  a v  a  2s  . com*/

    String base64Content = MiscStringUtils.toAsciiString(content);

    sw.append(base64Content);

    sw.flush();

    MimeMessage message = MailUtils.byteArrayToMessage(bos.toByteArray());

    return message;
}

From source file:es.sm2.openppm.core.plugin.action.GenericAction.java

/**
 *
 * @param files/* w ww . java  2 s  .  c om*/
 * @return
 * @throws IOException
 */
public static byte[] zipFiles(List<File> files) throws IOException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);

    for (File f : files) {

        zos.putNextEntry(new ZipEntry(f.getName()));

        zos.write(getBytesFromFile(f.getAbsoluteFile()));

        zos.closeEntry();
    }

    zos.flush();
    baos.flush();
    zos.close();
    baos.close();

    return baos.toByteArray();
}

From source file:gridool.util.GridUtils.java

public static File getWorkDir(boolean verify) {
    File colDir = Settings.getDataDirectory();
    if (verify && !colDir.exists()) {
        throw new IllegalStateException("Database directory not found: " + colDir.getAbsoluteFile());
    }/*from  ww w .j  a  va  2  s  . c o m*/
    return colDir;
}

From source file:app.utils.ACache.java

public static ACache get(File cacheDir, int max_zise, int max_count) {
    ACache manager = instanceMap.get(cacheDir.getAbsoluteFile() + getPid());
    if (manager == null) {
        manager = new ACache(cacheDir, max_zise, max_count);
        instanceMap.put(cacheDir.getAbsolutePath() + getPid(), manager);
    }//from  www .ja v  a2 s  .  c  om
    return manager;
}

From source file:com.github.jengelman.gradle.plugins.integration.TestFile.java

private static File join(File file, Object[] path) {
    File current = file.getAbsoluteFile();
    for (Object p : path) {
        current = new File(current, p.toString());
    }/*from www  .j a va2 s  .c  o m*/
    try {
        return current.getCanonicalFile();
    } catch (IOException e) {
        throw new RuntimeException(String.format("Could not canonicalise '%s'.", current), e);
    }
}

From source file:com.valco.utility.FacturasUtility.java

public static void guardaXml(String name, String content, String path, Integer facturaId) throws Exception {
    try {//  ww  w. ja va 2  s.  c  om
        File file = new File(path + name);
        // if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(content);
        bw.close();
    } catch (Exception ex) {
        throw new Exception("Factura " + facturaId + ": Ocurrio un error al generar el PDF.");
    }

}

From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditorUtility.java

/**
 * output SPDXDocument RDF model as file
 * @param document//from   w  w w  . j a va 2  s  .c  o  m
 * @param file
 * @throws FileNotFoundException
 */
public static void saveModelToFile(SPDXDocument document, File file) throws FileNotFoundException {
    // Save document
    Model spdxFileModel = document.getModel();

    //RDFWriter w = spdxFileModel.getWriter("RDF/XML-ABBREV");
    RDFWriter w = spdxFileModel.getWriter("RDF/XML");
    w.setProperty("attribtueQuoteChar", "'");
    w.setProperty("showXMLDeclaration", "true");
    w.setProperty("tab", "3");

    OutputStream fileOut = new FileOutputStream(file.getAbsoluteFile());
    w.write(spdxFileModel, fileOut, "");
}

From source file:net.dv8tion.jda.core.utils.SimpleLog.java

/**
 * Will duplicate the output-streams to the specified Files.
 * This will catch everything that is sent to sout and serr (even stuff not logged via SimpleLog).
 *
 * @param std/*from w  ww . j  ava  2s.  c  o m*/
 *      The file to use for System.out logging, or null to not LOG System.out to a file
 * @param err
 *      The file to use for System.err logging, or null to not LOG System.err to a file
 * @throws java.io.IOException
 *      If an IO error is encountered while dealing with the file. Most likely
 *      to be caused by a lack of permissions when creating the log folders or files.
 */
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void addFileLogs(File std, File err) throws IOException {
    if (std != null) {
        if (origStd == null)
            origStd = System.out;
        if (!std.getAbsoluteFile().getParentFile().exists()) {
            std.getAbsoluteFile().getParentFile().mkdirs();
        }
        if (!std.exists()) {
            std.createNewFile();
        }
        FileOutputStream fOut = new FileOutputStream(std, true);
        System.setOut(new PrintStream(new OutputStream() {
            @Override
            public void write(int b) throws IOException {
                origStd.write(b);
                fOut.write(b);
            }
        }));
        if (stdOut != null)
            stdOut.close();
        stdOut = fOut;
    } else if (origStd != null) {
        System.setOut(origStd);
        stdOut.close();
        origStd = null;
    }
    if (err != null) {
        if (origErr == null)
            origErr = System.err;
        if (!err.getAbsoluteFile().getParentFile().exists()) {
            err.getAbsoluteFile().getParentFile().mkdirs();
        }
        if (!err.exists()) {
            err.createNewFile();
        }
        FileOutputStream fOut = new FileOutputStream(err, true);
        System.setErr(new PrintStream(new OutputStream() {
            @Override
            public void write(int b) throws IOException {
                origErr.write(b);
                fOut.write(b);
            }
        }));
        if (errOut != null)
            errOut.close();
        errOut = fOut;
    } else if (origErr != null) {
        System.setErr(origErr);
        errOut.close();
        origErr = null;
    }
}

From source file:org.dataconservancy.dcs.integration.main.ManualDepositIT.java

private static File createReferenceSipFile(boolean extant) throws IOException {
    Dcp sip = new Dcp();

    DcsDeliverableUnit du = new DcsDeliverableUnit();
    du.setId("example:/du");
    du.setTitle("title");

    DcsManifestation man = new DcsManifestation();
    man.setId("example:/man");
    man.setDeliverableUnit("example:/du");

    DcsManifestationFile dmf = new DcsManifestationFile();
    dmf.setRef(new DcsFileRef("example:/file"));
    man.addManifestationFile(dmf);//from   w  w  w.  ja v a 2  s  . co  m

    DcsFile file = new DcsFile();
    file.setId("example:/file");
    file.setSource("file://" + sampleFilePath);
    file.setName("file.png");
    file.setExtant(extant);

    sip.addDeliverableUnit(du);
    sip.addManifestation(man);
    sip.addFile(file);

    String sipFileName = "reference_" + extant + ".xml";
    File sipFile = new File(baseDir, sipFileName);

    OutputStream out = FileUtils.openOutputStream(sipFile);
    new DcsXstreamStaxModelBuilder().buildSip(sip, out);
    new DcsXstreamStaxModelBuilder().buildSip(sip, new FileOutputStream("/tmp/dcp.xml"));

    out.close();

    log.info(String.format("Created example sip file %s", sipFile.getAbsoluteFile()));

    return sipFile;

}

From source file:ch.admin.suis.msghandler.util.FileUtils.java

/**
 * Moves a file. If destination already exists, it will be delete before the move.<br />Complete logging implemented<p
 * />/*  w w  w  .  j  a v  a2 s .co  m*/
 * Both parameters have to be files (not directories).
 *
 * @param src  Source File
 * @param dest Destination File
 */
public static void moveFile(File src, File dest) throws IOException {

    checkForFreeDiskSpace(src, dest); //Mantis: 0006311
    boolean isFileDeleted;
    try {
        if (dest.exists()) {
            LOG.info("moveFile: " + dest.getAbsoluteFile() + " already exists. Will be overwritten with: "
                    + src.getAbsolutePath());
            isFileDeleted = dest.delete();
            if (!isFileDeleted) {
                LOG.error("Unable to delete file: " + dest.getAbsolutePath());
            }
        }
        org.apache.commons.io.FileUtils.moveFile(src, dest);
        LOG.debug("File succesfull moved: " + src.getAbsolutePath() + " to: " + dest.getAbsolutePath());
    } catch (IOException ex) {
        isFileDeleted = false; // Assuming it went wrong here
        LOG.error("Unable to move file from: " + src.getAbsolutePath() + " to: " + dest.getAbsolutePath()
                + ", reason: " + ex.getMessage(), ex);
        if (dest.exists()) {
            isFileDeleted = dest.delete();
        }
        if (!isFileDeleted) {
            throw new IOException("Unable to delete file " + dest.getAbsolutePath());
        }
        throw ex;
    }
}