EMMA Coverage Report (generated Thu Nov 19 17:07:02 CET 2009)
[all classes][org.apache.james.jdkim.mailets]

COVERAGE SUMMARY FOR SOURCE FILE [HeaderSkippingOutputStream.java]

nameclass, %method, %block, %line, %
HeaderSkippingOutputStream.java100% (1/1)100% (3/3)65%  (75/115)75%  (18/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HeaderSkippingOutputStream100% (1/1)100% (3/3)65%  (75/115)75%  (18/24)
write (int): void 100% (1/1)23%  (8/35)38%  (3/8)
write (byte [], int, int): void 100% (1/1)80%  (53/66)91%  (10/11)
HeaderSkippingOutputStream (OutputStream): void 100% (1/1)100% (14/14)100% (5/5)

1/****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one   *
3 * or more contributor license agreements.  See the NOTICE file *
4 * distributed with this work for additional information        *
5 * regarding copyright ownership.  The ASF licenses this file   *
6 * to you under the Apache License, Version 2.0 (the            *
7 * "License"); you may not use this file except in compliance   *
8 * with the License.  You may obtain a copy of the License at   *
9 *                                                              *
10 *   http://www.apache.org/licenses/LICENSE-2.0                 *
11 *                                                              *
12 * Unless required by applicable law or agreed to in writing,   *
13 * software distributed under the License is distributed on an  *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15 * KIND, either express or implied.  See the License for the    *
16 * specific language governing permissions and limitations      *
17 * under the License.                                           *
18 ****************************************************************/
19 
20package org.apache.james.jdkim.mailets;
21 
22import java.io.FilterOutputStream;
23import java.io.IOException;
24import java.io.OutputStream;
25 
26/**
27 * Ignore writes until the given sequence is found.
28 */
29public class HeaderSkippingOutputStream extends FilterOutputStream {
30 
31    boolean inHeaders = true;
32    byte[] skipTo = "\r\n\r\n".getBytes();
33    int pos = 0;
34 
35    public HeaderSkippingOutputStream(OutputStream out) {
36        super(out);
37    }
38 
39    public void write(byte[] b, int off, int len) throws IOException {
40        if (inHeaders) {
41            for (int i = off; i < off + len; i++) {
42                if (b[i] == skipTo[pos]) {
43                    pos++;
44                    if (pos == skipTo.length) {
45                        inHeaders = false;
46                        if (len - i - 1 > 0)
47                            out.write(b, i + 1, len - i - 1);
48                        break;
49                    }
50                } else
51                    pos = 0;
52            }
53        } else {
54            out.write(b, off, len);
55        }
56    }
57 
58    public void write(int b) throws IOException {
59        if (inHeaders) {
60            if (skipTo[pos] == b) {
61                pos++;
62                if (pos == skipTo.length)
63                    inHeaders = false;
64            } else
65                pos = 0;
66        } else {
67            out.write(b);
68        }
69    }
70 
71}

[all classes][org.apache.james.jdkim.mailets]
EMMA 2.0.5312 (C) Vladimir Roubtsov