You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ay...@apache.org on 2014/06/12 22:05:36 UTC
git commit: creating a string without copying a byte array
Repository: camel
Updated Branches:
refs/heads/master 0c3017b6b -> 23840df83
creating a string without copying a byte array
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/23840df8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/23840df8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/23840df8
Branch: refs/heads/master
Commit: 23840df83443628d4f3adbf2c3a5bcb34de434c9
Parents: 0c3017b
Author: Akitoshi Yoshida <ay...@apache.org>
Authored: Thu Jun 12 22:02:54 2014 +0200
Committer: Akitoshi Yoshida <ay...@apache.org>
Committed: Thu Jun 12 22:05:04 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/support/RecordableInputStream.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/23840df8/camel-core/src/main/java/org/apache/camel/support/RecordableInputStream.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/RecordableInputStream.java b/camel-core/src/main/java/org/apache/camel/support/RecordableInputStream.java
index 8ae29e6..c69cd3c 100644
--- a/camel-core/src/main/java/org/apache/camel/support/RecordableInputStream.java
+++ b/camel-core/src/main/java/org/apache/camel/support/RecordableInputStream.java
@@ -58,16 +58,16 @@ class RecordableInputStream extends FilterInputStream {
public String getText(int pos) {
String t = null;
recording = false;
- final byte[] ba = buf.toByteArray(pos);
- buf.trim(pos, 0);
try {
if (charset == null) {
- t = new String(ba);
+ t = new String(buf.getByteArray(), 0, pos);
} else {
- t = new String(ba, charset);
+ t = new String(buf.getByteArray(), 0, pos, charset);
}
} catch (UnsupportedEncodingException e) {
// ignore it as this encoding exception should have been caught earlier while scanning.
+ } finally {
+ buf.trim(pos, 0);
}
return t;
@@ -99,6 +99,10 @@ class RecordableInputStream extends FilterInputStream {
System.arraycopy(buf, 0, b, 0, len);
return b;
}
+
+ byte[] getByteArray() {
+ return buf;
+ }
}
}