1 16 17 18 package org.apache.commons.io.output; 19 20 21 import java.io.ByteArrayOutputStream ; 22 import java.io.IOException ; 23 24 import junit.framework.TestCase; 25 26 27 31 32 public class TeeOutputStreamTest extends TestCase { 33 34 public TeeOutputStreamTest(String name) { 35 super(name); 36 } 37 38 public void testTee() throws IOException { 39 ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); 40 ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); 41 TeeOutputStream tos = new TeeOutputStream(baos1, baos2); 42 for(int i = 0; i < 20; i++) { 43 tos.write(i); 44 } 45 assertByteArrayEquals("TeeOutputStream.write(int)", baos1.toByteArray(), baos2.toByteArray() ); 46 47 byte[] array = new byte[10]; 48 for(int i = 20; i < 30; i++) { 49 array[i-20] = (byte)i; 50 } 51 tos.write(array); 52 assertByteArrayEquals("TeeOutputStream.write(byte[])", baos1.toByteArray(), baos2.toByteArray() ); 53 54 for(int i = 25; i < 35; i++) { 55 array[i-25] = (byte)i; 56 } 57 tos.write(array, 5, 5); 58 assertByteArrayEquals("TeeOutputStream.write(byte[], int, int)", baos1.toByteArray(), baos2.toByteArray() ); 59 } 60 61 private void assertByteArrayEquals(String msg, byte[] array1, byte[] array2) { 62 assertEquals(msg+": array size mismatch", array1.length, array2.length); 63 for(int i=0; i<array1.length; i++) { 64 assertEquals(msg+": array[ " + i + "] mismatch", array1[i], array2[i]); 65 } 66 } 67 68 } 69 | Popular Tags |