- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- kala.compress.archivers.ArchiveInputStream<ArArchiveEntry>
-
- kala.compress.archivers.ar.ArArchiveInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ArArchiveInputStream extends ArchiveInputStream<ArArchiveEntry>
Implements the "ar" archive format as an input stream.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.PatternBSD_LONGNAME_PATTERN(package private) static java.lang.StringBSD_LONGNAME_PREFIXprivate static intBSD_LONGNAME_PREFIX_LENprivate booleanclosedprivate ArArchiveEntrycurrentEntryprivate longentryOffsetThe offset where the current entry started.private static intFILE_MODE_LENprivate static intFILE_MODE_OFFSETprivate static java.util.regex.PatternGNU_LONGNAME_PATTERNprivate static java.lang.StringGNU_STRING_TABLE_NAMEprivate static intGROUP_ID_LENprivate static intGROUP_ID_OFFSETprivate static intLAST_MODIFIED_LENprivate static intLAST_MODIFIED_OFFSETprivate static intLENGTH_LENprivate static intLENGTH_OFFSETprivate byte[]metaDataCached buffer for meta data - must only be used locally in the class (COMPRESS-172 - reduce garbage collection).private static intNAME_LENprivate static intNAME_OFFSETprivate byte[]namebufferStorage area for extra long names (GNU ar).private longoffsetprivate static intUSER_ID_LENprivate static intUSER_ID_OFFSET-
Fields inherited from class kala.compress.archivers.ArchiveInputStream
encoding
-
-
Constructor Summary
Constructors Constructor Description ArArchiveInputStream(java.io.InputStream inputStream)Constructs an Ar input stream with the referenced stream
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intasInt(byte[] byteArray, int offset, int len)private intasInt(byte[] byteArray, int offset, int len, boolean treatBlankAsZero)private intasInt(byte[] byteArray, int offset, int len, int base)private intasInt(byte[] byteArray, int offset, int len, int base, boolean treatBlankAsZero)private longasLong(byte[] byteArray, int offset, int len)voidclose()private java.lang.StringgetBSDLongName(java.lang.String bsdLongName)Reads the real name from the current stream assuming the very first bytes to be read are the real file name.private java.lang.StringgetExtendedName(int offset)Gets an extended name from the GNU extended name buffer.ArArchiveEntrygetNextEntry()Gets the next Archive Entry in this Stream.private static booleanisBSDLongName(java.lang.String name)Does the name look like it is a long name (or a name containing spaces) as encoded by BSD ar?private booleanisGNULongName(java.lang.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 booleanisGNUStringTable(java.lang.String name)Is this the name of the "Archive String Table" as used by SVR4/GNU to store long file names?static booleanmatches(byte[] signature, int length)Checks if the signature matches ASCII "!<arch>" followed by a single LF control characterintread(byte[] b, int off, int len)private ArArchiveEntryreadGNUStringTable(byte[] length, int offset, int len)Reads the GNU archive String Table.private voidtrackReadBytes(long read)-
Methods inherited from class kala.compress.archivers.ArchiveInputStream
canReadEntryData, count, count, forEach, getBytesRead, getEncoding, iterator, mark, markSupported, pushedBackBytes, read, reset
-
-
-
-
Field Detail
-
NAME_OFFSET
private static final int NAME_OFFSET
- See Also:
- Constant Field Values
-
NAME_LEN
private static final int NAME_LEN
- See Also:
- Constant Field Values
-
LAST_MODIFIED_OFFSET
private static final int LAST_MODIFIED_OFFSET
- See Also:
- Constant Field Values
-
LAST_MODIFIED_LEN
private static final int LAST_MODIFIED_LEN
- See Also:
- Constant Field Values
-
USER_ID_OFFSET
private static final int USER_ID_OFFSET
- See Also:
- Constant Field Values
-
USER_ID_LEN
private static final int USER_ID_LEN
- See Also:
- Constant Field Values
-
GROUP_ID_OFFSET
private static final int GROUP_ID_OFFSET
- See Also:
- Constant Field Values
-
GROUP_ID_LEN
private static final int GROUP_ID_LEN
- See Also:
- Constant Field Values
-
FILE_MODE_OFFSET
private static final int FILE_MODE_OFFSET
- See Also:
- Constant Field Values
-
FILE_MODE_LEN
private static final int FILE_MODE_LEN
- See Also:
- Constant Field Values
-
LENGTH_OFFSET
private static final int LENGTH_OFFSET
- See Also:
- Constant Field Values
-
LENGTH_LEN
private static final int LENGTH_LEN
- See Also:
- Constant Field Values
-
BSD_LONGNAME_PREFIX
static final java.lang.String BSD_LONGNAME_PREFIX
- See Also:
- Constant Field Values
-
BSD_LONGNAME_PREFIX_LEN
private static final int BSD_LONGNAME_PREFIX_LEN
-
BSD_LONGNAME_PATTERN
private static final java.util.regex.Pattern BSD_LONGNAME_PATTERN
-
GNU_STRING_TABLE_NAME
private static final java.lang.String GNU_STRING_TABLE_NAME
- See Also:
- Constant Field Values
-
GNU_LONGNAME_PATTERN
private static final java.util.regex.Pattern GNU_LONGNAME_PATTERN
-
offset
private long offset
-
closed
private boolean closed
-
currentEntry
private ArArchiveEntry currentEntry
-
namebuffer
private byte[] namebuffer
Storage area for extra long names (GNU ar).
-
entryOffset
private long entryOffset
The offset where the current entry started. -1 if no entry has been called
-
metaData
private final byte[] metaData
Cached buffer for meta data - must only be used locally in the class (COMPRESS-172 - reduce garbage collection).
-
-
Method Detail
-
isBSDLongName
private static boolean isBSDLongName(java.lang.String name)
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
-
isGNUStringTable
private static boolean isGNUStringTable(java.lang.String name)
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.
-
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
-
asInt
private int asInt(byte[] byteArray, int offset, int len) throws java.io.IOException- Throws:
java.io.IOException
-
asInt
private int asInt(byte[] byteArray, int offset, int len, boolean treatBlankAsZero) throws java.io.IOException- Throws:
java.io.IOException
-
asInt
private int asInt(byte[] byteArray, int offset, int len, int base) throws java.io.IOException- Throws:
java.io.IOException
-
asInt
private int asInt(byte[] byteArray, int offset, int len, int base, boolean treatBlankAsZero) throws java.io.IOException- Throws:
java.io.IOException
-
asLong
private long asLong(byte[] byteArray, int offset, int len) throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
getBSDLongName
private java.lang.String getBSDLongName(java.lang.String bsdLongName) throws java.io.IOExceptionReads the real name from the current stream assuming the very first bytes to be read are the real file name.- Throws:
java.io.IOException- Since:
- 1.3
- See Also:
isBSDLongName(java.lang.String)
-
getExtendedName
private java.lang.String getExtendedName(int offset) throws java.io.IOExceptionGets 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:
java.io.IOException- if name not found or buffer not set up
-
getNextEntry
public ArArchiveEntry getNextEntry() throws java.io.IOException
Description copied from class:ArchiveInputStreamGets the next Archive Entry in this Stream.- Specified by:
getNextEntryin classArchiveInputStream<ArArchiveEntry>- Returns:
- the next entry, or
nullif there are no more entries. - Throws:
java.io.IOException- if the next entry could not be read.
-
isGNULongName
private boolean isGNULongName(java.lang.String name)
Does the name look like it is a long name (or a name containing spaces) as encoded by SVR4/GNU ar?- See Also:
isGNUStringTable(java.lang.String)
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
readGNUStringTable
private ArArchiveEntry readGNUStringTable(byte[] length, int offset, int len) throws java.io.IOException
Reads the GNU archive String Table.- Throws:
java.io.IOException- See Also:
isGNUStringTable(java.lang.String)
-
trackReadBytes
private void trackReadBytes(long read)
-
-