List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:Main.java
public static void main(String[] argv) throws Exception { Sequence sequence = MidiSystem.getSequence(new File("midiaudiofile")); sequence = MidiSystem.getSequence(new URL("http://hostname/midiaudiofile")); // Create a sequencer for the sequence Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open();/*w w w .j ava 2 s . co m*/ sequencer.setSequence(sequence); double durationInSecs = sequencer.getMicrosecondLength() / 1000000.0; }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage image = ImageIO.read(url); int w = image.getWidth(); int h = image.getHeight(); Ellipse2D.Double ellipse1 = new Ellipse2D.Double(10, 10, 20, 30); Ellipse2D.Double ellipse2 = new Ellipse2D.Double(15, 15, 20, 30); Area circle = new Area(ellipse1); circle.subtract(new Area(ellipse2)); BufferedImage result = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g = result.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setClip(circle);// w ww. j av a 2 s . c o m g.drawImage(image, 0, 0, null); g.dispose(); ImageIO.write(result, "png", new File("result.png")); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://hostname:80/index.html"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str;// w w w.ja v a2s. c o m while ((str = in.readLine()) != null) { System.out.println(str); } in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ImageIcon icon = new ImageIcon(new URL("http://www.java2s.com/style/download.png")); JLabel iconLabel = new JLabel(icon); JPanel iconPanel = new JPanel(new GridBagLayout()); iconPanel.add(iconLabel);/* w w w. ja v a2 s. c o m*/ JPanel textPanel = new JPanel(new GridLayout(0, 1)); for (int i = 0; i < 15; i++) { textPanel.add(new JLabel("Hello")); } JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(textPanel); mainPanel.add(iconPanel, BorderLayout.WEST); JOptionPane.showMessageDialog(null, mainPanel, "Center Image Dialog", JOptionPane.PLAIN_MESSAGE); }
From source file:Main.java
public static void main(String[] args) throws Exception { CookieManager cm = new CookieManager(); cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cm); new URL("http://google.com").openConnection().getContent(); CookieStore cookieStore = cm.getCookieStore(); cookieStore.removeAll();/*from w w w.j a v a2s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { ImageInputStream imageStream = ImageIO.createImageInputStream(new URL("").openStream()); Iterator<ImageReader> readers = ImageIO.getImageReaders(imageStream); ImageReader reader = null;//from w w w . j av a 2s. co m if (!readers.hasNext()) { imageStream.close(); return; } else { reader = readers.next(); } String formatName = reader.getFormatName(); if (!formatName.equalsIgnoreCase("jpeg") && !formatName.equalsIgnoreCase("png") && !formatName.equalsIgnoreCase("gif")) { imageStream.close(); return; } reader.setInput(imageStream, true, true); BufferedImage theImage = reader.read(0); reader.dispose(); imageStream.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new URL("http://www.your server.com/daily.xml").openStream(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(is);//from w w w . j ava2s . c om NodeList nodeList = doc.getElementsByTagName("v"); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.getAttribute("currency").equals("BRL")) { System.out.println(element.getAttribute("rate")); } } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Sequence sequence = MidiSystem.getSequence(new File("midifile")); // From URL//from www. j a v a2s . co m sequence = MidiSystem.getSequence(new URL("http://hostname/midifile")); // Create a sequencer for the sequence Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(sequence); // Start playing sequencer.start(); }
From source file:Main.java
public static void main(String args[]) throws Exception { int c;/*from w ww . j a v a 2s .c om*/ URL hp = new URL("http://www.internic.net"); URLConnection hpCon = hp.openConnection(); long d = hpCon.getDate(); if (d == 0) System.out.println("No date information."); else System.out.println("Date: " + new Date(d)); System.out.println("Content-Type: " + hpCon.getContentType()); d = hpCon.getExpiration(); if (d == 0) System.out.println("No expiration information."); else System.out.println("Expires: " + new Date(d)); d = hpCon.getLastModified(); if (d == 0) System.out.println("No last-modified information."); else System.out.println("Last-Modified: " + new Date(d)); int len = hpCon.getContentLength(); if (len == -1) System.out.println("Content length unavailable."); else System.out.println("Content-Length: " + len); if (len != 0) { InputStream input = hpCon.getInputStream(); int i = len; while (((c = input.read()) != -1)) { // && (--i > 0)) { System.out.print((char) c); } input.close(); } else { System.out.println("No content available."); } }
From source file:Main.java
public static void main(String[] args) throws IOException { final int SCALE = 2; Image img = new ImageIcon(new URL("http://www.java2s.com/style/download.png")).getImage(); BufferedImage bi = new BufferedImage(SCALE * img.getWidth(null), SCALE * img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D grph = (Graphics2D) bi.getGraphics(); grph.scale(SCALE, SCALE);// ww w . j av a 2 s. co m grph.drawImage(img, 0, 0, null); grph.dispose(); ImageIO.write(bi, "png", new File("double_size.png")); }