length -= n; return md.toObjectId();
/** {@inheritDoc} */ @Override public ObjectId insert(int type, long len, InputStream in) throws IOException { byte[] buf = insertBuffer(len); if (len <= buf.length) { IO.readFully(in, buf, 0, (int) len); return insert(type, buf, 0, (int) len); } long offset = beginObject(type, len); SHA1 md = digest(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); while (0 < len) { int n = in.read(buf, 0, (int) Math.min(buf.length, len)); if (n <= 0) throw new EOFException(); md.update(buf, 0, n); packOut.compress.write(buf, 0, n); len -= n; } packOut.compress.finish(); return endObject(md.toObjectId(), offset); }
/** {@inheritDoc} */ @Override public ObjectId insert(int type, long len, InputStream in) throws IOException { byte[] buf = buffer(); if (len <= buf.length) { IO.readFully(in, buf, 0, (int) len); return insert(type, buf, 0, (int) len); } long offset = beginObject(type, len); SHA1 md = digest(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); while (0 < len) { int n = in.read(buf, 0, (int) Math.min(buf.length, len)); if (n <= 0) { throw new EOFException(); } md.update(buf, 0, n); packOut.compress.write(buf, 0, n); len -= n; } packOut.compress.finish(); return endObject(md.toObjectId(), offset); }
/** * Insert a loose object into the database. If createDuplicate is true, * write the loose object even if we already have it in the loose or packed * ODB. * * @param type * @param len * @param is * @param createDuplicate * @return ObjectId * @throws IOException */ ObjectId insert(int type, long len, InputStream is, boolean createDuplicate) throws IOException { if (len <= buffer().length) { byte[] buf = buffer(); int actLen = IO.readFully(is, buf, 0); return insert(type, buf, 0, actLen, createDuplicate); } else { SHA1 md = digest(); File tmp = toTemp(md, type, len, is); ObjectId id = md.toObjectId(); return insertOneObject(tmp, id, createDuplicate); } }
/** * Compute the name of an object, without inserting it. * * @param type * type code of the object to store. * @param data * complete content of the object. * @param off * first position within {@code data}. * @param len * number of bytes to copy from {@code data}. * @return the name of the object. */ public ObjectId idFor(int type, byte[] data, int off, int len) { SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); md.update(data, off, len); return md.toObjectId(); }
length -= n; return md.toObjectId();
/** {@inheritDoc} */ @Override public ObjectId insert(int type, long len, InputStream in) throws IOException { byte[] buf = insertBuffer(len); if (len <= buf.length) { IO.readFully(in, buf, 0, (int) len); return insert(type, buf, 0, (int) len); } long offset = beginObject(type, len); SHA1 md = digest(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); while (0 < len) { int n = in.read(buf, 0, (int) Math.min(buf.length, len)); if (n <= 0) throw new EOFException(); md.update(buf, 0, n); packOut.compress.write(buf, 0, n); len -= n; } packOut.compress.finish(); return endObject(md.toObjectId(), offset); }
/** {@inheritDoc} */ @Override public ObjectId insert(int type, long len, InputStream in) throws IOException { byte[] buf = buffer(); if (len <= buf.length) { IO.readFully(in, buf, 0, (int) len); return insert(type, buf, 0, (int) len); } long offset = beginObject(type, len); SHA1 md = digest(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); while (0 < len) { int n = in.read(buf, 0, (int) Math.min(buf.length, len)); if (n <= 0) { throw new EOFException(); } md.update(buf, 0, n); packOut.compress.write(buf, 0, n); len -= n; } packOut.compress.finish(); return endObject(md.toObjectId(), offset); }
/** * Insert a loose object into the database. If createDuplicate is true, * write the loose object even if we already have it in the loose or packed * ODB. * * @param type * @param len * @param is * @param createDuplicate * @return ObjectId * @throws IOException */ ObjectId insert(int type, long len, InputStream is, boolean createDuplicate) throws IOException { if (len <= buffer().length) { byte[] buf = buffer(); int actLen = IO.readFully(is, buf, 0); return insert(type, buf, 0, actLen, createDuplicate); } else { SHA1 md = digest(); File tmp = toTemp(md, type, len, is); ObjectId id = md.toObjectId(); return insertOneObject(tmp, id, createDuplicate); } }
/** * Compute the name of an object, without inserting it. * * @param type * type code of the object to store. * @param data * complete content of the object. * @param off * first position within {@code data}. * @param len * number of bytes to copy from {@code data}. * @return the name of the object. */ public ObjectId idFor(int type, byte[] data, int off, int len) { SHA1 md = SHA1.newInstance(); md.update(Constants.encodedTypeString(type)); md.update((byte) ' '); md.update(Constants.encodeASCII(len)); md.update((byte) 0); md.update(data, off, len); return md.toObjectId(); }