summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.server.test/tst/org
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2016-07-28 12:16:24 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2016-07-28 12:17:45 +0900
commitddb12b003f5f7654bd8aeb45e4b4c879358ead00 (patch)
treecdbf32432d45ead3a1f47e0297b0480325ba022c /org.eclipse.jgit.lfs.server.test/tst/org
parentbb9988c2368f1986fc0d59cc44fa754f22ca2708 (diff)
downloadjgit-ddb12b003f5f7654bd8aeb45e4b4c879358ead00.tar.gz
jgit-ddb12b003f5f7654bd8aeb45e4b4c879358ead00.zip
LfsServerTest: Treat response body as UTF-8 when decoding error message
Change-Id: I495f0b60b7128fff27502641e6a5d05f888d4e8a Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.lfs.server.test/tst/org')
-rw-r--r--org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
index b4a4228901..2dab6ea5ef 100644
--- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
+++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
@@ -42,10 +42,10 @@
*/
package org.eclipse.jgit.lfs.server.fs;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -80,6 +80,7 @@ import org.eclipse.jgit.lfs.lib.Constants;
import org.eclipse.jgit.lfs.lib.LongObjectId;
import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils;
import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.IO;
import org.junit.After;
import org.junit.Before;
@@ -189,15 +190,17 @@ public abstract class LfsServerTest {
if (statusLine.getStatusCode() >= 400) {
String error;
try {
- BufferedInputStream bis = new BufferedInputStream(
- response.getEntity().getContent());
- ByteArrayOutputStream buf = new ByteArrayOutputStream();
- int result = bis.read();
- while (result != -1) {
- buf.write((byte) result);
- result = bis.read();
+ ByteBuffer buf = IO.readWholeStream(new BufferedInputStream(
+ response.getEntity().getContent()), 1024);
+ if (buf.hasArray()) {
+ error = new String(buf.array(),
+ buf.arrayOffset() + buf.position(), buf.remaining(),
+ UTF_8);
+ } else {
+ final byte[] b = new byte[buf.remaining()];
+ buf.duplicate().get(b);
+ error = new String(b, UTF_8);
}
- error = buf.toString();
} catch (IOException e) {
error = statusLine.getReasonPhrase();
}