1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.opennap.net;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.net.Socket;
25
26 import org.xnap.XNap;
27 import org.xnap.util.QuotedStringTokenizer;
28
29 public class UploadSocket extends IncomingSocket {
30
31
32
33 public String requestFilename;
34 public String nick;
35 public long offset;
36
37
38
39 /***
40 * This is a bit ugly since we have to read in the file offset too and
41 * pass it on to the actual upload.
42 */
43 public UploadSocket(Socket socket, InputStream in) throws IOException
44 {
45 super(socket, in);
46
47 byte data[] = new byte[2048];
48 int j = in.read(data);
49 if (j < 0) {
50 throw new IOException(XNap.tr("invalid request"));
51 }
52 String response = new String(data, 0, j);
53
54 QuotedStringTokenizer t = new QuotedStringTokenizer(response);
55
56 if (t.countTokens() < 3) {
57 throw new IOException(XNap.tr("invalid request: {0}", response));
58 }
59
60 nick = t.nextToken();
61 requestFilename = t.nextToken();
62
63 try {
64 offset = Long.parseLong(t.nextToken());
65 }
66 catch (NumberFormatException e) {
67 throw new IOException(XNap.tr("invalid request"));
68 }
69 }
70
71
72
73 }
74
75