Java Reference
In-Depth Information
/**
* This method will download an amortization table for the
* specified parameters.
* @param interest The interest rate for the loan.
* @param term The term(in months) of the loan.
* @param principle The principle amount of the loan.
* @throws IOException Thrown if a communication error occurs.
*/
public void process(double interest,int term,int principle)
throws IOException
{
URL url = new URL("http://www.httprecipes.com/1/9/loan.php");
URLConnection http = url.openConnection();
http.setDoOutput(true);
OutputStream os = http.getOutputStream();
FormUtility form = new FormUtility(os,null);
form.add("interest", ""+interest);
form.add("term", ""+term);
form.add("principle", ""+principle);
form.complete();
InputStream is = http.getInputStream();
ParseHTML parse = new ParseHTML(is);
StringBuilder buffer = new StringBuilder();
List<String> list = new ArrayList<String>();
boolean capture = false;
advance(parse,"table",3);
int ch;
while ((ch = parse.read()) != -1)
{
if (ch == 0)
{
HTMLTag tag = parse.getTag();
if (tag.getName().equalsIgnoreCase("tr"))
{
list.clear();
capture = false;
buffer.setLength(0);
} else if (tag.getName().equalsIgnoreCase("/tr"))
{
if (list.size() > 0)
{
processTableRow(list);
list.clear();
Search WWH ::




Custom Search