# Class ApplicationPart

java.lang.Object
org.apache.catalina.core.ApplicationPart

All Implemented Interfaces:
  `Part`

public class ApplicationPart extends Object implements Part
Adaptor to allow `FileItem` objects generated by the package renamed commons-upload to be used by the Servlet 3.0 upload API that expects `Part`s.

## Constructor Summary

Constructors
Constructor
Description
`ApplicationPart(FileItem fileItem, File location)`

## Method Summary

Modifier and Type
Method
Description
`void`
`delete()`
Deletes the underlying storage for a part, including deleting any associated temporary disk file.
`String`
`getContentType()`
Obtain the content type passed by the browser.
`String`
`getHeader(String name)`
Obtains the value of the specified part header as a String.
`Collection<String>`
`getHeaderNames()`
Get the header names provided for this part.
`Collection<String>`
`getHeaders(String name)`
Obtain all the values of the specified part header.
`InputStream`
`getInputStream()`
Obtain an `InputStream` that can be used to retrieve the contents of the file.
`String`
`getName()`
Obtain the name of the field in the multipart form corresponding to this part.
`long`
`getSize()`
Obtain the size of this part.
`String`
`getString(String encoding)`
`String`
`getSubmittedFileName()`
If this part represents an uploaded file, gets the file name submitted in the upload.
`void`
`write(String fileName)`
A convenience method to write an uploaded part to disk.

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

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

## Constructor Details

### ApplicationPart

public ApplicationPart(FileItem fileItem, File location)

## Method Details

### delete

public void delete() throws IOException
Description copied from interface: `jakarta.servlet.http.Part`
Deletes the underlying storage for a part, including deleting any associated temporary disk file. Although the container will delete this storage automatically this method can be used to ensure that this is done at an earlier time, thus preserving system resources.

Containers are only required to delete the associated storage when the Part instance is garbage collected. Apache Tomcat will delete the associated storage when the associated request has finished processing. Behaviour of other containers may be different.

Specified by:
  `delete` in interface `Part`
Throws:
  `IOException` - if an I/O occurs while attempting to delete the part

### getContentType

public String getContentType()
Description copied from interface: `jakarta.servlet.http.Part`
Obtain the content type passed by the browser.

Specified by:
  `getContentType` in interface `Part`
Returns:
  The content type passed by the browser or `null` if not defined.

### getHeader

public String getHeader(String name)
Description copied from interface: `jakarta.servlet.http.Part`
Obtains the value of the specified part header as a String. If there are multiple headers with the same name, this method returns the first header in the part. The header name is case-insensitive.

Specified by:
  `getHeader` in interface `Part`
Parameters:
  `name` - Header name
Returns:
  The header value or `null` if the header is not present

### getHeaderNames

public Collection<String> getHeaderNames()
Description copied from interface: `jakarta.servlet.http.Part`
Get the header names provided for this part.

Specified by:
  `getHeaderNames` in interface `Part`
Returns:
  a Collection of all the header names provided for this part.

### getHeaders

public Collection<String> getHeaders(String name)
Description copied from interface: `jakarta.servlet.http.Part`
Obtain all the values of the specified part header.

Specified by:
  `getHeaders` in interface `Part`
Parameters:
  `name` - The name of the header of interest. The header name is case-insensitive.
Returns:
  All the values of the specified part header. If the part did not include any headers of the specified name, this method returns an empty Collection.

### getInputStream

public InputStream getInputStream() throws IOException
Description copied from interface: `jakarta.servlet.http.Part`
Obtain an `InputStream` that can be used to retrieve the contents of the file.

Specified by:
  `getInputStream` in interface `Part`
Returns:
  An InputStream for the contents of the file
Throws:
  `IOException` - if an I/O occurs while obtaining the stream

### getName

public String getName()
Description copied from interface: `jakarta.servlet.http.Part`
Obtain the name of the field in the multipart form corresponding to this part.

Specified by:
  `getName` in interface `Part`
Returns:
  The name of the field in the multipart form corresponding to this part.

### getSize

public long getSize()
Description copied from interface: `jakarta.servlet.http.Part`
Obtain the size of this part.

Specified by:
  `getSize` in interface `Part`
Returns:
  The size of the part if bytes

### write

public void write(String fileName) throws IOException
Description copied from interface: `jakarta.servlet.http.Part`
A convenience method to write an uploaded part to disk. The client code is not concerned with whether the part is stored in memory, or on disk in a temporary location. They just want to write the uploaded part to a file. This method is not guaranteed to succeed if called more than once for the same part. This allows a particular implementation to use, for example, file renaming, where possible, rather than copying all of the underlying data, thus gaining a significant performance benefit.

Specified by:
  `write` in interface `Part`
Parameters:
  `fileName` - The location into which the uploaded part should be stored. Relative locations are relative to `MultipartConfigElement.getLocation()`
Throws:
  `IOException` - if an I/O occurs while attempting to write the part

### getString

public String getString(String encoding) throws UnsupportedEncodingException, IOException

Throws:
  `UnsupportedEncodingException`
  `IOException`

### getSubmittedFileName

public String getSubmittedFileName()
Description copied from interface: `jakarta.servlet.http.Part`
If this part represents an uploaded file, gets the file name submitted in the upload. Returns `null` if no file name is available or if this part is not a file upload.

Specified by:
  `getSubmittedFileName` in interface `Part`
Returns:
  the submitted file name or `null`.