List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:com.gs.tools.doc.extractor.core.util.HttpUtility.java
public static byte[] getExcelFromPost(String sourceUrl, String postString) throws Exception { byte[] result = null; URL targetUrl = new URL(sourceUrl); /*// w w w . ja va 2 s . c o m * Create http parameter to set Connection timeout = 300000 Socket/Read * timeout = 300000 Socket Read Buffer = 10485760 */ HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 300000); HttpConnectionParams.setSocketBufferSize(httpParams, 10485760); HttpConnectionParams.setSoTimeout(httpParams, 300000); // set the http param to the DefaultHttpClient HttpClient httpClient = new DefaultHttpClient(httpParams); // create POST method and set the URL and POST data HttpPost post = new HttpPost(targetUrl.toURI()); post.addHeader("Host", targetUrl.getHost()); post.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.0; rv:8.0) Gecko/20100101 Firefox/8.0"); post.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); post.addHeader("Accept-Language", "en-gb,en;q=0.5"); post.addHeader("Accept-Encoding", "gzip, deflate"); post.addHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); post.addHeader("Connection", "keep-alive"); post.addHeader("Content-Type", "application/x-www-form-urlencoded"); post.addHeader("X-Requested-With", "XMLHttpRequest"); StringEntity entity = new StringEntity(postString, "UTF-8"); post.setEntity(entity); logger.info("Execute the POST request with all input data"); // Execute the POST request on the http client to get the response HttpResponse response = httpClient.execute(post, new BasicHttpContext()); if (null != response && response.getStatusLine().getStatusCode() == 200) { HttpEntity httpEntity = response.getEntity(); if (null != httpEntity) { long contentLength = httpEntity.getContentLength(); logger.info("Content length: " + contentLength); logger.info("Content type: " + httpEntity.getContentType().getValue()); // no data, if the content length is insufficient if (contentLength <= 0) { return null; } // read the response to String InputStream responseStream = httpEntity.getContent(); if (null != responseStream) { result = IOUtils.toByteArray(responseStream); } } } logger.info("data read complete :: length " + result.length); return result; }
From source file:com.microsoft.applicationinsights.agent.internal.config.XmlAgentConfigurationBuilderTest.java
private AgentConfiguration testConfiguration(String testFileName) throws IOException { File folder = null;/*from w w w .j a va2s . c om*/ try { folder = createFolder(); ClassLoader classLoader = getClass().getClassLoader(); URL testFileUrl = classLoader.getResource(testFileName); File sourceFile = new File(testFileUrl.toURI()); File destinationFile = new File(folder, TEMP_CONF_FILE); FileUtils.copyFile(sourceFile, destinationFile); return new XmlAgentConfigurationBuilder().parseConfigurationFile(folder.toString()); } catch (java.net.URISyntaxException e) { return null; } finally { cleanFolder(folder); } }
From source file:com.stratumsoft.xmlgen.SchemaUtilTest.java
@Test public void testGetNamesFromSchemaWithImport() throws Exception { final InputStream is = getClass().getResourceAsStream(elementFormXsd); assertNotNull(is);/* w ww . j a v a2 s . co m*/ final StreamSource source = new StreamSource(is); final XmlSchemaCollection schemaColl = new XmlSchemaCollection(); final URL baseUrl = SchemaUtilTest.class.getResource(elementFormXsd); final String baseUri = baseUrl.toURI().toString(); schemaColl.setBaseUri(baseUri); final XmlSchema schema = schemaColl.read(source); assertNotNull(schema); System.out.println("There are " + schemaColl.getXmlSchemas().length + " schemas present"); final Collection<QName> elements = SchemaUtil.getElements(schema); assertNotNull(elements); assertFalse(elements.isEmpty()); System.out.println("Got the following elements from schema:"); CollectionUtils.forAllDo(elements, new Closure() { @Override public void execute(Object input) { System.out.println(input); } }); }
From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.XPathActivityParser.java
@Override public List<URI> getAdditionalSchemas() { URL xpathXsd = XPathActivityParser.class.getResource(ACTIVITY_XSD); try {/*from w w w.j ava 2 s .c om*/ return Arrays.asList(xpathXsd.toURI()); } catch (Exception e) { throw new IllegalStateException("Can't find XPath schema " + xpathXsd); } }
From source file:com.netflix.nicobar.core.archive.JarScriptArchiveTest.java
@Test public void testLoadTextJar() throws Exception { URL testJarUrl = getClass().getClassLoader().getResource(TEST_TEXT_JAR.getResourcePath()); Path jarPath = Paths.get(testJarUrl.toURI()).toAbsolutePath(); JarScriptArchive scriptArchive = new JarScriptArchive.Builder(jarPath) .setModuleSpec(new ScriptModuleSpec.Builder(ModuleId.create("testModuleId")).build()).build(); assertEquals(scriptArchive.getModuleSpec().getModuleId().toString(), "testModuleId"); Set<String> archiveEntryNames = scriptArchive.getArchiveEntryNames(); assertEquals(archiveEntryNames, TEST_TEXT_JAR.getContentPaths()); for (String entryName : archiveEntryNames) { URL entryUrl = scriptArchive.getEntry(entryName); assertNotNull(entryUrl);//ww w . j av a2s .c o m InputStream inputStream = entryUrl.openStream(); String content = IOUtils.toString(inputStream, Charsets.UTF_8); assertNotNull(content); } }
From source file:com.github.thesmartenergy.sparql.generate.jena.engine.Bnodes.java
public void test(String value) throws Exception { URL examplePath = Bnodes.class.getResource("/" + value); File exampleDir = new File(examplePath.toURI()); // read location-mapping URI confUri = exampleDir.toURI().resolve("configuration.ttl"); Model conf = RDFDataMgr.loadModel(confUri.toString()); // initialize file manager FileManager fileManager = FileManager.makeGlobal(); Locator loc = new LocatorFile(exampleDir.toURI().getPath()); LocationMapper mapper = new LocationMapper(conf); fileManager.addLocator(loc);/*from ww w . ja va 2 s . c o m*/ fileManager.setLocationMapper(mapper); String qstring = IOUtils.toString(fileManager.open("query.rqg"), "UTF-8"); SPARQLGenerateQuery q = (SPARQLGenerateQuery) QueryFactory.create(qstring, SPARQLGenerate.SYNTAX); // create generation plan PlanFactory factory = new PlanFactory(fileManager); RootPlan plan = factory.create(q); Model output = plan.exec(); // write output output.write(System.out, "TTL"); Model expectedOutput = fileManager.loadModel("expected_output.ttl"); StringWriter sw = new StringWriter(); expectedOutput.write(sw, "TTL"); LOG.debug("\n" + sw.toString()); Assert.assertTrue(output.isIsomorphicWith(expectedOutput)); }
From source file:com.jayway.maven.plugins.android.AbstractAndroidMojoTest.java
@Test public void givenAndroidManifestThenTargetPackageIsFound() throws MalformedURLException, URISyntaxException, MojoExecutionException { final URL url = this.getClass().getResource("AndroidManifest.xml"); final URI uri = url.toURI(); final File file = new File(uri); final String foundTargetPackage = androidMojo.extractPackageNameFromAndroidManifest(file); Assert.assertEquals("com.example.android.apis.tests", foundTargetPackage); }
From source file:com.jayway.maven.plugins.android.AbstractAndroidMojoTest.java
@Test public void givenAndroidManifestThenInstrumentationRunnerIsFound() throws MalformedURLException, URISyntaxException, MojoExecutionException { final URL url = this.getClass().getResource("AndroidManifest.xml"); final URI uri = url.toURI(); final File file = new File(uri); final String foundInstrumentationRunner = androidMojo.extractInstrumentationRunnerFromAndroidManifest(file); Assert.assertEquals("android.test.InstrumentationTestRunner", foundInstrumentationRunner); }
From source file:au.org.ala.delta.key.TreatCharactersAsVariableTest.java
@Test public void testTreatCharactersAsVariable() throws Exception { URL directivesFileURL = getClass().getResource("/sample/testTreatCharactersAsVariableInputFile"); File directivesFile = new File(directivesFileURL.toURI()); KeyContext context = new KeyContext(directivesFile); context.setMaximumNumberOfItems(100); context.setNumberOfCharacters(100);/*from w ww. ja va2 s . com*/ KeyDirectiveParser parser = KeyDirectiveParser.createInstance(); parser.parse(directivesFile, context); assertEquals(new HashSet<Integer>(Arrays.asList(ArrayUtils.toObject(new int[] { 44, 66 }))), context.getVariableCharactersForTaxon(1)); assertEquals(new HashSet<Integer>(Arrays.asList(ArrayUtils.toObject(new int[] { 4, 5, 6, 7, 8, 9, 10 }))), context.getVariableCharactersForTaxon(4)); KeyUtils.loadDataset(context); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(1, 44))); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(1, 66))); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(4, 4))); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(4, 5))); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(4, 6))); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(4, 7))); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(4, 8))); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(4, 9))); assertTrue(isVariable((MultiStateAttribute) context.getDataSet().getAttribute(4, 10))); }
From source file:com.spotify.docker.client.CompressedDirectoryTest.java
@Test public void testFile() throws Exception { // note: Paths.get(someURL.toUri()) is the platform-neutral way to convert a URL to a Path final URL dockerDirectory = Resources.getResource("dockerDirectory"); try (CompressedDirectory dir = CompressedDirectory.create(Paths.get(dockerDirectory.toURI())); BufferedInputStream fileIn = new BufferedInputStream(Files.newInputStream(dir.file())); GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(fileIn); TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn)) { final List<String> names = new ArrayList<>(); TarArchiveEntry entry;// w ww. j a v a2s.c om while ((entry = tarIn.getNextTarEntry()) != null) { final String name = entry.getName(); names.add(name); } assertThat(names, containsInAnyOrder("Dockerfile", "bin/date.sh", "innerDir/innerDockerfile")); } }