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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
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 package hudson.util;
25
26 import java.io.IOException;
27 import java.io.Writer;
28 import java.util.LinkedList;
29 import java.util.List;
30
31 /**
32 * {@link Writer} that spools the output and writes to another {@link Writer} later.
33 *
34 * @author Kohsuke Kawaguchi
35 * @deprecated since 2008-05-28. moved to stapler
36 */
37 public final class CharSpool extends Writer {
38 private List<char[]> buf;
39
40 private char[] last = new char[1024];
41 private int pos;
42
43 public void write(char cbuf[], int off, int len) {
44 while(len>0) {
45 int sz = Math.min(last.length-pos,len);
46 System.arraycopy(cbuf,off,last,pos,sz);
47 len -= sz;
48 off += sz;
49 pos += sz;
50 renew();
51 }
52 }
53
54 private void renew() {
55 if(pos<last.length)
56 return;
57
58 if(buf==null)
59 buf = new LinkedList<char[]>();
60 buf.add(last);
61 last = new char[1024];
62 pos = 0;
63 }
64
65 public void write(int c) {
66 renew();
67 last[pos++] = (char)c;
68 }
69
70 public void flush() {
71 // noop
72 }
73
74 public void close() {
75 // noop
76 }
77
78 public void writeTo(Writer w) throws IOException {
79 if(buf!=null) {
80 for (char[] cb : buf) {
81 w.write(cb);
82 }
83 }
84 w.write(last,0,pos);
85 }
86 }
87