Refactor magic string.
diff --git a/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java
index 3ce49b5..a033a14 100644
--- a/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java
@@ -50,9 +50,8 @@
if ((localFileHeader.arjFlags & LocalFileHeader.Flags.PATHSYM) != 0) {
return localFileHeader.name.replaceAll("/",
Matcher.quoteReplacement(File.separator));
- } else {
- return localFileHeader.name;
}
+ return localFileHeader.name;
}
/**
diff --git a/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
index 96d1e8c..f049299 100644
--- a/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
@@ -114,10 +114,9 @@
}
if (charsetName != null) {
return new String(buffer.toByteArray(), charsetName);
- } else {
- // intentionally using the default encoding as that's the contract for a null charsetName
- return new String(buffer.toByteArray());
}
+ // intentionally using the default encoding as that's the contract for a null charsetName
+ return new String(buffer.toByteArray());
}
private void readFully(final DataInputStream dataIn, byte[] b)
@@ -330,10 +329,9 @@
currentLocalFileHeader.originalSize, currentLocalFileHeader.originalCrc32);
}
return new ArjArchiveEntry(currentLocalFileHeader);
- } else {
- currentInputStream = null;
- return null;
}
+ currentInputStream = null;
+ return null;
}
@Override
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/BoundedRandomAccessFileInputStream.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/BoundedRandomAccessFileInputStream.java
index 482bd7a..63cf4bb 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/BoundedRandomAccessFileInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/BoundedRandomAccessFileInputStream.java
@@ -36,9 +36,8 @@
if (bytesRemaining > 0) {
--bytesRemaining;
return file.read();
- } else {
- return -1;
}
+ return -1;
}
@Override
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
index c3f2bb9..b15bb7d 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
@@ -147,10 +147,9 @@
public Date getCreationDate() {
if (hasCreationDate) {
return ntfsTimeToJavaTime(creationDate);
- } else {
- throw new UnsupportedOperationException(
- "The entry doesn't have this timestamp");
}
+ throw new UnsupportedOperationException(
+ "The entry doesn't have this timestamp");
}
/**
@@ -199,10 +198,9 @@
public Date getLastModifiedDate() {
if (hasLastModifiedDate) {
return ntfsTimeToJavaTime(lastModifiedDate);
- } else {
- throw new UnsupportedOperationException(
- "The entry doesn't have this timestamp");
}
+ throw new UnsupportedOperationException(
+ "The entry doesn't have this timestamp");
}
/**
@@ -250,10 +248,9 @@
public Date getAccessDate() {
if (hasAccessDate) {
return ntfsTimeToJavaTime(accessDate);
- } else {
- throw new UnsupportedOperationException(
- "The entry doesn't have this timestamp");
}
+ throw new UnsupportedOperationException(
+ "The entry doesn't have this timestamp");
}
/**
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index 0e47f8c..2512eec 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -381,10 +381,9 @@
final int external = header.readUnsignedByte();
if (external != 0) {
throw new IOException("External unsupported");
- } else {
- for (int i = 0; i < (int)numFolders; i++) {
- folders[i] = readFolder(header);
- }
+ }
+ for (int i = 0; i < (int)numFolders; i++) {
+ folders[i] = readFolder(header);
}
nid = header.readUnsignedByte();
@@ -647,23 +646,22 @@
final int external = header.readUnsignedByte();
if (external != 0) {
throw new IOException("Not implemented");
- } else {
- if (((size - 1) & 1) != 0) {
- throw new IOException("File names length invalid");
+ }
+ if (((size - 1) & 1) != 0) {
+ throw new IOException("File names length invalid");
+ }
+ final byte[] names = new byte[(int)(size - 1)];
+ header.readFully(names);
+ int nextFile = 0;
+ int nextName = 0;
+ for (int i = 0; i < names.length; i += 2) {
+ if (names[i] == 0 && names[i+1] == 0) {
+ files[nextFile++].setName(new String(names, nextName, i-nextName, CharsetNames.UTF_16LE));
+ nextName = i + 2;
}
- final byte[] names = new byte[(int)(size - 1)];
- header.readFully(names);
- int nextFile = 0;
- int nextName = 0;
- for (int i = 0; i < names.length; i += 2) {
- if (names[i] == 0 && names[i+1] == 0) {
- files[nextFile++].setName(new String(names, nextName, i-nextName, CharsetNames.UTF_16LE));
- nextName = i + 2;
- }
- }
- if (nextName != names.length || nextFile != files.length) {
- throw new IOException("Error parsing file names");
- }
+ }
+ if (nextName != names.length || nextFile != files.length) {
+ throw new IOException("Error parsing file names");
}
break;
}
@@ -672,12 +670,11 @@
final int external = header.readUnsignedByte();
if (external != 0) {
throw new IOException("Unimplemented");
- } else {
- for (int i = 0; i < files.length; i++) {
- files[i].setHasCreationDate(timesDefined.get(i));
- if (files[i].getHasCreationDate()) {
- files[i].setCreationDate(Long.reverseBytes(header.readLong()));
- }
+ }
+ for (int i = 0; i < files.length; i++) {
+ files[i].setHasCreationDate(timesDefined.get(i));
+ if (files[i].getHasCreationDate()) {
+ files[i].setCreationDate(Long.reverseBytes(header.readLong()));
}
}
break;
@@ -687,12 +684,11 @@
final int external = header.readUnsignedByte();
if (external != 0) {
throw new IOException("Unimplemented");
- } else {
- for (int i = 0; i < files.length; i++) {
- files[i].setHasAccessDate(timesDefined.get(i));
- if (files[i].getHasAccessDate()) {
- files[i].setAccessDate(Long.reverseBytes(header.readLong()));
- }
+ }
+ for (int i = 0; i < files.length; i++) {
+ files[i].setHasAccessDate(timesDefined.get(i));
+ if (files[i].getHasAccessDate()) {
+ files[i].setAccessDate(Long.reverseBytes(header.readLong()));
}
}
break;
@@ -702,12 +698,11 @@
final int external = header.readUnsignedByte();
if (external != 0) {
throw new IOException("Unimplemented");
- } else {
- for (int i = 0; i < files.length; i++) {
- files[i].setHasLastModifiedDate(timesDefined.get(i));
- if (files[i].getHasLastModifiedDate()) {
- files[i].setLastModifiedDate(Long.reverseBytes(header.readLong()));
- }
+ }
+ for (int i = 0; i < files.length; i++) {
+ files[i].setHasLastModifiedDate(timesDefined.get(i));
+ if (files[i].getHasLastModifiedDate()) {
+ files[i].setLastModifiedDate(Long.reverseBytes(header.readLong()));
}
}
break;
@@ -717,12 +712,11 @@
final int external = header.readUnsignedByte();
if (external != 0) {
throw new IOException("Unimplemented");
- } else {
- for (int i = 0; i < files.length; i++) {
- files[i].setHasWindowsAttributes(attributesDefined.get(i));
- if (files[i].getHasWindowsAttributes()) {
- files[i].setWindowsAttributes(Integer.reverseBytes(header.readInt()));
- }
+ }
+ for (int i = 0; i < files.length; i++) {
+ files[i].setHasWindowsAttributes(attributesDefined.get(i));
+ if (files[i].getHasWindowsAttributes()) {
+ files[i].setWindowsAttributes(Integer.reverseBytes(header.readInt()));
}
}
break;
@@ -888,9 +882,8 @@
if (folder.hasCrc) {
return new CRC32VerifyingInputStream(inputStreamStack,
folder.getUnpackSize(), folder.crc);
- } else {
- return inputStreamStack;
}
+ return inputStreamStack;
}
/**
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/CircularBuffer.java b/src/main/java/org/apache/commons/compress/archivers/zip/CircularBuffer.java
index af64a85..10a35a8 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/CircularBuffer.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/CircularBuffer.java
@@ -67,9 +67,8 @@
int value = buffer[readIndex];
readIndex = (readIndex + 1) % size;
return value & 0xFF;
- } else {
- return -1;
}
+ return -1;
}
/**
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java b/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java
index 4baae8a..14bab4a 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java
@@ -76,9 +76,8 @@
public ByteBuffer encode(String name) throws IOException {
if (this.charsetName == null) { // i.e. use default charset, see no-args constructor
return ByteBuffer.wrap(name.getBytes());
- } else {
- return ByteBuffer.wrap(name.getBytes(this.charsetName));
}
+ return ByteBuffer.wrap(name.getBytes(this.charsetName));
}
/**
@@ -88,8 +87,7 @@
public String decode(byte[] data) throws IOException {
if (this.charsetName == null) { // i.e. use default charset, see no-args constructor
return new String(data);
- } else {
- return new String(data,this.charsetName);
}
+ return new String(data,this.charsetName);
}
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/X000A_NTFS.java b/src/main/java/org/apache/commons/compress/archivers/zip/X000A_NTFS.java
index 0b5e419..e2bde27 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/X000A_NTFS.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/X000A_NTFS.java
@@ -321,9 +321,8 @@
return (modifyTime == xf.modifyTime || (modifyTime != null && modifyTime.equals(xf.modifyTime))) &&
(accessTime == xf.accessTime || (accessTime != null && accessTime.equals(xf.accessTime))) &&
(createTime == xf.createTime || (createTime != null && createTime.equals(xf.createTime)));
- } else {
- return false;
}
+ return false;
}
@Override
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java b/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
index b1ac3ee..8a7c7df 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
@@ -562,9 +562,8 @@
(modifyTime == xf.modifyTime || (modifyTime != null && modifyTime.equals(xf.modifyTime))) &&
(accessTime == xf.accessTime || (accessTime != null && accessTime.equals(xf.accessTime))) &&
(createTime == xf.createTime || (createTime != null && createTime.equals(xf.createTime)));
- } else {
- return false;
}
+ return false;
}
@Override
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
index f8df66b..be036e5 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
@@ -654,10 +654,9 @@
long n = in.read(buf.array(), 0, (int) Math.min(buf.capacity(), remaining));
if (n < 0) {
throw new EOFException("Truncated ZIP entry: " + current.entry.getName());
- } else {
- count(n);
- remaining -= n;
}
+ count(n);
+ remaining -= n;
}
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
index f1bcbef..3b51b07 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
@@ -475,9 +475,8 @@
in.close();
}
}
- } else {
- return null;
}
+ return null;
}
/**
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
index 7c21e29..757967d 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
@@ -99,9 +99,8 @@
public static long adjustToLong(int i) {
if (i < 0) {
return 2 * ((long) Integer.MAX_VALUE) + 2 + i;
- } else {
- return i;
}
+ return i;
}
/**
@@ -135,9 +134,8 @@
static long bigToLong(BigInteger big) {
if (big.bitLength() <= 63) { // bitLength() doesn't count the sign bit.
return big.longValue();
- } else {
- throw new NumberFormatException("The BigInteger cannot fit inside a 64 bit java long: [" + big + "]");
}
+ throw new NumberFormatException("The BigInteger cannot fit inside a 64 bit java long: [" + big + "]");
}
/**
@@ -173,9 +171,8 @@
public static int signedByteToUnsignedInt(byte b) {
if (b >= 0) {
return b;
- } else {
- return 256 + b;
}
+ return 256 + b;
}
/**
@@ -192,9 +189,8 @@
}
if (i < 128) {
return (byte) i;
- } else {
- return (byte) (i - 256);
}
+ return (byte) (i - 256);
}
/**
@@ -354,9 +350,8 @@
throw
new UnsupportedZipFeatureException(UnsupportedZipFeatureException
.Feature.METHOD, ze);
- } else {
- throw new UnsupportedZipFeatureException(m, ze);
}
+ throw new UnsupportedZipFeatureException(m, ze);
}
}
}
diff --git a/src/main/java/org/apache/commons/compress/changes/ChangeSet.java b/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
index a9be42d..72df166 100644
--- a/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
+++ b/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
@@ -108,10 +108,9 @@
it.remove();
changes.add(pChange);
return;
- } else {
- // do not add this change
- return;
}
+ // do not add this change
+ return;
}
}
}
diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
index edf90cb..b4c7d9d 100644
--- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
@@ -140,9 +140,8 @@
int r = read0();
count(r < 0 ? -1 : 1);
return r;
- } else {
- throw new IOException("stream closed");
}
+ throw new IOException("stream closed");
}
/*
@@ -299,24 +298,23 @@
) {
this.currentState = EOF;
throw new IOException("bad block header");
- } else {
- this.storedBlockCRC = bsGetInt();
- this.blockRandomised = bsR(1) == 1;
-
- /**
- * Allocate data here instead in constructor, so we do not allocate
- * it if the input file is empty.
- */
- if (this.data == null) {
- this.data = new Data(this.blockSize100k);
- }
-
- // currBlockNo++;
- getAndMoveToFrontDecode();
-
- this.crc.initialiseCRC();
- this.currentState = START_BLOCK_STATE;
}
+ this.storedBlockCRC = bsGetInt();
+ this.blockRandomised = bsR(1) == 1;
+
+ /**
+ * Allocate data here instead in constructor, so we do not allocate
+ * it if the input file is empty.
+ */
+ if (this.data == null) {
+ this.data = new Data(this.blockSize100k);
+ }
+
+ // currBlockNo++;
+ getAndMoveToFrontDecode();
+
+ this.crc.initialiseCRC();
+ this.currentState = START_BLOCK_STATE;
}
private void endBlock() throws IOException {
@@ -630,9 +628,8 @@
bsBuffShadow = (bsBuffShadow << 8) | thech;
bsLiveShadow += 8;
continue;
- } else {
- throw new IOException("unexpected end of stream");
}
+ throw new IOException("unexpected end of stream");
}
int zvec = (bsBuffShadow >> (bsLiveShadow - zn))
& ((1 << zn) - 1);
@@ -646,10 +643,9 @@
bsBuffShadow = (bsBuffShadow << 8) | thech;
bsLiveShadow += 8;
continue;
- } else {
- throw new IOException(
- "unexpected end of stream");
}
+ throw new IOException(
+ "unexpected end of stream");
}
bsLiveShadow--;
zvec = (zvec << 1)
@@ -713,9 +709,8 @@
bsBuffShadow = (bsBuffShadow << 8) | thech;
bsLiveShadow += 8;
continue;
- } else {
- throw new IOException("unexpected end of stream");
}
+ throw new IOException("unexpected end of stream");
}
int zvec = (bsBuffShadow >> (bsLiveShadow - zn))
& ((1 << zn) - 1);
@@ -729,9 +724,8 @@
bsBuffShadow = (bsBuffShadow << 8) | thech;
bsLiveShadow += 8;
continue;
- } else {
- throw new IOException("unexpected end of stream");
}
+ throw new IOException("unexpected end of stream");
}
bsLiveShadow--;
zvec = (zvec << 1) | ((bsBuffShadow >> bsLiveShadow) & 1);
@@ -764,9 +758,8 @@
bsBuffShadow = (bsBuffShadow << 8) | thech;
bsLiveShadow += 8;
continue;
- } else {
- throw new IOException("unexpected end of stream");
}
+ throw new IOException("unexpected end of stream");
}
bsLiveShadow--;
zvec = (zvec << 1) | ((bsBuffShadow >> bsLiveShadow) & 1);
@@ -833,11 +826,10 @@
this.currentState = RAND_PART_B_STATE;
this.crc.updateCRC(su_ch2Shadow);
return su_ch2Shadow;
- } else {
- endBlock();
- initBlock();
- return setupBlock();
}
+ endBlock();
+ initBlock();
+ return setupBlock();
}
private int setupNoRandPartA() throws IOException {
@@ -850,12 +842,11 @@
this.currentState = NO_RAND_PART_B_STATE;
this.crc.updateCRC(su_ch2Shadow);
return su_ch2Shadow;
- } else {
- this.currentState = NO_RAND_PART_A_STATE;
- endBlock();
- initBlock();
- return setupBlock();
}
+ this.currentState = NO_RAND_PART_A_STATE;
+ endBlock();
+ initBlock();
+ return setupBlock();
}
private int setupRandPartB() throws IOException {
@@ -891,12 +882,11 @@
this.crc.updateCRC(this.su_ch2);
this.su_j2++;
return this.su_ch2;
- } else {
- this.currentState = RAND_PART_A_STATE;
- this.su_i2++;
- this.su_count = 0;
- return setupRandPartA();
}
+ this.currentState = RAND_PART_A_STATE;
+ this.su_i2++;
+ this.su_count = 0;
+ return setupRandPartA();
}
private int setupNoRandPartB() throws IOException {
@@ -920,11 +910,10 @@
this.su_j2++;
this.currentState = NO_RAND_PART_C_STATE;
return su_ch2Shadow;
- } else {
- this.su_i2++;
- this.su_count = 0;
- return setupNoRandPartA();
}
+ this.su_i2++;
+ this.su_count = 0;
+ return setupNoRandPartA();
}
private static final class Data {
diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java b/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
index c7c26b2..bafa9e5 100644
--- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
+++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
@@ -725,13 +725,10 @@
}
break HAMMER;
} // while x > 0
- else {
- if ((block[i1] & 0xff) > (block[i2] & 0xff)) {
- continue HAMMER;
- } else {
- break HAMMER;
- }
+ if ((block[i1] & 0xff) > (block[i2] & 0xff)) {
+ continue HAMMER;
}
+ break HAMMER;
} else if ((block[i1 + 5] & 0xff) > (block[i2 + 5] & 0xff)) {
continue HAMMER;
} else {
diff --git a/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java b/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
index 791f08c..5b35667 100644
--- a/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
@@ -45,9 +45,8 @@
if (bytesRemaining > 0) {
--bytesRemaining;
return in.read();
- } else {
- return -1;
}
+ return -1;
}
@Override
diff --git a/src/main/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStream.java b/src/main/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStream.java
index 69bf03c..856e448 100644
--- a/src/main/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStream.java
@@ -98,9 +98,8 @@
// Can't really skip, we have to hash everything to verify the checksum
if (read() >= 0) {
return 1;
- } else {
- return 0;
}
+ return 0;
}
@Override