Module kala.compress.archivers.dump
Package kala.compress.archivers.dump
Class DumpArchiveInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- kala.compress.archivers.ArchiveInputStream<DumpArchiveEntry>
-
- kala.compress.archivers.dump.DumpArchiveInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class DumpArchiveInputStream extends ArchiveInputStream<DumpArchiveEntry>
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
Fields Modifier and Type Field Description private DumpArchiveEntryactiveprivate byte[]blockBufferprivate static java.lang.StringCURRENT_PATH_SEGMENTprivate longentryOffsetprivate longentrySizeprivate longfileposprivate booleanhasHitEOFprivate booleanisClosedprivate java.util.Map<java.lang.Integer,Dirent>namesMap of ino -> dirent entry.private static java.lang.StringPARENT_PATH_SEGMENTprivate java.util.Map<java.lang.Integer,DumpArchiveEntry>pendingMap of ino -> (directory) entry when we're missing one or more elements in the path.private java.util.Queue<DumpArchiveEntry>queueQueue of (directory) entries where we now have the full path.protected TapeInputStreamrawprivate byte[]readBufprivate intreadIdxprivate intrecordOffsetprivate DumpArchiveSummarysummary-
Fields inherited from class kala.compress.archivers.ArchiveInputStream
encoding
-
-
Constructor Summary
Constructors Constructor Description DumpArchiveInputStream(java.io.InputStream is)Constructor using the UTF-8 for file names.DumpArchiveInputStream(java.io.InputStream is, java.nio.charset.Charset encoding)Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the stream for this entry.longgetBytesRead()Gets the current number of bytes read from this stream.DumpArchiveEntrygetNextEntry()Gets the next Archive Entry in this Stream.private java.lang.StringgetPath(DumpArchiveEntry entry)Gets full path for specified archive entry, or null if there's a gap.DumpArchiveSummarygetSummary()Gets the archive summary information.static booleanmatches(byte[] buffer, int length)Look at the first few bytes of the file to decide if it's a dump archive.intread(byte[] buf, int off, int len)Reads bytes from the current dump archive entry.private voidreadBITS()Read BITS segment.private voidreadCLRI()Read CLRI (deleted inode) segment.private voidreadDirectoryEntry(DumpArchiveEntry entry)Read directory entry.-
Methods inherited from class kala.compress.archivers.ArchiveInputStream
canReadEntryData, count, count, forEach, getEncoding, iterator, mark, markSupported, pushedBackBytes, read, reset
-
-
-
-
Field Detail
-
CURRENT_PATH_SEGMENT
private static final java.lang.String CURRENT_PATH_SEGMENT
- See Also:
- Constant Field Values
-
PARENT_PATH_SEGMENT
private static final java.lang.String PARENT_PATH_SEGMENT
- See Also:
- Constant Field Values
-
summary
private final DumpArchiveSummary summary
-
active
private DumpArchiveEntry 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
protected TapeInputStream raw
-
names
private final java.util.Map<java.lang.Integer,Dirent> names
Map of ino -> dirent entry. We can use this to reconstruct full paths.
-
pending
private final java.util.Map<java.lang.Integer,DumpArchiveEntry> pending
Map of ino -> (directory) entry when we're missing one or more elements in the path.
-
queue
private final java.util.Queue<DumpArchiveEntry> queue
Queue of (directory) entries where we now have the full path.
-
-
Constructor Detail
-
DumpArchiveInputStream
public DumpArchiveInputStream(java.io.InputStream is) throws ArchiveExceptionConstructor using the UTF-8 for file names.- Parameters:
is- stream to read from- Throws:
ArchiveException- on error
-
DumpArchiveInputStream
public DumpArchiveInputStream(java.io.InputStream is, java.nio.charset.Charset encoding) throws ArchiveExceptionConstructs a new instance.- Parameters:
is- stream to read fromencoding- the encoding to use for file names, use null for the UTF-8- Throws:
ArchiveException- on error- Since:
- 1.27.1-0
-
-
Method Detail
-
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
public void close() throws java.io.IOExceptionCloses the stream for this entry.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
getBytesRead
public long getBytesRead()
Description copied from class:ArchiveInputStreamGets the current number of bytes read from this stream.- Overrides:
getBytesReadin classArchiveInputStream<DumpArchiveEntry>- Returns:
- the number of read bytes.
-
getNextEntry
public DumpArchiveEntry getNextEntry() throws java.io.IOException
Description copied from class:ArchiveInputStreamGets the next Archive Entry in this Stream.- Specified by:
getNextEntryin classArchiveInputStream<DumpArchiveEntry>- Returns:
- the next entry, or
nullif there are no more entries. - Throws:
java.io.IOException- if the next entry could not be read.
-
getPath
private java.lang.String getPath(DumpArchiveEntry entry) throws DumpArchiveException
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
public DumpArchiveSummary getSummary()
Gets the archive summary information.- Returns:
- the summary
-
read
public int read(byte[] buf, int off, int len) throws java.io.IOExceptionReads 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:
readin classjava.io.FilterInputStream- 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:
java.io.IOException- on error
-
readBITS
private void readBITS() throws java.io.IOExceptionRead BITS segment.- Throws:
java.io.IOException
-
readCLRI
private void readCLRI() throws java.io.IOExceptionRead CLRI (deleted inode) segment.- Throws:
java.io.IOException
-
readDirectoryEntry
private void readDirectoryEntry(DumpArchiveEntry entry) throws java.io.IOException
Read directory entry.- Throws:
java.io.IOException
-
-