Coverage details for com.martiansoftware.nailgun.NGOutputStream

LineHitsSource
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) {
450        super(out);
460        header = new byte[5];
470        header[4] = (byte) code;
480    }
49     
50     /**
51      * @see java.io.OutputStream.write(byte[])
52      */
53     public void write(byte[] b) throws IOException {
540        write(b, 0, b.length);
550    }
56     
57     /**
58      * @see java.io.OutputStream.write(int)
59      */
60     public void write(int b) throws IOException {
610        byte[] b2 = {(byte) b};
620        write(b2, 0, 1);
630    }
64     
65     /**
66      * @see java.io.OutputStream.write(byte[],int,int)
67      */
68     public void write(byte[] b, int offset, int len) throws IOException {
690        LongUtils.toArray(len, header, 0);
700        synchronized(out) {
710            out.write(header, 0, 5);
720            out.write(b, offset, len);
730        }
740        out.flush();
750    }
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.