1 23 package com.sun.enterprise.admin.common; 24 25 import java.io.File ; 26 import java.io.Serializable ; 27 28 34 public class DownloadRequestInfo implements Serializable { 35 36 39 private DownloadRequestInfo() { 40 _downloadFilePath = null; 41 _numChunks = 0; 42 _numBytesSent = 0; 43 _isPrepared = false; 44 _chunkIndex = -1; 45 _chunk = null; 46 } 47 48 public DownloadRequestInfo(File f) { 49 super(); 50 51 if (f.exists()) { 52 _downloadFilePath = f.getAbsolutePath(); 53 54 _totalFileSize = f.length(); 56 57 _numChunks = Math.round(_totalFileSize/ByteChunk.kChunkMaxSize); 59 60 if (_numChunks * ByteChunk.kChunkMaxSize < _totalFileSize) { 62 _numChunks += 1; 63 } 64 65 _isPrepared = true; 67 _chunkIndex = 0; 68 } 69 } 70 71 76 public String getDownloadFilePath() { 77 return _downloadFilePath; 78 } 79 80 85 void setDownloadFilePath(String f) { 86 _downloadFilePath = f; 87 } 88 89 94 public int getNumberOfChunks() { 95 return _numChunks; 96 } 97 98 103 void setNumberOfChunks(int n) { 104 _numChunks = n; 105 } 106 107 112 public boolean isPrepared() { 113 return _isPrepared; 114 } 115 116 121 void setPrepared(boolean p) { 122 _isPrepared = p; 123 } 124 125 130 public int getChunkIndex() { 131 return _chunkIndex; 132 } 133 134 139 void setChunkIndex(int i) { 140 _chunkIndex = i; 141 142 _chunk = null; 144 } 145 146 151 public long getNumberOfBytesSent() { 152 return _numBytesSent; 153 } 154 155 160 public void incrementNumberOfBytesSent(int bytesRead) { 161 _numBytesSent += bytesRead; 162 } 163 164 169 public boolean isFirstChunk() { 170 return (_chunkIndex == 0); 171 } 172 173 178 public boolean isLastChunk() { 179 return (_chunkIndex == (_numChunks-1)); 180 } 181 182 187 public ByteChunk getChunk() { 188 return _chunk; 189 } 190 191 196 public void setChunk(ByteChunk chunk) { 197 _chunk = chunk; 198 } 199 200 205 public long getTotalFileSize() { 206 return _totalFileSize; 207 } 208 209 private String _downloadFilePath; 211 private int _numChunks; 212 private long _numBytesSent; 213 private boolean _isPrepared; 214 private int _chunkIndex; 215 private ByteChunk _chunk; 216 private long _totalFileSize; 217 } 218 | Popular Tags |