You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/05/31 12:58:49 UTC
(commons-compress) 07/07: Internal refactoring
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
commit fc3fa9c10f512f81434b0f5b6f04cd7cf8858d0c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 31 08:58:37 2025 -0400
Internal refactoring
---
.../compress/archivers/tar/TarArchiveEntry.java | 24 ++++++++++++----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
index e5c3649af..c3389bde6 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
@@ -858,10 +858,7 @@ public Map<String, String> getExtraPaxHeaders() {
* @return this entry's file or null if the entry was not created from a file.
*/
public File getFile() {
- if (file == null) {
- return null;
- }
- return file.toFile();
+ return file != null ? file.toFile() : null;
}
/**
@@ -922,7 +919,7 @@ public FileTime getLastModifiedTime() {
* @since 1.23
*/
public byte getLinkFlag() {
- return this.linkFlag;
+ return linkFlag;
}
/**
@@ -970,8 +967,7 @@ public int getMode() {
* @see TarArchiveEntry#getLastModifiedTime()
*/
public Date getModTime() {
- final FileTime fileTime = mTime;
- return FileTimes.toDate(fileTime);
+ return FileTimes.toDate(mTime);
}
/**
@@ -1449,15 +1445,14 @@ private void parseTarHeader(final byte[] header, final ZipEncoding encoding, fin
private void parseTarHeader(final Map<String, String> globalPaxHeaders, final byte[] header, final ZipEncoding encoding, final boolean oldStyle,
final boolean lenient) throws IOException {
try {
- parseTarHeaderUnwrapped(globalPaxHeaders, header, encoding, oldStyle, lenient);
+ parseUstarHeaderBlock(globalPaxHeaders, header, encoding, oldStyle, lenient);
} catch (final IllegalArgumentException ex) {
throw new IOException("Corrupted TAR archive.", ex);
}
}
- private void parseTarHeaderUnwrapped(final Map<String, String> globalPaxHeaders, final byte[] header, final ZipEncoding encoding, final boolean oldStyle,
- final boolean lenient) throws IOException {
- int offset = 0;
+ private int parseTarHeaderBlock(final byte[] header, final ZipEncoding encoding, final boolean oldStyle, final boolean lenient, int offset)
+ throws IOException {
name = oldStyle ? TarUtils.parseName(header, offset, NAMELEN) : TarUtils.parseName(header, offset, NAMELEN, encoding);
offset += NAMELEN;
mode = (int) parseOctalOrBinary(header, offset, MODELEN, lenient);
@@ -1477,6 +1472,13 @@ private void parseTarHeaderUnwrapped(final Map<String, String> globalPaxHeaders,
offset += CHKSUMLEN;
linkFlag = header[offset++];
linkName = oldStyle ? TarUtils.parseName(header, offset, NAMELEN) : TarUtils.parseName(header, offset, NAMELEN, encoding);
+ return offset;
+ }
+
+ private void parseUstarHeaderBlock(final Map<String, String> globalPaxHeaders, final byte[] header, final ZipEncoding encoding, final boolean oldStyle,
+ final boolean lenient) throws IOException {
+ int offset = 0;
+ offset = parseTarHeaderBlock(header, encoding, oldStyle, lenient, offset);
offset += NAMELEN;
magic = TarUtils.parseName(header, offset, MAGICLEN);
offset += MAGICLEN;