FileDocCategorySizeDatePackage
FilePartSource.javaAPI DocAndroid 1.5 API4272Wed May 06 22:41:56 BST 2009com.android.internal.http.multipart

FilePartSource

public class FilePartSource extends Object implements PartSource
A PartSource that reads from a File.
author
Michael Becke
author
Mark Diggory
author
Mike Bowler
since
2.0

Fields Summary
private File
file
File part file.
private String
fileName
File part file name.
Constructors Summary
public FilePartSource(File file)
Constructor for FilePartSource.

param
file the FilePart source File.
throws
FileNotFoundException if the file does not exist or cannot be read

    
                                 
         
        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();       
        }
    
public FilePartSource(String fileName, File file)
Constructor for FilePartSource.

param
fileName the file name of the FilePart
param
file the source File for the FilePart
throws
FileNotFoundException if the file does not exist or cannot be read

        this(file);
        if (fileName != null) {
            this.fileName = fileName;
        }
    
Methods Summary
public java.io.InputStreamcreateInputStream()
Return a new {@link FileInputStream} for the current filename.

return
the new input stream.
throws
IOException If an IO problem occurs.
see
PartSource#createInputStream()

        if (this.file != null) {
            return new FileInputStream(this.file);
        } else {
            return new ByteArrayInputStream(new byte[] {});
        }
    
public java.lang.StringgetFileName()
Return the current filename

return
the filename.
see
PartSource#getFileName()

        return (fileName == null) ? "noname" : fileName;
    
public longgetLength()
Return the length of the file

return
the length of the file.
see
PartSource#getLength()

        if (this.file != null) {
            return this.file.length();
        } else {
            return 0;
        }