org.melati.servlet
Class BaseFileDataAdaptor

java.lang.Object
  extended by org.melati.servlet.BaseFileDataAdaptor
All Implemented Interfaces:
FormDataAdaptor
Direct Known Subclasses:
DefaultFileDataAdaptor, TemporaryFileDataAdaptor

public abstract class BaseFileDataAdaptor
extends java.lang.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  java.io.File file
          The file in which to save the data.
protected  java.lang.String url
          A URL to the data.
 
Constructor Summary
BaseFileDataAdaptor()
           
 
Method Summary
protected abstract  java.io.File calculateLocalFile()
           
protected abstract  java.lang.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.
 java.io.File getFile()
          Return a File object pointing to the saved data.
 long getSize()
          Return the size of the data.
 java.lang.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 java.io.File file
The file in which to save the data.


url

protected java.lang.String url
A URL to the data.


field

public MultipartFormField field
Information about the uploaded file.

Constructor Detail

BaseFileDataAdaptor

public BaseFileDataAdaptor()
Method Detail

calculateLocalFile

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

calculateURL

protected abstract java.lang.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 java.io.File getFile()
Return a File object pointing to the saved data.

Specified by:
getFile in interface FormDataAdaptor
Returns:
the file

getURL

public java.lang.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 java.io.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:
java.io.IOException - if there is a problem reading the input


Copyright © 2000-2008 PanEris. All Rights Reserved.