File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\console\PlainTextConsoleOutputStream.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010, InfraDNA, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 package hudson.console;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.DataInputStream;
29 import java.io.IOException;
30 import java.io.OutputStream;
31 import java.util.logging.Logger;
32
33 /**
34 * Filters out console notes.
35 *
36 * @author Kohsuke Kawaguchi
37 */
38 public class PlainTextConsoleOutputStream extends LineTransformationOutputStream {
39 private final OutputStream out;
40
41 /**
42 *
43 */
44 public PlainTextConsoleOutputStream(OutputStream out) {
45 this.out = out;
46 }
47
48 /**
49 * Called after we read the whole line of plain text.
50 */
51 protected void eol(byte[] in, int sz) throws IOException {
52
53 int next = ConsoleNote.findPreamble(in,0,sz);
54
55 // perform byte[]->char[] while figuring out the char positions of the BLOBs
56 int written = 0;
57 while (next>=0) {
58 if (next>written) {
59 out.write(in,written,next-written);
60 written = next;
61 } else {
62 assert next==written;
63 }
64
65 int rest = sz - next;
66 ByteArrayInputStream b = new ByteArrayInputStream(in, next, rest);
67
68 ConsoleNote.skip(new DataInputStream(b));
69
70 int bytesUsed = rest - b.available(); // bytes consumed by annotations
71 written += bytesUsed;
72
73
74 next = ConsoleNote.findPreamble(in,written,sz-written);
75 }
76 // finish the remaining bytes->chars conversion
77 out.write(in,written,sz-written);
78 }
79
80 @Override
81 public void flush() throws IOException {
82 out.flush();
83 }
84
85 @Override
86 public void close() throws IOException {
87 super.close();
88 out.close();
89 }
90
91
92 private static final Logger LOGGER = Logger.getLogger(ConsoleAnnotationOutputStream.class.getName());
93 }
94