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.asakusafw.lang.inspection.cli.Cli.java

private static OutputStream openOutput(File file) throws IOException {
    File parent = file.getAbsoluteFile().getParentFile();
    if (parent.mkdirs() == false && parent.isDirectory() == false) {
        throw new IOException(MessageFormat.format("failed to create output: {0}", file));
    }// ww  w .  jav a 2 s . co m
    return new FileOutputStream(file);
}

From source file:Main.java

public static void getStringFromXML(Node node, String dtdFilename, Writer outputWriter)
        throws TransformerException {
    File dtdFile = null;
    String workingPath = null;//  w  w w.j  a  v a  2s .  c  om
    if (dtdFilename != null) {
        dtdFile = new File(dtdFilename);
        workingPath = System.setProperty("user.dir", dtdFile.getAbsoluteFile().getParent());
    }
    try {
        if (node instanceof Document)
            node = ((Document) node).getDocumentElement();

        TransformerFactory tranFact = TransformerFactory.newInstance();
        Transformer tf = tranFact.newTransformer();
        if (dtdFile != null) {
            tf.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtdFile.getName());
            tf.setOutputProperty(OutputKeys.INDENT, "yes");
        }

        Source src = new DOMSource(node);
        Result dest = new StreamResult(outputWriter);

        tf.transform(src, dest);
    } finally {
        if (workingPath != null)
            System.setProperty("user.dir", workingPath);
    }
}

From source file:de.tudarmstadt.ukp.clarin.webanno.api.dao.ZipUtils.java

/**
 * While exporting annotation documents, some of the writers generate multiple outputs, e.g. a
 * type system file in addition to the annotation data. This method generates a zip file if the
 * exported file do contain multiple file output
 * //from  www. jav  a2  s .co m
 * @param srcFolder source folder.
 * @param destZipFile target folder.
 * @throws IOException if an I/O error occurs.
 */
public static void zipFolder(File srcFolder, File destZipFile) throws IOException {
    ZipOutputStream zip = null;
    try {
        zip = new ZipOutputStream(new FileOutputStream(destZipFile));

        for (File file : srcFolder.getAbsoluteFile().listFiles()) {
            addToZip(zip, srcFolder.getAbsoluteFile(), file);
        }
        zip.flush();
    } finally {
        closeQuietly(zip);
    }
}

From source file:gridool.db.partitioning.monetdb.MonetDBPrepareCopyIntoOperation.java

private static File prepareLoadFile(final String tableName, final byte[] data, final boolean append) {
    DbCollection rootColl = DbCollection.getRootCollection();
    File colDir = rootColl.getDirectory();
    if (!colDir.exists()) {
        throw new IllegalStateException("Database directory not found: " + colDir.getAbsoluteFile());
    }/* w ww.  j  av  a2 s.c  o m*/
    final File loadFile;
    final FileOutputStream fos;
    try {
        loadFile = new File(colDir, tableName + ".csv");
        fos = new FileOutputStream(loadFile, append);
    } catch (IOException e) {
        throw new IllegalStateException("Failed to create a load file", e);
    }
    try {
        FastBufferedOutputStream bos = new FastBufferedOutputStream(fos, 8192);
        bos.write(data, 0, data.length);
        bos.flush();
        bos.close();
    } catch (IOException e) {
        try {
            fos.close();
        } catch (IOException ioe) {
            LOG.debug(ioe);
        }
        throw new IllegalStateException("Failed to write data into file: " + loadFile.getAbsolutePath(), e);
    }
    return loadFile;
}

From source file:edu.ku.brc.af.ui.forms.ViewSetMgrManager.java

/**
 * Empties the stack with optionally keep the backstop
 * @param keepBackStop true keeps the backstop, false removes it
 */// w w  w.j av  a  2  s.c om
public static void clear(final boolean keepBackStop) {
    while ((keepBackStop && stack.size() > 1) || !keepBackStop && stack.size() > 0) {
        ViewSetMgr vm = stack.pop();
        vm.clearAll();
    }

    // If the remaining VSM is not the BackStop then remove it.
    if (stack.size() > 0) {
        ViewSetMgr vsm = stack.peek();
        if (vsm != null) {
            File bsDir = new File(XMLHelper.getConfigDirPath(File.separator + ViewSetMgrManager.BACKSTOP));

            if (!vsm.getContextDir().getAbsoluteFile().equals(bsDir.getAbsoluteFile())) {
                vsm.clearAll();
                stack.pop();
            }
        }
    }
}

From source file:mc.lib.files.FileReadingHelper.java

public static String readText(File file) {
    FileInputStream is = null;/*from w ww .j  a va 2 s . c o  m*/
    try {
        is = new FileInputStream(file);
        return StreamHelper.readStream(is);
    } catch (FileNotFoundException e) {
        Log.e(LOGTAG, "Cannot read file " + file.getAbsoluteFile(), e);
    } finally {
        StreamHelper.close(is);
    }
    return null;
}

From source file:com.yata.core.FileManager.java

public static BufferedWriter getFileWriter(String fileName) throws IOException {

    System.out.println("getFileWriter@" + className + " : File to write in :-> " + fileName);

    File file = new File(fileName);

    // if file doesnt exists, then create it
    if (!file.exists()) {
        file.createNewFile();/*from   www  .jav a 2  s .c o  m*/
    }

    FileWriter fileWriter = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

    return bufferedWriter;
}

From source file:Main.java

public static void getStringFromXML(Node node, String dtdFilename, String outputFileName)
        throws TransformerException, IOException {
    File file = new File(outputFileName);
    if (!file.isFile())
        file.createNewFile();//from w  w  w . j  a  v  a2s .c  om
    BufferedWriter out = new BufferedWriter(new FileWriter(file));

    String workingPath = System.setProperty("user.dir", file.getAbsoluteFile().getParent());
    try {
        getStringFromXML(node, dtdFilename, out);
    } finally {
        System.setProperty("user.dir", workingPath);
    }

    out.flush();
    out.close();
}

From source file:com.company.et.service.JsonService.java

/**
 *
 * @param json String what we write to file
 *//*from  ww w  .  jav  a2  s .  c om*/
public static void writeToFile(String json) {

    try {
        File file = new File(getFilename());
        if (!file.exists()) {
            file.createNewFile();
        }

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

        // @TODO: add LOG message
    } catch (IOException e) {
        e.printStackTrace();

        // @TODO: add LOG message
    }

}

From source file:Main.java

public static boolean isSymLink(File filePath) throws IOException {
    if (filePath == null)
        throw new NullPointerException("filePath cannot be null");
    File canonical;
    if (filePath.getParent() == null) {
        canonical = filePath;//w  w  w. java  2s  .  co m
    } else {
        File canonDir = filePath.getParentFile().getCanonicalFile();
        canonical = new File(canonDir, filePath.getName());
    }
    return !canonical.getCanonicalFile().equals(canonical.getAbsoluteFile());
}