net.lingala.zip4j.ZipFile Java Examples

The following examples show how to use net.lingala.zip4j.ZipFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnalysisSaikuService.java    From collect-earth with MIT License 6 votes vote down vote up
private boolean restoreProjectSaikuDB() {
	boolean restoredSaiku = false;
	if (getZippedSaikuProjectDB().exists()) {
		// Unzip file

		try {
			ZipFile zippedProjectSaikuData = new ZipFile(getZippedSaikuProjectDB());
			zippedProjectSaikuData.extractAll(FolderFinder.getCollectEarthDataFolder());
			restoredSaiku = true;
		} catch (ZipException e) {
			logger.error("Problems unzipping the contents of the zipped Saiku DB to the local user folder ", e);
		}

	}
	return restoredSaiku;
}
 
Example #2
Source File: ApkFile.java    From apkfile with Apache License 2.0 6 votes vote down vote up
ApkFile(String apkPath, boolean parseCertificate) throws IOException, ZipException {
    zipFile = new ZipFile(apkPath);
    theFile = new File(apkPath);
    androidManifest = null;
    resources = null;
    entryNameToDex = new HashMap<>();
    entryNameToEntry = buildEntryNameToEntry(zipFile);

    if (parseCertificate) {
        try {
            parseCertificate();
        } catch (ParseException e) {
            logger.error("Exception parsing certificate", e);
        }
    } else {
        certificate = null;
    }
}
 
Example #3
Source File: S3DataManagerTest.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testZipSourceBuildSpec() throws Exception {
    String buildSpecName = "Buildspec.yml";
    File buildSpec = new File("/tmp/source/" + buildSpecName);
    String buildSpecContents = "yo\n";
    FileUtils.write(buildSpec, buildSpecContents);

    ZipOutputStream out = new ZipOutputStream(new FileOutputStream("/tmp/source.zip"));
    ZipSourceCallable.zipSource(testZipSourceWorkspace, "/tmp/source/", out, "/tmp/source/");
    out.close();

    File zip = new File("/tmp/source.zip");
    assertTrue(zip.exists());

    File unzipFolder = new File("/tmp/folder/");
    unzipFolder.mkdir();
    ZipFile z = new ZipFile(zip.getPath());
    z.extractAll(unzipFolder.getPath());
    assertTrue(unzipFolder.list().length == 1);
    assertEquals(buildSpecName, unzipFolder.list()[0]);
    File extractedBuildSpec = new File(unzipFolder.getPath() + "/" + buildSpecName);
    assertTrue(FileUtils.readFileToString(extractedBuildSpec).equals(buildSpecContents));
}
 
Example #4
Source File: TestCaseController.java    From android-uiconductor with Apache License 2.0 6 votes vote down vote up
@CrossOrigin(origins = "*")
@RequestMapping(value = "/exportProjectToZip", method = RequestMethod.GET)
public ResponseEntity<Resource> exportProjectToZip(
    @RequestParam(value = "projectId") String projectId,
    @RequestParam(value = "projectName") String projectName) throws IOException, UicdException{
  ZipFile file = testCasesImportExportManager.zipAndExport(projectId, projectName, "");
  HttpHeaders header = new HttpHeaders();
  header.add(HttpHeaders.CONTENT_DISPOSITION,
      String.format("attachment; filename=%s.zip", projectName));
  header.add("Cache-Control", "no-cache, no-store, must-revalidate");
  header.add("Pragma", "no-cache");
  header.add("Expires", "0");

  ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(file.getFile().toPath()));

  return ResponseEntity.ok()
      .headers(header)
      .contentLength(file.getFile().length())
      .contentType(MediaType.parseMediaType("application/octet-stream"))
      .body(resource);
}
 
Example #5
Source File: UserModelService.java    From KOMORAN with Apache License 2.0 6 votes vote down vote up
public File deployUserModel(String modelDir) {
    ModelValidator.CheckValidModelName(modelDir);

    String dirNameToArchive = String.join(File.separator, MODELS_BASEDIR, modelDir);
    String zipNameToArchive = "UserModel" + modelDir + ".zip";

    ZipFile zipFileToDeploy = new ZipFile(zipNameToArchive);
    ZipParameters zipFileParams = new ZipParameters();

    zipFileParams.setReadHiddenFiles(false);
    zipFileParams.setReadHiddenFolders(false);
    zipFileParams.setIncludeRootFolder(false);

    try {
        zipFileToDeploy.addFolder(new File(dirNameToArchive), zipFileParams);
    } catch (ZipException e) {
        throw new ServerErrorException("모델 배포를 위한 압축 파일 생성에 실패했습니다.");
    }

    return zipFileToDeploy.getFile();
}
 
Example #6
Source File: ZipOutputStreamIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
private void verifyEntries() throws ZipException {
  ZipFile zipFile = new ZipFile(generatedZipFile);
  for (FileHeader fileHeader : zipFile.getFileHeaders()) {
    byte[] generalPurposeBytes = fileHeader.getGeneralPurposeFlag();
    assertThat(BitUtils.isBitSet(generalPurposeBytes[0], 3)).isTrue();

    if (fileHeader.isEncrypted()
        && fileHeader.getEncryptionMethod().equals(EncryptionMethod.AES)) {

      if (fileHeader.getAesExtraDataRecord().getAesVersion().equals(AesVersion.TWO)) {
        assertThat(fileHeader.getCrc()).isZero();
      } else if (fileHeader.getCompressedSize() > 0) {
        assertThat(fileHeader.getCrc()).isNotZero();
      }
    }
  }
}
 
Example #7
Source File: ZipInputStreamIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
private File createZipFile(CompressionMethod compressionMethod, boolean encryptFiles,
                           EncryptionMethod encryptionMethod, AesKeyStrength aesKeyStrength, char[] password,
                           AesVersion aesVersion)
    throws IOException {

  File outputFile = temporaryFolder.newFile("output.zip");
  deleteFileIfExists(outputFile);

  ZipFile zipFile = new ZipFile(outputFile, password);

  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setCompressionMethod(compressionMethod);
  zipParameters.setEncryptFiles(encryptFiles);
  zipParameters.setEncryptionMethod(encryptionMethod);
  zipParameters.setAesKeyStrength(aesKeyStrength);
  zipParameters.setAesVersion(aesVersion);

  zipFile.addFiles(AbstractIT.FILES_TO_ADD, zipParameters);

  return outputFile;
}
 
Example #8
Source File: ZipFileVerifier.java    From zip4j with Apache License 2.0 6 votes vote down vote up
public static void verifyZipFileByExtractingAllFiles(File zipFileToExtract, char[] password, File outputFolder,
                                                     int expectedNumberOfEntries, boolean verifyFileContents, Charset charset)
    throws IOException {

  assertThat(zipFileToExtract).isNotNull();
  assertThat(zipFileToExtract).exists();

  ZipFile zipFile = new ZipFile(zipFileToExtract, password);

  if (charset != null) {
    zipFile.setCharset(charset);
  }

  zipFile.extractAll(outputFolder.getPath());
  assertThat(zipFile.getFileHeaders().size()).as("Number of file headers").isEqualTo(expectedNumberOfEntries);

  List<File> extractedFiles = FileUtils.getFilesInDirectoryRecursive(outputFolder, true, true);
  assertThat(extractedFiles).hasSize(expectedNumberOfEntries);

  if (verifyFileContents) {
    verifyFolderContentsSameAsSourceFiles(outputFolder);
  }
}
 
Example #9
Source File: HeaderVerifier.java    From zip4j with Apache License 2.0 6 votes vote down vote up
private static InputStream positionRandomAccessFileToLocalFileHeaderStart(File generatedZipFile, String fileNameInZip)
    throws IOException{

  ZipFile zipFile = new ZipFile(generatedZipFile);
  FileHeader fileHeader = zipFile.getFileHeader(fileNameInZip);

  if (fileHeader == null) {
    throw new RuntimeException("Cannot find an entry with name: " + fileNameInZip + " in zip file: "
        + generatedZipFile);
  }

  InputStream inputStream = new FileInputStream(generatedZipFile);
  if (inputStream.skip(fileHeader.getOffsetLocalHeader()) != fileHeader.getOffsetLocalHeader()) {
    throw new IOException("Cannot skip " + fileHeader.getOffsetLocalHeader() + " bytes for entry "
        + fileHeader.getFileName());
  }
  return inputStream;
}
 
Example #10
Source File: CollectEarthUtils.java    From collect-earth with MIT License 6 votes vote down vote up
public static ZipFile addFileToZip(String fileToCompress, File srcFile, String fileNameInZip )
		throws ZipException,IOException{
	File destBackupFile = new File( fileToCompress );	
	ZipFile zipBackupFile = new ZipFile( destBackupFile );

	ZipParameters zipParameters = new ZipParameters();
	// COMP_DEFLATE is for compression
	zipParameters.setCompressionMethod(CompressionMethod.DEFLATE);
	// DEFLATE_LEVEL_ULTRA = maximum compression
	zipParameters.setCompressionLevel(CompressionLevel.ULTRA);
	// deprecated in version 2 of lingala ?? does it matter? zipParameters.setSourceExternalStream(true);
	zipParameters.setFileNameInZip( fileNameInZip );				
	zipBackupFile.addFile(srcFile, zipParameters);

	return zipBackupFile;
}
 
Example #11
Source File: UnzipUtilIT.java    From zip4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateZipInputStream() throws ZipException, IOException {
  ZipFile zipFile = createZipFile();
  ZipModel zipModel = createZipModel();
  FileHeader fileHeader = zipFile.getFileHeaders().get(1);
  File extractedFile = temporaryFolder.newFile();

  try (InputStream inputStream = UnzipUtil.createZipInputStream(zipModel, fileHeader, "password".toCharArray());
       OutputStream outputStream = new FileOutputStream(extractedFile)) {
    byte[] b = new byte[InternalZipConstants.BUFF_SIZE];
    int readLen = 0;

    while ((readLen = inputStream.read(b)) != -1) {
      outputStream.write(b, 0, readLen);
    }
  }

  assertThat(extractedFile.length()).isEqualTo(TestUtils.getTestFileFromResources("sample_text_large.txt").length());
}
 
Example #12
Source File: PaySimProjectIntegrationTest.java    From coderadar with MIT License 5 votes vote down vote up
@BeforeAll
static void setUp() throws IOException {
  FileUtils.deleteDirectory(new File("coderadar-workdir/PaySim"));
  ZipFile zipFile =
      new ZipFile(
          PaySimProjectIntegrationTest.class
              .getClassLoader()
              .getResource("PaySim.zip")
              .getPath());
  zipFile.extractAll("coderadar-workdir");
}
 
Example #13
Source File: OFDReader.java    From ofdrw with Apache License 2.0 5 votes vote down vote up
/**
 * 构造一个 OFDReader
 *
 * @param ofdFile OFD文件
 * @throws IOException OFD文件操作IO异常
 */
public OFDReader(Path ofdFile) throws IOException {
    if (ofdFile == null || Files.notExists(ofdFile)) {
        throw new IllegalArgumentException("文件位置(ofdFile)不正确");
    }
    workDir = Files.createTempDirectory("ofd-tmp-");
    // 解压文档,到临时的工作目录
    new ZipFile(ofdFile.toFile()).extractAll(workDir.toAbsolutePath().toString());
    ofdDir = new OFDDir(workDir);
    // 创建资源定位器
    rl = new ResourceLocator(ofdDir);
}
 
Example #14
Source File: Zip4jUtil.java    From youran with Apache License 2.0 5 votes vote down vote up
/**
 * 解压zip文件
 *
 * @param zipFile 待解压的zip文件
 * @param destDir 解压目录
 */
public static void extractAll(File zipFile, String destDir) {
    try {
        ZipFile zip = new ZipFile(zipFile);
        zip.extractAll(destDir);
    } catch (ZipException e) {
        LOGGER.error("解压zip包异常", e);
        throw new BusinessException("解压zip包异常");
    }
}
 
Example #15
Source File: Zip4jUtil.java    From youran with Apache License 2.0 5 votes vote down vote up
/**
 * 压缩文件夹
 *
 * @param folderToAdd 待压缩的文件夹
 * @param outFile     输出zip文件
 */
public static void compressFolder(File folderToAdd, File outFile) {
    try {
        ZipFile zipFile = new ZipFile(outFile);
        ZipParameters parameters = new ZipParameters();
        zipFile.addFolder(folderToAdd, parameters);
    } catch (ZipException e) {
        LOGGER.error("压缩zip包异常", e);
    }
}
 
Example #16
Source File: UnzipUtilIT.java    From zip4j with Apache License 2.0 5 votes vote down vote up
private ZipFile createZipFile() throws ZipException {
  ZipFile zipFile = new ZipFile(generatedZipFile, "password".toCharArray());
  zipFile.addFiles(Arrays.asList(
      TestUtils.getTestFileFromResources("sample_text1.txt"),
      TestUtils.getTestFileFromResources("sample_text_large.txt")
  ));
  return zipFile;
}
 
Example #17
Source File: Main2.java    From apkfile with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ZipFile zipFile = new ZipFile(args[0]);
    System.out.println("Is valid " + zipFile.isValidZipFile());
    for (Object header : zipFile.getFileHeaders()) {
        System.out.println("Found header: " + ((FileHeader) header).getFileName());
    }
    System.out.println("Getting stupid entry: " + zipFile.getFileHeader("asdflkasdjflskjdderpy"));
}
 
Example #18
Source File: ZipOutputStreamIT.java    From zip4j with Apache License 2.0 5 votes vote down vote up
private void verifyFileEntryComment(String commentPrefix, Charset charset) throws IOException {
  ZipFile zipFile = initializeZipFileWithCharset(charset);
  List<FileHeader> fileHeaders = zipFile.getFileHeaders();
  for (int i = 0; i < fileHeaders.size(); i++) {
    FileHeader fileHeader = fileHeaders.get(i);
    if (i == 0) {
      assertThat(fileHeader.getFileComment()).isEqualTo(commentPrefix + i);
    } else {
      assertThat(fileHeader.getFileComment()).isNull();
    }
  }
}
 
Example #19
Source File: DocsGenerator.java    From ballerina-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Process files inside given directory.
 *
 * @param directoryPath path of the directory
 */
private static void zipBallerinaProjects(String directoryPath, String tempDir) {
    File folder = new File(directoryPath);
    File[] listOfFiles = folder.listFiles();

    if (listOfFiles != null) {
        for (File file : listOfFiles) {
            if (file.isFile() && (file.getName().equals(BALLERINA_TOML))) {
                // Zip parent folder since this is a Ballerina project.

                // Removing unnecessary md files
                File mdFile = new File(directoryPath + "/1.md");
                mdFile.delete();

                try {
                    new ZipFile(getZipFileName(tempDir, file))
                            .addFolder(new File(file.getParentFile().getPath()));
                } catch (ZipException e) {
                    throw new ServiceException("Error when zipping the directory: "
                            + file.getParentFile().getPath(), e);
                }
            } else if (file.isDirectory()) {
                zipBallerinaProjects(file.getPath(), tempDir);
            }
        }
    }
}
 
Example #20
Source File: OFDDir.java    From ofdrw with Apache License 2.0 5 votes vote down vote up
/**
 * 打包OFD文件
 *
 * @param workDirPath    OFD虚拟容器目录
 * @param fullOfFilePath 生成文件的完整路径(包含后缀的路径)
 * @throws IOException IO异常
 */
private void zip(String workDirPath, String fullOfFilePath) throws IOException {
    ZipFile ofdFile = new ZipFile(fullOfFilePath);
    final File[] files = new File(workDirPath).listFiles();
    if (files == null) {
        throw new RuntimeException("目录中没有任何文件无法打包");
    }
    for (File f : files) {
        if (f.isDirectory()) {
            ofdFile.addFolder(f);
        } else {
            ofdFile.addFile(f);
        }
    }
}
 
Example #21
Source File: ApkFile.java    From apkfile with Apache License 2.0 5 votes vote down vote up
private static Map<String, FileHeader> buildEntryNameToEntry(ZipFile zipFile) throws ZipException {
    Map<String, FileHeader> entryNameToEntry = new HashMap<>();
    for (FileHeader fileHeader : zipFile.getFileHeaders()) {
        entryNameToEntry.put(fileHeader.getFileName(), fileHeader);
    }

    return entryNameToEntry;
}
 
Example #22
Source File: AppClassLoader.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
private static void prepareZipFile() {
	File midletResFile = new File(Config.APP_DIR,
			AppClassLoader.getName() + Config.MIDLET_RES_FILE);
	if (midletResFile.exists()) {
		zipFile = new ZipFile(midletResFile);
	}
}
 
Example #23
Source File: S3DataManagerTest.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testZipSourceEmptyDir() throws Exception {
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream("/tmp/source.zip"));
    ZipSourceCallable.zipSource(testZipSourceWorkspace, "/tmp/source/", out, "/tmp/source/");
    out.close();

    File zip = new File("/tmp/source.zip");
    assertTrue(zip.exists());

    File unzipFolder = new File("/tmp/folder/");
    unzipFolder.mkdir();
    ZipFile z = new ZipFile(zip.getPath());
    assertFalse(z.isValidZipFile()); //checks that zipfile is empty
}
 
Example #24
Source File: EarthProjectsService.java    From collect-earth with MIT License 5 votes vote down vote up
private File unzipContents(File projectZipFile, String projectName) throws ZipException {
	File projectFolder = new File( getProjectsFolder() + File.separator  + projectName );
	if( projectFolder.exists() || projectFolder.mkdirs() ){		
		ZipFile zipFile = new ZipFile(projectZipFile);
		zipFile.extractAll( projectFolder.getAbsolutePath() );
	}
	return projectFolder;
}
 
Example #25
Source File: S3DataManagerTest.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testZipSourceOneDirEmpty() throws Exception {
    String buildSpecName = "Buildspec.yml";
    File buildSpec = new File("/tmp/source/" + buildSpecName);
    String buildSpecContents = "yo\n";
    FileUtils.write(buildSpec, buildSpecContents);
    File sourceDir = new File("/tmp/source/src");
    sourceDir.mkdir();

    ZipOutputStream out = new ZipOutputStream(new FileOutputStream("/tmp/source.zip"));
    ZipSourceCallable.zipSource(testZipSourceWorkspace, "/tmp/source/", out, "/tmp/source/");
    out.close();

    File zip = new File("/tmp/source.zip");
    assertTrue(zip.exists());

    File unzipFolder = new File("/tmp/folder/");
    unzipFolder.mkdir();
    ZipFile z = new ZipFile(zip.getPath());
    z.extractAll(unzipFolder.getPath());
    assertEquals(2, unzipFolder.list().length);
    assertTrue(Arrays.asList(unzipFolder.list()).contains(buildSpecName));
    assertTrue(Arrays.asList(unzipFolder.list()).contains("src"));
    File extractedBuildSpec = new File(unzipFolder.getPath() + "/" + buildSpecName);
    assertEquals(buildSpecContents, FileUtils.readFileToString(extractedBuildSpec));
    File srcDir = new File(unzipFolder.getPath() + "/src");
    assertTrue(srcDir.isDirectory());
    assertEquals(0, srcDir.list().length);
}
 
Example #26
Source File: S3DataManagerTest.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testZipSourceOneDir() throws Exception {
    String buildSpecName = "Buildspec.yml";
    File buildSpec = new File("/tmp/source/" + buildSpecName);
    String buildSpecContents = "yo\n";
    FileUtils.write(buildSpec, buildSpecContents);
    File sourceDir = new File("/tmp/source/src");
    sourceDir.mkdir();
    String srcFileName = "/tmp/source/src/file.java";
    File srcFile = new File(srcFileName);
    String srcFileContents = "int i = 1;";
    FileUtils.write(srcFile, srcFileContents);

    ZipOutputStream out = new ZipOutputStream(new FileOutputStream("/tmp/source.zip"));
    ZipSourceCallable.zipSource(testZipSourceWorkspace, "/tmp/source/", out, "/tmp/source/");
    out.close();

    File zip = new File("/tmp/source.zip");
    assertTrue(zip.exists());

    File unzipFolder = new File("/tmp/folder/");
    unzipFolder.mkdir();
    ZipFile z = new ZipFile(zip.getPath());
    z.extractAll(unzipFolder.getPath());
    String[] fileList = unzipFolder.list();
    assertNotNull(fileList);
    Arrays.sort(fileList);

    assertTrue(fileList.length == 2);
    assertEquals(fileList[0], buildSpecName);
    File extractedBuildSpec = new File(unzipFolder.getPath() + "/" + buildSpecName);
    assertEquals(FileUtils.readFileToString(extractedBuildSpec), buildSpecContents);

    assertEquals(fileList[1], "src");
    File extractedSrcFile = new File(unzipFolder.getPath() + "/src/file.java");
    assertTrue(extractedSrcFile.exists());
    assertEquals(FileUtils.readFileToString(extractedSrcFile), srcFileContents);
}
 
Example #27
Source File: S3DataManagerTest.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testZipSourceHugeFile() throws Exception {
    String buildSpecName = "buildspec.yml";
    File buildSpec = new File("/tmp/source/" + buildSpecName);

    StringBuilder contents = new StringBuilder();

    for(int i = 0; i < 50000; i++) {
        contents.append("123234345456567678456234");
    }

    FileUtils.write(buildSpec, contents.toString());

    ZipOutputStream out = new ZipOutputStream(new FileOutputStream("/tmp/source.zip"));
    ZipSourceCallable.zipSource(testZipSourceWorkspace, "/tmp/source/", out, "/tmp/source/");
    out.close();

    File zip = new File("/tmp/source.zip");
    assertTrue(zip.exists());

    File unzipFolder = new File("/tmp/folder/");
    unzipFolder.mkdir();
    ZipFile z = new ZipFile(zip.getPath());
    z.extractAll(unzipFolder.getPath());
    assertTrue(unzipFolder.list().length == 1);
    assertTrue(unzipFolder.list()[0].equals(buildSpecName));

    File extractedBuildSpec = new File(unzipFolder.getPath() + "/" + buildSpecName);
    assertTrue(FileUtils.readFileToString(extractedBuildSpec).equals(contents.toString()));
}
 
Example #28
Source File: EarthProjectsService.java    From collect-earth with MIT License 5 votes vote down vote up
private String getProjectFolderName(File projectZipFile, int maxLenghtFolderName) throws ZipException, IOException {
	ZipFile zipFile = new ZipFile(projectZipFile);
	File definitionFolder = new File(EarthConstants.GENERATED_FOLDER);
	zipFile.extractFile( PROJECT_PROPERTIES_FILE_NAME, definitionFolder.getAbsolutePath() );		
	String projectName =  getProjectSurveyName(new File( definitionFolder + File.separator + PROJECT_PROPERTIES_FILE_NAME) );
	
	projectName = StringUtils.remove(projectName, " "); //$NON-NLS-1$
	
	if( projectName.length() > maxLenghtFolderName ){
		projectName = projectName.substring(0, maxLenghtFolderName);
	}
	
	return projectName;

}
 
Example #29
Source File: CollectEarthUtils.java    From collect-earth with MIT License 5 votes vote down vote up
public static void addFolderToZip(ZipFile zipFile, File folderToCompress )
		throws ZipException {
	ZipParameters zipParameters = new ZipParameters();
	// COMP_DEFLATE is for compression
	zipParameters.setCompressionMethod(CompressionMethod.DEFLATE);
	// DEFLATE_LEVEL_ULTRA = maximum compression
	zipParameters.setCompressionLevel(CompressionLevel.ULTRA);

	if( folderToCompress.exists() && folderToCompress.isDirectory() ){
		zipFile.addFolder(folderToCompress, zipParameters);
	}
}
 
Example #30
Source File: ImputationChrXTest.java    From imputationserver with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testChr23PipelinePhased() throws IOException, ZipException {

	String configFolder = "test-data/configs/hapmap-chrX";
	String inputFolder = "test-data/data/chr23-phased";

	File file = new File("test-data/tmp");
	if (file.exists()) {
		FileUtil.deleteDirectory(file);
	}

	// create workflow context
	WorkflowTestContext context = buildContext(inputFolder, "phase1");

	// run qc to create chunkfile
	QcStatisticsMock qcStats = new QcStatisticsMock(configFolder);
	boolean result = run(context, qcStats);

	assertTrue(result);

	// add panel to hdfs
	importRefPanel(FileUtil.path(configFolder, "ref-panels"));
	// importMinimacMap("test-data/B38_MAP_FILE.map");
	importBinaries("files/bin");

	// run imputation
	ImputationMinimac3Mock imputation = new ImputationMinimac3Mock(configFolder);
	result = run(context, imputation);
	assertTrue(result);

	// run export
	CompressionEncryptionMock export = new CompressionEncryptionMock("files");
	result = run(context, export);
	assertTrue(result);

	ZipFile zipFile = new ZipFile("test-data/tmp/local/chr_X.zip", PASSWORD.toCharArray());
	zipFile.extractAll("test-data/tmp");

	VcfFile vcfFile = VcfFileUtil.load("test-data/tmp/chrX.dose.vcf.gz", 100000000, false);

	assertEquals("X", vcfFile.getChromosome());
	assertEquals(26, vcfFile.getNoSamples());
	assertEquals(true, vcfFile.isPhased());
	assertEquals(TOTAL_REFPANEL_CHRX_B37, vcfFile.getNoSnps());

	FileUtil.deleteDirectory(file);

}