-
Notifications
You must be signed in to change notification settings - Fork 0
/
Uploader.java
46 lines (38 loc) · 1.38 KB
/
Uploader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import javax.swing.*;
import javax.swing.filechooser.*;
public class Uploader {
DashBoard DB;
String fpath;
String fname;
public Uploader(DashBoard DB) {
log.debug("creating uploader...");
this.DB=DB;
if(!chooseFile()) return;
try {
Packetizer pizer = new Packetizer(fpath);
int pktNo = 1;
while(pizer.hasMorePackets()) {
String payload = pizer.nextPacket();
String packet = "FURP" + DB.getUser() + ":private*java*" + fname + ":" + pktNo + ":" + payload.length();
pktNo++;
//log.info("Sending " + packet + ":" + payload);
DB.sendMessageToServer(packet + ":" + payload);
Thread.sleep(100);
}
}catch(Exception e) {
e.printStackTrace();
log.error("Got Exception while creating Packetizer for " + fpath + ", error=" + e);
}
}
public boolean chooseFile() {
boolean ret = false;
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(DB);
if(returnVal == JFileChooser.APPROVE_OPTION) {
fpath = chooser.getCurrentDirectory() + "/" + chooser.getSelectedFile().getName();
fname = chooser.getSelectedFile().getName();
ret = true;
}
return ret;
}
}//Uploader