List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:MP3Player.java
public static void main(String[] args) throws Exception { File file = new File("test.mp3"); MediaLocator mrl = new MediaLocator(file.toURL()); Player player = Manager.createPlayer(mrl); player.start();/* w w w.jav a 2s.c o m*/ }
From source file:NoisyButton.java
public static void main(String[] args) throws Exception { java.io.File file = new java.io.File("bark.aiff"); AudioClip sound = Applet.newAudioClip(file.toURL()); sound.play();/*from w w w . ja v a 2s . com*/ }
From source file:Play.java
public static void main(String args[]) { try {//from w w w .j a v a2 s .c o m // Loop URL url = new URL("http://java.sun.com/applets/other/Hangman/audio/whoopy.au"); AudioClip clip = Applet.newAudioClip(url); clip.loop(); Thread.sleep(5000); //Play File file = new File("bark.wav"); clip = Applet.newAudioClip(file.toURL()); clip.play(); Thread.sleep(500); System.exit(0); } catch (InterruptedException e) { } catch (MalformedURLException e) { } }
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/a/b/a/test.txt"); URL uri;//from w w w. j a va 2s . co m try { uri = f.toURL(); System.out.println("uri: " + uri); } catch (MalformedURLException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("c:/mysql-connector-java-5.1.18-bin.jar"); URLClassLoader urlCl = new URLClassLoader(new URL[] { f.toURL() }, System.class.getClassLoader()); Class mySqlDriver = urlCl.loadClass("com.mysql.jdbc.Driver"); System.out.println(mySqlDriver.newInstance()); System.out.println("Is this interface? = " + mySqlDriver.isInterface()); Class interfaces[] = mySqlDriver.getInterfaces(); int i = 1;//from w w w . ja v a 2 s . c o m for (Class _interface : interfaces) { System.out.println("Implemented Interface Name " + (i++) + " = " + _interface.getName()); } Constructor constructors[] = mySqlDriver.getConstructors(); for (Constructor constructor : constructors) { System.out.println("Constructor Name = " + constructor.getName()); System.out.println("Is Constructor Accessible? = " + constructor.isAccessible()); } }
From source file:com.cyclopsgroup.waterview.jelly.JellyRunner.java
/** * Main entry to run a script//from w ww . j a v a2 s .co m * * @param args Script paths * @throws Exception Throw it out */ public static final void main(String[] args) throws Exception { List scripts = new ArrayList(); for (int i = 0; i < args.length; i++) { String path = args[i]; File file = new File(path); if (file.isFile()) { scripts.add(file.toURL()); } else { Enumeration enu = JellyRunner.class.getClassLoader().getResources(path); CollectionUtils.addAll(scripts, enu); } } if (scripts.isEmpty()) { System.out.println("No script to run, return!"); return; } String basedir = new File("").getAbsolutePath(); Properties initProperties = new Properties(System.getProperties()); initProperties.setProperty("basedir", basedir); initProperties.setProperty("plexus.home", basedir); WaterviewPlexusContainer container = new WaterviewPlexusContainer(); for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) { String initPropertyName = (String) j.next(); container.addContextValue(initPropertyName, initProperties.get(initPropertyName)); } container.addContextValue(Waterview.INIT_PROPERTIES, initProperties); container.initialize(); container.start(); JellyEngine je = (JellyEngine) container.lookup(JellyEngine.ROLE); JellyContext jc = new JellyContext(je.getGlobalContext()); for (Iterator i = scripts.iterator(); i.hasNext();) { URL script = (URL) i.next(); System.out.print("Running script " + script); jc.runScript(script, XMLOutput.createDummyXMLOutput()); System.out.println("... Done!"); } container.dispose(); }
From source file:org.apache.xml.security.samples.signature.VerifyCollectableSignature.java
/** * Method main//w w w. jav a2s. com * * @param unused * @throws Exception */ public static void main(String unused[]) throws Exception { javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE); try { File signatureFile = new File("collectableSignature.xml"); String BaseURI = signatureFile.toURL().toString(); System.out.println("Try to verify " + signatureFile.toURL().toString()); javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(new org.apache.xml.security.utils.IgnoreAllErrorHandler()); org.w3c.dom.Document doc = db.parse(new java.io.FileInputStream(signatureFile)); Element nscontext = SampleUtils.createDSctx(doc, "ds", Constants.SignatureSpecNS); NodeList signatureElems = XPathAPI.selectNodeList(doc, "//ds:Signature", nscontext); for (int i = 0; i < signatureElems.getLength(); i++) { Element sigElement = (Element) signatureElems.item(i); XMLSignature signature = new XMLSignature(sigElement, BaseURI); byte[] secretKey = "secretValue".getBytes(); System.out.println("The XML signature number " + i + " in file " + BaseURI + " is " + (signature.checkSignatureValue( signature.createSecretKey(CreateCollectableSignature.passphrase.getBytes())) ? "valid (good)" : "invalid !!!!! (bad)")); SignedInfo s = signature.getSignedInfo(); for (int j = 0; j < s.getSignedContentLength(); j++) { System.out.println("################ Signed Resource " + i + "/" + j + " ################"); System.out.println(new String(s.getSignedContentItem(j))); System.out.println(); } } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.cyclopsgroup.waterview.jelly.JellyScriptsRunner.java
/** * Main entry to run a script/*w ww . jav a 2 s.co m*/ * * @param args Script paths * @throws Exception Throw it out */ public static final void main(String[] args) throws Exception { List scripts = new ArrayList(); for (int i = 0; i < args.length; i++) { String path = args[i]; File file = new File(path); if (file.isFile()) { scripts.add(file.toURL()); } else { Enumeration enu = JellyScriptsRunner.class.getClassLoader().getResources(path); CollectionUtils.addAll(scripts, enu); } } if (scripts.isEmpty()) { System.out.println("No script to run, return!"); return; } String basedir = new File("").getAbsolutePath(); Properties initProperties = new Properties(System.getProperties()); initProperties.setProperty("basedir", basedir); initProperties.setProperty("plexus.home", basedir); WaterviewPlexusContainer container = new WaterviewPlexusContainer(); for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) { String initPropertyName = (String) j.next(); container.addContextValue(initPropertyName, initProperties.get(initPropertyName)); } container.addContextValue(Waterview.INIT_PROPERTIES, initProperties); container.initialize(); container.start(); JellyEngine je = (JellyEngine) container.lookup(JellyEngine.ROLE); JellyContext jc = new JellyContext(je.getGlobalContext()); XMLOutput output = XMLOutput.createXMLOutput(System.out); for (Iterator i = scripts.iterator(); i.hasNext();) { URL script = (URL) i.next(); System.out.print("Running script " + script); ExtendedProperties ep = new ExtendedProperties(); ep.putAll(initProperties); ep.load(script.openStream()); for (Iterator j = ep.getKeys("script"); j.hasNext();) { String name = (String) j.next(); if (name.endsWith(".file")) { File file = new File(ep.getString(name)); if (file.exists()) { System.out.println("Runner jelly file " + file); jc.runScript(file, output); } } else if (name.endsWith(".resource")) { Enumeration k = JellyScriptsRunner.class.getClassLoader().getResources(ep.getString(name)); while (j != null && k.hasMoreElements()) { URL s = (URL) k.nextElement(); System.out.println("Running jelly script " + s); jc.runScript(s, output); } } } //jc.runScript( script, XMLOutput.createDummyXMLOutput() ); System.out.println("... Done!"); } container.dispose(); }
From source file:org.apache.xml.security.samples.signature.CreateCollectableSignature.java
/** * Method main/*from w ww. ja v a 2 s . c o m*/ * * @param unused * @throws Exception */ public static void main(String unused[]) throws Exception { //J- File signatureFile = new File("collectableSignature.xml"); String BaseURI = signatureFile.toURL().toString(); //J+ javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.newDocument(); Element rootElement = doc.createElementNS(null, "root"); doc.appendChild(rootElement); /* Element signedResourceElement = doc.createElementNS("http://custom/", "custom:signedContent"); signedResourceElement.setAttributeNS(Constants.NamespaceNS, "xmlns:custom", "http://custom/"); signedResourceElement.setAttributeNS(null, "Id", "id0"); */ Element signedResourceElement = doc.createElementNS(null, "signedContent"); signedResourceElement.appendChild(doc.createTextNode("Signed Text\n")); rootElement.appendChild(signedResourceElement); XMLSignature sig = new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_MAC_HMAC_SHA1); signedResourceElement.appendChild(sig.getElement()); { String rootnamespace = signedResourceElement.getNamespaceURI(); boolean rootprefixed = (rootnamespace != null) && (rootnamespace.length() > 0); String rootlocalname = signedResourceElement.getNodeName(); Transforms transforms = new Transforms(doc); XPathContainer xpath = new XPathContainer(doc); xpath.setXPathNamespaceContext("ds", Constants.SignatureSpecNS); if (rootprefixed) { xpath.setXPathNamespaceContext("root", rootnamespace); } //J- String xpathStr = "\n" + "count( " + "\n" + " ancestor-or-self::" + (rootprefixed ? "root:" : "") + rootlocalname + "" + "\n" + " | " + "\n" + " here()/ancestor::" + (rootprefixed ? "root:" : "") + rootlocalname + "[1] " + "\n" + ") <= count( " + "\n" + " ancestor-or-self::" + (rootprefixed ? "root:" : "") + rootlocalname + "" + "\n" + ") " + "\n" + " and " + "\n" + "count( " + "\n" + " ancestor-or-self::ds:Signature " + "\n" + " | " + "\n" + " here()/ancestor::ds:Signature[1] " + "\n" + ") > count( " + "\n" + " ancestor-or-self::ds:Signature " + "\n" + ") " + "\n" ; //J+ xpath.setXPath(xpathStr); transforms.addTransform(Transforms.TRANSFORM_XPATH, xpath.getElementPlusReturns()); sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1); } { sig.getKeyInfo().add(new KeyName(doc, CreateCollectableSignature.passphrase)); System.out.println("Start signing"); sig.sign(sig.createSecretKey(CreateCollectableSignature.passphrase.getBytes())); System.out.println("Finished signing"); } FileOutputStream f = new FileOutputStream(signatureFile); XMLUtils.outputDOMc14nWithComments(doc, f); f.close(); System.out.println("Wrote signature to " + BaseURI); SignedInfo s = sig.getSignedInfo(); for (int i = 0; i < s.getSignedContentLength(); i++) { System.out.println("################ Signed Resource " + i + " ################"); System.out.println(new String(s.getSignedContentItem(i))); System.out.println(); } }
From source file:org.apache.xml.security.samples.signature.CreateNullURIReference.java
/** * Method main/* w w w .jav a 2s . com*/ * * @param unused * @throws Exception */ public static void main(String unused[]) throws Exception { //J- String keystoreType = "JKS"; String keystoreFile = "data/org/apache/xml/security/samples/input/keystore.jks"; String keystorePass = "xmlsecurity"; String privateKeyAlias = "test"; String privateKeyPass = "xmlsecurity"; String certificateAlias = "test"; File signatureFile = new File("signature.xml"); //J+ KeyStore ks = KeyStore.getInstance(keystoreType); FileInputStream fis = new FileInputStream(keystoreFile); ks.load(fis, keystorePass.toCharArray()); PrivateKey privateKey = (PrivateKey) ks.getKey(privateKeyAlias, privateKeyPass.toCharArray()); javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.newDocument(); String BaseURI = signatureFile.toURL().toString(); Constants.setSignatureSpecNSprefix(null); XMLSignature sig = new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_SIGNATURE_DSA); byte[][] memoryData = { "The secret data".getBytes(), "dataset 2".getBytes(), }; sig.addResourceResolver(new NullURIReferenceResolver(memoryData)); doc.appendChild(sig.getElement()); { sig.addDocument(null, null, Constants.ALGO_ID_DIGEST_SHA1); sig.addDocument(null, null, Constants.ALGO_ID_DIGEST_SHA1); } { X509Certificate cert = (X509Certificate) ks.getCertificate(certificateAlias); sig.addKeyInfo(cert); sig.addKeyInfo(cert.getPublicKey()); System.out.println("Start signing"); sig.sign(privateKey); System.out.println("Finished signing"); } FileOutputStream f = new FileOutputStream(signatureFile); XMLUtils.outputDOMc14nWithComments(doc, f); f.close(); System.out.println("Wrote signature to " + BaseURI); }