fix download files

This commit is contained in:
Mateusz Kowalczyk 2020-01-02 21:28:51 +01:00
parent da104fdd61
commit 89c6696c67
2 changed files with 24 additions and 19 deletions

View File

@ -26,8 +26,8 @@ public class FilePaneBuilder {
} }
private String getName(String fileName) { private String getName(String fileName) {
if (fileName.length() > 120) { if (fileName.length() > 20) {
fileName = fileName.substring(0, 120); fileName = fileName.substring(0, 20);
} }
return fileName; return fileName;

View File

@ -5,6 +5,7 @@ import ftp.sar.exception.CannotConnectException;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64;
public class ServerConnector { public class ServerConnector {
private final Server server; private final Server server;
@ -79,39 +80,43 @@ public class ServerConnector {
} }
public void getFile(String filename, String path) { public void getFile(String filename, String path) {
File file = new File(path + "\\" + filename); File file = new File(path + "/" + filename);
DataInputStream dataInputStream = null;
try { try {
this.sendRequest("FTP_" + filename); this.sendRequest("FTP_" + filename);
} catch (CannotConnectException e) { } catch (CannotConnectException e) {
e.printStackTrace(); e.printStackTrace();
} }
DataInputStream dataInputStream = null; byte[] buffer = new byte[512];
char[] buffer = new char[512];
try { try {
dataInputStream = new DataInputStream(this.server.getSocket().getInputStream());
InputStreamReader inputStreamReader = new InputStreamReader(dataInputStream);
BufferedReader reader = new BufferedReader(inputStreamReader);
reader.read(buffer); this.server.getSocket().getInputStream().read(buffer, 0, 512);
String lengthOfFile = new String(buffer, "UTF-8");
String l = ""; String l = "";
for (char c: buffer) { for (char c: lengthOfFile.toCharArray()) {
if (Character.isDigit(c)) { if (Character.isDigit(c)) {
l += c; l += c;
} else {
break;
} }
} }
//TODO: Finish getting file //TODO: Finish getting file
// long lengthOFFile = Long.parseLong(l.trim()); long lengthOFFile = Long.parseLong(l.trim());
//
// FileOutputStream fileOutputStream = new FileOutputStream(file);
// byte[] fileBuffer = new byte[4096];
// byte[] fileBuffer = new byte[4096];
// do { int part = 0;
// dataInputStream.read(fileBuffer); do {
// lengthOFFile -= 4096; int bytesRead = this.server.getSocket().getInputStream().read(fileBuffer, 0, 4096);
// } while (lengthOFFile > 0); lengthOFFile -= 4096;
part++;
fileOutputStream.write(fileBuffer, 0, bytesRead);
} while (lengthOFFile > 0);
System.out.println(l); System.out.println(l);
} catch (IOException e) { } catch (IOException e) {