View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.overnet.net.msg.core;
21  
22  import java.nio.ByteBuffer;
23  import java.util.*;
24  
25  import org.apache.log4j.Logger;
26  import org.xnap.plugin.overnet.util.OvernetPreferences;
27  
28  public class NewDownloadMessage extends OvernetCoreMessage
29  {
30  	//--- Constant(s) ---
31  
32  	public static final byte TYPE = (byte)188;
33  
34  	public static final byte PRIORITY_LOW = 0;
35  	public static final byte PRIORITY_NORMAL = 1;
36  	public static final byte PRIORITY_HIGH = 2;
37  	public static final byte PRIORITY_HIGHEST = 3;
38  
39  	//--- Data field(s) ---
40  	
41  	public String filename;
42  	public int filesize;
43  	public byte[] hash = new byte[16];
44  	/***
45  	 * Holds the priority whith which the file should be downloaded.
46  	 *
47  	 * <pre>
48  	 * 0, low
49  	 * 1, normal
50  	 * 2, high
51  	 * 3, highest
52  	 * </pre>
53  	 */
54  	public byte priority;
55  	public int id = 0;
56  
57  	public Tags tags;
58  
59  	private static Logger logger = Logger.getLogger(NewDownloadMessage.class);
60  
61  	//--- Constructor(s) ---
62  	
63  	public NewDownloadMessage(ByteBuffer buffer)
64  	{
65  		super(TYPE, buffer);
66  		get(hash);
67  		skip(6);
68  		tags = readTags();
69  		filename = tags.getShortName();
70  		filesize = tags.getSize();
71  
72  		for (Iterator i = tags.iterator(); i.hasNext();) {
73  			logger.debug(i.next());
74  		}
75  		priority = get();
76  
77  		logger.debug("priority : " + priority);
78  
79  		if (remaining() > 0) {
80  			//  short i = getShort();
81  //  			logger.debug("string length " + i);
82  //  			byte[] tmpfn = new byte[i+1];
83  //  			tmpfn[0] = get();
84  //  			tmpfn[1] = get();
85  //  			if (tmpfn[0] == '/' || tmpfn[1] == ':') {
86  //  				for (int pos = 2; pos < i; pos++) {
87  //  					tmpfn[pos] = get();
88  //  				}
89  //  			}
90  			String tmpFileName = getString();
91  			logger.debug("tmp filename " + tmpFileName);
92  		}
93  		if (remaining() >= 4) {
94  			OvernetPreferences.getInstance().setNewDownloadID(true);
95  			id = getInt();
96  			logger.debug("new dl: " + filename + " with id " + id);
97  		}
98  		else {
99  			OvernetPreferences.getInstance().setNewDownloadID(false);
100 		}
101 	}
102 
103     //--- Method(s) ---
104 }