|
1 | 1 | package net.sourceforge.smallbasic; |
2 | 2 |
|
3 | | -import javax.xml.ws.Response; |
4 | 3 | import java.io.BufferedOutputStream; |
5 | 4 | import java.io.ByteArrayInputStream; |
6 | 5 | import java.io.ByteArrayOutputStream; |
|
15 | 14 | import java.text.DateFormat; |
16 | 15 | import java.util.ArrayList; |
17 | 16 | import java.util.Collection; |
18 | | -import java.util.Collections; |
19 | 17 | import java.util.HashMap; |
20 | 18 | import java.util.List; |
21 | 19 | import java.util.Map; |
@@ -65,13 +63,27 @@ public void run() { |
65 | 63 | protected abstract void renameFile(String from, String to) throws IOException; |
66 | 64 | protected abstract void saveFile(String fileName, byte[] content) throws IOException; |
67 | 65 |
|
| 66 | + /** |
| 67 | + * Return all file names |
| 68 | + */ |
| 69 | + private Collection<String> getAllFileNames() throws IOException { |
| 70 | + Collection<String> result = new ArrayList<>(); |
| 71 | + for (FileData fileData : getFileData()) { |
| 72 | + result.add(fileData.fileName); |
| 73 | + } |
| 74 | + return result; |
| 75 | + } |
| 76 | + |
68 | 77 | /** |
69 | 78 | * Download files button handler |
70 | 79 | */ |
71 | 80 | private Response handleDownload(Map<String, Collection<String>> data) throws IOException { |
72 | 81 | Collection<String> fileNames = data.get("f"); |
73 | | - Response result; |
74 | 82 | if (fileNames == null || fileNames.size() == 0) { |
| 83 | + fileNames = getAllFileNames(); |
| 84 | + } |
| 85 | + Response result; |
| 86 | + if (fileNames.size() == 0) { |
75 | 87 | result = handleStatus(false, "File list is empty"); |
76 | 88 | } else if (fileNames.size() == 1) { |
77 | 89 | // plain text download single file |
@@ -534,13 +546,13 @@ void send(Socket socket, String cookie) throws IOException { |
534 | 546 | String contentLength = "Content-length: " + length + "\r\n"; |
535 | 547 | BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream()); |
536 | 548 | String code = errorCode == SC_OKAY ? SC_OKAY + " OK" : String.valueOf(errorCode); |
537 | | - out.write(("HTTP/1.0 " + code + "\r\n").getBytes()); |
538 | | - out.write("Content-type: text/html\r\n".getBytes()); |
539 | | - out.write(contentLength.getBytes()); |
| 549 | + out.write(("HTTP/1.0 " + code + "\r\n").getBytes(UTF_8)); |
| 550 | + out.write("Content-type: text/html\r\n".getBytes(UTF_8)); |
| 551 | + out.write(contentLength.getBytes(UTF_8)); |
540 | 552 | if (cookie != null) { |
541 | | - out.write(("Set-Cookie: " + TOKEN + "=" + cookie + "\r\n").getBytes()); |
| 553 | + out.write(("Set-Cookie: " + TOKEN + "=" + cookie + "\r\n").getBytes(UTF_8)); |
542 | 554 | } |
543 | | - out.write("Server: SmallBASIC for Android\r\n\r\n".getBytes()); |
| 555 | + out.write("Server: SmallBASIC for Android\r\n\r\n".getBytes(UTF_8)); |
544 | 556 | socket.setSendBufferSize(SEND_SIZE); |
545 | 557 | int sent = toStream(out); |
546 | 558 | log("sent " + sent + " bytes"); |
|
0 commit comments