List of usage examples for java.net URI URI
public URI(String str) throws URISyntaxException
From source file:de.betterform.xml.xforms.xpath.saxon.function.xpath.FileSize.java
public Item evaluateItem(XPathContext xpathContext) throws XPathException { if (argument.length != 1) { throw new XPathException("There must be 1 argument (filename) for this function"); }//from ww w. j a v a 2s . c om final Expression keyExpression = argument[0]; final String filename = keyExpression.evaluateAsString(xpathContext).toString(); if (filename == null) { return new FloatValue(Float.NaN); } try { Container container = getContainer(xpathContext); return new FloatValue(new URI(container.getProcessor().getBaseURI()).resolve(filename).toURL() .openConnection().getContentLength()); } catch (Exception e) { LOGGER.error("Unable to retrieve file size", e); return new FloatValue(Float.NaN); } }
From source file:pl.chilldev.web.spring.config.XmlnsBeanDefinitionParser.java
/** * {@inheritDoc}//from w w w .j a va2 s .co m * @since 0.0.1 */ @Override public BeanDefinition parse(Element element, ParserContext parserContext) { try { URI namespace = new URI(element.getAttribute(XmlnsBeanDefinitionParser.ATTRIBUTE_NAMESPACE)); String alias = element.getAttribute(XmlnsBeanDefinitionParser.ATTRIBUTE_ALIAS); this.logger.info("Registring XML namespace \"{}\" with alias \"{}\".", namespace, alias); this.namespaces.put(namespace, alias); } catch (URISyntaxException error) { parserContext.getReaderContext().error("Invalid XML namespace URI.", element, error); } return null; }
From source file:com.couchbase.sqoop.mapreduce.db.CouchbaseRecordReadSerializeTest.java
@Before @Override/*from w ww . j a va 2 s . c o m*/ public void setUp() throws Exception { super.setUp(); tappedStuff = new HashMap<String, ResponseMessage>(); URI uri = new URI(CouchbaseUtils.CONNECT_STRING); String user = CouchbaseUtils.COUCHBASE_USER_NAME; String pass = CouchbaseUtils.COUCHBASE_USER_PASS; try { cb = new CouchbaseClient(Arrays.asList(uri), user, pass); } catch (IOException e) { LOG.error("Couldn't connect to server" + e.getMessage()); fail(e.toString()); } this.client = new TapClient(Arrays.asList(uri), user, pass); cb.flush(); Thread.sleep(500); // set up the items we're going to deserialize Integer anint = new Integer(Integer.MIN_VALUE); cb.set(anint.toString(), 0x300, anint).get(); Long along = new Long(Long.MAX_VALUE); cb.set(along.toString(), 0, along).get(); Float afloat = new Float(Float.MAX_VALUE); cb.set(afloat.toString(), 0, afloat).get(); Double doubleBase = new Double(Double.NEGATIVE_INFINITY); cb.set(doubleBase.toString(), 0, doubleBase).get(); Boolean booleanBase = true; cb.set(booleanBase.toString(), 0, booleanBase).get(); rightnow = new Date(); // instance, needed later dateText = rightnow.toString().replaceAll(" ", "_"); cb.set(dateText, 0, rightnow).get(); Byte byteMeSix = new Byte("6"); cb.set(byteMeSix.toString(), 0, byteMeSix).get(); String ourString = "hi,there"; cb.set(ourString.toString(), 0, ourString).get(); client.tapDump("tester"); while (client.hasMoreMessages()) { ResponseMessage m = client.getNextMessage(); if (m == null) { continue; } tappedStuff.put(m.getKey(), m); } }
From source file:fi.capeismi.fish.uistelupaivakirja.model.WeatherInfo.java
public WeatherInfo(String city, EventItem event) throws IllegalStateException, IOException, URISyntaxException, ParserConfigurationException, SAXException { m_city = city;//w ww . j a v a2 s .c om m_event = event; HttpClient httpclient = new DefaultHttpClient(); HttpGet get = new HttpGet(new URI("http://www.google.fi/ig/api?weather=" + m_city)); HttpResponse response = httpclient.execute(get); InputStream instream = response.getEntity().getContent(); parseXML(instream); instream.close(); }
From source file:nl.esciencecenter.octopus.webservice.mac.MacCredentialTest.java
@Test public void testMacCredentialStringStringURI() throws URISyntaxException { assertThat(cred.getAlgorithm()).isEqualTo("hmac-sha-1"); assertThat(cred.getId()).isEqualTo("id"); assertThat(cred.getKey()).isEqualTo("key"); assertThat(cred.getScope()).isEqualTo(new URI("http://localhost")); }
From source file:com.nebhale.cyclinglibrary.repository.RepositoryConfiguration.java
@Bean DataSource dataSource() throws URISyntaxException { String dbUrlProperty = System.getenv(DB_URL_PROPERTY_NAME); Assert.hasText(dbUrlProperty,/*from ww w. j a v a 2 s . co m*/ String.format("The enviroment variable '%s' must be specified", DB_URL_PROPERTY_NAME)); URI dbUri = new URI(dbUrlProperty); String username = dbUri.getUserInfo().split(":")[0]; String password = dbUri.getUserInfo().split(":")[1]; String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath() + "?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"; BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(Driver.class.getCanonicalName()); dataSource.setJdbcUrl(dbUrl); dataSource.setUsername(username); dataSource.setPassword(password); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.migrate(); return dataSource; }
From source file:eu.unifiedviews.plugins.transformer.gunzipper.GunzipperTest.java
@Test public void testSmallFile() throws Exception { GunzipperConfig_V1 config = new GunzipperConfig_V1(); // Prepare DPU. Gunzipper dpu = new Gunzipper(); dpu.configure((new ConfigurationBuilder()).setDpuConfiguration(config).toString()); // Prepare test environment. TestEnvironment environment = new TestEnvironment(); // Prepare data unit. WritableFilesDataUnit filesOutput = environment.createFilesOutput("filesOutput"); WritableFilesDataUnit filesInput = environment.createFilesInput("filesInput"); File inputFile = new File(URI.create(filesInput.addNewFile("LICENSE.gz"))); try (FileOutputStream fout = new FileOutputStream(inputFile)) { IOUtils.copy(Thread.currentThread().getContextClassLoader().getResourceAsStream("LICENSE.gz"), fout); }//from w w w .j a v a 2 s . c o m try { // Run. environment.run(dpu); // Get file iterator. Set<FilesDataUnit.Entry> outputFiles = FilesHelper.getFiles(filesOutput); Assert.assertEquals(1, outputFiles.size()); FilesDataUnit.Entry entry = outputFiles.iterator().next(); String outputContent = IOUtils.toString(new URI(entry.getFileURIString()), "US-ASCII"); String expectedContent = IOUtils.toString( Thread.currentThread().getContextClassLoader().getResourceAsStream("LICENSE"), "US-ASCII"); Assert.assertEquals(expectedContent, outputContent); Assert.assertEquals("LICENSE", VirtualPathHelpers.getVirtualPath(filesOutput, "LICENSE.gz")); } finally { // Release resources. environment.release(); } }
From source file:sample.mvc.JsonMessageParser.java
private User getUserFromUri(String userUri) throws Exception { URI uri = new URI(userUri); Map<String, String> extractUriTemplateVariables = pathMatcher.extractUriTemplateVariables("/users/{id}", uri.getPath());/*from w ww . j av a2 s. c o m*/ String idString = extractUriTemplateVariables.get("id"); Long id = Long.parseLong(idString); return userRepository.findOne(id); }
From source file:com.vmware.identity.interop.PlatformUtils.java
/** * Create URI with specified scheme, hostname and port * @param scheme// w w w . ja v a 2 s .c om * @param hostName * @param port * @return an URI object, or null in case of URISyntaxException. */ public static URI getConnectionUri(String scheme, String hostName, int port) { String uriStr = String.format("%s://%s:%d", scheme, hostName, port); try { return new URI(uriStr); } catch (URISyntaxException e) { logger.error(String.format("invalid uri string [%s] : %s", uriStr, e.getMessage())); return null; } }
From source file:gov.nih.nci.caarray.util.URIUserType.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s. c om*/ */ @Override public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o) throws SQLException { final String val = (String) Hibernate.STRING.nullSafeGet(inResultSet, names[0]); if (val == null) { return null; } URI uri = null; try { uri = new URI(val); } catch (final URISyntaxException e) { LOG.error("problem creating URI from " + val); } return uri; }