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

public Class ArArchiveInputStream

extends ArchiveInputStream<ArArchiveEntry>
Class Inheritance
Imports
java.io.EOFException, .IOException, .InputStream, java.nio.charset.StandardCharsets, java.util.Arrays, java.util.regex.Pattern, org.apache.commons.compress.archivers.ArchiveInputStream, org.apache.commons.compress.utils.ArchiveUtils, .IOUtils, .ParsingUtils

Implements the "ar" archive format as an input stream.

Field Summary

Modifier and TypeField and Description
private static final Pattern
pack-priv static final String
private static final int
private boolean
private ArArchiveEntry
private long
entryOffset

The offset where the current entry started.

private static final int
private static final int
private static final Pattern
private static final String
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private final byte[]
metaData

Cached buffer for meta data - must only be used locally in the class (COMPRESS-172 - reduce garbage collection).

private static final int
private static final int
private byte[]
namebuffer

Storage area for extra long names (GNU ar).

private long
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public
ArArchiveInputStream(final InputStream
the ar input stream
inputStream
)

Constructs an Ar input stream with the referenced stream

Method Summary

Modifier and TypeMethod and Description
private int
asInt(final byte[] byteArray, final int offset, final int len)

private int
asInt(final byte[] byteArray, final int offset, final int len, final boolean treatBlankAsZero)

private int
asInt(final byte[] byteArray, final int offset, final int len, final int base)

private int
asInt(final byte[] byteArray, final int offset, final int len, final int base, final boolean treatBlankAsZero)

private long
asLong(final byte[] byteArray, final int offset, final int len)

public void
close()

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.
private String
getBSDLongName(final 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

Returns:

the extended file name; without trailing "/" if present.
getExtendedName
(final int
pointer to entry within the buffer
offset
)

Gets an extended name from the GNU extended name buffer.

public ArArchiveEntry

Returns:

the next AR entry.
getNextArEntry
()

Deprecated Use getNextEntry().
Returns the next AR entry in this stream.
public ArArchiveEntry
getNextEntry()

Implements abstract org.apache.commons.compress.archivers.ArchiveInputStream.getNextEntry.

Gets the next Archive Entry in this Stream.
private static boolean
isBSDLongName(final 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(final 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(final String name)

Is this the name of the "Archive String Table" as used by SVR4/GNU to store long file names?

public static boolean

Returns:

true, if this stream is an Ar archive stream, false otherwise
matches
(final byte[]
the bytes to check
signature
,
final int
the number of bytes to check
length
)

Checks if the signature matches ASCII "!

public int
read(final byte[]
the buffer into which the data is read.
b
,
final int
the start offset in array b at which the data is written.
off
,
final int
the maximum number of bytes to read.
len
)

Overrides java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes.
private ArArchiveEntry
readGNUStringTable(final byte[] length, final int offset, final int len)

Reads the GNU archive String Table.

private void
trackReadBytes(final long read)

Inherited from org.apache.commons.compress.archivers.ArchiveInputStream:
canReadEntryDatacountcountgetBytesReadgetCharsetgetCountpushedBackBytesread

Field Detail

BSD_LONGNAME_PATTERNback to summary
private static final Pattern BSD_LONGNAME_PATTERN
BSD_LONGNAME_PREFIXback to summary
pack-priv static final String BSD_LONGNAME_PREFIX
BSD_LONGNAME_PREFIX_LENback to summary
private static final int BSD_LONGNAME_PREFIX_LEN
closedback to summary
private boolean closed
currentEntryback to summary
private ArArchiveEntry currentEntry
entryOffsetback to summary
private long entryOffset

The offset where the current entry started. -1 if no entry has been called

FILE_MODE_LENback to summary
private static final int FILE_MODE_LEN
FILE_MODE_OFFSETback to summary
private static final int FILE_MODE_OFFSET
GNU_LONGNAME_PATTERNback to summary
private static final Pattern GNU_LONGNAME_PATTERN
GNU_STRING_TABLE_NAMEback to summary
private static final String GNU_STRING_TABLE_NAME
GROUP_ID_LENback to summary
private static final int GROUP_ID_LEN
GROUP_ID_OFFSETback to summary
private static final int GROUP_ID_OFFSET
LAST_MODIFIED_LENback to summary
private static final int LAST_MODIFIED_LEN
LAST_MODIFIED_OFFSETback to summary
private static final int LAST_MODIFIED_OFFSET
LENGTH_LENback to summary
private static final int LENGTH_LEN
LENGTH_OFFSETback to summary
private static final int LENGTH_OFFSET
metaDataback to summary
private final byte[] metaData

Cached buffer for meta data - must only be used locally in the class (COMPRESS-172 - reduce garbage collection).

NAME_LENback to summary
private static final int NAME_LEN
NAME_OFFSETback to summary
private static final int NAME_OFFSET
namebufferback to summary
private byte[] namebuffer

Storage area for extra long names (GNU ar).

offsetback to summary
private long offset
USER_ID_LENback to summary
private static final int USER_ID_LEN
USER_ID_OFFSETback to summary
private static final int USER_ID_OFFSET

Constructor Detail

ArArchiveInputStreamback to summary
public ArArchiveInputStream(final InputStream inputStream)

Constructs an Ar input stream with the referenced stream

Parameters
inputStream:InputStream

the ar input stream

Method Detail

asIntback to summary
private int asInt(final byte[] byteArray, final int offset, final int len) throws IOException
asIntback to summary
private int asInt(final byte[] byteArray, final int offset, final int len, final boolean treatBlankAsZero) throws IOException
asIntback to summary
private int asInt(final byte[] byteArray, final int offset, final int len, final int base) throws IOException
asIntback to summary
private int asInt(final byte[] byteArray, final int offset, final int len, final int base, final boolean treatBlankAsZero) throws IOException
asLongback to summary
private long asLong(final byte[] byteArray, final int offset, final int len) throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.FilterInputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getBSDLongNameback to summary
private String getBSDLongName(final String bsdLongName) throws IOException

Reads the real name from the current stream assuming the very first bytes to be read are the real file name.

Since
1.3
See Also
isBSDLongName
getExtendedNameback to summary
private String getExtendedName(final int offset) throws IOException

Gets an extended name from the GNU extended name buffer.

Parameters
offset:int

pointer to entry within the buffer

Returns:String

the extended file name; without trailing "/" if present.

Exceptions
IOException:
if name not found or buffer not set up
getNextArEntryback to summary
public ArArchiveEntry getNextArEntry() throws IOException

Deprecated

Use getNextEntry().

Returns the next AR entry in this stream.

Returns:ArArchiveEntry

the next AR entry.

Annotations
@Deprecated
Exceptions
IOException:
if the entry could not be read
getNextEntryback to summary
public ArArchiveEntry getNextEntry() throws IOException

Implements abstract org.apache.commons.compress.archivers.ArchiveInputStream.getNextEntry.

Doc from org.apache.commons.compress.archivers.ArchiveInputStream.getNextEntry.

Gets the next Archive Entry in this Stream.

Returns:ArArchiveEntry

the next entry, or null if there are no more entries

Annotations
@Override
Exceptions
IOException:
if the next entry could not be read
isBSDLongNameback to summary
private static boolean isBSDLongName(final 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
isGNULongNameback to summary
private boolean isGNULongName(final 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
isGNUStringTableback to summary
private static boolean isGNUStringTable(final 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.

matchesback to summary
public static boolean matches(final byte[] signature, final int length)

Checks if the signature matches ASCII "!<arch>" followed by a single LF control character

Parameters
signature:byte[]

the bytes to check

length:int

the number of bytes to check

Returns:boolean

true, if this stream is an Ar archive stream, false otherwise

readback to summary
public int read(final byte[] b, final int off, final int len) throws IOException

Overrides java.io.FilterInputStream.read.

Doc from java.io.FilterInputStream.read.

Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

Parameters
b:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readGNUStringTableback to summary
private ArArchiveEntry readGNUStringTable(final byte[] length, final int offset, final int len) throws IOException

Reads the GNU archive String Table.

See Also
isGNUStringTable
trackReadBytesback to summary
private void trackReadBytes(final long read)