|
|
@ -57,23 +57,21 @@ public class WindowProtoHandler implements ProtoHandler { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handleFile(String username, String filename, byte[] data) { |
|
|
|
if (filename.endsWith(".png") || filename.endsWith(".jpg")) { |
|
|
|
Platform.runLater(() -> { |
|
|
|
Image image = new Image(new ByteArrayInputStream(data)); |
|
|
|
chatWindow.addImage(username, image); |
|
|
|
}); |
|
|
|
} |
|
|
|
else { |
|
|
|
Platform.runLater(() -> { |
|
|
|
Platform.runLater(() -> { |
|
|
|
{ |
|
|
|
try { |
|
|
|
if (filename.endsWith(".png") || filename.endsWith(".jpg")) { |
|
|
|
Image image = new Image(new ByteArrayInputStream(data)); |
|
|
|
chatWindow.addImage(username, image); |
|
|
|
} |
|
|
|
chatWindow.addMessage("Server", "User [" + username + "] has sent the file \"" + filename + "\"."); |
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(filename); |
|
|
|
fileOutputStream.write(data); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|