當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。