org.apache.commons.httpclient.methods.multipart
public class: FilePartSource [javadoc |
source]
java.lang.Object
org.apache.commons.httpclient.methods.multipart.FilePartSource
All Implemented Interfaces:
PartSource
A PartSource that reads from a File.
- author:
<
- a href="mailto:becke@u.washington.edu">Michael Becke
- author:
<
- a href="mailto:mdiggory@latte.harvard.edu">Mark Diggory
- author:
<
- a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler
- since:
2.0
-
Constructor: |
public FilePartSource(File file) throws FileNotFoundException {
this.file = file;
if (file != null) {
if (!file.isFile()) {
throw new FileNotFoundException("File is not a normal file.");
}
if (!file.canRead()) {
throw new FileNotFoundException("File is not readable.");
}
this.fileName = file.getName();
}
}
Constructor for FilePartSource. Parameters:
file - the FilePart source File.
Throws:
FileNotFoundException - if the file does not exist or
cannot be read
|
public FilePartSource(String fileName,
File file) throws FileNotFoundException {
this(file);
if (fileName != null) {
this.fileName = fileName;
}
}
Constructor for FilePartSource. Parameters:
fileName - the file name of the FilePart
file - the source File for the FilePart
Throws:
FileNotFoundException - if the file does not exist or
cannot be read
|
Method from org.apache.commons.httpclient.methods.multipart.FilePartSource Detail: |
public InputStream createInputStream() throws IOException {
if (this.file != null) {
return new FileInputStream(this.file);
} else {
return new ByteArrayInputStream(new byte[] {});
}
}
|
public String getFileName() {
return (fileName == null) ? "noname" : fileName;
}
Return the current filename |
public long getLength() {
if (this.file != null) {
return this.file.length();
} else {
return 0;
}
}
Return the length of the file |