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:it.unibas.spicy.persistence.json.ExportJsonInstances.java

public void createJsonDocument(String tableName, String schema, INode tableNode, String folderPath,
        Statement statement) throws SQLException, IOException {
    BufferedWriter bw = null;/*  w  w w .  j av a 2s .c  o m*/
    ResultSet instancesSet = null;
    try {
        File file = new File(folderPath + File.separator + tableName + ".json");
        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        bw = new BufferedWriter(fw);
        if (!file.exists()) {
            file.createNewFile();
        }
        instancesSet = statement.executeQuery(
                "SELECT row_to_json(\"" + tableName + "\") FROM " + schema + ".\"" + tableName + "\";");
        //check to see if the result set is empty
        if (instancesSet.isBeforeFirst()) {
            bw.write("[");
            bw.newLine();
            while (instancesSet.next()) {
                bw.write(instancesSet.getString(1));
                //if it is not the last result
                if (!instancesSet.isLast()) {
                    bw.write(",");
                }
                bw.newLine();
            }
            bw.write("]");
        }
        //alternative for one-row json 
        /*instancesSet = statement.executeQuery("SELECT array_to_json(array_agg("+"\""+tableName+"\")) FROM "+schema+"\""+tableName+"\";");
        while (instancesSet.next() && instancesSet.getString(1)!=null){ 
            bw.write(instancesSet.getString(1));
        }
        }*/
    } finally {
        bw.close();
        instancesSet.close();
    }
}

From source file:net.sf.zekr.common.runtime.ApplicationRuntime.java

/**
 * Makes the application home directory.
 * //  www  .j a v a  2 s .co  m
 * @throws IOException
 */
public void configureDirectories() throws IOException {
    logger.info("Making application required directories (if not exist)...");

    for (Iterator<String> iter = dirList.iterator(); iter.hasNext();) {
        File file = new File(iter.next());
        if (!file.exists() && !file.mkdirs())
            throw new IOException("Can not create \'" + file.getAbsoluteFile() + "\'.");
    }
}

From source file:gridool.dht.TcbLocalDirectory.java

public void start() throws DbException {
    DbCollection rootColl = DbCollection.getRootCollection();
    File colDir = rootColl.getDirectory();
    assert (colDir.exists()) : colDir.getAbsoluteFile();
    File idxFile = new File(colDir, DIR_IDX_NAME);
    String filePath = idxFile.getAbsolutePath();

    if (!tcb.open(filePath, (BDB.OWRITER | BDB.OCREAT))) {
        int ecode = tcb.ecode();
        String errmsg = "open error: " + BDB.errmsg(ecode);
        LOG.fatal(errmsg);//w ww.j  av  a2  s.  c  o  m
        throw new DbException(errmsg);
    } else {
        LOG.info("Use a TokyoCabinet B+tree index on " + filePath + " for LocalDirectory");
    }
}

From source file:hudson.Util.java

/**
 * Checks if the given file represents a symlink.
 *//*from  w w  w  . java2s .  c  o m*/
//Taken from http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?view=markup
public static boolean isSymlink(File file) throws IOException {
    String name = file.getName();
    if (name.equals(".") || name.equals(".."))
        return false;

    File fileInCanonicalParent = null;
    File parentDir = file.getParentFile();
    if (parentDir == null) {
        fileInCanonicalParent = file;
    } else {
        fileInCanonicalParent = new File(parentDir.getCanonicalPath(), name);
    }
    return !fileInCanonicalParent.getCanonicalFile().equals(fileInCanonicalParent.getAbsoluteFile());
}

From source file:com.seniorproject.semanticweb.services.HadoopService.java

private void createSparqlFile(String queryString) throws IOException {
    String prefix = "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
            + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
            + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
            + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
            + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "
            + "PREFIX oddlinker: <http://data.linkedmdb.org/resource/oddlinker/> "
            + "PREFIX map: <file:/C:/d2r-server-0.4/mapping.n3#> "
            + "PREFIX db: <http://data.linkedmdb.org/resource/> "
            + "PREFIX dbpedia: <http://dbpedia.org/property/> "
            + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> " + "PREFIX dc: <http://purl.org/dc/terms/> "
            + "PREFIX movie: <http://data.linkedmdb.org/resource/movie/> ";
    File file = new File(servletContext.getRealPath("/WEB-INF/classes/PigSPARQL_v1.0/"), "test1.sparql");

    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(prefix + queryString);/*from w w  w. j  a  v a  2  s.c om*/
    bw.close();
}

From source file:JSONRequesterWithParser.java

private void Save(VehicleData vehicle, String filePath) {
    //print each vehicle information in file in tabular format
    try {/*from   w ww  .  j  a v a 2 s .  co  m*/
        //File file = new File("E:\\Projects\\Car2Go\\car1.txt"); // just for testing.
        //System.out.println("File Path"+filePath);
        File file = new File(filePath);
        FileWriter fw = null;
        if (!file.exists()) {
            file.createNewFile();
            fw = new FileWriter(file.getAbsoluteFile());
            String header = "Date Time" + "\t" + "Address" + "\t" + "Car Name" + "\t" + "License Plate" + "\t"
                    + "Group" + "\t" + "Latitude" + "\t" + "Longitude" + "\n";
            fw.write(header);
        } else {
            fw = new FileWriter(file.getAbsoluteFile(), true);
            String formatedVehicleData = vehicle.dateTime + "\t" + vehicle.address + "\t" + vehicle.carName
                    + "\t" + vehicle.licensePlate + "\t" + vehicle.group + "\t" + vehicle.latitude + "\t"
                    + vehicle.longitude + "\n";
            fw.write(formatedVehicleData);

        }
        fw.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:labr_client.ehealth.e_health_session_manager.java

public e_health_session_manager() {
    File config_file = new File("data\\" + geteHealthPropertiesLocation());
    try {/*from   www .  j  av a  2  s.  co  m*/
        setConfigLocation(config_file.getAbsoluteFile().getAbsolutePath());
        setConfigLocation("data/tmp/eHealthProps.properties");

        //ConfigFactory.getConfigValidator().setProperty("endpoint.sts", "https://services-int.ehealth.fgov.be/IAM/Saml11TokenService/Legacy/v1"); 
        //ConfigFactory.getConfigValidator().setProperty("endpoint.ehbox.consultation.v3", "https://services-int.ehealth.fgov.be/ehBoxConsultation/v3"); 
        //ConfigFactory.getConfigValidator().setProperty("endpoint.ehbox.publication.v3", "https://services-int.ehealth.fgov.be/ehBoxPublication/v3"); 
        //ConfigFactory.getConfigValidator().setProperty("endpoint.etk", "https://services-int.ehealth.fgov.be/EtkDepot/v1"); 

    } catch (TechnicalConnectorException ex) {
        getLogger(e_health.class.getName()).log(SEVERE, null, ex);

    }

}

From source file:jenkins.plugins.shiningpanda.workspace.TestSlaveWorkspace.java

public void testGetPackageDirExists() throws Exception {
    File masterPackagesDir = createPackagesDir();
    File masterPackagesFile = new File(masterPackagesDir, "toto.txt");
    FileUtils.writeStringToFile(masterPackagesFile, "hello");
    FilePath slavePackagesDir = getSlaveWorkspace().getPackagesDir();
    File slavePackagesFile = new File(toFile(slavePackagesDir), "toto.txt");
    assertContentEquals(masterPackagesFile, slavePackagesFile);
    assertNotSame("path of package on slave should differ from master one",
            masterPackagesFile.getAbsolutePath(), slavePackagesFile.getAbsoluteFile());
}

From source file:br.edu.ifpb.sislivros.model.ProcessadorFotos.java

public boolean salvarImagemCapa(String path, InputStream item, String nameToSave) {
    try {//  w  w  w.  ja v  a  2s.c  o  m
        File f = new File(path);
        if (!f.exists()) {
            f.mkdir();
        }

        File savedFile = new File(f.getAbsoluteFile() + File.separator + nameToSave);
        FileOutputStream fos = new FileOutputStream(savedFile);

        //            InputStream is = item.openStream();
        InputStream is = item;

        int x = 0;
        byte[] b = new byte[1024];
        while ((x = is.read(b)) != -1) {
            fos.write(b, 0, x);
        }
        fos.flush();
        fos.close();

        return true;

    } catch (Exception ex) {
    }
    return false;
}

From source file:com.seanbright.osgi.launcher.FrameworkThread.java

private void installBundles(BundleContext context, String path) {
    List<Bundle> bundles = new ArrayList<Bundle>();

    if (path == null) {
        // They don't want to autostart anything
        return;//from  w w  w  .  ja  v  a 2s .co m
    }

    File parent = new File(path);

    if (!parent.exists()) {
        throw new RuntimeException(path + " does not exist.");
    }

    if (!parent.isDirectory()) {
        throw new RuntimeException(path + " is not a directory.");
    }

    for (File candidate : parent.listFiles()) {
        if (!candidate.isFile()) {
            continue;
        }

        try {
            bundles.add(context.installBundle(candidate.getAbsoluteFile().toURI().toString()));
        } catch (BundleException ex) {
            ex.printStackTrace(System.err);
        }
    }

    for (Bundle bundle : bundles) {
        try {
            bundle.start();
        } catch (BundleException ex) {
            ex.printStackTrace(System.err);
        }
    }
}