コード例 #1
0
ファイル: HJSplit.java プロジェクト: sn0w/jdownloader
 @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);
   }
 }
コード例 #2
0
ファイル: HJSplit.java プロジェクト: sn0w/jdownloader
 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;
 }