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:edu.ku.brc.af.ui.forms.ViewSetMgr.java

/**
 * Reads the Form Registry. The forms are loaded when needed and only one ViewSet can be the "core" ViewSet which is where most of the forms
 * reside. This could also be thought of as the "default" set of forms.
 * //from w w w  . j  av  a  2  s. c om
 * @param contextDirArg the directory in which load the view sets
 */
protected void init(final File contextDirArg, final boolean emptyIsOK) {
    this.contextDir = contextDirArg;
    this.registryExists = false;

    if (contextDirArg != null) {
        log.debug(contextDirArg.getAbsoluteFile());
        File vsRegFile = new File(contextDirArg.getAbsoluteFile() + File.separator + REGISTRY_FILENAME);
        if (vsRegFile.exists()) {
            registryExists = true;

            try {
                org.dom4j.Document document = readFileToDOM4J(new FileInputStream(vsRegFile));
                Element root = document.getRootElement();

                init(root);

            } catch (Exception ex) {
                log.error(ex);
                ex.printStackTrace();
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ViewSetMgr.class, ex);
            }
        } else if (!emptyIsOK) {
            throw new ConfigurationException(vsRegFile.getAbsoluteFile() + " doesn't exist.");
        }
    }
}

From source file:com.moss.appkeep.tools.MavenUploader.java

public List<Component> upload(File launchSpec, AppkeepService appkeep, IdProover idProver, boolean forceUpload)
        throws IdProovingException, SecurityException {

    // 1) select launch-spec
    Object o;/*from   w w  w. j  av a 2 s. c om*/
    try {
        JAXBContext jaxb = JAXBContext.newInstance(JavaAppSpec.class, JavaAppletSpec.class);

        o = jaxb.createUnmarshaller().unmarshal(launchSpec.toURL());
    } catch (Throwable e) {
        throw new RuntimeException("Error reading file \"" + launchSpec + "\"", e);
    }

    final List<Component> components = new LinkedList<Component>();

    if (o instanceof JavaAppSpec) {
        JavaAppSpec spec = (JavaAppSpec) o;

        {
            components.addAll(spec.components());

            for (BundleSpec b : spec.bundles()) {
                components.addAll(b.components());
            }

            for (AppProfile p : spec.profiles()) {
                components.addAll(p.components());
            }
        }
    } else if (o instanceof JavaAppletSpec) {
        JavaAppletSpec spec = (JavaAppletSpec) o;

        {
            components.addAll(spec.components());

            for (AppletProfile p : spec.profiles()) {
                components.addAll(p.components());
            }
        }
    }

    // 2) for each component (in each profile):
    for (Component c : components) {
        // a) locate the component in the maven repo (local, remote?)
        MavenCoordinatesHandle m = MavenArtifactGrabber.getMavenArtifact(c.artifactHandles());
        if (m == null) {
            throw new RuntimeException("Component has no maven handle: " + c);
        }

        final String logPrefix = c.type() + ": " + m;

        ComponentInfo info = appkeep.getInfo(new ComponentHandlesSelector(c.artifactHandles()),
                new UserAccountDownloadToken(idProver.giveProof()));

        //         List<ComponentInfo> matches = appkeep.listByMavenInfo(m.groupId(), m.artifactId(), m.version(), idProver.giveProof());

        if (forceUpload || info == null) {
            if (forceUpload) {
                log.info("[FORCING] " + logPrefix + " ");
            } else {
                log.info("[NOT IN KEEP] " + logPrefix + " ");
            }
            // b) download it
            SimpleArtifactFinder finder = new SimpleArtifactFinder();
            File location = finder.findLocal(m.groupId(), m.artifactId(), m.version());
            if (!location.exists()) {
                throw new RuntimeException("Cannot find " + m
                        + " in local repository.  I was expecting to find it at " + location.getAbsolutePath());
            }

            log.info(" found in local repository: " + location.getAbsoluteFile());

            InputStream data;
            try {
                data = new FileInputStream(location);
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
            try {
                log.info("uploading");
                // c) upload it if necessary
                appkeep.post(c.artifactHandles().toArray(new ComponentHandle[] {}), c.type(),
                        idProver.giveProof(), data);
                log.info("done");
            } catch (SecurityException e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    data.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        } else {
            log.info("[ALREADY IN KEEP] " + logPrefix + " ");
        }
    }
    /*
     * 3) upload the launch-spec itself?
     */

    return components;
}

From source file:easycare.load.util.db.loader.UserDataLoader.java

private void requestIDSCertificateForUser(ContextOfCurrentLoad context, User userWhoNeedsCert) {
    /*/* ww w.  j ava 2s. c  om*/
     * If BulkDataLoader is configured to also create IDS certificate
     * request for the created user, this section will create a CSV file
     * storing the username and IDS certificate retrieval passcode. The
     * passcode is then used to manually retrieve the corresponding
     * certificate to be packaged into the keystore uses by JMeter for
     * performance test. This poses no security threats as the user are test
     * users and the file is stored within the network of IDS & ECO.
     */
    if (context != null) {
        if (context.isIDSCertificateRequestToBeCreated() && !idsCertificatePasscodePath.isEmpty()) {
            String certificateRetrievalPasscode;
            try {
                certificateRetrievalPasscode = createIdsCertificateRequest(context, userWhoNeedsCert);
            } catch (IdsServiceException e) {
                log.error(e.getMessage(), e);
                certificateRetrievalPasscode = e.getMessage();
            }

            try {
                log.info("Appending IDS certificate retrieval passcode for user: "
                        + userWhoNeedsCert.getUsername() + " to CSV file at location: "
                        + idsCertificatePasscodePath);
                File file = new File(idsCertificatePasscodePath);
                if (!file.exists()) {
                    file.createNewFile();
                }
                PrintWriter pWriter = new PrintWriter(
                        new BufferedWriter(new FileWriter(file.getAbsoluteFile(), true)));
                pWriter.println(userWhoNeedsCert.getUsername() + "," + certificateRetrievalPasscode);
                pWriter.close();
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}

From source file:eu.scape_project.tool.toolwrapper.toolwrapper_bash_generator.BashWrapperGenerator.java

private void copySpecsToInstallDir(File outputDir, File toolSpec, File componentSpec) {
    Utils.copyFile(toolSpec,/*from  w w w  .j  a  v  a  2s.c o  m*/
            new File(outputDir.getAbsoluteFile() + File.separator + Constants.BASHGENERATOR_INSTALL_OUTDIRNAME,
                    toolSpec.getName()),
            false);
    if (componentSpec != null) {
        Utils.copyFile(componentSpec, new File(
                outputDir.getAbsoluteFile() + File.separator + Constants.BASHGENERATOR_INSTALL_OUTDIRNAME,
                componentSpec.getName()), false);
    }
}

From source file:com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever.java

private void extractEntry(TarArchiveInputStream tar, File destination, TarArchiveEntry entry)
        throws IOException {
    File file = new File(destination, entry.getName());
    if (entry.isDirectory()) {
        file.mkdirs();/*from  ww  w  . ja  v a  2 s.  c om*/
    } else {
        try (FileOutputStream fos = new FileOutputStream(file)) {
            logger.debug("Extracting {} to {}", entry.getName(), file.getAbsoluteFile());
            IOUtils.copy(tar, fos);
        }
    }
}

From source file:com.dien.manager.servlet.UploadShpServlet.java

public void getAllFile(File file, ArrayList slist) {
    if (file.isDirectory()) {
        // isHanzi(file.getAbsolutePath().toString());
        File[] filearry = file.listFiles();
        for (File f : filearry) {
            // isHanzi(f.getAbsolutePath().toString());
            if (f.isDirectory()) {
                getAllFile(f, slist);//from   w ww.ja  v a 2s . c o m
            } else {
                Matcher m = p.matcher(f.getAbsolutePath());
                if (m.matches()) {
                    String s = f.getAbsoluteFile().toString();
                    slist.add(s);
                }

            }
        }
    }
}

From source file:br.com.semanticwot.cd.controllers.UserController.java

private void createSettingsNodeRed(SystemUser systemUser) throws SettingsNodeRedNotCreated {
    try {/*from ww w  .j a v a  2  s  .com*/
        File file = new File(System.getProperty("user.home") + System.getProperty("file.separator")
                + Constants.NODERED_PATH + System.getProperty("file.separator") + Constants.SETTINGS_TEMPLATE);

        // O caminho esta correto
        //System.out.println(System.getProperty("user.home")
        //        + System.getProperty("file.separator")
        //        + Constants.NODERED_PATH
        //        + System.getProperty("file.separator")
        //        + Constants.SETTINGS_TEMPLATE);
        // Esta lendo o arquivo de boas
        //System.out.println(new String(Files.readAllBytes(file.toPath())));
        String text = new String(Files.readAllBytes(file.toPath()));

        File formated = new File(
                System.getProperty("user.home") + System.getProperty("file.separator") + Constants.NODERED_PATH
                        + System.getProperty("file.separator") + "settings_" + systemUser.getLogin() + ".js");

        FileWriter fw = new FileWriter(formated.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);

        // Editando o settings_template.js
        if (systemUser.getPerfilstatus().equals(PerfilStatus.PRIVATE)) {
            System.out.println("Entrei em privado");
            text = text.replace("{PROFILE}", "httpNodeAuth: {user:\"{1}\",pass:\"{2}\"},");
        } else {
            System.out.println("Entrei em publico");
            text = text.replace("{PROFILE}", "");
        }

        text = text.replace("{0}", String.valueOf(systemUser.getPort()));
        text = text.replace("{1}", systemUser.getLogin());
        text = text.replace("{2}", systemUser.getPassword());

        bw.write(text);
        bw.close();

    } catch (IOException ex) {
        Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
        throw new SettingsNodeRedNotCreated("Settings not created");
    }

}

From source file:com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever.java

private void writeMarkerFile(File destination, URI ovaOrOvfUri) {
    Properties props = new Properties();
    props.setProperty("download-uri", ovaOrOvfUri.toString());
    props.setProperty("download-date", new Date().toString());
    props.setProperty("download-folder", destination.getAbsolutePath());

    try {//w ww  . ja va 2  s .c  om
        File propFile = new File(destination, MARKER_FILE);
        try (FileOutputStream fos = new FileOutputStream(propFile)) {
            try {
                props.store(fos, null);
                logger.debug("Stored OVA download progress to {}", propFile.getAbsoluteFile());
            } catch (IOException ignore) {

            }
        }
    } catch (IOException e) {

    }
}

From source file:abfab3d.shapejs.ShapeJSGlobal.java

/**
 * js function to load a font// w w  w.  j a  va2  s  . c o  m
 * returns BufferedImage
 */
public static Object loadFont(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
    if (args.length < 1) {
        throw Context.reportRuntimeError("loadFont() requires one filename.");
    }

    String filename = Context.toString(args[0]);

    if (filename == null || filename.length() == 0) {
        throw Context.reportRuntimeError("No file provided for loadFont() command");
    }

    printf("loading font file: %s\n", filename);

    String reason = null;

    File f = new File(filename);
    Font font = null;
    if (!f.exists()) {
        throw Context.reportRuntimeError(fmt("Cannot find font file: %s\n", f.getAbsoluteFile()));
    }

    if (f.length() > 800000) {
        // Bit of security thought here, font's should not be too large unless they contain some malware payload
        throw Context.reportRuntimeError(fmt("Font file too large"));
    }
    try {
        int type = Font.TRUETYPE_FONT;
        if (filename.indexOf(".ttf") == -1)
            type = Font.TYPE1_FONT;
        font = Font.createFont(type, f);
    } catch (Exception e) {
        reason = e.getMessage();
        e.printStackTrace();
    }
    if (font == null) {
        throw Context.reportRuntimeError(fmt("failed to load font file: %s.  Reason: %s\n", filename, reason));
    }

    return font;
}

From source file:com.prowidesoftware.swift.model.mx.AbstractMX.java

/**
 * Writes the message document content into a file in XML format (headers not included).
 *
 * @param file a non null file to write, if it does not exists, it will be created
 * @since 7.7//from  ww w.j  a va  2  s.  com
 */
public void write(final File file) throws IOException {
    Validate.notNull(file, "the file to write cannot be null");
    if (!file.exists()) {
        file.createNewFile();
    }
    final FileOutputStream stream = new FileOutputStream(file.getAbsoluteFile());
    write(stream);
}