Explicitly specify charset in constructor of String
Change-Id: Ie9a9f917503019e7fa51ccbc11a5a3518b74434b Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
ee40efcea4
commit
a7d3fa3064
|
@ -42,6 +42,7 @@
|
|||
*/
|
||||
package org.eclipse.jgit.lfs.server.fs;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -149,7 +150,7 @@ public void testPushSimple() throws Exception {
|
|||
new String(IO
|
||||
.readWholeStream(is,
|
||||
(int) ldr.getSize())
|
||||
.array()));
|
||||
.array(), UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
*/
|
||||
package org.eclipse.jgit.api;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
|
@ -231,7 +232,9 @@ public MockOutputStream createArchiveOutputStream(OutputStream s,
|
|||
|
||||
@Override
|
||||
public void putEntry(MockOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) {
|
||||
String content = mode != FileMode.TREE ? new String(loader.getBytes()) : null;
|
||||
String content = mode != FileMode.TREE
|
||||
? new String(loader.getBytes(), UTF_8)
|
||||
: null;
|
||||
entries.put(path, content);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
*/
|
||||
package org.eclipse.jgit.api;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -1298,7 +1299,7 @@ static private String getHead(Git git, String path)
|
|||
final TreeWalk tw = TreeWalk.forPath(repo, path,
|
||||
rw.parseTree(headId));
|
||||
return new String(tw.getObjectReader().open(tw.getObjectId(0))
|
||||
.getBytes());
|
||||
.getBytes(), UTF_8);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
*/
|
||||
package org.eclipse.jgit.api;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -722,10 +723,10 @@ private void collectEntryContentAndAttributes(FileMode type, String pathName,
|
|||
}
|
||||
e.attrs = e.attrs.trim();
|
||||
e.file = new String(
|
||||
IO.readFully(new File(db.getWorkTree(), pathName)));
|
||||
IO.readFully(new File(db.getWorkTree(), pathName)), UTF_8);
|
||||
DirCacheEntry dce = dirCache.getEntry(pathName);
|
||||
ObjectLoader open = walk.getObjectReader().open(dce.getObjectId());
|
||||
e.index = new String(open.getBytes());
|
||||
e.index = new String(open.getBytes(), UTF_8);
|
||||
e.indexContentLength = dce.getLength();
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.jgit.internal.storage.file;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -75,7 +76,7 @@ public void shouldFilterLineFeedFromMessage() throws Exception {
|
|||
|
||||
byte[] buffer = new byte[oneLine.getBytes().length];
|
||||
readReflog(buffer);
|
||||
assertEquals(oneLine, new String(buffer));
|
||||
assertEquals(oneLine, new String(buffer, UTF_8));
|
||||
}
|
||||
|
||||
private void readReflog(byte[] buffer)
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
package org.eclipse.jgit.util;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -77,8 +78,8 @@ public void testCopyStdIn() throws IOException, InterruptedException {
|
|||
new ProcessBuilder("sh", script.getPath()), out, err,
|
||||
new ByteArrayInputStream(inputStr.getBytes()));
|
||||
assertEquals(0, rc);
|
||||
assertEquals(inputStr, new String(out.toByteArray()));
|
||||
assertEquals("", new String(err.toByteArray()));
|
||||
assertEquals(inputStr, new String(out.toByteArray(), UTF_8));
|
||||
assertEquals("", new String(err.toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -88,8 +89,8 @@ public void testCopyNullStdIn() throws IOException, InterruptedException {
|
|||
new ProcessBuilder("sh", script.getPath()), out, err,
|
||||
(InputStream) null);
|
||||
assertEquals(0, rc);
|
||||
assertEquals("", new String(out.toByteArray()));
|
||||
assertEquals("", new String(err.toByteArray()));
|
||||
assertEquals("", new String(out.toByteArray(), UTF_8));
|
||||
assertEquals("", new String(err.toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -99,8 +100,8 @@ public void testArguments() throws IOException, InterruptedException {
|
|||
new ProcessBuilder("sh",
|
||||
script.getPath(), "a", "b", "c"), out, err, (InputStream) null);
|
||||
assertEquals(0, rc);
|
||||
assertEquals("3,a,b,c,,,\n", new String(out.toByteArray()));
|
||||
assertEquals("", new String(err.toByteArray()));
|
||||
assertEquals("3,a,b,c,,,\n", new String(out.toByteArray(), UTF_8));
|
||||
assertEquals("", new String(err.toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -110,8 +111,8 @@ public void testRc() throws IOException, InterruptedException {
|
|||
new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
|
||||
out, err, (InputStream) null);
|
||||
assertEquals(3, rc);
|
||||
assertEquals("", new String(out.toByteArray()));
|
||||
assertEquals("", new String(err.toByteArray()));
|
||||
assertEquals("", new String(out.toByteArray(), UTF_8));
|
||||
assertEquals("", new String(err.toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -121,8 +122,8 @@ public void testNullStdout() throws IOException, InterruptedException {
|
|||
new ProcessBuilder("sh", script.getPath()), null, err,
|
||||
(InputStream) null);
|
||||
assertEquals(0, rc);
|
||||
assertEquals("", new String(out.toByteArray()));
|
||||
assertEquals("", new String(err.toByteArray()));
|
||||
assertEquals("", new String(out.toByteArray(), UTF_8));
|
||||
assertEquals("", new String(err.toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -132,8 +133,8 @@ public void testStdErr() throws IOException, InterruptedException {
|
|||
new ProcessBuilder("sh", script.getPath()), null, err,
|
||||
(InputStream) null);
|
||||
assertEquals(0, rc);
|
||||
assertEquals("", new String(out.toByteArray()));
|
||||
assertEquals("hi" + LF, new String(err.toByteArray()));
|
||||
assertEquals("", new String(out.toByteArray(), UTF_8));
|
||||
assertEquals("hi" + LF, new String(err.toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -144,8 +145,8 @@ public void testAllTogetherBin() throws IOException, InterruptedException {
|
|||
new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
|
||||
out, err, new ByteArrayInputStream(inputStr.getBytes()));
|
||||
assertEquals(5, rc);
|
||||
assertEquals(inputStr, new String(out.toByteArray()));
|
||||
assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray()));
|
||||
assertEquals(inputStr, new String(out.toByteArray(), UTF_8));
|
||||
assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
|
@ -174,8 +175,9 @@ public void testCopyStdInExecute()
|
|||
ExecutionResult res = FS.DETECTED.execute(pb,
|
||||
new ByteArrayInputStream(inputStr.getBytes()));
|
||||
assertEquals(0, res.getRc());
|
||||
assertEquals(inputStr, new String(res.getStdout().toByteArray()));
|
||||
assertEquals("", new String(res.getStderr().toByteArray()));
|
||||
assertEquals(inputStr,
|
||||
new String(res.getStdout().toByteArray(), UTF_8));
|
||||
assertEquals("", new String(res.getStderr().toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -184,8 +186,9 @@ public void testStdErrExecute() throws IOException, InterruptedException {
|
|||
ProcessBuilder pb = new ProcessBuilder("sh", script.getPath());
|
||||
ExecutionResult res = FS.DETECTED.execute(pb, null);
|
||||
assertEquals(0, res.getRc());
|
||||
assertEquals("", new String(res.getStdout().toByteArray()));
|
||||
assertEquals("hi" + LF, new String(res.getStderr().toByteArray()));
|
||||
assertEquals("", new String(res.getStdout().toByteArray(), UTF_8));
|
||||
assertEquals("hi" + LF,
|
||||
new String(res.getStderr().toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -199,9 +202,10 @@ public void testAllTogetherBinExecute()
|
|||
ExecutionResult res = FS.DETECTED.execute(pb,
|
||||
new ByteArrayInputStream(inputStr.getBytes()));
|
||||
assertEquals(5, res.getRc());
|
||||
assertEquals(inputStr, new String(res.getStdout().toByteArray()));
|
||||
assertEquals(inputStr,
|
||||
new String(res.getStdout().toByteArray(), UTF_8));
|
||||
assertEquals("3,a,b,c,,," + LF,
|
||||
new String(res.getStderr().toByteArray()));
|
||||
new String(res.getStderr().toByteArray(), UTF_8));
|
||||
}
|
||||
|
||||
private File writeTempFile(String body) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue