Kayıtlar

Ekim, 2012 tarihine ait yayınlar gösteriliyor

Parsing a URL

Sample - 1 import java.net.*; import java.io.*; public class ParseURL { public static void main(String[] args) throws Exception { URL aURL = new URL("http://example.com:80/docs/books/tutorial" + "/index.html?name=networking#DOWNLOADING"); System.out.println("protocol = " + aURL.getProtocol()); System.out.println("authority = " + aURL.getAuthority()); System.out.println("host = " + aURL.getHost()); System.out.println("port = " + aURL.getPort()); System.out.println("path = " + aURL.getPath()); System.out.println("query = " + aURL.getQuery()); System.out.println("filename = " + aURL.getFile()); System.out.println("ref = " + aURL.getRef()); } } Here is the output displayed by the program: protocol = http authority = example.com:80 host = example.com port = 80 path = /docs/boo...

Quick and easy image resizing with Java ImageIO

Quick and easy image resizing with Java ImageIO There are quite a lot of examples of image resizing floating around the web but they all seem to access all sort of hidden features and classes deep inside the JDK to achieve their goal. Here is the most straightforward method that I could come up with - all in all just 5 lines of code. It requires ImageIO and requires Java 1.4 or later to run. If the ImageIO.write() method accepted plain ol' AWT Image arguments it could have been reduced further still to three lines, but you have to give it a BufferedImage instance as input. The snippet below assumes that there exist the following variables (coloured green in the code): an input stream to read from a desired width variable (specifying the height as -1 tells the toolkit to preserve the original aspect ratio) and an output stream to write the encoded image to. Sample code: import java.awt.Image; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; // .....

Get Images from link and store in movie folder on andriod

                            URL url = new URL(R.string.VM_01 + "movie_image/scene/kung_fu_panda_2/kung_fu_panda_2_1.jpg");                             InputStream is = url.openStream();                             OutputStream os = new FileOutputStream( "movie/pic/large/kung_fu_panda_2_1.jpg");                                                   ...

Android Simple Http Get Request without any Parameter

                    String result="";                     HttpClient httpclient = new  DefaultHttpClient();                                         // Prepare a request object                     HttpGet link = new HttpGet("http://12.133.183.155:8081/MCP/media/getMediaItems?page=1&pagesize=1");                                         // Execute the request                  ...