FileDocCategorySizeDatePackage
FileEntity.javaAPI DocAndroid 1.5 API3323Wed May 06 22:41:10 BST 2009org.apache.http.entity

FileEntity

public class FileEntity extends AbstractHttpEntity implements Cloneable
An entity whose content is retrieved from a file.
author
Oleg Kalnichevski
version
$Revision: 604625 $
since
4.0

Fields Summary
protected final File
file
Constructors Summary
public FileEntity(File file, String contentType)

        super();
        if (file == null) {
            throw new IllegalArgumentException("File may not be null");
        }
        this.file = file;
        setContentType(contentType);
    
Methods Summary
public java.lang.Objectclone()

        // File instance is considered immutable
        // No need to make a copy of it
        return super.clone();
    
public java.io.InputStreamgetContent()

        return new FileInputStream(this.file);
    
public longgetContentLength()

        return this.file.length();
    
public booleanisRepeatable()

        return true;
    
public booleanisStreaming()
Tells that this entity is not streaming.

return
false

        return false;
    
public voidwriteTo(java.io.OutputStream outstream)

        if (outstream == null) {
            throw new IllegalArgumentException("Output stream may not be null");
        }
        InputStream instream = new FileInputStream(this.file);
        try {
            byte[] tmp = new byte[4096];
            int l;
            while ((l = instream.read(tmp)) != -1) {
                outstream.write(tmp, 0, l);
            }
            outstream.flush();
        } finally {
            instream.close();
        }