org.apache.cocoon.servlet.multipart
Class Part

java.lang.Object
  extended byorg.apache.cocoon.servlet.multipart.Part
All Implemented Interfaces:
Disposable
Direct Known Subclasses:
PartInMemory, PartOnDisk, RejectedPart

public abstract class Part
extends Object
implements Disposable

This abstract class represents a file part parsed from a http post stream. The concrete class, PartOnDisk or PartInMemory that is used depends on the upload configuration in web.xml.

If uploaded data size exceeds the maximum allowed upload size (also specified in web.xml), then an RejectedPart is used, from which no data can be obtained, but which gives some information on the rejected uploads.

Version:
$Id: Part.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  Map headers
          Field headers
 
Constructor Summary
protected Part(Map headers)
           
 
Method Summary
 void copyToFile(String filename)
          Convenience method to copy a part to a file.
 void copyToSource(ModifiableSource source)
          Convenience method to copy a part to a modifiable source.
abstract  void dispose()
          Dispose any resources held by this part, such as a file or memory buffer.
 boolean disposeWithRequest()
          Do we want any temporary resource held by this part to be cleaned up when processing of the request that created it is finished? Default is true.
abstract  String getFileName()
          Returns the filename
 Map getHeaders()
          Returns the part headers
abstract  InputStream getInputStream()
          Returns an InputStream containing the file data
 String getMimeType()
          Returns the mime type (or null if unknown)
abstract  int getSize()
          Returns the length of the file content
 String getUploadName()
          Returns the original filename
 boolean isRejected()
          Is this part a rejected part? Provided as an alternative to instanceof RejectedPart in places where it's not convenient such as flowscript.
 void setDisposeWithRequest(boolean dispose)
          Set the value of the disposeWithRequest flag (default is true).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

headers

protected Map headers
Field headers

Constructor Detail

Part

protected Part(Map headers)
Method Detail

getHeaders

public Map getHeaders()
Returns the part headers


getFileName

public abstract String getFileName()
Returns the filename


getUploadName

public String getUploadName()
Returns the original filename


getSize

public abstract int getSize()
Returns the length of the file content


isRejected

public boolean isRejected()
Is this part a rejected part? Provided as an alternative to instanceof RejectedPart in places where it's not convenient such as flowscript.

Returns:
true if this part was rejected

getMimeType

public String getMimeType()
Returns the mime type (or null if unknown)


disposeWithRequest

public boolean disposeWithRequest()
Do we want any temporary resource held by this part to be cleaned up when processing of the request that created it is finished? Default is true.

Returns:
true if the part should be disposed with the request.

setDisposeWithRequest

public void setDisposeWithRequest(boolean dispose)
Set the value of the disposeWithRequest flag (default is true).

Parameters:
dispose - true if the part should be disposed after request processing

getInputStream

public abstract InputStream getInputStream()
                                    throws IOException
Returns an InputStream containing the file data

Throws:
IOException

copyToSource

public void copyToSource(ModifiableSource source)
                  throws IOException
Convenience method to copy a part to a modifiable source.

Parameters:
source - the modifiable source to write to
Throws:
IOException
Since:
2.1.8

copyToFile

public void copyToFile(String filename)
                throws IOException
Convenience method to copy a part to a file.

Parameters:
filename - name of the file to write to
Throws:
IOException
Since:
2.1.8

dispose

public abstract void dispose()
Dispose any resources held by this part, such as a file or memory buffer.

Disposal occurs in all cases when the part is garbage collected, but calling it explicitely allows to cleanup resources more quickly.

Specified by:
dispose in interface Disposable


Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.