org.encog.util.http

## Class FormUtility

- java.lang.Object
- - org.encog.util.http.FormUtility

-     public class FormUtility
      extends Object

  This class is used to construct responses to HTML forms. The class supports both standard HTML forms, as well as multipart forms.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BUFFER_SIZE` The size of the read buffer.
    `static String` | `ENCODE` The charset to use for URL encoding.
    `static int` | `RANDOM_LENGTH` The length of random string to create for multipart.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FormUtility(OutputStream os, String boundary)` Prepare to access either a regular, or multipart, form.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(String name, File file)` Add a file to a multipart form.
    `void` | `add(String name, String value)` Add a regular text field to either a regular or multipart form.
    `void` | `complete()` Complete the building of the form.
    `static String` | `getBoundary()` Generate a boundary for a multipart form.
    `static Map<String,String>` | `parse(String form)` Parse a URL query string.
    `protected static String` | `randomString()` Generate a random string, of a specified length.
    `protected void` | `writeln(String str)` Write a string, with a carriage return and linefeed.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ENCODE

          public static final String ENCODE

      The charset to use for URL encoding. Per URL coding spec, this value should always be UTF-8.
      See Also:
        Constant Field Values

    - #### BUFFER_SIZE

          public static final int BUFFER_SIZE

      The size of the read buffer.
      See Also:
        Constant Field Values

    - #### RANDOM_LENGTH

          public static final int RANDOM_LENGTH

      The length of random string to create for multipart.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FormUtility

          public FormUtility(OutputStream os,
                     String boundary)

      Prepare to access either a regular, or multipart, form.
      Parameters:
        `os` - The stream to output to.
        `boundary` - The boundary to be used, or null if this is not a multipart form.

  - ### Method Detail

    - #### getBoundary

          public static String getBoundary()

      Generate a boundary for a multipart form.
      Returns:
        The boundary.

    - #### parse

          public static Map<String,String> parse(String form)

      Parse a URL query string. Return a map of all of the name value pairs.
      Parameters:
        `form` - The query string to parse.
      Returns:
        A map of name-value pairs.

    - #### randomString

          protected static String randomString()

      Generate a random string, of a specified length. This is used to generate the multipart boundary.
      Returns:
        A random string.

    - #### add

          public void add(String name,
                 File file)

      Add a file to a multipart form.
      Parameters:
        `name` - The field name.
        `file` - The file to attach.

    - #### add

          public void add(String name,
                 String value)

      Add a regular text field to either a regular or multipart form.
      Parameters:
        `name` - The name of the field.
        `value` - The value of the field.

    - #### complete

          public void complete()

      Complete the building of the form.

    - #### writeln

          protected void writeln(String str)

      Write a string, with a carriage return and linefeed.
      Parameters:
        `str` - The string to write.

Copyright © 2014. All Rights Reserved.