Package org.apache.james.mime4j.util

Examples of org.apache.james.mime4j.util.TempFile


    }

    public void testCreateTempFile() throws IOException {
        SimpleTempStorage man = new SimpleTempStorage();
        TempPath path = man.getRootTempPath().createTempPath();
        TempFile file = path.createTempFile();
        assertTrue(file.getAbsolutePath().startsWith(path.getAbsolutePath()));
       
        String fileName = file.getAbsolutePath().substring(
                file.getAbsolutePath().lastIndexOf(File.separatorChar) + 1);
        assertTrue("Unexpected chars in file name " + fileName,
                    fileName.matches("^[0-9]+\\.tmp$"));
        assertTrue("Temp file doesn't exist",
                   new File(file.getAbsolutePath()).exists());
       
        String s = "A short string";
        OutputStream out = file.getOutputStream();
        out.write(s.getBytes());
        out.close();

        byte[] buffer = new byte[s.length() * 2];
        InputStream in = file.getInputStream();
        int i = 0;
        for (int data; (data = in.read()) != -1; i++) {
            buffer[i] = (byte) data;
        }
        in.close();
View Full Code Here


    }
   
    public void testCreateTempFileStringString() throws IOException {
        SimpleTempStorage man = new SimpleTempStorage();
        TempPath path = man.getRootTempPath().createTempPath();
        TempFile file = path.createTempFile("test_prefix", ".suffix");
        assertTrue(file.getAbsolutePath().startsWith(path.getAbsolutePath()));
       
        String fileName = file.getAbsolutePath().substring(
                file.getAbsolutePath().lastIndexOf(File.separatorChar) + 1);
        assertTrue("Unexpected chars in file name " + fileName,
                    fileName.matches("^test_prefix[0-9]+\\.suffix$"));
        assertTrue("Temp file doesn't exist",
                   new File(file.getAbsolutePath()).exists());
    }   
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.util.TempFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.