private class PackInserter.PackStream
extends java.io.OutputStream
Backed by two views of the same open file descriptor: a random-access file, and an output stream. Seeking in the file causes subsequent writes to the output stream to occur wherever the file pointer is pointing, so we need to take care to always seek to the end of the file before writing a new object.
Callers should always use seek(long) to seek, rather than reaching
into the file member. As long as this contract is followed, calls to write(byte[], int, int) are guaranteed to write at the end of the file,
even if there have been intermediate seeks.
| Modifier and Type | Field and Description |
|---|---|
private boolean |
atEnd |
(package private) java.util.zip.DeflaterOutputStream |
compress |
(package private) java.util.zip.CRC32 |
crc32 |
private java.util.zip.Deflater |
deflater |
private java.io.RandomAccessFile |
file |
(package private) byte[] |
hdrBuf |
private CountingOutputStream |
out |
| Constructor and Description |
|---|
PackStream(java.io.File pack) |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
beginObject(int objectType,
long length) |
void |
close() |
private int |
encodeTypeSize(int type,
long rawLength) |
(package private) byte[] |
finishPack() |
(package private) long |
getOffset() |
(package private) byte[] |
inflate(long filePos,
int len) |
(package private) void |
seek(long offset) |
private int |
setInput(long filePos,
java.util.zip.Inflater inf,
byte[] buf) |
void |
write(byte[] data,
int off,
int len) |
void |
write(int b) |
final byte[] hdrBuf
final java.util.zip.CRC32 crc32
final java.util.zip.DeflaterOutputStream compress
private final java.io.RandomAccessFile file
private final CountingOutputStream out
private final java.util.zip.Deflater deflater
private boolean atEnd
PackStream(java.io.File pack)
throws java.io.IOException
java.io.IOExceptionlong getOffset()
void seek(long offset) throws java.io.IOException
java.io.IOExceptionvoid beginObject(int objectType,
long length)
throws java.io.IOException
java.io.IOExceptionprivate int encodeTypeSize(int type,
long rawLength)
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void write(byte[] data,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionbyte[] finishPack()
throws java.io.IOException
java.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreamjava.io.IOExceptionbyte[] inflate(long filePos,
int len)
throws java.io.IOException,
java.util.zip.DataFormatException
java.io.IOExceptionjava.util.zip.DataFormatExceptionprivate int setInput(long filePos,
java.util.zip.Inflater inf,
byte[] buf)
throws java.io.IOException
java.io.IOException