assertTrue(vd.isByteArray());
}
public void testCreateFileStreamTransientValueData() throws Exception
{
FileCleaner testFileCleaner = new FileCleaner();
try
{
byte[] buf = "0123456789".getBytes();
File file = new File("target/testCreateFileStreamTransientValueData");
if (file.exists())
file.delete();
FileOutputStream out = new FileOutputStream(file);
out.write(buf);
out.close();
FileInputStream fs1 = new FileInputStream(file);
SpoolConfig spoolConfig = SpoolConfig.getDefaultSpoolConfig();
spoolConfig.maxBufferSize = 5;
TransientValueData vd = new TransientValueData(0, fs1, null, spoolConfig);
// spool to file
InputStream fs2 = vd.getAsStream();
assertEquals(10, vd.getLength());
assertTrue(fs2 instanceof FileInputStream);
// not the same object as new is is from spool file
assertNotSame(fs1, fs2);
// spooled to file so not a byte array
assertFalse(vd.isByteArray());
// next call return not the same object as well
// (new stream every time)
assertNotSame(vd.getAsStream(), fs2);
assertEquals(10, vd.getLength());
// gets as byte array
assertEquals(10, vd.getAsByteArray().length);
// but still spooled to file
assertFalse(vd.isByteArray());
}
finally
{
testFileCleaner.halt();
}
}