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.opennap.net.msg.client;
21  
22  import org.xnap.io.*;
23  import org.xnap.plugin.opennap.OpenNapPlugin;
24  import org.xnap.plugin.opennap.util.OpenNapFileHelper;
25  import org.xnap.search.MediaType;
26  import org.xnap.search.SearchManager;
27  
28  public class ShareFileMessage extends ClientMessage {
29  
30      //--- Constant(s) ---
31  
32      // FIX ME: we should use 10300
33      public static final int TYPE = 100;
34  
35      //--- Constructor(s) ---
36  
37      public ShareFileMessage(int index, MetaInfoFile file)
38      {
39  		super(TYPE);
40  	
41  		StringBuffer sb = new StringBuffer();
42  		sb.append("\"");
43  		sb.append(OpenNapFileHelper.getShareString(index, file));
44  		sb.append("\" ");
45  
46  		if (MP3MetaInfo.hasInfo(file)) {
47  			MP3MetaInfo m = new MP3MetaInfo(file);
48  			// do not calculate md5, send 0 instead
49  			sb.append("0 ");
50  			sb.append(file.length());
51  			sb.append(" ");
52  			sb.append(m.getBitrate());
53  			sb.append(" ");
54  			sb.append(m.getFrequency());
55  			sb.append(" ");
56  			sb.append(m.getPlayingTime());
57  		}
58  		else {
59  			MediaType mt = SearchManager.getMediaType(file.getName());
60  			if (mt != null) {
61  				// use new share syntax
62  				type = 10300;
63  				sb.append(file.length());
64  				sb.append(" 0 ");
65  
66  				String realm = OpenNapPlugin.getSearchManager().getRealm(mt);
67  				sb.append((realm != null) ? realm : "application");
68  			}
69  			else {
70  				sb.append("0 ");
71  				sb.append(file.length());
72  				sb.append(" ");
73  				sb.append("24 16000 600");
74  			}
75  
76  		}
77  
78  		data = sb.toString();
79      }
80  
81      //--- Method(s) ---
82  
83      public int getPriority()
84      {
85  		return PRIORITY_LOW;
86      }
87  
88  }