Skip to content

Package: LineCounter

LineCounter

nameinstructionbranchcomplexitylinemethod
LineCounter(OutputStream)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getLineCount()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
main(String[])
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
write(byte[])
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
write(byte[], int, int)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
write(int)
M: 24 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.mbox;
18:
19: import java.io.FilterOutputStream;
20: import java.io.IOException;
21: import java.io.OutputStream;
22:
23: /**
24: * Count number of lines output.
25: */
26: class LineCounter extends FilterOutputStream {
27: private int lastb = -1;
28: protected int lineCount;
29:
30: public LineCounter(OutputStream os) {
31: super(os);
32: }
33:
34: public void write(int b) throws IOException {
35: // If we have a full line, count it.
36:• if (b == '\r' || (b == '\n' && lastb != '\r'))
37: lineCount++;
38: out.write(b);
39: lastb = b;
40: }
41:
42: public void write(byte[] b) throws IOException {
43: write(b, 0, b.length);
44: }
45:
46: public void write(byte[] b, int off, int len) throws IOException {
47:• for (int i = 0; i < len; i++) {
48: write(b[off + i]);
49: }
50: }
51:
52: public int getLineCount() {
53: return lineCount;
54: }
55:
56: // for testing
57: public static void main(String[] argv) throws Exception {
58: int b;
59: LineCounter os =
60: new LineCounter(System.out);
61:• while ((b = System.in.read()) >= 0)
62: os.write(b);
63: os.flush();
64: System.out.println(os.getLineCount());
65: }
66: }