Code example for URLConnection

Methods: connect, getContentLength, getInputStream

0
 
	public byte[] getContent() throws Exception 
	{ 
		URL url = new URL(getUrl().getPath());
		URLConnection connect = url.openConnection();
		connect.connect();
		if( connect.getContentLength() > 10000 * 1024 )
		{ 
			log.error(getUrl() +" is over 10 megs");
			return null; 
		} 
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		InputStream in = connect.getInputStream();
		try 
		{ 
			new OutputFiller().fill(in, out);
		} 
		finally 
		{ 
			in.close();
		}