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 args[]) throws Exception { URL url = new URL(args[0]); Reader reader = new InputStreamReader((InputStream) url.getContent()); new ParserDelegator().parse(reader, new TextOnly(), false); }
From source file:MainClass.java
public static void main(String args[]) { URL u;// ww w .j av a 2 s . com URLConnection uc; String header; try { u = new URL("http://www.java2s.com"); uc = u.openConnection(); for (int j = 1;; j++) { header = uc.getHeaderField(j); if (header == null) break; System.out.println(uc.getHeaderFieldKey(j) + " " + header); } } catch (MalformedURLException e) { System.err.println("not a URL I understand."); } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) throws IOException { URL[] urls = { new URL("http://yourserver/small.png") }; for (URL url : urls) { ImageInputStream iis = ImageIO.createImageInputStream(url.openStream()); Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); System.out.println("url= " + url.getPath()); while (readers.hasNext()) { ImageReader read = readers.next(); System.out.println("format name = " + read.getFormatName()); }/*from ww w.java2 s . c o m*/ System.out.println(); } }
From source file:Main.java
public static void main(String[] args) throws IOException { URL url = new URL("http://www.java2s.com/style/download.png"); InputStream inputStream = url.openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int n = 0;//from w ww.j a v a2s.c o m while (-1 != (n = inputStream.read(buffer))) { output.write(buffer, 0, n); } inputStream.close(); byte[] data = output.toByteArray(); OutputStream out = new FileOutputStream("data.png"); out.write(data); out.close(); for (byte b : data) { System.out.printf("0x%x ", b); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { URL u = new URL("http://www.java2s.com"); HttpURLConnection uc = (HttpURLConnection) u.openConnection(); int code = uc.getResponseCode(); String response = uc.getResponseMessage(); System.out.println("HTTP/1.x " + code + " " + response); for (int j = 1;; j++) { String header = uc.getHeaderField(j); String key = uc.getHeaderFieldKey(j); if (header == null || key == null) break; System.out.println(uc.getHeaderFieldKey(j) + ": " + header); }/* w w w .ja va2 s . c om*/ InputStream in = new BufferedInputStream(uc.getInputStream()); Reader r = new InputStreamReader(in); int c; while ((c = r.read()) != -1) { System.out.print((char) c); } }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/style/download.png"); final Image img = ImageIO.read(url); Runnable r = new Runnable() { @Override/*w w w .j a va2s.c om*/ public void run() { JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(img))); } }; SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedImage master = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); BufferedImage gray = new BufferedImage(master.getWidth(), master.getHeight(), BufferedImage.TYPE_INT_ARGB); ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); op.filter(master, gray);/*from w w w . j av a2 s . c o m*/ // new JLabel(new ImageIcon(master)); // new JLabel(new ImageIcon(gray)); ImageIO.write(master, "png", new File("c:/Java_Dev/master.png")); ImageIO.write(gray, "png", new File("c:/Java_Dev/gray.png")); }
From source file:Main.java
public static void main(String[] args) { try {//w ww . j ava2s . c o m // get the java lang package Package pack = Package.getPackage("java.lang"); // check if this package is sealed URL url = new URL("http://www.oracle.com"); System.out.println("" + pack.isSealed(url)); } catch (MalformedURLException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Read from a URL URL url = new URL("http://java.org/source.gif"); Image image = ImageIO.read(url); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack();//from w w w .j av a 2 s .c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { URLConnection connection = new URL("http://api.androidhive.info/pizza/?format=xml").openConnection(); InputStream inputStream = connection.getInputStream(); XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream, "UTF-8"); while (streamReader.hasNext()) if (streamReader.next() == XMLStreamConstants.START_ELEMENT) System.out.println("START_ELEMENT " + streamReader.getName()); }