/** {@inheritDoc} */ @Override public void flush() throws IOException { if (packDsc == null) return; if (packOut == null) throw new IOException(); byte[] packHash = packOut.writePackFooter(); packDsc.addFileExt(PACK); packDsc.setFileSize(PACK, packOut.getCount()); packOut.close(); packOut = null; sortObjectsById(); PackIndex index = writePackIndex(packDsc, packHash, objectList); db.commitPack(Collections.singletonList(packDsc), null); rollback = false; DfsPackFile p = new DfsPackFile(cache, packDsc); if (index != null) p.setPackIndex(index); db.addPack(p); clear(); }
void beginObject(int objectType, long length) throws IOException { crc32.reset(); deflater.reset(); write(hdrBuf, 0, encodeTypeSize(objectType, length)); }
private void writeNoHash(byte[] data, int off, int len) throws IOException { while (0 < len) { int n = Math.min(len, currBuf.length - currPtr); if (n == 0) { flushBlock(); currBuf = new byte[blockSize]; continue; } System.arraycopy(data, off, currBuf, currPtr, n); off += n; len -= n; currPtr += n; } }
int cnt = packOut.read(obj.getOffset(), buf, 0, 20); if (cnt <= 0) throw new EOFException(DfsText.get().unexpectedEofInPack);
int cnt = packOut.read(obj.getOffset(), buf, 0, 20); if (cnt <= 0) throw new EOFException(JGitText.get().unexpectedEofInPack);
/** {@inheritDoc} */ @Override public void flush() throws IOException { if (packDsc == null) return; if (packOut == null) throw new IOException(); byte[] packHash = packOut.writePackFooter(); packDsc.addFileExt(PACK); packDsc.setFileSize(PACK, packOut.getCount()); packOut.close(); packOut = null; sortObjectsById(); PackIndex index = writePackIndex(packDsc, packHash, objectList); db.commitPack(Collections.singletonList(packDsc), null); rollback = false; DfsPackFile p = new DfsPackFile(cache, packDsc); if (index != null) p.setPackIndex(index); db.addPack(p); clear(); }
/** {@inheritDoc} */ @Override public void close() { if (packOut != null) { try { packOut.close(); } catch (IOException err) { // Ignore a close failure, the pack should be removed. } finally { packOut = null; } } if (rollback && packDsc != null) { try { db.rollbackPack(Collections.singletonList(packDsc)); } finally { packDsc = null; rollback = false; } } clear(); }
@Override public void flush() throws IOException { if (packDsc == null) return; if (packOut == null) throw new IOException(); byte[] packHash = packOut.writePackFooter(); packDsc.addFileExt(PACK); packDsc.setFileSize(PACK, packOut.getCount()); packOut.close(); packOut = null; sortObjectsById(); PackIndex index = writePackIndex(packDsc, packHash, objectList); db.commitPack(Collections.singletonList(packDsc), null); rollback = false; DfsPackFile p = cache.getOrCreate(packDsc, packKey); if (index != null) p.setPackIndex(index); db.addPack(p); clear(); }
@Override public void close() { if (packOut != null) { try { packOut.close(); } catch (IOException err) { // Ignore a close failure, the pack should be removed. } finally { packOut = null; } } if (rollback && packDsc != null) { try { db.rollbackPack(Collections.singletonList(packDsc)); } finally { packDsc = null; rollback = false; } } clear(); }
private void beginPack() throws IOException { objectList = new BlockList<>(); objectMap = new ObjectIdOwnerMap<>(); cache = DfsBlockCache.getInstance(); rollback = true; packDsc = db.newPack(DfsObjDatabase.PackSource.INSERT); DfsOutputStream dfsOut = db.writeFile(packDsc, PACK); packDsc.setBlockSize(PACK, dfsOut.blockSize()); packOut = new PackStream(dfsOut); packKey = packDsc.getStreamKey(PACK); // Write the header as though it were a single object pack. byte[] buf = packOut.hdrBuf; System.arraycopy(Constants.PACK_SIGNATURE, 0, buf, 0, 4); NB.encodeInt32(buf, 4, 2); // Always use pack version 2. NB.encodeInt32(buf, 8, 1); // Always assume 1 object. packOut.write(buf, 0, 12); }
int read(long pos, byte[] dst, int ptr, int cnt) throws IOException { int r = 0; while (pos < currPos && r < cnt) { DfsBlock b = getOrLoadBlock(pos); int n = b.copy(pos, dst, ptr + r, cnt - r); pos += n; r += n; } if (currPos <= pos && r < cnt) { int s = (int) (pos - currPos); int n = Math.min(currPtr - s, cnt - r); System.arraycopy(currBuf, s, dst, ptr + r, n); r += n; } return r; }
private void writeNoHash(byte[] data, int off, int len) throws IOException { while (0 < len) { int n = Math.min(len, currBuf.length - currPtr); if (n == 0) { flushBlock(); currBuf = new byte[blockSize]; continue; } System.arraycopy(data, off, currBuf, currPtr, n); off += n; len -= n; currPtr += n; } }
int read(long pos, byte[] dst, int ptr, int cnt) throws IOException { int r = 0; while (pos < currPos && r < cnt) { DfsBlock b = getOrLoadBlock(pos); int n = b.copy(pos, dst, ptr + r, cnt - r); pos += n; r += n; } if (currPos <= pos && r < cnt) { int s = (int) (pos - currPos); int n = Math.min(currPtr - s, cnt - r); System.arraycopy(currBuf, s, dst, ptr + r, n); r += n; } return r; }
private void writeNoHash(byte[] data, int off, int len) throws IOException { while (0 < len) { int n = Math.min(len, currBuf.length - currPtr); if (n == 0) { flushBlock(); currBuf = new byte[blockSize]; continue; } System.arraycopy(data, off, currBuf, currPtr, n); off += n; len -= n; currPtr += n; } }
private void beginPack() throws IOException { objectList = new BlockList<PackedObjectInfo>(); objectMap = new ObjectIdOwnerMap<PackedObjectInfo>(); cache = DfsBlockCache.getInstance(); rollback = true; packDsc = db.newPack(DfsObjDatabase.PackSource.INSERT); packOut = new PackStream(db.writeFile(packDsc, PACK)); packKey = new DfsPackKey(); // Write the header as though it were a single object pack. byte[] buf = packOut.hdrBuf; System.arraycopy(Constants.PACK_SIGNATURE, 0, buf, 0, 4); NB.encodeInt32(buf, 4, 2); // Always use pack version 2. NB.encodeInt32(buf, 8, 1); // Always assume 1 object. packOut.write(buf, 0, 12); }
private byte[] inflate(PackedObjectInfo obj, long zpos, int sz) throws IOException, CorruptObjectException { try { return packOut.inflate(ctx, zpos, sz); } catch (DataFormatException dfe) { CorruptObjectException coe = new CorruptObjectException( MessageFormat.format( JGitText.get().objectAtHasBadZlibStream, Long.valueOf(obj.getOffset()), packDsc.getFileName(PackExt.PACK))); coe.initCause(dfe); throw coe; } }
private byte[] inflate(PackedObjectInfo obj, long zpos, int sz) throws IOException, CorruptObjectException { try { return packOut.inflate(ctx, zpos, sz); } catch (DataFormatException dfe) { throw new CorruptObjectException( MessageFormat.format( JGitText.get().objectAtHasBadZlibStream, Long.valueOf(obj.getOffset()), packDsc.getFileName(PackExt.PACK)), dfe); } }
private int setInput(long pos, Inflater inf) throws IOException, DataFormatException { if (pos < currPos) return getOrLoadBlock(pos).setInput(pos, inf); if (pos < currPos + currPtr) { int s = (int) (pos - currPos); int n = currPtr - s; inf.setInput(currBuf, s, n); return n; } throw new EOFException(DfsText.get().unexpectedEofInPack); }
byte[] writePackFooter() throws IOException { byte[] packHash = md.digest(); writeNoHash(packHash, 0, packHash.length); if (currPtr != 0) flushBlock(); return packHash; }
private int setInput(long pos, Inflater inf) throws IOException, DataFormatException { if (pos < currPos) return getOrLoadBlock(pos).setInput(pos, inf); if (pos < currPos + currPtr) { int s = (int) (pos - currPos); int n = currPtr - s; inf.setInput(currBuf, s, n); return n; } throw new EOFException(JGitText.get().unexpectedEofInPack); }