public void downloadAndUntar(Map urlMap, File fullDir) { try { File file = new File(fullDir, urlMap.get("filesFilename").toString()); if (!file.isFile()) { FileUtils.copyURLToFile(new URL(urlMap.get("filesURL").toString()), file); } String fileName = file.toString(); if (fileName.endsWith(".tgz") || fileName.endsWith(".tar.gz") || fileName.endsWith(".gz") || fileName.endsWith(".zip")) ArchiveUtils.unzipFileTo(file.getAbsolutePath(), fullDir.getAbsolutePath()); } catch (IOException e) { throw new IllegalStateException("Unable to fetch images",e); } }
public File downloadAndUntar() throws IOException { if(fileDir != null) { return fileDir; } // mac gives unique tmp each run and we want to store this persist // this data across restarts File tmpDir = new File(System.getProperty("user.home")); File baseDir = new File(tmpDir, LOCAL_DIR_NAME); if(!(baseDir.isDirectory() || baseDir.mkdir())) { throw new IOException("Could not mkdir " + baseDir); } log.info("Downloading mnist..."); // getFromOrigin training records File tarFile = new File(baseDir, trainingFilesFilename); if(!tarFile.isFile()) { FileUtils.copyURLToFile(new URL(trainingFilesURL), tarFile); } ArchiveUtils.unzipFileTo(tarFile.getAbsolutePath(),baseDir.getAbsolutePath()); // getFromOrigin training records File labels = new File(baseDir, trainingFileLabelsFilename); if(!labels.isFile()) { FileUtils.copyURLToFile(new URL(trainingFileLabelsURL), labels); } ArchiveUtils.unzipFileTo(labels.getAbsolutePath(), baseDir.getAbsolutePath()); fileDir = baseDir; return fileDir; }