Example usage for java.io File toURI

List of usage examples for java.io File toURI

Introduction

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

Prototype

public URI toURI() 

Source Link

Document

Constructs a file: URI that represents this abstract pathname.

Usage

From source file:com.eviware.soapui.impl.wsdl.actions.project.AddWsdlAction.java

public void perform(WsdlProject project, Object param) {
    if (dialog == null) {
        dialog = ADialogBuilder.buildDialog(Form.class);
        dialog.setValue(Form.CREATEREQUEST, Boolean.toString(true));
        dialog.getFormField(Form.INITIALWSDL).addFormFieldListener(new XFormFieldListener() {
            public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
                String value = newValue.toLowerCase().trim();

                dialog.getFormField(Form.CREATEREQUEST).setEnabled(value.length() > 0);
                dialog.getFormField(Form.GENERATEMOCKSERVICE).setEnabled(newValue.trim().length() > 0);
                dialog.getFormField(Form.GENERATETESTSUITE).setEnabled(newValue.trim().length() > 0);
            }//from  w ww  .ja v a 2 s  .  c  om
        });
    } else {
        dialog.setValue(Form.INITIALWSDL, "");

        dialog.getFormField(Form.CREATEREQUEST).setEnabled(false);
        dialog.getFormField(Form.GENERATEMOCKSERVICE).setEnabled(false);
        dialog.getFormField(Form.GENERATETESTSUITE).setEnabled(false);
    }

    while (dialog.show()) {
        try {
            String url = dialog.getValue(Form.INITIALWSDL).trim();
            if (StringUtils.hasContent(url)) {
                String expUrl = PathUtils.expandPath(url, project);

                File wsdl = new File(expUrl);
                if (wsdl.exists())
                    url = wsdl.toURI().toURL().toString();

                log.info("importing: " + expUrl);
                WsdlInterface[] results = importWsdl(project, expUrl);

                if (!url.equals(expUrl))
                    for (WsdlInterface iface : results)
                        iface.setDefinition(url, false);

                break;
            }
        } catch (Exception ex) {
            UISupport.showErrorMessage(ex);
        }
    }
}

From source file:com.github.fhirschmann.clozegen.cli.Main.java

/**
 * Runs the command line interface.//from  w  w w.ja  v a 2 s.co  m
 *
 * <p>
 * You will need to pass a {@link ClozeTestGenerator} to this method. This
 * will allow you to, for example, add new input reader.
 * </p>
 *
 * @param gen the {@link ClozeTestGenerator} to use
 * @param args the arguments to the CLI
 */
public void run(final ClozeTestGenerator gen, final String[] args) {
    CommandLineParser parser = new PosixParser();
    options.addOption("h", "help", false, "print help message and exit");
    options.addOption("g", "generators", true, "generators to activate");
    options.addOption("l", "language", true, "language of the input file");
    options.addOption(null, "list-generators", false, "list all available gap generators");
    options.addOption(null, "list-input-methods", false, "list all available input methods");
    options.addOption(null, "list-output-methods", false, "list all available output methods");
    options.addOption("d", "debug", false, "enable debug mode");
    boolean debug = true;

    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("debug")) {
            Logger.getRootLogger().setLevel(Level.DEBUG);
        } else {
            Logger.getRootLogger().setLevel(Level.INFO);
            debug = false;
        }

        if (line.hasOption("help")) {
            printHelp();
            System.exit(0);
        }

        if (line.hasOption("list-generators")) {
            for (AnnotatorRegisterEntry entry : Registers.annotator()) {
                System.out.println(String.format("[%s]%s %s", entry.getIdentifier(),
                        entry.getSupportedLanguages(), entry.getName()));
            }
        } else if (line.hasOption("list-input-methods")) {
            for (ReaderRegisterEntry entry : Registers.reader()) {
                System.out.println(String.format("[.%s] %s", entry.getIdentifier(), entry.getName()));
            }
        } else if (line.hasOption("list-output-methods")) {
            for (WriterRegisterEntry entry : Registers.writer()) {
                System.out.println(String.format("[.%s] %s", entry.getIdentifier(), entry.getName()));
            }
        } else {
            checkArgument(line.getArgs().length == 2, "Exactly two arguments are required!");

            Map<String, Integer> generators = Maps.newHashMap();

            if (line.hasOption("generators")) {
                generators.putAll(Utils.parseGapClasses(line.getOptionValue("generators")));
            }

            gen.activate(generators);

            File inputFile = new File(line.getArgs()[0]);
            File outputFile = new File(line.getArgs()[1]);

            gen.run(inputFile.toURI().toURL(), outputFile.toURI().toURL(),
                    line.hasOption("language") ? line.getOptionValue("language") : "en");
        }

    } catch (Exception exp) {
        if (debug) {
            exp.printStackTrace();
        } else {
            System.err.println("ERROR: " + exp.getMessage());
        }
        printHelp();
    }
}

From source file:com.clican.pluto.orm.dynamic.impl.DynamicClassLoader.java

/**
 * This will be initialize by Spring Framework.
 * /*from  w  ww  .j av a2  s.  c om*/
 * @throws MalformedURLException
 * @throws ClassNotFoundException
 */
public void init() throws MalformedURLException, ClassNotFoundException {
    File file = new File(tempORMCfgPojoFolder);
    if (!file.exists()) {
        file.mkdirs();
    }
    urlClassLoader = new URLClassLoader(new URL[] { file.toURI().toURL() }, parent);
    loadAllClasses(file);
}

From source file:com.scorpio4.util.io.JarArchiver.java

public void open(File file) throws IOException {
    addAttribute(Attributes.Name.MANIFEST_VERSION, "1.0");
    addAttribute(Attributes.Name.IMPLEMENTATION_VENDOR, "Scorpio4");
    addAttribute(Attributes.Name.IMPLEMENTATION_VENDOR_ID, file.toURI().toString());
    jarOutputStream = new JarOutputStream(new FileOutputStream(file), manifest);
}

From source file:fr.efl.chaine.xslt.GauloisListenerTest.java

@Test
public void listenerStart() throws Exception {
    GauloisPipe piper = new GauloisPipe(configFactory);
    ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(),
            "./src/test/resources/listener/start.xml");
    Config config = cu.buildConfig(emptyInputParams);
    config.setLogFileSize(true);/*w w w. j a  va2 s.co  m*/
    config.verify();
    assertEquals("Port escape does not work", 8123, config.getSources().getListener().getPort());
    assertEquals("STOP keyword escape does not work", "ARRETE",
            config.getSources().getListener().getStopKeyword());
    piper.setConfig(config);
    piper.setInstanceName("LISTENER_1");
    piper.launch();
    DefaultHttpClient httpClient = new DefaultHttpClient();
    File userDir = new File(System.getProperty("user.dir"));
    File source = new File(userDir, "src/test/resources/source.xml");
    HttpPut put = new HttpPut("http://localhost:8123/?url="
            + URLEncoder.encode(source.toURI().toURL().toExternalForm(), "UTF-8"));
    HttpResponse response = httpClient.execute(put);
    System.out.println(response.getStatusLine().toString());
    assertEquals(200, response.getStatusLine().getStatusCode());
    put.releaseConnection();
    // the same, with accents
    source = new File(userDir, "src/test/resources/source_avec_accents.xml");
    put = new HttpPut("http://localhost:8123/?url="
            + URLEncoder.encode(source.toURI().toURL().toExternalForm(), "UTF-8"));
    response = httpClient.execute(put);
    System.out.println(response.getStatusLine().toString());
    assertEquals(200, response.getStatusLine().getStatusCode());
    put.releaseConnection();

    // we must let GauloisPipe process submitted file, because JUnit closes since the tested method returns.
    Thread.sleep(1000);
    File outputDir = new File("target/generated-test-files");
    File target = new File(outputDir, "source-listen1.xml");
    assertTrue("File " + target.toString() + " does not exists", target.exists());
    HttpDelete delete = new HttpDelete("http://localhost:8123/?keyword=ARRETE");
    response = httpClient.execute(delete);
    System.out.println(response.getStatusLine().toString());
    assertEquals(200, response.getStatusLine().getStatusCode());
    delete.releaseConnection();
    File appendee = new File(outputDir, "listener-appendee.txt");
    assertTrue(appendee.getAbsolutePath() + " does not exists.", appendee.exists());
    String previousLine = null;
    try (BufferedReader br = new BufferedReader(new FileReader(appendee))) {
        String currentLine = br.readLine();
        while (currentLine != null) {
            previousLine = currentLine;
            currentLine = br.readLine();
        }
    }
    assertEquals(appendee.getAbsolutePath() + " does not ends with \"EOF\"", "EOF", previousLine);
}

From source file:com.athena.peacock.engine.action.SshActionTest.java

@Test
public void perform() {
    // /*w w  w  .  j a  v a 2  s. co m*/
    commandList = new ArrayList<String>();
    commandList.add("echo Hello World!");
    commandList.add("touch SshAction");
    commandList.add("ls -al SshAction");
    commandList.add("rm -f SshAction");

    action = new SshAction(targetHost, commandList);

    try {
        // 
        action.perform();

        // ?
        File output = new File("exec_result.log");

        assertTrue("exec_result.log ??  .", output.exists());

        String resultMsg = IOUtils.toString(output.toURI());

        assertTrue(" ? \"Hello World!\"  .",
                resultMsg.indexOf("Hello World!") > -1);
        assertTrue(" ? \"SshAction\"?  .",
                resultMsg.indexOf("SshAction") > -1);
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Exception? ? ?.  ?    ? ? ?    .");
    }
}

From source file:de.bitinsomnia.webdav.server.MiltonFolderResource.java

private String getRootRelativePath(File file) {
    URI toInspectURI = file.toURI();
    URI relativePath = resourceFactory.getRootFolder().toURI().relativize(toInspectURI);
    return "/" + relativePath.getPath();
}

From source file:org.artifactory.repo.remote.browse.HtmlRepositoryBrowserTest.java

private File createValidHtml(File source) throws IOException {
    File tempFile = File.createTempFile("artifactory", "html");
    String fileContent = FileUtils.readFileToString(source);
    fileContent = fileContent.replace("{placeHolder}", tempFile.toURI().toURL().toExternalForm());
    FileUtils.writeStringToFile(tempFile, fileContent);
    return tempFile;
}

From source file:de.xwic.sandbox.server.ServletLifecycleListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    HibernateDAOProvider hbnDP = new HibernateDAOProvider();

    DAOFactory factory = CommonConfiguration.createCommonDaoFactory(hbnDP);

    DAOSystem.setDAOFactory(factory);// www .ja v a 2s .  com
    DAOSystem.setSecurityManager(new ServerSecurityManager());
    DAOSystem.setUseCaseService(new DefaultUseCaseService(hbnDP));
    DAOSystem.setFileHandler(new HbnFileOracleFixDAO());

    SandboxModelConfig.register(factory);
    StartModelConfig.register(factory);

    DemoAppModelConfig.register(factory);

    final ServletContext context = event.getServletContext();
    SandboxModelConfig.setWebRootDirectory(new File(context.getRealPath("/")));

    final String rootPath = context.getRealPath("");

    final File path = new File(rootPath + "/config");
    Setup setup;
    try {
        setup = XmlConfigLoader.loadSetup(path.toURI().toURL());
    } catch (Exception e) {
        log.error("Error loading product configuration", e);
        throw new RuntimeException("Error loading product configuration: " + e, e);
    }
    ConfigurationManager.setSetup(setup);

    if (!HibernateUtil.isInitialized()) {
        Configuration configuration = new Configuration();
        configuration.configure(); // load configuration settings from hbm file.
        // load properties
        Properties prop = new Properties();
        InputStream in = context.getResourceAsStream("WEB-INF/hibernate.properties");
        if (in == null) {
            in = context.getResourceAsStream("/WEB-INF/hibernate.properties");
        }
        if (in != null) {
            try {
                prop.load(in);
                configuration.setProperties(prop);
            } catch (IOException e) {
                log.error("Error loading hibernate.properties. Skipping this step! : " + e);
            }
        }
        HibernateUtil.initialize(configuration);
    }

    File prefStorePath = new File(new File(rootPath), "WEB-INF/prefstore");
    if (!prefStorePath.exists() && !prefStorePath.mkdirs()) {
        throw new IllegalStateException("Error initializing preference store: can not create directory "
                + prefStorePath.getAbsolutePath());
    }
    Platform.initialize(new StorageProvider(prefStorePath), new UserContextPreferenceProvider());

}

From source file:com.pinterest.terrapin.tools.HFileGeneratorTest.java

@Test
public void testGenerateHFiles() throws IOException {
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);
    int numOfPart = 10;
    int numOfKeys = 1000;
    HFileGenerator.generateHFiles(fs, conf, outputDir, PartitionerType.CASCADING, numOfPart, numOfKeys);
    FilenameFilter hfileFilter = new FilenameFilter() {
        @Override/* ww w. j  av  a 2 s.c o m*/
        public boolean accept(File dir, String name) {
            return name.startsWith(Constants.FILE_PREFIX);
        }
    };
    File[] hfiles = outputDir.listFiles(hfileFilter);
    assertEquals(numOfPart, hfiles.length);

    int count = 0;
    for (File hfile : hfiles) {
        HColumnDescriptor columnDescriptor = new HColumnDescriptor();
        columnDescriptor.setBlockCacheEnabled(false);
        HFile.Reader reader = HFile.createReader(fs, new Path(hfile.toURI()),
                new CacheConfig(conf, columnDescriptor));
        count += reader.getEntries();
        reader.close();
    }
    assertEquals(numOfKeys, count);
}