1 25 package org.archive.io; 26 27 import java.io.ByteArrayInputStream ; 28 import java.io.ByteArrayOutputStream ; 29 import java.io.File ; 30 import java.io.IOException ; 31 32 import org.archive.util.TmpDirTestCase; 33 34 35 40 public class RecordingInputStreamTest extends TmpDirTestCase 41 { 42 43 44 47 protected void setUp() throws Exception 48 { 49 super.setUp(); 50 } 51 52 60 public void testReadFullyOrUntil() throws RecorderTimeoutException, IOException , InterruptedException 61 { 62 RecordingInputStream ris = new RecordingInputStream(16384, (new File ( 63 getTmpDir(), "testReadFullyOrUntil").getAbsolutePath())); 64 ByteArrayInputStream bais = new ByteArrayInputStream ( 65 "abcdefghijklmnopqrstuvwxyz".getBytes()); 66 ris.open(bais); 68 ris.readFullyOrUntil(7,10,0,0); 69 ris.close(); 70 ReplayInputStream res = ris.getReplayInputStream(); 71 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 72 res.readFullyTo(baos); 73 assertEquals("soft max cutoff","abcdefg",new String (baos.toByteArray())); 74 bais.reset(); 76 baos.reset(); 77 ris.open(bais); 78 boolean exceptionThrown = false; 79 try { 80 ris.readFullyOrUntil(13,10,0,0); 81 } catch (RecorderLengthExceededException ex) { 82 exceptionThrown = true; 83 } 84 assertTrue("hard max exception",exceptionThrown); 85 ris.close(); 86 res = ris.getReplayInputStream(); 87 res.readFullyTo(baos); 88 assertEquals("hard max cutoff","abcdefghijk", 89 new String (baos.toByteArray())); 90 } 92 } 93 | Popular Tags |