KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > NTParameterPacker


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb.server;
18
19 import org.alfresco.filesys.util.DataPacker;
20
21 /**
22  * NT Dialect Parameter Packer Class
23  * <p>
24  * The NT SMB dialect uses parameters that are not always word/longword aligned.
25  */

26 class NTParameterPacker
27 {
28
29     // Buffer and current offset
30

31     private byte[] m_buf;
32     private int m_pos;
33
34     /**
35      * Class constructor
36      *
37      * @param buf byte[]
38      */

39     public NTParameterPacker(byte[] buf)
40     {
41         m_buf = buf;
42         m_pos = SMBSrvPacket.PARAMWORDS;
43     }
44
45     /**
46      * Class constructor
47      *
48      * @param buf byte[]
49      * @param pos int
50      */

51     public NTParameterPacker(byte[] buf, int pos)
52     {
53         m_buf = buf;
54         m_pos = pos;
55     }
56
57     /**
58      * Pack a byte (8 bit) value
59      *
60      * @param val byte
61      */

62     public final void packByte(byte val)
63     {
64         m_buf[m_pos++] = val;
65     }
66
67     /**
68      * Pack a byte (8 bit) value
69      *
70      * @param val int
71      */

72     public final void packByte(int val)
73     {
74         m_buf[m_pos++] = (byte) val;
75     }
76
77     /**
78      * Pack a word (16 bit) value
79      *
80      * @param val int
81      */

82     public final void packWord(int val)
83     {
84         DataPacker.putIntelShort(val, m_buf, m_pos);
85         m_pos += 2;
86     }
87
88     /**
89      * Pack an integer (32 bit) value
90      *
91      * @param val int
92      */

93     public final void packInt(int val)
94     {
95         DataPacker.putIntelInt(val, m_buf, m_pos);
96         m_pos += 4;
97     }
98
99     /**
100      * Pack a long (64 bit) value
101      *
102      * @param val long
103      */

104     public final void packLong(long val)
105     {
106         DataPacker.putIntelLong(val, m_buf, m_pos);
107         m_pos += 8;
108     }
109
110     /**
111      * Return the current buffer position
112      *
113      * @return int
114      */

115     public final int getPosition()
116     {
117         return m_pos;
118     }
119
120     /**
121      * Return the buffer
122      *
123      * @return byte[]
124      */

125     public final byte[] getBuffer()
126     {
127         return m_buf;
128     }
129
130     /**
131      * Unpack a byte value
132      *
133      * @return int
134      */

135     public final int unpackByte()
136     {
137         return (int) m_buf[m_pos++];
138     }
139
140     /**
141      * Unpack a word (16 bit) value
142      *
143      * @return int
144      */

145     public final int unpackWord()
146     {
147         int val = DataPacker.getIntelShort(m_buf, m_pos);
148         m_pos += 2;
149         return val;
150     }
151
152     /**
153      * Unpack an integer (32 bit) value
154      *
155      * @return int
156      */

157     public final int unpackInt()
158     {
159         int val = DataPacker.getIntelInt(m_buf, m_pos);
160         m_pos += 4;
161         return val;
162     }
163
164     /**
165      * Unpack a long (64 bit) value
166      *
167      * @return int
168      */

169     public final long unpackLong()
170     {
171         long val = DataPacker.getIntelLong(m_buf, m_pos);
172         m_pos += 8;
173         return val;
174     }
175
176     /**
177      * Reset the parameter packer/reader to use the new buffer/offset
178      *
179      * @param buf byte[]
180      * @param off int
181      */

182     public final void reset(byte[] buf, int pos)
183     {
184         m_buf = buf;
185         m_pos = pos;
186     }
187 }
188
Popular Tags