KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > smb > SmbComWrite


1 /* jcifs smb client library in Java
2  * Copyright (C) 2003 "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.smb;
20
21 import jcifs.Config;
22
23 class SmbComWrite extends ServerMessageBlock {
24
25     private int fid,
26         count,
27         offset,
28         remaining,
29         off;
30     private byte[] b;
31
32     SmbComWrite() {
33         super();
34         command = SMB_COM_WRITE;
35     }
36     SmbComWrite( int fid, int offset, int remaining, byte[] b, int off, int len ) {
37         this.fid = fid;
38         this.count = len;
39         this.offset = offset;
40         this.remaining = remaining;
41         this.b = b;
42         this.off = off;
43         command = SMB_COM_WRITE;
44     }
45
46     void setParam( int fid, long offset, int remaining,
47                     byte[] b, int off, int len ) {
48         this.fid = fid;
49         this.offset = (int)(offset & 0xFFFFFFFFL);
50         this.remaining = remaining;
51         this.b = b;
52         this.off = off;
53         count = len;
54         digest = null; /* otherwise recycled commands
55                         * like writeandx will choke if session
56                         * closes in between */

57     }
58     int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
59         int start = dstIndex;
60
61         writeInt2( fid, dst, dstIndex );
62         dstIndex += 2;
63         writeInt2( count, dst, dstIndex );
64         dstIndex += 2;
65         writeInt4( offset, dst, dstIndex );
66         dstIndex += 4;
67         writeInt2( remaining, dst, dstIndex );
68         dstIndex += 2;
69
70         return dstIndex - start;
71     }
72     int writeBytesWireFormat( byte[] dst, int dstIndex ) {
73         int start = dstIndex;
74
75         dst[dstIndex++] = (byte)0x01; /* BufferFormat */
76         writeInt2( count, dst, dstIndex ); /* DataLength? */
77         dstIndex += 2;
78         System.arraycopy( b, off, dst, dstIndex, count );
79         dstIndex += count;
80
81         return dstIndex - start;
82     }
83     int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
84         return 0;
85     }
86     int readBytesWireFormat( byte[] buffer, int bufferIndex ) {
87         return 0;
88     }
89     public String JavaDoc toString() {
90         return new String JavaDoc( "SmbComWrite[" +
91             super.toString() +
92             ",fid=" + fid +
93             ",count=" + count +
94             ",offset=" + offset +
95             ",remaining=" + remaining + "]" );
96     }
97 }
98
Popular Tags