Change-Id: I3b748620f067582afef20f144feebe40d0332be2 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>tags/v5.1.0.201809051400-rc1
package org.eclipse.jgit.http.server; | package org.eclipse.jgit.http.server; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.http.server.ServletUtils.getRepository; | import static org.eclipse.jgit.http.server.ServletUtils.getRepository; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
final Repository db = getRepository(req); | final Repository db = getRepository(req); | ||||
try (OutputStreamWriter out = new OutputStreamWriter( | try (OutputStreamWriter out = new OutputStreamWriter( | ||||
new SmartOutputStream(req, rsp, true), | new SmartOutputStream(req, rsp, true), | ||||
Constants.CHARSET)) { | |||||
UTF_8)) { | |||||
final RefAdvertiser adv = new RefAdvertiser() { | final RefAdvertiser adv = new RefAdvertiser() { | ||||
@Override | @Override | ||||
protected void writeOne(CharSequence line) | protected void writeOne(CharSequence line) |
package org.eclipse.jgit.http.test; | package org.eclipse.jgit.http.test; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_ENCODING; | import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_ENCODING; | ||||
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_LENGTH; | import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_LENGTH; | ||||
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE; | import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE; | ||||
public void testInvalidWant() throws Exception { | public void testInvalidWant() throws Exception { | ||||
@SuppressWarnings("resource") | @SuppressWarnings("resource") | ||||
ObjectId id = new ObjectInserter.Formatter().idFor(Constants.OBJ_BLOB, | ObjectId id = new ObjectInserter.Formatter().idFor(Constants.OBJ_BLOB, | ||||
"testInvalidWant".getBytes(CHARSET)); | |||||
"testInvalidWant".getBytes(UTF_8)); | |||||
Repository dst = createBareRepository(); | Repository dst = createBareRepository(); | ||||
try (Transport t = Transport.open(dst, remoteURI); | try (Transport t = Transport.open(dst, remoteURI); |
package org.eclipse.jgit.junit; | package org.eclipse.jgit.junit; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
throws IOException { | throws IOException { | ||||
FileUtils.mkdirs(f.getParentFile(), true); | FileUtils.mkdirs(f.getParentFile(), true); | ||||
try (Writer w = new OutputStreamWriter(new FileOutputStream(f), | try (Writer w = new OutputStreamWriter(new FileOutputStream(f), | ||||
CHARSET)) { | |||||
UTF_8)) { | |||||
w.write(body); | w.write(body); | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
public static String read(File file) throws IOException { | public static String read(File file) throws IOException { | ||||
final byte[] body = IO.readFully(file); | final byte[] body = IO.readFully(file); | ||||
return new String(body, 0, body.length, CHARSET); | |||||
return new String(body, 0, body.length, UTF_8); | |||||
} | } | ||||
/** | /** |
package org.eclipse.jgit.junit; | package org.eclipse.jgit.junit; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.fail; | import static org.junit.Assert.fail; | ||||
if (0 != (includedOptions & CONTENT)) { | if (0 != (includedOptions & CONTENT)) { | ||||
sb.append(", content:" | sb.append(", content:" | ||||
+ new String(repo.open(entry.getObjectId(), | + new String(repo.open(entry.getObjectId(), | ||||
Constants.OBJ_BLOB).getCachedBytes(), CHARSET)); | |||||
Constants.OBJ_BLOB).getCachedBytes(), UTF_8)); | |||||
} | } | ||||
if (0 != (includedOptions & ASSUME_UNCHANGED)) | if (0 != (includedOptions & ASSUME_UNCHANGED)) | ||||
sb.append(", assume-unchanged:" | sb.append(", assume-unchanged:" |
package org.eclipse.jgit.junit; | package org.eclipse.jgit.junit; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import java.io.File; | import java.io.File; | ||||
protected static void checkFile(File f, String checkData) | protected static void checkFile(File f, String checkData) | ||||
throws IOException { | throws IOException { | ||||
try (Reader r = new InputStreamReader(new FileInputStream(f), | try (Reader r = new InputStreamReader(new FileInputStream(f), | ||||
CHARSET)) { | |||||
UTF_8)) { | |||||
if (checkData.length() > 0) { | if (checkData.length() > 0) { | ||||
char[] data = new char[checkData.length()]; | char[] data = new char[checkData.length()]; | ||||
assertEquals(data.length, r.read(data)); | assertEquals(data.length, r.read(data)); |
package org.eclipse.jgit.junit; | package org.eclipse.jgit.junit; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.fail; | import static org.junit.Assert.fail; | ||||
* @throws Exception | * @throws Exception | ||||
*/ | */ | ||||
public RevBlob blob(String content) throws Exception { | public RevBlob blob(String content) throws Exception { | ||||
return blob(content.getBytes(CHARSET)); | |||||
return blob(content.getBytes(UTF_8)); | |||||
} | } | ||||
/** | /** |
*/ | */ | ||||
package org.eclipse.jgit.lfs.server.fs; | package org.eclipse.jgit.lfs.server.fs; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||
if (buf.hasArray()) { | if (buf.hasArray()) { | ||||
error = new String(buf.array(), | error = new String(buf.array(), | ||||
buf.arrayOffset() + buf.position(), buf.remaining(), | buf.arrayOffset() + buf.position(), buf.remaining(), | ||||
CHARSET); | |||||
UTF_8); | |||||
} else { | } else { | ||||
final byte[] b = new byte[buf.remaining()]; | final byte[] b = new byte[buf.remaining()]; | ||||
buf.duplicate().get(b); | buf.duplicate().get(b); | ||||
error = new String(b, CHARSET); | |||||
error = new String(b, UTF_8); | |||||
} | } | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
error = statusLine.getReasonPhrase(); | error = statusLine.getReasonPhrase(); |
*/ | */ | ||||
package org.eclipse.jgit.lfs.server; | package org.eclipse.jgit.lfs.server; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.apache.http.HttpStatus.SC_FORBIDDEN; | import static org.apache.http.HttpStatus.SC_FORBIDDEN; | ||||
import static org.apache.http.HttpStatus.SC_INSUFFICIENT_STORAGE; | import static org.apache.http.HttpStatus.SC_INSUFFICIENT_STORAGE; | ||||
import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR; | import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR; | ||||
protected void doPost(HttpServletRequest req, HttpServletResponse res) | protected void doPost(HttpServletRequest req, HttpServletResponse res) | ||||
throws ServletException, IOException { | throws ServletException, IOException { | ||||
Writer w = new BufferedWriter( | Writer w = new BufferedWriter( | ||||
new OutputStreamWriter(res.getOutputStream(), CHARSET)); | |||||
new OutputStreamWriter(res.getOutputStream(), UTF_8)); | |||||
Reader r = new BufferedReader( | Reader r = new BufferedReader( | ||||
new InputStreamReader(req.getInputStream(), CHARSET)); | |||||
new InputStreamReader(req.getInputStream(), UTF_8)); | |||||
LfsRequest request = LfsGson.fromJson(r, LfsRequest.class); | LfsRequest request = LfsGson.fromJson(r, LfsRequest.class); | ||||
String path = req.getPathInfo(); | String path = req.getPathInfo(); | ||||
*/ | */ | ||||
package org.eclipse.jgit.lfs.server.s3; | package org.eclipse.jgit.lfs.server.s3; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; | import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; | ||||
import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||
private static byte[] hash(String s) { | private static byte[] hash(String s) { | ||||
MessageDigest md = Constants.newMessageDigest(); | MessageDigest md = Constants.newMessageDigest(); | ||||
md.update(s.getBytes(CHARSET)); | |||||
md.update(s.getBytes(UTF_8)); | |||||
return md.digest(); | return md.digest(); | ||||
} | } | ||||
private static byte[] sign(String stringData, byte[] key) { | private static byte[] sign(String stringData, byte[] key) { | ||||
try { | try { | ||||
byte[] data = stringData.getBytes(CHARSET); | |||||
byte[] data = stringData.getBytes(UTF_8); | |||||
Mac mac = Mac.getInstance(HMACSHA256); | Mac mac = Mac.getInstance(HMACSHA256); | ||||
mac.init(new SecretKeySpec(key, HMACSHA256)); | mac.init(new SecretKeySpec(key, HMACSHA256)); | ||||
return mac.doFinal(data); | return mac.doFinal(data); | ||||
private static String urlEncode(String url, boolean keepPathSlash) { | private static String urlEncode(String url, boolean keepPathSlash) { | ||||
String encoded; | String encoded; | ||||
try { | try { | ||||
encoded = URLEncoder.encode(url, CHARSET.name()); | |||||
encoded = URLEncoder.encode(url, UTF_8.name()); | |||||
} catch (UnsupportedEncodingException e) { | } catch (UnsupportedEncodingException e) { | ||||
throw new RuntimeException(LfsServerText.get().unsupportedUtf8, e); | throw new RuntimeException(LfsServerText.get().unsupportedUtf8, e); | ||||
} | } |
*/ | */ | ||||
package org.eclipse.jgit.lfs.test; | package org.eclipse.jgit.lfs.test; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
*/ | */ | ||||
public static LongObjectId hash(String s) { | public static LongObjectId hash(String s) { | ||||
MessageDigest md = Constants.newMessageDigest(); | MessageDigest md = Constants.newMessageDigest(); | ||||
md.update(s.getBytes(CHARSET)); | |||||
md.update(s.getBytes(UTF_8)); | |||||
return LongObjectId.fromRaw(md.digest()); | return LongObjectId.fromRaw(md.digest()); | ||||
} | } | ||||
package org.eclipse.jgit.lfs.lib; | package org.eclipse.jgit.lfs.lib; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static java.nio.charset.StandardCharsets.US_ASCII; | import static java.nio.charset.StandardCharsets.US_ASCII; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import org.eclipse.jgit.junit.JGitTestUtil; | import org.eclipse.jgit.junit.JGitTestUtil; | ||||
import org.eclipse.jgit.lfs.errors.InvalidLongObjectIdException; | import org.eclipse.jgit.lfs.errors.InvalidLongObjectIdException; | ||||
import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils; | import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.util.FileUtils; | import org.eclipse.jgit.util.FileUtils; | ||||
import org.junit.AfterClass; | import org.junit.AfterClass; | ||||
import org.junit.BeforeClass; | import org.junit.BeforeClass; | ||||
AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test"); | AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test"); | ||||
ByteArrayOutputStream os = new ByteArrayOutputStream(64); | ByteArrayOutputStream os = new ByteArrayOutputStream(64); | ||||
try (OutputStreamWriter w = new OutputStreamWriter(os, | try (OutputStreamWriter w = new OutputStreamWriter(os, | ||||
Constants.CHARSET)) { | |||||
UTF_8)) { | |||||
id1.copyTo(w); | id1.copyTo(w); | ||||
} | } | ||||
assertEquals(id1, LongObjectId.fromString(os.toByteArray(), 0)); | assertEquals(id1, LongObjectId.fromString(os.toByteArray(), 0)); | ||||
AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test"); | AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test"); | ||||
ByteArrayOutputStream os = new ByteArrayOutputStream(64); | ByteArrayOutputStream os = new ByteArrayOutputStream(64); | ||||
try (OutputStreamWriter w = new OutputStreamWriter(os, | try (OutputStreamWriter w = new OutputStreamWriter(os, | ||||
Constants.CHARSET)) { | |||||
UTF_8)) { | |||||
char[] buf = new char[64]; | char[] buf = new char[64]; | ||||
id1.copyTo(buf, w); | id1.copyTo(buf, w); | ||||
} | } |
*/ | */ | ||||
package org.eclipse.jgit.lfs; | package org.eclipse.jgit.lfs; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
*/ | */ | ||||
public void encode(OutputStream out) { | public void encode(OutputStream out) { | ||||
try (PrintStream ps = new PrintStream(out, false, | try (PrintStream ps = new PrintStream(out, false, | ||||
CHARSET.name())) { | |||||
UTF_8.name())) { | |||||
ps.print("version "); //$NON-NLS-1$ | ps.print("version "); //$NON-NLS-1$ | ||||
ps.print(VERSION + "\n"); //$NON-NLS-1$ | ps.print(VERSION + "\n"); //$NON-NLS-1$ | ||||
ps.print("oid " + HASH_FUNCTION_NAME + ":"); //$NON-NLS-1$ //$NON-NLS-2$ | ps.print("oid " + HASH_FUNCTION_NAME + ":"); //$NON-NLS-1$ //$NON-NLS-2$ | ||||
ps.print(size + "\n"); //$NON-NLS-1$ | ps.print(size + "\n"); //$NON-NLS-1$ | ||||
} catch (UnsupportedEncodingException e) { | } catch (UnsupportedEncodingException e) { | ||||
// should not happen, we are using a standard charset | // should not happen, we are using a standard charset | ||||
throw new UnsupportedCharsetException(CHARSET.name()); | |||||
throw new UnsupportedCharsetException(UTF_8.name()); | |||||
} | } | ||||
} | } | ||||
long sz = -1; | long sz = -1; | ||||
try (BufferedReader br = new BufferedReader( | try (BufferedReader br = new BufferedReader( | ||||
new InputStreamReader(in, CHARSET))) { | |||||
new InputStreamReader(in, UTF_8))) { | |||||
for (String s = br.readLine(); s != null; s = br.readLine()) { | for (String s = br.readLine(); s != null; s = br.readLine()) { | ||||
if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$ | if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$ | ||||
continue; | continue; |
*/ | */ | ||||
package org.eclipse.jgit.lfs; | package org.eclipse.jgit.lfs; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lfs.Protocol.OPERATION_UPLOAD; | import static org.eclipse.jgit.lfs.Protocol.OPERATION_UPLOAD; | ||||
import static org.eclipse.jgit.lfs.internal.LfsConnectionFactory.toRequest; | import static org.eclipse.jgit.lfs.internal.LfsConnectionFactory.toRequest; | ||||
import static org.eclipse.jgit.transport.http.HttpConnection.HTTP_OK; | import static org.eclipse.jgit.transport.http.HttpConnection.HTTP_OK; | ||||
} | } | ||||
Gson gson = Protocol.gson(); | Gson gson = Protocol.gson(); | ||||
api.getOutputStream().write( | api.getOutputStream().write( | ||||
gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(CHARSET)); | |||||
gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(UTF_8)); | |||||
int responseCode = api.getResponseCode(); | int responseCode = api.getResponseCode(); | ||||
if (responseCode != HTTP_OK) { | if (responseCode != HTTP_OK) { | ||||
throw new IOException( | throw new IOException( | ||||
private void uploadContents(HttpConnection api, | private void uploadContents(HttpConnection api, | ||||
Map<String, LfsPointer> oid2ptr) throws IOException { | Map<String, LfsPointer> oid2ptr) throws IOException { | ||||
try (JsonReader reader = new JsonReader( | try (JsonReader reader = new JsonReader( | ||||
new InputStreamReader(api.getInputStream(), CHARSET))) { | |||||
new InputStreamReader(api.getInputStream(), UTF_8))) { | |||||
for (Protocol.ObjectInfo o : parseObjects(reader)) { | for (Protocol.ObjectInfo o : parseObjects(reader)) { | ||||
if (o.actions == null) { | if (o.actions == null) { | ||||
continue; | continue; |
*/ | */ | ||||
package org.eclipse.jgit.lfs; | package org.eclipse.jgit.lfs; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
.write(gson | .write(gson | ||||
.toJson(LfsConnectionFactory | .toJson(LfsConnectionFactory | ||||
.toRequest(Protocol.OPERATION_DOWNLOAD, res)) | .toRequest(Protocol.OPERATION_DOWNLOAD, res)) | ||||
.getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
int responseCode = lfsServerConn.getResponseCode(); | int responseCode = lfsServerConn.getResponseCode(); | ||||
if (responseCode != HttpConnection.HTTP_OK) { | if (responseCode != HttpConnection.HTTP_OK) { | ||||
throw new IOException( | throw new IOException( | ||||
} | } | ||||
try (JsonReader reader = new JsonReader( | try (JsonReader reader = new JsonReader( | ||||
new InputStreamReader(lfsServerConn.getInputStream(), | new InputStreamReader(lfsServerConn.getInputStream(), | ||||
CHARSET))) { | |||||
UTF_8))) { | |||||
Protocol.Response resp = gson.fromJson(reader, | Protocol.Response resp = gson.fromJson(reader, | ||||
Protocol.Response.class); | Protocol.Response.class); | ||||
for (Protocol.ObjectInfo o : resp.objects) { | for (Protocol.ObjectInfo o : resp.objects) { |
*/ | */ | ||||
package org.eclipse.jgit.pgm; | package org.eclipse.jgit.pgm; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertArrayEquals; | import static org.junit.Assert.assertArrayEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.fail; | import static org.junit.Assert.fail; | ||||
private BufferedReader readFromProcess(Process proc) throws Exception { | private BufferedReader readFromProcess(Process proc) throws Exception { | ||||
return new BufferedReader( | return new BufferedReader( | ||||
new InputStreamReader(proc.getInputStream(), CHARSET)); | |||||
new InputStreamReader(proc.getInputStream(), UTF_8)); | |||||
} | } | ||||
private void grepForEntry(String name, String mode, String... cmdline) | private void grepForEntry(String name, String mode, String... cmdline) | ||||
// found! | // found! | ||||
List<String> l = new ArrayList<>(); | List<String> l = new ArrayList<>(); | ||||
BufferedReader reader = new BufferedReader( | BufferedReader reader = new BufferedReader( | ||||
new InputStreamReader(in, CHARSET)); | |||||
new InputStreamReader(in, UTF_8)); | |||||
String line; | String line; | ||||
while ((line = reader.readLine()) != null) | while ((line = reader.readLine()) != null) | ||||
l.add(line); | l.add(line); |
package org.eclipse.jgit.pgm; | package org.eclipse.jgit.pgm; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
private void scan(URL cUrl) { | private void scan(URL cUrl) { | ||||
try (BufferedReader cIn = new BufferedReader( | try (BufferedReader cIn = new BufferedReader( | ||||
new InputStreamReader(cUrl.openStream(), CHARSET))) { | |||||
new InputStreamReader(cUrl.openStream(), UTF_8))) { | |||||
String line; | String line; | ||||
while ((line = cIn.readLine()) != null) { | while ((line = cIn.readLine()) != null) { | ||||
if (line.length() > 0 && !line.startsWith("#")) //$NON-NLS-1$ | if (line.length() > 0 && !line.startsWith("#")) //$NON-NLS-1$ |
package org.eclipse.jgit.pgm; | package org.eclipse.jgit.pgm; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
} | } | ||||
PrintWriter createErrorWriter() { | PrintWriter createErrorWriter() { | ||||
return new PrintWriter(new OutputStreamWriter(System.err, CHARSET)); | |||||
return new PrintWriter(new OutputStreamWriter(System.err, UTF_8)); | |||||
} | } | ||||
private void execute(String[] argv) throws Exception { | private void execute(String[] argv) throws Exception { |
package org.eclipse.jgit.pgm.debug; | package org.eclipse.jgit.pgm.debug; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.HEAD; | import static org.eclipse.jgit.lib.Constants.HEAD; | ||||
import static org.eclipse.jgit.lib.Constants.MASTER; | import static org.eclipse.jgit.lib.Constants.MASTER; | ||||
import static org.eclipse.jgit.lib.Constants.R_HEADS; | import static org.eclipse.jgit.lib.Constants.R_HEADS; | ||||
throws IOException, FileNotFoundException { | throws IOException, FileNotFoundException { | ||||
RefList.Builder<Ref> list = new RefList.Builder<>(); | RefList.Builder<Ref> list = new RefList.Builder<>(); | ||||
try (BufferedReader br = new BufferedReader(new InputStreamReader( | try (BufferedReader br = new BufferedReader(new InputStreamReader( | ||||
new FileInputStream(lsRemotePath), CHARSET))) { | |||||
new FileInputStream(lsRemotePath), UTF_8))) { | |||||
Ref last = null; | Ref last = null; | ||||
String line; | String line; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { |
package org.eclipse.jgit.pgm.debug; | package org.eclipse.jgit.pgm.debug; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
try (RevWalk rw = new RevWalk(db); | try (RevWalk rw = new RevWalk(db); | ||||
final BufferedReader br = new BufferedReader( | final BufferedReader br = new BufferedReader( | ||||
new InputStreamReader(new FileInputStream(graph), | new InputStreamReader(new FileInputStream(graph), | ||||
Constants.CHARSET))) { | |||||
UTF_8))) { | |||||
String line; | String line; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { | ||||
final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$ | final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$ | ||||
try (RevWalk rw = new RevWalk(db); | try (RevWalk rw = new RevWalk(db); | ||||
BufferedReader br = new BufferedReader( | BufferedReader br = new BufferedReader( | ||||
new InputStreamReader(new FileInputStream(refList), | new InputStreamReader(new FileInputStream(refList), | ||||
Constants.CHARSET))) { | |||||
UTF_8))) { | |||||
String line; | String line; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { | ||||
final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$ | final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$ |
package org.eclipse.jgit.pgm.debug; | package org.eclipse.jgit.pgm.debug; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.HEAD; | import static org.eclipse.jgit.lib.Constants.HEAD; | ||||
import static org.eclipse.jgit.lib.Constants.MASTER; | import static org.eclipse.jgit.lib.Constants.MASTER; | ||||
import static org.eclipse.jgit.lib.Constants.R_HEADS; | import static org.eclipse.jgit.lib.Constants.R_HEADS; | ||||
static List<Ref> readRefs(String inputFile) throws IOException { | static List<Ref> readRefs(String inputFile) throws IOException { | ||||
List<Ref> refs = new ArrayList<>(); | List<Ref> refs = new ArrayList<>(); | ||||
try (BufferedReader br = new BufferedReader( | try (BufferedReader br = new BufferedReader( | ||||
new InputStreamReader(new FileInputStream(inputFile), CHARSET))) { | |||||
new InputStreamReader(new FileInputStream(inputFile), UTF_8))) { | |||||
String line; | String line; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { | ||||
ObjectId id = ObjectId.fromString(line.substring(0, 40)); | ObjectId id = ObjectId.fromString(line.substring(0, 40)); | ||||
List<LogEntry> log = new ArrayList<>(); | List<LogEntry> log = new ArrayList<>(); | ||||
try (BufferedReader br = new BufferedReader( | try (BufferedReader br = new BufferedReader( | ||||
new InputStreamReader(new FileInputStream(logPath), CHARSET))) { | |||||
new InputStreamReader(new FileInputStream(logPath), UTF_8))) { | |||||
@SuppressWarnings("nls") | @SuppressWarnings("nls") | ||||
Pattern pattern = Pattern.compile("([^,]+)" // 1: ref | Pattern pattern = Pattern.compile("([^,]+)" // 1: ref | ||||
+ ",([0-9]+(?:[.][0-9]+)?)" // 2: time | + ",([0-9]+(?:[.][0-9]+)?)" // 2: time |
*/ | */ | ||||
package org.eclipse.jgit.ignore; | package org.eclipse.jgit.ignore; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.File; | import java.io.File; | ||||
this.gitDir = gitDir; | this.gitDir = gitDir; | ||||
this.pattern = pattern; | this.pattern = pattern; | ||||
Files.write(FileUtils.toPath(new File(gitDir, ".gitignore")), | Files.write(FileUtils.toPath(new File(gitDir, ".gitignore")), | ||||
(pattern + "\n").getBytes(CHARSET), StandardOpenOption.CREATE, | |||||
(pattern + "\n").getBytes(UTF_8), StandardOpenOption.CREATE, | |||||
StandardOpenOption.TRUNCATE_EXISTING, | StandardOpenOption.TRUNCATE_EXISTING, | ||||
StandardOpenOption.WRITE); | StandardOpenOption.WRITE); | ||||
} | } | ||||
Process proc = Runtime.getRuntime().exec(command, new String[0], | Process proc = Runtime.getRuntime().exec(command, new String[0], | ||||
gitDir); | gitDir); | ||||
try (OutputStream out = proc.getOutputStream()) { | try (OutputStream out = proc.getOutputStream()) { | ||||
out.write((path + "\n").getBytes(CHARSET)); | |||||
out.write((path + "\n").getBytes(UTF_8)); | |||||
out.flush(); | out.flush(); | ||||
} | } | ||||
return proc; | return proc; |
package org.eclipse.jgit.patch; | package org.eclipse.jgit.patch; | ||||
import static java.nio.charset.StandardCharsets.ISO_8859_1; | import static java.nio.charset.StandardCharsets.ISO_8859_1; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.util.MutableInteger; | import org.eclipse.jgit.util.MutableInteger; | ||||
import org.eclipse.jgit.util.RawParseUtils; | import org.eclipse.jgit.util.RawParseUtils; | ||||
import org.eclipse.jgit.util.TemporaryBuffer; | import org.eclipse.jgit.util.TemporaryBuffer; | ||||
i.added = RawParseUtils.parseBase10(buf, ptr.value, ptr); | i.added = RawParseUtils.parseBase10(buf, ptr.value, ptr); | ||||
i.deleted = RawParseUtils.parseBase10(buf, ptr.value + 1, ptr); | i.deleted = RawParseUtils.parseBase10(buf, ptr.value + 1, ptr); | ||||
final int eol = RawParseUtils.nextLF(buf, ptr.value); | final int eol = RawParseUtils.nextLF(buf, ptr.value); | ||||
final String name = RawParseUtils.decode(Constants.CHARSET, | |||||
final String name = RawParseUtils.decode(UTF_8, | |||||
buf, ptr.value + 1, eol - 1); | buf, ptr.value + 1, eol - 1); | ||||
files.put(name, i); | files.put(name, i); | ||||
ptr.value = eol; | ptr.value = eol; |
package org.eclipse.jgit.api; | package org.eclipse.jgit.api; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_CRLF; | import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_CRLF; | ||||
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_LF; | import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_LF; | ||||
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.DIRECT; | import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.DIRECT; | ||||
EolStreamType streamTypeWithBinaryCheck, String output, | EolStreamType streamTypeWithBinaryCheck, String output, | ||||
String expectedConversion) throws Exception { | String expectedConversion) throws Exception { | ||||
ByteArrayOutputStream b; | ByteArrayOutputStream b; | ||||
byte[] outputBytes = output.getBytes(CHARSET); | |||||
byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET); | |||||
byte[] outputBytes = output.getBytes(UTF_8); | |||||
byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8); | |||||
// test using output text and assuming it was declared TEXT | // test using output text and assuming it was declared TEXT | ||||
b = new ByteArrayOutputStream(); | b = new ByteArrayOutputStream(); | ||||
private void testCheckin(EolStreamType streamTypeText, | private void testCheckin(EolStreamType streamTypeText, | ||||
EolStreamType streamTypeWithBinaryCheck, String input, | EolStreamType streamTypeWithBinaryCheck, String input, | ||||
String expectedConversion) throws Exception { | String expectedConversion) throws Exception { | ||||
byte[] inputBytes = input.getBytes(CHARSET); | |||||
byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET); | |||||
byte[] inputBytes = input.getBytes(UTF_8); | |||||
byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8); | |||||
// test using input text and assuming it was declared TEXT | // test using input text and assuming it was declared TEXT | ||||
try (InputStream in = EolStreamTypeUtil.wrapInputStream( | try (InputStream in = EolStreamTypeUtil.wrapInputStream( |
*/ | */ | ||||
package org.eclipse.jgit.api; | package org.eclipse.jgit.api; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import java.util.List; | import java.util.List; | ||||
git.notesAdd().setObjectId(commit2).setMessage("data").call(); | git.notesAdd().setObjectId(commit2).setMessage("data").call(); | ||||
Note note = git.notesShow().setObjectId(commit2).call(); | Note note = git.notesShow().setObjectId(commit2).call(); | ||||
String content = new String(db.open(note.getData()).getCachedBytes(), | String content = new String(db.open(note.getData()).getCachedBytes(), | ||||
CHARSET); | |||||
UTF_8); | |||||
assertEquals(content, "data"); | assertEquals(content, "data"); | ||||
git.notesRemove().setObjectId(commit2).call(); | git.notesRemove().setObjectId(commit2).call(); |
*/ | */ | ||||
package org.eclipse.jgit.api; | package org.eclipse.jgit.api; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
private static void writeToFile(File actFile, String string) | private static void writeToFile(File actFile, String string) | ||||
throws IOException { | throws IOException { | ||||
try (FileOutputStream fos = new FileOutputStream(actFile)) { | try (FileOutputStream fos = new FileOutputStream(actFile)) { | ||||
fos.write(string.getBytes(CHARSET)); | |||||
fos.write(string.getBytes(UTF_8)); | |||||
} | } | ||||
} | } | ||||
bos.write(buffer, 0, read); | bos.write(buffer, 0, read); | ||||
read = fis.read(buffer); | read = fis.read(buffer); | ||||
} | } | ||||
String content = new String(bos.toByteArray(), CHARSET); | |||||
String content = new String(bos.toByteArray(), UTF_8); | |||||
assertEquals(string, content); | assertEquals(string, content); | ||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.eclipse.jgit.api; | package org.eclipse.jgit.api; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
private static void writeToFile(File actFile, String string) | private static void writeToFile(File actFile, String string) | ||||
throws IOException { | throws IOException { | ||||
try (FileOutputStream fos = new FileOutputStream(actFile)) { | try (FileOutputStream fos = new FileOutputStream(actFile)) { | ||||
fos.write(string.getBytes(CHARSET)); | |||||
fos.write(string.getBytes(UTF_8)); | |||||
} | } | ||||
} | } | ||||
bos.write(buffer, 0, read); | bos.write(buffer, 0, read); | ||||
read = fis.read(buffer); | read = fis.read(buffer); | ||||
} | } | ||||
String content = new String(bos.toByteArray(), CHARSET); | |||||
String content = new String(bos.toByteArray(), UTF_8); | |||||
assertEquals(string, content); | assertEquals(string, content); | ||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.eclipse.jgit.api; | package org.eclipse.jgit.api; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.hamcrest.CoreMatchers.equalTo; | import static org.hamcrest.CoreMatchers.equalTo; | ||||
import static org.hamcrest.CoreMatchers.not; | import static org.hamcrest.CoreMatchers.not; | ||||
import static org.hamcrest.MatcherAssert.assertThat; | import static org.hamcrest.MatcherAssert.assertThat; | ||||
assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]); | assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]); | ||||
PersonIdent parsedIdent = git.rebase().parseAuthor( | PersonIdent parsedIdent = git.rebase().parseAuthor( | ||||
convertedAuthor.getBytes(CHARSET)); | |||||
convertedAuthor.getBytes(UTF_8)); | |||||
assertEquals(ident.getName(), parsedIdent.getName()); | assertEquals(ident.getName(), parsedIdent.getName()); | ||||
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); | assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); | ||||
// this is rounded to the last second | // this is rounded to the last second | ||||
assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]); | assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]); | ||||
parsedIdent = git.rebase().parseAuthor( | parsedIdent = git.rebase().parseAuthor( | ||||
convertedAuthor.getBytes(CHARSET)); | |||||
convertedAuthor.getBytes(UTF_8)); | |||||
assertEquals(ident.getName(), parsedIdent.getName()); | assertEquals(ident.getName(), parsedIdent.getName()); | ||||
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); | assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); | ||||
assertEquals(123456789000L, parsedIdent.getWhen().getTime()); | assertEquals(123456789000L, parsedIdent.getWhen().getTime()); | ||||
int count = 0; | int count = 0; | ||||
File todoFile = getTodoFile(); | File todoFile = getTodoFile(); | ||||
try (BufferedReader br = new BufferedReader(new InputStreamReader( | try (BufferedReader br = new BufferedReader(new InputStreamReader( | ||||
new FileInputStream(todoFile), CHARSET))) { | |||||
new FileInputStream(todoFile), UTF_8))) { | |||||
String line = br.readLine(); | String line = br.readLine(); | ||||
while (line != null) { | while (line != null) { | ||||
int firstBlank = line.indexOf(' '); | int firstBlank = line.indexOf(' '); |
*/ | */ | ||||
package org.eclipse.jgit.attributes; | package org.eclipse.jgit.attributes; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertArrayEquals; | import static org.junit.Assert.assertArrayEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import java.util.Set; | import java.util.Set; | ||||
import org.eclipse.jgit.junit.RepositoryTestCase; | import org.eclipse.jgit.junit.RepositoryTestCase; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.lib.StoredConfig; | import org.eclipse.jgit.lib.StoredConfig; | ||||
import org.eclipse.jgit.treewalk.FileTreeIterator; | import org.eclipse.jgit.treewalk.FileTreeIterator; | ||||
import org.eclipse.jgit.treewalk.TreeWalk; | import org.eclipse.jgit.treewalk.TreeWalk; | ||||
builder.directory(db.getWorkTree()); | builder.directory(db.getWorkTree()); | ||||
builder.environment().put("HOME", fs.userHome().getAbsolutePath()); | builder.environment().put("HOME", fs.userHome().getAbsolutePath()); | ||||
ExecutionResult result = fs.execute(builder, new ByteArrayInputStream( | ExecutionResult result = fs.execute(builder, new ByteArrayInputStream( | ||||
input.toString().getBytes(Constants.CHARSET))); | |||||
input.toString().getBytes(UTF_8))); | |||||
String errorOut = toString(result.getStderr()); | String errorOut = toString(result.getStderr()); | ||||
assertEquals("External git failed", "exit 0\n", | assertEquals("External git failed", "exit 0\n", | ||||
"exit " + result.getRc() + '\n' + errorOut); | "exit " + result.getRc() + '\n' + errorOut); | ||||
LinkedHashMap<String, Attributes> map = new LinkedHashMap<>(); | LinkedHashMap<String, Attributes> map = new LinkedHashMap<>(); | ||||
try (BufferedReader r = new BufferedReader(new InputStreamReader( | try (BufferedReader r = new BufferedReader(new InputStreamReader( | ||||
new BufferedInputStream(result.getStdout().openInputStream()), | new BufferedInputStream(result.getStdout().openInputStream()), | ||||
Constants.CHARSET))) { | |||||
UTF_8))) { | |||||
r.lines().forEach(line -> { | r.lines().forEach(line -> { | ||||
// Parse the line and add to result map | // Parse the line and add to result map | ||||
int start = 0; | int start = 0; |
package org.eclipse.jgit.diff; | package org.eclipse.jgit.diff; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
r.append(text.charAt(i)); | r.append(text.charAt(i)); | ||||
r.append('\n'); | r.append('\n'); | ||||
} | } | ||||
return new RawText(r.toString().getBytes(CHARSET)); | |||||
return new RawText(r.toString().getBytes(UTF_8)); | |||||
} | } | ||||
} | } |
package org.eclipse.jgit.diff; | package org.eclipse.jgit.diff; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertArrayEquals; | import static org.junit.Assert.assertArrayEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
e = c.reduceCommonStartEnd(t("abQxy"), t("abRxy"), e); | e = c.reduceCommonStartEnd(t("abQxy"), t("abRxy"), e); | ||||
assertEquals(new Edit(2, 3, 2, 3), e); | assertEquals(new Edit(2, 3, 2, 3), e); | ||||
RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(CHARSET)); | |||||
RawText b = new RawText("p\na b \nR\n c d \n".getBytes(CHARSET)); | |||||
RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(UTF_8)); | |||||
RawText b = new RawText("p\na b \nR\n c d \n".getBytes(UTF_8)); | |||||
e = new Edit(0, 4, 0, 4); | e = new Edit(0, 4, 0, 4); | ||||
e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e); | e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e); | ||||
assertEquals(new Edit(2, 3, 2, 3), e); | assertEquals(new Edit(2, 3, 2, 3), e); | ||||
RawText b; | RawText b; | ||||
Edit e; | Edit e; | ||||
a = new RawText("R\n y\n".getBytes(CHARSET)); | |||||
b = new RawText("S\n\n y\n".getBytes(CHARSET)); | |||||
a = new RawText("R\n y\n".getBytes(UTF_8)); | |||||
b = new RawText("S\n\n y\n".getBytes(UTF_8)); | |||||
e = new Edit(0, 2, 0, 3); | e = new Edit(0, 2, 0, 3); | ||||
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); | e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); | ||||
assertEquals(new Edit(0, 1, 0, 2), e); | assertEquals(new Edit(0, 1, 0, 2), e); | ||||
a = new RawText("S\n\n y\n".getBytes(CHARSET)); | |||||
b = new RawText("R\n y\n".getBytes(CHARSET)); | |||||
a = new RawText("S\n\n y\n".getBytes(UTF_8)); | |||||
b = new RawText("R\n y\n".getBytes(UTF_8)); | |||||
e = new Edit(0, 3, 0, 2); | e = new Edit(0, 3, 0, 2); | ||||
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); | e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); | ||||
assertEquals(new Edit(0, 2, 0, 1), e); | assertEquals(new Edit(0, 2, 0, 1), e); | ||||
RawText a; | RawText a; | ||||
RawText b; | RawText b; | ||||
Edit e; | Edit e; | ||||
a = new RawText("start".getBytes(CHARSET)); | |||||
b = new RawText("start of line".getBytes(CHARSET)); | |||||
a = new RawText("start".getBytes(UTF_8)); | |||||
b = new RawText("start of line".getBytes(UTF_8)); | |||||
e = new Edit(0, 1, 0, 1); | e = new Edit(0, 1, 0, 1); | ||||
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); | e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); | ||||
assertEquals(new Edit(0, 1, 0, 1), e); | assertEquals(new Edit(0, 1, 0, 1), e); | ||||
RawText a; | RawText a; | ||||
RawText b; | RawText b; | ||||
Edit e; | Edit e; | ||||
a = new RawText("start".getBytes(CHARSET)); | |||||
b = new RawText("start of\nlastline".getBytes(CHARSET)); | |||||
a = new RawText("start".getBytes(UTF_8)); | |||||
b = new RawText("start of\nlastline".getBytes(UTF_8)); | |||||
e = new Edit(0, 1, 0, 2); | e = new Edit(0, 1, 0, 2); | ||||
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); | e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); | ||||
assertEquals(new Edit(0, 1, 0, 2), e); | assertEquals(new Edit(0, 1, 0, 2), e); | ||||
r.append(text.charAt(i)); | r.append(text.charAt(i)); | ||||
r.append('\n'); | r.append('\n'); | ||||
} | } | ||||
return new RawText(r.toString().getBytes(CHARSET)); | |||||
return new RawText(r.toString().getBytes(UTF_8)); | |||||
} | } | ||||
} | } |
package org.eclipse.jgit.diff; | package org.eclipse.jgit.diff; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
+ "A\n" // | + "A\n" // | ||||
+ "B\n" // | + "B\n" // | ||||
+ "B\n" // | + "B\n" // | ||||
+ "B\n").getBytes(CHARSET); | |||||
+ "B\n").getBytes(UTF_8); | |||||
SimilarityIndex si = new SimilarityIndex(); | SimilarityIndex si = new SimilarityIndex(); | ||||
si.hash(new ByteArrayInputStream(in), in.length, false); | si.hash(new ByteArrayInputStream(in), in.length, false); | ||||
assertEquals(2, si.size()); | assertEquals(2, si.size()); | ||||
+ "D\r\n" // | + "D\r\n" // | ||||
+ "B\r\n"; | + "B\r\n"; | ||||
SimilarityIndex src = new SimilarityIndex(); | SimilarityIndex src = new SimilarityIndex(); | ||||
byte[] bytes1 = text.getBytes(CHARSET); | |||||
byte[] bytes1 = text.getBytes(UTF_8); | |||||
src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true); | src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true); | ||||
src.sort(); | src.sort(); | ||||
SimilarityIndex dst = new SimilarityIndex(); | SimilarityIndex dst = new SimilarityIndex(); | ||||
byte[] bytes2 = text.replace("\r", "").getBytes(CHARSET); | |||||
byte[] bytes2 = text.replace("\r", "").getBytes(UTF_8); | |||||
dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true); | dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true); | ||||
dst.sort(); | dst.sort(); | ||||
package org.eclipse.jgit.dircache; | package org.eclipse.jgit.dircache; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.junit.Assert.assertEquals; | import static org.eclipse.jgit.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertArrayEquals; | import static org.junit.Assert.assertArrayEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
private static Map<String, CGitIndexRecord> readLsFiles() throws Exception { | private static Map<String, CGitIndexRecord> readLsFiles() throws Exception { | ||||
final LinkedHashMap<String, CGitIndexRecord> r = new LinkedHashMap<>(); | final LinkedHashMap<String, CGitIndexRecord> r = new LinkedHashMap<>(); | ||||
try (BufferedReader br = new BufferedReader(new InputStreamReader( | try (BufferedReader br = new BufferedReader(new InputStreamReader( | ||||
new FileInputStream(pathOf("gitgit.lsfiles")), CHARSET))) { | |||||
new FileInputStream(pathOf("gitgit.lsfiles")), UTF_8))) { | |||||
String line; | String line; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { | ||||
final CGitIndexRecord cr = new CGitIndexRecord(line); | final CGitIndexRecord cr = new CGitIndexRecord(line); | ||||
private static Map<String, CGitLsTreeRecord> readLsTree() throws Exception { | private static Map<String, CGitLsTreeRecord> readLsTree() throws Exception { | ||||
final LinkedHashMap<String, CGitLsTreeRecord> r = new LinkedHashMap<>(); | final LinkedHashMap<String, CGitLsTreeRecord> r = new LinkedHashMap<>(); | ||||
try (BufferedReader br = new BufferedReader(new InputStreamReader( | try (BufferedReader br = new BufferedReader(new InputStreamReader( | ||||
new FileInputStream(pathOf("gitgit.lstree")), CHARSET))) { | |||||
new FileInputStream(pathOf("gitgit.lstree")), UTF_8))) { | |||||
String line; | String line; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { | ||||
final CGitLsTreeRecord cr = new CGitLsTreeRecord(line); | final CGitLsTreeRecord cr = new CGitLsTreeRecord(line); |
*/ | */ | ||||
package org.eclipse.jgit.gitrepo; | package org.eclipse.jgit.gitrepo; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
import static org.junit.Assert.fail; | import static org.junit.Assert.fail; | ||||
ManifestParser parser = new ManifestParser( | ManifestParser parser = new ManifestParser( | ||||
null, null, "master", baseUrl, null, null); | null, null, "master", baseUrl, null, null); | ||||
parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET))); | |||||
parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))); | |||||
// Unfiltered projects should have them all. | // Unfiltered projects should have them all. | ||||
results.clear(); | results.clear(); | ||||
results.add("foo"); | results.add("foo"); | ||||
baseUrl, null, null); | baseUrl, null, null); | ||||
try { | try { | ||||
parser.read(new ByteArrayInputStream( | parser.read(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))); | |||||
xmlContent.toString().getBytes(UTF_8))); | |||||
fail("ManifestParser did not throw exception for missing fetch"); | fail("ManifestParser did not throw exception for missing fetch"); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
assertTrue(e.getCause() instanceof SAXException); | assertTrue(e.getCause() instanceof SAXException); | ||||
ManifestParser parser = new ManifestParser(null, null, "master", | ManifestParser parser = new ManifestParser(null, null, "master", | ||||
"https://git.google.com/", null, null); | "https://git.google.com/", null, null); | ||||
parser.read(new ByteArrayInputStream( | parser.read(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))); | |||||
xmlContent.toString().getBytes(UTF_8))); | |||||
assertEquals(Stream.of("bar", "baz").collect(Collectors.toSet()), | assertEquals(Stream.of("bar", "baz").collect(Collectors.toSet()), | ||||
parser.getProjects().stream().map(RepoProject::getName) | parser.getProjects().stream().map(RepoProject::getName) |
*/ | */ | ||||
package org.eclipse.jgit.gitrepo; | package org.eclipse.jgit.gitrepo; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.assertNull; | import static org.junit.Assert.assertNull; | ||||
RevCommit commit = cmd | RevCommit commit = cmd | ||||
.setInputStream(new ByteArrayInputStream( | .setInputStream(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))) | |||||
xmlContent.toString().getBytes(UTF_8))) | |||||
.setRemoteReader(repos).setURI("platform/") | .setRemoteReader(repos).setURI("platform/") | ||||
.setTargetURI("platform/superproject") | .setTargetURI("platform/superproject") | ||||
.setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) | .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) | ||||
String firstIdStr = commit.getId().name() + ":" + ".gitmodules"; | String firstIdStr = commit.getId().name() + ":" + ".gitmodules"; | ||||
commit = new RepoCommand(dest) | commit = new RepoCommand(dest) | ||||
.setInputStream(new ByteArrayInputStream( | .setInputStream(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))) | |||||
xmlContent.toString().getBytes(UTF_8))) | |||||
.setRemoteReader(repos).setURI("platform/") | .setRemoteReader(repos).setURI("platform/") | ||||
.setTargetURI("platform/superproject") | .setTargetURI("platform/superproject") | ||||
.setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) | .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) | ||||
RevCommit commit = cmd | RevCommit commit = cmd | ||||
.setInputStream(new ByteArrayInputStream( | .setInputStream(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))) | |||||
xmlContent.toString().getBytes(UTF_8))) | |||||
.setRemoteReader(repos).setURI("platform/") | .setRemoteReader(repos).setURI("platform/") | ||||
.setTargetURI("platform/superproject") | .setTargetURI("platform/superproject") | ||||
.setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) | .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) | ||||
try (Repository dest = cloneRepository(db, true)) { | try (Repository dest = cloneRepository(db, true)) { | ||||
RevCommit commit = new RepoCommand(dest) | RevCommit commit = new RepoCommand(dest) | ||||
.setInputStream(new ByteArrayInputStream( | .setInputStream(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))) | |||||
xmlContent.toString().getBytes(UTF_8))) | |||||
.setRemoteReader(new IndexedRepos()).setURI("platform/") | .setRemoteReader(new IndexedRepos()).setURI("platform/") | ||||
.setTargetURI("platform/superproject") | .setTargetURI("platform/superproject") | ||||
.setRecordRemoteBranch(true).setIgnoreRemoteFailures(true) | .setRecordRemoteBranch(true).setIgnoreRemoteFailures(true) | ||||
RevCommit commit = cmd | RevCommit commit = cmd | ||||
.setInputStream(new ByteArrayInputStream( | .setInputStream(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))) | |||||
xmlContent.toString().getBytes(UTF_8))) | |||||
.setRemoteReader(repos).setURI("").setTargetURI("gerrit") | .setRemoteReader(repos).setURI("").setTargetURI("gerrit") | ||||
.setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) | .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) | ||||
.call(); | .call(); | ||||
RevCommit commit = cmd | RevCommit commit = cmd | ||||
.setInputStream(new ByteArrayInputStream( | .setInputStream(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))) | |||||
xmlContent.toString().getBytes(UTF_8))) | |||||
.setRemoteReader(repos).setURI(baseUrl) | .setRemoteReader(repos).setURI(baseUrl) | ||||
.setTargetURI("gerrit").setRecordRemoteBranch(true) | .setTargetURI("gerrit").setRecordRemoteBranch(true) | ||||
.setRecordSubmoduleLabels(true).call(); | .setRecordSubmoduleLabels(true).call(); | ||||
RevCommit commit = cmd | RevCommit commit = cmd | ||||
.setInputStream(new ByteArrayInputStream( | .setInputStream(new ByteArrayInputStream( | ||||
xmlContent.toString().getBytes(CHARSET))) | |||||
xmlContent.toString().getBytes(UTF_8))) | |||||
.setRemoteReader(repos).setURI(baseUrl) | .setRemoteReader(repos).setURI(baseUrl) | ||||
.setTargetURI(abs + "/superproject") | .setTargetURI(abs + "/superproject") | ||||
.setRecordRemoteBranch(true) | .setRecordRemoteBranch(true) |
*/ | */ | ||||
package org.eclipse.jgit.ignore; | package org.eclipse.jgit.ignore; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertArrayEquals; | import static org.junit.Assert.assertArrayEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import java.util.Set; | import java.util.Set; | ||||
import org.eclipse.jgit.junit.RepositoryTestCase; | import org.eclipse.jgit.junit.RepositoryTestCase; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.lib.StoredConfig; | import org.eclipse.jgit.lib.StoredConfig; | ||||
import org.eclipse.jgit.treewalk.FileTreeIterator; | import org.eclipse.jgit.treewalk.FileTreeIterator; | ||||
import org.eclipse.jgit.treewalk.TreeWalk; | import org.eclipse.jgit.treewalk.TreeWalk; | ||||
"exit " + result.getRc() + '\n' + errorOut); | "exit " + result.getRc() + '\n' + errorOut); | ||||
try (BufferedReader r = new BufferedReader(new InputStreamReader( | try (BufferedReader r = new BufferedReader(new InputStreamReader( | ||||
new BufferedInputStream(result.getStdout().openInputStream()), | new BufferedInputStream(result.getStdout().openInputStream()), | ||||
Constants.CHARSET))) { | |||||
UTF_8))) { | |||||
return r.lines().toArray(String[]::new); | return r.lines().toArray(String[]::new); | ||||
} | } | ||||
} | } | ||||
"exit " + result.getRc() + '\n' + errorOut); | "exit " + result.getRc() + '\n' + errorOut); | ||||
try (BufferedReader r = new BufferedReader(new InputStreamReader( | try (BufferedReader r = new BufferedReader(new InputStreamReader( | ||||
new BufferedInputStream(result.getStdout().openInputStream()), | new BufferedInputStream(result.getStdout().openInputStream()), | ||||
Constants.CHARSET))) { | |||||
UTF_8))) { | |||||
return r.lines().toArray(String[]::new); | return r.lines().toArray(String[]::new); | ||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.eclipse.jgit.ignore; | package org.eclipse.jgit.ignore; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.junit.Assert.assertEquals; | import static org.eclipse.jgit.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
for (String line : rules) { | for (String line : rules) { | ||||
data.append(line + "\n"); | data.append(line + "\n"); | ||||
} | } | ||||
return new ByteArrayInputStream(data.toString().getBytes(CHARSET)); | |||||
return new ByteArrayInputStream(data.toString().getBytes(UTF_8)); | |||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.eclipse.jgit.indexdiff; | package org.eclipse.jgit.indexdiff; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertArrayEquals; | import static org.junit.Assert.assertArrayEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
File restoreScript = new File(testDir, name + ".sh"); | File restoreScript = new File(testDir, name + ".sh"); | ||||
try (OutputStream out = new BufferedOutputStream( | try (OutputStream out = new BufferedOutputStream( | ||||
new FileOutputStream(restoreScript)); | new FileOutputStream(restoreScript)); | ||||
Writer writer = new OutputStreamWriter(out, CHARSET)) { | |||||
Writer writer = new OutputStreamWriter(out, UTF_8)) { | |||||
writer.write("echo `which git` 1>&2\n"); | writer.write("echo `which git` 1>&2\n"); | ||||
writer.write("echo `git --version` 1>&2\n"); | writer.write("echo `git --version` 1>&2\n"); | ||||
writer.write("git init " + name + " && \\\n"); | writer.write("git init " + name + " && \\\n"); | ||||
private String readStream(InputStream stream) throws IOException { | private String readStream(InputStream stream) throws IOException { | ||||
try (BufferedReader in = new BufferedReader( | try (BufferedReader in = new BufferedReader( | ||||
new InputStreamReader(stream, CHARSET))) { | |||||
new InputStreamReader(stream, UTF_8))) { | |||||
StringBuilder out = new StringBuilder(); | StringBuilder out = new StringBuilder(); | ||||
String line; | String line; | ||||
while ((line = in.readLine()) != null) { | while ((line = in.readLine()) != null) { |
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static org.eclipse.jgit.junit.Assert.assertEquals; | import static org.eclipse.jgit.junit.Assert.assertEquals; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; | import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
ObjectId blobId; | ObjectId blobId; | ||||
try (ObjectInserter ins = bareRepo.newObjectInserter()) { | try (ObjectInserter ins = bareRepo.newObjectInserter()) { | ||||
blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(CHARSET)); | |||||
blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(UTF_8)); | |||||
ins.flush(); | ins.flush(); | ||||
} | } | ||||
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static java.nio.charset.StandardCharsets.ISO_8859_1; | import static java.nio.charset.StandardCharsets.ISO_8859_1; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
+ " email = A U Thor <thor@example.com> # Just an example...\n" | + " email = A U Thor <thor@example.com> # Just an example...\n" | ||||
+ " name = \"A Thor \\\\ \\\"\\t \"\n" | + " name = \"A Thor \\\\ \\\"\\t \"\n" | ||||
+ " defaultCheckInComment = a many line\\ncomment\\n to test\n"; | + " defaultCheckInComment = a many line\\ncomment\\n to test\n"; | ||||
assertEquals(expectedStr, new String(IO.readFully(cfg), Constants.CHARSET)); | |||||
assertEquals(expectedStr, new String(IO.readFully(cfg), UTF_8)); | |||||
} | } | ||||
@Test | @Test | ||||
4294967295000L, 60)); | 4294967295000L, 60)); | ||||
commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com", | commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com", | ||||
4294967295000L, 60)); | 4294967295000L, 60)); | ||||
commit.setEncoding(CHARSET); | |||||
commit.setEncoding(UTF_8); | |||||
commit.setMessage("\u00dcbergeeks"); | commit.setMessage("\u00dcbergeeks"); | ||||
ObjectId cid = insertCommit(commit); | ObjectId cid = insertCommit(commit); | ||||
assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name()); | assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name()); | ||||
final ObjectId treeId; | final ObjectId treeId; | ||||
try (ObjectInserter oi = db.newObjectInserter()) { | try (ObjectInserter oi = db.newObjectInserter()) { | ||||
final ObjectId blobId = oi.insert(Constants.OBJ_BLOB, | final ObjectId blobId = oi.insert(Constants.OBJ_BLOB, | ||||
"and this is the data in me\n".getBytes(Constants.CHARSET | |||||
"and this is the data in me\n".getBytes(UTF_8 | |||||
.name())); | .name())); | ||||
TreeFormatter fmt = new TreeFormatter(); | TreeFormatter fmt = new TreeFormatter(); | ||||
fmt.append("i-am-a-file", FileMode.REGULAR_FILE, blobId); | fmt.append("i-am-a-file", FileMode.REGULAR_FILE, blobId); | ||||
ObjectId id2; | ObjectId id2; | ||||
try (ObjectInserter ins = db.newObjectInserter()) { | try (ObjectInserter ins = db.newObjectInserter()) { | ||||
id1 = ins.insert( | id1 = ins.insert( | ||||
Constants.OBJ_BLOB, "contents1".getBytes(Constants.CHARSET)); | |||||
Constants.OBJ_BLOB, "contents1".getBytes(UTF_8)); | |||||
id2 = ins.insert( | id2 = ins.insert( | ||||
Constants.OBJ_BLOB, "contents2".getBytes(Constants.CHARSET)); | |||||
Constants.OBJ_BLOB, "contents2".getBytes(UTF_8)); | |||||
ins.flush(); | ins.flush(); | ||||
} | } | ||||
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
try (BufferedReader br = new BufferedReader(new InputStreamReader( | try (BufferedReader br = new BufferedReader(new InputStreamReader( | ||||
new FileInputStream(JGitTestUtil | new FileInputStream(JGitTestUtil | ||||
.getTestResourceFile("all_packed_objects.txt")), | .getTestResourceFile("all_packed_objects.txt")), | ||||
Constants.CHARSET))) { | |||||
UTF_8))) { | |||||
String line; | String line; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { | ||||
final String[] parts = line.split(" {1,}"); | final String[] parts = line.split(" {1,}"); |
package org.eclipse.jgit.junit; | package org.eclipse.jgit.junit; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.assertNotEquals; | import static org.junit.Assert.assertNotEquals; | ||||
RevObject obj = tr.get(rw.parseTree(treeish), path); | RevObject obj = tr.get(rw.parseTree(treeish), path); | ||||
assertSame(RevBlob.class, obj.getClass()); | assertSame(RevBlob.class, obj.getClass()); | ||||
ObjectLoader loader = rw.getObjectReader().open(obj); | ObjectLoader loader = rw.getObjectReader().open(obj); | ||||
return new String(loader.getCachedBytes(), CHARSET); | |||||
return new String(loader.getCachedBytes(), UTF_8); | |||||
} | } | ||||
} | } |
package org.eclipse.jgit.lib; | package org.eclipse.jgit.lib; | ||||
import static java.lang.Integer.valueOf; | import static java.lang.Integer.valueOf; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.junit.JGitTestUtil.concat; | import static org.eclipse.jgit.junit.JGitTestUtil.concat; | ||||
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH; | import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH; | ||||
import static org.eclipse.jgit.lib.Constants.OBJ_BAD; | import static org.eclipse.jgit.lib.Constants.OBJ_BAD; | ||||
StringBuilder b = new StringBuilder(); | StringBuilder b = new StringBuilder(); | ||||
entry(b, "100644 A"); | entry(b, "100644 A"); | ||||
entry(b, "100644 a"); | entry(b, "100644 a"); | ||||
byte[] data = b.toString().getBytes(CHARSET); | |||||
byte[] data = b.toString().getBytes(UTF_8); | |||||
checker.setSafeForWindows(true); | checker.setSafeForWindows(true); | ||||
assertCorrupt("duplicate entry names", OBJ_TREE, data); | assertCorrupt("duplicate entry names", OBJ_TREE, data); | ||||
assertSkipListAccepts(OBJ_TREE, data); | assertSkipListAccepts(OBJ_TREE, data); | ||||
StringBuilder b = new StringBuilder(); | StringBuilder b = new StringBuilder(); | ||||
entry(b, "100644 A"); | entry(b, "100644 A"); | ||||
entry(b, "100644 a"); | entry(b, "100644 a"); | ||||
byte[] data = b.toString().getBytes(CHARSET); | |||||
byte[] data = b.toString().getBytes(UTF_8); | |||||
checker.setSafeForMacOS(true); | checker.setSafeForMacOS(true); | ||||
assertCorrupt("duplicate entry names", OBJ_TREE, data); | assertCorrupt("duplicate entry names", OBJ_TREE, data); | ||||
assertSkipListAccepts(OBJ_TREE, data); | assertSkipListAccepts(OBJ_TREE, data); | ||||
StringBuilder b = new StringBuilder(); | StringBuilder b = new StringBuilder(); | ||||
entry(b, "100644 \u0065\u0301"); | entry(b, "100644 \u0065\u0301"); | ||||
entry(b, "100644 \u00e9"); | entry(b, "100644 \u00e9"); | ||||
byte[] data = b.toString().getBytes(CHARSET); | |||||
byte[] data = b.toString().getBytes(UTF_8); | |||||
checker.setSafeForMacOS(true); | checker.setSafeForMacOS(true); | ||||
assertCorrupt("duplicate entry names", OBJ_TREE, data); | assertCorrupt("duplicate entry names", OBJ_TREE, data); | ||||
assertSkipListAccepts(OBJ_TREE, data); | assertSkipListAccepts(OBJ_TREE, data); | ||||
StringBuilder b = new StringBuilder(); | StringBuilder b = new StringBuilder(); | ||||
entry(b, "100644 A"); | entry(b, "100644 A"); | ||||
checker.setSafeForMacOS(true); | checker.setSafeForMacOS(true); | ||||
checker.checkTree(b.toString().getBytes(CHARSET)); | |||||
checker.checkTree(b.toString().getBytes(UTF_8)); | |||||
} | } | ||||
@Test | @Test |
*/ | */ | ||||
package org.eclipse.jgit.merge; | package org.eclipse.jgit.merge; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
StringBuilder result = new StringBuilder(); | StringBuilder result = new StringBuilder(); | ||||
ObjectReader or = r.newObjectReader(); | ObjectReader or = r.newObjectReader(); | ||||
try (BufferedReader br = new BufferedReader( | try (BufferedReader br = new BufferedReader( | ||||
new InputStreamReader(or.open(blobId).openStream(), CHARSET))) { | |||||
new InputStreamReader(or.open(blobId).openStream(), UTF_8))) { | |||||
String line; | String line; | ||||
boolean first = true; | boolean first = true; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { |
*/ | */ | ||||
package org.eclipse.jgit.merge; | package org.eclipse.jgit.merge; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; | import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
} | } | ||||
binary[50] = '\0'; | binary[50] = '\0'; | ||||
writeTrashFile("file", new String(binary, CHARSET)); | |||||
writeTrashFile("file", new String(binary, UTF_8)); | |||||
git.add().addFilepattern("file").call(); | git.add().addFilepattern("file").call(); | ||||
RevCommit first = git.commit().setMessage("added file").call(); | RevCommit first = git.commit().setMessage("added file").call(); | ||||
int idx = LINELEN * 1200 + 1; | int idx = LINELEN * 1200 + 1; | ||||
byte save = binary[idx]; | byte save = binary[idx]; | ||||
binary[idx] = '@'; | binary[idx] = '@'; | ||||
writeTrashFile("file", new String(binary, CHARSET)); | |||||
writeTrashFile("file", new String(binary, UTF_8)); | |||||
binary[idx] = save; | binary[idx] = save; | ||||
git.add().addFilepattern("file").call(); | git.add().addFilepattern("file").call(); | ||||
git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call(); | git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call(); | ||||
binary[LINELEN * 1500 + 1] = '!'; | binary[LINELEN * 1500 + 1] = '!'; | ||||
writeTrashFile("file", new String(binary, CHARSET)); | |||||
writeTrashFile("file", new String(binary, UTF_8)); | |||||
git.add().addFilepattern("file").call(); | git.add().addFilepattern("file").call(); | ||||
RevCommit sideCommit = git.commit().setAll(true) | RevCommit sideCommit = git.commit().setAll(true) | ||||
.setMessage("modified file l 1500").call(); | .setMessage("modified file l 1500").call(); | ||||
merger.getMergeResults().get("file"); | merger.getMergeResults().get("file"); | ||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { | try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { | ||||
fmt.formatMerge(out, merger.getMergeResults().get("file"), | fmt.formatMerge(out, merger.getMergeResults().get("file"), | ||||
"BASE", "OURS", "THEIRS", CHARSET.name()); | |||||
"BASE", "OURS", "THEIRS", UTF_8.name()); | |||||
String expected = "<<<<<<< OURS\n" | String expected = "<<<<<<< OURS\n" | ||||
+ "1master\n" | + "1master\n" | ||||
+ "=======\n" | + "=======\n" | ||||
+ ">>>>>>> THEIRS\n" | + ">>>>>>> THEIRS\n" | ||||
+ "2\n" | + "2\n" | ||||
+ "3"; | + "3"; | ||||
assertEquals(expected, new String(out.toByteArray(), CHARSET)); | |||||
assertEquals(expected, new String(out.toByteArray(), UTF_8)); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
if (obj == null) { | if (obj == null) { | ||||
return null; | return null; | ||||
} | } | ||||
return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), CHARSET); | |||||
return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), | |||||
UTF_8); | |||||
} | } | ||||
} | } |
package org.eclipse.jgit.patch; | package org.eclipse.jgit.patch; | ||||
import static java.nio.charset.StandardCharsets.ISO_8859_1; | import static java.nio.charset.StandardCharsets.ISO_8859_1; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
import static org.junit.Assert.fail; | import static org.junit.Assert.fail; | ||||
@Test | @Test | ||||
public void testGetText_Convert() throws IOException { | public void testGetText_Convert() throws IOException { | ||||
final Charset csOld = ISO_8859_1; | final Charset csOld = ISO_8859_1; | ||||
final Charset csNew = CHARSET; | |||||
final Charset csNew = UTF_8; | |||||
final Patch p = parseTestPatchFile(); | final Patch p = parseTestPatchFile(); | ||||
assertTrue(p.getErrors().isEmpty()); | assertTrue(p.getErrors().isEmpty()); | ||||
assertEquals(1, p.getFiles().size()); | assertEquals(1, p.getFiles().size()); | ||||
@Test | @Test | ||||
public void testGetText_DiffCc() throws IOException { | public void testGetText_DiffCc() throws IOException { | ||||
final Charset csOld = ISO_8859_1; | final Charset csOld = ISO_8859_1; | ||||
final Charset csNew = CHARSET; | |||||
final Charset csNew = UTF_8; | |||||
final Patch p = parseTestPatchFile(); | final Patch p = parseTestPatchFile(); | ||||
assertTrue(p.getErrors().isEmpty()); | assertTrue(p.getErrors().isEmpty()); | ||||
assertEquals(1, p.getFiles().size()); | assertEquals(1, p.getFiles().size()); |
package org.eclipse.jgit.revwalk; | package org.eclipse.jgit.revwalk; | ||||
import static java.nio.charset.StandardCharsets.ISO_8859_1; | import static java.nio.charset.StandardCharsets.ISO_8859_1; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
import static org.junit.Assert.assertNull; | import static org.junit.Assert.assertNull; | ||||
assertNull(c.getTree()); | assertNull(c.getTree()); | ||||
assertNull(c.parents); | assertNull(c.parents); | ||||
c.parseCanonical(rw, body.toString().getBytes(CHARSET)); | |||||
c.parseCanonical(rw, body.toString().getBytes(UTF_8)); | |||||
assertNotNull(c.getTree()); | assertNotNull(c.getTree()); | ||||
assertEquals(treeId, c.getTree().getId()); | assertEquals(treeId, c.getTree().getId()); | ||||
assertSame(rw.lookupTree(treeId), c.getTree()); | assertSame(rw.lookupTree(treeId), c.getTree()); | ||||
final RevCommit c; | final RevCommit c; | ||||
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET)); | |||||
c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8)); | |||||
return c; | return c; | ||||
} | } | ||||
final RevCommit c; | final RevCommit c; | ||||
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET)); | |||||
c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8)); | |||||
assertEquals("", c.getFullMessage()); | assertEquals("", c.getFullMessage()); | ||||
assertEquals("", c.getShortMessage()); | assertEquals("", c.getShortMessage()); | ||||
final RevCommit c; | final RevCommit c; | ||||
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET)); | |||||
c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8)); | |||||
assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent()); | assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent()); | ||||
assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent()); | assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent()); | ||||
@Test | @Test | ||||
public void testParse_implicit_UTF8_encoded() throws Exception { | public void testParse_implicit_UTF8_encoded() throws Exception { | ||||
final ByteArrayOutputStream b = new ByteArrayOutputStream(); | final ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); | |||||
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(CHARSET)); | |||||
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); | |||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); | |||||
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8)); | |||||
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8)); | |||||
final RevCommit c; | final RevCommit c; | ||||
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id | c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id | ||||
c.parseCanonical(new RevWalk(db), b.toByteArray()); | c.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
assertSame(Constants.CHARSET, c.getEncoding()); | |||||
assertSame(UTF_8, c.getEncoding()); | |||||
assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName()); | assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName()); | ||||
assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage()); | assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage()); | ||||
assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); | assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); | ||||
@Test | @Test | ||||
public void testParse_implicit_mixed_encoded() throws Exception { | public void testParse_implicit_mixed_encoded() throws Exception { | ||||
final ByteArrayOutputStream b = new ByteArrayOutputStream(); | final ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); | |||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); | |||||
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1)); | b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1)); | ||||
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); | |||||
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8)); | |||||
final RevCommit c; | final RevCommit c; | ||||
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id | c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id | ||||
c.parseCanonical(new RevWalk(db), b.toByteArray()); | c.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
assertSame(Constants.CHARSET, c.getEncoding()); | |||||
assertSame(UTF_8, c.getEncoding()); | |||||
assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName()); | assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName()); | ||||
assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage()); | assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage()); | ||||
assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); | assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); | ||||
@Test | @Test | ||||
public void testParse_explicit_bad_encoded() throws Exception { | public void testParse_explicit_bad_encoded() throws Exception { | ||||
final ByteArrayOutputStream b = new ByteArrayOutputStream(); | final ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); | |||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); | |||||
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1)); | b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1)); | ||||
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET)); | |||||
b.write("encoding EUC-JP\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Hi\n".getBytes(CHARSET)); | |||||
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8)); | |||||
b.write("encoding EUC-JP\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Hi\n".getBytes(UTF_8)); | |||||
final RevCommit c; | final RevCommit c; | ||||
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id | c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id | ||||
c.parseCanonical(new RevWalk(db), b.toByteArray()); | c.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
@Test | @Test | ||||
public void testParse_explicit_bad_encoded2() throws Exception { | public void testParse_explicit_bad_encoded2() throws Exception { | ||||
final ByteArrayOutputStream b = new ByteArrayOutputStream(); | final ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); | |||||
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(CHARSET)); | |||||
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET)); | |||||
b.write("encoding ISO-8859-1\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Hi\n".getBytes(CHARSET)); | |||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); | |||||
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8)); | |||||
b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8)); | |||||
b.write("encoding ISO-8859-1\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Hi\n".getBytes(UTF_8)); | |||||
final RevCommit c; | final RevCommit c; | ||||
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id | c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id | ||||
c.parseCanonical(new RevWalk(db), b.toByteArray()); | c.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
public void testParse_incorrectUtf8Name() throws Exception { | public void testParse_incorrectUtf8Name() throws Exception { | ||||
ByteArrayOutputStream b = new ByteArrayOutputStream(); | ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | ||||
.getBytes(CHARSET)); | |||||
b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8)); | |||||
b.write("committer co <c@example.com> 1218123390 -0500\n" | b.write("committer co <c@example.com> 1218123390 -0500\n" | ||||
.getBytes(CHARSET)); | |||||
b.write("encoding 'utf8'\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
b.write("encoding 'utf8'\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8)); | |||||
RevCommit c = new RevCommit( | RevCommit c = new RevCommit( | ||||
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
@Test | @Test | ||||
public void testParse_illegalEncoding() throws Exception { | public void testParse_illegalEncoding() throws Exception { | ||||
ByteArrayOutputStream b = new ByteArrayOutputStream(); | ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); | |||||
b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET)); | |||||
b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(CHARSET)); | |||||
b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("message\n".getBytes(CHARSET)); | |||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); | |||||
b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8)); | |||||
b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8)); | |||||
b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("message\n".getBytes(UTF_8)); | |||||
RevCommit c = new RevCommit( | RevCommit c = new RevCommit( | ||||
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
@Test | @Test | ||||
public void testParse_unsupportedEncoding() throws Exception { | public void testParse_unsupportedEncoding() throws Exception { | ||||
ByteArrayOutputStream b = new ByteArrayOutputStream(); | ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); | |||||
b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET)); | |||||
b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(CHARSET)); | |||||
b.write("encoding it_IT.UTF8\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("message\n".getBytes(CHARSET)); | |||||
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); | |||||
b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8)); | |||||
b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8)); | |||||
b.write("encoding it_IT.UTF8\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("message\n".getBytes(UTF_8)); | |||||
RevCommit c = new RevCommit( | RevCommit c = new RevCommit( | ||||
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); |
package org.eclipse.jgit.revwalk; | package org.eclipse.jgit.revwalk; | ||||
import static java.nio.charset.StandardCharsets.ISO_8859_1; | import static java.nio.charset.StandardCharsets.ISO_8859_1; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
import static org.junit.Assert.assertNull; | import static org.junit.Assert.assertNull; | ||||
assertNull(c.getObject()); | assertNull(c.getObject()); | ||||
assertNull(c.getTagName()); | assertNull(c.getTagName()); | ||||
c.parseCanonical(rw, b.toString().getBytes(CHARSET)); | |||||
c.parseCanonical(rw, b.toString().getBytes(UTF_8)); | |||||
assertNotNull(c.getObject()); | assertNotNull(c.getObject()); | ||||
assertEquals(id, c.getObject().getId()); | assertEquals(id, c.getObject().getId()); | ||||
assertSame(rw.lookupAny(id, typeCode), c.getObject()); | assertSame(rw.lookupAny(id, typeCode), c.getObject()); | ||||
assertNull(c.getObject()); | assertNull(c.getObject()); | ||||
assertNull(c.getTagName()); | assertNull(c.getTagName()); | ||||
c.parseCanonical(rw, body.toString().getBytes(CHARSET)); | |||||
c.parseCanonical(rw, body.toString().getBytes(UTF_8)); | |||||
assertNotNull(c.getObject()); | assertNotNull(c.getObject()); | ||||
assertEquals(treeId, c.getObject().getId()); | assertEquals(treeId, c.getObject().getId()); | ||||
assertSame(rw.lookupTree(treeId), c.getObject()); | assertSame(rw.lookupTree(treeId), c.getObject()); | ||||
assertNull(c.getObject()); | assertNull(c.getObject()); | ||||
assertNull(c.getTagName()); | assertNull(c.getTagName()); | ||||
c.parseCanonical(rw, body.toString().getBytes(CHARSET)); | |||||
c.parseCanonical(rw, body.toString().getBytes(UTF_8)); | |||||
assertNotNull(c.getObject()); | assertNotNull(c.getObject()); | ||||
assertEquals(treeId, c.getObject().getId()); | assertEquals(treeId, c.getObject().getId()); | ||||
assertSame(rw.lookupTree(treeId), c.getObject()); | assertSame(rw.lookupTree(treeId), c.getObject()); | ||||
final RevTag c; | final RevTag c; | ||||
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET)); | |||||
c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8)); | |||||
return c; | return c; | ||||
} | } | ||||
public void testParse_implicit_UTF8_encoded() throws Exception { | public void testParse_implicit_UTF8_encoded() throws Exception { | ||||
final ByteArrayOutputStream b = new ByteArrayOutputStream(); | final ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | ||||
.getBytes(CHARSET)); | |||||
b.write("type tree\n".getBytes(CHARSET)); | |||||
b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
b.write("type tree\n".getBytes(UTF_8)); | |||||
b.write("tag v1.2.3.4.5\n".getBytes(UTF_8)); | |||||
b | b | ||||
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" | .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" | ||||
.getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8)); | |||||
final RevTag c; | final RevTag c; | ||||
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
c.parseCanonical(new RevWalk(db), b.toByteArray()); | c.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
public void testParse_implicit_mixed_encoded() throws Exception { | public void testParse_implicit_mixed_encoded() throws Exception { | ||||
final ByteArrayOutputStream b = new ByteArrayOutputStream(); | final ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | ||||
.getBytes(CHARSET)); | |||||
b.write("type tree\n".getBytes(CHARSET)); | |||||
b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
b.write("type tree\n".getBytes(UTF_8)); | |||||
b.write("tag v1.2.3.4.5\n".getBytes(UTF_8)); | |||||
b.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" | b.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" | ||||
.getBytes(ISO_8859_1)); | .getBytes(ISO_8859_1)); | ||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8)); | |||||
final RevTag c; | final RevTag c; | ||||
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
c.parseCanonical(new RevWalk(db), b.toByteArray()); | c.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
public void testParse_explicit_bad_encoded() throws Exception { | public void testParse_explicit_bad_encoded() throws Exception { | ||||
final ByteArrayOutputStream b = new ByteArrayOutputStream(); | final ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | ||||
.getBytes(CHARSET)); | |||||
b.write("type tree\n".getBytes(CHARSET)); | |||||
b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
b.write("type tree\n".getBytes(UTF_8)); | |||||
b.write("tag v1.2.3.4.5\n".getBytes(UTF_8)); | |||||
b | b | ||||
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" | .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" | ||||
.getBytes(ISO_8859_1)); | .getBytes(ISO_8859_1)); | ||||
b.write("encoding EUC-JP\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Hi\n".getBytes(CHARSET)); | |||||
b.write("encoding EUC-JP\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Hi\n".getBytes(UTF_8)); | |||||
final RevTag c; | final RevTag c; | ||||
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
c.parseCanonical(new RevWalk(db), b.toByteArray()); | c.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
public void testParse_explicit_bad_encoded2() throws Exception { | public void testParse_explicit_bad_encoded2() throws Exception { | ||||
final ByteArrayOutputStream b = new ByteArrayOutputStream(); | final ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" | ||||
.getBytes(CHARSET)); | |||||
b.write("type tree\n".getBytes(CHARSET)); | |||||
b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
b.write("type tree\n".getBytes(UTF_8)); | |||||
b.write("tag v1.2.3.4.5\n".getBytes(UTF_8)); | |||||
b | b | ||||
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" | .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n" | ||||
.getBytes(CHARSET)); | |||||
b.write("encoding ISO-8859-1\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("Hi\n".getBytes(CHARSET)); | |||||
.getBytes(UTF_8)); | |||||
b.write("encoding ISO-8859-1\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("\u304d\u308c\u3044\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("Hi\n".getBytes(UTF_8)); | |||||
final RevTag c; | final RevTag c; | ||||
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
c.parseCanonical(new RevWalk(db), b.toByteArray()); | c.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
@Test | @Test | ||||
public void testParse_illegalEncoding() throws Exception { | public void testParse_illegalEncoding() throws Exception { | ||||
ByteArrayOutputStream b = new ByteArrayOutputStream(); | ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); | |||||
b.write("type tree\n".getBytes(CHARSET)); | |||||
b.write("tag v1.0\n".getBytes(CHARSET)); | |||||
b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(CHARSET)); | |||||
b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("message\n".getBytes(CHARSET)); | |||||
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); | |||||
b.write("type tree\n".getBytes(UTF_8)); | |||||
b.write("tag v1.0\n".getBytes(UTF_8)); | |||||
b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8)); | |||||
b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("message\n".getBytes(UTF_8)); | |||||
RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
t.parseCanonical(new RevWalk(db), b.toByteArray()); | t.parseCanonical(new RevWalk(db), b.toByteArray()); | ||||
@Test | @Test | ||||
public void testParse_unsupportedEncoding() throws Exception { | public void testParse_unsupportedEncoding() throws Exception { | ||||
ByteArrayOutputStream b = new ByteArrayOutputStream(); | ByteArrayOutputStream b = new ByteArrayOutputStream(); | ||||
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); | |||||
b.write("type tree\n".getBytes(CHARSET)); | |||||
b.write("tag v1.0\n".getBytes(CHARSET)); | |||||
b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(CHARSET)); | |||||
b.write("encoding it_IT.UTF8\n".getBytes(CHARSET)); | |||||
b.write("\n".getBytes(CHARSET)); | |||||
b.write("message\n".getBytes(CHARSET)); | |||||
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); | |||||
b.write("type tree\n".getBytes(UTF_8)); | |||||
b.write("tag v1.0\n".getBytes(UTF_8)); | |||||
b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8)); | |||||
b.write("encoding it_IT.UTF8\n".getBytes(UTF_8)); | |||||
b.write("\n".getBytes(UTF_8)); | |||||
b.write("message\n".getBytes(UTF_8)); | |||||
RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); | ||||
t.parseCanonical(new RevWalk(db), b.toByteArray()); | t.parseCanonical(new RevWalk(db), b.toByteArray()); |
*/ | */ | ||||
package org.eclipse.jgit.storage.file; | package org.eclipse.jgit.storage.file; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.util.FileUtils.pathToString; | import static org.eclipse.jgit.util.FileUtils.pathToString; | ||||
import static org.junit.Assert.assertArrayEquals; | import static org.junit.Assert.assertArrayEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
@Test | @Test | ||||
public void testUTF8withoutBOM() throws IOException, ConfigInvalidException { | public void testUTF8withoutBOM() throws IOException, ConfigInvalidException { | ||||
final File file = createFile(CONTENT1.getBytes(CHARSET)); | |||||
final File file = createFile(CONTENT1.getBytes(UTF_8)); | |||||
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); | final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); | ||||
config.load(); | config.load(); | ||||
assertEquals(ALICE, config.getString(USER, null, NAME)); | assertEquals(ALICE, config.getString(USER, null, NAME)); | ||||
bos1.write(0xEF); | bos1.write(0xEF); | ||||
bos1.write(0xBB); | bos1.write(0xBB); | ||||
bos1.write(0xBF); | bos1.write(0xBF); | ||||
bos1.write(CONTENT1.getBytes(CHARSET)); | |||||
bos1.write(CONTENT1.getBytes(UTF_8)); | |||||
final File file = createFile(bos1.toByteArray()); | final File file = createFile(bos1.toByteArray()); | ||||
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); | final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); | ||||
bos2.write(0xEF); | bos2.write(0xEF); | ||||
bos2.write(0xBB); | bos2.write(0xBB); | ||||
bos2.write(0xBF); | bos2.write(0xBF); | ||||
bos2.write(CONTENT2.getBytes(CHARSET)); | |||||
bos2.write(CONTENT2.getBytes(UTF_8)); | |||||
assertArrayEquals(bos2.toByteArray(), IO.readFully(file)); | assertArrayEquals(bos2.toByteArray(), IO.readFully(file)); | ||||
} | } | ||||
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; | import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
Ref ref = repo.exactRef(refName); | Ref ref = repo.exactRef(refName); | ||||
assertNotNull(ref); | assertNotNull(ref); | ||||
assertEquals(id, ref.getObjectId()); | assertEquals(id, ref.getObjectId()); | ||||
assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), CHARSET)); | |||||
assertEquals(data, | |||||
new String(repo.open(id, OBJ_BLOB).getBytes(), UTF_8)); | |||||
} | } | ||||
} | } | ||||
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertNull; | import static org.junit.Assert.assertNull; | ||||
private void config(String data) throws IOException { | private void config(String data) throws IOException { | ||||
try (OutputStreamWriter fw = new OutputStreamWriter( | try (OutputStreamWriter fw = new OutputStreamWriter( | ||||
new FileOutputStream(configFile), CHARSET)) { | |||||
new FileOutputStream(configFile), UTF_8)) { | |||||
fw.write(data); | fw.write(data); | ||||
} | } | ||||
} | } |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertArrayEquals; | import static org.junit.Assert.assertArrayEquals; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
long lastMtime = configFile.lastModified(); | long lastMtime = configFile.lastModified(); | ||||
do { | do { | ||||
try (final OutputStreamWriter fw = new OutputStreamWriter( | try (final OutputStreamWriter fw = new OutputStreamWriter( | ||||
new FileOutputStream(configFile), CHARSET)) { | |||||
new FileOutputStream(configFile), UTF_8)) { | |||||
fw.write(data); | fw.write(data); | ||||
} | } | ||||
} while (lastMtime == configFile.lastModified()); | } while (lastMtime == configFile.lastModified()); |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListPBE; | import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListPBE; | ||||
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans; | import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans; | ||||
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete; | import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete; | ||||
* @throws Exception | * @throws Exception | ||||
*/ | */ | ||||
static String textRead(File file) throws Exception { | static String textRead(File file) throws Exception { | ||||
return new String(Files.readAllBytes(file.toPath()), CHARSET); | |||||
return new String(Files.readAllBytes(file.toPath()), UTF_8); | |||||
} | } | ||||
/** | /** | ||||
* @throws Exception | * @throws Exception | ||||
*/ | */ | ||||
static void textWrite(File file, String text) throws Exception { | static void textWrite(File file, String text) throws Exception { | ||||
Files.write(file.toPath(), text.getBytes(CHARSET)); | |||||
Files.write(file.toPath(), text.getBytes(UTF_8)); | |||||
} | } | ||||
static void verifyFileContent(File fileOne, File fileTwo) | static void verifyFileContent(File fileOne, File fileTwo) | ||||
c.setConnectTimeout(500); | c.setConnectTimeout(500); | ||||
c.setReadTimeout(500); | c.setReadTimeout(500); | ||||
try (BufferedReader reader = new BufferedReader( | try (BufferedReader reader = new BufferedReader( | ||||
new InputStreamReader(c.getInputStream(), CHARSET))) { | |||||
new InputStreamReader(c.getInputStream(), UTF_8))) { | |||||
return reader.readLine(); | return reader.readLine(); | ||||
} | } | ||||
} catch (UnknownHostException | SocketTimeoutException e) { | } catch (UnknownHostException | SocketTimeoutException e) { | ||||
AmazonS3 s3 = new AmazonS3(props); | AmazonS3 s3 = new AmazonS3(props); | ||||
String file = JGIT_USER + "-" + UUID.randomUUID().toString(); | String file = JGIT_USER + "-" + UUID.randomUUID().toString(); | ||||
String path = JGIT_REMOTE_DIR + "/" + file; | String path = JGIT_REMOTE_DIR + "/" + file; | ||||
s3.put(bucket, path, file.getBytes(CHARSET)); | |||||
s3.put(bucket, path, file.getBytes(UTF_8)); | |||||
s3.delete(bucket, path); | s3.delete(bucket, path); | ||||
} | } | ||||
package org.eclipse.jgit.treewalk; | package org.eclipse.jgit.treewalk; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.FileMode.REGULAR_FILE; | import static org.eclipse.jgit.lib.FileMode.REGULAR_FILE; | ||||
import static org.eclipse.jgit.lib.FileMode.SYMLINK; | import static org.eclipse.jgit.lib.FileMode.SYMLINK; | ||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
} | } | ||||
private String path() { | private String path() { | ||||
return RawParseUtils.decode(Constants.CHARSET, ctp.path, | |||||
return RawParseUtils.decode(UTF_8, ctp.path, | |||||
ctp.pathOffset, ctp.pathLen); | ctp.pathOffset, ctp.pathLen); | ||||
} | } | ||||
final String name = b.toString(); | final String name = b.toString(); | ||||
ctp.reset(entry(m644, name, hash_a)); | ctp.reset(entry(m644, name, hash_a)); | ||||
assertFalse(ctp.eof()); | assertFalse(ctp.eof()); | ||||
assertEquals(name, RawParseUtils.decode(Constants.CHARSET, ctp.path, | |||||
assertEquals(name, RawParseUtils.decode(UTF_8, ctp.path, | |||||
ctp.pathOffset, ctp.pathLen)); | ctp.pathOffset, ctp.pathLen)); | ||||
} | } | ||||
package org.eclipse.jgit.treewalk; | package org.eclipse.jgit.treewalk; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
} | } | ||||
private static String nameOf(AbstractTreeIterator i) { | private static String nameOf(AbstractTreeIterator i) { | ||||
return RawParseUtils.decode(Constants.CHARSET, i.path, 0, i.pathLen); | |||||
return RawParseUtils.decode(UTF_8, i.path, 0, i.pathLen); | |||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.eclipse.jgit.util; | package org.eclipse.jgit.util; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertNotNull; | import static org.junit.Assert.assertNotNull; | ||||
} | } | ||||
private static RawCharSequence raw(String text) { | private static RawCharSequence raw(String text) { | ||||
byte[] bytes = text.getBytes(CHARSET); | |||||
byte[] bytes = text.getBytes(UTF_8); | |||||
return new RawCharSequence(bytes, 0, bytes.length); | return new RawCharSequence(bytes, 0, bytes.length); | ||||
} | } | ||||
} | } |
package org.eclipse.jgit.util.io; | package org.eclipse.jgit.util.io; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import java.io.ByteArrayInputStream; | import java.io.ByteArrayInputStream; | ||||
} | } | ||||
private static byte[] asBytes(String in) { | private static byte[] asBytes(String in) { | ||||
return in.getBytes(CHARSET); | |||||
return in.getBytes(UTF_8); | |||||
} | } | ||||
} | } |
package org.eclipse.jgit.util.sha1; | package org.eclipse.jgit.util.sha1; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||
import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
import static org.junit.Assert.fail; | import static org.junit.Assert.fail; | ||||
.fromString("a9993e364706816aba3e25717850c26c9cd0d89d"); | .fromString("a9993e364706816aba3e25717850c26c9cd0d89d"); | ||||
MessageDigest m = MessageDigest.getInstance("SHA-1"); | MessageDigest m = MessageDigest.getInstance("SHA-1"); | ||||
m.update(TEST1.getBytes(CHARSET)); | |||||
m.update(TEST1.getBytes(UTF_8)); | |||||
ObjectId m1 = ObjectId.fromRaw(m.digest()); | ObjectId m1 = ObjectId.fromRaw(m.digest()); | ||||
SHA1 s = SHA1.newInstance(); | SHA1 s = SHA1.newInstance(); | ||||
s.update(TEST1.getBytes(CHARSET)); | |||||
s.update(TEST1.getBytes(UTF_8)); | |||||
ObjectId s1 = ObjectId.fromRaw(s.digest()); | ObjectId s1 = ObjectId.fromRaw(s.digest()); | ||||
s.reset(); | s.reset(); | ||||
s.update(TEST1.getBytes(CHARSET)); | |||||
s.update(TEST1.getBytes(UTF_8)); | |||||
ObjectId s2 = s.toObjectId(); | ObjectId s2 = s.toObjectId(); | ||||
assertEquals(m1, s1); | assertEquals(m1, s1); | ||||
.fromString("84983e441c3bd26ebaae4aa1f95129e5e54670f1"); | .fromString("84983e441c3bd26ebaae4aa1f95129e5e54670f1"); | ||||
MessageDigest m = MessageDigest.getInstance("SHA-1"); | MessageDigest m = MessageDigest.getInstance("SHA-1"); | ||||
m.update(TEST2.getBytes(CHARSET)); | |||||
m.update(TEST2.getBytes(UTF_8)); | |||||
ObjectId m1 = ObjectId.fromRaw(m.digest()); | ObjectId m1 = ObjectId.fromRaw(m.digest()); | ||||
SHA1 s = SHA1.newInstance(); | SHA1 s = SHA1.newInstance(); | ||||
s.update(TEST2.getBytes(CHARSET)); | |||||
s.update(TEST2.getBytes(UTF_8)); | |||||
ObjectId s1 = ObjectId.fromRaw(s.digest()); | ObjectId s1 = ObjectId.fromRaw(s.digest()); | ||||
s.reset(); | s.reset(); | ||||
s.update(TEST2.getBytes(CHARSET)); | |||||
s.update(TEST2.getBytes(UTF_8)); | |||||
ObjectId s2 = s.toObjectId(); | ObjectId s2 = s.toObjectId(); | ||||
assertEquals(m1, s1); | assertEquals(m1, s1); |
*/ | */ | ||||
package org.eclipse.jgit.attributes; | package org.eclipse.jgit.attributes; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.List; | import java.util.List; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
/** | /** | ||||
* Represents a bundle of attributes inherited from a base directory. | * Represents a bundle of attributes inherited from a base directory. | ||||
* | * | ||||
} | } | ||||
private static BufferedReader asReader(InputStream in) { | private static BufferedReader asReader(InputStream in) { | ||||
return new BufferedReader(new InputStreamReader(in, Constants.CHARSET)); | |||||
return new BufferedReader(new InputStreamReader(in, UTF_8)); | |||||
} | } | ||||
/** | /** |
package org.eclipse.jgit.dircache; | package org.eclipse.jgit.dircache; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.EOFException; | import java.io.EOFException; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
} | } | ||||
static String toString(byte[] path) { | static String toString(byte[] path) { | ||||
return Constants.CHARSET.decode(ByteBuffer.wrap(path)).toString(); | |||||
return UTF_8.decode(ByteBuffer.wrap(path)).toString(); | |||||
} | } | ||||
static int getMaximumInfoLength(boolean extended) { | static int getMaximumInfoLength(boolean extended) { |
package org.eclipse.jgit.dircache; | package org.eclipse.jgit.dircache; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.FileMode.TREE; | import static org.eclipse.jgit.lib.FileMode.TREE; | ||||
import static org.eclipse.jgit.lib.TreeFormatter.entrySize; | import static org.eclipse.jgit.lib.TreeFormatter.entrySize; | ||||
*/ | */ | ||||
public String getNameString() { | public String getNameString() { | ||||
final ByteBuffer bb = ByteBuffer.wrap(encodedName); | final ByteBuffer bb = ByteBuffer.wrap(encodedName); | ||||
return Constants.CHARSET.decode(bb).toString(); | |||||
return UTF_8.decode(bb).toString(); | |||||
} | } | ||||
/** | /** |
*/ | */ | ||||
package org.eclipse.jgit.hooks; | package org.eclipse.jgit.hooks; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
PrintStream hookErrRedirect = null; | PrintStream hookErrRedirect = null; | ||||
try { | try { | ||||
hookErrRedirect = new PrintStream(errorByteArray, false, | hookErrRedirect = new PrintStream(errorByteArray, false, | ||||
CHARSET.name()); | |||||
UTF_8.name()); | |||||
} catch (UnsupportedEncodingException e) { | } catch (UnsupportedEncodingException e) { | ||||
// UTF-8 is guaranteed to be available | // UTF-8 is guaranteed to be available | ||||
} | } | ||||
hookErrRedirect, getStdinArgs()); | hookErrRedirect, getStdinArgs()); | ||||
if (result.isExecutedWithError()) { | if (result.isExecutedWithError()) { | ||||
throw new AbortedByHookException( | throw new AbortedByHookException( | ||||
new String(errorByteArray.toByteArray(), CHARSET), | |||||
new String(errorByteArray.toByteArray(), UTF_8), | |||||
getHookName(), result.getExitCode()); | getHookName(), result.getExitCode()); | ||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.eclipse.jgit.ignore; | package org.eclipse.jgit.ignore; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
import java.util.List; | import java.util.List; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
/** | /** | ||||
* Represents a bundle of ignore rules inherited from a base directory. | * Represents a bundle of ignore rules inherited from a base directory. | ||||
* | * | ||||
} | } | ||||
private static BufferedReader asReader(InputStream in) { | private static BufferedReader asReader(InputStream in) { | ||||
return new BufferedReader(new InputStreamReader(in, Constants.CHARSET)); | |||||
return new BufferedReader(new InputStreamReader(in, UTF_8)); | |||||
} | } | ||||
/** | /** |
package org.eclipse.jgit.internal.storage.dfs; | package org.eclipse.jgit.internal.storage.dfs; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
*/ | */ | ||||
public static DfsStreamKey of(DfsRepositoryDescription repo, String name, | public static DfsStreamKey of(DfsRepositoryDescription repo, String name, | ||||
@Nullable PackExt ext) { | @Nullable PackExt ext) { | ||||
return new ByteArrayDfsStreamKey(repo, name.getBytes(CHARSET), ext); | |||||
return new ByteArrayDfsStreamKey(repo, name.getBytes(UTF_8), ext); | |||||
} | } | ||||
final int hash; | final int hash; |
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
if (content.length() > 0) { | if (content.length() > 0) { | ||||
nonEmpty = true; | nonEmpty = true; | ||||
} | } | ||||
lock.write(content.getBytes(CHARSET)); | |||||
lock.write(content.getBytes(UTF_8)); | |||||
} | } | ||||
} | } |
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.File; | import java.io.File; | ||||
private ObjectIdOwnerMap<Entry> load() { | private ObjectIdOwnerMap<Entry> load() { | ||||
ObjectIdOwnerMap<Entry> r = new ObjectIdOwnerMap<>(); | ObjectIdOwnerMap<Entry> r = new ObjectIdOwnerMap<>(); | ||||
try (FileInputStream fin = new FileInputStream(src); | try (FileInputStream fin = new FileInputStream(src); | ||||
Reader rin = new InputStreamReader(fin, CHARSET); | |||||
Reader rin = new InputStreamReader(fin, UTF_8); | |||||
BufferedReader br = new BufferedReader(rin)) { | BufferedReader br = new BufferedReader(rin)) { | ||||
MutableObjectId id = new MutableObjectId(); | MutableObjectId id = new MutableObjectId(); | ||||
for (String line; (line = br.readLine()) != null;) { | for (String line; (line = br.readLine()) != null;) { |
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.HEAD; | import static org.eclipse.jgit.lib.Constants.HEAD; | ||||
import static org.eclipse.jgit.lib.Constants.LOGS; | import static org.eclipse.jgit.lib.Constants.LOGS; | ||||
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; | import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; | ||||
try (BufferedReader br = new BufferedReader(new InputStreamReader( | try (BufferedReader br = new BufferedReader(new InputStreamReader( | ||||
new DigestInputStream(new FileInputStream(packedRefsFile), | new DigestInputStream(new FileInputStream(packedRefsFile), | ||||
digest), | digest), | ||||
CHARSET))) { | |||||
UTF_8))) { | |||||
try { | try { | ||||
return new PackedRefList(parsePackedRefs(br), snapshot, | return new PackedRefList(parsePackedRefs(br), snapshot, | ||||
ObjectId.fromRaw(digest.digest())); | ObjectId.fromRaw(digest.digest())); |
package org.eclipse.jgit.internal.storage.reftable; | package org.eclipse.jgit.internal.storage.reftable; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.internal.storage.reftable.BlockWriter.compare; | import static org.eclipse.jgit.internal.storage.reftable.BlockWriter.compare; | ||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE; | ||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; | ||||
if (blockType == LOG_BLOCK_TYPE) { | if (blockType == LOG_BLOCK_TYPE) { | ||||
len -= 9; | len -= 9; | ||||
} | } | ||||
return RawParseUtils.decode(CHARSET, nameBuf, 0, len); | |||||
return RawParseUtils.decode(UTF_8, nameBuf, 0, len); | |||||
} | } | ||||
boolean match(byte[] match, boolean matchIsPrefix) { | boolean match(byte[] match, boolean matchIsPrefix) { | ||||
} | } | ||||
Ref readRef() throws IOException { | Ref readRef() throws IOException { | ||||
String name = RawParseUtils.decode(CHARSET, nameBuf, 0, nameLen); | |||||
String name = RawParseUtils.decode(UTF_8, nameBuf, 0, nameLen); | |||||
switch (valueType & VALUE_TYPE_MASK) { | switch (valueType & VALUE_TYPE_MASK) { | ||||
case VALUE_NONE: // delete | case VALUE_NONE: // delete | ||||
return newRef(name); | return newRef(name); | ||||
private String readValueString() { | private String readValueString() { | ||||
int len = readVarint32(); | int len = readVarint32(); | ||||
int end = ptr + len; | int end = ptr + len; | ||||
String s = RawParseUtils.decode(CHARSET, buf, ptr, end); | |||||
String s = RawParseUtils.decode(UTF_8, buf, ptr, end); | |||||
ptr = end; | ptr = end; | ||||
return s; | return s; | ||||
} | } |
package org.eclipse.jgit.internal.storage.reftable; | package org.eclipse.jgit.internal.storage.reftable; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; | ||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE; | ||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE; | ||||
} | } | ||||
private static byte[] nameUtf8(Ref ref) { | private static byte[] nameUtf8(Ref ref) { | ||||
return ref.getName().getBytes(CHARSET); | |||||
return ref.getName().getBytes(UTF_8); | |||||
} | } | ||||
} | } | ||||
this.newId = newId; | this.newId = newId; | ||||
this.timeSecs = who.getWhen().getTime() / 1000L; | this.timeSecs = who.getWhen().getTime() / 1000L; | ||||
this.tz = (short) who.getTimeZoneOffset(); | this.tz = (short) who.getTimeZoneOffset(); | ||||
this.name = who.getName().getBytes(CHARSET); | |||||
this.email = who.getEmailAddress().getBytes(CHARSET); | |||||
this.msg = message.getBytes(CHARSET); | |||||
this.name = who.getName().getBytes(UTF_8); | |||||
this.email = who.getEmailAddress().getBytes(UTF_8); | |||||
this.msg = message.getBytes(UTF_8); | |||||
} | } | ||||
static byte[] key(String ref, long index) { | static byte[] key(String ref, long index) { | ||||
byte[] name = ref.getBytes(CHARSET); | |||||
byte[] name = ref.getBytes(UTF_8); | |||||
byte[] key = Arrays.copyOf(name, name.length + 1 + 8); | byte[] key = Arrays.copyOf(name, name.length + 1 + 8); | ||||
NB.encodeInt64(key, key.length - 8, reverseUpdateIndex(index)); | NB.encodeInt64(key, key.length - 8, reverseUpdateIndex(index)); | ||||
return key; | return key; |
package org.eclipse.jgit.internal.storage.reftable; | package org.eclipse.jgit.internal.storage.reftable; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; | ||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE; | ||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE; | ||||
} | } | ||||
void writeVarintString(String s) { | void writeVarintString(String s) { | ||||
writeVarintString(s.getBytes(CHARSET)); | |||||
writeVarintString(s.getBytes(UTF_8)); | |||||
} | } | ||||
void writeVarintString(byte[] msg) { | void writeVarintString(byte[] msg) { |
package org.eclipse.jgit.internal.storage.reftable; | package org.eclipse.jgit.internal.storage.reftable; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.internal.storage.reftable.BlockReader.decodeBlockLen; | import static org.eclipse.jgit.internal.storage.reftable.BlockReader.decodeBlockLen; | ||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE; | ||||
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_FOOTER_LEN; | import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_FOOTER_LEN; | ||||
public RefCursor seekRef(String refName) throws IOException { | public RefCursor seekRef(String refName) throws IOException { | ||||
initRefIndex(); | initRefIndex(); | ||||
byte[] key = refName.getBytes(CHARSET); | |||||
byte[] key = refName.getBytes(UTF_8); | |||||
RefCursorImpl i = new RefCursorImpl(refEnd, key, false); | RefCursorImpl i = new RefCursorImpl(refEnd, key, false); | ||||
i.block = seek(REF_BLOCK_TYPE, key, refIndex, 0, refEnd); | i.block = seek(REF_BLOCK_TYPE, key, refIndex, 0, refEnd); | ||||
return i; | return i; | ||||
public RefCursor seekRefsWithPrefix(String prefix) throws IOException { | public RefCursor seekRefsWithPrefix(String prefix) throws IOException { | ||||
initRefIndex(); | initRefIndex(); | ||||
byte[] key = prefix.getBytes(CHARSET); | |||||
byte[] key = prefix.getBytes(UTF_8); | |||||
RefCursorImpl i = new RefCursorImpl(refEnd, key, true); | RefCursorImpl i = new RefCursorImpl(refEnd, key, true); | ||||
i.block = seek(REF_BLOCK_TYPE, key, refIndex, 0, refEnd); | i.block = seek(REF_BLOCK_TYPE, key, refIndex, 0, refEnd); | ||||
return i; | return i; | ||||
initLogIndex(); | initLogIndex(); | ||||
if (logPosition > 0) { | if (logPosition > 0) { | ||||
byte[] key = LogEntry.key(refName, updateIndex); | byte[] key = LogEntry.key(refName, updateIndex); | ||||
byte[] match = refName.getBytes(CHARSET); | |||||
byte[] match = refName.getBytes(UTF_8); | |||||
LogCursorImpl i = new LogCursorImpl(logEnd, match); | LogCursorImpl i = new LogCursorImpl(logEnd, match); | ||||
i.block = seek(LOG_BLOCK_TYPE, key, logIndex, logPosition, logEnd); | i.block = seek(LOG_BLOCK_TYPE, key, logIndex, logPosition, logEnd); | ||||
return i; | return i; |
package org.eclipse.jgit.lib; | package org.eclipse.jgit.lib; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
super(base); | super(base); | ||||
final String decoded; | final String decoded; | ||||
if (isUtf8(blob)) { | if (isUtf8(blob)) { | ||||
decoded = RawParseUtils.decode(CHARSET, blob, 3, blob.length); | |||||
decoded = RawParseUtils.decode(UTF_8, blob, 3, blob.length); | |||||
} else { | } else { | ||||
decoded = RawParseUtils.decode(blob); | decoded = RawParseUtils.decode(blob); | ||||
} | } |
package org.eclipse.jgit.lib; | package org.eclipse.jgit.lib; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||
*/ | */ | ||||
public CommitBuilder() { | public CommitBuilder() { | ||||
parentIds = EMPTY_OBJECTID_LIST; | parentIds = EMPTY_OBJECTID_LIST; | ||||
encoding = Constants.CHARSET; | |||||
encoding = UTF_8; | |||||
} | } | ||||
/** | /** | ||||
w.flush(); | w.flush(); | ||||
os.write('\n'); | os.write('\n'); | ||||
if (getEncoding() != Constants.CHARSET) { | |||||
if (getEncoding() != UTF_8) { | |||||
os.write(hencoding); | os.write(hencoding); | ||||
os.write(' '); | os.write(' '); | ||||
os.write(Constants.encodeASCII(getEncoding().name())); | os.write(Constants.encodeASCII(getEncoding().name())); | ||||
r.append(committer != null ? committer.toString() : "NOT_SET"); | r.append(committer != null ? committer.toString() : "NOT_SET"); | ||||
r.append("\n"); | r.append("\n"); | ||||
if (encoding != null && encoding != Constants.CHARSET) { | |||||
if (encoding != null && encoding != UTF_8) { | |||||
r.append("encoding "); | r.append("encoding "); | ||||
r.append(encoding.name()); | r.append(encoding.name()); | ||||
r.append("\n"); | r.append("\n"); |
package org.eclipse.jgit.lib; | package org.eclipse.jgit.lib; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.text.MessageFormat; | import java.text.MessageFormat; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
String decoded; | String decoded; | ||||
if (isUtf8(bytes)) { | if (isUtf8(bytes)) { | ||||
decoded = RawParseUtils.decode(CHARSET, bytes, 3, bytes.length); | |||||
decoded = RawParseUtils.decode(UTF_8, bytes, 3, bytes.length); | |||||
} else { | } else { | ||||
decoded = RawParseUtils.decode(bytes); | decoded = RawParseUtils.decode(bytes); | ||||
} | } |
*/ | */ | ||||
public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' }; | public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' }; | ||||
/** Native character encoding for commit messages, file names... */ | |||||
/** | |||||
* Native character encoding for commit messages, file names... | |||||
* | |||||
* @deprecated Use {@link java.nio.charset.StandardCharsets#UTF_8} directly | |||||
* instead. | |||||
**/ | |||||
@Deprecated | |||||
public static final Charset CHARSET; | public static final Charset CHARSET; | ||||
/** Native character encoding for commit messages, file names... */ | /** Native character encoding for commit messages, file names... */ | ||||
* @see #CHARACTER_ENCODING | * @see #CHARACTER_ENCODING | ||||
*/ | */ | ||||
public static byte[] encode(String str) { | public static byte[] encode(String str) { | ||||
final ByteBuffer bb = Constants.CHARSET.encode(str); | |||||
final ByteBuffer bb = UTF_8.encode(str); | |||||
final int len = bb.limit(); | final int len = bb.limit(); | ||||
if (bb.hasArray() && bb.arrayOffset() == 0) { | if (bb.hasArray() && bb.arrayOffset() == 0) { | ||||
final byte[] arr = bb.array(); | final byte[] arr = bb.array(); | ||||
if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength()) | if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength()) | ||||
throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH); | throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH); | ||||
CHARSET = UTF_8; | CHARSET = UTF_8; | ||||
CHARACTER_ENCODING = CHARSET.name(); | |||||
CHARACTER_ENCODING = UTF_8.name(); | |||||
} | } | ||||
/** name of the file containing the commit msg for a merge commit */ | /** name of the file containing the commit msg for a merge commit */ |
package org.eclipse.jgit.lib; | package org.eclipse.jgit.lib; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedOutputStream; | import java.io.BufferedOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
switch (tokenCount) { | switch (tokenCount) { | ||||
case 0: | case 0: | ||||
String actionToken = new String(buf, tokenBegin, | String actionToken = new String(buf, tokenBegin, | ||||
nextSpace - tokenBegin - 1, CHARSET); | |||||
nextSpace - tokenBegin - 1, UTF_8); | |||||
tokenBegin = nextSpace; | tokenBegin = nextSpace; | ||||
action = RebaseTodoLine.Action.parse(actionToken); | action = RebaseTodoLine.Action.parse(actionToken); | ||||
if (action == null) | if (action == null) | ||||
case 1: | case 1: | ||||
nextSpace = RawParseUtils.next(buf, tokenBegin, ' '); | nextSpace = RawParseUtils.next(buf, tokenBegin, ' '); | ||||
String commitToken = new String(buf, tokenBegin, | String commitToken = new String(buf, tokenBegin, | ||||
nextSpace - tokenBegin - 1, CHARSET); | |||||
nextSpace - tokenBegin - 1, UTF_8); | |||||
tokenBegin = nextSpace; | tokenBegin = nextSpace; | ||||
commit = AbbreviatedObjectId.fromString(commitToken); | commit = AbbreviatedObjectId.fromString(commitToken); | ||||
break; | break; |
package org.eclipse.jgit.lib; | package org.eclipse.jgit.lib; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||
public byte[] build() { | public byte[] build() { | ||||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||||
try (OutputStreamWriter w = new OutputStreamWriter(os, | try (OutputStreamWriter w = new OutputStreamWriter(os, | ||||
Constants.CHARSET)) { | |||||
UTF_8)) { | |||||
w.write("object "); //$NON-NLS-1$ | w.write("object "); //$NON-NLS-1$ | ||||
getObjectId().copyTo(w); | getObjectId().copyTo(w); | ||||
w.write('\n'); | w.write('\n'); |
package org.eclipse.jgit.lib; | package org.eclipse.jgit.lib; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||
* Initialize a new progress monitor. | * Initialize a new progress monitor. | ||||
*/ | */ | ||||
public TextProgressMonitor() { | public TextProgressMonitor() { | ||||
this(new PrintWriter(new OutputStreamWriter(System.err, CHARSET))); | |||||
this(new PrintWriter(new OutputStreamWriter(System.err, UTF_8))); | |||||
} | } | ||||
/** | /** |
package org.eclipse.jgit.patch; | package org.eclipse.jgit.patch; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.encodeASCII; | import static org.eclipse.jgit.lib.Constants.encodeASCII; | ||||
import static org.eclipse.jgit.util.RawParseUtils.decode; | import static org.eclipse.jgit.util.RawParseUtils.decode; | ||||
import static org.eclipse.jgit.util.RawParseUtils.decodeNoFallback; | import static org.eclipse.jgit.util.RawParseUtils.decodeNoFallback; | ||||
import org.eclipse.jgit.diff.EditList; | import org.eclipse.jgit.diff.EditList; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.lib.AbbreviatedObjectId; | import org.eclipse.jgit.lib.AbbreviatedObjectId; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.lib.FileMode; | import org.eclipse.jgit.lib.FileMode; | ||||
import org.eclipse.jgit.util.QuotedString; | import org.eclipse.jgit.util.QuotedString; | ||||
import org.eclipse.jgit.util.RawParseUtils; | import org.eclipse.jgit.util.RawParseUtils; | ||||
* Convert the patch script for this file into a string. | * Convert the patch script for this file into a string. | ||||
* <p> | * <p> | ||||
* The default character encoding | * The default character encoding | ||||
* ({@link org.eclipse.jgit.lib.Constants#CHARSET}) is assumed for both the | |||||
* ({@link java.nio.charset.StandardCharsets#UTF_8}) is assumed for both the | |||||
* old and new files. | * old and new files. | ||||
* | * | ||||
* @return the patch script, as a Unicode string. | * @return the patch script, as a Unicode string. | ||||
if (trySimpleConversion(charsetGuess)) { | if (trySimpleConversion(charsetGuess)) { | ||||
Charset cs = charsetGuess != null ? charsetGuess[0] : null; | Charset cs = charsetGuess != null ? charsetGuess[0] : null; | ||||
if (cs == null) | |||||
cs = Constants.CHARSET; | |||||
if (cs == null) { | |||||
cs = UTF_8; | |||||
} | |||||
try { | try { | ||||
return decodeNoFallback(cs, buf, startOffset, endOffset); | return decodeNoFallback(cs, buf, startOffset, endOffset); | ||||
} catch (CharacterCodingException cee) { | } catch (CharacterCodingException cee) { | ||||
final String[] r = new String[tmp.length]; | final String[] r = new String[tmp.length]; | ||||
for (int i = 0; i < tmp.length; i++) { | for (int i = 0; i < tmp.length; i++) { | ||||
Charset cs = csGuess != null ? csGuess[i] : null; | Charset cs = csGuess != null ? csGuess[i] : null; | ||||
if (cs == null) | |||||
cs = Constants.CHARSET; | |||||
if (cs == null) { | |||||
cs = UTF_8; | |||||
} | |||||
r[i] = RawParseUtils.decode(cs, tmp[i].toByteArray()); | r[i] = RawParseUtils.decode(cs, tmp[i].toByteArray()); | ||||
} | } | ||||
return r; | return r; | ||||
oldPath = QuotedString.GIT_PATH.dequote(buf, bol, sp - 1); | oldPath = QuotedString.GIT_PATH.dequote(buf, bol, sp - 1); | ||||
oldPath = p1(oldPath); | oldPath = p1(oldPath); | ||||
} else { | } else { | ||||
oldPath = decode(Constants.CHARSET, buf, aStart, sp - 1); | |||||
oldPath = decode(UTF_8, buf, aStart, sp - 1); | |||||
} | } | ||||
newPath = oldPath; | newPath = oldPath; | ||||
return eol; | return eol; | ||||
tab--; | tab--; | ||||
if (ptr == tab) | if (ptr == tab) | ||||
tab = end; | tab = end; | ||||
r = decode(Constants.CHARSET, buf, ptr, tab - 1); | |||||
r = decode(UTF_8, buf, ptr, tab - 1); | |||||
} | } | ||||
if (r.equals(DEV_NULL)) | if (r.equals(DEV_NULL)) |
package org.eclipse.jgit.patch; | package org.eclipse.jgit.patch; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.util.Locale; | import java.util.Locale; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.util.RawParseUtils; | import org.eclipse.jgit.util.RawParseUtils; | ||||
/** | /** | ||||
*/ | */ | ||||
public String getLineText() { | public String getLineText() { | ||||
final int eol = RawParseUtils.nextLF(buf, offset); | final int eol = RawParseUtils.nextLF(buf, offset); | ||||
return RawParseUtils.decode(Constants.CHARSET, buf, offset, eol); | |||||
return RawParseUtils.decode(UTF_8, buf, offset, eol); | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ |
package org.eclipse.jgit.revwalk; | package org.eclipse.jgit.revwalk; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.nio.charset.Charset; | import java.nio.charset.Charset; | ||||
try { | try { | ||||
return getEncoding(); | return getEncoding(); | ||||
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) { | } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { | ||||
return CHARSET; | |||||
return UTF_8; | |||||
} | } | ||||
} | } | ||||
package org.eclipse.jgit.revwalk; | package org.eclipse.jgit.revwalk; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.nio.charset.Charset; | import java.nio.charset.Charset; | ||||
int p = pos.value += 4; // "tag " | int p = pos.value += 4; // "tag " | ||||
final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1; | final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1; | ||||
tagName = RawParseUtils.decode(CHARSET, rawTag, p, nameEnd); | |||||
tagName = RawParseUtils.decode(UTF_8, rawTag, p, nameEnd); | |||||
if (walk.isRetainBody()) | if (walk.isRetainBody()) | ||||
buffer = rawTag; | buffer = rawTag; | ||||
try { | try { | ||||
return RawParseUtils.parseEncoding(buffer); | return RawParseUtils.parseEncoding(buffer); | ||||
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) { | } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { | ||||
return CHARSET; | |||||
return UTF_8; | |||||
} | } | ||||
} | } | ||||
package org.eclipse.jgit.storage.file; | package org.eclipse.jgit.storage.file; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
} else { | } else { | ||||
final String decoded; | final String decoded; | ||||
if (isUtf8(in)) { | if (isUtf8(in)) { | ||||
decoded = RawParseUtils.decode(CHARSET, | |||||
decoded = RawParseUtils.decode(UTF_8, | |||||
in, 3, in.length); | in, 3, in.length); | ||||
utf8Bom = true; | utf8Bom = true; | ||||
} else { | } else { | ||||
bos.write(0xEF); | bos.write(0xEF); | ||||
bos.write(0xBB); | bos.write(0xBB); | ||||
bos.write(0xBF); | bos.write(0xBF); | ||||
bos.write(text.getBytes(CHARSET)); | |||||
bos.write(text.getBytes(UTF_8)); | |||||
out = bos.toByteArray(); | out = bos.toByteArray(); | ||||
} else { | } else { | ||||
out = Constants.encode(text); | out = Constants.encode(text); |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
try { | try { | ||||
final Mac m = Mac.getInstance(HMAC); | final Mac m = Mac.getInstance(HMAC); | ||||
m.init(privateKey); | m.init(privateKey); | ||||
sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(CHARSET))); | |||||
sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(UTF_8))); | |||||
} catch (NoSuchAlgorithmException e) { | } catch (NoSuchAlgorithmException e) { | ||||
throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage())); | throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage())); | ||||
} catch (InvalidKeyException e) { | } catch (InvalidKeyException e) { |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import org.eclipse.jgit.errors.TransportException; | import org.eclipse.jgit.errors.TransportException; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.internal.storage.file.PackLock; | import org.eclipse.jgit.internal.storage.file.PackLock; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.lib.NullProgressMonitor; | import org.eclipse.jgit.lib.NullProgressMonitor; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.ObjectIdRef; | import org.eclipse.jgit.lib.ObjectIdRef; | ||||
IO.skipFully(bin, 1); | IO.skipFully(bin, 1); | ||||
done = true; | done = true; | ||||
} | } | ||||
line.append(RawParseUtils.decode(Constants.CHARSET, hdrbuf, 0, lf)); | |||||
line.append(RawParseUtils.decode(UTF_8, hdrbuf, 0, lf)); | |||||
} | } | ||||
return line.toString(); | return line.toString(); | ||||
} | } |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||
packWriter.setTagTargets(tagTargets); | packWriter.setTagTargets(tagTargets); | ||||
packWriter.preparePack(monitor, inc, exc); | packWriter.preparePack(monitor, inc, exc); | ||||
final Writer w = new OutputStreamWriter(os, Constants.CHARSET); | |||||
final Writer w = new OutputStreamWriter(os, UTF_8); | |||||
w.write(TransportBundle.V2_BUNDLE_SIGNATURE); | w.write(TransportBundle.V2_BUNDLE_SIGNATURE); | ||||
w.write('\n'); | w.write('\n'); | ||||
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static java.nio.charset.StandardCharsets.ISO_8859_1; | import static java.nio.charset.StandardCharsets.ISO_8859_1; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.File; | import java.io.File; | ||||
import java.security.InvalidKeyException; | import java.security.InvalidKeyException; | ||||
} | } | ||||
String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$ | String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$ | ||||
byte[] rawHmac = mac.doFinal(input.getBytes(CHARSET)); | |||||
byte[] rawHmac = mac.doFinal(input.getBytes(UTF_8)); | |||||
return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$ | return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$ | ||||
} | } | ||||
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; | import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; | ||||
import static org.eclipse.jgit.util.HttpSupport.HDR_WWW_AUTHENTICATE; | import static org.eclipse.jgit.util.HttpSupport.HDR_WWW_AUTHENTICATE; | ||||
@Override | @Override | ||||
void configureRequest(HttpConnection conn) throws IOException { | void configureRequest(HttpConnection conn) throws IOException { | ||||
String ident = user + ":" + pass; //$NON-NLS-1$ | String ident = user + ":" + pass; //$NON-NLS-1$ | ||||
String enc = Base64.encodeBytes(ident.getBytes(CHARSET)); | |||||
String enc = Base64.encodeBytes(ident.getBytes(UTF_8)); | |||||
conn.setRequestProperty(HDR_AUTHORIZATION, type.getSchemeName() | conn.setRequestProperty(HDR_AUTHORIZATION, type.getSchemeName() | ||||
+ " " + enc); //$NON-NLS-1$ | + " " + enc); //$NON-NLS-1$ | ||||
} | } | ||||
private static String H(String data) { | private static String H(String data) { | ||||
MessageDigest md = newMD5(); | MessageDigest md = newMD5(); | ||||
md.update(data.getBytes(CHARSET)); | |||||
md.update(data.getBytes(UTF_8)); | |||||
return LHEX(md.digest()); | return LHEX(md.digest()); | ||||
} | } | ||||
private static String KD(String secret, String data) { | private static String KD(String secret, String data) { | ||||
MessageDigest md = newMD5(); | MessageDigest md = newMD5(); | ||||
md.update(secret.getBytes(CHARSET)); | |||||
md.update(secret.getBytes(UTF_8)); | |||||
md.update((byte) ':'); | md.update((byte) ':'); | ||||
md.update(data.getBytes(CHARSET)); | |||||
md.update(data.getBytes(UTF_8)); | |||||
return LHEX(md.digest()); | return LHEX(md.digest()); | ||||
} | } | ||||
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.text.MessageFormat; | import java.text.MessageFormat; | ||||
import org.eclipse.jgit.errors.PackProtocolException; | import org.eclipse.jgit.errors.PackProtocolException; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.lib.MutableObjectId; | import org.eclipse.jgit.lib.MutableObjectId; | ||||
import org.eclipse.jgit.util.IO; | import org.eclipse.jgit.util.IO; | ||||
import org.eclipse.jgit.util.RawParseUtils; | import org.eclipse.jgit.util.RawParseUtils; | ||||
if (raw[len - 1] == '\n') | if (raw[len - 1] == '\n') | ||||
len--; | len--; | ||||
String s = RawParseUtils.decode(Constants.CHARSET, raw, 0, len); | |||||
String s = RawParseUtils.decode(UTF_8, raw, 0, len); | |||||
log.debug("git< " + s); //$NON-NLS-1$ | log.debug("git< " + s); //$NON-NLS-1$ | ||||
return s; | return s; | ||||
} | } | ||||
IO.readFully(in, raw, 0, len); | IO.readFully(in, raw, 0, len); | ||||
String s = RawParseUtils.decode(Constants.CHARSET, raw, 0, len); | |||||
String s = RawParseUtils.decode(UTF_8, raw, 0, len); | |||||
log.debug("git< " + s); //$NON-NLS-1$ | log.debug("git< " + s); //$NON-NLS-1$ | ||||
return s; | return s; | ||||
} | } |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
out.write(lenbuffer, 0, 4); | out.write(lenbuffer, 0, 4); | ||||
out.write(buf, pos, len); | out.write(buf, pos, len); | ||||
if (log.isDebugEnabled()) { | if (log.isDebugEnabled()) { | ||||
String s = RawParseUtils.decode(Constants.CHARSET, buf, pos, len); | |||||
String s = RawParseUtils.decode(UTF_8, buf, pos, len); | |||||
log.debug("git> " + s); //$NON-NLS-1$ | log.debug("git> " + s); //$NON-NLS-1$ | ||||
} | } | ||||
} | } |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
private void write(String s) { | private void write(String s) { | ||||
if (write) { | if (write) { | ||||
try { | try { | ||||
out.write(s.getBytes(CHARSET)); | |||||
out.write(s.getBytes(UTF_8)); | |||||
out.flush(); | out.flush(); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
write = false; | write = false; |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.util.RawParseUtils.lastIndexOfTrim; | import static org.eclipse.jgit.util.RawParseUtils.lastIndexOfTrim; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
*/ | */ | ||||
public static PushCertificateIdent parse(String str) { | public static PushCertificateIdent parse(String str) { | ||||
MutableInteger p = new MutableInteger(); | MutableInteger p = new MutableInteger(); | ||||
byte[] raw = str.getBytes(CHARSET); | |||||
byte[] raw = str.getBytes(UTF_8); | |||||
int tzBegin = raw.length - 1; | int tzBegin = raw.length - 1; | ||||
tzBegin = lastIndexOfTrim(raw, ' ', tzBegin); | tzBegin = lastIndexOfTrim(raw, ' ', tzBegin); | ||||
if (tzBegin < 0 || raw[tzBegin] != ' ') { | if (tzBegin < 0 || raw[tzBegin] != ' ') { | ||||
idEnd = raw.length; | idEnd = raw.length; | ||||
} | } | ||||
} | } | ||||
String id = new String(raw, 0, idEnd, CHARSET); | |||||
String id = new String(raw, 0, idEnd, UTF_8); | |||||
return new PushCertificateIdent(str, id, when * 1000L, tz); | return new PushCertificateIdent(str, id, when * 1000L, tz); | ||||
} | } |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; | import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; | ||||
import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT; | import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT; | ||||
import static org.eclipse.jgit.lib.FileMode.TYPE_FILE; | import static org.eclipse.jgit.lib.FileMode.TYPE_FILE; | ||||
ObjectLoader loader = | ObjectLoader loader = | ||||
tw.getObjectReader().open(tw.getObjectId(0), OBJ_BLOB); | tw.getObjectReader().open(tw.getObjectId(0), OBJ_BLOB); | ||||
try (InputStream in = loader.openStream(); | try (InputStream in = loader.openStream(); | ||||
Reader r = new BufferedReader(new InputStreamReader(in, CHARSET))) { | |||||
Reader r = new BufferedReader( | |||||
new InputStreamReader(in, UTF_8))) { | |||||
return PushCertificateParser.fromReader(r); | return PushCertificateParser.fromReader(r); | ||||
} | } | ||||
} | } | ||||
DirCacheEditor editor = dc.editor(); | DirCacheEditor editor = dc.editor(); | ||||
String certText = pc.cert.toText() + pc.cert.getSignature(); | String certText = pc.cert.toText() + pc.cert.getSignature(); | ||||
final ObjectId certId = inserter.insert(OBJ_BLOB, certText.getBytes(CHARSET)); | |||||
final ObjectId certId = inserter.insert(OBJ_BLOB, certText.getBytes(UTF_8)); | |||||
boolean any = false; | boolean any = false; | ||||
for (ReceiveCommand cmd : pc.cert.getCommands()) { | for (ReceiveCommand cmd : pc.cert.getCommands()) { | ||||
if (byRef != null && !commandsEqual(cmd, byRef.get(cmd.getRefName()))) { | if (byRef != null && !commandsEqual(cmd, byRef.get(cmd.getRefName()))) { |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; | import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; | ||||
import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SYMREF; | import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SYMREF; | ||||
public abstract class RefAdvertiser { | public abstract class RefAdvertiser { | ||||
/** Advertiser which frames lines in a {@link PacketLineOut} format. */ | /** Advertiser which frames lines in a {@link PacketLineOut} format. */ | ||||
public static class PacketLineOutRefAdvertiser extends RefAdvertiser { | public static class PacketLineOutRefAdvertiser extends RefAdvertiser { | ||||
private final CharsetEncoder utf8 = CHARSET.newEncoder(); | |||||
private final CharsetEncoder utf8 = UTF_8.newEncoder(); | |||||
private final PacketLineOut pckOut; | private final PacketLineOut pckOut; | ||||
private byte[] binArr = new byte[256]; | private byte[] binArr = new byte[256]; |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.transport.SideBandOutputStream.HDR_SIZE; | import static org.eclipse.jgit.transport.SideBandOutputStream.HDR_SIZE; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.eclipse.jgit.errors.PackProtocolException; | import org.eclipse.jgit.errors.PackProtocolException; | ||||
import org.eclipse.jgit.errors.TransportException; | import org.eclipse.jgit.errors.TransportException; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.lib.Constants; | |||||
import org.eclipse.jgit.lib.ProgressMonitor; | import org.eclipse.jgit.lib.ProgressMonitor; | ||||
import org.eclipse.jgit.util.IO; | import org.eclipse.jgit.util.IO; | ||||
import org.eclipse.jgit.util.RawParseUtils; | import org.eclipse.jgit.util.RawParseUtils; | ||||
private String readString(int len) throws IOException { | private String readString(int len) throws IOException { | ||||
final byte[] raw = new byte[len]; | final byte[] raw = new byte[len]; | ||||
IO.readFully(rawIn, raw, 0, len); | IO.readFully(rawIn, raw, 0, len); | ||||
return RawParseUtils.decode(Constants.CHARSET, raw, 0, len); | |||||
return RawParseUtils.decode(UTF_8, raw, 0, len); | |||||
} | } | ||||
} | } |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.lib.Constants.CHARSET; | |||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
private static void scan(ClassLoader ldr, URL url) { | private static void scan(ClassLoader ldr, URL url) { | ||||
try (BufferedReader br = new BufferedReader( | try (BufferedReader br = new BufferedReader( | ||||
new InputStreamReader(url.openStream(), CHARSET))) { | |||||
new InputStreamReader(url.openStream(), UTF_8))) { | |||||
String line; | String line; | ||||
while ((line = br.readLine()) != null) { | while ((line = br.readLine()) != null) { | ||||
line = line.trim(); | line = line.trim(); |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import static org.eclipse.jgit.lib.Constants.HEAD; | import static org.eclipse.jgit.lib.Constants.HEAD; | ||||
import static org.eclipse.jgit.util.HttpSupport.ENCODING_GZIP; | import static org.eclipse.jgit.util.HttpSupport.ENCODING_GZIP; | ||||
import static org.eclipse.jgit.util.HttpSupport.ENCODING_X_GZIP; | import static org.eclipse.jgit.util.HttpSupport.ENCODING_X_GZIP; | ||||
} | } | ||||
private BufferedReader toBufferedReader(InputStream in) { | private BufferedReader toBufferedReader(InputStream in) { | ||||
return new BufferedReader(new InputStreamReader(in, Constants.CHARSET)); | |||||
return new BufferedReader(new InputStreamReader(in, UTF_8)); | |||||
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
// Line oriented readable content is likely to compress well. | // Line oriented readable content is likely to compress well. | ||||
// Request gzip encoding. | // Request gzip encoding. | ||||
InputStream is = open(path, AcceptEncoding.GZIP).in; | InputStream is = open(path, AcceptEncoding.GZIP).in; | ||||
return new BufferedReader(new InputStreamReader(is, Constants.CHARSET)); | |||||
return new BufferedReader(new InputStreamReader(is, UTF_8)); | |||||
} | } | ||||
@Override | @Override |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
*/ | */ | ||||
BufferedReader openReader(String path) throws IOException { | BufferedReader openReader(String path) throws IOException { | ||||
final InputStream is = open(path).in; | final InputStream is = open(path).in; | ||||
return new BufferedReader(new InputStreamReader(is, Constants.CHARSET)); | |||||
return new BufferedReader(new InputStreamReader(is, UTF_8)); | |||||
} | } | ||||
/** | /** |
package org.eclipse.jgit.treewalk; | package org.eclipse.jgit.treewalk; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.nio.ByteBuffer; | import java.nio.ByteBuffer; | ||||
import java.nio.CharBuffer; | import java.nio.CharBuffer; | ||||
if (prefix != null && prefix.length() > 0) { | if (prefix != null && prefix.length() > 0) { | ||||
final ByteBuffer b; | final ByteBuffer b; | ||||
b = Constants.CHARSET.encode(CharBuffer.wrap(prefix)); | |||||
b = UTF_8.encode(CharBuffer.wrap(prefix)); | |||||
pathLen = b.limit(); | pathLen = b.limit(); | ||||
path = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)]; | path = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)]; | ||||
b.get(path, 0, pathLen); | b.get(path, 0, pathLen); |
package org.eclipse.jgit.treewalk; | package org.eclipse.jgit.treewalk; | ||||
import static java.nio.charset.StandardCharsets.UTF_8; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Map; | import java.util.Map; | ||||
final AbstractTreeIterator t = currentHead; | final AbstractTreeIterator t = currentHead; | ||||
final int off = t.pathOffset; | final int off = t.pathOffset; | ||||
final int end = t.pathLen; | final int end = t.pathLen; | ||||
return RawParseUtils.decode(Constants.CHARSET, t.path, off, end); | |||||
return RawParseUtils.decode(UTF_8, t.path, off, end); | |||||
} | } | ||||
/** | /** | ||||
} | } | ||||
static String pathOf(AbstractTreeIterator t) { | static String pathOf(AbstractTreeIterator t) { | ||||
return RawParseUtils.decode(Constants.CHARSET, t.path, 0, t.pathLen); | |||||
return RawParseUtils.decode(UTF_8, t.path, 0, t.pathLen); | |||||
} | } | ||||
static String pathOf(byte[] buf, int pos, int end) { | static String pathOf(byte[] buf, int pos, int end) { | ||||
return RawParseUtils.decode(Constants.CHARSET, buf, pos, end); | |||||
return RawParseUtils.decode(UTF_8, buf, pos, end); | |||||
} | } | ||||
/** | /** |