Class DumpArchiveInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.compress.archivers.ArchiveInputStream<DumpArchiveEntry>
org.apache.commons.compress.archivers.dump.DumpArchiveInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
The DumpArchiveInputStream reads a UNIX dump archive as an InputStream. Methods are provided to position at each successive entry in the archive, and the
read each entry as a normal input stream using read().
There doesn't seem to exist a hint on the encoding of string values in any piece documentation. Given the main purpose of dump/restore is backing up a system it seems very likely the format uses the current default encoding of the system.
- Since:
- 1.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DumpArchiveEntry
private byte[]
private static final String
private long
private long
private long
private boolean
private boolean
Map of ino -> dirent entry.private static final String
private final Map
<Integer, DumpArchiveEntry> Map of ino -> (directory) entry when we're missing one or more elements in the path.private final Queue
<DumpArchiveEntry> Queue of (directory) entries where we now have the full path.protected TapeInputStream
private final byte[]
private int
private int
private final DumpArchiveSummary
private final ZipEncoding
The encoding to use for file names and labels.Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor using the platform's default encoding for file names.DumpArchiveInputStream
(InputStream is, String encoding) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the stream for this entry.long
Gets the current number of bytes read from this stream.int
getCount()
Deprecated.Deprecated.Gets the next Archive Entry in this Stream.private String
getPath
(DumpArchiveEntry entry) Gets full path for specified archive entry, or null if there's a gap.Gets the archive summary information.static boolean
matches
(byte[] buffer, int length) Look at the first few bytes of the file to decide if it's a dump archive.int
read
(byte[] buf, int off, int len) Reads bytes from the current dump archive entry.private void
readBITS()
Read BITS segment.private void
readCLRI()
Read CLRI (deleted inode) segment.private void
Read directory entry.Methods inherited from class org.apache.commons.compress.archivers.ArchiveInputStream
canReadEntryData, count, count, forEach, getCharset, iterator, mark, markSupported, pushedBackBytes, read, reset
Methods inherited from class java.io.FilterInputStream
available, read, skip
-
Field Details
-
CURRENT_PATH_SEGMENT
- See Also:
-
PARENT_PATH_SEGMENT
- See Also:
-
summary
-
active
-
isClosed
private boolean isClosed -
hasHitEOF
private boolean hasHitEOF -
entrySize
private long entrySize -
entryOffset
private long entryOffset -
readIdx
private int readIdx -
readBuf
private final byte[] readBuf -
blockBuffer
private byte[] blockBuffer -
recordOffset
private int recordOffset -
filepos
private long filepos -
raw
-
names
Map of ino -> dirent entry. We can use this to reconstruct full paths. -
pending
Map of ino -> (directory) entry when we're missing one or more elements in the path. -
queue
Queue of (directory) entries where we now have the full path. -
zipEncoding
The encoding to use for file names and labels.
-
-
Constructor Details
-
DumpArchiveInputStream
Constructor using the platform's default encoding for file names.- Parameters:
is
- stream to read from- Throws:
ArchiveException
- on error
-
DumpArchiveInputStream
Constructs a new instance.- Parameters:
is
- stream to read fromencoding
- the encoding to use for file names, use null for the platform's default encoding- Throws:
ArchiveException
- on error- Since:
- 1.6
-
-
Method Details
-
matches
public static boolean matches(byte[] buffer, int length) Look at the first few bytes of the file to decide if it's a dump archive. With 32 bytes we can look at the magic value, with a full 1k we can verify the checksum.- Parameters:
buffer
- data to matchlength
- length of data- Returns:
- whether the buffer seems to contain dump data
-
close
Closes the stream for this entry.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
-
getBytesRead
public long getBytesRead()Description copied from class:ArchiveInputStream
Gets the current number of bytes read from this stream.- Overrides:
getBytesRead
in classArchiveInputStream<DumpArchiveEntry>
- Returns:
- the number of read bytes
-
getCount
Deprecated.Description copied from class:ArchiveInputStream
Gets the current number of bytes read from this stream.- Overrides:
getCount
in classArchiveInputStream<DumpArchiveEntry>
- Returns:
- the number of read bytes
-
getNextDumpEntry
Deprecated.UsegetNextEntry()
.Reads the next entry.- Returns:
- the next entry
- Throws:
IOException
- on error
-
getNextEntry
Description copied from class:ArchiveInputStream
Gets the next Archive Entry in this Stream.- Specified by:
getNextEntry
in classArchiveInputStream<DumpArchiveEntry>
- Returns:
- the next entry, or
null
if there are no more entries. - Throws:
IOException
- if the next entry could not be read.
-
getPath
Gets full path for specified archive entry, or null if there's a gap.- Parameters:
entry
-- Returns:
- full path for specified archive entry, or null if there's a gap.
- Throws:
DumpArchiveException
- Infinite loop detected in directory entries.
-
getSummary
Gets the archive summary information.- Returns:
- the summary
-
read
Reads bytes from the current dump archive entry. This method is aware of the boundaries of the current entry in the archive and will deal with them as if they were this stream's start and EOF.- Overrides:
read
in classFilterInputStream
- Parameters:
buf
- The buffer into which to place bytes read.off
- The offset at which to place bytes read.len
- The number of bytes to read.- Returns:
- The number of bytes read, or -1 at EOF.
- Throws:
IOException
- on error
-
readBITS
Read BITS segment.- Throws:
IOException
-
readCLRI
Read CLRI (deleted inode) segment.- Throws:
IOException
-
readDirectoryEntry
Read directory entry.- Throws:
IOException
-
getNextEntry()
.