1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.jdkim.canon;
21
22 import java.io.ByteArrayOutputStream;
23 import java.io.IOException;
24 import java.security.NoSuchAlgorithmException;
25 import java.util.Iterator;
26 import java.util.LinkedList;
27 import java.util.List;
28
29 public class CompoundOutputStreamTest extends AbstractOutputStreamTestCase {
30
31 private byte[] testData;
32
33 protected void setUp() throws Exception {
34 testData = new byte[4096];
35 for (int i = 0; i < testData.length; i++) {
36 testData[i] = (byte) ((i * i * 4095 + (testData.length - i) * 17) % 128);
37 }
38 }
39
40 public void testSingleBytes() throws NoSuchAlgorithmException, IOException {
41 List
42 for (int i = 0; i < 5; i++) {
43 oss.add(new ByteArrayOutputStream());
44 }
45 CompoundOutputStream os = new CompoundOutputStream(oss);
46 for (int i = 0; i < testData.length; i++) {
47 os.write(testData[i]);
48 }
49 os.close();
50 for (Iterator i = oss.iterator(); i.hasNext();) {
51 ByteArrayOutputStream bos = (ByteArrayOutputStream) i.next();
52 assertArrayEquals(testData, bos.toByteArray());
53 }
54 }
55
56 public void testChunks() throws NoSuchAlgorithmException, IOException {
57 List
58 for (int i = 0; i < 5; i++) {
59 oss.add(new ByteArrayOutputStream());
60 }
61 CompoundOutputStream os = new CompoundOutputStream(oss);
62 chunker(testData, os);
63 for (Iterator i = oss.iterator(); i.hasNext();) {
64 ByteArrayOutputStream bos = (ByteArrayOutputStream) i.next();
65 assertArrayEquals(testData, bos.toByteArray());
66 }
67 }
68
69 }