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.jaeksoft.searchlib.util.XPathParser.java

public XPathParser(File file) throws ParserConfigurationException, SAXException, IOException {
    this(file, DomUtils.readXml(new StreamSource(file.getAbsoluteFile()), true));
}

From source file:de.thischwa.pmcms.gui.dialog.pojo.DialogFieldsImageComp.java

@Override
public boolean isValid() {
    if (StringUtils.isBlank(textFilename.getText())) {
        dialogCreator.setErrorMessage(LabelHolder.get("dialog.pojo.image.error.file")); //$NON-NLS-1$
        return false;
    }/*from   ww w  . j a v  a2  s  .  c o m*/
    image.setTitle(textTitle.getText());
    image.setDescription(textDescription.getText());
    File galleryDir = PoPathInfo.getSiteGalleryDirectory(image.getParent());
    if (chosenImageFile != null && !FileTool.isInside(galleryDir, chosenImageFile)) { // image isn't inside the gallery dir
        try {
            File imageFile = FileTool.copyToDirectoryUnique(chosenImageFile, galleryDir);
            chosenImageFile = imageFile.getAbsoluteFile();
            textFilename.setText(imageFile.getName());
        } catch (IOException e1) {
            logger.error("While copying the image file inside gallery's directory: " + e1.getMessage(), e1); //$NON-NLS-1$
            dialogCreator.setErrorMessage(String.format("Error while copying [%s] to [%s]: %s",
                    chosenImageFile.getPath(), galleryDir.getPath()));
            return false;
        }
    }
    image.setFileName(textFilename.getText());
    return true;
}

From source file:org.bigloupe.web.scheduler.InitializeScheduler.java

private File getBackupFile(Props defaultProps, File initialJobDir) {
    File retVal = new File(initialJobDir.getAbsoluteFile(), "jobs.schedule.backup");

    String backupFile = defaultProps.getString("schedule.backup.file", null);
    if (backupFile != null)
        retVal = new File(backupFile);
    else/*  w  ww  . j a v a  2  s  . com*/
        logger.info("Schedule backup file param not set. Defaulting to " + retVal.getAbsolutePath());

    return retVal;
}

From source file:org.bigloupe.web.scheduler.InitializeScheduler.java

private File getScheduleFile(Props defaultProps, File initialJobDir) {
    File retVal = new File(initialJobDir.getAbsoluteFile(), "jobs.schedule");

    String scheduleFile = defaultProps.getString("schedule.file", null);
    if (scheduleFile != null)
        retVal = new File(scheduleFile);
    else/*  w  w w. j a  va2  s .  co  m*/
        logger.info("Schedule file param not set. Defaulting to " + retVal.getAbsolutePath());

    return retVal;
}

From source file:org.chimi.s4s.storage.localfs.LocalFSFileStorage.java

/**
 *  ? ?  ?  ? ?? ./*  ww  w  .j  a v  a 2  s  . c o m*/
 * <p>
 * []/yyyyMM/dd/
 * 
 * @param id
 * @param file
 * @throws IOException
 */
private void saveFile(FileId id, File file) throws IOException {
    File dir = makeDirectory(id);
    File target = new File(dir, id.toString());
    if (target.isFile() && target.exists()) {
        throw new AleadySameIDFileExists(
                String.format("Same ID[%s] file[%s] aleady exists.", id.getId(), target.getAbsoluteFile()));
    }
    copyFile(file, target);
}

From source file:com.splunk.shuttl.archiver.filesystem.hadoop.HadoopArchiveFileSystem.java

private void getFile(Path src, File temp, File dst) throws IOException {
    if (dst.exists())
        throw new FileOverwriteException();
    FileUtils.deleteDirectory(temp);/*w  w w  . j a  v  a2 s. co m*/
    hadoopFileSystem.copyToLocalFile(src, new Path(temp.getAbsoluteFile().toURI()));
}

From source file:hd3gtv.mydmam.auth.AuthenticationBackend.java

public static void checkFirstPlayBoot() throws Exception {
    if (authenticators == null) {
        throw new NullPointerException("No backend");
    }/*from  w w w. j  a  v  a 2 s.c om*/
    if (authenticators.size() == 0) {
        throw new NullPointerException("No backend");
    }
    if ((authenticators.get(0) instanceof AuthenticatorLocalsqlite) == false) {
        /**
         * Admin has set a configuration : no need to setup a first boot
         */
        return;
    }
    AuthenticatorLocalsqlite authenticatorlocalsqlite = (AuthenticatorLocalsqlite) authenticators.get(0);
    if (authenticatorlocalsqlite.isUserExists(ACLUser.ADMIN_NAME) == false) {
        String newpassword = passwordGenerator();
        authenticatorlocalsqlite.createUser(ACLUser.ADMIN_NAME, newpassword, "Local Admin", true);

        File textfile = new File("play-new-password.txt");
        FileWriter fw = new FileWriter(textfile, false);
        fw.write("Admin login: " + ACLUser.ADMIN_NAME + "\r\n");
        fw.write("Admin password: " + newpassword + "\r\n");
        fw.write("\r\n");
        fw.write("You should remove this file after keeping this password..\r\n");
        fw.write("\r\n");
        fw.write("You can change this password with mydmam-cli:\r\n");
        fw.write("$ mydmam-cli localauth -f " + authenticatorlocalsqlite.getDbfile().getAbsolutePath()
                + " -key " + authenticatorlocalsqlite.getMaster_password_key() + " -passwd -u "
                + ACLUser.ADMIN_NAME + "\r\n");
        fw.write("\r\n");
        fw.write(
                "Note: you haven't need a local authenticator if you set another backend and if you grant some new administrators\r\n");
        fw.close();

        Log2Dump dump = new Log2Dump();
        dump.add("login", ACLUser.ADMIN_NAME);
        dump.add("password file", textfile.getAbsoluteFile());
        dump.add("local database", authenticatorlocalsqlite.getDbfile());
        Log2.log.security("Create Play administrator account", dump);

    } else if (authenticatorlocalsqlite.isEnabledUser(ACLUser.ADMIN_NAME) == false) {
        throw new Exception("User " + ACLUser.ADMIN_NAME + " is disabled in sqlite file !");
    }

}

From source file:ezbake.frack.submitter.SubmitterService.java

@Override
public SubmitResult submit(ByteBuffer zip, String pipelineId) throws TException {
    File unzippedPack = null;//from   w  w w  .  j  a  v  a 2  s .c o m
    try {
        // Unzip the provided pack
        unzippedPack = UnzipUtil.unzip(new File("/tmp"), zip);

        // Find the jar path
        Optional<String> jarPath = UnzipUtil.getJarPath(unzippedPack);
        if (!jarPath.isPresent()) {
            return new SubmitResult(false,
                    "Could not find jar file. Make sure to place jar file in zip within bin/ directory");
        }
        final File jarFile = new File(jarPath.get());

        // Get the builder class
        Optional<String> builderClass = ClasspathUtil.findClassInJar(jarFile);
        if (!builderClass.isPresent()) {
            log.error("Could not find PipelineBuilder implementation in {}", jarFile.getName());
            return new SubmitResult(false,
                    "Could not find PipelineBuilder implementation in jar: " + jarFile.getName());
        }
        log.debug("Building pipeline with builder class {}", builderClass.get());

        SubmitterConfiguration config = new SubmitterConfiguration().setIngestSystem("Storm")
                .setBuilderClass(builderClass.get()).setPipelineId(pipelineId).setProduction(!insecure);

        Optional<String> confPath = UnzipUtil.getConfDirectory(unzippedPack);
        List<File> newFiles = Lists.newArrayList();
        if (confPath.isPresent()) {
            config.setUserPropertiesFolder(confPath.get());
            File confDir = new File(confPath.get());
            File stagingDir = new File(unzippedPack, "staging");
            stagingDir.mkdir();

            File newPropertiesDir = new File(stagingDir, "frack_properties");
            FileUtils.copyDirectory(confDir, newPropertiesDir);
            newFiles.add(newPropertiesDir);

            Optional<String> sslPath = UnzipUtil.getSSLPath(confDir);
            if (sslPath.isPresent()) {
                File sslDir = new File(sslPath.get());
                config.setSslDir(sslDir.getAbsoluteFile().getAbsolutePath());
                File newSSLDir = new File(stagingDir, "ssl");
                FileUtils.copyDirectory(sslDir, newSSLDir);
                newFiles.add(newSSLDir);
            } else {
                log.warn("No SSL directory found for {}, needed for using Thrift services", jarFile.getName());
            }

            File keyDir = UnzipUtil.findSubDir(unzippedPack, "keys");
            if (keyDir != null && keyDir.exists()) {
                File newKeyDir = new File(stagingDir, "keys");
                FileUtils.copyDirectory(keyDir, newKeyDir);
                newFiles.add(newKeyDir);
            } else {
                log.warn("No Keys directory found for {}, needed for broadcasting", jarFile.getName());
            }
        } else {
            log.warn("No configuration directory found for {}", jarFile.getName());
        }

        // Create the repackaged jar
        log.info("Repackaging jar with configuration information");
        File newJar = JarUtil.addFilesToJar(jarFile, newFiles);
        config.setPathToJar(newJar.getAbsolutePath());

        log.debug("Sending information to PipelineSubmitter");
        SubmitResult result = PipelineSubmitter.submit(config);
        log.info("Submission result: {}", result.getMessage());
        return result;
    } catch (IOException e) {
        String message = "Could not unzip provided build pack binary";
        log.error(message, e);
        throw new TException(message, e);
    } catch (InterruptedException e) {
        String message = "Interrupted exception occurred when submitting pipeline";
        log.error(message, e);
        throw new TException(message, e);
    } catch (ClassNotFoundException e) {
        String message = "PipelineBuilder class not found when interrogating jar file";
        log.error(message, e);
        throw new TException(message, e);
    } finally {
        if (unzippedPack != null && unzippedPack.exists()) {
            try {
                FileUtils.deleteDirectory(unzippedPack);
            } catch (IOException e) {
                throw new TException("Could not delete unzipped buildpack directory", e);
            }
        }
    }
}

From source file:com.c4om.autoconf.ulysses.configanalyzer.guilauncher.TemporaryChangesetFilesSavingGUILauncher.java

/**
 * For each extracted configuration, this stores at its temporary folder all
 * the changesets asociated to it./*from w w  w  .j ava  2  s.  c  o m*/
 * 
 * @param context
 *            the configuration context
 * @param target the target to filter from. If null, no per-target filtering will be performed.
 * @return a {@link List} the list of temporary folders with the extracted
 *         configurations and changesets.
 * @throws TemporaryStorageException If there is any problem storing the temporary files.
 * @throws GUILaunchException if there are other problems
 */
@SuppressWarnings("unchecked")
protected List<File> getTemporaryStoredChangesetsAndConfigs(ConfigurationAnalysisContext context, Target target)
        throws TemporaryStorageException, GUILaunchException {
    try {
        List<File> results = new ArrayList<File>(context.getExtractedConfigurations().size());
        for (ExtractedConfiguration<?> extractedConfiguration : context.getExtractedConfigurations()) {
            if (!(extractedConfiguration.getConfigurationData().size() > 0)
                    || !(extractedConfiguration.getConfigurationData().get(0) instanceof File)) {
                continue;
            }
            if (target != null && !extractedConfiguration.getTarget().equals(target)) {
                continue;
            }
            // First, we get the temporary folder. It is the parent path of
            // all the URIs, so we get the parent path of the first one
            File temporaryFolder = ((File) extractedConfiguration.getConfigurationData().get(0))
                    .getParentFile();
            List<Changeset<Document>> changesetsToStore = new ArrayList<>();
            // Now, we look for all the change sets related to the
            // configuration.
            for (Changeset<?> changeset : context.getChangesets()) {
                if (!(changeset.getChangesetData() instanceof Document)
                        || !changeset.getTarget().equals(extractedConfiguration.getTarget())) {
                    continue;
                }
                changesetsToStore.add((Changeset<Document>) changeset);
            }

            List<URI> changesetPathsForCatalog = new ArrayList<>(changesetsToStore.size());

            // Now, we store the change sets into the file system
            for (Changeset<Document> changesetToStore : changesetsToStore) {
                File changesetFile = new File(temporaryFolder, changesetToStore.getId() + ".xml");
                changesetPathsForCatalog.add(changesetFile.getAbsoluteFile().toURI());
                String changesetString = convertJDOMDocumentToString(changesetToStore.getChangesetData());
                BufferedWriter bw = new BufferedWriter(
                        new OutputStreamWriter(new FileOutputStream(changesetFile), StandardCharsets.UTF_8));
                bw.write(changesetString);
                bw.close();
            }

            //Now, we generate the catalog file from the changesets.
            generateCatalog(temporaryFolder, changesetPathsForCatalog);

            //Lastly, we add the temporary folder to the list of results.
            results.add(temporaryFolder);
        }
        return results;
    } catch (IOException e) {
        throw new TemporaryStorageException(e);
    }
}

From source file:dk.netarkivet.common.distribute.HTTPRemoteFile.java

/** Copy this remote file to the given file.
 * If the file resides on the current machine, remote file transfer is done
 * locally. Otherwise, the remote file is transferred over http.
 * If the file is not set to be able to be transferred multiple times, it is
 * cleaned up after the transfer.//  w ww  .  jav a 2  s.  c o  m
 * @param destFile The file to write the remote file to.
 * @throws ArgumentNotValid on null destFile, or parent to destfile is not
 * a writeable directory, or destfile exists and cannot be overwritten.
 * @throws IOFailure on I/O trouble writing remote file to destination.
 */
public void copyTo(File destFile) {
    ArgumentNotValid.checkNotNull(destFile, "File destFile");
    destFile = destFile.getAbsoluteFile();
    if ((!destFile.isFile() || !destFile.canWrite())
            && (!destFile.getParentFile().isDirectory() || !destFile.getParentFile().canWrite())) {
        throw new ArgumentNotValid(
                "Destfile '" + destFile + "' does not point to a writable file for remote file '" + file + "'");
    }
    if (isLocal() && fileDeletable && !multipleDownloads && !useChecksums) {
        if (file.renameTo(destFile)) {
            cleanup();
            return;
        }
        //if rename fails we fall back to normal usage.
    }
    super.copyTo(destFile);
}