1 19 package org.apache.avalon.excalibur.monitor.test; 20 21 import java.io.ByteArrayInputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.InputStreamReader ; 25 import java.io.OutputStream ; 26 import java.io.OutputStreamWriter ; 27 import java.io.Reader ; 28 import java.io.Writer ; 29 30 import org.apache.avalon.excalibur.monitor.ResourceOutputStream; 31 import org.apache.avalon.excalibur.monitor.ResourceWriter; 32 import org.apache.avalon.excalibur.monitor.StreamResource; 33 34 39 public class MockResource extends StreamResource 40 { 41 private final Mock m_mock; 42 43 46 public MockResource( final String resource ) 47 throws Exception 48 { 49 this( new Mock( resource ) ); 50 } 51 52 public MockResource( final Mock resource ) 53 throws Exception 54 { 55 super( resource.getName() ); 56 m_mock = resource; 57 setPreviousModified( m_mock.lastModified() ); 58 } 59 60 63 public long lastModified() 64 { 65 return m_mock.lastModified(); 66 } 67 68 71 public InputStream getResourceAsStream() 72 throws IOException 73 { 74 return new ByteArrayInputStream ( m_mock.getContent().getBytes() ); 75 } 76 77 80 public Reader getResourceAsReader() 81 throws IOException 82 { 83 return new InputStreamReader ( getResourceAsStream() ); 84 } 85 86 89 public OutputStream setResourceAsStream() 90 throws IOException 91 { 92 return new ResourceOutputStream( new MockOutputStream( m_mock ), this ); 93 } 94 95 98 public Writer setResourceAsWriter() 99 throws IOException 100 { 101 return new ResourceWriter( new OutputStreamWriter ( new MockOutputStream( m_mock ) ), this ); 102 } 103 } 104 | Popular Tags |