# Coverage details for com.martiansoftware.nailgun.NGOutputStream

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | ``
3 |  | `Copyright 2004, Martian Software, Inc.`
4 |  | ``
5 |  | `Licensed under the Apache License, Version 2.0 (the "License");`
6 |  | `you may not use this file except in compliance with the License.`
7 |  | `You may obtain a copy of the License at`
8 |  | ``
9 |  | `http://www.apache.org/licenses/LICENSE-2.0`
10 |  | ``
11 |  | `Unless required by applicable law or agreed to in writing, software`
12 |  | `distributed under the License is distributed on an "AS IS" BASIS,`
13 |  | `WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.`
14 |  | `See the License for the specific language governing permissions and`
15 |  | `limitations under the License.`
16 |  | ``
17 |  | `*/`
18 |  | ``
19 |  | `package com.martiansoftware.nailgun;`
20 |  | ``
21 |  | `import java.io.IOException;`
22 |  | ``
23 |  | `/**`
24 |  | `* Wraps an OutputStream to send writes in NailGun chunks. Because`
25 |  | `* multiple NGOutputStreams wrap the same OutputStream (that is,`
26 |  | `* the OutputStream obtained from the Socket connection with`
27 |  | `* the client), writes are synchronized on the underlying OutputStream.`
28 |  | `* If this were not the case, write interleaving could completely`
29 |  | `* break the NailGun protocol.`
30 |  | `*`
31 |  | `* @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>`
32 |  | `*/`
33 |  | `class NGOutputStream extends java.io.FilterOutputStream {`
34 |  | ``
35 |  | `private byte[] header;`
36 |  | ``
37 |  | `/**`
38 |  | `* Creates a new NGOutputStream wrapping the specified`
39 |  | `* OutputStream and using the specified Nailgun chunk code.`
40 |  | `* @param out the OutputStream to wrap`
41 |  | `* @param code the NailGun chunk code associated with this`
42 |  | `* stream (i.e., '1' for stdout, '2' for stderr).`
43 |  | `*/`
44 |  | `public NGOutputStream(java.io.OutputStream out, char code) {`
45 | 0 | `super(out);`
46 | 0 | `header = new byte[5];`
47 | 0 | `header[4] = (byte) code;`
48 | 0 | `}`
49 |  | ``
50 |  | `/**`
51 |  | `* @see java.io.OutputStream.write(byte[])`
52 |  | `*/`
53 |  | `public void write(byte[] b) throws IOException {`
54 | 0 | `write(b, 0, b.length);`
55 | 0 | `}`
56 |  | ``
57 |  | `/**`
58 |  | `* @see java.io.OutputStream.write(int)`
59 |  | `*/`
60 |  | `public void write(int b) throws IOException {`
61 | 0 | `byte[] b2 = {(byte) b};`
62 | 0 | `write(b2, 0, 1);`
63 | 0 | `}`
64 |  | ``
65 |  | `/**`
66 |  | `* @see java.io.OutputStream.write(byte[],int,int)`
67 |  | `*/`
68 |  | `public void write(byte[] b, int offset, int len) throws IOException {`
69 | 0 | `LongUtils.toArray(len, header, 0);`
70 | 0 | `synchronized(out) {`
71 | 0 | `out.write(header, 0, 5);`
72 | 0 | `out.write(b, offset, len);`
73 | 0 | `}`
74 | 0 | `out.flush();`
75 | 0 | `}`
76 |  | `}`

this report was generated by version 1.0.5 of jcoverage. visit www.jcoverage.com for updates. | copyright © 2003, jcoverage ltd. all rights reserved. Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.