Пример #1
0
  private static byte[] getDelta(ObjectReader reader, RevObject obj)
      throws IOException, MissingObjectException, StoredObjectRepresentationNotAvailableException {
    ObjectReuseAsIs asis = (ObjectReuseAsIs) reader;
    ObjectToPack target = asis.newObjectToPack(obj, obj.getType());

    PackWriter pw =
        new PackWriter(reader) {
          @Override
          public void select(ObjectToPack otp, StoredObjectRepresentation next) {
            otp.select(next);
          }
        };

    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    asis.selectObjectRepresentation(
        pw, NullProgressMonitor.INSTANCE, Collections.singleton(target));
    asis.copyObjectAsIs(new PackOutputStream(NullProgressMonitor.INSTANCE, buf, pw), target, true);

    // At this point the object header has no delta information,
    // because it was output as though it were a whole object.
    // Skip over the header and inflate.
    //
    byte[] bufArray = buf.toByteArray();
    int ptr = 0;
    while ((bufArray[ptr] & 0x80) != 0) ptr++;
    ptr++;

    @SuppressWarnings("resource" /* java 7 */)
    TemporaryBuffer.Heap raw = new TemporaryBuffer.Heap(bufArray.length);
    InflaterInputStream inf =
        new InflaterInputStream(new ByteArrayInputStream(bufArray, ptr, bufArray.length));
    raw.copy(inf);
    inf.close();
    return raw.toByteArray();
  }
  private void openPack(TemporaryBuffer.Heap buf) throws IOException {
    if (inserter == null) inserter = src.newObjectInserter();

    final byte[] raw = buf.toByteArray();
    PackParser p = inserter.newPackParser(new ByteArrayInputStream(raw));
    p.setAllowThin(true);
    p.parse(PM);
  }
 private static PacketLineIn asPacketLineIn(TemporaryBuffer.Heap buf) throws IOException {
   return new PacketLineIn(new ByteArrayInputStream(buf.toByteArray()));
 }
 private static void digest(TemporaryBuffer.Heap buf) throws IOException {
   MessageDigest md = Constants.newMessageDigest();
   md.update(buf.toByteArray());
   buf.write(md.digest());
 }
 private static void receive(
     final ReceivePack rp, final TemporaryBuffer.Heap inBuf, final TemporaryBuffer.Heap outBuf)
     throws IOException {
   rp.receive(new ByteArrayInputStream(inBuf.toByteArray()), outBuf, null);
 }