Class ArArchiveInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.compress.archivers.ArchiveInputStream
org.apache.commons.compress.archivers.ar.ArArchiveInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Implements the "ar" archive format as an input stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
(package private) static final String
private static final int
private boolean
private ArArchiveEntry
private long
private static final int
private static final int
private static final String
private static final String
private static final int
private static final int
private final InputStream
private static final int
private static final int
private static final int
private static final int
private final byte[]
private static final int
private static final int
private byte[]
private long
private static final int
private static final int
-
Constructor Summary
ConstructorsConstructorDescriptionArArchiveInputStream
(InputStream pInput) Constructs an Ar input stream with the referenced stream -
Method Summary
Modifier and TypeMethodDescriptionprivate int
asInt
(byte[] byteArray, int offset, int len) private int
asInt
(byte[] byteArray, int offset, int len, boolean treatBlankAsZero) private int
asInt
(byte[] byteArray, int offset, int len, int base) private int
asInt
(byte[] byteArray, int offset, int len, int base, boolean treatBlankAsZero) private long
asLong
(byte[] byteArray, int offset, int len) void
close()
private String
getBSDLongName
(String bsdLongName) Reads the real name from the current stream assuming the very first bytes to be read are the real file name.private String
getExtendedName
(int offset) Get an extended name from the GNU extended name buffer.Returns the next AR entry in this stream.Returns the next Archive Entry in this Stream.private static boolean
isBSDLongName
(String name) Does the name look like it is a long name (or a name containing spaces) as encoded by BSD ar?private boolean
isGNULongName
(String name) Does the name look like it is a long name (or a name containing spaces) as encoded by SVR4/GNU ar?private static boolean
isGNUStringTable
(String name) Is this the name of the "Archive String Table" as used by SVR4/GNU to store long file names?static boolean
matches
(byte[] signature, int length) Checks if the signature matches ASCII "!<arch>" followed by a single LF control characterint
read
(byte[] b, int off, int len) private ArArchiveEntry
readGNUStringTable
(byte[] length, int offset, int len) Reads the GNU archive String Table.private void
trackReadBytes
(long read) Methods inherited from class org.apache.commons.compress.archivers.ArchiveInputStream
canReadEntryData, count, count, getBytesRead, getCount, pushedBackBytes, read
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, readAllBytes, readNBytes, reset, skip, transferTo
-
Field Details
-
input
-
offset
private long offset -
closed
private boolean closed -
currentEntry
-
namebuffer
private byte[] namebuffer -
entryOffset
private long entryOffset -
NAME_OFFSET
private static final int NAME_OFFSET- See Also:
-
NAME_LEN
private static final int NAME_LEN- See Also:
-
LAST_MODIFIED_OFFSET
private static final int LAST_MODIFIED_OFFSET- See Also:
-
LAST_MODIFIED_LEN
private static final int LAST_MODIFIED_LEN- See Also:
-
USER_ID_OFFSET
private static final int USER_ID_OFFSET- See Also:
-
USER_ID_LEN
private static final int USER_ID_LEN- See Also:
-
GROUP_ID_OFFSET
private static final int GROUP_ID_OFFSET- See Also:
-
GROUP_ID_LEN
private static final int GROUP_ID_LEN- See Also:
-
FILE_MODE_OFFSET
private static final int FILE_MODE_OFFSET- See Also:
-
FILE_MODE_LEN
private static final int FILE_MODE_LEN- See Also:
-
LENGTH_OFFSET
private static final int LENGTH_OFFSET- See Also:
-
LENGTH_LEN
private static final int LENGTH_LEN- See Also:
-
metaData
private final byte[] metaData -
BSD_LONGNAME_PREFIX
- See Also:
-
BSD_LONGNAME_PREFIX_LEN
private static final int BSD_LONGNAME_PREFIX_LEN -
BSD_LONGNAME_PATTERN
- See Also:
-
GNU_STRING_TABLE_NAME
- See Also:
-
GNU_LONGNAME_PATTERN
- See Also:
-
-
Constructor Details
-
ArArchiveInputStream
Constructs an Ar input stream with the referenced stream- Parameters:
pInput
- the ar input stream
-
-
Method Details
-
getNextArEntry
Returns the next AR entry in this stream.- Returns:
- the next AR entry.
- Throws:
IOException
- if the entry could not be read
-
getExtendedName
Get an extended name from the GNU extended name buffer.- Parameters:
offset
- pointer to entry within the buffer- Returns:
- the extended file name; without trailing "/" if present.
- Throws:
IOException
- if name not found or buffer not set up
-
asLong
private long asLong(byte[] byteArray, int offset, int len) -
asInt
private int asInt(byte[] byteArray, int offset, int len) -
asInt
private int asInt(byte[] byteArray, int offset, int len, boolean treatBlankAsZero) -
asInt
private int asInt(byte[] byteArray, int offset, int len, int base) -
asInt
private int asInt(byte[] byteArray, int offset, int len, int base, boolean treatBlankAsZero) -
getNextEntry
Description copied from class:ArchiveInputStream
Returns the next Archive Entry in this Stream.- Specified by:
getNextEntry
in classArchiveInputStream
- Returns:
- the next entry,
or
null
if there are no more entries - Throws:
IOException
- if the next entry could not be read
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
matches
public static boolean matches(byte[] signature, int length) Checks if the signature matches ASCII "!<arch>" followed by a single LF control character- Parameters:
signature
- the bytes to checklength
- the number of bytes to check- Returns:
- true, if this stream is an Ar archive stream, false otherwise
-
isBSDLongName
Does the name look like it is a long name (or a name containing spaces) as encoded by BSD ar?From the FreeBSD ar(5) man page:
BSD In the BSD variant, names that are shorter than 16 characters and without embedded spaces are stored directly in this field. If a name has an embedded space, or if it is longer than 16 characters, then the string "#1/" followed by the decimal represen- tation of the length of the file name is placed in this field. The actual file name is stored immedi- ately after the archive header. The content of the archive member follows the file name. The ar_size field of the header (see below) will then hold the sum of the size of the file name and the size of the member.
- Since:
- 1.3
-
getBSDLongName
Reads the real name from the current stream assuming the very first bytes to be read are the real file name.- Throws:
IOException
- Since:
- 1.3
- See Also:
-
isGNUStringTable
Is this the name of the "Archive String Table" as used by SVR4/GNU to store long file names?GNU ar stores multiple extended file names in the data section of a file with the name "//", this record is referred to by future headers.
A header references an extended file name by storing a "/" followed by a decimal offset to the start of the file name in the extended file name data section.
The format of the "//" file itself is simply a list of the long file names, each separated by one or more LF characters. Note that the decimal offsets are number of characters, not line or string number within the "//" file.
-
trackReadBytes
private void trackReadBytes(long read) -
readGNUStringTable
Reads the GNU archive String Table.- Throws:
IOException
- See Also:
-
isGNULongName
Does the name look like it is a long name (or a name containing spaces) as encoded by SVR4/GNU ar?- See Also:
-