Top Description Fields Constructors Methods
org.apache.commons.compress.archivers.ar

public Class ArArchiveEntry

extends Object
implements ArchiveEntry
Class Inheritance
All Implemented Interfaces
org.apache.commons.compress.archivers.ArchiveEntry
Imports
java.io.File, .IOException, java.nio.file.Files, .LinkOption, .Path, java.util.Date, .Objects, org.apache.commons.compress.archivers.ArchiveEntry

Represents an archive entry in the "ar" format.

Each AR archive starts with "!<arch>" followed by a LF. After these 8 bytes the archive entries are listed. The format of an entry header is as it follows:

START BYTE   END BYTE    NAME                    FORMAT      LENGTH
0            15          File name               ASCII       16
16           27          Modification timestamp  Decimal     12
28           33          Owner ID                Decimal     6
34           39          Group ID                Decimal     6
40           47          File mode               Octal       8
48           57          File size (bytes)       Decimal     10
58           59          File magic              \140\012    2

This specifies that an ar archive entry header contains 60 bytes.

Due to the limitation of the file name length to 16 bytes GNU and BSD has their own variants of this format. Currently Commons Compress can read but not write the GNU variant. It fully supports the BSD variant.

See Also
ar man page

Field Summary

Modifier and TypeField and Description
private static final int
private final int
public static final String
HEADER

The header for each entry

private final long
private final long
private final int
private final String
name

SVR4/GNU adds a trailing / to names; BSD does not.

public static final String
TRAILER

The trailer for each entry

private final int

Constructor Summary

AccessConstructor and Description
public
ArArchiveEntry(final File
the file to create an entry from
inputFile
,
final String
the name of the entry
entryName
)

Creates a new instance using the attributes of the given file

public
ArArchiveEntry(final Path
the file to create an entry from
inputPath
,
final String
the name of the entry
entryName
,
final LinkOption...
options indicating how symbolic links are handled.
options
)

Creates a new instance using the attributes of the given file

public
ArArchiveEntry(final String
name of the entry
name
,
final long
length of the entry in bytes
length
)

Constructs a new instance using a couple of default values.

public
ArArchiveEntry(final String
name of the entry
name
,
final long
length of the entry in bytes
length
,
final int
numeric user id
userId
,
final int
numeric group id
groupId
,
final int
file mode
mode
,
final long
last modified time in seconds since the epoch
lastModified
)

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int

Returns:

the group ID.
getGroupId
()

Gets the group ID.

public long

Returns:

the last modified date.
getLastModified
()

Gets the last modified time in seconds since the epoch.

public Date
public long

Returns:

the length.
getLength
()

Gets the length.

public int

Returns:

the mode.
getMode
()

Gets the mode.

public String
getName()

Implements org.apache.commons.compress.archivers.ArchiveEntry.getName.

Gets the name of the entry in this archive.
public long
getSize()

Implements org.apache.commons.compress.archivers.ArchiveEntry.getSize.

Gets the uncompressed size of this entry.
public int

Returns:

the user ID.
getUserId
()

Gets the user ID.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
isDirectory()

Implements org.apache.commons.compress.archivers.ArchiveEntry.isDirectory.

Tests whether this entry refers to a directory (true).
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_MODEback to summary
private static final int DEFAULT_MODE
groupIdback to summary
private final int groupId
lastModifiedback to summary
private final long lastModified
lengthback to summary
private final long length
modeback to summary
private final int mode
nameback to summary
private final String name

SVR4/GNU adds a trailing / to names; BSD does not. They also vary in how names longer than 16 characters are represented. (Not yet fully supported by this implementation)

TRAILERback to summary
public static final String TRAILER

The trailer for each entry

userIdback to summary
private final int userId

Constructor Detail

ArArchiveEntryback to summary
public ArArchiveEntry(final File inputFile, final String entryName)

Creates a new instance using the attributes of the given file

Parameters
inputFile:File

the file to create an entry from

entryName:String

the name of the entry

ArArchiveEntryback to summary
public ArArchiveEntry(final Path inputPath, final String entryName, final LinkOption... options) throws IOException

Creates a new instance using the attributes of the given file

Parameters
inputPath:Path

the file to create an entry from

entryName:String

the name of the entry

options:LinkOption[]

options indicating how symbolic links are handled.

Exceptions
IOException:
if an I/O error occurs.
Since
1.21
ArArchiveEntryback to summary
public ArArchiveEntry(final String name, final long length)

Constructs a new instance using a couple of default values.

Sets userId and groupId to 0, the octal file mode to 644 and the last modified time to the current time.

Parameters
name:String

name of the entry

length:long

length of the entry in bytes

ArArchiveEntryback to summary
public ArArchiveEntry(final String name, final long length, final int userId, final int groupId, final int mode, final long lastModified)

Constructs a new instance.

Parameters
name:String

name of the entry

length:long

length of the entry in bytes

userId:int

numeric user id

groupId:int

numeric group id

mode:int

file mode

lastModified:long

last modified time in seconds since the epoch

Method Detail

equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getGroupIdback to summary
public int getGroupId()

Gets the group ID.

Returns:int

the group ID.

getLastModifiedback to summary
public long getLastModified()

Gets the last modified time in seconds since the epoch.

Returns:long

the last modified date.

getLastModifiedDateback to summary
public Date getLastModifiedDate()

Implements org.apache.commons.compress.archivers.ArchiveEntry.getLastModifiedDate.

Doc from org.apache.commons.compress.archivers.ArchiveEntry.getLastModifiedDate.

Gets the last modified date of this entry.

Returns:Date

the last modified date of this entry.

Annotations
@Override
getLengthback to summary
public long getLength()

Gets the length.

Returns:long

the length.

getModeback to summary
public int getMode()

Gets the mode.

Returns:int

the mode.

getNameback to summary
public String getName()

Implements org.apache.commons.compress.archivers.ArchiveEntry.getName.

Doc from org.apache.commons.compress.archivers.ArchiveEntry.getName.

Gets the name of the entry in this archive. May refer to a file or directory or other item.

This method returns the raw name as it is stored inside of the archive.

Returns:String

The name of this entry in the archive.

Annotations
@Override
getSizeback to summary
public long getSize()

Implements org.apache.commons.compress.archivers.ArchiveEntry.getSize.

Doc from org.apache.commons.compress.archivers.ArchiveEntry.getSize.

Gets the uncompressed size of this entry. May be -1 (SIZE_UNKNOWN) if the size is unknown

Returns:long

the uncompressed size of this entry.

Annotations
@Override
getUserIdback to summary
public int getUserId()

Gets the user ID.

Returns:int

the user ID.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isDirectoryback to summary
public boolean isDirectory()

Implements org.apache.commons.compress.archivers.ArchiveEntry.isDirectory.

Doc from org.apache.commons.compress.archivers.ArchiveEntry.isDirectory.

Tests whether this entry refers to a directory (true).

Returns:boolean

true if this entry refers to a directory.

Annotations
@Override