Debian Codegraph @

gss/src/main/java/org/globus/gsi/gssapi/net/impl/GSIGssOutputStream.java

raw
1 /*
2 * Copyright 1999-2010 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied.
12 *
13 * See the License for the specific language governing permissions and limitations under the License.
14 */
15 package org.globus.gsi.gssapi.net.impl;
16
17 import java.io.OutputStream;
18 import java.io.IOException;
19
20 import org.globus.gsi.gssapi.net.GssSocket;
21 import org.globus.gsi.gssapi.net.GssOutputStream;
22 import org.globus.gsi.gssapi.SSLUtil;
23
24 import org.ietf.jgss.GSSContext;
25
26 public class GSIGssOutputStream extends GssOutputStream {
27
28 protected byte [] header;
29 protected int mode;
30
31 public GSIGssOutputStream(OutputStream out, GSSContext context) {
32 this(out, context, GssSocket.SSL_MODE);
33 }
34
35 public GSIGssOutputStream(OutputStream out, GSSContext context, int mode) {
36 super(out, context);
37 this.header = new byte[4];
38 setWrapMode(mode);
39 }
40
41 public void flush()
42 throws IOException {
43 if (this.index == 0) return;
44 writeToken(wrap());
45 this.index = 0;
46 }
47
48 public void setWrapMode(int mode) {
49 this.mode = mode;
50 }
51
52 public int getWrapMode() {
53 return this.mode;
54 }
55
56 public void writeToken(byte[] token)
57 throws IOException {
58 if (this.mode == GssSocket.GSI_MODE) {
59 SSLUtil.writeInt(token.length, this.header, 0);
60 this.out.write(this.header);
61 }
62 this.out.write(token);
63 this.out.flush();
64 }
65
66 }