Code cleanups

This commit is contained in:
Goooler 2021-08-27 01:00:37 +08:00
parent 2cbefeb91d
commit 94ed86db28
47 changed files with 266 additions and 308 deletions

View File

@ -186,7 +186,7 @@ public class Main {
} catch (CantFindFrameworkResException ex) {
System.err
.println("Can't find framework resources for package of id: "
+ String.valueOf(ex.getPkgId())
+ ex.getPkgId()
+ ". You must install proper "
+ "framework files, see project website for more info.");
System.exit(1);
@ -509,17 +509,17 @@ public class Main {
listFrameworkOptions.addOption(frameIfDirOption);
// add all, loop existing cats then manually add advance
for (Object op : normalOptions.getOptions()) {
allOptions.addOption((Option)op);
for (Option op : normalOptions.getOptions()) {
allOptions.addOption(op);
}
for (Object op : DecodeOptions.getOptions()) {
allOptions.addOption((Option)op);
for (Option op : DecodeOptions.getOptions()) {
allOptions.addOption(op);
}
for (Object op : BuildOptions.getOptions()) {
allOptions.addOption((Option)op);
for (Option op : BuildOptions.getOptions()) {
allOptions.addOption(op);
}
for (Object op : frameOptions.getOptions()) {
allOptions.addOption((Option)op);
for (Option op : frameOptions.getOptions()) {
allOptions.addOption(op);
}
allOptions.addOption(apiLevelOption);
allOptions.addOption(analysisOption);
@ -561,7 +561,7 @@ public class Main {
if (isAdvanceMode()) {
System.out.println("Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0)\n");
}else {
System.out.println("");
System.out.println();
}
// 4 usage outputs (general, frameworks, decode, build)
@ -573,10 +573,8 @@ public class Main {
formatter.printHelp("apktool " + verbosityHelp() + "publicize-resources <file_path>", emptyOptions);
formatter.printHelp("apktool " + verbosityHelp() + "empty-framework-dir [options]", emptyFrameworkOptions);
formatter.printHelp("apktool " + verbosityHelp() + "list-frameworks [options]", listFrameworkOptions);
System.out.println("");
} else {
System.out.println("");
}
System.out.println();
// print out more information
System.out.println(

View File

@ -30,5 +30,5 @@ public interface XmlResourceParser extends XmlPullParser, AttributeSet {
* Close this interface to the resource. Calls on the interface are no
* longer value after this call.
*/
public void close();
void close();
}

View File

@ -26,7 +26,7 @@ public interface AttributeSet {
int getAttributeNameResource(int index);
int getAttributeListValue(int index, String options[], int defaultValue);
int getAttributeListValue(int index, String[] options, int defaultValue);
boolean getAttributeBooleanValue(int index, boolean defaultValue);
@ -49,7 +49,7 @@ public interface AttributeSet {
String getAttributeValue(String namespace, String attribute);
int getAttributeListValue(String namespace, String attribute,
String options[], int defaultValue);
String[] options, int defaultValue);
boolean getAttributeBooleanValue(String namespace, String attribute,
boolean defaultValue);

View File

@ -217,7 +217,7 @@ public class TypedValue {
private static final float MANTISSA_MULT = 1.0f / (1 << TypedValue.COMPLEX_MANTISSA_SHIFT);
private static final float[] RADIX_MULTS = new float[] {
1.0f * MANTISSA_MULT, 1.0f / (1 << 7) * MANTISSA_MULT,
MANTISSA_MULT, 1.0f / (1 << 7) * MANTISSA_MULT,
1.0f / (1 << 15) * MANTISSA_MULT, 1.0f / (1 << 23) * MANTISSA_MULT };
/**
@ -251,7 +251,7 @@ public class TypedValue {
* @return String The coerced string value. If the value is null or the type
* is not known, null is returned.
*/
public static final String coerceToString(int type, int data) {
public static String coerceToString(int type, int data) {
switch (type) {
case TYPE_NULL:
return null;
@ -262,11 +262,11 @@ public class TypedValue {
case TYPE_FLOAT:
return Float.toString(Float.intBitsToFloat(data));
case TYPE_DIMENSION:
return Float.toString(complexToFloat(data))
return complexToFloat(data)
+ DIMENSION_UNIT_STRS[(data >> COMPLEX_UNIT_SHIFT)
& COMPLEX_UNIT_MASK];
case TYPE_FRACTION:
return Float.toString(complexToFloat(data) * 100)
return complexToFloat(data) * 100
+ FRACTION_UNIT_STRS[(data >> COMPLEX_UNIT_SHIFT)
& COMPLEX_UNIT_MASK];
case TYPE_INT_HEX:
@ -286,22 +286,19 @@ public class TypedValue {
res = res.substring(2);
break;
case TYPE_INT_COLOR_ARGB4:// #AARRGGBB->#ARGB
res = new StringBuffer().append(vals[0]).append(vals[2])
.append(vals[4]).append(vals[6]).toString();
res = String.valueOf(vals[0]) + vals[2] +
vals[4] + vals[6];
break;
case TYPE_INT_COLOR_RGB4:// #FFRRGGBB->#RGB
res = new StringBuffer().append(vals[2]).append(vals[4])
.append(vals[6]).toString();
res = String.valueOf(vals[2]) + vals[4] +
vals[6];
break;
}
return "#" + res;
} else if (type >= TYPE_FIRST_INT && type <= TYPE_LAST_INT) {
String res;
switch (type) {
default:
case TYPE_INT_DEC:
res = Integer.toString(data);
break;
String res = null;
if (type == TYPE_INT_DEC) {
res = Integer.toString(data);
}
return res;
}

View File

@ -25,7 +25,6 @@ import brut.androlib.res.data.ResUnknownFiles;
import brut.common.InvalidUnknownFileException;
import brut.common.RootUnknownFileException;
import brut.common.TraversalUnknownFileException;
import brut.directory.ExtFile;
import brut.androlib.res.xml.ResXmlPatcher;
import brut.androlib.src.SmaliBuilder;
import brut.androlib.src.SmaliDecoder;
@ -48,7 +47,7 @@ import java.util.zip.ZipOutputStream;
public class Androlib {
private final AndrolibResources mAndRes = new AndrolibResources();
protected final ResUnknownFiles mResUnknownFiles = new ResUnknownFiles();
public ApkOptions apkOptions;
public final ApkOptions apkOptions;
private int mMinSdkVersion = 0;
public Androlib() {
@ -779,8 +778,8 @@ public class Androlib {
}
private boolean isModified(File[] working, File[] stored) {
for (int i = 0; i < stored.length; i++) {
if (!stored[i].exists()) {
for (File file : stored) {
if (!file.exists()) {
return true;
}
}

View File

@ -165,12 +165,10 @@ public class ApkDecoder {
mAndrolib.decodeRawFiles(mApkFile, outDir, mDecodeAssets);
mAndrolib.decodeUnknownFiles(mApkFile, outDir);
mUncompressedFiles = new ArrayList<String>();
mUncompressedFiles = new ArrayList<>();
mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles);
mAndrolib.writeOriginalFiles(mApkFile, outDir);
writeMetaFile();
} catch (Exception ex) {
throw ex;
} finally {
try {
mApkFile.close();

View File

@ -24,7 +24,7 @@ public class ApkOptions {
public boolean debugMode = false;
public boolean verbose = false;
public boolean copyOriginalFiles = false;
public boolean updateFiles = false;
public final boolean updateFiles = false;
public boolean isFramework = false;
public boolean resourcesAreCompressed = false;
public boolean useAapt2 = false;

View File

@ -29,7 +29,7 @@ public class StringExConstructor extends Constructor {
private class ConstructStringEx extends AbstractConstruct {
public Object construct(Node node) {
String val = (String) constructScalar((ScalarNode) node);
String val = constructScalar((ScalarNode) node);
return YamlStringEscapeUtils.unescapeString(val);
}
}

View File

@ -62,7 +62,7 @@ final public class AndrolibResources {
throws AndrolibException {
LOGGER.info("Loading resource table...");
ResPackage[] pkgs = getResPackagesFromApk(apkFile, resTable, sKeepBroken);
ResPackage pkg = null;
ResPackage pkg;
switch (pkgs.length) {
case 1:
@ -71,14 +71,11 @@ final public class AndrolibResources {
case 2:
if (pkgs[0].getName().equals("android")) {
LOGGER.warning("Skipping \"android\" package group");
pkg = pkgs[1];
break;
} else if (pkgs[0].getName().equals("com.htc")) {
LOGGER.warning("Skipping \"htc\" package group");
pkg = pkgs[1];
break;
}
pkg = pkgs[1];
break;
default:
pkg = selectPkgWithMostResSpecs(pkgs);
break;
@ -128,7 +125,7 @@ final public class AndrolibResources {
}
if (pkg.getId() != id) {
throw new AndrolibException("Expected pkg of id: " + String.valueOf(id) + ", got: " + pkg.getId());
throw new AndrolibException("Expected pkg of id: " + id + ", got: " + pkg.getId());
}
resTable.addPackage(pkg, false);
@ -619,7 +616,7 @@ final public class AndrolibResources {
String aaptPath = apkOptions.aaptPath;
boolean customAapt = !aaptPath.isEmpty();
List<String> cmd = new ArrayList<String>();
List<String> cmd = new ArrayList<>();
try {
String aaptCommand = AaptManager.getAaptExecutionCommand(aaptPath, getAaptBinaryFile());
@ -705,7 +702,7 @@ final public class AndrolibResources {
axmlParser.setAttrDecoder(new ResAttrDecoder());
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()));
return new Duo<ResFileDecoder, AXmlResourceParser>(new ResFileDecoder(decoders), axmlParser);
return new Duo<>(new ResFileDecoder(decoders), axmlParser);
}
public Duo<ResFileDecoder, AXmlResourceParser> getManifestFileDecoder(boolean withResources) {
@ -717,7 +714,7 @@ final public class AndrolibResources {
}
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser,getResXmlSerializer()));
return new Duo<ResFileDecoder, AXmlResourceParser>(new ResFileDecoder(decoders), axmlParser);
return new Duo<>(new ResFileDecoder(decoders), axmlParser);
}
public ExtMXSerializer getResXmlSerializer() {
@ -783,15 +780,10 @@ final public class AndrolibResources {
throws AndrolibException {
try {
Directory dir = apkFile.getDirectory();
BufferedInputStream bfi = new BufferedInputStream(dir.getFileInput("resources.arsc"));
try {
try (BufferedInputStream bfi = new BufferedInputStream(dir.getFileInput("resources.arsc"))) {
return ARSCDecoder.decode(bfi, false, keepBroken, resTable).getPackages();
} finally {
try {
bfi.close();
} catch (IOException ignored) {}
}
} catch (DirectoryException ex) {
} catch (DirectoryException | IOException ex) {
throw new AndrolibException("Could not load resources.arsc from file: " + apkFile, ex);
}
}
@ -808,7 +800,7 @@ final public class AndrolibResources {
}
}
apk = new File(dir, String.valueOf(id) + ".apk");
apk = new File(dir, id + ".apk");
if (apk.exists()) {
return apk;
}
@ -888,8 +880,8 @@ final public class AndrolibResources {
ARSCData arsc = ARSCDecoder.decode(new ByteArrayInputStream(data), true, true);
publicizeResources(data, arsc.getFlagsOffsets());
File outFile = new File(getFrameworkDir(), String.valueOf(arsc
.getOnePackage().getId())
File outFile = new File(getFrameworkDir(), arsc
.getOnePackage().getId()
+ (tag == null ? "" : '-' + tag)
+ ".apk");

View File

@ -59,9 +59,6 @@ public class ResID {
return false;
}
final ResID other = (ResID) obj;
if (this.id != other.id) {
return false;
}
return true;
return this.id == other.id;
}
}

View File

@ -29,10 +29,10 @@ public class ResPackage {
private final ResTable mResTable;
private final int mId;
private final String mName;
private final Map<ResID, ResResSpec> mResSpecs = new LinkedHashMap<ResID, ResResSpec>();
private final Map<ResConfigFlags, ResType> mConfigs = new LinkedHashMap<ResConfigFlags, ResType>();
private final Map<String, ResTypeSpec> mTypes = new LinkedHashMap<String, ResTypeSpec>();
private final Set<ResID> mSynthesizedRes = new HashSet<ResID>();
private final Map<ResID, ResResSpec> mResSpecs = new LinkedHashMap<>();
private final Map<ResConfigFlags, ResType> mConfigs = new LinkedHashMap<>();
private final Map<String, ResTypeSpec> mTypes = new LinkedHashMap<>();
private final Set<ResID> mSynthesizedRes = new HashSet<>();
private ResValueFactory mValueFactory;
@ -43,7 +43,7 @@ public class ResPackage {
}
public List<ResResSpec> listResSpecs() {
return new ArrayList<ResResSpec>(mResSpecs.values());
return new ArrayList<>(mResSpecs.values());
}
public boolean hasResSpec(ResID resID) {
@ -80,7 +80,7 @@ public class ResPackage {
}
public Set<ResResource> listFiles() {
Set<ResResource> ret = new HashSet<ResResource>();
Set<ResResource> ret = new HashSet<>();
for (ResResSpec spec : mResSpecs.values()) {
for (ResResource res : spec.listResources()) {
if (res.getValue() instanceof ResFileValue) {
@ -92,13 +92,13 @@ public class ResPackage {
}
public Collection<ResValuesFile> listValuesFiles() {
Map<Duo<ResTypeSpec, ResType>, ResValuesFile> ret = new HashMap<Duo<ResTypeSpec, ResType>, ResValuesFile>();
Map<Duo<ResTypeSpec, ResType>, ResValuesFile> ret = new HashMap<>();
for (ResResSpec spec : mResSpecs.values()) {
for (ResResource res : spec.listResources()) {
if (res.getValue() instanceof ResValuesXmlSerializable) {
ResTypeSpec type = res.getResSpec().getType();
ResType config = res.getConfig();
Duo<ResTypeSpec, ResType> key = new Duo<ResTypeSpec, ResType>(type, config);
Duo<ResTypeSpec, ResType> key = new Duo<>(type, config);
ResValuesFile values = ret.get(key);
if (values == null) {
values = new ResValuesFile(this, type, config);
@ -163,13 +163,10 @@ public class ResPackage {
return false;
}
final ResPackage other = (ResPackage) obj;
if (this.mResTable != other.mResTable && (this.mResTable == null || !this.mResTable.equals(other.mResTable))) {
if (!Objects.equals(this.mResTable, other.mResTable)) {
return false;
}
if (this.mId != other.mId) {
return false;
}
return true;
return this.mId == other.mId;
}
@Override

View File

@ -30,7 +30,7 @@ public class ResResSpec {
private final String mName;
private final ResPackage mPackage;
private final ResTypeSpec mType;
private final Map<ResConfigFlags, ResResource> mResources = new LinkedHashMap<ResConfigFlags, ResResource>();
private final Map<ResConfigFlags, ResResource> mResources = new LinkedHashMap<>();
public ResResSpec(ResID id, String name, ResPackage pkg, ResTypeSpec type) {
this.mId = id;
@ -38,7 +38,7 @@ public class ResResSpec {
ResResSpec resResSpec = type.getResSpecUnsafe(name);
if (resResSpec != null) {
cleanName = String.format("APKTOOL_DUPLICATE_%s_%s", type.toString(), id.toString());
cleanName = String.format("APKTOOL_DUPLICATE_%s_%s", type, id.toString());
} else {
cleanName = ((name == null || name.isEmpty()) ? ("APKTOOL_DUMMYVAL_" + id.toString()) : name);
}
@ -49,7 +49,7 @@ public class ResResSpec {
}
public Set<ResResource> listResources() {
return new LinkedHashSet<ResResource>(mResources.values());
return new LinkedHashSet<>(mResources.values());
}
public ResResource getResource(ResType config) throws AndrolibException {

View File

@ -26,10 +26,10 @@ import java.util.*;
public class ResTable {
private final AndrolibResources mAndRes;
private final Map<Integer, ResPackage> mPackagesById = new HashMap<Integer, ResPackage>();
private final Map<String, ResPackage> mPackagesByName = new HashMap<String, ResPackage>();
private final Set<ResPackage> mMainPackages = new LinkedHashSet<ResPackage>();
private final Set<ResPackage> mFramePackages = new LinkedHashSet<ResPackage>();
private final Map<Integer, ResPackage> mPackagesById = new HashMap<>();
private final Map<String, ResPackage> mPackagesByName = new HashMap<>();
private final Set<ResPackage> mMainPackages = new LinkedHashSet<>();
private final Set<ResPackage> mFramePackages = new LinkedHashSet<>();
private String mPackageRenamed;
private String mPackageOriginal;
@ -38,8 +38,8 @@ public class ResTable {
private boolean mSharedLibrary = false;
private boolean mSparseResources = false;
private Map<String, String> mSdkInfo = new LinkedHashMap<>();
private VersionInfo mVersionInfo = new VersionInfo();
private final Map<String, String> mSdkInfo = new LinkedHashMap<>();
private final VersionInfo mVersionInfo = new VersionInfo();
public ResTable() {
mAndRes = null;
@ -124,7 +124,7 @@ public class ResTable {
public void addPackage(ResPackage pkg, boolean main) throws AndrolibException {
Integer id = pkg.getId();
if (mPackagesById.containsKey(id)) {
throw new AndrolibException("Multiple packages: id=" + id.toString());
throw new AndrolibException("Multiple packages: id=" + id);
}
String name = pkg.getName();
if (mPackagesByName.containsKey(name)) {

View File

@ -22,7 +22,7 @@ import java.util.*;
public class ResType {
private final ResConfigFlags mFlags;
private final Map<ResResSpec, ResResource> mResources = new LinkedHashMap<ResResSpec, ResResource>();
private final Map<ResResSpec, ResResource> mResources = new LinkedHashMap<>();
public ResType(ResConfigFlags flags) {
this.mFlags = flags;

View File

@ -28,7 +28,7 @@ public final class ResTypeSpec {
public static final String RES_TYPE_NAME_ATTR = "attr";
private final String mName;
private final Map<String, ResResSpec> mResSpecs = new LinkedHashMap<String, ResResSpec>();
private final Map<String, ResResSpec> mResSpecs = new LinkedHashMap<>();
private final ResTable mResTable;
private final ResPackage mPackage;

View File

@ -17,13 +17,14 @@
package brut.androlib.res.data;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
public class ResValuesFile {
private final ResPackage mPackage;
private final ResTypeSpec mType;
private final ResType mConfig;
private final Set<ResResource> mResources = new LinkedHashSet<ResResource>();
private final Set<ResResource> mResources = new LinkedHashSet<>();
public ResValuesFile(ResPackage pkg, ResTypeSpec type, ResType config) {
this.mPackage = pkg;
@ -62,13 +63,10 @@ public class ResValuesFile {
return false;
}
final ResValuesFile other = (ResValuesFile) obj;
if (this.mType != other.mType && (this.mType == null || !this.mType.equals(other.mType))) {
if (!Objects.equals(this.mType, other.mType)) {
return false;
}
if (this.mConfig != other.mConfig && (this.mConfig == null || !this.mConfig.equals(other.mConfig))) {
return false;
}
return true;
return Objects.equals(this.mConfig, other.mConfig);
}
@Override

View File

@ -51,17 +51,17 @@ public class ResArrayValue extends ResBagValue implements
serializer.attribute(null, "name", res.getResSpec().getName());
// lets check if we need to add formatted="false" to this array
for (int i = 0; i < mItems.length; i++) {
if (mItems[i].hasMultipleNonPositionalSubstitutions()) {
for (ResScalarValue item : mItems) {
if (item.hasMultipleNonPositionalSubstitutions()) {
serializer.attribute(null, "formatted", "false");
break;
}
}
// add <item>'s
for (int i = 0; i < mItems.length; i++) {
for (ResScalarValue mItem : mItems) {
serializer.startTag(null, "item");
serializer.text(mItems[i].encodeAsResXmlNonEscapedItemValue());
serializer.text(mItem.encodeAsResXmlNonEscapedItemValue());
serializer.endTag(null, "item");
}
serializer.endTag(null, type);
@ -72,16 +72,16 @@ public class ResArrayValue extends ResBagValue implements
return null;
}
String type = mItems[0].getType();
for (int i = 0; i < mItems.length; i++) {
if (mItems[i].encodeAsResXmlItemValue().startsWith("@string")) {
for (ResScalarValue mItem : mItems) {
if (mItem.encodeAsResXmlItemValue().startsWith("@string")) {
return "string";
} else if (mItems[i].encodeAsResXmlItemValue().startsWith("@drawable")) {
} else if (mItem.encodeAsResXmlItemValue().startsWith("@drawable")) {
return null;
} else if (mItems[i].encodeAsResXmlItemValue().startsWith("@integer")) {
} else if (mItem.encodeAsResXmlItemValue().startsWith("@integer")) {
return "integer";
} else if (!"string".equals(type) && !"integer".equals(type)) {
return null;
} else if (!type.equals(mItems[i].getType())) {
} else if (!type.equals(mItem.getType())) {
return null;
}
}

View File

@ -96,9 +96,9 @@ public class ResAttr extends ResBagValue implements ResValuesXmlSerializable {
for (; i < items.length; i++) {
int resId = items[i].m1;
pkg.addSynthesizedRes(resId);
attrItems[j++] = new Duo<ResReferenceValue, ResIntValue>(
factory.newReference(resId, null),
(ResIntValue) items[i].m2);
attrItems[j++] = new Duo<>(
factory.newReference(resId, null),
(ResIntValue) items[i].m2);
}
switch (type & 0xff0000) {
case TYPE_ENUM:

View File

@ -80,5 +80,5 @@ public class ResEnumAttr extends ResAttr {
}
private final Duo<ResReferenceValue, ResIntValue>[] mItems;
private final Map<Integer, String> mItemsCache = new HashMap<Integer, String>();
private final Map<Integer, String> mItemsCache = new HashMap<>();
}

View File

@ -23,7 +23,6 @@ import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
public class ResFlagsAttr extends ResAttr {
ResFlagsAttr(ResReferenceValue parent, int type, Integer min, Integer max,
@ -55,8 +54,7 @@ public class ResFlagsAttr extends ResAttr {
FlagItem[] flagItems = new FlagItem[mFlags.length];
int[] flags = new int[mFlags.length];
int flagsCount = 0;
for (int i = 0; i < mFlags.length; i++) {
FlagItem flagItem = mFlags[i];
for (FlagItem flagItem : mFlags) {
int flag = flagItem.flag;
if ((intVal & flag) != flag) {
@ -74,20 +72,18 @@ public class ResFlagsAttr extends ResAttr {
@Override
protected void serializeBody(XmlSerializer serializer, ResResource res)
throws AndrolibException, IOException {
for (int i = 0; i < mItems.length; i++) {
FlagItem item = mItems[i];
for (FlagItem item : mItems) {
serializer.startTag(null, "flag");
serializer.attribute(null, "name", item.getValue());
serializer.attribute(null, "value",
String.format("0x%08x", item.flag));
String.format("0x%08x", item.flag));
serializer.endTag(null, "flag");
}
}
private boolean isSubpartOf(int flag, int[] flags) {
for (int i = 0; i < flags.length; i++) {
if ((flags[i] & flag) == flag) {
for (int j : flags) {
if ((j & flag) == flag) {
return true;
}
}
@ -95,12 +91,12 @@ public class ResFlagsAttr extends ResAttr {
}
private String renderFlags(FlagItem[] flags) throws AndrolibException {
String ret = "";
for (int i = 0; i < flags.length; i++) {
ret += "|" + flags[i].getValue();
StringBuilder ret = new StringBuilder();
for (FlagItem flag : flags) {
ret.append("|").append(flag.getValue());
}
if (ret.isEmpty()) {
return ret;
if (ret.length() == 0) {
return ret.toString();
}
return ret.substring(1);
}
@ -115,8 +111,7 @@ public class ResFlagsAttr extends ResAttr {
FlagItem[] flags = new FlagItem[mItems.length];
int flagsCount = 0;
for (int i = 0; i < mItems.length; i++) {
FlagItem item = mItems[i];
for (FlagItem item : mItems) {
if (item.flag == 0) {
zeroFlags[zeroFlagsCount++] = item;
} else {
@ -127,13 +122,7 @@ public class ResFlagsAttr extends ResAttr {
mZeroFlags = Arrays.copyOf(zeroFlags, zeroFlagsCount);
mFlags = Arrays.copyOf(flags, flagsCount);
Arrays.sort(mFlags, new Comparator<FlagItem>() {
@Override
public int compare(FlagItem o1, FlagItem o2) {
return Integer.valueOf(Integer.bitCount(o2.flag)).compareTo(
Integer.bitCount(o1.flag));
}
});
Arrays.sort(mFlags, (o1, o2) -> Integer.compare(Integer.bitCount(o2.flag), Integer.bitCount(o1.flag)));
}
private final FlagItem[] mItems;

View File

@ -32,8 +32,8 @@ public class ResPluralsValue extends ResBagValue implements
super(parent);
mItems = new ResScalarValue[6];
for (int i = 0; i < items.length; i++) {
mItems[items[i].m1 - BAG_KEY_PLURALS_START] = items[i].m2;
for (Duo<Integer, ResScalarValue> item : items) {
mItems[item.m1 - BAG_KEY_PLURALS_START] = item.m2;
}
}

View File

@ -34,8 +34,8 @@ public class ResStyleValue extends ResBagValue implements
mItems = new Duo[items.length];
for (int i = 0; i < items.length; i++) {
mItems[i] = new Duo<ResReferenceValue, ResScalarValue>(
factory.newReference(items[i].m1, null), items[i].m2);
mItems[i] = new Duo<>(
factory.newReference(items[i].m1, null), items[i].m2);
}
}
@ -49,16 +49,16 @@ public class ResStyleValue extends ResBagValue implements
} else if (res.getResSpec().getName().indexOf('.') != -1) {
serializer.attribute(null, "parent", "");
}
for (int i = 0; i < mItems.length; i++) {
ResResSpec spec = mItems[i].m1.getReferent();
for (Duo<ResReferenceValue, ResScalarValue> mItem : mItems) {
ResResSpec spec = mItem.m1.getReferent();
if (spec == null) {
LOGGER.fine(String.format("null reference: m1=0x%08x(%s), m2=0x%08x(%s)",
mItems[i].m1.getRawIntValue(), mItems[i].m1.getType(), mItems[i].m2.getRawIntValue(), mItems[i].m2.getType()));
mItem.m1.getRawIntValue(), mItem.m1.getType(), mItem.m2.getRawIntValue(), mItem.m2.getType()));
continue;
}
String name = null;
String name;
String value = null;
ResValue resource = spec.getDefaultResource().getValue();
@ -66,14 +66,14 @@ public class ResStyleValue extends ResBagValue implements
continue;
} else if (resource instanceof ResAttr) {
ResAttr attr = (ResAttr) resource;
value = attr.convertToResXmlFormat(mItems[i].m2);
value = attr.convertToResXmlFormat(mItem.m2);
name = spec.getFullName(res.getResSpec().getPackage(), true);
} else {
name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
}
if (value == null) {
value = mItems[i].m2.encodeAsResXmlValue();
value = mItem.m2.encodeAsResXmlValue();
}
if (value == null) {

View File

@ -59,7 +59,7 @@ public class ARSCDecoder {
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) {
arscStream = mCountIn = new CountingInputStream(arscStream);
if (storeFlagsOffsets) {
mFlagsOffsets = new ArrayList<FlagsOffset>();
mFlagsOffsets = new ArrayList<>();
} else {
mFlagsOffsets = null;
}
@ -251,7 +251,7 @@ public class ARSCDecoder {
}
mType = flags.isInvalid && !mKeepBroken ? null : mPkg.getOrCreateConfig(flags);
HashMap<Integer, EntryData> offsetsToEntryData = new HashMap<Integer, EntryData>();
HashMap<Integer, EntryData> offsetsToEntryData = new HashMap<>();
for (int offset : entryOffsets) {
if (offset == -1 || offsetsToEntryData.containsKey(offset)) {
@ -327,7 +327,7 @@ public class ARSCDecoder {
if (mKeepBroken) {
mType.addResource(res, true);
spec.addResource(res, true);
LOGGER.warning(String.format("Duplicate Resource Detected. Ignoring duplicate: %s", res.toString()));
LOGGER.warning(String.format("Duplicate Resource Detected. Ignoring duplicate: %s", res));
} else {
throw ex;
}
@ -347,12 +347,10 @@ public class ARSCDecoder {
resId = mIn.readInt();
resValue = readValue();
if (resValue instanceof ResScalarValue) {
items[i] = new Duo<Integer, ResScalarValue>(resId, (ResScalarValue) resValue);
} else {
if (!(resValue instanceof ResScalarValue)) {
resValue = new ResStringValue(resValue.toString(), resValue.getRawIntValue());
items[i] = new Duo<Integer, ResScalarValue>(resId, (ResScalarValue) resValue);
}
items[i] = new Duo<>(resId, (ResScalarValue) resValue);
}
return factory.bagFactory(parent, items, mTypeSpec);
@ -574,7 +572,7 @@ public class ARSCDecoder {
private int mResId;
private int mTypeIdOffset = 0;
private boolean[] mMissingResSpecs;
private HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>();
private final HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>();
private final static short ENTRY_FLAG_COMPLEX = 0x0001;
private final static short ENTRY_FLAG_PUBLIC = 0x0002;

View File

@ -345,7 +345,7 @@ public class AXmlResourceParser implements XmlResourceParser {
if (resourceId != 0) {
value = mAttrDecoder.decodeManifestAttr(getAttributeNameResource(index));
}
} catch (AndrolibException | NullPointerException e) { }
} catch (AndrolibException | NullPointerException ignored) {}
}
return value;
}
@ -601,12 +601,12 @@ public class AXmlResourceParser implements XmlResourceParser {
m_data = new int[32];
}
public final void reset() {
public void reset() {
m_dataLength = 0;
m_depth = 0;
}
public final int getCurrentCount() {
public int getCurrentCount() {
if (m_dataLength == 0) {
return 0;
}
@ -614,7 +614,7 @@ public class AXmlResourceParser implements XmlResourceParser {
return m_data[offset];
}
public final int getAccumulatedCount(int depth) {
public int getAccumulatedCount(int depth) {
if (m_dataLength == 0 || depth < 0) {
return 0;
}
@ -631,7 +631,7 @@ public class AXmlResourceParser implements XmlResourceParser {
return accumulatedCount;
}
public final void push(int prefix, int uri) {
public void push(int prefix, int uri) {
if (m_depth == 0) {
increaseDepth();
}
@ -645,7 +645,7 @@ public class AXmlResourceParser implements XmlResourceParser {
m_dataLength += 2;
}
public final boolean pop() {
public boolean pop() {
if (m_dataLength == 0) {
return false;
}
@ -663,23 +663,23 @@ public class AXmlResourceParser implements XmlResourceParser {
return true;
}
public final int getPrefix(int index) {
public int getPrefix(int index) {
return get(index, true);
}
public final int getUri(int index) {
public int getUri(int index) {
return get(index, false);
}
public final int findPrefix(int uri) {
public int findPrefix(int uri) {
return find(uri, false);
}
public final int getDepth() {
public int getDepth() {
return m_depth;
}
public final void increaseDepth() {
public void increaseDepth() {
ensureDataCapacity(2);
int offset = m_dataLength;
m_data[offset] = 0;
@ -688,7 +688,7 @@ public class AXmlResourceParser implements XmlResourceParser {
m_depth += 1;
}
public final void decreaseDepth() {
public void decreaseDepth() {
if (m_dataLength == 0) {
return;
}
@ -712,7 +712,7 @@ public class AXmlResourceParser implements XmlResourceParser {
m_data = newData;
}
private final int find(int prefixOrUri, boolean prefix) {
private int find(int prefixOrUri, boolean prefix) {
if (m_dataLength == 0) {
return -1;
}
@ -736,7 +736,7 @@ public class AXmlResourceParser implements XmlResourceParser {
return -1;
}
private final int get(int index, boolean prefix) {
private int get(int index, boolean prefix) {
if (m_dataLength == 0 || index < 0) {
return -1;
}
@ -762,7 +762,7 @@ public class AXmlResourceParser implements XmlResourceParser {
private int m_depth;
}
private final int getAttributeOffset(int index) {
private int getAttributeOffset(int index) {
if (m_event != START_TAG) {
throw new IndexOutOfBoundsException("Current event is not START_TAG.");
}
@ -773,7 +773,7 @@ public class AXmlResourceParser implements XmlResourceParser {
return offset;
}
private final int findAttribute(String namespace, String attribute) {
private int findAttribute(String namespace, String attribute) {
if (m_strings == null || attribute == null) {
return -1;
}
@ -791,7 +791,7 @@ public class AXmlResourceParser implements XmlResourceParser {
return -1;
}
private final void resetEventInfo() {
private void resetEventInfo() {
m_event = -1;
m_lineNumber = -1;
m_name = -1;
@ -802,7 +802,7 @@ public class AXmlResourceParser implements XmlResourceParser {
m_styleAttribute = -1;
}
private final void doNext() throws IOException {
private void doNext() throws IOException {
// Delayed initialization.
if (m_strings == null) {
m_reader.skipCheckInt(CHUNK_AXML_FILE, CHUNK_AXML_FILE_BROKEN);
@ -938,7 +938,7 @@ public class AXmlResourceParser implements XmlResourceParser {
private boolean m_operational = false;
private StringBlock m_strings;
private int[] m_resourceIDs;
private NamespaceStack m_namespaces = new NamespaceStack();
private final NamespaceStack m_namespaces = new NamespaceStack();
private final String android_ns = "http://schemas.android.com/apk/res/android";
private boolean m_decreaseDepth;
private int m_event;

View File

@ -111,14 +111,12 @@ public class Res9patchStreamDecoder implements ResStreamDecoder {
}
ImageIO.write(im2, "png", out);
} catch (IOException ex) {
} catch (IOException | NullPointerException ex) {
throw new AndrolibException(ex);
} catch (NullPointerException ex) {
// In my case this was triggered because a .png file was
// containing a html document instead of an image.
// This could be more verbose and try to MIME ?
throw new AndrolibException(ex);
}
} // In my case this was triggered because a .png file was
// containing a html document instead of an image.
// This could be more verbose and try to MIME ?
}
private NinePatch getNinePatch(byte[] data) throws AndrolibException,

View File

@ -21,6 +21,6 @@ import java.io.InputStream;
import java.io.OutputStream;
public interface ResStreamDecoder {
public void decode(InputStream in, OutputStream out)
void decode(InputStream in, OutputStream out)
throws AndrolibException;
}

View File

@ -23,7 +23,7 @@ import java.util.HashMap;
import java.util.Map;
public class ResStreamDecoderContainer {
private final Map<String, ResStreamDecoder> mDecoders = new HashMap<String, ResStreamDecoder>();
private final Map<String, ResStreamDecoder> mDecoders = new HashMap<>();
public void decode(InputStream in, OutputStream out, String decoderName)
throws AndrolibException {

View File

@ -177,7 +177,7 @@ public class StringBlock {
if (pos == -1) {
builder.append(tag);
} else {
builder.append(tag.substring(0, pos));
builder.append(tag, 0, pos);
if (!close) {
boolean loop = true;
while (loop) {
@ -187,7 +187,7 @@ public class StringBlock {
// prematurely end style tags, if recreation
// cannot be created.
if (pos2 != -1) {
builder.append(' ').append(tag.substring(pos + 1, pos2)).append("=\"");
builder.append(' ').append(tag, pos + 1, pos2).append("=\"");
pos = tag.indexOf(';', pos2 + 1);
String val;
@ -305,11 +305,11 @@ public class StringBlock {
}
}
private static final int getShort(byte[] array, int offset) {
private static int getShort(byte[] array, int offset) {
return (array[offset + 1] & 0xff) << 8 | array[offset] & 0xff;
}
private static final int[] getUtf8(byte[] array, int offset) {
private static int[] getUtf8(byte[] array, int offset) {
int val = array[offset];
int length;
// We skip the utf16 length of the string
@ -331,7 +331,7 @@ public class StringBlock {
return new int[] { offset, length};
}
private static final int[] getUtf16(byte[] array, int offset) {
private static int[] getUtf16(byte[] array, int offset) {
int val = ((array[offset + 1] & 0xFF) << 8 | array[offset] & 0xFF);
if ((val & 0x8000) != 0) {
@ -350,8 +350,8 @@ public class StringBlock {
private int[] m_styles;
private boolean m_isUTF8;
private final CharsetDecoder UTF16LE_DECODER = Charset.forName("UTF-16LE").newDecoder();
private final CharsetDecoder UTF8_DECODER = Charset.forName("UTF-8").newDecoder();
private final CharsetDecoder UTF16LE_DECODER = StandardCharsets.UTF_16LE.newDecoder();
private final CharsetDecoder UTF8_DECODER = StandardCharsets.UTF_8.newDecoder();
private final CharsetDecoder CESU8_DECODER = Charset.forName("CESU8").newDecoder();
private static final Logger LOGGER = Logger.getLogger(StringBlock.class.getName());

View File

@ -22,11 +22,11 @@ import java.io.IOException;
public interface ExtXmlSerializer extends XmlSerializer {
public ExtXmlSerializer newLine() throws IOException;
ExtXmlSerializer newLine() throws IOException;
public void setDisabledAttrEscape(boolean disabled);
void setDisabledAttrEscape(boolean disabled);
public static final String PROPERTY_SERIALIZER_INDENTATION = "http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
public static final String PROPERTY_SERIALIZER_LINE_SEPARATOR = "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator";
public static final String PROPERTY_DEFAULT_ENCODING = "DEFAULT_ENCODING";
String PROPERTY_SERIALIZER_INDENTATION = "http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
String PROPERTY_SERIALIZER_LINE_SEPARATOR = "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator";
String PROPERTY_DEFAULT_ENCODING = "DEFAULT_ENCODING";
}

View File

@ -23,6 +23,6 @@ import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
public interface ResValuesXmlSerializable {
public void serializeToResValuesXml(XmlSerializer serializer,
ResResource res) throws IOException, AndrolibException;
void serializeToResValuesXml(XmlSerializer serializer,
ResResource res) throws IOException, AndrolibException;
}

View File

@ -19,7 +19,7 @@ package brut.androlib.res.xml;
import brut.androlib.AndrolibException;
public interface ResXmlEncodable {
public String encodeAsResXmlAttr() throws AndrolibException;
String encodeAsResXmlAttr() throws AndrolibException;
public String encodeAsResXmlValue() throws AndrolibException;
String encodeAsResXmlValue() throws AndrolibException;
}

View File

@ -102,15 +102,13 @@ public final class ResXmlEncoders {
wasSpace = false;
switch (c) {
case '\\':
case '"':
out.append('\\');
break;
case '\'':
case '\n':
enclose = true;
break;
case '"':
out.append('\\');
break;
case '<':
isInStyleTag = true;
if (enclose) {
@ -154,7 +152,7 @@ public final class ResXmlEncoders {
int pos = 0;
int count = 0;
for (Integer sub : subs) {
out.append(str.substring(pos, ++sub)).append(++count).append('$');
out.append(str, pos, ++sub).append(++count).append('$');
pos = sub;
}
out.append(str.substring(pos));

View File

@ -324,11 +324,8 @@ public final class ResXmlPatcher {
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// Not using the parse(File) method on purpose, so that we can control when
// to close it. Somehow parse(File) does not seem to close the file in all cases.
FileInputStream inputStream = new FileInputStream(file);
try {
return docBuilder.parse(inputStream);
} finally {
inputStream.close();
try (FileInputStream inputStream = new FileInputStream(file)) {
return docBuilder.parse(inputStream);
}
}

View File

@ -69,15 +69,15 @@ public class MXSerializer implements XmlSerializer {
protected int depth = 0;
// element stack
protected String elNamespace[] = new String[2];
protected String elName[] = new String[elNamespace.length];
protected String elPrefix[] = new String[elNamespace.length];
protected int elNamespaceCount[] = new int[elNamespace.length];
protected String[] elNamespace = new String[2];
protected String[] elName = new String[elNamespace.length];
protected String[] elPrefix = new String[elNamespace.length];
protected int[] elNamespaceCount = new int[elNamespace.length];
// namespace stack
protected int namespaceEnd = 0;
protected String namespacePrefix[] = new String[8];
protected String namespaceUri[] = new String[namespacePrefix.length];
protected String[] namespacePrefix = new String[8];
protected String[] namespaceUri = new String[namespacePrefix.length];
protected boolean finished;
protected boolean pastRoot;
@ -92,9 +92,9 @@ public class MXSerializer implements XmlSerializer {
// buffer output if needed to write escaped String see text(String)
private static final int BUF_LEN = Runtime.getRuntime().freeMemory() > 1000000L ? 8 * 1024 : 256;
protected char buf[] = new char[BUF_LEN];
protected char[] buf = new char[BUF_LEN];
protected static final String precomputedPrefixes[];
protected static final String[] precomputedPrefixes;
static {
precomputedPrefixes = new String[32]; // arbitrary number ...
@ -103,7 +103,7 @@ public class MXSerializer implements XmlSerializer {
}
}
private boolean checkNamesInterned = false;
private final boolean checkNamesInterned = false;
private void checkInterning(String name) {
if (namesInterned && name != name.intern()) {
@ -157,7 +157,7 @@ public class MXSerializer implements XmlSerializer {
+ elStackSize + " ==> " + newSize);
}
final boolean needsCopying = elStackSize > 0;
String[] arr = null;
String[] arr;
// reuse arr local variable slot
arr = new String[newSize];
if (needsCopying)
@ -242,7 +242,7 @@ public class MXSerializer implements XmlSerializer {
* requested chnages.
*/
protected void rebuildIndentationBuf() {
if (doIndent == false)
if (!doIndent)
return;
final int maxIndent = 65; // hardcoded maximum indentation size in characters
int bufSize = 0;
@ -277,7 +277,7 @@ public class MXSerializer implements XmlSerializer {
protected void writeIndent() throws IOException {
final int start = writeLineSepartor ? 0 : offsetNewLine;
final int level = (depth > maxIndentLevel) ? maxIndentLevel : depth;
final int level = Math.min(depth, maxIndentLevel);
out.write(indentationBuf, start, ((level - 1) * indentationJump) + offsetNewLine);
}
@ -288,15 +288,19 @@ public class MXSerializer implements XmlSerializer {
if (name == null) {
throw new IllegalArgumentException("property name can not be null");
}
if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
indentationString = (String) value;
} else if (PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) {
lineSeparator = (String) value;
} else if (PROPERTY_LOCATION.equals(name)) {
location = (String) value;
} else {
throw new IllegalStateException("unsupported property " + name);
}
switch (name) {
case PROPERTY_SERIALIZER_INDENTATION:
indentationString = (String) value;
break;
case PROPERTY_SERIALIZER_LINE_SEPARATOR:
lineSeparator = (String) value;
break;
case PROPERTY_LOCATION:
location = (String) value;
break;
default:
throw new IllegalStateException("unsupported property " + name);
}
writeLineSepartor = lineSeparator != null && lineSeparator.length() > 0;
writeIndentation = indentationString != null
&& indentationString.length() > 0;
@ -314,15 +318,16 @@ public class MXSerializer implements XmlSerializer {
if (name == null) {
throw new IllegalArgumentException("property name can not be null");
}
if (PROPERTY_SERIALIZER_INDENTATION.equals(name)) {
return indentationString;
} else if (PROPERTY_SERIALIZER_LINE_SEPARATOR.equals(name)) {
return lineSeparator;
} else if (PROPERTY_LOCATION.equals(name)) {
return location;
} else {
return null;
}
switch (name) {
case PROPERTY_SERIALIZER_INDENTATION:
return indentationString;
case PROPERTY_SERIALIZER_LINE_SEPARATOR:
return lineSeparator;
case PROPERTY_LOCATION:
return location;
default:
return null;
}
}
private String getLocation() {
@ -370,7 +375,7 @@ public class MXSerializer implements XmlSerializer {
if (standalone != null) {
out.write(" standalone=");
out.write(attributeUseApostrophe ? '\'' : '"');
if (standalone.booleanValue()) {
if (standalone) {
out.write("yes");
} else {
out.write("no");
@ -462,9 +467,9 @@ public class MXSerializer implements XmlSerializer {
continue;
// now check that prefix is still in scope
for (int p = namespaceEnd - 1; p > i; --p) {
if (prefix == namespacePrefix[p])
continue; // too bad - prefix is redeclared with different namespace
}
if (prefix == namespacePrefix[p]) {
} // too bad - prefix is redeclared with different namespace
}
return prefix;
}
}
@ -487,8 +492,8 @@ public class MXSerializer implements XmlSerializer {
// make sure this prefix is not declared in any scope (avoid hiding in-scope prefixes)!
for (int i = namespaceEnd - 1; i >= 0; --i) {
if (prefix == namespacePrefix[i]) {
continue; // prefix is already declared - generate new and try again
}
// prefix is already declared - generate new and try again
}
}
// declare prefix
@ -713,8 +718,7 @@ public class MXSerializer implements XmlSerializer {
if (startTagIncomplete) {
writeNamespaceDeclarations();
out.write(" />"); // space is added to make it easier to work in XHTML!!!
--depth;
} else {
} else {
if (doIndent && seenTag) {
writeIndent();
}
@ -726,9 +730,9 @@ public class MXSerializer implements XmlSerializer {
}
out.write(name);
out.write('>');
--depth;
}
namespaceEnd = elNamespaceCount[depth];
}
--depth;
namespaceEnd = elNamespaceCount[depth];
startTagIncomplete = false;
seenTag = true;
return this;
@ -1009,7 +1013,7 @@ public class MXSerializer implements XmlSerializer {
}
}
protected static final String printable(String s) {
protected static String printable(String s) {
if (s == null) {
return "null";
}
@ -1022,7 +1026,7 @@ public class MXSerializer implements XmlSerializer {
return retval.toString();
}
protected static final String printable(char ch) {
protected static String printable(char ch) {
StringBuffer retval = new StringBuffer();
addPrintable(retval, ch);
return retval.toString();
@ -1049,7 +1053,7 @@ public class MXSerializer implements XmlSerializer {
retval.append("\\\"");
break;
case '\'':
retval.append("\\\'");
retval.append("\\'");
break;
case '\\':
retval.append("\\\\");
@ -1057,7 +1061,7 @@ public class MXSerializer implements XmlSerializer {
default:
if (ch < 0x20 || ch > 0x7e) {
final String ss = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + ss.substring(ss.length() - 4));
retval.append("\\u").append(ss.substring(ss.length() - 4));
} else {
retval.append(ch);
}

View File

@ -45,7 +45,7 @@ public abstract class TestUtils {
int eventType;
String key = null;
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map = new HashMap<>();
while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
@ -78,14 +78,14 @@ public abstract class TestUtils {
}
}
public static void copyResourceDir(Class class_, String dirPath, File out) throws BrutException {
public static void copyResourceDir(Class<?> class_, String dirPath, File out) throws BrutException {
if (!out.exists()) {
out.mkdirs();
}
copyResourceDir(class_, dirPath, new FileDirectory(out));
}
public static void copyResourceDir(Class class_, String dirPath, Directory out) throws BrutException {
public static void copyResourceDir(Class<?> class_, String dirPath, Directory out) throws BrutException {
if (class_ == null) {
class_ = Class.class;
}

View File

@ -176,7 +176,7 @@ public class BuildAndDecodeTest extends BaseTest {
public void storedMp3FilesAreNotCompressedTest() throws BrutException {
ExtFile extFile = new ExtFile(sTmpDir, "testapp.apk");
Integer built = extFile.getDirectory().getCompressionLevel("res/raw/rain.mp3");
assertEquals(new Integer(0), built);
assertEquals(Integer.valueOf(0), built);
}
@Test

View File

@ -79,7 +79,7 @@ public class UnknownCompressionTest extends BaseTest {
// Check that control = rebuilt (both stored)
// Add extra check for checking = 0 to enforce check for stored just in case control breaks
assertEquals(control, rebuilt);
assertEquals(new Integer(0), rebuilt);
assertEquals(Integer.valueOf(0), rebuilt);
}
@Test
@ -88,7 +88,7 @@ public class UnknownCompressionTest extends BaseTest {
Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("test.json");
assertEquals(control, rebuilt);
assertEquals(new Integer(8), rebuilt);
assertEquals(Integer.valueOf(8), rebuilt);
}
@Test
@ -97,6 +97,6 @@ public class UnknownCompressionTest extends BaseTest {
Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("950x150.png");
assertEquals(control, rebuilt);
assertEquals(new Integer(8), rebuilt);
assertEquals(Integer.valueOf(8), rebuilt);
}
}

View File

@ -33,7 +33,7 @@ import java.nio.file.Paths;
import static org.junit.Assert.assertTrue;
public class DecodeKotlinCoroutinesTest extends BaseTest {
private static String apk = "test-kotlin-coroutines.apk";
private static final String apk = "test-kotlin-coroutines.apk";
@BeforeClass
public static void beforeClass() throws Exception {

View File

@ -272,8 +272,8 @@ public abstract class AbstractDirectory implements Directory {
private class ParsedPath {
public String dir;
public String subpath;
public final String dir;
public final String subpath;
public ParsedPath(String dir, String subpath) {
this.dir = dir;
this.subpath = subpath;
@ -281,8 +281,8 @@ public abstract class AbstractDirectory implements Directory {
}
private class SubPath {
public AbstractDirectory dir;
public String path;
public final AbstractDirectory dir;
public final String path;
public SubPath(AbstractDirectory dir, String path) {
this.dir = dir;

View File

@ -41,8 +41,8 @@ public class DirUtil {
public static void copyToDir(Directory in, Directory out,
String[] fileNames) throws DirectoryException {
for (int i = 0; i < fileNames.length; i++) {
copyToDir(in, out, fileNames[i]);
for (String fileName : fileNames) {
copyToDir(in, out, fileName);
}
}
@ -73,8 +73,8 @@ public class DirUtil {
public static void copyToDir(Directory in, File out, String[] fileNames)
throws DirectoryException {
for (int i = 0; i < fileNames.length; i++) {
copyToDir(in, out, fileNames[i]);
for (String fileName : fileNames) {
copyToDir(in, out, fileName);
}
}

View File

@ -21,41 +21,41 @@ import java.util.Map;
import java.util.Set;
public interface Directory {
public Set<String> getFiles();
public Set<String> getFiles(boolean recursive);
public Map<String, Directory> getDirs();
public Map<String, Directory> getDirs(boolean recursive);
Set<String> getFiles();
Set<String> getFiles(boolean recursive);
Map<String, Directory> getDirs();
Map<String, Directory> getDirs(boolean recursive);
public boolean containsFile(String path);
public boolean containsDir(String path);
boolean containsFile(String path);
boolean containsDir(String path);
public InputStream getFileInput(String path) throws DirectoryException;
public OutputStream getFileOutput(String path) throws DirectoryException;
public Directory getDir(String path) throws PathNotExist;
public Directory createDir(String path) throws DirectoryException;
InputStream getFileInput(String path) throws DirectoryException;
OutputStream getFileOutput(String path) throws DirectoryException;
Directory getDir(String path) throws PathNotExist;
Directory createDir(String path) throws DirectoryException;
public boolean removeFile(String path);
boolean removeFile(String path);
public void copyToDir(Directory out) throws DirectoryException;
public void copyToDir(Directory out, String[] fileNames)
void copyToDir(Directory out) throws DirectoryException;
void copyToDir(Directory out, String[] fileNames)
throws DirectoryException;
public void copyToDir(Directory out, String fileName)
void copyToDir(Directory out, String fileName)
throws DirectoryException;
public void copyToDir(File out) throws DirectoryException;
public void copyToDir(File out, String[] fileNames)
void copyToDir(File out) throws DirectoryException;
void copyToDir(File out, String[] fileNames)
throws DirectoryException;
public void copyToDir(File out, String fileName)
void copyToDir(File out, String fileName)
throws DirectoryException;
public long getSize(String fileName)
long getSize(String fileName)
throws DirectoryException;
public long getCompressedSize(String fileName)
long getCompressedSize(String fileName)
throws DirectoryException;
public int getCompressionLevel(String fileName)
int getCompressionLevel(String fileName)
throws DirectoryException;
public void close() throws IOException;
void close() throws IOException;
public final char separator = '/';
char separator = '/';
}

View File

@ -22,7 +22,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
public class FileDirectory extends AbstractDirectory {
private File mDir;
private final File mDir;
public FileDirectory(ExtFile dir, String folder) throws DirectoryException {
this(new File(dir.toString().replaceAll("%20", " "), folder));
@ -101,19 +101,18 @@ public class FileDirectory extends AbstractDirectory {
}
private void loadAll() {
mFiles = new LinkedHashSet<String>();
mDirs = new LinkedHashMap<String, AbstractDirectory>();
mFiles = new LinkedHashSet<>();
mDirs = new LinkedHashMap<>();
File[] files = getDir().listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
for (File file : files) {
if (file.isFile()) {
mFiles.add(file.getName());
} else {
// IMPOSSIBLE_EXCEPTION
try {
mDirs.put(file.getName(), new FileDirectory(file));
} catch (DirectoryException e) {}
} catch (DirectoryException ignored) {}
}
}
}

View File

@ -27,8 +27,8 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ZipRODirectory extends AbstractDirectory {
private ZipFile mZipFile;
private String mPath;
private final ZipFile mZipFile;
private final String mPath;
public ZipRODirectory(String zipFileName) throws DirectoryException {
this(zipFileName, "");
@ -129,8 +129,8 @@ public class ZipRODirectory extends AbstractDirectory {
}
private void loadAll() {
mFiles = new LinkedHashSet<String>();
mDirs = new LinkedHashMap<String, AbstractDirectory>();
mFiles = new LinkedHashSet<>();
mDirs = new LinkedHashMap<>();
int prefixLen = getPath().length();
Enumeration<? extends ZipEntry> entries = getZipFile().entries();

View File

@ -41,8 +41,8 @@ public class BrutIO {
public static long recursiveModifiedTime(File[] files) {
long modified = 0;
for (int i = 0; i < files.length; i++) {
long submodified = recursiveModifiedTime(files[i]);
for (File file : files) {
long submodified = recursiveModifiedTime(file);
if (submodified > modified) {
modified = submodified;
}
@ -54,8 +54,8 @@ public class BrutIO {
long modified = file.lastModified();
if (file.isDirectory()) {
File[] subfiles = file.listFiles();
for (int i = 0; i < subfiles.length; i++) {
long submodified = recursiveModifiedTime(subfiles[i]);
for (File subfile : subfiles) {
long submodified = recursiveModifiedTime(subfile);
if (submodified > modified) {
modified = submodified;
}

View File

@ -16,6 +16,8 @@
*/
package brut.util;
import java.util.Objects;
public class Duo<T1, T2> {
public final T1 m1;
public final T2 m2;
@ -34,13 +36,10 @@ public class Duo<T1, T2> {
return false;
}
final Duo<T1, T2> other = (Duo<T1, T2>) obj;
if (this.m1 != other.m1 && (this.m1 == null || !this.m1.equals(other.m1))) {
if (!Objects.equals(this.m1, other.m1)) {
return false;
}
if (this.m2 != other.m2 && (this.m2 == null || !this.m2.equals(other.m2))) {
return false;
}
return true;
return Objects.equals(this.m2, other.m2);
}
@Override

View File

@ -80,9 +80,9 @@ public class ExtDataInput extends DataInputDelegate {
*/
public final int skipBytes(int n) throws IOException {
int total = 0;
int cur = 0;
int cur;
while ((total < n) && ((cur = (int) super.skipBytes(n - total)) > 0)) {
while ((total < n) && ((cur = super.skipBytes(n - total)) > 0)) {
total += cur;
}

View File

@ -27,7 +27,7 @@ import java.util.concurrent.ThreadLocalRandom;
public abstract class Jar {
private static final Map<String, File> mExtracted = new HashMap<>();
public static File getResourceAsFile(String name, Class clazz) throws BrutException {
public static File getResourceAsFile(String name, Class<?> clazz) throws BrutException {
File file = mExtracted.get(name);
if (file == null) {
file = extractToTmp(name, clazz);
@ -36,11 +36,11 @@ public abstract class Jar {
return file;
}
public static File extractToTmp(String resourcePath, Class clazz) throws BrutException {
public static File extractToTmp(String resourcePath, Class<?> clazz) throws BrutException {
return extractToTmp(resourcePath, "brut_util_Jar_", clazz);
}
public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz) throws BrutException {
public static File extractToTmp(String resourcePath, String tmpPrefix, Class<?> clazz) throws BrutException {
try {
InputStream in = clazz.getResourceAsStream(resourcePath);
if (in == null) {