FileDocCategorySizeDatePackage
BinaryTempFileBody.javaAPI DocAndroid 1.5 API3068Wed May 06 22:42:46 BST 2009com.android.email.mail.internet

BinaryTempFileBody

public class BinaryTempFileBody extends Object implements com.android.email.mail.Body
A Body that is backed by a temp file. The Body exposes a getOutputStream method that allows the user to write to the temp file. After the write the body is available via getInputStream and writeTo one time. After writeTo is called, or the InputStream returned from getInputStream is closed the file is deleted and the Body should be considered disposed of.

Fields Summary
private static File
mTempDirectory
private File
mFile
Constructors Summary
public BinaryTempFileBody()

        if (mTempDirectory == null) {
            throw new
                RuntimeException("setTempDirectory has not been called on BinaryTempFileBody!");
        }
    
Methods Summary
public java.io.InputStreamgetInputStream()

        try {
            return new BinaryTempFileBodyInputStream(new FileInputStream(mFile));
        }
        catch (IOException ioe) {
            throw new MessagingException("Unable to open body", ioe);
        }
    
public java.io.OutputStreamgetOutputStream()

        mFile = File.createTempFile("body", null, mTempDirectory);
        mFile.deleteOnExit();
        return new FileOutputStream(mFile);
    
public static voidsetTempDirectory(java.io.File tempDirectory)

        mTempDirectory = tempDirectory;
    
public voidwriteTo(java.io.OutputStream out)

        InputStream in = getInputStream();
        Base64OutputStream base64Out = new Base64OutputStream(out);
        IOUtils.copy(in, base64Out);
        base64Out.close();
        mFile.delete();