DiskFile (Apache Struts API Documentation)
Keywords: org.apache.struts.upload.DiskFile,DiskFile class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts.upload
Class DiskFile

    java.lang.Object
      |
      +--org.apache.struts.upload.DiskFile

All Implemented Interfaces:
  FormFile

public class DiskFile
extends java.lang.Object
implements FormFile

Field Summary
`protected java.lang.String` | `contentType` The content type of the file
`protected java.lang.String` | `fileName` The name of the file
`protected java.lang.String` | `filePath` The filepath to the temporary file
`protected int` | `fileSize` The size in bytes of the file

Constructor Summary
`DiskFile(java.lang.String filePath)`

Method Summary
`void` | `destroy()` Delete the temporary file.
`java.lang.String` | `getContentType()` Get the content type
`byte[]` | `getFileData()` Attempt to read the temporary file and get it's data in byte array form.
`byte[]` | `getFileData(int bufferSize)` Attempts to read a file n bytes at a time, n being equal to "bufferSize".
`java.lang.String` | `getFileName()` Get the file name
`java.lang.String` | `getFilePath()` Get the temporary file path for this form file
`int` | `getFileSize()` Get the file size
`java.io.InputStream` | `getInputStream()` Returns a FileInputStream to the file
`void` | `setContentType(java.lang.String contentType)` Set the content type
`void` | `setFileName(java.lang.String filename)` Set the file name
`void` | `setFileSize(int fileSize)` Set the file size

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### filePath

    protected java.lang.String filePath

  The filepath to the temporary file

### contentType

    protected java.lang.String contentType

  The content type of the file

### fileSize

    protected int fileSize

  The size in bytes of the file

### fileName

    protected java.lang.String fileName

  The name of the file

Constructor Detail

### DiskFile

    public DiskFile(java.lang.String filePath)

Method Detail

### getFileData

    public byte[] getFileData()
                       throws java.io.FileNotFoundException,
                              java.io.IOException

  Attempt to read the temporary file and get it's data in byte array form. Tries to read the entire file (using a byte array the size of getFileSize()) at once, in one call to FileInputStream.read(byte[]). For buffered reading, see `getFileData(int)`. Note that this method can be dangerous, and that the size of a file can cause an OutOfMemoryError quite easily. You should use `getInputStream` and do your own thing.

  Specified by:
    `getFileData` in interface `FormFile`
  Returns:
    The file data as a byte array.
  Throws:
    `java.io.FileNotFoundException` - If the temp file no longer exists
    `java.io.IOException` - if there is some sort of IO problem.
  See Also:
    `getFileData(int)`

### getFileData

    public byte[] getFileData(int bufferSize)
                       throws java.io.FileNotFoundException,
                              java.io.IOException

  Attempts to read a file n bytes at a time, n being equal to "bufferSize". Note that this method can be dangerous, and that the size of a file can cause an OutOfMemoryError quite easily. You should use `getInputStream` and do your own thing.

  Parameters:
    `bufferSize` - The size in bytes that are read from the file at a time
  Throws:
    `java.io.FileNotFoundException` - If the temp file no longer exists
    `java.io.IOException`

### destroy

    public void destroy()

  Delete the temporary file.

  Specified by:
    `destroy` in interface `FormFile`

### getFilePath

    public java.lang.String getFilePath()

  Get the temporary file path for this form file

  Returns:
    A filepath to the temporary file

### setFileName

    public void setFileName(java.lang.String filename)

  Set the file name

  Specified by:
    `setFileName` in interface `FormFile`
  Parameters:
    `filename` - The base file name.

### setContentType

    public void setContentType(java.lang.String contentType)

  Set the content type

  Specified by:
    `setContentType` in interface `FormFile`
  Parameters:
    `contentType` - The content type for the file.

### setFileSize

    public void setFileSize(int fileSize)

  Set the file size

  Specified by:
    `setFileSize` in interface `FormFile`
  Parameters:
    `fileSize` - The size of the file in bytes

### getFileName

    public java.lang.String getFileName()

  Get the file name

  Specified by:
    `getFileName` in interface `FormFile`
  Returns:
    The base file name.

### getContentType

    public java.lang.String getContentType()

  Get the content type

  Specified by:
    `getContentType` in interface `FormFile`
  Returns:
    A String representing content type.

### getFileSize

    public int getFileSize()

  Get the file size

  Specified by:
    `getFileSize` in interface `FormFile`
  Returns:
    The size of this file in bytes

### getInputStream

    public java.io.InputStream getInputStream()
                                       throws java.io.FileNotFoundException,
                                              java.io.IOException

  Returns a FileInputStream to the file

  Specified by:
    `getInputStream` in interface `FormFile`
  Throws:
    `java.io.FileNotFoundException` - if the uploaded file is not found.
    `java.io.IOException` - if an error occurred while reading the file.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2003 - Apache Software Foundation