PackStream(DfsOutputStream out) { this.out = out; hdrBuf = new byte[32]; md = Constants.newMessageDigest(); crc32 = new CRC32(); deflater = new Deflater(compression); compress = new DeflaterOutputStream(this, deflater, 8192); int size = out.blockSize(); if (size <= 0) size = cache.getBlockSize(); else if (size < cache.getBlockSize()) size = (cache.getBlockSize() / size) * size; blockSize = size; currBuf = new byte[blockSize]; }
@Override public void close() throws IOException { deflater.end(); out.close(); } }
private int read(long pos, byte[] dst, int off, int len) throws IOException { if (len == 0) return 0; int cnt = 0; while (0 < len) { int r = out.read(pos, ByteBuffer.wrap(dst, off, len)); if (r <= 0) break; pos += r; off += r; len -= r; cnt += r; } return cnt != 0 ? cnt : -1; }
/** {@inheritDoc} */ @Override public abstract void write(byte[] buf, int off, int len) throws IOException;
private DfsBlock flushBlock() throws IOException { if (isEmptyPack) throw new IOException(DfsText.get().willNotStoreEmptyPack); out.write(currBuf, 0, currEnd); byte[] buf; if (currEnd == currBuf.length) { buf = currBuf; } else { buf = new byte[currEnd]; System.arraycopy(currBuf, 0, buf, 0, currEnd); } DfsBlock v = new DfsBlock(packKey, currPos, buf); readBlock = v; blockCache.put(v); return v; }
static ReftableConfig configureReftable(ReftableConfig cfg, DfsOutputStream out) { int bs = out.blockSize(); if (bs > 0) { cfg = new ReftableConfig(cfg); cfg.setRefBlockSize(bs); cfg.setAlignBlocks(true); } return cfg; }
private void flushBlock() throws IOException { out.write(currBuf, 0, currPtr); byte[] buf; if (currPtr == currBuf.length) buf = currBuf; else buf = copyOf(currBuf, 0, currPtr); cache.put(new DfsBlock(packKey, currPos, buf)); currPos += currPtr; currPtr = 0; currBuf = null; }
private DfsBlock getOrLoadBlock(long pos) throws IOException { long s = toBlockStart(pos); DfsBlock b = cache.get(packKey, s); if (b != null) return b; byte[] d = new byte[blockSize]; for (int p = 0; p < blockSize;) { int n = out.read(s + p, ByteBuffer.wrap(d, p, blockSize - p)); if (n <= 0) throw new EOFException(JGitText.get().unexpectedEofInPack); p += n; } b = new DfsBlock(packKey, s, d); cache.put(b); return b; }
private static void writePack(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw, ProgressMonitor pm) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, PACK)) { pw.writePack(pm, pm, out); pack.addFileExt(PACK); pack.setBlockSize(PACK, out.blockSize()); } }
/** {@inheritDoc} */ @Override public abstract void write(byte[] buf, int off, int len) throws IOException;
@Override public void close() throws IOException { deflater.end(); out.close(); } }
private int read(long pos, byte[] dst, int off, int len) throws IOException { if (len == 0) return 0; int cnt = 0; while (0 < len) { int r = out.read(pos, ByteBuffer.wrap(dst, off, len)); if (r <= 0) break; pos += r; off += r; len -= r; cnt += r; } return cnt != 0 ? cnt : -1; }
/** {@inheritDoc} */ @Override protected void onPackHeader(long objectCount) throws IOException { if (objectCount == 0) { isEmptyPack = true; currBuf = new byte[256]; return; } packDsc = objdb.newPack(DfsObjDatabase.PackSource.RECEIVE); out = objdb.writeFile(packDsc, PACK); packKey = packDsc.getStreamKey(PACK); int size = out.blockSize(); if (size <= 0) size = blockCache.getBlockSize(); else if (size < blockCache.getBlockSize()) size = (blockCache.getBlockSize() / size) * size; blockSize = size; currBuf = new byte[blockSize]; }
@Override public abstract void write(byte[] buf, int off, int len) throws IOException;
@Override public void close() throws IOException { deflater.end(); out.close(); } }
private int read(long pos, byte[] dst, int off, int len) throws IOException { if (len == 0) return 0; int cnt = 0; while (0 < len) { int r = out.read(pos, ByteBuffer.wrap(dst, off, len)); if (r <= 0) break; pos += r; off += r; len -= r; cnt += r; } return cnt != 0 ? cnt : -1; }
private static void writeIndex(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw) throws IOException { try (DfsOutputStream out = objdb.writeFile(pack, INDEX)) { CountingOutputStream cnt = new CountingOutputStream(out); pw.writeIndex(cnt); pack.addFileExt(INDEX); pack.setFileSize(INDEX, cnt.getCount()); pack.setBlockSize(INDEX, out.blockSize()); pack.setIndexVersion(pw.getIndexVersion()); } }
private DfsBlock flushBlock() throws IOException { if (isEmptyPack) throw new IOException(DfsText.get().willNotStoreEmptyPack); out.write(currBuf, 0, currEnd); byte[] buf; if (currEnd == currBuf.length) { buf = currBuf; } else { buf = new byte[currEnd]; System.arraycopy(currBuf, 0, buf, 0, currEnd); } DfsBlock v = new DfsBlock(packKey, currPos, buf); readBlock = v; blockCache.put(v); return v; }
private static void writePack(DfsObjDatabase objdb, DfsPackDescription pack, PackWriter pw, ProgressMonitor pm) throws IOException { DfsOutputStream out = objdb.writeFile(pack, PACK); try { pw.writePack(pm, pm, out); pack.addFileExt(PACK); } finally { out.close(); } }