Author: mduerig
Date: Wed Apr 19 12:09:22 2017
New Revision: 1791905

URL: http://svn.apache.org/viewvc?rev=1791905&view=rev
Log:
OAK-6056: Refactor SegmentStream to reduce buffering
Use ByteBuffer instead of array of byte for inlined streams

Modified:
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java?rev=1791905&r1=1791904&r2=1791905&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java
 Wed Apr 19 12:09:22 2017
@@ -55,7 +55,7 @@ public class SegmentStream extends Input
 
     private final RecordId recordId;
 
-    private final byte[] inline;
+    private final ByteBuffer inline;
 
     private final ListRecord blocks;
 
@@ -75,9 +75,7 @@ public class SegmentStream extends Input
 
     SegmentStream(RecordId recordId, ByteBuffer inline, int length) {
         this.recordId = checkNotNull(recordId);
-        // TODO rewrite this class to leverage the ByteBuffer apis
-        this.inline = new byte[length];
-        inline.get(this.inline);
+        this.inline = inline.duplicate();
         this.blocks = null;
         this.length = length;
     }
@@ -96,7 +94,7 @@ public class SegmentStream extends Input
 
     public String getString() {
         if (inline != null) {
-            return new String(inline, Charsets.UTF_8);
+            return Charsets.UTF_8.decode(inline).toString();
         } else if (length > Integer.MAX_VALUE) {
             throw new IllegalStateException("Too long value: " + length);
         } else {
@@ -154,7 +152,8 @@ public class SegmentStream extends Input
         }
 
         if (inline != null) {
-            System.arraycopy(inline, (int) position, b, off, len);
+            inline.position((int) position);
+            inline.get(b, off, len);
         } else {
             int blockIndex = (int) (position / BLOCK_SIZE);
             int blockOffset = (int) (position % BLOCK_SIZE);


Reply via email to