Skip to content
Permalink
Browse files
Minor change: (#206)
* Simplify conditions
* Make final var
  • Loading branch information
arturobernalg committed Feb 20, 2022
1 parent f383b72 commit c936bba5b8f8d4e86ab753f9e04da100e883cb78
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 38 deletions.
@@ -410,10 +410,6 @@ public boolean equals(final Object o) {

final DumpArchiveEntry rhs = (DumpArchiveEntry) o;

if (rhs.header == null) {
return false;
}

if (ino != rhs.ino) {
return false;
}
@@ -47,7 +47,8 @@ class Coders {
private static final Map<SevenZMethod, CoderBase> CODER_MAP = new HashMap<SevenZMethod, CoderBase>() {

private static final long serialVersionUID = 1664829131806520867L;
{

{
put(SevenZMethod.COPY, new CopyDecoder());
put(SevenZMethod.LZMA, new LZMADecoder());
put(SevenZMethod.LZMA2, new LZMA2Decoder());
@@ -62,7 +63,8 @@ class Coders {
put(SevenZMethod.BCJ_ARM_THUMB_FILTER, new BCJDecoder(new ARMThumbOptions()));
put(SevenZMethod.BCJ_SPARC_FILTER, new BCJDecoder(new SPARCOptions()));
put(SevenZMethod.DELTA_FILTER, new DeltaDecoder());
}};
}
};

static CoderBase findByMethod(final SevenZMethod method) {
return CODER_MAP.get(method);
@@ -1707,28 +1707,25 @@ private static String normalizeFileName(String fileName,
if (!preserveAbsolutePath) {
final String osname = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);

if (osname != null) {

// Strip off drive letters!
// REVIEW Would a better check be "(File.separator == '\')"?

if (osname.startsWith("windows")) {
if (fileName.length() > 2) {
final char ch1 = fileName.charAt(0);
final char ch2 = fileName.charAt(1);

if (ch2 == ':'
&& (ch1 >= 'a' && ch1 <= 'z'
|| ch1 >= 'A' && ch1 <= 'Z')) {
fileName = fileName.substring(2);
}
}
} else if (osname.contains("netware")) {
final int colon = fileName.indexOf(':');
if (colon != -1) {
fileName = fileName.substring(colon + 1);
// Strip off drive letters!
// REVIEW Would a better check be "(File.separator == '\')"?

if (osname.startsWith("windows")) {
if (fileName.length() > 2) {
final char ch1 = fileName.charAt(0);
final char ch2 = fileName.charAt(1);

if (ch2 == ':'
&& (ch1 >= 'a' && ch1 <= 'z'
|| ch1 >= 'A' && ch1 <= 'Z')) {
fileName = fileName.substring(2);
}
}
} else if (osname.contains("netware")) {
final int colon = fileName.indexOf(':');
if (colon != -1) {
fileName = fileName.substring(colon + 1);
}
}
}

@@ -319,7 +319,7 @@ public int hashCode() {
*/
static byte[] trimLeadingZeroesForceMinLength(final byte[] array) {
if (array == null) {
return array;
return null;
}

int pos = 0;
@@ -776,8 +776,7 @@ public String getName() {
*/
@Override
public boolean isDirectory() {
final String n = getName();
return n != null && n.endsWith("/");
return getName().endsWith("/");
}

/**
@@ -894,8 +893,7 @@ public int hashCode() {
// on the super.hashCode() method since super.getName() always return
// the empty string in the current implementation (there's no setter)
// so it is basically draining the performance of a hashmap lookup
final String n = getName();
return (n == null ? "" : n).hashCode();
return getName().hashCode();
}

/**
@@ -125,7 +125,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream implements InputSt
* https://issues.apache.org/jira/projects/COMPRESS/issues/COMPRESS-555
* https://github.com/apache/commons-compress/pull/137#issuecomment-690835644
*/
private boolean allowStoredEntriesWithDataDescriptor;
private final boolean allowStoredEntriesWithDataDescriptor;

/** Count decompressed bytes for current entry */
private long uncompressedCount;
@@ -249,9 +249,6 @@ private void nextBlock() throws IOException {
final long len = ByteUtils.fromLittleEndian(supplier, 4);
final boolean uncompressed = (len & UNCOMPRESSED_FLAG_MASK) != 0;
final int realLen = (int) (len & (~UNCOMPRESSED_FLAG_MASK));
if (realLen < 0) {
throw new IOException("Found illegal block with negative size");
}
if (realLen == 0) {
verifyContentChecksum();
if (!decompressConcatenated) {
@@ -159,9 +159,6 @@ private void fill() throws IOException {
*/

length = 4 + ((b >> 2) & 0x07);
if (length < 0) {
throw new IOException("Illegal block with a negative match length found");
}
uncompressedBytesRemaining -= length;
offset = (b & 0xE0) << 3;
b = readOneByte();

0 comments on commit c936bba

Please sign in to comment.