Package com.github.junrar

Examples of com.github.junrar.Archive


        .println("usage: java -jar extractArchive.jar <thearchive> <the destination directory>");
  }
    }

    public static void extractArchive(File archive, File destination) {
  Archive arch = null;
  try {
      arch = new Archive(archive);
  } catch (RarException e) {
      logger.error(e);
  } catch (IOException e1) {
      logger.error(e1);
  }
  if (arch != null) {
      if (arch.isEncrypted()) {
    logger.warn("archive is encrypted cannot extreact");
    return;
      }
      FileHeader fh = null;
      while (true) {
    fh = arch.nextFileHeader();
    if (fh == null) {
        break;
    }
    if (fh.isEncrypted()) {
        logger.warn("file is encrypted cannot extract: "
          + fh.getFileNameString());
        continue;
    }
    logger.info("extracting: " + fh.getFileNameString());
    try {
        if (fh.isDirectory()) {
      createDirectory(fh, destination);
        } else {
      File f = createFile(fh, destination);
      OutputStream stream = new FileOutputStream(f);
      arch.extractFile(fh, stream);
      stream.close();
        }
    } catch (IOException e) {
        logger.error("error extracting the file", e);
    } catch (RarException e) {
View Full Code Here


    if(s.equalsIgnoreCase("rar")){
      System.out.println(file.toString());
      ReadOnlyAccessFile readFile = null;
      try {
//        readFile = new ReadOnlyAccessFile(file);
        Archive arc = null;
        try {
          arc = new Archive(file);
        } catch (RarException e) {
          logger.error("archive consturctor error",e);
          errorFiles.add(file.toString());
          return;
        }
        if(arc != null){
          if(arc.isEncrypted()){
            logger.warn("archive is encrypted cannot extreact");
            unsupportedFiles.add(file.toString());
            return;
          }
          List<FileHeader> files = arc.getFileHeaders();
          for(FileHeader fh : files)
          {
            if(fh.isEncrypted()){
              logger.warn("file is encrypted cannot extract: "+fh.getFileNameString());
              unsupportedFiles.add(file.toString());
              return;
            }
            logger.info("extracting file: "+fh.getFileNameString());
            if(fh.isFileHeader() && fh.isUnicode()){
              logger.info("unicode name: "+fh.getFileNameW());
            }
            logger.info("start: "+new Date());
           
            ByteArrayOutputStream os = new ByteArrayOutputStream();
           
           
            try {
              arc.extractFile(fh, os);
            } catch (RarException e) {
              if(e.getType().equals(RarExceptionType.notImplementedYet)){
                logger.error("error extracting unsupported file: "+fh.getFileNameString(),e);
                unsupportedFiles.add(file.toString());
                return;
View Full Code Here

  public void init() throws FileSystemException {
    super.init();

    try {
      try {
        archive = new Archive(new VFSVolumeManager(parentLayer));
        // Build the index
        List<RARFileObject> strongRef = new ArrayList<RARFileObject>(
            100);
        for (final FileHeader header : archive.getFileHeaders()) {
          AbstractFileName name = (AbstractFileName) getFileSystemManager()
View Full Code Here

  public RarredFile(File f) {
    this.f = f;
    setLastModified(f.lastModified());

    try {
      rarFile = new Archive(f);
      List<FileHeader> headers = rarFile.getFileHeaders();

      for (FileHeader fh : headers) {
        // if (fh.getFullUnpackSize() < MAX_ARCHIVE_ENTRY_SIZE && fh.getFullPackSize() < MAX_ARCHIVE_ENTRY_SIZE)
        addChild(new RarredEntry(fh.getFileNameString(), f, fh.getFileNameString(), fh.getFullUnpackSize()));
View Full Code Here

  @Override
  public void push(final OutputStream out) throws IOException {
    Runnable r = new Runnable() {
      @Override
      public void run() {
        Archive rarFile = null;
        try {
          rarFile = new Archive(file);
          FileHeader header = null;
          for (FileHeader fh : rarFile.getFileHeaders()) {
            if (fh.getFileNameString().equals(fileHeaderName)) {
              header = fh;
              break;
            }
          }
          if (header != null) {
            LOGGER.trace("Starting the extraction of " + header.getFileNameString());
            rarFile.extractFile(header, out);
          }
        } catch (RarException | IOException e) {
          LOGGER.debug("Unpack error, maybe it's normal, as backend can be terminated: " + e.getMessage());
        } finally {
          try {
            rarFile.close();
            out.close();
          } catch (IOException e) {
            LOGGER.debug("Caught exception", e);
          }
        }
View Full Code Here

  @Override
  public void push(final OutputStream out) throws IOException {
    Runnable r = new Runnable() {

      public void run() {
        Archive rarFile = null;
        try {
          rarFile = new Archive(file);
          FileHeader header = null;
          for (FileHeader fh : rarFile.getFileHeaders()) {
            if (fh.getFileNameString().equals(fileHeaderName)) {
              header = fh;
              break;
            }
          }
          if (header != null) {
            logger.trace("Starting the extraction of " + header.getFileNameString());
            rarFile.extractFile(header, out);
          }
        } catch (Exception e) {
          logger.debug("Unpack error, maybe it's normal, as backend can be terminated: " + e.getMessage());
        } finally {
          try {
            rarFile.close();
            out.close();
          } catch (IOException e) {
            logger.debug("Caught exception", e);
          }
        }
View Full Code Here

  public RarredFile(File f) {
    this.f = f;
    setLastModified(f.lastModified());

    try {
      rarFile = new Archive(f);
      List<FileHeader> headers = rarFile.getFileHeaders();

      for (FileHeader fh : headers) {
        // if (fh.getFullUnpackSize() < MAX_ARCHIVE_ENTRY_SIZE && fh.getFullPackSize() < MAX_ARCHIVE_ENTRY_SIZE)
        addChild(new RarredEntry(fh.getFileNameString(), f, fh.getFileNameString(), fh.getFullUnpackSize()));
View Full Code Here

TOP

Related Classes of com.github.junrar.Archive

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.