|
|
@ -2,12 +2,10 @@ package window; |
|
|
|
|
|
|
|
import javafx.application.Platform; |
|
|
|
import javafx.scene.control.Alert; |
|
|
|
import javafx.scene.image.Image; |
|
|
|
import proto.ProtoHandler; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.security.AlgorithmConstraints; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
public class WindowProtoHandler implements ProtoHandler { |
|
|
@ -59,15 +57,23 @@ public class WindowProtoHandler implements ProtoHandler { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handleFile(String username, String filename, byte[] data) { |
|
|
|
Platform.runLater(() -> { |
|
|
|
try { |
|
|
|
chatWindow.addMessage("Server", "User [" + username + "] has sent the file \"" + filename + "\"."); |
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(filename); |
|
|
|
fileOutputStream.write(data); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
if (filename.endsWith(".png") || filename.endsWith(".jpg")) { |
|
|
|
Platform.runLater(() -> { |
|
|
|
Image image = new Image(new ByteArrayInputStream(data)); |
|
|
|
chatWindow.addImage(username, image); |
|
|
|
}); |
|
|
|
} |
|
|
|
else { |
|
|
|
Platform.runLater(() -> { |
|
|
|
try { |
|
|
|
chatWindow.addMessage("Server", "User [" + username + "] has sent the file \"" + filename + "\"."); |
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(filename); |
|
|
|
fileOutputStream.write(data); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|