|
3 | 3 | import java.io.ByteArrayInputStream;
|
4 | 4 | import java.io.IOException;
|
5 | 5 | import java.io.InputStream;
|
| 6 | +import java.io.FileInputStream; |
6 | 7 | import java.io.File;
|
7 | 8 | import java.io.FileWriter;
|
8 | 9 | import java.nio.file.Path;
|
|
15 | 16 | import java.util.List;
|
16 | 17 | import java.util.Map;
|
17 | 18 |
|
| 19 | +import com.horstmann.codecheck.Util; |
| 20 | + |
18 | 21 | import javax.inject.Inject;
|
19 | 22 | import javax.inject.Singleton;
|
20 | 23 |
|
|
47 | 50 | import com.fasterxml.jackson.databind.ObjectMapper;
|
48 | 51 | import com.fasterxml.jackson.databind.node.ObjectNode;
|
49 | 52 | import com.typesafe.config.Config;
|
| 53 | +import com.typesafe.config.ConfigException; |
50 | 54 |
|
51 | 55 | import play.Logger;
|
52 | 56 |
|
@@ -210,14 +214,26 @@ public void write(String contents, String repo, String key) throws IOException {
|
210 | 214 | public void write(byte[] contents, String repo, String key) throws IOException {
|
211 | 215 | Path repoPath = Path.of(config.getString("com.horstmann.codecheck.repo." + repo));
|
212 | 216 | Path problemDir = repoPath.resolve(key);
|
213 |
| - com.horstmann.codecheck.Util.deleteDirectory(problemDir); // Delete any prior contents so that it is replaced by new zip file |
| 217 | + Util.deleteDirectory(problemDir); // Delete any prior contents so that it is replaced by new zip file |
214 | 218 | Files.createDirectories(problemDir);
|
215 | 219 | problemDir = problemDir.resolve("problem.zip");
|
216 | 220 | org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(problemDir.toString()), contents);
|
217 | 221 | }
|
218 |
| - public void delete(String repo, String key) throws IOException {} |
| 222 | + public void delete(String repo, String key) throws IOException { |
| 223 | + |
| 224 | + } |
219 | 225 | public byte[] read(String repo, String problem) throws IOException {
|
220 |
| - return null; |
| 226 | + Path repoPath = Path.of(config.getString("com.horstmann.codecheck.repo." + repo)); |
| 227 | + if (problem.startsWith("/")) |
| 228 | + problem = problem.substring(1); |
| 229 | + |
| 230 | + byte[] result = null; |
| 231 | + try { |
| 232 | + InputStream in = new FileInputStream(repoPath.resolve(problem).resolve("problem.zip").toString()); |
| 233 | + result = in.readAllBytes(); |
| 234 | + } catch (IOException ex) {} |
| 235 | + |
| 236 | + return result; |
221 | 237 | }
|
222 | 238 | }
|
223 | 239 |
|
|
0 commit comments