List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:MainClass.java
public static void main(String args[]) { String name = "http://urlWithClassName"; try {//from ww w .j ava2 s. c o m if (!name.endsWith(".class")) { System.err.println("That doesn't look like a byte code file!"); return; } URL u = new URL(name); URLClassLoader ucl = new URLClassLoader(u); // parse out the name of the class from the URL String s = u.getFile(); String classname = s.substring(s.lastIndexOf('/'), s.lastIndexOf(".class")); Class AppletClass = ucl.loadClass(classname, true); Applet apl = (Applet) AppletClass.newInstance(); JFrame f = new JFrame(); f.setSize(200, 200); f.add("Center", apl); apl.init(); apl.start(); f.setVisible(true); } catch (Exception e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(Main.class.getSimpleName()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BufferedImage bi = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(new ImageIcon(bi)); panel.add(label);//from w ww . ja v a 2 s . co m MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); ((JPanel) e.getSource()).scrollRectToVisible(r); } }; panel.addMouseMotionListener(doScrollRectToVisible); panel.setAutoscrolls(true); f.add(new JScrollPane(panel)); f.pack(); f.setSize(f.getWidth() / 2, f.getHeight() / 2); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myURL CHAR);"); String INSERT_RECORD = "insert into survey(id, myURL) values(?, ?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); pstmt.setURL(2, new URL("http://www.java2s.com")); pstmt.executeUpdate();//from w w w.j av a2 s . c o m ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); SOAPConnection connection = sfc.createConnection(); MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d"); URL endpoint = new URL("http://YourSOAPServer.com"); SOAPMessage response = connection.call(sm, endpoint); SOAPBody sb = response.getSOAPBody(); java.util.Iterator iterator = sb.getChildElements(bodyName); while (iterator.hasNext()) { SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next(); String val = bodyElement.getValue(); System.out.println("The Value is:" + val); }//w ww. j a va 2 s . c o m }
From source file:ChunksFontBackgroundPDF.java
public static void main(String[] args) { Document document = new Document(); try {// ww w .ja v a2 s.com PdfWriter.getInstance(document, new FileOutputStream("ChunksFontBackgroundPDF.pdf")); document.open(); Chunk test = new Chunk("some text"); float superscript = 8.0f; test.setTextRise(superscript); test.setBackground(new Color(0xFF, 0xDE, 0xAD)); test.setAnchor("http://www.java2s.com"); test.setAnchor(new URL("http://www.java2s.com")); document.add(test); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
From source file:MinAppletviewer.java
public static void main(String args[]) throws Exception { AppSupport theAppSupport = new AppSupport(); JFrame f = new JFrame(); URL toload = new URL(args[0]); String host = toload.getHost(); int port = toload.getPort(); String protocol = toload.getProtocol(); String path = toload.getFile(); int join = path.lastIndexOf('/'); String file = path.substring(join + 1); path = path.substring(0, join + 1);// w w w .ja va 2 s.c o m theAppSupport.setCodeBase(new URL(protocol, host, port, path)); theAppSupport.setDocumentBase(theAppSupport.getCodeBase()); URL[] bases = { theAppSupport.getCodeBase() }; URLClassLoader loader = new URLClassLoader(bases); Class theAppletClass = loader.loadClass(file); Applet theApplet = (Applet) (theAppletClass.newInstance()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(theApplet, BorderLayout.CENTER); theApplet.setStub(theAppSupport); f.setSize(200, 200); f.setVisible(true); theApplet.init(); theApplet.start(); }
From source file:AuthenticationHeader.java
public static void main(String[] args) { try {/*w ww. j a v a 2s. c om*/ URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); JAXBContext context = JAXBContext.newInstance(AuthenticationHeader.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(header, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:SOAPResponse.java
public static void main(String[] args) { try {// w ww. j av a 2s . co m SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); SOAPConnection connection = sfc.createConnection(); MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d"); URL endpoint = new URL("http://YourSOAPServer.com"); SOAPMessage response = connection.call(sm, endpoint); SOAPBody sb = response.getSOAPBody(); java.util.Iterator iterator = sb.getChildElements(bodyName); while (iterator.hasNext()) { SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next(); String val = bodyElement.getValue(); System.out.println("The Value is:" + val); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { ParserGetter kit = new ParserGetter(); HTMLEditorKit.Parser parser = kit.getParser(); URL u = new URL("http://www.java2s.com"); InputStream in = u.openStream(); InputStreamReader r = new InputStreamReader(in); String remoteFileName = u.getFile(); if (remoteFileName.endsWith("/")) { remoteFileName += "index.html"; }/*from ww w .j a va 2s . c om*/ if (remoteFileName.startsWith("/")) { remoteFileName = remoteFileName.substring(1); } File localDirectory = new File(u.getHost()); while (remoteFileName.indexOf('/') > -1) { String part = remoteFileName.substring(0, remoteFileName.indexOf('/')); remoteFileName = remoteFileName.substring(remoteFileName.indexOf('/') + 1); localDirectory = new File(localDirectory, part); } if (localDirectory.mkdirs()) { File output = new File(localDirectory, remoteFileName); FileWriter out = new FileWriter(output); HTMLEditorKit.ParserCallback callback = new PageSaver(out, u); parser.parse(r, callback, false); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] b = new byte[1]; Properties systemSettings = System.getProperties(); systemSettings.put("http.proxyHost", "proxy.mydomain.local"); systemSettings.put("http.proxyPort", "80"); Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("mydomain\\username", "password".toCharArray()); }/*from w ww.j av a 2 s . c om*/ }); URL u = new URL("http://www.google.com"); HttpURLConnection con = (HttpURLConnection) u.openConnection(); DataInputStream di = new DataInputStream(con.getInputStream()); while (-1 != di.read(b, 0, 1)) { System.out.print(new String(b)); } }