1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.azureus;
21
22 import java.io.File;
23
24 import javax.swing.Action;
25
26 import org.apache.log4j.Logger;
27 import org.gudy.azureus2.core3.disk.DiskManagerFileInfo;
28 import org.xnap.XNap;
29 import org.xnap.peer.Peer;
30 import org.xnap.plugin.Plugin;
31 import org.xnap.transfer.AbstractTransfer;
32 import org.xnap.transfer.Download;
33 import org.xnap.transfer.Segment;
34
35 /***
36 * Downloads a file.
37 */
38 public class AzureusDownload extends AbstractTransfer implements Download {
39
40
41
42
43
44 private static Logger logger = Logger.getLogger(AzureusDownload.class);
45
46 private AzureusDownloadContainer parent;
47 private DiskManagerFileInfo file;
48 private AzureusDownloadSegment[] segments;
49
50
51
52 public AzureusDownload(AzureusDownloadContainer parent,
53 DiskManagerFileInfo file)
54 {
55 this.parent = parent;
56 this.file = file;
57
58 long pieceLength = parent.getManager().getDiskManager().getPieceLength();
59 Segment[] parentSegments = parent.getSegments();
60
61 this.segments = new AzureusDownloadSegment[file.getNbPieces()];
62 for (int i = 0; i < segments.length; i++) {
63 long start = i * pieceLength;
64 segments[i] = new AzureusDownloadSegment
65 (getFilesize(), start, start + pieceLength,
66 parentSegments[file.getFirstPieceNumber() + i]);
67 }
68 }
69
70
71
72 public long getBytesTransferred()
73 {
74 return file.getDownloaded();
75 }
76
77 public Action[] getActions()
78 {
79 return parent.getActions();
80 }
81
82 public File getFile()
83 {
84 return new File(file.getPath() + file.getName());
85 }
86
87 public String getFilename()
88 {
89 return file.getName();
90 }
91
92 public long getFilesize()
93 {
94 return file.getLength();
95 }
96
97 public Peer getPeer()
98 {
99 return null;
100 }
101
102 public Plugin getPlugin()
103 {
104 return AzureusPlugin.getInstance();
105 }
106
107 public Segment[] getSegments()
108 {
109 return segments;
110 }
111
112 public String getStatus()
113 {
114 if (!isRunning()) {
115 return null;
116 }
117
118 switch (file.getAccessMode()) {
119 case DiskManagerFileInfo.READ:
120 return XNap.tr("Read");
121 case DiskManagerFileInfo.WRITE:
122 return XNap.tr("Write");
123 default:
124 return XNap.tr("Unknown State {0}", file.getAccessMode());
125 }
126 }
127
128 public long getTotalBytesTransferred()
129 {
130 return getBytesTransferred();
131 }
132
133 public boolean isDone()
134 {
135 return parent.isDone();
136 }
137
138 public boolean isRunning()
139 {
140 return parent.isRunning();
141 }
142
143 /***
144 * Redeclare in order to make it accessible to AzureusDownloadContainer.
145 * @see org.xnap.transfer.AbstractTransfer#transferStarted()
146 */
147 protected void transferStarted()
148 {
149 super.transferStarted();
150 }
151
152 /***
153 * Redeclare in order to make it accessible to AzureusDownloadContainer.
154 * @see org.xnap.transfer.AbstractTransfer#transferStarted()
155 */
156 protected void transferStopped()
157 {
158 super.transferStopped();
159 }
160
161
162
163 }