org.melati.servlet
Class BaseFileFormDataAdaptor

Package class diagram package BaseFileFormDataAdaptor
java.lang.Object
  extended by org.melati.servlet.BaseFileFormDataAdaptor
All Implemented Interfaces:
FormDataAdaptor
Direct Known Subclasses:
DefaultFileFormDataAdaptor, TemporaryFileFormDataAdaptor

public abstract class BaseFileFormDataAdaptor
extends Object
implements FormDataAdaptor

Common elements of uploading a file from an HTML form. We store the data uploaded from a multipart form by saving it to a file on disk and, optionally, give it an associated URL.


Field Summary
protected  int BUFSIZE
          Size for byte buffers.
 MultipartFormField field
          Information about the uploaded file.
protected  File file
          The file in which to save the data.
protected  String url
          A URL to the data.
 
Constructor Summary
BaseFileFormDataAdaptor()
           
 
Method Summary
protected abstract  File calculateLocalFile()
           
protected abstract  String calculateURL()
          Return a URL to the saved file, null if not appropriate.
 byte[] getData()
          Return the data in the file as a byte array.
 File getFile()
          Return a File object pointing to the saved data.
 long getSize()
          Return the size of the data.
 String getURL()
          Return a url to the object or null if none exists.
 void readData(MultipartFormField fieldP, DelimitedBufferedInputStream in, byte[] delim)
          Read data from in until the delim, work out which file to save it in, and save it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFSIZE

protected int BUFSIZE
Size for byte buffers.


file

protected File file
The file in which to save the data.


url

protected String url
A URL to the data.


field

public MultipartFormField field
Information about the uploaded file.

Constructor Detail

BaseFileFormDataAdaptor

public BaseFileFormDataAdaptor()
Method Detail

calculateLocalFile

protected abstract File calculateLocalFile()
Returns:
The file in which to save the data

calculateURL

protected abstract String calculateURL()
Return a URL to the saved file, null if not appropriate.

Returns:
a URL to the saved file, null if not appropriate

getData

public byte[] getData()
Return the data in the file as a byte array.

Specified by:
getData in interface FormDataAdaptor
Returns:
the data in the file as a byte array

getSize

public long getSize()
Return the size of the data.

Specified by:
getSize in interface FormDataAdaptor
Returns:
the size of the data as a long

getFile

public File getFile()
Return a File object pointing to the saved data.

Specified by:
getFile in interface FormDataAdaptor
Returns:
the file

getURL

public String getURL()
Description copied from interface: FormDataAdaptor
Return a url to the object or null if none exists.

Specified by:
getURL in interface FormDataAdaptor
Returns:
Url to the data, null if there isn't an appropriate one

readData

public void readData(MultipartFormField fieldP,
                     DelimitedBufferedInputStream in,
                     byte[] delim)
              throws IOException
Read data from in until the delim, work out which file to save it in, and save it.

Specified by:
readData in interface FormDataAdaptor
Parameters:
fieldP - a MultipartFormField
in - a DelimitedBufferedInputStream
delim - the delimiter used to denote elements
Throws:
IOException - if there is a problem reading the input


Copyright © 2000-2010 PanEris. All Rights Reserved.