This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push:
new f0f067e47 Reduce vertical whitespace
f0f067e47 is described below
commit f0f067e477c7cb0f6039ad841f8751c721cc86eb
Author: Gary Gregory <[email protected]>
AuthorDate: Fri May 30 16:00:27 2025 -0400
Reduce vertical whitespace
---
.../compress/archivers/ArchiveStreamFactory.java | 11 ------
.../archivers/tar/TarArchiveInputStream.java | 39 ++--------------------
2 files changed, 3 insertions(+), 47 deletions(-)
diff --git
a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
index 42dc976d0..4e066e4e7 100644
---
a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
+++
b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
@@ -212,11 +212,9 @@ public static String detect(final InputStream in) throws
ArchiveException {
if (in == null) {
throw new IllegalArgumentException("Stream must not be null.");
}
-
if (!in.markSupported()) {
throw new IllegalArgumentException("Mark is not supported.");
}
-
final byte[] signature = new byte[SIGNATURE_SIZE];
in.mark(signature.length);
int signatureLength = -1;
@@ -226,7 +224,6 @@ public static String detect(final InputStream in) throws
ArchiveException {
} catch (final IOException e) {
throw new ArchiveException("Failure reading signature.",
(Throwable) e);
}
-
// For now JAR files are detected as ZIP files.
if (ZipArchiveInputStream.matches(signature, signatureLength)) {
return ZIP;
@@ -247,7 +244,6 @@ public static String detect(final InputStream in) throws
ArchiveException {
if (SevenZFile.matches(signature, signatureLength)) {
return SEVEN_Z;
}
-
// Dump needs a bigger buffer to check the signature;
final byte[] dumpsig = new byte[DUMP_SIGNATURE_SIZE];
in.mark(dumpsig.length);
@@ -260,7 +256,6 @@ public static String detect(final InputStream in) throws
ArchiveException {
if (DumpArchiveInputStream.matches(dumpsig, signatureLength)) {
return DUMP;
}
-
// Tar needs an even bigger buffer to check the signature; read the
first block
final byte[] tarHeader = new byte[TAR_HEADER_SIZE];
in.mark(tarHeader.length);
@@ -273,7 +268,6 @@ public static String detect(final InputStream in) throws
ArchiveException {
if (TarArchiveInputStream.matches(tarHeader, signatureLength)) {
return TAR;
}
-
// COMPRESS-117
if (signatureLength >= TAR_HEADER_SIZE) {
try (TarArchiveInputStream inputStream = new
TarArchiveInputStream(new ByteArrayInputStream(tarHeader))) {
@@ -423,15 +417,12 @@ public <I extends ArchiveInputStream<? extends
ArchiveEntry>> I createArchiveInp
@Override
public <I extends ArchiveInputStream<? extends ArchiveEntry>> I
createArchiveInputStream(final String archiverName, final InputStream in,
final String actualEncoding) throws ArchiveException {
-
if (archiverName == null) {
throw new IllegalArgumentException("Archiver name must not be
null.");
}
-
if (in == null) {
throw new IllegalArgumentException("InputStream must not be
null.");
}
-
if (AR.equalsIgnoreCase(archiverName)) {
return (I) new ArArchiveInputStream(in);
}
@@ -474,12 +465,10 @@ public <I extends ArchiveInputStream<? extends
ArchiveEntry>> I createArchiveInp
if (SEVEN_Z.equalsIgnoreCase(archiverName)) {
throw new StreamingNotSupportedException(SEVEN_Z);
}
-
final ArchiveStreamProvider archiveStreamProvider =
getArchiveInputStreamProviders().get(toKey(archiverName));
if (archiveStreamProvider != null) {
return
archiveStreamProvider.createArchiveInputStream(archiverName, in,
actualEncoding);
}
-
throw new ArchiveException("Archiver: " + archiverName + " not
found.");
}
diff --git
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index c24c6106c..165b72907 100644
---
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -60,9 +60,9 @@ public class TarArchiveInputStream extends
ArchiveInputStream<TarArchiveEntry> {
/**
* Checks if the signature matches what is expected for a tar file.
*
- * @param signature the bytes to check
- * @param length the number of bytes to check
- * @return true, if this stream is a tar archive stream, false otherwise
+ * @param signature the bytes to check.
+ * @param length the number of bytes to check.
+ * @return true, if this stream is a tar archive stream, false otherwise.
*/
public static boolean matches(final byte[] signature, final int length) {
final int versionOffset = TarConstants.VERSION_OFFSET;
@@ -70,7 +70,6 @@ public static boolean matches(final byte[] signature, final
int length) {
if (length < versionOffset + versionLen) {
return false;
}
-
final int magicOffset = TarConstants.MAGIC_OFFSET;
final int magicLen = TarConstants.MAGICLEN;
if (ArchiveUtils.matchAsciiBuffer(TarConstants.MAGIC_POSIX, signature,
magicOffset, magicLen)
@@ -421,32 +420,25 @@ public TarArchiveEntry getNextTarEntry() throws
IOException {
if (isAtEOF()) {
return null;
}
-
if (currEntry != null) {
/* Skip will only go to the end of the current entry */
IOUtils.skip(this, Long.MAX_VALUE);
-
/* skip to the end of the last record */
skipRecordPadding();
}
-
final byte[] headerBuf = getRecord();
-
if (headerBuf == null) {
/* hit EOF */
currEntry = null;
return null;
}
-
try {
currEntry = new TarArchiveEntry(globalPaxHeaders, headerBuf,
zipEncoding, lenient);
} catch (final IllegalArgumentException e) {
throw new IOException("Error detected parsing the header", e);
}
-
entryOffset = 0;
entrySize = currEntry.getSize();
-
if (currEntry.isGNULongLinkEntry()) {
final byte[] longLinkData = getLongNameData();
if (longLinkData == null) {
@@ -456,7 +448,6 @@ public TarArchiveEntry getNextTarEntry() throws IOException
{
}
currEntry.setLinkName(zipEncoding.decode(longLinkData));
}
-
if (currEntry.isGNULongNameEntry()) {
final byte[] longNameData = getLongNameData();
if (longNameData == null) {
@@ -464,7 +455,6 @@ public TarArchiveEntry getNextTarEntry() throws IOException
{
// Malformed tar file - long entry name not followed by entry
return null;
}
-
// COMPRESS-509 : the name of directories should end with '/'
final String name = zipEncoding.decode(longNameData);
currEntry.setName(name);
@@ -472,11 +462,9 @@ public TarArchiveEntry getNextTarEntry() throws
IOException {
currEntry.setName(name + "/");
}
}
-
if (currEntry.isGlobalPaxHeader()) { // Process Global Pax headers
readGlobalPaxHeaders();
}
-
try {
if (currEntry.isPaxHeader()) { // Process Pax headers
paxHeaders();
@@ -486,17 +474,14 @@ public TarArchiveEntry getNextTarEntry() throws
IOException {
} catch (final NumberFormatException e) {
throw new IOException("Error detected parsing the pax header", e);
}
-
if (currEntry.isOldGNUSparse()) { // Process sparse files
readOldGNUSparse();
}
-
// If the size of the next element in the archive has changed
// due to a new size being reported in the POSIX header
// information, we update entrySize here so that it contains
// the correct value.
entrySize = currEntry.getSize();
-
return currEntry;
}
@@ -595,7 +580,6 @@ public boolean markSupported() {
private void paxHeaders() throws IOException {
List<TarArchiveStructSparse> sparseHeaders = new ArrayList<>();
final Map<String, String> headers = TarUtils.parsePaxHeaders(this,
sparseHeaders, globalPaxHeaders, entrySize);
-
// for 0.1 PAX Headers
if (headers.containsKey(TarGnuSparseKeys.MAP)) {
sparseHeaders = new
ArrayList<>(TarUtils.parseFromPAX01SparseHeaders(headers.get(TarGnuSparseKeys.MAP)));
@@ -605,13 +589,11 @@ private void paxHeaders() throws IOException {
throw new IOException("premature end of tar archive. Didn't find
any entry after PAX header.");
}
applyPaxHeadersToCurrentEntry(headers, sparseHeaders);
-
// for 1.0 PAX Format, the sparse map is stored in the file data block
if (currEntry.isPaxGNU1XSparse()) {
sparseHeaders = TarUtils.parsePAX1XSparseHeaders(in,
getRecordSize());
currEntry.setSparseHeaders(sparseHeaders);
}
-
// sparse headers are all done reading, we need to build
// sparse input streams using these sparse headers
buildSparseInputStreams();
@@ -635,28 +617,22 @@ public int read(final byte[] buf, final int offset, int
numToRead) throws IOExce
return 0;
}
int totalRead = 0;
-
if (isAtEOF() || isDirectory()) {
return -1;
}
-
if (currEntry == null) {
throw new IllegalStateException("No current tar entry");
}
-
if (entryOffset >= currEntry.getRealSize()) {
return -1;
}
-
numToRead = Math.min(numToRead, available());
-
if (currEntry.isSparse()) {
// for sparse entries, we need to read them in another way
totalRead = readSparse(buf, offset, numToRead);
} else {
totalRead = in.read(buf, offset, numToRead);
}
-
if (totalRead == -1) {
if (numToRead > 0) {
throw new IOException("Truncated TAR archive");
@@ -666,14 +642,12 @@ public int read(final byte[] buf, final int offset, int
numToRead) throws IOExce
count(totalRead);
entryOffset += totalRead;
}
-
return totalRead;
}
private void readGlobalPaxHeaders() throws IOException {
globalPaxHeaders = TarUtils.parsePaxHeaders(this, globalSparseHeaders,
globalPaxHeaders, entrySize);
getNextEntry(); // Get the actual file entry
-
if (currEntry == null) {
throw new IOException("Error detected parsing the pax header");
}
@@ -696,7 +670,6 @@ private void readOldGNUSparse() throws IOException {
currEntry.getSparseHeaders().addAll(entry.getSparseHeaders());
} while (entry.isExtended());
}
-
// sparse headers are all done reading, we need to build
// sparse input streams using these sparse headers
buildSparseInputStreams();
@@ -714,7 +687,6 @@ protected byte[] readRecord() throws IOException {
if (readCount != getRecordSize()) {
return null;
}
-
return recordBuffer;
}
@@ -804,12 +776,10 @@ public long skip(final long n) throws IOException {
if (n <= 0 || isDirectory()) {
return 0;
}
-
final long availableOfInputStream = in.available();
final long available = currEntry.getRealSize() - entryOffset;
final long numToSkip = Math.min(n, available);
long skipped;
-
if (!currEntry.isSparse()) {
skipped = IOUtils.skip(in, numToSkip);
// for non-sparse entry, we should get the bytes actually skipped
bytes along with
@@ -818,7 +788,6 @@ public long skip(final long n) throws IOException {
} else {
skipped = skipSparse(numToSkip);
}
-
count(skipped);
entryOffset += skipped;
return skipped;
@@ -835,9 +804,7 @@ private void skipRecordPadding() throws IOException {
final long numRecords = this.entrySize / getRecordSize() + 1;
final long padding = numRecords * getRecordSize() - this.entrySize;
long skipped = IOUtils.skip(in, padding);
-
skipped = getActuallySkipped(available, skipped, padding);
-
count(skipped);
}
}