private void writeDeltaObjectDeflate(PackOutputStream out, final ObjectToPack otp) throws IOException { writeBase(out, otp.getDeltaBase()); crc32.reset(); otp.setOffset(out.length()); DeltaCache.Ref ref = otp.popCachedDelta(); if (ref != null) { byte[] zbuf = ref.get(); if (zbuf != null) { out.writeHeader(otp, otp.getCachedSize()); out.write(zbuf); typeStats.cntDeltas++; typeStats.deltaBytes += out.length() - otp.getOffset(); return; } } try (TemporaryBuffer.Heap delta = delta(otp)) { out.writeHeader(otp, delta.length()); Deflater deflater = deflater(); deflater.reset(); DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater); delta.writeTo(dst, null); dst.finish(); } typeStats.cntDeltas++; typeStats.deltaBytes += out.length() - otp.getOffset(); }
PackIndex writePackIndex(DfsPackDescription pack, byte[] packHash, List<PackedObjectInfo> list) throws IOException { pack.setIndexVersion(INDEX_VERSION); pack.setObjectCount(list.size()); // If there are less than 58,000 objects, the entire index fits in under // 2 MiB. Callers will probably need the index immediately, so buffer // the index in process and load from the buffer. PackIndex packIndex = null; try (TemporaryBuffer.Heap buf = maybeGetTemporaryBuffer(list); DfsOutputStream os = db.writeFile(pack, INDEX); CountingOutputStream cnt = new CountingOutputStream(os)) { if (buf != null) { index(buf, packHash, list); packIndex = PackIndex.read(buf.openInputStream()); buf.writeTo(cnt, null); } else { index(cnt, packHash, list); } pack.addFileExt(INDEX); pack.setBlockSize(INDEX, os.blockSize()); pack.setFileSize(INDEX, cnt.getCount()); } return packIndex; }
private void writeDeltaObjectDeflate(PackOutputStream out, final ObjectToPack otp) throws IOException { writeBase(out, otp.getDeltaBase()); crc32.reset(); otp.setOffset(out.length()); DeltaCache.Ref ref = otp.popCachedDelta(); if (ref != null) { byte[] zbuf = ref.get(); if (zbuf != null) { out.writeHeader(otp, otp.getCachedSize()); out.write(zbuf); typeStats.cntDeltas++; typeStats.deltaBytes += out.length() - otp.getOffset(); return; } } TemporaryBuffer.Heap delta = delta(otp); out.writeHeader(otp, delta.length()); Deflater deflater = deflater(); deflater.reset(); DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater); delta.writeTo(dst, null); dst.finish(); typeStats.cntDeltas++; typeStats.deltaBytes += out.length() - otp.getOffset(); }
private void writeDeltaObjectDeflate(PackOutputStream out, final ObjectToPack otp) throws IOException { writeBase(out, otp.getDeltaBase()); crc32.reset(); otp.setOffset(out.length()); DeltaCache.Ref ref = otp.popCachedDelta(); if (ref != null) { byte[] zbuf = ref.get(); if (zbuf != null) { out.writeHeader(otp, otp.getCachedSize()); out.write(zbuf); typeStats.cntDeltas++; typeStats.deltaBytes += out.length() - otp.getOffset(); return; } } try (TemporaryBuffer.Heap delta = delta(otp)) { out.writeHeader(otp, delta.length()); Deflater deflater = deflater(); deflater.reset(); DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater); delta.writeTo(dst, null); dst.finish(); } typeStats.cntDeltas++; typeStats.deltaBytes += out.length() - otp.getOffset(); }
PackIndex writePackIndex(DfsPackDescription pack, byte[] packHash, List<PackedObjectInfo> list) throws IOException { pack.setIndexVersion(INDEX_VERSION); pack.setObjectCount(list.size()); // If there are less than 58,000 objects, the entire index fits in under // 2 MiB. Callers will probably need the index immediately, so buffer // the index in process and load from the buffer. TemporaryBuffer.Heap buf = null; PackIndex packIndex = null; if (list.size() <= 58000) { buf = new TemporaryBuffer.Heap(2 << 20); index(buf, packHash, list); packIndex = PackIndex.read(buf.openInputStream()); } DfsOutputStream os = db.writeFile(pack, INDEX); try { CountingOutputStream cnt = new CountingOutputStream(os); if (buf != null) buf.writeTo(cnt, null); else index(cnt, packHash, list); pack.addFileExt(INDEX); pack.setFileSize(INDEX, cnt.getCount()); } finally { os.close(); } return packIndex; }
PackIndex writePackIndex(DfsPackDescription pack, byte[] packHash, List<PackedObjectInfo> list) throws IOException { pack.setIndexVersion(INDEX_VERSION); pack.setObjectCount(list.size()); // If there are less than 58,000 objects, the entire index fits in under // 2 MiB. Callers will probably need the index immediately, so buffer // the index in process and load from the buffer. PackIndex packIndex = null; try (TemporaryBuffer.Heap buf = maybeGetTemporaryBuffer(list); DfsOutputStream os = db.writeFile(pack, INDEX); CountingOutputStream cnt = new CountingOutputStream(os)) { if (buf != null) { index(buf, packHash, list); packIndex = PackIndex.read(buf.openInputStream()); buf.writeTo(cnt, null); } else { index(cnt, packHash, list); } pack.addFileExt(INDEX); pack.setBlockSize(INDEX, os.blockSize()); pack.setFileSize(INDEX, cnt.getCount()); } return packIndex; }
private void cacheDelta(ObjectToPack srcObj, ObjectToPack resObj) { if (deltaCache.canCache(deltaLen, srcObj, resObj)) { try { byte[] zbuf = new byte[deflateBound(deltaLen)]; ZipStream zs = new ZipStream(deflater(), zbuf); if (deltaBuf instanceof byte[]) zs.write((byte[]) deltaBuf, 0, deltaLen); else ((TemporaryBuffer.Heap) deltaBuf).writeTo(zs, null); deltaBuf = null; int len = zs.finish(); resObj.setCachedDelta(deltaCache.cache(zbuf, len, deltaLen)); resObj.setCachedSize(deltaLen); } catch (IOException err) { deltaCache.credit(deltaLen); } catch (OutOfMemoryError err) { deltaCache.credit(deltaLen); } } }
private void cacheDelta(ObjectToPack srcObj, ObjectToPack resObj) { if (deltaCache.canCache(deltaLen, srcObj, resObj)) { try { byte[] zbuf = new byte[deflateBound(deltaLen)]; ZipStream zs = new ZipStream(deflater(), zbuf); if (deltaBuf instanceof byte[]) zs.write((byte[]) deltaBuf, 0, deltaLen); else ((TemporaryBuffer.Heap) deltaBuf).writeTo(zs, null); deltaBuf = null; int len = zs.finish(); resObj.setCachedDelta(deltaCache.cache(zbuf, len, deltaLen)); resObj.setCachedSize(deltaLen); } catch (IOException err) { deltaCache.credit(deltaLen); } catch (OutOfMemoryError err) { deltaCache.credit(deltaLen); } } }
private void cacheDelta(ObjectToPack srcObj, ObjectToPack resObj) { if (deltaCache.canCache(deltaLen, srcObj, resObj)) { try { byte[] zbuf = new byte[deflateBound(deltaLen)]; ZipStream zs = new ZipStream(deflater(), zbuf); if (deltaBuf instanceof byte[]) zs.write((byte[]) deltaBuf, 0, deltaLen); else ((TemporaryBuffer.Heap) deltaBuf).writeTo(zs, null); deltaBuf = null; int len = zs.finish(); resObj.setCachedDelta(deltaCache.cache(zbuf, len, deltaLen)); resObj.setCachedSize(deltaLen); } catch (IOException err) { deltaCache.credit(deltaLen); } catch (OutOfMemoryError err) { deltaCache.credit(deltaLen); } } }