KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > jcifs > smb > SmbComWriteAndX


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 com.knowgate.jcifs.smb;
20
21 import com.knowgate.jcifs.Config;
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24
25 class SmbComWriteAndX extends AndXServerMessageBlock {
26
27     private static final int READ_ANDX_BATCH_LIMIT =
28                             Config.getInt( "jcifs.smb.client.WriteAndX.ReadAndX", 1 );
29     private static final int CLOSE_BATCH_LIMIT =
30                             Config.getInt( "jcifs.smb.client.WriteAndX.Close", 1 );
31
32     private int fid,
33         writeMode,
34         remaining,
35         dataLength,
36         dataOffset,
37         off;
38     private byte[] b;
39     private long offset;
40
41     SmbComWriteAndX() {
42         super( null );
43         command = SMB_COM_WRITE_ANDX;
44     }
45     SmbComWriteAndX( int fid, long offset, int remaining,
46                     byte[] b, int off, int len, ServerMessageBlock andx ) {
47         super( andx );
48         this.fid = fid;
49         this.offset = offset;
50         this.remaining = remaining;
51         this.b = b;
52         this.off = off;
53         dataLength = len;
54         command = SMB_COM_WRITE_ANDX;
55     }
56
57     void setParam( int fid, long offset, int remaining,
58                     byte[] b, int off, int len ) {
59         this.fid = fid;
60         this.offset = offset;
61         this.remaining = remaining;
62         this.b = b;
63         this.off = off;
64         dataLength = len;
65     }
66     int getBatchLimit( byte command ) {
67         if( command == SMB_COM_READ_ANDX ) {
68             return READ_ANDX_BATCH_LIMIT;
69         }
70         if( command == SMB_COM_CLOSE ) {
71             return CLOSE_BATCH_LIMIT;
72         }
73         return 0;
74     }
75     int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
76         int start = dstIndex;
77
78         dataOffset = (dstIndex - headerStart) + 26; // 26 = off from here to pad
79
/*
80  * pad = ( dataOffset - headerStart ) % 4;
81  * pad = pad == 0 ? 0 : 4 - pad;
82  * dataOffset += pad;
83  */

84
85         writeInt2( fid, dst, dstIndex );
86         dstIndex += 2;
87         writeInt4( offset, dst, dstIndex );
88         dstIndex += 4;
89         for( int i = 0; i < 4; i++ ) {
90             dst[dstIndex++] = (byte)0x00;
91         }
92         writeInt2( writeMode, dst, dstIndex );
93         dstIndex += 2;
94         writeInt2( remaining, dst, dstIndex );
95         dstIndex += 2;
96         dst[dstIndex++] = (byte)0x00;
97         dst[dstIndex++] = (byte)0x00;
98         writeInt2( dataLength, dst, dstIndex );
99         dstIndex += 2;
100         writeInt2( dataOffset, dst, dstIndex );
101         dstIndex += 2;
102         writeInt4( offset >> 32, dst, dstIndex );
103         dstIndex += 4;
104
105         return dstIndex - start;
106     }
107     int writeBytesWireFormat( byte[] dst, int dstIndex ) {
108         int start = dstIndex;
109
110 /* Netware doesn't like this
111  * while( pad-- > 0 ) {
112  * dst[dstIndex++] = (byte)0x00;
113  * }
114  */

115         System.arraycopy( b, off, dst, dstIndex, dataLength );
116         dstIndex += dataLength;
117
118         return dstIndex - start;
119     }
120     int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
121         return 0;
122     }
123     int readBytesWireFormat( byte[] buffer, int bufferIndex ) {
124         return 0;
125     }
126     int readBytesDirectWireFormat( InputStream JavaDoc in, int byteCount,
127                 byte[] buffer, int bufferIndex ) throws IOException JavaDoc {
128         return 0;
129     }
130     public String JavaDoc toString() {
131         return new String JavaDoc( "SmbComWriteAndX[" +
132             super.toString() +
133             ",fid=" + fid +
134             ",offset=" + offset +
135             ",writeMode=" + writeMode +
136             ",remaining=" + remaining +
137             ",dataLength=" + dataLength +
138             ",dataOffset=" + dataOffset + "]" );
139     }
140 }
141
Popular Tags