From cc07a471dcd83740d4a8efc4a5323d83eb60d2fb Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 7 May 2021 10:50:58 +0200 Subject: Add TemporaryBuffer.toString(int limit) Change-Id: I8603fcdfd0244088b3b217f002a78e7a646ea205 Signed-off-by: Matthias Sohn --- .../org/eclipse/jgit/dircache/DirCacheCheckout.java | 6 ++---- .../eclipse/jgit/treewalk/WorkingTreeIterator.java | 3 +-- .../src/org/eclipse/jgit/util/TemporaryBuffer.java | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) (limited to 'org.eclipse.jgit/src/org/eclipse') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java index 671475ed47..c904a782db 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java @@ -1610,11 +1610,9 @@ public class DirCacheCheckout { } if (rc != 0) { throw new IOException(new FilterFailedException(rc, - checkoutMetadata.smudgeFilterCommand, - path, + checkoutMetadata.smudgeFilterCommand, path, result.getStdout().toByteArray(MAX_EXCEPTION_TEXT_SIZE), - RawParseUtils.decode(result.getStderr() - .toByteArray(MAX_EXCEPTION_TEXT_SIZE)))); + result.getStderr().toString(MAX_EXCEPTION_TEXT_SIZE))); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 55b7d6279a..0b7c0a9e4b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -502,8 +502,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { throw new IOException(new FilterFailedException(rc, filterCommand, getEntryPathString(), result.getStdout().toByteArray(MAX_EXCEPTION_TEXT_SIZE), - RawParseUtils.decode(result.getStderr() - .toByteArray(MAX_EXCEPTION_TEXT_SIZE)))); + result.getStderr().toString(MAX_EXCEPTION_TEXT_SIZE))); } return result.getStdout().openInputStreamWithAutoDestroy(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java index 562eb05dd9..fb893a66f0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java @@ -18,6 +18,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.UncheckedIOException; import java.util.ArrayList; import org.eclipse.jgit.internal.JGitText; @@ -212,6 +213,24 @@ public abstract class TemporaryBuffer extends OutputStream { return out; } + /** + * Convert first {@code limit} number of bytes of the buffer content to + * String. + * + * @param limit + * the maximum number of bytes to be converted to String + * @return first {@code limit} number of bytes of the buffer content + * converted to String. + * @since 5.12 + */ + public String toString(int limit) { + try { + return RawParseUtils.decode(toByteArray(limit)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + /** * Convert this buffer's contents into a contiguous byte array. If this size * of the buffer exceeds the limit only return the first {@code limit} bytes -- cgit v1.2.3