1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.compress.archivers.sevenz; 18 19 /** 20 * Collects options for reading 7z archives. 21 * 22 * @since 1.19 23 * @Immutable 24 * @deprecated Use {@link SevenZFile.Builder}. 25 */ 26 @Deprecated 27 public class SevenZFileOptions { 28 29 /** 30 * Mutable builder for the immutable {@link SevenZFileOptions}. 31 * 32 * @since 1.19 33 */ 34 public static class Builder { 35 36 private int maxMemoryLimitKb = SevenZFile.Builder.MEMORY_LIMIT_IN_KB; 37 private boolean useDefaultNameForUnnamedEntries = SevenZFile.Builder.USE_DEFAULTNAME_FOR_UNNAMED_ENTRIES; 38 private boolean tryToRecoverBrokenArchives = SevenZFile.Builder.TRY_TO_RECOVER_BROKEN_ARCHIVES; 39 40 /** 41 * Builds the {@link SevenZFileOptions}. 42 * 43 * @return configured {@link SevenZFileOptions}. 44 */ 45 public SevenZFileOptions build() { 46 return new SevenZFileOptions(maxMemoryLimitKb, useDefaultNameForUnnamedEntries, tryToRecoverBrokenArchives); 47 } 48 49 /** 50 * Sets the maximum amount of memory to use for parsing the archive and during extraction. 51 * <p> 52 * Not all codecs will honor this setting. Currently only LZMA and LZMA2 are supported. 53 * </p> 54 * 55 * @param maxMemoryLimitKb limit of the maximum amount of memory to use 56 * @return the reconfigured builder 57 */ 58 public Builder withMaxMemoryLimitInKb(final int maxMemoryLimitKb) { 59 this.maxMemoryLimitKb = maxMemoryLimitKb; 60 return this; 61 } 62 63 /** 64 * Sets whether {@link SevenZFile} will try to recover broken archives where the CRC of the file's metadata is 0. 65 * <p> 66 * This special kind of broken archive is encountered when mutli volume archives are closed prematurely. If you enable this option SevenZFile will trust 67 * 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 68 * option without setting {@link #withMaxMemoryLimitInKb} at the same time. 69 * </p> 70 * 71 * @param tryToRecoverBrokenArchives if true SevenZFile will try to recover archives that are broken in the specific way 72 * @return the reconfigured builder 73 * @since 1.21 74 */ 75 public Builder withTryToRecoverBrokenArchives(final boolean tryToRecoverBrokenArchives) { 76 this.tryToRecoverBrokenArchives = tryToRecoverBrokenArchives; 77 return this; 78 } 79 80 /** 81 * Sets whether entries without a name should get their names set to the archive's default file name. 82 * 83 * @param useDefaultNameForUnnamedEntries if true the name of unnamed entries will be set to the archive's default name 84 * @return the reconfigured builder 85 */ 86 public Builder withUseDefaultNameForUnnamedEntries(final boolean useDefaultNameForUnnamedEntries) { 87 this.useDefaultNameForUnnamedEntries = useDefaultNameForUnnamedEntries; 88 return this; 89 } 90 } 91 92 /** 93 * The default options. 94 * <ul> 95 * <li>no memory limit</li> 96 * <li>don't modify the name of unnamed entries</li> 97 * </ul> 98 */ 99 public static final SevenZFileOptions DEFAULT = new SevenZFileOptions(SevenZFile.Builder.MEMORY_LIMIT_IN_KB, 100 SevenZFile.Builder.USE_DEFAULTNAME_FOR_UNNAMED_ENTRIES, SevenZFile.Builder.TRY_TO_RECOVER_BROKEN_ARCHIVES); 101 102 /** 103 * Obtains a builder for SevenZFileOptions. 104 * 105 * @return a builder for SevenZFileOptions. 106 */ 107 public static Builder builder() { 108 return new Builder(); 109 } 110 111 private final int maxMemoryLimitKb; 112 private final boolean useDefaultNameForUnnamedEntries; 113 private final boolean tryToRecoverBrokenArchives; 114 115 private SevenZFileOptions(final int maxMemoryLimitKb, final boolean useDefaultNameForUnnamedEntries, final boolean tryToRecoverBrokenArchives) { 116 this.maxMemoryLimitKb = maxMemoryLimitKb; 117 this.useDefaultNameForUnnamedEntries = useDefaultNameForUnnamedEntries; 118 this.tryToRecoverBrokenArchives = tryToRecoverBrokenArchives; 119 } 120 121 /** 122 * Gets the maximum amount of memory to use for parsing the archive and during extraction. 123 * <p> 124 * Not all codecs will honor this setting. Currently only LZMA and LZMA2 are supported. 125 * </p> 126 * 127 * @return the maximum amount of memory to use for extraction 128 */ 129 public int getMaxMemoryLimitInKb() { 130 return maxMemoryLimitKb; 131 } 132 133 /** 134 * Whether {@link SevenZFile} shall try to recover from a certain type of broken archive. 135 * 136 * @return whether SevenZFile shall try to recover from a certain type of broken archive. 137 * @since 1.21 138 */ 139 public boolean getTryToRecoverBrokenArchives() { 140 return tryToRecoverBrokenArchives; 141 } 142 143 /** 144 * Gets whether entries without a name should get their names set to the archive's default file name. 145 * 146 * @return whether entries without a name should get their names set to the archive's default file name 147 */ 148 public boolean getUseDefaultNameForUnnamedEntries() { 149 return useDefaultNameForUnnamedEntries; 150 } 151 }