Class PackInserter.PackStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.eclipse.jgit.internal.storage.file.PackInserter.PackStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
- Enclosing class:
- PackInserter
private class PackInserter.PackStream extends java.io.OutputStreamStream that writes to a pack file.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 towrite(byte[], int, int)are guaranteed to write at the end of the file, even if there have been intermediate seeks.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanatEnd(package private) java.util.zip.DeflaterOutputStreamcompress(package private) java.util.zip.CRC32crc32private java.util.zip.Deflaterdeflaterprivate java.io.RandomAccessFilefile(package private) byte[]hdrBufprivate CountingOutputStreamout
-
Constructor Summary
Constructors Constructor Description PackStream(java.io.File pack)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidbeginObject(int objectType, long length)voidclose()private intencodeTypeSize(int type, long rawLength)(package private) byte[]finishPack()(package private) longgetOffset()(package private) byte[]inflate(long filePos, int len)(package private) voidseek(long offset)private intsetInput(long filePos, java.util.zip.Inflater inf, byte[] buf)voidwrite(byte[] data, int off, int len)voidwrite(int b)
-
-
-
Field Detail
-
hdrBuf
final byte[] hdrBuf
-
crc32
final java.util.zip.CRC32 crc32
-
compress
final java.util.zip.DeflaterOutputStream compress
-
file
private final java.io.RandomAccessFile file
-
out
private final CountingOutputStream out
-
deflater
private final java.util.zip.Deflater deflater
-
atEnd
private boolean atEnd
-
-
Method Detail
-
getOffset
long getOffset()
-
seek
void seek(long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
beginObject
void beginObject(int objectType, long length) throws java.io.IOException- Throws:
java.io.IOException
-
encodeTypeSize
private int encodeTypeSize(int type, long rawLength)
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] data, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
finishPack
byte[] finishPack() 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.OutputStream- Throws:
java.io.IOException
-
inflate
byte[] inflate(long filePos, int len) throws java.io.IOException, java.util.zip.DataFormatException- Throws:
java.io.IOExceptionjava.util.zip.DataFormatException
-
setInput
private int setInput(long filePos, java.util.zip.Inflater inf, byte[] buf) throws java.io.IOException- Throws:
java.io.IOException
-
-