Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:com.esri.geoportal.harvester.folder.FolderBrokerDefinitionAdaptor.java

/**
 * Sets root folder./*  w w w.  ja va  2s. co m*/
 *
 * @param rootFolder root folder
 */
public void setRootFolder(File rootFolder) {
    this.rootFolder = rootFolder;
    set(P_ROOT_FOLDER, rootFolder.toString());
}

From source file:io.hops.hopsworks.common.util.HopsUtils.java

/**
 * Utility method that copies project user certificates from the Database, to
 * either hdfs to be passed as LocalResources to the YarnJob or to used
 * by another method.//from  w w w. j  a v  a  2s. co m
 *
 * @param project
 * @param username
 * @param localTmpDir
 * @param remoteTmpDir
 * @param jobType
 * @param dfso
 * @param projectLocalResources
 * @param jobSystemProperties
 * @param flinkCertsDir
 * @param applicationId
 */
public static void copyProjectUserCerts(Project project, String username, String localTmpDir,
        String remoteTmpDir, JobType jobType, DistributedFileSystemOps dfso,
        List<LocalResourceDTO> projectLocalResources, Map<String, String> jobSystemProperties,
        String flinkCertsDir, String applicationId, CertificateMaterializer certMat, boolean isRpcTlsEnabled) {

    // Let the Certificate Materializer handle the certificates
    UserCerts userCert = new UserCerts(project.getName(), username);
    try {
        certMat.materializeCertificatesLocal(username, project.getName());
        CertificateMaterializer.CryptoMaterial material = certMat.getUserMaterial(username, project.getName());
        userCert.setUserKey(material.getKeyStore().array());
        userCert.setUserCert(material.getTrustStore().array());
        userCert.setUserKeyPwd(new String(material.getPassword()));
    } catch (IOException | CryptoPasswordNotFoundException ex) {
        throw new RuntimeException("Could not materialize user certificates", ex);
    }

    //Check if the user certificate was actually retrieved
    if (userCert.getUserCert() != null && userCert.getUserCert().length > 0 && userCert.getUserKey() != null
            && userCert.getUserKey().length > 0) {

        Map<String, byte[]> certFiles = new HashMap<>();
        certFiles.put(Settings.T_CERTIFICATE, userCert.getUserCert());
        certFiles.put(Settings.K_CERTIFICATE, userCert.getUserKey());

        try {
            String kCertName = HopsUtils.getProjectKeystoreName(project.getName(), username);
            String tCertName = HopsUtils.getProjectTruststoreName(project.getName(), username);
            String passName = getProjectMaterialPasswordName(project.getName(), username);

            try {
                if (jobType != null) {
                    switch (jobType) {
                    case FLINK:
                        File appDir = Paths.get(flinkCertsDir, applicationId).toFile();
                        if (!appDir.exists()) {
                            appDir.mkdir();
                        }

                        File f_k_cert = new File(appDir.toString() + File.separator + kCertName);
                        f_k_cert.setExecutable(false);
                        f_k_cert.setReadable(true, true);
                        f_k_cert.setWritable(false);

                        File t_k_cert = new File(appDir.toString() + File.separator + tCertName);
                        t_k_cert.setExecutable(false);
                        t_k_cert.setReadable(true, true);
                        t_k_cert.setWritable(false);

                        if (!f_k_cert.exists()) {
                            Files.write(certFiles.get(Settings.K_CERTIFICATE), f_k_cert);
                            Files.write(certFiles.get(Settings.T_CERTIFICATE), t_k_cert);
                        }

                        File certPass = new File(appDir.toString() + File.separator + passName);
                        certPass.setExecutable(false);
                        certPass.setReadable(true, true);
                        certPass.setWritable(false);
                        FileUtils.writeStringToFile(certPass, userCert.getUserKeyPwd(), false);
                        jobSystemProperties.put(Settings.CRYPTO_MATERIAL_PASSWORD, certPass.toString());
                        jobSystemProperties.put(Settings.K_CERTIFICATE, f_k_cert.toString());
                        jobSystemProperties.put(Settings.T_CERTIFICATE, t_k_cert.toString());
                        break;
                    case PYSPARK:
                    case SPARK:
                        Map<String, File> certs = new HashMap<>();
                        certs.put(Settings.K_CERTIFICATE, new File(localTmpDir + File.separator + kCertName));
                        certs.put(Settings.T_CERTIFICATE, new File(localTmpDir + File.separator + tCertName));
                        certs.put(Settings.CRYPTO_MATERIAL_PASSWORD,
                                new File(localTmpDir + File.separator + passName));

                        for (Map.Entry<String, File> entry : certs.entrySet()) {
                            //Write the actual file(cert) to localFS
                            //Create HDFS certificate directory. This is done
                            //So that the certificates can be used as LocalResources
                            //by the YarnJob
                            if (!dfso.exists(remoteTmpDir)) {
                                dfso.mkdir(new Path(remoteTmpDir),
                                        new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));
                            }
                            //Put project certificates in its own dir
                            String certUser = project.getName() + "__" + username;
                            String remoteTmpProjDir = remoteTmpDir + File.separator + certUser;
                            if (!dfso.exists(remoteTmpProjDir)) {
                                dfso.mkdir(new Path(remoteTmpProjDir),
                                        new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.NONE));
                                dfso.setOwner(new Path(remoteTmpProjDir), certUser, certUser);
                            }

                            String remoteProjAppDir = remoteTmpProjDir + File.separator + applicationId;
                            Path remoteProjAppPath = new Path(remoteProjAppDir);
                            if (!dfso.exists(remoteProjAppDir)) {
                                dfso.mkdir(remoteProjAppPath,
                                        new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.NONE));
                                dfso.setOwner(remoteProjAppPath, certUser, certUser);
                            }

                            dfso.copyToHDFSFromLocal(false, entry.getValue().getAbsolutePath(),
                                    remoteProjAppDir + File.separator + entry.getValue().getName());

                            dfso.setPermission(
                                    new Path(remoteProjAppDir + File.separator + entry.getValue().getName()),
                                    new FsPermission(FsAction.ALL, FsAction.NONE, FsAction.NONE));
                            dfso.setOwner(
                                    new Path(remoteProjAppDir + File.separator + entry.getValue().getName()),
                                    certUser, certUser);

                            projectLocalResources.add(new LocalResourceDTO(entry.getKey(),
                                    "hdfs://" + remoteProjAppDir + File.separator + entry.getValue().getName(),
                                    LocalResourceVisibility.APPLICATION.toString(),
                                    LocalResourceType.FILE.toString(), null));
                        }
                        break;
                    default:
                        break;
                    }
                }
            } catch (IOException ex) {
                LOG.log(Level.SEVERE, "Error writing project user certificates to local fs", ex);
            }

        } finally {
            if (jobType != null) {
                certMat.removeCertificatesLocal(username, project.getName());
            }
        }
    }
}

From source file:com.exilant.exility.core.LoadHandler.java

@Override
public void process(final String fileName, final String summaryFile) throws ExilityException {
    TestReportInterface testProcessor = new TestReport();

    File dir = new File(fileName);

    for (File testFolder : dir.listFiles()) {
        String qualifiedFileName = FilenameUtils.getName(testFolder.toString());

        if (qualifiedFileName.equals(Constants.DS_STORE) || (qualifiedFileName.equals(Constants.SUMMARY))) {
            continue;
        }//from   www.j  a  v  a2  s .c  o m
        try {
            testProcessor.process(testFolder.toString(), summaryFile);
        } catch (ExilityException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.thomasbolz.renamer.RenamerTest.java

@Test
public void testExcecuteCopyTasks() throws Exception {

    log.debug("\n*** testExcecuteCopyTasks ***\n");
    Renamer renamer = new Renamer(source, target);
    final Map<Path, List<CopyTask>> pathListMap = renamer.prepareCopyTasks();
    renamer.executeCopyTasks();//from w w  w .ja v a 2s  .  co m

    log.debug(renamer.getExcludedFiles());
    final File[] files = Paths.get(new File(".").getCanonicalPath(), "target", "dir1", "subdir").toFile()
            .listFiles();

    Assert.assertEquals(7, files.length);
    for (File file : files) {
        Assert.assertTrue(isIncludedFile(file.toString()));
    }

}

From source file:com.github.fge.jsonschema.main.cli.Main.java

private RetCode doSyntax(final Reporter reporter, final List<File> files) throws IOException {
    RetCode retcode, ret = ALL_OK;/* w  w w. j  av  a2 s  .c o m*/
    String fileName;
    JsonNode node;

    for (final File file : files) {
        fileName = file.toString();
        node = MAPPER.readTree(file);
        retcode = reporter.validateSchema(syntaxValidator, fileName, node);
        if (retcode != ALL_OK)
            ret = retcode;
    }

    return ret;
}

From source file:jeplus.EPlusWinTools.java

/**
 * Create working directory and prepare input files for simulation
 * @param config Not used in this function
 * @param workdir The directory to be created
 * @return Preparation successful or not
 *///from   w w w .  j a va 2 s.  c  om
public static boolean prepareWorkDir(EPlusConfig config, String workdir) {
    boolean success = true;
    // Create the directory
    File dir = new File(workdir);
    if (!dir.exists()) {
        success = dir.mkdirs();
    } else if (!dir.isDirectory()) {
        logger.error(dir.toString() + " is present but not a directory.");
        return false;
    }
    return success;
}

From source file:com.googlesource.gerrit.plugins.rabbitmq.Properties.java

public Config getPluginConfig(File cfgPath) {
    LOGGER.info("Loading " + cfgPath.toString() + " ...");
    FileBasedConfig cfg = new FileBasedConfig(cfgPath, FS.DETECTED);
    if (!cfg.getFile().exists()) {
        LOGGER.warn("No " + cfg.getFile());
        return cfg;
    }//from  w ww  . java  2s.  com
    if (cfg.getFile().length() == 0) {
        LOGGER.info("Empty " + cfg.getFile());
        return cfg;
    }

    try {
        cfg.load();
    } catch (ConfigInvalidException e) {
        LOGGER.info("Config file " + cfg.getFile() + " is invalid: " + e.getMessage());
    } catch (IOException e) {
        LOGGER.info("Cannot read " + cfg.getFile() + ": " + e.getMessage());
    }
    return cfg;
}

From source file:com.cloudera.sqoop.metastore.hsqldb.AutoHsqldbStorage.java

/**
 * Determine the user's home directory and return a connect
 * string to HSQLDB that uses ~/.sqoop/ as the storage location
 * for the metastore database.//from  ww  w  .j  a v  a  2s  .c o  m
 */
private String getHomeDirFileConnectStr() {
    String homeDir = System.getProperty("user.home");

    File homeDirObj = new File(homeDir);
    File sqoopDataDirObj = new File(homeDirObj, ".sqoop");
    File databaseFileObj = new File(sqoopDataDirObj, "metastore.db");

    String dbFileStr = databaseFileObj.toString();
    return "jdbc:hsqldb:file:" + dbFileStr + ";hsqldb.write_delay=false;shutdown=true";
}

From source file:com.sforce.dataset.DatasetUtilMain.java

public static void getRequiredParams(String action, PartnerConnection partnerConnection,
        DatasetUtilParams params) {/*  ww  w.ja v a2s.com*/
    if (action == null || action.trim().isEmpty()) {
        System.out.println("\nERROR: Invalid action {" + action + "}");
        System.out.println();
        return;
    } else if (action.equalsIgnoreCase("load")) {
        while (params.inputFile == null || params.inputFile.isEmpty()) {
            String tmp = getInputFromUser("Enter inputFile: ", true, false);
            if (tmp != null) {
                File tempFile = validateInputFile(tmp, action);
                if (tempFile != null) {
                    params.inputFile = tempFile.toString();
                    break;
                }
            } else
                System.out.println("File {" + tmp + "} not found");
            System.out.println();
        }

        if (params.dataset == null || params.dataset.isEmpty()) {
            params.dataset = getInputFromUser("Enter dataset name: ", true, false);
        }

        if (params.datasetLabel == null || params.datasetLabel.isEmpty()) {
            params.datasetLabel = getInputFromUser("Enter datasetLabel (Optional): ", false, false);
        }

        if (params.app == null || params.app.isEmpty()) {
            params.app = getInputFromUser("Enter datasetFolder (Optional): ", false, false);
            if (params.app != null && params.app.isEmpty())
                params.app = null;
        }

        while (params.Operation == null || params.Operation.isEmpty()) {
            params.Operation = getInputFromUser("Enter Operation (Default=Overwrite): ", false, false);
            if (params.Operation == null || params.Operation.isEmpty()) {
                params.Operation = "overwrite";
            } else {
                if (params.Operation.equalsIgnoreCase("overwrite")) {
                    params.Operation = "overwrite";
                } else if (params.Operation.equalsIgnoreCase("upsert")) {
                    params.Operation = "upsert";
                } else if (params.Operation.equalsIgnoreCase("append")) {
                    params.Operation = "append";
                } else if (params.Operation.equalsIgnoreCase("delete")) {
                    params.Operation = "delete";
                } else {
                    System.out.println("Invalid Operation {" + params.Operation
                            + "} Must be Overwrite or Upsert or Append or Delete");
                    params.Operation = null;
                }
            }

        }

        if (params.fileEncoding == null || params.fileEncoding.isEmpty()) {
            while (true) {
                params.fileEncoding = getInputFromUser("Enter fileEncoding (Optional): ", false, false);
                if (params.fileEncoding != null && !params.fileEncoding.trim().isEmpty()) {
                    try {
                        Charset.forName(params.fileEncoding);
                        break;
                    } catch (Throwable e) {
                    }
                } else {
                    params.fileEncoding = null;
                    break;
                }
                System.out.println("\nERROR: Invalid fileEncoding {" + params.fileEncoding + "}");
                System.out.println();
            }
        }

        while (params.uploadFormat == null || params.uploadFormat.isEmpty()) {
            String response = getInputFromUser("Parse file before uploading (Yes/No): ", false, false);
            if (response == null || response.isEmpty()) {
                params.uploadFormat = "binary";
                break;
            } else if (response != null && !(response.equalsIgnoreCase("Y") || response.equalsIgnoreCase("YES")
                    || response.equalsIgnoreCase("N") || response.equalsIgnoreCase("NO"))) {
                continue;
            } else if (response.equalsIgnoreCase("Y") || response.equalsIgnoreCase("YES")) {
                params.uploadFormat = "binary";
                break;
            } else {
                params.uploadFormat = "csv";
                break;
            }
            //            System.out.println();
        }

    } else if (action.equalsIgnoreCase("downloadErrorFile")) {
        if (params.dataset == null || params.dataset.isEmpty()) {
            params.dataset = getInputFromUser("Enter dataset name: ", true, false);
        }

    } else if (action.equalsIgnoreCase("detectEncoding")) {
        while (params.inputFile == null || params.inputFile.isEmpty()) {
            String tmp = getInputFromUser("Enter inputFile: ", true, false);
            if (tmp != null) {
                File tempFile = validateInputFile(tmp, action);
                if (tempFile != null) {
                    params.inputFile = tempFile.toString();
                    break;
                }
            } else
                System.out.println("File {" + tmp + "} not found");
            System.out.println();
        }

    } else if (action.equalsIgnoreCase("uploadxmd")) {
        while (params.inputFile == null || params.inputFile.isEmpty()) {
            String tmp = getInputFromUser("Enter inputFile: ", true, false);
            if (tmp != null) {
                File tempFile = validateInputFile(tmp, action);
                if (tempFile != null) {
                    params.inputFile = tempFile.toString();
                    break;
                }
            } else
                System.out.println("File {" + tmp + "} not found");
            System.out.println();
        }

        if (params.dataset == null || params.dataset.isEmpty()) {
            params.dataset = getInputFromUser("Enter dataset name: ", true, false);
        }
    } else if (action.equalsIgnoreCase("downloadxmd")) {
        if (params.dataset == null || params.dataset.isEmpty()) {
            params.dataset = getInputFromUser("Enter dataset name: ", true, false);
        }
    } else if (action.equalsIgnoreCase("defineAugmentFlow")) {

    } else if (action.equalsIgnoreCase("defineExtractFlow")) {
        while (params.rootObject == null || params.rootObject.isEmpty()) {
            String tmp = getInputFromUser("Enter root SObject name for Extract: ", true, false);
            Map<String, String> objectList = null;
            try {
                objectList = SfdcUtils.getObjectList(partnerConnection, Pattern.compile("\\b" + tmp + "\\b"),
                        false);
            } catch (ConnectionException e) {
            }
            if (objectList == null || objectList.size() == 0) {
                System.out.println("\nError: Object {" + tmp + "} not found");
                System.out.println();
            } else {
                params.rootObject = tmp;
                break;
            }
        }

    } else if (action.equalsIgnoreCase("downloadErrorFile")) {
        if (params.dataset == null || params.dataset.isEmpty()) {
            params.dataset = getInputFromUser("Enter dataset name: ", true, false);
        }
    } else {
        printUsage();
        System.out.println("\nERROR: Invalid action {" + action + "}");
    }
}

From source file:com.hpcloud.util.config.ConfigurationFactory.java

public T build(File file) throws IOException, ConfigurationException {
    final JsonNode node = mapper.readTree(file);
    final String filename = file.toString();
    return build(node, filename);
}