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.util.QuotedStringTokenizer;
27
28 public class DownloadSocket extends IncomingSocket {
29
30
31
32 public String filename;
33 public long filesize;
34 public String nick;
35
36
37
38 public DownloadSocket(Socket socket, InputStream in) throws IOException
39 {
40 super(socket, in);
41
42 byte data[] = new byte[2048];
43 int i = in.read(data);
44 if (i > 0) {
45 String response = new String(data, 0, i);
46
47 QuotedStringTokenizer t = new QuotedStringTokenizer(response);
48
49 if (t.countTokens() < 3) {
50 throw new IOException("invalid request: " + response);
51 }
52
53 nick = t.nextToken();
54 filename = t.nextToken();
55 try {
56 filesize = Long.parseLong(t.nextToken());
57 }
58 catch (NumberFormatException e) {
59 throw new IOException("invalid request: " + response);
60 }
61
62 logger.info("download response from " + nick + " for " + filename);
63 }
64 else {
65 throw new IOException("empty request");
66 }
67 }
68
69 public DownloadSocket(String nick, String filename, long filesize)
70 {
71 this.nick = nick;
72 this.filename = filename;
73 this.filesize = filesize;
74 }
75
76
77
78 public boolean equals(Object obj)
79 {
80 if (obj != null) {
81 if (obj instanceof DownloadSocket) {
82 DownloadSocket d = (DownloadSocket)obj;
83 return (nick.equals(d.nick) && filename.equals(d.filename)
84 && filesize == d.filesize);
85 }
86 }
87
88 return false;
89 }
90 }
91
92