/** * Convert an integer into its decimal representation. * * @param s * the integer to convert. * @return a decimal representation of the input integer. The returned array * is the smallest array that will hold the value. */ public static byte[] encodeASCII(long s) { return encodeASCII(Long.toString(s)); }
void writeHeader(OutputStream out, int type, long len) throws IOException { out.write(Constants.encodedTypeString(type)); out.write((byte) ' '); out.write(Constants.encodeASCII(len)); out.write((byte) 0); }
private void writeRange(char prefix, int begin, int cnt) throws IOException { out.write(' '); out.write(prefix); switch (cnt) { case 0: // If the range is empty, its beginning number must be the // line just before the range, or 0 if the range is at the // start of the file stream. Here, begin is always 1 based, // so an empty file would produce "0,0". // out.write(encodeASCII(begin - 1)); out.write(','); out.write('0'); break; case 1: // If the range is exactly one line, produce only the number. // out.write(encodeASCII(begin)); break; default: out.write(encodeASCII(begin)); out.write(','); out.write(encodeASCII(cnt)); break; } }
/** * Convert an ObjectId from hex characters. * * @param str * the string to read from. Must be 40 characters long. */ public void fromString(String str) { if (str.length() != Constants.OBJECT_ID_STRING_LENGTH) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().invalidId, str)); fromHexString(Constants.encodeASCII(str), 0); }
/** * Convert an AbbreviatedObjectId from hex characters. * * @param str * the string to read from. Must be <= 40 characters. * @return the converted object id. */ public static final AbbreviatedObjectId fromString(String str) { if (str.length() > Constants.OBJECT_ID_STRING_LENGTH) throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidId, str)); final byte[] b = Constants.encodeASCII(str); return fromHexString(b, 0, b.length); }
private NoteParser(AbbreviatedObjectId prefix, ObjectReader r, ObjectId t) throws IncorrectObjectTypeException, IOException { super(encodeASCII(prefix.name()), r, t); prefixLen = prefix.length(); // Our path buffer has a '/' that we don't want after the prefix. // Drop it by shifting the path down one position. pathPadding = 0 < prefixLen ? 1 : 0; if (0 < pathPadding) System.arraycopy(path, 0, path, pathPadding, prefixLen); }
/** * Rebuild the {@link #INFO_PACKS} for dumb transport clients. * <p> * This method rebuilds the contents of the {@link #INFO_PACKS} file to * match the passed list of pack names. * * @param packNames * names of available pack files, in the order they should appear * in the file. Valid pack name strings are of the form * <code>pack-035760ab452d6eebd123add421f253ce7682355a.pack</code>. * @throws IOException * writing is not supported, or attempting to write the file * failed, possibly due to permissions or remote disk full, etc. */ void writeInfoPacks(Collection<String> packNames) throws IOException { final StringBuilder w = new StringBuilder(); for (String n : packNames) { w.append("P "); //$NON-NLS-1$ w.append(n); w.append('\n'); } writeFile(INFO_PACKS, Constants.encodeASCII(w.toString())); }
/** * Convert an ObjectId from hex characters. * * @param str * the string to read from. Must be 40 characters long. * @return the converted object id. */ public static ObjectId fromString(String str) { if (str.length() != Constants.OBJECT_ID_STRING_LENGTH) { throw new InvalidObjectIdException(str); } return fromHexString(Constants.encodeASCII(str), 0); }
|| (escapeReservedChars && reservedChars.get(b))) { os.write('%'); byte[] tmp = Constants.encodeASCII(String.format("%02x", //$NON-NLS-1$ Integer.valueOf(b))); os.write(tmp[0]);
/** * Output the first header line * * @param o * The stream the formatter will write the first header line to * @param type * The {@link org.eclipse.jgit.diff.DiffEntry.ChangeType} * @param oldPath * old path to the file * @param newPath * new path to the file * @throws java.io.IOException * the stream threw an exception while writing to it. */ protected void formatGitDiffFirstHeaderLine(ByteArrayOutputStream o, final ChangeType type, final String oldPath, final String newPath) throws IOException { o.write(encodeASCII("diff --git ")); //$NON-NLS-1$ o.write(encode(quotePath(oldPrefix + (type == ADD ? newPath : oldPath)))); o.write(' '); o.write(encode(quotePath(newPrefix + (type == DELETE ? oldPath : newPath)))); o.write('\n'); }
os.write(hencoding); os.write(' '); os.write(Constants.encodeASCII(getEncoding().name())); os.write('\n');
private static byte[] writeGitLinkText(AbbreviatedObjectId id) { if (ObjectId.zeroId().equals(id.toObjectId())) { return EMPTY; } return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$ + "\n"); //$NON-NLS-1$ }
/** * Format index line * * @param o * the stream the formatter will write line data to * @param ent * the DiffEntry to create the FileHeader for * @throws java.io.IOException * writing to the supplied stream failed. */ protected void formatIndexLine(OutputStream o, DiffEntry ent) throws IOException { o.write(encodeASCII("index " // //$NON-NLS-1$ + format(ent.getOldId()) // + ".." // //$NON-NLS-1$ + format(ent.getNewId()))); if (ent.getOldMode().equals(ent.getNewMode())) { o.write(' '); ent.getNewMode().copyTo(o); } o.write('\n'); }
md.update(Constants.encodedTypeString(objectType)); md.update((byte) ' '); md.update(Constants.encodeASCII(length)); md.update((byte) 0); byte[] buf = buffer();
/** {@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); }
/** * 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(); }
objectDigest.update(Constants.encodedTypeString(type)); objectDigest.update((byte) ' '); objectDigest.update(Constants.encodeASCII(visit.data.length)); objectDigest.update((byte) 0); objectDigest.update(visit.data);
buf.write(encodeASCII("Binary files differ\n")); //$NON-NLS-1$ editList = new EditList(); type = PatchType.BINARY;
objectDigest.update(Constants.encodedTypeString(type)); objectDigest.update((byte) ' '); objectDigest.update(Constants.encodeASCII(sz)); objectDigest.update((byte) 0);