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; }
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; }