Exemple #1
0
 @Override
 public Boolean isSupported(final ArchiveFactory factory, final boolean allowDeepInspection) {
   if (splitType.matches(factory.getFilePath())) {
     if (factory instanceof DownloadLinkArchiveFactory) {
       for (final DownloadLink link : ((DownloadLinkArchiveFactory) factory).getDownloadLinks()) {
         final ExtensionsFilterInterface hint =
             CompiledFiletypeFilter.getExtensionsFilterInterface(link.getMimeHint());
         if (hint != null
             && !hint.isSameExtensionGroup(CompiledFiletypeFilter.ArchiveExtensions.NUM)) {
           return false;
         }
       }
     } else if (factory instanceof CrawledLinkFactory) {
       for (final CrawledLink link : ((CrawledLinkFactory) factory).getLinks()) {
         final DownloadLink dlLink = link.getDownloadLink();
         if (dlLink != null) {
           final ExtensionsFilterInterface hint =
               CompiledFiletypeFilter.getExtensionsFilterInterface(dlLink.getMimeHint());
           if (hint != null
               && !hint.isSameExtensionGroup(CompiledFiletypeFilter.ArchiveExtensions.NUM)) {
             return false;
           }
         }
       }
     }
     if (allowDeepInspection) {
       try {
         return SplitType.createArchive(factory, splitType, allowDeepInspection) != null;
       } catch (ArchiveException e) {
         getLogger().log(e);
       }
     } else {
       return true;
     }
   }
   return false;
 }
Exemple #2
0
 @Override
 public void extract(ExtractionController ctrl) {
   final Archive archive = getExtractionController().getArchive();
   final ArchiveFile firstArchiveFile = archive.getArchiveFiles().get(0);
   final String matches[] = splitType.getMatches(firstArchiveFile.getName());
   if (matches != null) {
     try {
       final String fileName;
       final int skipBytes;
       final String signature =
           JDHexUtils.toString(
               FileSignatures.readFileSignature(new File(firstArchiveFile.getFilePath())));
       if (new Regex(signature, "^[\\w]{3}  \\d{3}").matches()) {
         final String extension = new Regex(signature, "^([\\w]{3})").getMatch(0);
         fileName = matches[0] + "." + extension;
         skipBytes = 8;
       } else {
         skipBytes = 0;
         fileName = matches[0];
       }
       if (SplitUtil.merge(getExtractionController(), fileName, skipBytes, getConfig())) {
         archive.setExitCode(ExtractionControllerConstants.EXIT_CODE_SUCCESS);
       } else {
         if (archive.getExitCode() == -1) {
           archive.setExitCode(ExtractionControllerConstants.EXIT_CODE_FATAL_ERROR);
         }
       }
       return;
     } catch (ExtractionControllerException e) {
       archive.setExitCode(e.getExitCode());
     } catch (IOException e) {
       archive.setExitCode(ExtractionControllerConstants.EXIT_CODE_FATAL_ERROR);
     }
   } else {
     archive.setExitCode(ExtractionControllerConstants.EXIT_CODE_FATAL_ERROR);
   }
 }
Exemple #3
0
 public Archive buildArchive(ArchiveFactory link, boolean allowDeepInspection)
     throws ArchiveException {
   return SplitType.createArchive(link, splitType, allowDeepInspection);
 }
Exemple #4
0
 public DummyArchive checkComplete(Archive archive) throws CheckException {
   if (archive.getSplitType() == splitType) {
     try {
       final DummyArchive ret = new DummyArchive(archive, splitType.name());
       boolean hasMissingArchiveFiles = false;
       for (ArchiveFile archiveFile : archive.getArchiveFiles()) {
         if (archiveFile instanceof MissingArchiveFile) {
           hasMissingArchiveFiles = true;
         }
         ret.add(new DummyArchiveFile(archiveFile));
       }
       if (hasMissingArchiveFiles == false) {
         final ArchiveFile firstFile = archive.getArchiveFiles().get(0);
         final String firstArchiveFile = firstFile.getFilePath();
         final String partNumberOfFirstArchiveFile =
             splitType.getPartNumberString(firstArchiveFile);
         if (splitType.getFirstPartIndex()
             != splitType.getPartNumber(partNumberOfFirstArchiveFile)) {
           throw new CheckException(
               "Wrong firstArchiveFile("
                   + firstArchiveFile
                   + ") for Archive("
                   + archive.getName()
                   + ")");
         }
         if (firstFile.exists()) {
           final String signature =
               JDHexUtils.toString(FileSignatures.readFileSignature(new File(firstArchiveFile)));
           if (new Regex(signature, "^[\\w]{3}  \\d{3}").matches()) {
             /** cutkiller header: extension and number of files */
             final String numberOfPartsString =
                 new Regex(signature, "^[\\w]{3}  (\\d{3})").getMatch(0);
             final int numberOfParts = Integer.parseInt(numberOfPartsString);
             final List<ArchiveFile> missingArchiveFiles =
                 SplitType.getMissingArchiveFiles(archive, splitType, numberOfParts);
             if (missingArchiveFiles != null) {
               for (ArchiveFile missingArchiveFile : missingArchiveFiles) {
                 ret.add(new DummyArchiveFile(missingArchiveFile));
               }
             }
             if (ret.getSize() < numberOfParts) {
               throw new CheckException(
                   "Missing archiveParts("
                       + numberOfParts
                       + "!="
                       + ret.getSize()
                       + ") for Archive("
                       + archive.getName()
                       + ")");
             } else if (ret.getSize() > numberOfParts) {
               throw new CheckException(
                   "Too many archiveParts("
                       + numberOfParts
                       + "!="
                       + ret.getSize()
                       + ") for Archive("
                       + archive.getName()
                       + ")");
             }
           }
         }
       }
       return ret;
     } catch (CheckException e) {
       throw e;
     } catch (Throwable e) {
       throw new CheckException("Cannot check Archive(" + archive.getName() + ")", e);
     }
   }
   return null;
 }