001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * https://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.commons.compress.archivers.sevenz; 020 021/** 022 * Collects options for reading 7z archives. 023 * 024 * @since 1.19 025 * @Immutable 026 * @deprecated Use {@link SevenZFile.Builder}. 027 */ 028@Deprecated 029public class SevenZFileOptions { 030 031 /** 032 * Mutable builder for the immutable {@link SevenZFileOptions}. 033 * 034 * @since 1.19 035 */ 036 public static class Builder { 037 038 private int maxMemoryLimitKb = SevenZFile.Builder.MEMORY_LIMIT_IN_KB; 039 private boolean useDefaultNameForUnnamedEntries = SevenZFile.Builder.USE_DEFAULTNAME_FOR_UNNAMED_ENTRIES; 040 private boolean tryToRecoverBrokenArchives = SevenZFile.Builder.TRY_TO_RECOVER_BROKEN_ARCHIVES; 041 042 /** 043 * Builds the {@link SevenZFileOptions}. 044 * 045 * @return configured {@link SevenZFileOptions}. 046 */ 047 public SevenZFileOptions build() { 048 return new SevenZFileOptions(maxMemoryLimitKb, useDefaultNameForUnnamedEntries, tryToRecoverBrokenArchives); 049 } 050 051 /** 052 * Sets the maximum amount of memory to use for parsing the archive and during extraction. 053 * <p> 054 * Not all codecs will honor this setting. Currently only LZMA and LZMA2 are supported. 055 * </p> 056 * 057 * @param maxMemoryLimitKiB limit of the maximum amount of memory to use in kibibytes. 058 * @return the reconfigured builder 059 */ 060 public Builder withMaxMemoryLimitInKb(final int maxMemoryLimitKiB) { 061 this.maxMemoryLimitKb = maxMemoryLimitKiB; 062 return this; 063 } 064 065 /** 066 * Sets whether {@link SevenZFile} will try to recover broken archives where the CRC of the file's metadata is 0. 067 * <p> 068 * This special kind of broken archive is encountered when mutli volume archives are closed prematurely. If you enable this option SevenZFile will trust 069 * data that looks as if it could contain metadata of an archive and allocate big amounts of memory. It is strongly recommended to not enable this 070 * option without setting {@link #withMaxMemoryLimitInKb} at the same time. 071 * </p> 072 * 073 * @param tryToRecoverBrokenArchives if true SevenZFile will try to recover archives that are broken in the specific way 074 * @return the reconfigured builder 075 * @since 1.21 076 */ 077 public Builder withTryToRecoverBrokenArchives(final boolean tryToRecoverBrokenArchives) { 078 this.tryToRecoverBrokenArchives = tryToRecoverBrokenArchives; 079 return this; 080 } 081 082 /** 083 * Sets whether entries without a name should get their names set to the archive's default file name. 084 * 085 * @param useDefaultNameForUnnamedEntries if true the name of unnamed entries will be set to the archive's default name 086 * @return the reconfigured builder 087 */ 088 public Builder withUseDefaultNameForUnnamedEntries(final boolean useDefaultNameForUnnamedEntries) { 089 this.useDefaultNameForUnnamedEntries = useDefaultNameForUnnamedEntries; 090 return this; 091 } 092 } 093 094 /** 095 * The default options. 096 * <ul> 097 * <li>no memory limit</li> 098 * <li>don't modify the name of unnamed entries</li> 099 * </ul> 100 */ 101 public static final SevenZFileOptions DEFAULT = new SevenZFileOptions(SevenZFile.Builder.MEMORY_LIMIT_IN_KB, 102 SevenZFile.Builder.USE_DEFAULTNAME_FOR_UNNAMED_ENTRIES, SevenZFile.Builder.TRY_TO_RECOVER_BROKEN_ARCHIVES); 103 104 /** 105 * Obtains a builder for SevenZFileOptions. 106 * 107 * @return a builder for SevenZFileOptions. 108 */ 109 public static Builder builder() { 110 return new Builder(); 111 } 112 113 private final int maxMemoryLimitKiB; 114 private final boolean useDefaultNameForUnnamedEntries; 115 private final boolean tryToRecoverBrokenArchives; 116 117 private SevenZFileOptions(final int maxMemoryLimitKb, final boolean useDefaultNameForUnnamedEntries, final boolean tryToRecoverBrokenArchives) { 118 this.maxMemoryLimitKiB = maxMemoryLimitKb; 119 this.useDefaultNameForUnnamedEntries = useDefaultNameForUnnamedEntries; 120 this.tryToRecoverBrokenArchives = tryToRecoverBrokenArchives; 121 } 122 123 /** 124 * Gets the maximum amount of memory to use for parsing the archive and during extraction. 125 * <p> 126 * Not all codecs will honor this setting. Currently only LZMA and LZMA2 are supported. 127 * </p> 128 * 129 * @return the maximum amount of memory to use for extraction in kibibytes. 130 */ 131 public int getMaxMemoryLimitInKb() { 132 return maxMemoryLimitKiB; 133 } 134 135 /** 136 * Gets whether {@link SevenZFile} shall try to recover from a certain type of broken archive. 137 * 138 * @return whether SevenZFile shall try to recover from a certain type of broken archive. 139 * @since 1.21 140 */ 141 public boolean getTryToRecoverBrokenArchives() { 142 return tryToRecoverBrokenArchives; 143 } 144 145 /** 146 * Gets whether entries without a name should get their names set to the archive's default file name. 147 * 148 * @return whether entries without a name should get their names set to the archive's default file name 149 */ 150 public boolean getUseDefaultNameForUnnamedEntries() { 151 return useDefaultNameForUnnamedEntries; 152 } 153}