private String decompressSVMWithSGDModel()

in core/src/main/java/org/apache/sdap/mudrod/main/MudrodEngine.java [169:211]


  private String decompressSVMWithSGDModel(String archiveName) throws IOException {

    URL scmArchive = getClass().getClassLoader().getResource(archiveName);
    if (scmArchive == null) {
      throw new IOException("Unable to locate " + archiveName + " as a classpath resource.");
    }
    File tempDir = Files.createTempDirectory("mudrod").toFile();
    boolean bWritable = tempDir.setWritable(true);
    assert bWritable;
    File archiveFile = new File(tempDir, archiveName);
    FileUtils.copyURLToFile(scmArchive, archiveFile);

    // Decompress archive
    int buffer_size = 512000;
    try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(archiveFile))) {
      ZipEntry entry;
      while ((entry = zipIn.getNextEntry()) != null) {
        File f = new File(tempDir, entry.getName());
        // If the entry is a directory, create the directory.
        if (entry.isDirectory() && !f.exists()) {
          boolean created = f.mkdirs();
          if (!created) {
            LOG.error("Unable to create directory '{}', during extraction of archive contents.", f.getAbsolutePath());
          }
        } else if (!entry.isDirectory()) {
          boolean created = f.getParentFile().mkdirs();
          if (!created && !f.getParentFile().exists()) {
            LOG.error("Unable to create directory '{}', during extraction of archive contents.", f.getParentFile().getAbsolutePath());
          }
          int count;
          byte data[] = new byte[buffer_size];
          FileOutputStream fos = new FileOutputStream(new File(tempDir, entry.getName()), false);
          try (BufferedOutputStream dest = new BufferedOutputStream(fos, buffer_size)) {
            while ((count = zipIn.read(data, 0, buffer_size)) != -1) {
              dest.write(data, 0, count);
            }
          }
        }
      }
    }

    return new File(tempDir, StringUtils.removeEnd(archiveName, ".zip")).toURI().toString();
  }