|
Lines 19-40
Link Here
|
| 19 |
import java.io.FileOutputStream; |
19 |
import java.io.FileOutputStream; |
| 20 |
import java.net.InetAddress; |
20 |
import java.net.InetAddress; |
| 21 |
|
21 |
|
|
|
22 |
import org.eclipse.tptp.platform.execution.client.core.IFileTransferManager; |
| 22 |
import org.eclipse.tptp.platform.execution.util.internal.Constants; |
23 |
import org.eclipse.tptp.platform.execution.util.internal.Constants; |
| 23 |
import org.eclipse.tptp.platform.execution.util.internal.DimeHeader; |
24 |
import org.eclipse.tptp.platform.execution.util.internal.DimeHeader; |
| 24 |
|
25 |
|
| 25 |
import java.io.IOException; |
26 |
import java.io.IOException; |
| 26 |
import java.util.Hashtable; |
27 |
import java.util.HashMap; |
| 27 |
|
28 |
|
| 28 |
public class FileDataProcessor implements IDataProcessorWithDime { |
29 |
public class FileDataProcessor implements IDataProcessorWithDime { |
| 29 |
|
30 |
|
| 30 |
private FileDataMapper _fileNameMapper; |
31 |
private FileDataMapper _fileNameMapper; |
| 31 |
private Hashtable CompletedFilesHash; |
32 |
private HashMap CompletedFilesHash; |
| 32 |
|
33 |
|
| 33 |
public FileDataProcessor() { |
34 |
public FileDataProcessor() { |
| 34 |
super(); |
35 |
super(); |
| 35 |
// TODO Auto-generated constructor stub |
36 |
// TODO Auto-generated constructor stub |
| 36 |
_fileNameMapper = new FileDataMapper(); |
37 |
_fileNameMapper = new FileDataMapper(); |
| 37 |
CompletedFilesHash = new Hashtable(); |
38 |
CompletedFilesHash = new HashMap(); |
| 38 |
} |
39 |
} |
| 39 |
|
40 |
|
| 40 |
public void incomingData(byte[] buffer, int length, InetAddress peer) |
41 |
public void incomingData(byte[] buffer, int length, InetAddress peer) |
|
Lines 47-60
Link Here
|
| 47 |
*/ |
48 |
*/ |
| 48 |
public void incomingData(byte[] buffer, int length, InetAddress peer, byte[] dimeHeader) |
49 |
public void incomingData(byte[] buffer, int length, InetAddress peer, byte[] dimeHeader) |
| 49 |
{ |
50 |
{ |
| 50 |
int i; |
|
|
| 51 |
int rc; |
| 52 |
File fileHandle = null; |
51 |
File fileHandle = null; |
| 53 |
String fileName = null; |
52 |
String fileName = null; |
| 54 |
int dime_length = Constants.DIME_HEADER_LEN; |
|
|
| 55 |
DataOutputStream FileWriteStream = null; |
53 |
DataOutputStream FileWriteStream = null; |
| 56 |
DimeHeader dimeHeaderObj = DimeHeader.getDIMEHeader(dimeHeader); |
54 |
DimeHeader dimeHeaderObj = DimeHeader.getDIMEHeader(dimeHeader); |
| 57 |
|
55 |
|
|
|
56 |
int errorCode = getErrCodeFromHeader(dimeHeader, dimeHeaderObj); |
| 57 |
|
| 58 |
try |
58 |
try |
| 59 |
{ |
59 |
{ |
| 60 |
//System.out.println("The file handle to be written into - " + fileHandle); |
60 |
//System.out.println("The file handle to be written into - " + fileHandle); |
|
Lines 64-74
Link Here
|
| 64 |
//{ |
64 |
//{ |
| 65 |
|
65 |
|
| 66 |
fileName = getFileNameFromHeader(dimeHeader, dimeHeaderObj.getIDLength()); |
66 |
fileName = getFileNameFromHeader(dimeHeader, dimeHeaderObj.getIDLength()); |
| 67 |
if (fileName == null) System.out.println("Error - file name is null"); |
67 |
if (fileName == null) { System.out.println("Error - file name is null"); return; } |
|
|
68 |
|
| 68 |
//System.out.println("File name is - " + fileName); |
69 |
//System.out.println("File name is - " + fileName); |
| 69 |
fileHandle = this._fileNameMapper.getProcessor(fileName); |
70 |
fileHandle = _fileNameMapper.getProcessor(fileName); |
| 70 |
//System.out.println("The file handle is - " + fileHandle); |
71 |
//System.out.println("The file handle is - " + fileHandle); |
| 71 |
if (fileHandle == null) {System.out.println("Invalid File Handle ");return;} |
72 |
if (fileHandle == null) {System.out.println("Invalid File Handle "); return; } |
|
|
73 |
|
| 74 |
if (errorCode != IFileTransferManager.FILE_TRANSFER_OK) { |
| 75 |
fileTransferCompleted (fileHandle, errorCode); |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 72 |
|
79 |
|
| 73 |
if (dimeHeaderObj.getMB()) |
80 |
if (dimeHeaderObj.getMB()) |
| 74 |
{ |
81 |
{ |
|
Lines 87-93
Link Here
|
| 87 |
/* Post the semaphore when we get to the last record */ |
94 |
/* Post the semaphore when we get to the last record */ |
| 88 |
if (dimeHeaderObj.getME()) { |
95 |
if (dimeHeaderObj.getME()) { |
| 89 |
//System.out.println("The File Transfer for file " + fileName + " is completed."); ; |
96 |
//System.out.println("The File Transfer for file " + fileName + " is completed."); ; |
| 90 |
CompletedFilesHash.put(fileHandle, new Boolean(true)); |
97 |
fileTransferCompleted (fileHandle, IFileTransferManager.FILE_TRANSFER_OK); |
| 91 |
} |
98 |
} |
| 92 |
//} |
99 |
//} |
| 93 |
//} |
100 |
//} |
|
Lines 99-104
Link Here
|
| 99 |
|
106 |
|
| 100 |
} |
107 |
} |
| 101 |
|
108 |
|
|
|
109 |
private synchronized void fileTransferCompleted (File file, int errorCode) { |
| 110 |
if (file != null) { |
| 111 |
CompletedFilesHash.put(file, new Integer(errorCode)); |
| 112 |
notifyAll (); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 102 |
/** |
116 |
/** |
| 103 |
* Handle the data coming |
117 |
* Handle the data coming |
| 104 |
*/ |
118 |
*/ |
|
Lines 137-176
Link Here
|
| 137 |
|
151 |
|
| 138 |
public void initializeFileTransfer(String fileName, File file) |
152 |
public void initializeFileTransfer(String fileName, File file) |
| 139 |
{ |
153 |
{ |
| 140 |
|
154 |
_fileNameMapper.addContext(fileName, file); |
| 141 |
this._fileNameMapper.addContext(fileName, file); |
|
|
| 142 |
} |
155 |
} |
| 143 |
|
156 |
|
| 144 |
|
157 |
|
| 145 |
public void waitForFileComplete(String fileName) |
158 |
public synchronized int waitForFileComplete(String fileName) |
| 146 |
{ |
159 |
{ |
| 147 |
File fileHandle = _fileNameMapper.getProcessor(fileName); |
160 |
File fileHandle = _fileNameMapper.getProcessor(fileName); |
| 148 |
boolean transferCompleted = false; |
161 |
if (fileHandle == null) return IFileTransferManager.FILE_TRANSFER_ERROR; |
|
|
162 |
|
| 163 |
Integer completed = null; |
| 149 |
|
164 |
|
| 150 |
try |
165 |
try { |
| 151 |
{ |
166 |
while (true) { |
| 152 |
while (!transferCompleted) |
167 |
completed = (Integer) CompletedFilesHash.remove(fileHandle); |
| 153 |
{ |
168 |
if (completed != null) { |
| 154 |
Boolean completed = (Boolean)CompletedFilesHash.get(fileHandle); |
|
|
| 155 |
if (completed != null && completed.booleanValue() == true) |
| 156 |
{ |
| 157 |
CompletedFilesHash.remove(fileHandle); |
| 158 |
_fileNameMapper.removeContext(fileName); |
169 |
_fileNameMapper.removeContext(fileName); |
| 159 |
//System.out.println("The file transfer completed"); |
|
|
| 160 |
break; |
170 |
break; |
| 161 |
} |
171 |
} |
| 162 |
else |
172 |
|
| 163 |
{ |
173 |
wait(); |
| 164 |
Thread.sleep(Constants.TIMEOUT_PERIOD); |
|
|
| 165 |
continue; |
| 166 |
} |
| 167 |
} |
174 |
} |
| 168 |
} |
175 |
} |
| 169 |
catch(InterruptedException exp) |
176 |
catch(InterruptedException exp) |
| 170 |
{ |
177 |
{ |
| 171 |
System.out.println("FileDataProcessor: Error waiting for file transfer complete " + exp); |
178 |
System.out.println("FileDataProcessor: Error waiting for file transfer complete " + exp); |
| 172 |
} |
179 |
} |
| 173 |
return; |
180 |
|
|
|
181 |
return completed.intValue(); |
| 174 |
} |
182 |
} |
| 175 |
|
183 |
|
| 176 |
|
184 |
|
|
Lines 179-190
Link Here
|
| 179 |
*/ |
187 |
*/ |
| 180 |
public static String getFileNameFromHeader(byte[] buffer, int fileNameLength) |
188 |
public static String getFileNameFromHeader(byte[] buffer, int fileNameLength) |
| 181 |
{ |
189 |
{ |
| 182 |
byte[] fileName = new byte[fileNameLength-1]; |
190 |
if (buffer == null || fileNameLength <= 1) return null; |
| 183 |
|
191 |
|
| 184 |
System.arraycopy(buffer,Constants.DIME_HEADER_LEN,fileName,0,fileNameLength-1); |
192 |
return new String(buffer, Constants.DIME_HEADER_LEN, fileNameLength-1); |
| 185 |
//System.out.println(fileName); |
193 |
} |
|
|
194 |
|
| 195 |
public static int getErrCodeFromHeader(byte[] dime, DimeHeader dimeHeaderObj) |
| 196 |
{ |
| 197 |
if (dimeHeaderObj.getOptionsLength() <= 0) return IFileTransferManager.FILE_TRANSFER_OK; |
| 186 |
|
198 |
|
| 187 |
return new String(fileName); |
199 |
int fileNameLen = dimeHeaderObj.getIDLength(); |
|
|
200 |
|
| 201 |
return dime[Constants.DIME_HEADER_LEN + fileNameLen]; |
| 188 |
} |
202 |
} |
| 189 |
|
|
|
| 190 |
} |
203 |
} |