Передача данных теперь работает корректно.
This commit is contained in:
parent
1bcc8bdcb1
commit
06525704de
@ -33,20 +33,13 @@ public class FileOperation implements Operation {
|
||||
FileOutputStream fout = null;
|
||||
try {
|
||||
String name = dis.readUTF();
|
||||
long length = dis.readLong();
|
||||
System.out.println("Filename: " + name);
|
||||
System.out.println("Size: " + (length / 1024) + "kb");
|
||||
fout = new FileOutputStream(Config.getTransferDir() + name);
|
||||
|
||||
for (long i = 0; i < length; i++) {
|
||||
byte read = dis.readByte();
|
||||
fout.write(read);
|
||||
}
|
||||
/*byte[] buffer = new byte[BUFFER_SIZE];
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int count;
|
||||
while ((count = dis.read(buffer, 0, BUFFER_SIZE)) > 0) {
|
||||
while ((count = dis.read(buffer, 0, BUFFER_SIZE)) != -1) {
|
||||
fout.write(buffer, 0, count);
|
||||
}*/
|
||||
}
|
||||
fout.flush();
|
||||
fout.close();
|
||||
} catch (IOException ex) {
|
||||
@ -69,8 +62,6 @@ public class FileOperation implements Operation {
|
||||
String name = file.getName();
|
||||
dos.writeUTF(name);
|
||||
|
||||
dos.writeLong(file.length());
|
||||
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int count;
|
||||
|
@ -25,6 +25,7 @@ public class MessageOperation implements Operation {
|
||||
public void startServerSide() throws IOException {
|
||||
String text = dis.readUTF();
|
||||
MessageHistory.addMessage(text);
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,11 +30,9 @@ public class OperationListener {
|
||||
|
||||
public void listenOperation() throws Exception {
|
||||
int mode = dis.readInt();
|
||||
System.out.println("Read mode: " + mode);
|
||||
Operation operation;
|
||||
switch(mode) {
|
||||
case MODE_FILE_TRANSFER:
|
||||
System.out.println("MODE_FILE_TRANSFER");
|
||||
operation = new FileOperation(dis);
|
||||
break;
|
||||
case MODE_MESSAGE_TRANSFER:
|
||||
|
@ -19,15 +19,10 @@ public class TransferServer implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Thread thr = Thread.currentThread();
|
||||
while(Thread.currentThread() == thr) {
|
||||
try {
|
||||
listener.listenOperation();
|
||||
//Thread.sleep(1);
|
||||
} catch (Exception ex) {
|
||||
ExceptionHandler.handle(ex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
listener.close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user