1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.messages;
30
31 import uk.ac.rdg.resc.jstyx.StyxUtils;
32
33 /***
34 * Message sent to create and open a file on a Styx server
35 *
36 * @author Jon Blower
37 * $Revision: 263 $
38 * $Date: 2005-05-25 16:39:02 +0100 (Wed, 25 May 2005) $
39 * $Log$
40 * Revision 1.5 2005/05/25 15:39:02 jonblower
41 * Bug fixes
42 *
43 * Revision 1.4 2005/03/15 09:01:48 jonblower
44 * Message type now stored as short, not int
45 *
46 * Revision 1.3 2005/03/11 14:02:15 jonblower
47 * Merged MINA-Test_20059309 into main line of development
48 *
49 * Revision 1.2.2.1 2005/03/10 11:50:59 jonblower
50 * Changed to fit with MINA framework
51 *
52 * Revision 1.2 2005/02/24 07:44:43 jonblower
53 * Added getFriendlyString()
54 *
55 * Revision 1.1.1.1 2005/02/16 18:58:29 jonblower
56 * Initial import
57 *
58 */
59 public class TcreateMessage extends StyxMessage
60 {
61
62 private long fid;
63
64
65 private String fileName;
66 private long perm;
67 private int mode;
68
69
70 /***
71 * Creates a new TcreateMessage. This constructor will be called by the
72 * MessageRecognizer.
73 * @param length The total length of the message (including all header info)
74 * @param type The type of the message (a number between 100 and 127)
75 * @param tag The tag that identifies this message
76 */
77 public TcreateMessage(int length, short type, int tag)
78 {
79 super(length, type, tag);
80 this.name = "Tcreate";
81 }
82
83 public TcreateMessage(long fid, String fileName, int permissions, boolean isDirectory, int mode)
84 {
85 this(0, (short)114, 0);
86 this.fid = fid;
87 this.fileName = fileName;
88 this.perm = permissions;
89 if (isDirectory)
90 {
91 this.perm |= StyxUtils.DMDIR;
92 }
93 this.mode = mode;
94
95
96 int nameLen = StyxUtils.strToUTF8(fileName).length;
97
98 this.length = StyxUtils.HEADER_LENGTH + 4 + 2 + nameLen + 4 + 1;
99 }
100
101 protected final void decodeBody(StyxBuffer buf)
102 {
103 this.fid = buf.getUInt();
104 this.fileName = buf.getString();
105 this.perm = buf.getUInt();
106 this.mode = buf.getUByte();
107 }
108
109 protected final void encodeBody(StyxBuffer buf)
110 {
111 buf.putUInt(this.fid).putString(this.fileName).putUInt(this.perm).putUByte(this.mode);
112 }
113
114 public long getFid()
115 {
116 return this.fid;
117 }
118
119 public String getFileName()
120 {
121 return this.fileName;
122 }
123
124 public long getPerm()
125 {
126 return this.perm;
127 }
128
129 public int getMode()
130 {
131 return this.mode;
132 }
133
134 protected String getElements()
135 {
136 return ", " + this.fid + ", " + this.fileName + ", " + this.perm + ", " +
137 this.mode;
138 }
139
140 public String toFriendlyString()
141 {
142
143 return "fid: " + this.fid + ", name: " + this.fileName + ", perm: " +
144 this.perm + ", mode: " + this.mode;
145 }
146
147 }