当前位置: 首页>>代码示例>>Java>>正文


Java ArchiveException类代码示例

本文整理汇总了Java中org.apache.commons.compress.archivers.ArchiveException的典型用法代码示例。如果您正苦于以下问题:Java ArchiveException类的具体用法?Java ArchiveException怎么用?Java ArchiveException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ArchiveException类属于org.apache.commons.compress.archivers包,在下文中一共展示了ArchiveException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: system_size

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
@Test
public void system_size() throws IOException, CompressorException, ArchiveException
{
   ProcessingManager mgr = new ProcessingManager();
   long size = mgr.system_size(sample);
   Assert.assertEquals(size, 494928);
   
   File folder=sample.getParentFile();
   File extaction_folder=new File(folder, "unzip");
   extaction_folder.mkdirs();
   
   UnZip.unCompress(sample.getAbsolutePath(), 
      extaction_folder.getAbsolutePath());
   
   File tocheck = extaction_folder.listFiles()[0];
   size = mgr.system_size(tocheck);
   Assert.assertEquals(size, SIZE, tocheck.getAbsolutePath());
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:19,代码来源:ProcessingManagerTest.java

示例2: makeOnlyUnZip

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
public static void makeOnlyUnZip() throws ArchiveException, IOException{
		final InputStream is = new FileInputStream("D:/中文名字.zip");
		ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
		ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry();
		
		String dir = "D:/cnname";
		File filedir = new File(dir);
		if(!filedir.exists()){
			filedir.mkdir();
		}
//		OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
		OutputStream out = new FileOutputStream(new File(filedir, entry.getName()));
		IOUtils.copy(in, out);
		out.close();
		in.close();
	}
 
开发者ID:h819,项目名称:spring-boot,代码行数:17,代码来源:CompressExample.java

示例3: testApache

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
public void testApache() throws IOException, ArchiveException {
	log.debug("testApache()");
	File zip = File.createTempFile("apache_", ".zip");
	
	// Create zip
	FileOutputStream fos = new FileOutputStream(zip);
	ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
	aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
	aos.closeArchiveEntry();
	aos.close();
	
	// Read zip
	FileInputStream fis = new FileInputStream(zip);
	ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
	ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
	assertEquals(zae.getName(), "coñeta");
	ais.close();
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:19,代码来源:ZipTest.java

示例4: tarFolder

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
/**
 * Tar a given folder to a file.
 *
 * @param folder the original folder to tar
 * @param destinationFile the destination file
 * @param waitingHandler a waiting handler used to cancel the process (can
 * be null)
 * @throws FileNotFoundException exception thrown whenever a file is not
 * found
 * @throws ArchiveException exception thrown whenever an error occurred
 * while taring
 * @throws IOException exception thrown whenever an error occurred while
 * reading/writing files
 */
public static void tarFolder(File folder, File destinationFile, WaitingHandler waitingHandler) throws FileNotFoundException, ArchiveException, IOException {
    FileOutputStream fos = new FileOutputStream(destinationFile);
    try {
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        try {
            TarArchiveOutputStream tarOutput = (TarArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.TAR, bos);
            try {
                tarOutput.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
                File matchFolder = folder;
                addFolderContent(tarOutput, matchFolder, waitingHandler);
            } finally {
                tarOutput.close();
            }
        } finally {
            bos.close();
        }
    } finally {
        fos.close();
    }
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:35,代码来源:TarUtils.java

示例5: extractMetadataFromArchive

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
private static Map<String, String> extractMetadataFromArchive(final String archiveType, final InputStream is) {
  final ArchiveStreamFactory archiveFactory = new ArchiveStreamFactory();
  try (ArchiveInputStream ais = archiveFactory.createArchiveInputStream(archiveType, is)) {
    ArchiveEntry entry = ais.getNextEntry();
    while (entry != null) {
      if (!entry.isDirectory() && DESCRIPTION_FILE_PATTERN.matcher(entry.getName()).matches()) {
        return parseDescriptionFile(ais);
      }
      entry = ais.getNextEntry();
    }
  }
  catch (ArchiveException | IOException e) {
    throw new RException(null, e);
  }
  throw new IllegalStateException("No metadata file found");
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-r,代码行数:17,代码来源:RDescriptionUtils.java

示例6: packageSubmission

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
/**
 * @param additionalFiles A map of filename -> content pairs to include in the package.
 * @return The packaged submission as a TAR archive.
 */
@Override
public byte[] packageSubmission(Map<String, byte[]> additionalFiles)
    throws IOException, ArchiveException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

  try (ArchiveOutputStream archive = new ArchiveStreamFactory()
      .createArchiveOutputStream(ArchiveStreamFactory.TAR, outputStream)) {

    addTemplateFiles(archive);
    addAdditionalFiles(archive, additionalFiles);

    archive.finish();
  }

  logger.debug("Finished packaging submission, size {} bytes.", outputStream.size());

  return outputStream.toByteArray();
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:23,代码来源:SubmissionPackagingService.java

示例7: task

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
@RequestMapping(value = "/task", method = RequestMethod.POST)
public RedirectView task(String submissionCode,
    long taskInstanceId,
    RedirectAttributes redirectAttributes) throws IOException, ArchiveException {
  logger.debug("Submitting task");

  TaskInstance taskInstance = taskInstanceService.findOne(taskInstanceId);
  Challenge currentChallenge = taskInstance.getTask().getChallenge();

  Submission submission = submitToTmc(taskInstance, currentChallenge, submissionCode);

  redirectAttributes.addFlashAttribute("submissionId", submission.getId().toString());
  redirectAttributes.addFlashAttribute("taskInstance", taskInstance);
  redirectAttributes.addFlashAttribute("challenge", currentChallenge);
  redirectAttributes.addFlashAttribute("user", userService.getCurrentUser());

  // Save user's answer from left editor
  taskInstanceService.updateTaskInstanceCode(taskInstanceId, submissionCode);
  logger.debug("Redirecting to feedback");
  return new RedirectView("/feedback");
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:22,代码来源:TaskController.java

示例8: submitToTmc

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
private Submission submitToTmc(TaskInstance taskInstance, Challenge challenge,
    String submissionCode)
    throws IOException, ArchiveException {
  logger.debug("Submitting to TMC");
  Map<String, byte[]> files = new HashMap<>();

  CodeStubBuilder stubBuilder = new CodeStubBuilder(challenge.getName());
  CodeStub implStub = stubBuilder.build();
  CodeStub testStub = new TestStubBuilder(stubBuilder).build();

  boolean isTest = taskInstance.getTask().getType() == TaskType.TEST;
  String staticCode;

  if (isTest) {
    staticCode = taskService.getCorrespondingTask(taskInstance.getTask()).getCodeStub();
  } else {
    staticCode = taskInstance.getTestTaskinstance().getCode();
  }

  files.put(isTest ? testStub.filename : implStub.filename, submissionCode.getBytes());
  files.put(isTest ? implStub.filename : testStub.filename, staticCode.getBytes());

  return sandboxService.submit(files, taskInstance);
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:25,代码来源:TaskController.java

示例9: packageContainsAllTemplateFiles

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
@Test
public void packageContainsAllTemplateFiles() throws ArchiveException, IOException {
  // Create a package with only template files
  byte[] packaged = packagingService.packageSubmission(new HashMap<>());
  createStreams(packaged);

  ArchiveEntry entry = inputArchive.getNextEntry();

  Set<String> foundEntries = new HashSet<>();

  for (; entry != null; entry = inputArchive.getNextEntry()) {
    assertNotEquals(0, entry.getSize());
    foundEntries.add(entry.getName());
  }

  assertEquals(templateEntries, foundEntries);
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:18,代码来源:SubmissionPackagingServiceTest.java

示例10: testAdditionalFiles

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
@Test
public void testAdditionalFiles() throws IOException, ArchiveException {
  Map<String, byte[]> randomFiles = generateRandomFiles(NUM_RANDOM_FILES);
  byte[] packaged = packagingService.packageSubmission(randomFiles);

  createStreams(packaged);

  ArchiveEntry entry = inputArchive.getNextEntry();

  for (; entry != null; entry = inputArchive.getNextEntry()) {
    // Skip template files
    if (templateEntries.contains(entry.getName())) {
      continue;
    }

    assertTrue(randomFiles.containsKey(entry.getName()));

    byte[] expectedContent = randomFiles.get(entry.getName());
    byte[] actualContent = new byte[(int) entry.getSize()];
    inputArchive.read(actualContent);

    assertArrayEquals(expectedContent, actualContent);
  }

}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:26,代码来源:SubmissionPackagingServiceTest.java

示例11: makeOnlyZip

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
public static void makeOnlyZip() throws IOException, ArchiveException{
	File f1 = new File("D:/compresstest.txt");
       File f2 = new File("D:/test1.xml");
       
       final OutputStream out = new FileOutputStream("D:/中文名字.zip");
       ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out);
       
       os.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
       IOUtils.copy(new FileInputStream(f1), os);
       os.closeArchiveEntry();

       os.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
       IOUtils.copy(new FileInputStream(f2), os);
       os.closeArchiveEntry();
       os.close();
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:17,代码来源:CompressExample.java

示例12: exportFolderAsJar

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
/**
 * Generate a jar file from a repository folder path
 */
private void exportFolderAsJar(String fldPath, OutputStream os) throws PathNotFoundException, AccessDeniedException,
		RepositoryException, ArchiveException, ParseException, NoSuchGroupException, IOException, DatabaseException, MessagingException {
	log.debug("exportFolderAsJar({}, {})", fldPath, os);
	StringWriter out = new StringWriter();
	File tmp = null;

	try {
		tmp = FileUtils.createTempDir();

		// Export files
		RepositoryExporter.exportDocuments(null, fldPath, tmp, false, false, out, new TextInfoDecorator(fldPath));

		// Jar files
		ArchiveUtils.createJar(tmp, PathUtils.getName(fldPath), os);
	} catch (IOException e) {
		log.error("Error exporting jar", e);
		throw e;
	} finally {
		IOUtils.closeQuietly(out);
		FileUtils.deleteQuietly(tmp);
	}

	log.debug("exportFolderAsJar: void");
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:28,代码来源:DownloadServlet.java

示例13: addFilesToZip

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
void addFilesToZip(File source, File destination) throws IOException, ArchiveException {
    OutputStream archiveStream = new FileOutputStream(destination);
    ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
    Collection<File> fileList = FileUtils.listFiles(source, null, true);
    for (File file : fileList) {
        String entryName = getEntryName(source, file);
        ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
        archive.putArchiveEntry(entry);
        BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(input, archive);
        input.close();
        archive.closeArchiveEntry();
    }
    archive.finish();
    archiveStream.close();
}
 
开发者ID:spirylics,项目名称:web2app,代码行数:17,代码来源:Npm.java

示例14: compressDirectory

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
public static void compressDirectory(File rootDir, boolean includeAsRoot, File output) throws IOException {
    if (!rootDir.isDirectory()) {
        throw new IOException("Provided file is not a directory");
    }
    try (OutputStream archiveStream = new FileOutputStream(output);
         ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream)) {
        String rootName = "";
        if (includeAsRoot) {
            insertDirectory(rootDir, rootDir.getName(), archive);
            rootName = rootDir.getName()+"/";
        }
        Collection<File> fileCollection = FileUtils.listFilesAndDirs(rootDir, TrueFileFilter.TRUE, TrueFileFilter.TRUE);
        for (File file : fileCollection) {
            String relativePath = getRelativePath(rootDir, file);
            String entryName = rootName+relativePath;
            if (!relativePath.isEmpty() && !"/".equals(relativePath)) {
                insertObject(file, entryName, archive);
            }
        }
        archive.finish();
    } catch (IOException | ArchiveException e) {
        throw new IOException(e);
    }
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:25,代码来源:ZipUtil.java

示例15: createInputStreamIterator

import org.apache.commons.compress.archivers.ArchiveException; //导入依赖的package包/类
Iterator<InputStream> createInputStreamIterator(InputStream in)
        throws IOException {
    // It is required to support mark to detect a file format.
    in = in.markSupported() ? in : new BufferedInputStream(in);
    try {
        return new ArchiveInputStreamIterator(
                createArchiveInputStream(AUTO_DETECT_FORMAT, in),
                this.matchName
        );
    } catch (IOException | ArchiveException e) {
        // ArchiveStreamFactory set mark and reset the stream.
        // So, we can use the same stream to check compressor.
        try {
            return toIterator(createCompressorInputStream(AUTO_DETECT_FORMAT, in));
        } catch (CompressorException e2) {
            throw new IOException("Failed to detect a file format.", e2);
        }
    }
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:20,代码来源:CommonsCompressProvider.java


注:本文中的org.apache.commons.compress.archivers.ArchiveException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。