コード例 #1
0
 private Test mapTest(
     PuzzleTestDto puzzleTest, Runner runner, Map<String, ByteArrayOutputStream> testFiles)
     throws IOException {
   Test test = new Test();
   test.setIndex(Integer.parseInt(puzzleTest.getIndex()));
   test.setRunner(runner);
   test = testRepository.save(test);
   String inputFileName = test.getId() + "/" + puzzleTest.getIndex() + ".txt";
   if (testFiles == null) {
     storage.uploadPublic(
         testsBucket,
         inputFileName,
         new ByteArrayInputStream(puzzleTest.getData().getBytes()),
         "text/plain");
   } else {
     storage.uploadPublic(
         testsBucket,
         inputFileName,
         new ByteArrayInputStream(testFiles.get(puzzleTest.getData()).toByteArray()),
         "text/plain");
   }
   storage.upload(
       testsBucket,
       test.getId() + "/output.txt",
       new ByteArrayInputStream(puzzleTest.getSolution().getBytes()),
       "text/plain");
   Map<String, String> testParams = new HashMap<>();
   testParams.put("test", testsBucket + "/" + test.getId() + "/output.txt");
   testParams.put("stdin", testsBucket + "/" + inputFileName);
   test.setParams(testParams);
   test = testRepository.save(test);
   test.setRunner(runner);
   return test;
 }
コード例 #2
0
 private Map<String, ByteArrayOutputStream> unzip(byte[] zipbytes) throws IOException {
   final int bufSize = 2048;
   Map<String, ByteArrayOutputStream> map = new HashMap<>();
   ZipInputStream zip = new ZipInputStream(new ByteArrayInputStream(zipbytes));
   ZipEntry entry;
   byte[] buf = new byte[bufSize];
   while ((entry = zip.getNextEntry()) != null) {
     String fileName = entry.getName().substring(entry.getName().indexOf("/") + 1);
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     int count;
     while ((count = zip.read(buf, 0, bufSize)) != -1) {
       baos.write(buf, 0, count);
     }
     map.put(fileName, baos);
   }
   return map;
 }