KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > netbios > SocketOutputStream


1 /* jcifs smb client library in Java
2  * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package jcifs.netbios;
20
21 import java.io.FilterOutputStream JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 class SocketOutputStream extends FilterOutputStream JavaDoc {
26
27     SocketOutputStream( OutputStream JavaDoc out ) {
28         super( out );
29     }
30
31     public synchronized void write( byte[] b, int off, int len ) throws IOException JavaDoc {
32         if( len > 0xFFFF ) {
33             throw new IOException JavaDoc( "write too large: " + len );
34         } else if( off < 4 ) {
35             throw new IOException JavaDoc( "NetBIOS socket output buffer requires 4 bytes available before off" );
36         }
37
38         off -= 4;
39
40         b[off + 0] = (byte)SessionServicePacket.SESSION_MESSAGE;
41         b[off + 1] = (byte)0x00;
42         b[off + 2] = (byte)(( len >> 8 ) & 0xFF );
43         b[off + 3] = (byte)( len & 0xFF );
44
45         out.write( b, off, 4 + len );
46     }
47 }
48
Popular Tags