Java Reference
In-Depth Information
Listing 7.1: Form Utility (FormUtility.java)
package com.heatonresearch.httprecipes.html;
import java.io.*;
import java.net.*;
import java.util.*;
public class FormUtility
{
/*
* The charset to use for URL encoding. Per URL coding
* spec, this value should always be UTF-8.
*/
private final static String encode = "UTF-8";
/*
* A Java random number generator.
*/
private static Random random = new Random();
/**
* Generate a boundary for a multipart form.
*
* @return The boundary.
*/
public static String getBoundary()
{
return "---------------------------" + randomString() +
randomString()
+ randomString();
}
/**
* Parse a URL query string. Return a map of all of the
* name value pairs.
*
* @param form
* The query string to parse.
* @return A map of name-value pairs.
*/
public static Map<String, String> parse(String form)
{
Map<String, String> result = new HashMap<String, String>();
StringTokenizer tok = new StringTokenizer(form, "&");
while (tok.hasMoreTokens())
{
Search WWH ::




Custom Search