Add Constants.encode as a utility for quick encoding in UTF-8
commitff18ea72691de0e0b2da2e3dc04069d1b076c840
authorShawn O. Pearce <spearce@spearce.org>
Tue, 12 Aug 2008 01:07:50 +0000 (11 18:07 -0700)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Thu, 14 Aug 2008 17:33:19 +0000 (14 19:33 +0200)
treeff738245abbb867fd39db3c04751a9ce2a7d8c4d
parent3803252cdbcf34e9247909d73ce0239422c2916a
Add Constants.encode as a utility for quick encoding in UTF-8

We often need to convert a string into a UTF-8 encoding, so that
we can use this string as a path filter in a TreeWalk or in some
other suitable place where we assume a standard UTF-8 encoding is
being used.  As we have already done the lookup for the CHARSET
we can reuse that same CHARSET reference during future encoding
calls, while allowing the CharSet implementation to cache and
reuse the actual encoder instance.

Whenever possible we try to avoid copying the result as most of
the time the returned ByteBuffer's internal array matches the
result array we need to return to our caller.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ConstantsEncodingTest.java [new file with mode: 0644]
org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java