UnarchiverProcess.java 27.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.commons.jcr.JcrUtil
 *  com.day.cq.dam.api.Asset
 *  com.day.cq.dam.api.AssetManager
 *  com.day.cq.dam.api.Rendition
 *  com.day.cq.dam.commons.process.AbstractAssetWorkflowProcess
 *  com.day.cq.workflow.WorkflowException
 *  com.day.cq.workflow.WorkflowSession
 *  com.day.cq.workflow.exec.WorkItem
 *  com.day.cq.workflow.exec.WorkflowData
 *  com.day.cq.workflow.exec.WorkflowProcess
 *  com.day.cq.workflow.metadata.MetaDataMap
 *  javax.jcr.Item
 *  javax.jcr.Node
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  org.apache.commons.io.IOUtils
 *  org.apache.commons.lang.StringUtils
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.jackrabbit.util.Text
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.commons.mime.MimeTypeService
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.dam.core.process;

import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.AssetManager;
import com.day.cq.dam.api.Rendition;
import com.day.cq.dam.commons.process.AbstractAssetWorkflowProcess;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowData;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.util.Text;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.mime.MimeTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service(value={WorkflowProcess.class})
@Property(name="process.label", value={"DAM Unarchiver Process"})
public class UnarchiverProcess
extends AbstractAssetWorkflowProcess {
    protected static final Logger log = LoggerFactory.getLogger(UnarchiverProcess.class);
    protected static final int BUFFER = 2048;
    protected static final String MIME_TYPE_ZIP = "application/zip";
    protected static final String FILE_EXT_ZIP = ".zip";

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Loose catch block
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     * Lifted jumps to return sites
     */
    public final void execute(WorkItem item, WorkflowSession wfSession, MetaDataMap args) throws WorkflowException {
        Session session = wfSession.getSession();
        Asset asset = this.getAssetFromPayload(item, session);
        if (null == asset) {
            log.error("execute: cannot extract archive, asset [{}] in workflow [{}] does not exist.", (Object)item.getWorkflowData().getPayload().toString(), (Object)item.getId());
            return;
        }
        String assetPath = asset.getPath();
        if (!UnarchiverProcess.isZipFile(asset)) {
            log.info("execute: ignoring asset [{}] as it is not a ZIP archive.", (Object)assetPath);
            return;
        }
        Rendition original = asset.getOriginal();
        if (null == original) {
            log.error("execute: cannot extract archive, asset [{}] in workflow [{}] doesn't have original file.", (Object)assetPath, (Object)item.getId());
            return;
        }
        InputStream stream = original.getStream();
        if (null == stream) {
            log.error("execute: cannot extract archive, asset [{}] in workflow [{}] doesn't have binary stream.", (Object)assetPath, (Object)item.getId());
            return;
        }
        AssetManager assetManager = this.getAssetManager(session);
        if (null == assetManager) {
            throw new WorkflowException("asset manager unavailable");
        }
        UnarchiverContext context = new UnarchiverContext(session, assetManager, asset, args);
        if (context.isDisableExtraction()) {
            log.info("execute: skipping extraction of [{}], disabled via configuration.", (Object)assetPath);
            return;
        }
        item.getWorkflowData().getMetaDataMap().put((Object)"noretry", (Object)true);
        log.info("scan: scanning archive [{}] and verifying configured limits", (Object)assetPath);
        this.scan(context);
        log.debug("execute: calling beforeExtract for [{}]", (Object)assetPath);
        this.beforeExtract(context);
        boolean isExtractionSuccessful = false;
        try {
            isExtractionSuccessful = this.extract(context);
            log.debug("execute: calling afterExtract for [{}] (extraction {})", (Object)assetPath, (Object)(isExtractionSuccessful ? "successful" : "failed"));
        }
        catch (IOException e) {
            log.error("execute: IO error while extracting archive [{}]: ", (Object)assetPath, (Object)e);
            log.debug("execute: calling afterExtract for [{}] (extraction {})", (Object)assetPath, (Object)(isExtractionSuccessful ? "successful" : "failed"));
            {
                catch (Throwable throwable) {
                    log.debug("execute: calling afterExtract for [{}] (extraction {})", (Object)assetPath, (Object)(isExtractionSuccessful ? "successful" : "failed"));
                    this.afterExtract(context, isExtractionSuccessful);
                    throw throwable;
                }
            }
            this.afterExtract(context, isExtractionSuccessful);
            return;
            catch (RepositoryException e) {
                log.error("execute: repository error while extracting archive [{}]: ", (Object)assetPath, (Object)e);
                log.debug("execute: calling afterExtract for [{}] (extraction {})", (Object)assetPath, (Object)(isExtractionSuccessful ? "successful" : "failed"));
                this.afterExtract(context, isExtractionSuccessful);
                return;
            }
        }
        this.afterExtract(context, isExtractionSuccessful);
        return;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private boolean extract(UnarchiverContext context) throws RepositoryException, IOException {
        Session session = context.getSession();
        Asset asset = context.getAsset();
        String assetPath = asset.getPath();
        ZipInputStream zis = context.createZipInputStream();
        try {
            log.info("extract: begin extraction of archive [{}] - update mode [{}]", (Object)assetPath, (Object)context.getUpdateMode().name());
            context.setRoot(this.getOrCreateRoot(context));
            try {
                ZipEntry entry;
                while (null != (entry = zis.getNextEntry())) {
                    String name = entry.getName();
                    if (this.isExtractEntry(context, entry)) {
                        long numFiles = context.updateNumFiles();
                        this.extractEntry(context, zis, entry);
                        if (numFiles % context.getSaveThreshold() != 0) continue;
                        log.debug("extract: threshold of [{}] reached, saving....", (Object)context.getSaveThreshold());
                        session.save();
                        continue;
                    }
                    log.info("extract: extraction of entry [{}] skipped for archive [{}]", (Object)name, (Object)assetPath);
                }
            }
            catch (Exception e) {
                log.error("extract: error while extracting archive [{}]: ", (Object)assetPath, (Object)e);
            }
            finally {
                zis.closeEntry();
            }
            session.save();
            log.info("extract: extraction of archive [{}] successfully completed.", (Object)assetPath);
            boolean e = true;
            return e;
        }
        finally {
            IOUtils.closeQuietly((InputStream)zis);
        }
    }

    private long getFolderCount(HashMap<String, Long> folderMap, String zipFolder) {
        long count;
        if (folderMap.containsKey(zipFolder)) {
            count = folderMap.get(zipFolder);
            folderMap.put(zipFolder, ++count);
        } else {
            count = 1;
            folderMap.put(zipFolder, count);
        }
        return count;
    }

    private String getSHA1(MessageDigest sha1) {
        return new BigInteger(1, sha1.digest()).toString(16);
    }

    private static boolean isZipFile(Asset asset) {
        return "application/zip".equals(asset.getMimeType()) || asset.getName().endsWith(".zip");
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    protected void scan(UnarchiverContext context) throws WorkflowException {
        Asset asset = context.getAsset();
        HashMap<String, Long> folderMap = new HashMap<String, Long>();
        String assetPath = asset.getPath();
        long maxBytes = context.getMaxBytes();
        long maxNumFiles = context.getMaxNumFiles();
        long maxNumFilesPerDir = context.getMaxNumFilesPerDirectory();
        log.info("scan: configured limits: max bytes [{}], max files [{}], max files per dir [" + maxNumFilesPerDir + "]", (Object)maxBytes, (Object)maxNumFiles);
        ZipInputStream zis = context.createZipInputStream();
        try {
            ZipEntry entry;
            long numBytes = 0;
            long numFiles = 0;
            while (null != (entry = zis.getNextEntry())) {
                int size;
                EntryInfo info = context.getEntryInfo(entry);
                String zipFolder = info.getParentPath();
                if (!this.isExtractEntry(context, entry)) continue;
                long entryBytes = 0;
                byte[] buffer = new byte[2048];
                while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                    entryBytes += (long)size;
                }
                entry.setSize(entryBytes);
                if ((numBytes += entryBytes) > maxBytes) {
                    log.error("scan: archive [{}] exceeds configured max bytes limit [{}]", (Object)assetPath, (Object)maxBytes);
                    throw new WorkflowException("Configured max number of bytes exceeded");
                }
                if (++numFiles > maxNumFiles) {
                    log.error("scan: archive [{}] exceeds max number of files limit [{}]", (Object)assetPath, (Object)maxNumFiles);
                    throw new WorkflowException("Configured max number of files limit exceeded");
                }
                long dirFileCount = this.getFolderCount(folderMap, zipFolder);
                if (dirFileCount > maxNumFilesPerDir) {
                    log.error("scan: archive [{}] exceeds max number of files/folders per directory limit [" + maxNumFilesPerDir + "] in directory [{}]", (Object)assetPath, (Object)zipFolder);
                    throw new WorkflowException("Configured total number of files limit reached");
                }
                log.debug("scan: scanned entry [{}] - [{}] bytes - folder:[" + zipFolder + " - " + dirFileCount + " - " + maxNumFilesPerDir + "]", (Object)entry.getName(), (Object)entry.getSize());
            }
            context.setTotalNumFiles(numFiles);
            context.setTotalNumBytes(numBytes);
            log.info("scan: scan of archive [{}] completed. archive is within configured limits.", (Object)assetPath);
            log.info("scan: archive [{}] will result in [{}] extracted files with a total of [" + numBytes + "] bytes.", (Object)assetPath, (Object)numFiles);
        }
        catch (IOException e) {
            log.error("scan: IO error while scanning archive [{}]: ", (Object)assetPath, (Object)e);
        }
        finally {
            IOUtils.closeQuietly((InputStream)zis);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    protected void extractEntry(UnarchiverContext context, ZipInputStream zis, ZipEntry entry) throws Exception {
        block13 : {
            Session session = context.getSession();
            Node root = context.getTargetRoot();
            EntryInfo info = context.getEntryInfo(entry);
            String name = entry.getName();
            String zipPath = info.getPath();
            String fileName = info.getFileName();
            String fullPath = info.getTargetPath(root.getPath());
            log.debug("extractEntry: extracting entry [{}] in archive [{}]", (Object)entry.getName(), (Object)context.getAsset().getPath());
            if (entry.isDirectory()) {
                if (!root.hasNode(zipPath)) {
                    Node node = JcrUtil.createPath((Node)root, (String)zipPath, (boolean)false, (String)"sling:OrderedFolder", (String)"sling:OrderedFolder", (Session)session, (boolean)false);
                    log.info("extractEntry: created directory [{}] from entry [{}]", (Object)node.getPath(), (Object)name);
                } else {
                    log.debug("extractEntry: directory [{}] already exists, skipping entry [{}]", (Object)fullPath, (Object)name);
                }
            } else {
                File tempFile = File.createTempFile("unarchiver-file-" + System.currentTimeMillis(), null);
                log.debug("extractEntry: created temporary file at [{}]", (Object)tempFile.getPath());
                FileOutputStream fos = null;
                FileInputStream fis = null;
                try {
                    String assetSha1;
                    int size;
                    long numBytes = 0;
                    byte[] buffer = new byte[2048];
                    MessageDigest sha1 = MessageDigest.getInstance("SHA1");
                    fos = new FileOutputStream(tempFile);
                    while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                        fos.write(buffer, 0, size);
                        sha1.update(buffer, 0, size);
                        numBytes += (long)size;
                    }
                    IOUtils.closeQuietly((OutputStream)fos);
                    context.updateNumBytes(numBytes);
                    if (this.isMatchSkipFileNamePatterns(context, fileName)) break block13;
                    String zipSha1 = this.getSHA1(sha1);
                    log.debug("extractEntry: got SHA-1 [{}] for entry [{}]", (Object)zipSha1, (Object)name);
                    Resource resource = this.getResourceResolver(session).getResource(fullPath);
                    Asset target = null;
                    if (null != resource && null != (target = (Asset)resource.adaptTo(Asset.class)) && StringUtils.equals((String)(assetSha1 = target.getMetadataValue("dam:sha1")), (String)zipSha1)) {
                        log.info("extractEntry: entry [{}] exists as asset [{}] with identical SHA-1, skipping.", (Object)name, (Object)target.getPath());
                        return;
                    }
                    fis = new FileInputStream(tempFile);
                    String mimeType = this.mimeTypeService.getMimeType(fileName);
                    if (null != target) {
                        Asset newAsset = target.addRendition("original", (InputStream)fis, mimeType).getAsset();
                        log.info("extractEntry: updated existing asset [{}] from entry [{}]", (Object)newAsset.getPath(), (Object)name);
                        break block13;
                    }
                    if (null != resource) {
                        log.error("extractEntry: cannot extract entry [{}], blocking resource at [{}]", (Object)name, (Object)resource.getPath());
                        throw new WorkflowException("Cannot extract entry, blocking resource.");
                    }
                    Asset newAsset = context.getAssetManager().createAsset(fullPath, (InputStream)fis, mimeType, false);
                    if (null != newAsset) {
                        log.info("extractEntry: created new asset [{}] from entry [{}]", (Object)newAsset.getPath(), (Object)name);
                        break block13;
                    }
                    log.error("extractEntry: asset manager couldn't create asset for entry [{}]", (Object)name);
                    throw new WorkflowException("Asset manager couldn't create asset for entry " + name);
                }
                finally {
                    IOUtils.closeQuietly((OutputStream)fos);
                    IOUtils.closeQuietly((InputStream)fis);
                    tempFile.delete();
                    log.debug("extractEntry: deleted temporary file at [{}]", (Object)tempFile.getPath());
                }
            }
        }
    }

    private boolean isMatchSkipFileNamePatterns(UnarchiverContext context, String fileName) {
        String[] patterns;
        for (String pattern : patterns = context.getSkipFileNamePatterns().split(":")) {
            if (!fileName.matches(pattern)) continue;
            return true;
        }
        return false;
    }

    protected void afterExtract(UnarchiverContext context, boolean isExtractionSuccessful) {
        String assetPath = context.getAsset().getPath();
        if (!isExtractionSuccessful) {
            log.info("afterExtract: not removing original archive [{}] as preceding extraction failed.", (Object)assetPath);
            return;
        }
        if (context.isRemoveOriginal()) {
            Session session = context.getSession();
            log.debug("afterExtract: removing original archive [{}]", (Object)assetPath);
            try {
                session.removeItem(assetPath);
                session.save();
                log.info("afterExtract: original archive [{}] removed", (Object)assetPath);
            }
            catch (RepositoryException e) {
                log.error("afterExtract: could not remove asset [{}]: ", (Object)assetPath, (Object)e);
            }
        } else {
            log.info("afterExtract: not removing original archive [{}] as per configuration.", (Object)assetPath);
        }
    }

    protected boolean isExtractEntry(UnarchiverContext context, ZipEntry entry) {
        return true;
    }

    protected void beforeExtract(UnarchiverContext context) {
    }

    protected Node getOrCreateRoot(UnarchiverContext context) throws RepositoryException {
        Node root;
        Session session = context.getSession();
        Asset asset = context.getAsset();
        String assetPath = asset.getPath();
        String rootHint = Text.getRelativeParent((String)asset.getPath(), (int)1) + "/" + StringUtils.substringBeforeLast((String)asset.getName(), (String)".");
        if (UnarchiverContext.UPDATE_MODE.OVERWRITE == context.getUpdateMode()) {
            if (session.itemExists(rootHint)) {
                log.debug("extract: update mode is [{}], removing existing folder [{}]...", (Object)context.getUpdateMode().name(), (Object)rootHint);
                session.getItem(rootHint).remove();
                session.save();
                log.info("extract: target folder [{}] removed.", (Object)rootHint);
            }
            root = JcrUtil.createPath((String)rootHint, (String)"sling:OrderedFolder", (Session)session);
            log.debug("extract: created extraction folder at [{}] for [{}]", (Object)root.getPath(), (Object)assetPath);
        } else if (UnarchiverContext.UPDATE_MODE.UPDATE == context.getUpdateMode()) {
            if (session.itemExists(rootHint)) {
                root = (Node)session.getItem(rootHint);
                log.debug("extract: update mode is [{}], using existing folder [{}]...", (Object)context.getUpdateMode().name(), (Object)rootHint);
            } else {
                root = JcrUtil.createPath((String)rootHint, (String)"sling:OrderedFolder", (Session)session);
                session.save();
                log.debug("extract: update mode is [{}], but destination doesn't exit, created [{}]", (Object)context.getUpdateMode().name(), (Object)rootHint);
            }
        } else {
            log.debug("extract: update mode is [{}], creating unique folder...", (Object)context.getUpdateMode().name());
            root = JcrUtil.createUniquePath((String)rootHint, (String)"sling:OrderedFolder", (Session)session);
            session.save();
            log.debug("extract: created extraction folder at [{}] for [{}]", (Object)root.getPath(), (Object)assetPath);
        }
        return root;
    }

    protected static class EntryInfo {
        private static final String ROOT_FOLDER = "./";
        private final ZipEntry entry;
        private final String path;
        private final String fileName;
        private final String parentPath;

        private EntryInfo(ZipEntry entry) {
            this.entry = entry;
            String name = entry.getName();
            this.path = name.endsWith("/") ? StringUtils.substring((String)name, (int)0, (int)(name.length() - 1)) : name;
            this.fileName = Text.getName((String)entry.getName());
            this.parentPath = Text.getRelativeParent((String)this.path, (int)1);
        }

        protected ZipEntry getEntry() {
            return this.entry;
        }

        protected String getFileName() {
            return this.fileName;
        }

        protected String getParentPath() {
            return StringUtils.isBlank((String)this.parentPath) ? "./" : this.parentPath;
        }

        protected String getPath() {
            return this.path;
        }

        protected String getTargetPath(String rootPath) {
            return rootPath + "/" + ("./".equals(this.getParentPath()) ? "" : new StringBuilder().append(this.getParentPath()).append("/").toString()) + Text.escapeIllegalJcrChars((String)this.getFileName());
        }
    }

    protected static class UnarchiverContext {
        protected static final String ARG_NAME_DISABLE_EXTRACT = "disableExtract";
        protected static final String ARG_NAME_REMOVE_ORIGINAL = "removeOriginal";
        protected static final String ARG_NAME_MAX_BYTES = "maxBytes";
        protected static final String ARG_NAME_MAX_NUM_ITEMS = "maxNumItems";
        protected static final String ARG_NAME_MAX_NUM_ITEMS_PER_DIR = "maxNumItemsPerDir";
        protected static final String ARG_NAME_SAVE_THRESHOLD = "saveThreshold";
        protected static final String ARG_NAME_UPDATE_MODE = "updateMode";
        protected static final String ARG_NAME_SKIP_FILE_NAME_PATTERNS = "skipFileNamePatterns";
        protected static final long DEFAULT_MAX_BYTES = 104857600;
        protected static final long DEFAULT_MAX_NUM_ITEMS = 10000;
        protected static final long DEFAULT_MAX_NUM_ITEMS_PER_DIR = 100;
        protected static final long DEFAULT_SAVE_THRESHOLD = 1024;
        private final boolean removeOriginal;
        private final boolean disableExtraction;
        private final long maxBytes;
        private final long maxNumFiles;
        private final long maxNumFilesPerDir;
        private final long saveThreshold;
        private final Session session;
        private final AssetManager assetManager;
        private final Asset asset;
        private Node root;
        private UPDATE_MODE updateMode;
        private long numFiles = 0;
        private long numBytes = 0;
        private long totalNumFiles;
        private long totalNumBytes;
        private String skipFileNamePatterns = "";

        private UnarchiverContext(Session session, AssetManager assetManager, Asset asset, MetaDataMap args) {
            this.session = session;
            this.assetManager = assetManager;
            this.asset = asset;
            this.removeOriginal = (Boolean)args.get("removeOriginal", (Object)false);
            this.disableExtraction = (Boolean)args.get("disableExtract", (Object)false);
            this.maxBytes = (Long)args.get("maxBytes", (Object)104857600);
            this.maxNumFiles = (Long)args.get("maxNumItems", (Object)10000);
            this.maxNumFilesPerDir = (Long)args.get("maxNumItemsPerDir", (Object)100);
            this.saveThreshold = (Long)args.get("saveThreshold", (Object)1024);
            this.skipFileNamePatterns = (String)args.get("skipFileNamePatterns", (Object)"");
            try {
                String updateModeStr = ((String)args.get("updateMode", (Object)"new")).toUpperCase();
                this.updateMode = UPDATE_MODE.valueOf(updateModeStr);
            }
            catch (IllegalArgumentException e) {
                this.updateMode = UPDATE_MODE.NEW;
            }
        }

        public Asset getAsset() {
            return this.asset;
        }

        public AssetManager getAssetManager() {
            return this.assetManager;
        }

        public EntryInfo getEntryInfo(ZipEntry entry) {
            return new EntryInfo(entry);
        }

        public long getSaveThreshold() {
            return this.saveThreshold;
        }

        public Node getTargetRoot() {
            return this.root;
        }

        public long getNumFiles() {
            return this.numFiles;
        }

        public long getNumBytes() {
            return this.numBytes;
        }

        public Session getSession() {
            return this.session;
        }

        protected long getMaxBytes() {
            return this.maxBytes;
        }

        protected long getMaxNumFiles() {
            return this.maxNumFiles;
        }

        public long getMaxNumFilesPerDirectory() {
            return this.maxNumFilesPerDir;
        }

        public long getTotalNumFiles() {
            return this.totalNumFiles;
        }

        public long getTotalNumBytes() {
            return this.totalNumBytes;
        }

        public UPDATE_MODE getUpdateMode() {
            return this.updateMode;
        }

        protected boolean isDisableExtraction() {
            return this.disableExtraction;
        }

        protected boolean isRemoveOriginal() {
            return this.removeOriginal;
        }

        protected ZipInputStream createZipInputStream() {
            return new ZipInputStream(new BufferedInputStream(this.asset.getOriginal().getStream()));
        }

        private void setRoot(Node root) {
            this.root = root;
        }

        private long updateNumBytes(long numBytes) {
            this.numBytes += numBytes;
            return this.numBytes;
        }

        private long updateNumFiles() {
            ++this.numFiles;
            return this.numFiles;
        }

        private void setTotalNumFiles(long totalNumFiles) {
            this.totalNumFiles = totalNumFiles;
        }

        private void setTotalNumBytes(long totalNumBytes) {
            this.totalNumBytes = totalNumBytes;
        }

        protected String getSkipFileNamePatterns() {
            return this.skipFileNamePatterns;
        }

        protected static enum UPDATE_MODE {
            OVERWRITE,
            UPDATE,
            NEW;
            

            private UPDATE_MODE() {
            }
        }

    }

}