Example usage for java.io File getPath

List of usage examples for java.io File getPath

Introduction

In this page you can find the example usage for java.io File getPath.

Prototype

public String getPath() 

Source Link

Document

Converts this abstract pathname into a pathname string.

Usage

From source file:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.AnsibleVault.java

/**
 * Encrypts file with Ansible vault.//from w w w  .  ja va 2 s  .  com
 * @param file File to encrypt
 * @param ansibleVaultPassword Ansible Vault Password
 * @throws IOException I/O exception
 */
public static void encrypt(File file, String ansibleVaultPassword) throws IOException {
    handleFile(file, data -> {
        try {
            return VaultHandler.encrypt(data, ansibleVaultPassword);
        } catch (IOException ex) {
            throw new RuntimeException("Unable to encrypt file " + file.getPath(), ex);
        }
    });
}

From source file:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.AnsibleVault.java

/**
 * Decrypts file with Ansible vault.//from   ww  w  .j  a v a 2  s . co m
 * @param file File to decrypt
 * @param ansibleVaultPassword Ansible Vault Password
 * @throws IOException I/O exception
 */
public static void decrypt(File file, String ansibleVaultPassword) throws IOException {
    handleFile(file, data -> {
        try {
            return VaultHandler.decrypt(data, ansibleVaultPassword);
        } catch (IOException ex) {
            throw new RuntimeException("Unable to decrypt file " + file.getPath(), ex);
        }
    });
}

From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java

public static PerformanceResultsData readResults(File resultsFile) throws Exception {

    if (!resultsFile.exists()) {
        throw new Exception("Results file: " + resultsFile.getPath() + " does not exist.");
    }/*from   w ww  .  j a  v a 2 s  .  c om*/

    ObjectInputStream in = new ObjectInputStream(new FileInputStream(resultsFile));
    return (PerformanceResultsData) in.readObject();
}

From source file:com.lxh.util.image.OtherUtils.java

/**
 * ??// w  w  w.  j a  v a  2 s  . c  om
 * @param dir {@link java.io.File}
 * @return ????byte-1
 */
public static long getAvailableSpace(File dir) {
    try {
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        return -1;
    }
}

From source file:net.orpiske.sdm.lib.io.IOUtil.java

/**
 * Protects a file or resource from being written
 * @param resource the resource to protect
 * @throws IOException//  w  w  w .j av  a  2s .  c  o m
 */
public static void shield(final String resource) throws IOException {
    File shieldedFile = new File(resource);

    if (!shieldedFile.exists()) {
        System.out.println("Resource " + resource + " does not exist");

        return;
    }

    File shielded = new File(resource + ShieldUtils.SHIELD_EXT);

    if (!shielded.exists()) {

        if (!shielded.createNewFile()) {
            System.err.println("Unable to create shield file " + shielded.getPath());
        }

        System.out.println("Resource " + resource + " was shielded");
    } else {
        System.out.println("Resource " + resource + " already shielded");
    }

    shielded.deleteOnExit();
}

From source file:jp.andeb.obbutil.ObbUtilMain.java

private static boolean doInfo(String[] args) {
    if (args.length != 1) {
        printUsage(PROGNAME);//from  ww  w  . j  a v a2 s .  c  o m
        return false;
    }
    final File targetFile = new File(args[0]);
    try {
        final ObbInfoV1 info = ObbInfoV1.fromFile(targetFile);
        System.out.println("OBB info for " + targetFile.getPath() + ":");
        info.prettyPrint(System.out);
    } catch (FileNotFoundException e) {
        System.err.println("???: " + targetFile.getPath());
        return false;
    } catch (IOException e) {
        System.err.println("????????: " + targetFile.getPath());
        return false;
    } catch (NotObbException e) {
        System.err.println(
                "? OBB ???????: " + targetFile.getPath());
        return false;
    }

    return true;
}

From source file:de.monticore.templateclassgenerator.Modelfinder.java

/**
 * Finds all models with a certain {@code fileExtension} in the given
 * {@code modelPath}/* w  w  w.j a  v a 2  s. c  o m*/
 * 
 * @param modelPath
 * @param fileExtension
 * @return List of all found models
 */
public static List<String> getModelsInModelPath(File modelPath, String fileExtension) {
    List<String> models = new ArrayList<String>();
    String[] extension = { fileExtension };
    Collection<File> files = FileUtils.listFiles(modelPath, extension, true);
    for (File f : files) {
        String model = getDotSeperatedFQNModelName(modelPath.getPath(), f.getPath(), fileExtension);
        if (model.startsWith(TemplateClassGeneratorConstants.TEMPLATE_CLASSES_SETUP_PACKAGE)) {
            Log.error("0xA700 ATemplate '" + model + "' must not lay in topfolder '"
                    + TemplateClassGeneratorConstants.TEMPLATE_CLASSES_SETUP_PACKAGE + "'");
        }

        else {
            Log.info("Found model: " + model, "Modelfinder");
            models.add(model);
        }
    }
    return models;
}

From source file:au.org.ala.spatial.util.UploadSpatialResource.java

public static String assignSld(String url, String extra, String username, String password, String data) {
    System.out.println("assignSld url:" + url);
    System.out.println("data:" + data);

    String output = "";

    HttpClient client = new HttpClient();
    client.setConnectionTimeout(10000);//from  w  ww.  ja  v a  2  s.  c o m
    client.setTimeout(60000);

    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

    PutMethod put = new PutMethod(url);
    put.setDoAuthentication(true);

    // Execute the request
    try {
        // Request content will be retrieved directly
        // from the input stream
        File file = File.createTempFile("sld", "xml");
        System.out.println("file:" + file.getPath());
        FileWriter fw = new FileWriter(file);
        fw.append(data);
        fw.close();
        RequestEntity entity = new FileRequestEntity(file, "text/xml");
        put.setRequestEntity(entity);

        int result = client.executeMethod(put);

        output = result + ": " + put.getResponseBodyAsString();

    } catch (Exception e) {
        output = "0: " + e.getMessage();
        e.printStackTrace(System.out);
    } finally {
        // Release current connection to the connection pool once you are done
        put.releaseConnection();
    }

    return output;
}

From source file:Main.java

protected static void delFiles(File file, String keep) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null) {
            for (int i = 0, size = files.length; i < size; i++) {
                File f = files[i];
                delFiles(f, keep);/*from  w  w w. j ava  2  s  . co m*/
            }
        }
    } else {
        if (keep.equals(file.getPath()))
            return;
        file.delete();
    }
}