Skip to content

Commit

Permalink
Minor change:
Browse files Browse the repository at this point in the history
* Simplify conditions
* Make final var
  • Loading branch information
arturobernalg committed Jun 12, 2021
1 parent 7c79a74 commit 7bc52c2
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1708,28 +1708,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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public int hashCode() {
*/
static byte[] trimLeadingZeroesForceMinLength(final byte[] array) {
if (array == null) {
return array;
return null;
}

int pos = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public String getName() {
@Override
public boolean isDirectory() {
final String n = getName();
return n != null && n.endsWith("/");
return n.endsWith("/");
}

/**
Expand Down Expand Up @@ -897,7 +897,7 @@ public int hashCode() {
// 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 n.hashCode();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7bc52c2

Please sign in to comment.