Index: oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveReader.java =================================================================== --- oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveReader.java (revision 1848197) +++ oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveReader.java (working copy) @@ -23,7 +23,6 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -40,6 +39,7 @@ import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; public class AzureSegmentArchiveReader implements SegmentArchiveReader { static final boolean OFF_HEAP = getBoolean("access.off.heap"); @@ -70,17 +70,17 @@ } @Override - public ByteBuffer readSegment(long msb, long lsb) throws IOException { + public Buffer readSegment(long msb, long lsb) throws IOException { AzureSegmentArchiveEntry indexEntry = index.get(new UUID(msb, lsb)); if (indexEntry == null) { return null; } - ByteBuffer buffer; + Buffer buffer; if (OFF_HEAP) { - buffer = ByteBuffer.allocateDirect(indexEntry.getLength()); + buffer = Buffer.allocateDirect(indexEntry.getLength()); } else { - buffer = ByteBuffer.allocate(indexEntry.getLength()); + buffer = Buffer.allocate(indexEntry.getLength()); } ioMonitor.beforeSegmentRead(pathAsFile(), msb, lsb, indexEntry.getLength()); Stopwatch stopwatch = Stopwatch.createStarted(); @@ -101,8 +101,8 @@ } @Override - public ByteBuffer getGraph() throws IOException { - ByteBuffer graph = readBlob(getName() + ".gph"); + public Buffer getGraph() throws IOException { + Buffer graph = readBlob(getName() + ".gph"); hasGraph = graph != null; return graph; } @@ -118,7 +118,7 @@ } @Override - public ByteBuffer getBinaryReferences() throws IOException { + public Buffer getBinaryReferences() throws IOException { return readBlob(getName() + ".brf"); } @@ -154,14 +154,14 @@ } } - private ByteBuffer readBlob(String name) throws IOException { + private Buffer readBlob(String name) throws IOException { try { CloudBlockBlob blob = getBlob(name); if (!blob.exists()) { return null; } long length = blob.getProperties().getLength(); - ByteBuffer buffer = ByteBuffer.allocate((int) length); + Buffer buffer = Buffer.allocate((int) length); AzureUtilities.readBufferFully(blob, buffer); return buffer; } catch (StorageException e) { Index: oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveWriter.java =================================================================== --- oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveWriter.java (revision 1848197) +++ oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveWriter.java (working copy) @@ -23,7 +23,6 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.nio.ByteBuffer; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -40,6 +39,7 @@ import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; public class AzureSegmentArchiveWriter implements SegmentArchiveWriter { @@ -99,22 +99,22 @@ } @Override - public ByteBuffer readSegment(long msb, long lsb) throws IOException { + public Buffer readSegment(long msb, long lsb) throws IOException { UUID uuid = new UUID(msb, lsb); Optional segment = queue.map(q -> q.read(uuid)); if (segment.isPresent()) { - return segment.get().toByteBuffer(); + return segment.get().toBuffer(); } AzureSegmentArchiveEntry indexEntry = index.get(new UUID(msb, lsb)); if (indexEntry == null) { return null; } - ByteBuffer buffer; + Buffer buffer; if (OFF_HEAP) { - buffer = ByteBuffer.allocateDirect(indexEntry.getLength()); + buffer = Buffer.allocateDirect(indexEntry.getLength()); } else { - buffer = ByteBuffer.allocate(indexEntry.getLength()); + buffer = Buffer.allocate(indexEntry.getLength()); } readBufferFully(getBlob(getSegmentFileName(indexEntry)), buffer); return buffer; Index: oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureUtilities.java =================================================================== --- oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureUtilities.java (revision 1848197) +++ oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureUtilities.java (working copy) @@ -20,7 +20,6 @@ import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; -import java.nio.ByteBuffer; import java.nio.file.Paths; import java.security.InvalidKeyException; import java.util.EnumSet; @@ -36,6 +35,7 @@ import com.microsoft.azure.storage.blob.CloudBlob; import com.microsoft.azure.storage.blob.CloudBlobContainer; import com.microsoft.azure.storage.blob.CloudBlobDirectory; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,7 +75,7 @@ } } - public static void readBufferFully(CloudBlob blob, ByteBuffer buffer) throws IOException { + public static void readBufferFully(CloudBlob blob, Buffer buffer) throws IOException { try { blob.download(new ByteBufferOutputStream(buffer)); buffer.flip(); @@ -105,7 +105,7 @@ public static CloudBlobDirectory cloudBlobDirectoryFrom(String connection, String containerName, String dir) throws InvalidKeyException, URISyntaxException, StorageException { - CloudStorageAccount cloud = CloudStorageAccount.parse(connection.toString()); + CloudStorageAccount cloud = CloudStorageAccount.parse(connection); CloudBlobContainer container = cloud.createCloudBlobClient().getContainerReference(containerName); container.createIfNotExists(); @@ -115,19 +115,19 @@ private static class ByteBufferOutputStream extends OutputStream { @NotNull - private final ByteBuffer buffer; + private final Buffer buffer; - public ByteBufferOutputStream(@NotNull ByteBuffer buffer) { + public ByteBufferOutputStream(@NotNull Buffer buffer) { this.buffer = buffer; } @Override - public void write(int b) throws IOException { + public void write(int b) { buffer.put((byte)b); } @Override - public void write(@NotNull byte[] bytes, int offset, int length) throws IOException { + public void write(@NotNull byte[] bytes, int offset, int length) { buffer.put(bytes, offset, length); } } Index: oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/queue/SegmentWriteAction.java =================================================================== --- oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/queue/SegmentWriteAction.java (revision 1848197) +++ oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/queue/SegmentWriteAction.java (working copy) @@ -17,9 +17,9 @@ package org.apache.jackrabbit.oak.segment.azure.queue; import org.apache.jackrabbit.oak.segment.azure.AzureSegmentArchiveEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.UUID; public class SegmentWriteAction { @@ -47,8 +47,8 @@ return new UUID(indexEntry.getMsb(), indexEntry.getLsb()); } - public ByteBuffer toByteBuffer() { - return ByteBuffer.wrap(buffer, offset, length); + public Buffer toBuffer() { + return Buffer.wrap(buffer, offset, length); } void passTo(SegmentWriteQueue.SegmentConsumer consumer) throws IOException { Index: oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java =================================================================== --- oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java (revision 1848197) +++ oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java (working copy) @@ -45,10 +45,10 @@ import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; import org.apache.jackrabbit.oak.segment.tool.Check; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import java.io.IOException; import java.io.PrintWriter; -import java.nio.ByteBuffer; import java.text.MessageFormat; import java.util.ArrayDeque; import java.util.Collections; @@ -317,12 +317,12 @@ writeSegment(segmentEntry, archiveReader, archiveWriter); } - ByteBuffer binRefBuffer = archiveReader.getBinaryReferences(); + Buffer binRefBuffer = archiveReader.getBinaryReferences(); byte[] binRefData = fetchByteArray(binRefBuffer); archiveWriter.writeBinaryReferences(binRefData); - ByteBuffer graphBuffer = archiveReader.getGraph(); + Buffer graphBuffer = archiveReader.getGraph(); byte[] graphData = fetchByteArray(graphBuffer); archiveWriter.writeGraph(graphData); @@ -344,7 +344,7 @@ int fullGeneration = segmentEntry.getFullGeneration(); boolean isCompacted = segmentEntry.isCompacted(); - ByteBuffer byteBuffer = archiveReader.readSegment(msb, lsb); + Buffer byteBuffer = archiveReader.readSegment(msb, lsb); byte[] data = fetchByteArray(byteBuffer); archiveWriter.writeSegment(msb, lsb, data, offset, size, generation, fullGeneration, isCompacted); Index: oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/ToolUtils.java =================================================================== --- oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/ToolUtils.java (revision 1848197) +++ oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/ToolUtils.java (working copy) @@ -24,12 +24,19 @@ import static org.apache.jackrabbit.oak.segment.azure.util.AzureConfigurationParserUtils.parseAzureConfigurationFromUri; import static org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.defaultGCOptions; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URISyntaxException; +import java.text.MessageFormat; +import java.util.Map; +import java.util.concurrent.TimeUnit; + import com.google.common.base.Stopwatch; import com.microsoft.azure.storage.StorageCredentials; import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; import com.microsoft.azure.storage.StorageException; import com.microsoft.azure.storage.blob.CloudBlobDirectory; - import org.apache.jackrabbit.oak.segment.azure.AzurePersistence; import org.apache.jackrabbit.oak.segment.azure.AzureUtilities; import org.apache.jackrabbit.oak.segment.file.FileStore; @@ -40,15 +47,7 @@ import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.net.URISyntaxException; -import java.nio.ByteBuffer; -import java.text.MessageFormat; -import java.util.Map; -import java.util.concurrent.TimeUnit; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; /** * Utility class for common stuff pertaining to tooling. @@ -164,7 +163,7 @@ pw.println(MessageFormat.format(format, arg)); } - public static byte[] fetchByteArray(ByteBuffer buffer) throws IOException { + public static byte[] fetchByteArray(Buffer buffer) throws IOException { byte[] data = new byte[buffer.remaining()]; buffer.get(data); return data; Index: oak-segment-azure/src/test/java/oak/apache/jackrabbit/oak/segment/azure/tool/SegmentCopyTestBase.java =================================================================== --- oak-segment-azure/src/test/java/oak/apache/jackrabbit/oak/segment/azure/tool/SegmentCopyTestBase.java (revision 1848197) +++ oak-segment-azure/src/test/java/oak/apache/jackrabbit/oak/segment/azure/tool/SegmentCopyTestBase.java (working copy) @@ -23,6 +23,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Collections; +import java.util.List; + import org.apache.jackrabbit.oak.segment.SegmentCache; import org.apache.jackrabbit.oak.segment.SegmentNodeStore; import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders; @@ -42,6 +48,7 @@ import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; @@ -50,13 +57,6 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.List; - public abstract class SegmentCopyTestBase { private static final String AZURE_DIRECTORY = "repository"; private static final String AZURE_CONTAINER = "oak-test"; @@ -164,20 +164,20 @@ assertEquals(srcSegment.getFullGeneration(), destSegment.getFullGeneration()); assertEquals(srcSegment.getGeneration(), destSegment.getFullGeneration()); - ByteBuffer srcDataBuffer = srcArchiveReader.readSegment(srcSegment.getMsb(), srcSegment.getLsb()); - ByteBuffer destDataBuffer = destArchiveReader.readSegment(destSegment.getMsb(), destSegment.getLsb()); + Buffer srcDataBuffer = srcArchiveReader.readSegment(srcSegment.getMsb(), srcSegment.getLsb()); + Buffer destDataBuffer = destArchiveReader.readSegment(destSegment.getMsb(), destSegment.getLsb()); assertEquals(srcDataBuffer, destDataBuffer); } - ByteBuffer srcBinRefBuffer = srcArchiveReader.getBinaryReferences(); - ByteBuffer destBinRefBuffer = destArchiveReader.getBinaryReferences(); + Buffer srcBinRefBuffer = srcArchiveReader.getBinaryReferences(); + Buffer destBinRefBuffer = destArchiveReader.getBinaryReferences(); assertEquals(srcBinRefBuffer, destBinRefBuffer); assertEquals(srcArchiveReader.hasGraph(), destArchiveReader.hasGraph()); - ByteBuffer srcGraphBuffer = srcArchiveReader.getGraph(); - ByteBuffer destGraphBuffer = destArchiveReader.getGraph(); + Buffer srcGraphBuffer = srcArchiveReader.getGraph(); + Buffer destGraphBuffer = destArchiveReader.getGraph(); assertEquals(srcGraphBuffer, destGraphBuffer); } } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java (working copy) @@ -27,7 +27,6 @@ import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; @@ -36,6 +35,7 @@ import org.apache.jackrabbit.oak.segment.file.GCNodeWriteMonitor; import org.apache.jackrabbit.oak.segment.file.cancel.Canceller; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.gc.GCMonitor; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; @@ -70,7 +70,7 @@ private interface NodeWriter { @NotNull - SegmentNodeState writeNode(@NotNull NodeState node, @Nullable ByteBuffer stableId) throws IOException; + SegmentNodeState writeNode(@NotNull NodeState node, @Nullable Buffer stableId) throws IOException; } /** @@ -141,7 +141,7 @@ } @Nullable - private static ByteBuffer getStableIdBytes(@NotNull NodeState node) { + private static Buffer getStableIdBytes(@NotNull NodeState node) { return node instanceof SegmentNodeState ? ((SegmentNodeState) node).getStableIdBytes() : null; Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Compactor.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Compactor.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Compactor.java (working copy) @@ -28,7 +28,6 @@ import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.List; import org.apache.jackrabbit.oak.api.Blob; @@ -37,6 +36,7 @@ import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder; import org.apache.jackrabbit.oak.segment.file.GCNodeWriteMonitor; import org.apache.jackrabbit.oak.segment.file.cancel.Canceller; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStateDiff; @@ -124,7 +124,7 @@ } @Nullable - private static ByteBuffer getStableIdBytes(NodeState state) { + private static Buffer getStableIdBytes(NodeState state) { if (state instanceof SegmentNodeState) { return ((SegmentNodeState) state).getStableIdBytes(); } else { Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java (working copy) @@ -52,7 +52,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; -import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -68,6 +67,7 @@ import org.apache.jackrabbit.oak.segment.RecordWriters.RecordWriter; import org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation; import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff; @@ -185,7 +185,7 @@ @Override @NotNull - public RecordId writeNode(@NotNull final NodeState state, @Nullable final ByteBuffer stableIdBytes) throws IOException { + public RecordId writeNode(@NotNull final NodeState state, @Nullable final Buffer stableIdBytes) throws IOException { return new SegmentWriteOperation(writeOperationHandler.getGCGeneration()) .writeNode(state, stableIdBytes); } @@ -740,7 +740,7 @@ return tid; } - private RecordId writeNode(@NotNull NodeState state, @Nullable ByteBuffer stableIdBytes) + private RecordId writeNode(@NotNull NodeState state, @Nullable Buffer stableIdBytes) throws IOException { RecordId compactedId = deduplicateNode(state); @@ -767,7 +767,7 @@ return (byte) (Byte.MIN_VALUE + 64 - numberOfLeadingZeros(childCount)); } - private RecordId writeNodeUncached(@NotNull NodeState state, @Nullable ByteBuffer stableIdBytes) + private RecordId writeNodeUncached(@NotNull NodeState state, @Nullable Buffer stableIdBytes) throws IOException { ModifiedNodeState after = null; @@ -873,7 +873,7 @@ RecordId stableId; if (stableIdBytes != null) { - ByteBuffer buffer = stableIdBytes.duplicate(); + Buffer buffer = stableIdBytes.duplicate(); byte[] bytes = new byte[buffer.remaining()]; buffer.get(bytes); stableId = writeBlock(bytes, 0, bytes.length); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordId.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordId.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordId.java (working copy) @@ -22,11 +22,11 @@ import static java.lang.Integer.parseInt; import static org.apache.jackrabbit.oak.segment.CacheWeights.OBJECT_HEADER_SIZE; -import java.nio.ByteBuffer; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; /** @@ -103,12 +103,12 @@ * @return this record id as byte array */ @NotNull - ByteBuffer getBytes() { + Buffer getBytes() { byte[] buffer = new byte[SERIALIZED_RECORD_ID_BYTES]; BinaryUtils.writeLong(buffer, 0, segmentId.getMostSignificantBits()); BinaryUtils.writeLong(buffer, 8, segmentId.getLeastSignificantBits()); BinaryUtils.writeInt(buffer, 16, offset); - return ByteBuffer.wrap(buffer); + return Buffer.wrap(buffer); } //--------------------------------------------------------< Comparable >-- Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java (working copy) @@ -36,7 +36,6 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; -import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Iterator; import java.util.UUID; @@ -54,6 +53,7 @@ import org.apache.jackrabbit.oak.segment.data.SegmentData; import org.apache.jackrabbit.oak.segment.data.StringData; import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -179,9 +179,9 @@ this.reader = checkNotNull(reader); this.info = checkNotNull(info); if (id.isDataSegmentId()) { - this.data = newSegmentData(ByteBuffer.wrap(buffer)); + this.data = newSegmentData(Buffer.wrap(buffer)); } else { - this.data = newRawSegmentData(ByteBuffer.wrap(buffer)); + this.data = newRawSegmentData(Buffer.wrap(buffer)); } this.version = SegmentVersion.fromByte(buffer[3]); this.recordNumbers = recordNumbers; @@ -192,7 +192,7 @@ public Segment(@NotNull SegmentIdProvider idProvider, @NotNull SegmentReader reader, @NotNull final SegmentId id, - @NotNull final ByteBuffer data) { + @NotNull final Buffer data) { this.reader = checkNotNull(reader); this.id = checkNotNull(id); if (id.isDataSegmentId()) { @@ -417,7 +417,7 @@ readBytes(recordNumber, position, length).get(buffer, offset, length); } - ByteBuffer readBytes(int recordNumber, int position, int length) { + Buffer readBytes(int recordNumber, int position, int length) { return data.readBytes(recordNumbers.getOffset(recordNumber) + position, length); } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBlob.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBlob.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBlob.java (working copy) @@ -21,9 +21,9 @@ import static com.google.common.base.Charsets.UTF_8; import static com.google.common.collect.Sets.newHashSet; import static java.util.Collections.emptySet; -import static org.apache.jackrabbit.oak.segment.SegmentStream.BLOCK_SIZE; import static org.apache.jackrabbit.oak.segment.Segment.MEDIUM_LIMIT; import static org.apache.jackrabbit.oak.segment.Segment.SMALL_LIMIT; +import static org.apache.jackrabbit.oak.segment.SegmentStream.BLOCK_SIZE; import java.io.InputStream; import java.util.List; @@ -198,7 +198,7 @@ private static String readShortBlobId(Segment segment, int recordNumber, byte head) { int length = (head & 0x0f) << 8 | (segment.readByte(recordNumber, 1) & 0xff); - return UTF_8.decode(segment.readBytes(recordNumber, 2, length)).toString(); + return segment.readBytes(recordNumber, 2, length).decode(UTF_8).toString(); } private static String readLongBlobId(Segment segment, int recordNumber) { Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitor.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitor.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitor.java (working copy) @@ -23,16 +23,16 @@ import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.nio.ByteBuffer; import java.util.Set; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.stats.CounterStats; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.jetbrains.annotations.NotNull; /** * This class exposes {@link CounterStats} for allocations and de-allocations - * of {@link ByteBuffer} instances: + * of {@link Buffer} instances: * *

- * Users of this class call {@link #trackAllocation(ByteBuffer)} to update above statistics. + * Users of this class call {@link #trackAllocation(Buffer)} to update above statistics. */ public class SegmentBufferMonitor { @@ -72,7 +72,7 @@ private final Set buffers = newConcurrentHashSet(); @NotNull - private final ReferenceQueue referenceQueue = new ReferenceQueue<>(); + private final ReferenceQueue referenceQueue = new ReferenceQueue<>(); @NotNull private final CounterStats directBufferCount; @@ -98,12 +98,12 @@ heapBufferCapacity = statisticsProvider.getCounterStats(HEAP_BUFFER_CAPACITY, METRICS_ONLY); } - private static class BufferReference extends WeakReference { + private static class BufferReference extends WeakReference { private final int capacity; private final boolean isDirect; - public BufferReference(@NotNull ByteBuffer buffer, - @NotNull ReferenceQueue queue) { + public BufferReference(@NotNull Buffer buffer, + @NotNull ReferenceQueue queue) { super(buffer, queue); this.capacity = buffer.capacity(); this.isDirect = buffer.isDirect(); @@ -114,7 +114,7 @@ * Track the allocation of a {@code buffer} and update the exposed statistics. * @param buffer */ - public void trackAllocation(@NotNull ByteBuffer buffer) { + public void trackAllocation(@NotNull Buffer buffer) { BufferReference reference = new BufferReference(buffer, referenceQueue); buffers.add(reference); allocated(reference); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java (working copy) @@ -36,7 +36,6 @@ import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE; import static org.apache.jackrabbit.oak.spi.state.AbstractNodeState.checkValidName; -import java.nio.ByteBuffer; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -47,6 +46,7 @@ import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState; import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.AbstractNodeState; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; @@ -134,8 +134,8 @@ } @NotNull - static String getStableId(@NotNull ByteBuffer stableId) { - ByteBuffer buffer = stableId.duplicate(); + static String getStableId(@NotNull Buffer stableId) { + Buffer buffer = stableId.duplicate(); long msb = buffer.getLong(); long lsb = buffer.getLong(); int offset = buffer.getInt(); @@ -161,7 +161,7 @@ * * @return the stable ID of this node. */ - public ByteBuffer getStableIdBytes() { + public Buffer getStableIdBytes() { // The first record id of this node points to the stable id. RecordId id = getSegment().readRecordId(getRecordNumber()); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java (working copy) @@ -25,12 +25,11 @@ import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; import java.util.List; import com.google.common.base.Charsets; import com.google.common.io.ByteStreams; - +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,7 +55,7 @@ private final RecordId recordId; - private final ByteBuffer inline; + private final Buffer inline; private final ListRecord blocks; @@ -74,7 +73,7 @@ this.length = length; } - SegmentStream(RecordId recordId, ByteBuffer inline, int length) { + SegmentStream(RecordId recordId, Buffer inline, int length) { this.recordId = checkNotNull(recordId); this.inline = inline.duplicate(); this.blocks = null; @@ -95,7 +94,7 @@ public String getString() { if (inline != null) { - return Charsets.UTF_8.decode(inline).toString(); + return inline.decode(Charsets.UTF_8).toString(); } else if (length > Integer.MAX_VALUE) { throw new IllegalStateException("Too long value: " + length); } else { Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java (working copy) @@ -19,9 +19,9 @@ import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; import org.apache.jackrabbit.oak.api.Blob; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,14 +65,14 @@ * @throws IOException */ @NotNull - RecordId writeNode(@NotNull NodeState state, @Nullable ByteBuffer stableIdBytes) throws IOException; + RecordId writeNode(@NotNull NodeState state, @Nullable Buffer stableIdBytes) throws IOException; /** * Write a node state. *

* Equivalent to {@code writeNode(state, null)} * - * @see #writeNode(NodeState, ByteBuffer) + * @see #writeNode(NodeState, Buffer) */ @NotNull default RecordId writeNode(@NotNull NodeState state) throws IOException { Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentData.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentData.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentData.java (working copy) @@ -19,7 +19,8 @@ import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; + +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; /** * Access the data of a segment. @@ -62,11 +63,11 @@ */ public interface SegmentData { - static SegmentData newSegmentData(ByteBuffer buffer) { + static SegmentData newSegmentData(Buffer buffer) { return SegmentDataLoader.newSegmentData(buffer); } - static SegmentData newRawSegmentData(ByteBuffer buffer) { + static SegmentData newRawSegmentData(Buffer buffer) { return SegmentDataLoader.newRawSegmentData(buffer); } @@ -108,7 +109,7 @@ long readLong(int recordReferenceOffset); - ByteBuffer readBytes(int recordReferenceOffset, int size); + Buffer readBytes(int recordReferenceOffset, int size); int size(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataLoader.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataLoader.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataLoader.java (working copy) @@ -17,7 +17,7 @@ package org.apache.jackrabbit.oak.segment.data; -import java.nio.ByteBuffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataLoader { @@ -27,7 +27,7 @@ private static final byte SEGMENT_DATA_V13 = 13; - static SegmentData newSegmentData(ByteBuffer buffer) { + static SegmentData newSegmentData(Buffer buffer) { switch (buffer.get(VERSION_OFFSET)) { case SEGMENT_DATA_V12: return new SegmentDataV12(buffer); @@ -38,7 +38,7 @@ } } - static SegmentData newRawSegmentData(ByteBuffer buffer) { + static SegmentData newRawSegmentData(Buffer buffer) { return new SegmentDataRaw(buffer); } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataRaw.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataRaw.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataRaw.java (working copy) @@ -19,13 +19,14 @@ import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; + +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataRaw implements SegmentData { - private final ByteBuffer buffer; + private final Buffer buffer; - SegmentDataRaw(ByteBuffer buffer) { + SegmentDataRaw(Buffer buffer) { this.buffer = buffer; } @@ -34,7 +35,7 @@ } @Override - public ByteBuffer readBytes(int recordReferenceOffset, int size) { + public Buffer readBytes(int recordReferenceOffset, int size) { return SegmentDataUtils.readBytes(buffer, index(recordReferenceOffset), size); } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataUtils.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataUtils.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataUtils.java (working copy) @@ -19,11 +19,11 @@ import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.WritableByteChannel; import org.apache.commons.io.HexDump; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataUtils { @@ -33,33 +33,33 @@ private static final int MAX_SEGMENT_SIZE = 1 << 18; - static void hexDump(ByteBuffer buffer, OutputStream stream) throws IOException { + static void hexDump(Buffer buffer, OutputStream stream) throws IOException { byte[] data = new byte[buffer.remaining()]; buffer.duplicate().get(data); HexDump.dump(data, 0, stream, 0); } - static void binDump(ByteBuffer buffer, OutputStream stream) throws IOException { - ByteBuffer data = buffer.duplicate(); + static void binDump(Buffer buffer, OutputStream stream) throws IOException { + Buffer data = buffer.duplicate(); try (WritableByteChannel channel = Channels.newChannel(stream)) { while (data.hasRemaining()) { - channel.write(data); + data.write(channel); } } } - static int estimateMemoryUsage(ByteBuffer buffer) { + static int estimateMemoryUsage(Buffer buffer) { return buffer.isDirect() ? 0 : buffer.remaining(); } - static ByteBuffer readBytes(ByteBuffer buffer, int index, int size) { - ByteBuffer duplicate = buffer.duplicate(); + static Buffer readBytes(Buffer buffer, int index, int size) { + Buffer duplicate = buffer.duplicate(); duplicate.position(index); duplicate.limit(index + size); return duplicate.slice(); } - static int index(ByteBuffer buffer, int recordReferenceOffset) { + static int index(Buffer buffer, int recordReferenceOffset) { return buffer.limit() - (MAX_SEGMENT_SIZE - recordReferenceOffset); } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV12.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV12.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV12.java (working copy) @@ -19,9 +19,9 @@ import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; import com.google.common.base.Charsets; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataV12 implements SegmentData { @@ -65,9 +65,9 @@ private static final int MAX_MEDIUM_LENGTH_VALUE = (1 << 14) + MAX_SMALL_LENGTH_VALUE; - final ByteBuffer buffer; + final Buffer buffer; - SegmentDataV12(ByteBuffer buffer) { + SegmentDataV12(Buffer buffer) { this.buffer = buffer; } @@ -192,10 +192,10 @@ } private StringData internalReadString(int index, int length) { - ByteBuffer duplicate = buffer.duplicate(); + Buffer duplicate = buffer.duplicate(); duplicate.position(index); duplicate.limit(index + length); - String string = Charsets.UTF_8.decode(duplicate).toString(); + String string = duplicate.decode(Charsets.UTF_8).toString(); return new StringData(string, length); } @@ -231,7 +231,7 @@ } @Override - public ByteBuffer readBytes(int recordReferenceOffset, int size) { + public Buffer readBytes(int recordReferenceOffset, int size) { return SegmentDataUtils.readBytes(buffer, index(recordReferenceOffset), size); } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV13.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV13.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV13.java (working copy) @@ -17,13 +17,13 @@ package org.apache.jackrabbit.oak.segment.data; -import java.nio.ByteBuffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataV13 extends SegmentDataV12 { private static final int FULL_GENERATION_OFFSET = 4; - SegmentDataV13(ByteBuffer buffer) { + SegmentDataV13(Buffer buffer) { super(buffer); } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractFileStore.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractFileStore.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractFileStore.java (working copy) @@ -24,7 +24,6 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -54,6 +53,7 @@ import org.apache.jackrabbit.oak.segment.file.tar.TarRecovery; import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.stats.StatsOptions; import org.jetbrains.annotations.NotNull; @@ -215,7 +215,7 @@ private void writeSegment(UUID id, byte[] data, EntryRecovery w) throws IOException { long msb = id.getMostSignificantBits(); long lsb = id.getLeastSignificantBits(); - ByteBuffer buffer = ByteBuffer.wrap(data); + Buffer buffer = Buffer.wrap(data); GCGeneration generation = SegmentId.isDataSegmentId(lsb) ? Segment.getGcGeneration(newSegmentData(buffer), id) : GCGeneration.NULL; @@ -279,7 +279,7 @@ } Segment readSegmentUncached(TarFiles tarFiles, SegmentId id) { - ByteBuffer buffer = tarFiles.readSegment(id.getMostSignificantBits(), id.getLeastSignificantBits()); + Buffer buffer = tarFiles.readSegment(id.getMostSignificantBits(), id.getLeastSignificantBits()); if (buffer == null) { throw new SegmentNotFoundException(id); } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java (working copy) @@ -29,7 +29,6 @@ import static org.apache.jackrabbit.oak.stats.StatsOptions.METRICS_ONLY; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Set; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -53,6 +52,7 @@ import org.apache.jackrabbit.oak.segment.file.tar.TarFiles; import org.apache.jackrabbit.oak.segment.spi.persistence.RepositoryLock; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.stats.CounterStats; import org.apache.jackrabbit.oak.stats.StatisticsProvider; @@ -517,14 +517,14 @@ Set binaryReferences = null; if (id.isDataSegmentId()) { - ByteBuffer data; + Buffer data; if (offset > 4096) { - data = ByteBuffer.allocate(length); + data = Buffer.allocate(length); data.put(buffer, offset, length); data.rewind(); } else { - data = ByteBuffer.wrap(buffer, offset, length); + data = Buffer.wrap(buffer, offset, length); } segment = new Segment(tracker, segmentReader, id, data); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java (working copy) @@ -20,15 +20,14 @@ import static com.google.common.base.Preconditions.checkState; import static java.nio.channels.FileChannel.MapMode.READ_ONLY; -import static org.apache.jackrabbit.oak.commons.IOUtils.readFully; import java.io.EOFException; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; + /** * A wrapper around either memory mapped files or random access files, to allow * reading from a file. @@ -39,7 +38,7 @@ abstract int length() throws IOException; - abstract ByteBuffer read(int position, int length) throws IOException; + abstract Buffer read(int position, int length) throws IOException; abstract void close() throws IOException; @@ -52,11 +51,11 @@ private final RandomAccessFile file; - private MappedByteBuffer buffer; + private Buffer buffer; Mapped(RandomAccessFile file) throws IOException { this.file = file; - this.buffer = file.getChannel().map(READ_ONLY, 0, file.length()); + this.buffer = Buffer.map(file.getChannel(), READ_ONLY, 0, file.length()); } @Override @@ -70,8 +69,8 @@ } @Override - public ByteBuffer read(int position, int length) { - ByteBuffer entry = buffer.asReadOnlyBuffer(); + public Buffer read(int position, int length) { + Buffer entry = buffer.asReadOnlyBuffer(); entry.position(entry.position() + position); entry.limit(entry.position() + length); return entry.slice(); @@ -111,12 +110,9 @@ } @Override - public synchronized ByteBuffer read(int position, int length) - throws IOException { - ByteBuffer entry; - entry = ByteBuffer.allocate(length); - - if (readFully(channel, position, entry) < length) { + public synchronized Buffer read(int position, int length) throws IOException { + Buffer entry = Buffer.allocate(length); + if (entry.readFully(channel, position) < length) { throw new EOFException(); } entry.flip(); @@ -141,12 +137,9 @@ } @Override - public synchronized ByteBuffer read(int position, int length) - throws IOException { - ByteBuffer entry; - entry = ByteBuffer.allocateDirect(length); - - if (readFully(channel, position, entry) < length) { + public synchronized Buffer read(int position, int length) throws IOException { + Buffer entry = Buffer.allocateDirect(length); + if (entry.readFully(channel, position) < length) { throw new EOFException(); } entry.flip(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/GraphLoader.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/GraphLoader.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/GraphLoader.java (working copy) @@ -18,20 +18,20 @@ */ package org.apache.jackrabbit.oak.segment.file.tar; -import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static com.google.common.collect.Lists.newArrayListWithCapacity; +import static com.google.common.collect.Maps.newHashMapWithExpectedSize; +import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.GRAPH_MAGIC; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.zip.CRC32; -import static com.google.common.collect.Lists.newArrayListWithCapacity; -import static com.google.common.collect.Maps.newHashMapWithExpectedSize; -import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.GRAPH_MAGIC; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; +import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class GraphLoader { @@ -48,8 +48,8 @@ * @return the graph or {@code null} if one was not found * @throws IOException if the tar file could not be read */ - public static ByteBuffer loadGraph(ReaderAtEnd readerAtEnd) throws IOException { - ByteBuffer meta = readerAtEnd.readAtEnd(FOOTER_SIZE, FOOTER_SIZE); + public static Buffer loadGraph(ReaderAtEnd readerAtEnd) throws IOException { + Buffer meta = readerAtEnd.readAtEnd(FOOTER_SIZE, FOOTER_SIZE); int crc32 = meta.getInt(); int count = meta.getInt(); @@ -71,7 +71,7 @@ return null; } - ByteBuffer graph = readerAtEnd.readAtEnd(bytes, bytes); + Buffer graph = readerAtEnd.readAtEnd(bytes, bytes); byte[] b = new byte[bytes - FOOTER_SIZE]; @@ -90,7 +90,7 @@ return graph; } - public static Map> parseGraph(ByteBuffer buffer) { + public static Map> parseGraph(Buffer buffer) { int nEntries = buffer.getInt(buffer.limit() - 12); Map> graph = newHashMapWithExpectedSize(nEntries); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarManager.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarManager.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarManager.java (working copy) @@ -19,23 +19,12 @@ package org.apache.jackrabbit.oak.segment.file.tar; import static com.google.common.base.Charsets.UTF_8; -import static java.nio.ByteBuffer.wrap; import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE; - -import org.apache.commons.io.filefilter.SuffixFileFilter; -import org.apache.jackrabbit.oak.segment.file.tar.index.Index; -import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; -import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static org.apache.jackrabbit.oak.segment.spi.persistence.Buffer.wrap; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; import java.nio.file.Files; import java.util.Arrays; import java.util.LinkedHashMap; @@ -45,6 +34,17 @@ import java.util.regex.Pattern; import java.util.zip.CRC32; +import org.apache.commons.io.filefilter.SuffixFileFilter; +import org.apache.jackrabbit.oak.segment.file.tar.index.Index; +import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; +import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class SegmentTarManager implements SegmentArchiveManager { /** @@ -219,7 +219,7 @@ } // The header checksum passes, so read the entry name and size - ByteBuffer buffer = wrap(header); + Buffer buffer = wrap(header); String name = readString(buffer, 100); buffer.position(124); int size = readNumber(buffer, 12); @@ -247,7 +247,7 @@ if (checksum != null) { CRC32 crc = new CRC32(); - crc.update(data); + crc.update(data, 0, data.length); if (crc.getValue() != Long.parseLong(checksum, 16)) { log.warn("Checksum mismatch in entry {} of tar file {}, skipping...", name, file); @@ -270,7 +270,7 @@ } } - private static String readString(ByteBuffer buffer, int fieldSize) { + private static String readString(Buffer buffer, int fieldSize) { byte[] b = new byte[fieldSize]; buffer.get(b); int n = 0; @@ -280,7 +280,7 @@ return new String(b, 0, n, UTF_8); } - private static int readNumber(ByteBuffer buffer, int fieldSize) { + private static int readNumber(Buffer buffer, int fieldSize) { byte[] b = new byte[fieldSize]; buffer.get(b); int number = 0; Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java (working copy) @@ -18,32 +18,32 @@ */ package org.apache.jackrabbit.oak.segment.file.tar; +import static org.apache.jackrabbit.oak.segment.file.tar.SegmentTarWriter.getPaddingSize; +import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE; +import static org.apache.jackrabbit.oak.segment.file.tar.index.IndexLoader.newIndexLoader; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; + import com.google.common.base.Stopwatch; -import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoader; import org.apache.jackrabbit.oak.segment.file.tar.binaries.InvalidBinaryReferencesIndexException; import org.apache.jackrabbit.oak.segment.file.tar.index.Index; import org.apache.jackrabbit.oak.segment.file.tar.index.IndexEntry; import org.apache.jackrabbit.oak.segment.file.tar.index.IndexLoader; import org.apache.jackrabbit.oak.segment.file.tar.index.InvalidIndexException; +import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static org.apache.jackrabbit.oak.segment.file.tar.SegmentTarWriter.getPaddingSize; -import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE; -import static org.apache.jackrabbit.oak.segment.file.tar.index.IndexLoader.newIndexLoader; - public class SegmentTarReader implements SegmentArchiveReader { private static final Logger log = LoggerFactory.getLogger(SegmentTarReader.class); @@ -71,7 +71,7 @@ } @Override - public ByteBuffer readSegment(long msb, long lsb) throws IOException { + public Buffer readSegment(long msb, long lsb) throws IOException { int i = index.findEntry(msb, lsb); if (i == -1) { return null; @@ -79,7 +79,7 @@ IndexEntry indexEntry = index.entry(i); ioMonitor.beforeSegmentRead(file, msb, lsb, indexEntry.getLength()); Stopwatch stopwatch = Stopwatch.createStarted(); - ByteBuffer buffer = access.read(indexEntry.getPosition(), indexEntry.getLength()); + Buffer buffer = access.read(indexEntry.getPosition(), indexEntry.getLength()); long elapsed = stopwatch.elapsed(TimeUnit.NANOSECONDS); ioMonitor.afterSegmentRead(file, msb, lsb, indexEntry.getLength(), elapsed); return buffer; @@ -115,7 +115,7 @@ return null; } ReaderAtEnd r = (whence, size) -> { - ByteBuffer buffer = ByteBuffer.allocate(size); + Buffer buffer = Buffer.allocate(size); file.seek(length - 2 * BLOCK_SIZE - whence); file.readFully(buffer.array()); return buffer; @@ -129,9 +129,9 @@ } @Override - public ByteBuffer getGraph() throws IOException { + public Buffer getGraph() throws IOException { int end = access.length() - 2 * BLOCK_SIZE - getIndexEntrySize(); - ByteBuffer graph = GraphLoader.loadGraph((whence, amount) -> access.read(end - whence, amount)); + Buffer graph = GraphLoader.loadGraph((whence, amount) -> access.read(end - whence, amount)); hasGraph = graph != null; return graph; } @@ -147,7 +147,7 @@ } @Override - public ByteBuffer getBinaryReferences() throws IOException { + public Buffer getBinaryReferences() throws IOException { try { int end = access.length() - 2 * BLOCK_SIZE - getIndexEntrySize() - getGraphEntrySize(); return BinaryReferencesIndexLoader.loadBinaryReferencesIndex((whence, amount) -> access.read(end - whence, amount)); @@ -181,7 +181,7 @@ } private int getGraphEntrySize() { - ByteBuffer buffer; + Buffer buffer; try { buffer = getGraph(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java (working copy) @@ -20,14 +20,12 @@ import static com.google.common.base.Charsets.UTF_8; import static com.google.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.oak.commons.IOUtils.readFully; import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE; import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Collections; import java.util.LinkedHashMap; @@ -43,6 +41,7 @@ import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -133,14 +132,14 @@ } @Override - public ByteBuffer readSegment(long msb, long lsb) throws IOException { + public Buffer readSegment(long msb, long lsb) throws IOException { IndexEntry indexEntry = index.get(new UUID(msb, lsb)); if (indexEntry == null) { return null; } checkState(channel != null); // implied by entry != null - ByteBuffer data = ByteBuffer.allocate(indexEntry.getLength()); - if (readFully(channel, indexEntry.getPosition(), data) < indexEntry.getLength()) { + Buffer data = Buffer.allocate(indexEntry.getLength()); + if (data.readFully(channel, indexEntry.getPosition()) < indexEntry.getLength()) { throw new EOFException(); } data.rewind(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java (working copy) @@ -28,7 +28,6 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -55,6 +54,7 @@ import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.stats.CounterStats; import org.apache.jackrabbit.oak.stats.NoopStats; import org.jetbrains.annotations.NotNull; @@ -547,14 +547,14 @@ return false; } - public ByteBuffer readSegment(long msb, long lsb) { + public Buffer readSegment(long msb, long lsb) { try { Node head; lock.readLock().lock(); try { if (writer != null) { - ByteBuffer b = writer.readEntry(msb, lsb); + Buffer b = writer.readEntry(msb, lsb); if (b != null) { return b; } @@ -565,7 +565,7 @@ } for (TarReader reader : iterable(head)) { - ByteBuffer b = reader.readEntry(msb, lsb); + Buffer b = reader.readEntry(msb, lsb); if (b != null) { return b; } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java (working copy) @@ -29,7 +29,6 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -42,13 +41,14 @@ import java.util.stream.Collectors; import com.google.common.base.Predicate; -import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoader; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndex; +import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoader; import org.apache.jackrabbit.oak.segment.file.tar.binaries.InvalidBinaryReferencesIndexException; import org.apache.jackrabbit.oak.segment.file.tar.index.IndexEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -305,7 +305,7 @@ * @param lsb the least significant bits of the segment id * @return the byte buffer, or null if not in this file. */ - ByteBuffer readEntry(long msb, long lsb) throws IOException { + Buffer readEntry(long msb, long lsb) throws IOException { return archive.readSegment(msb, lsb); } @@ -586,7 +586,7 @@ * @return The parsed graph, or {@code null} if one was not found. */ Map> getGraph() throws IOException { - ByteBuffer buffer = archive.getGraph(); + Buffer buffer = archive.getGraph(); if (buffer == null) { return null; } else { Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java (working copy) @@ -31,7 +31,6 @@ import java.io.Closeable; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -39,6 +38,7 @@ import java.util.zip.CRC32; import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexWriter; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; import org.apache.jackrabbit.oak.stats.CounterStats; @@ -127,7 +127,7 @@ * @param lsb the least significant bits of the segment id * @return the byte buffer, or null if not in this file */ - ByteBuffer readEntry(long msb, long lsb) throws IOException { + Buffer readEntry(long msb, long lsb) throws IOException { synchronized (this) { checkState(!closed); } @@ -279,7 +279,7 @@ graphSize += 16 * entry.getValue().size(); } - ByteBuffer buffer = ByteBuffer.allocate(graphSize); + Buffer buffer = Buffer.allocate(graphSize); for (Entry> entry : graph.entrySet()) { UUID from = entry.getKey(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoader.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoader.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoader.java (working copy) @@ -18,8 +18,8 @@ package org.apache.jackrabbit.oak.segment.file.tar.binaries; import java.io.IOException; -import java.nio.ByteBuffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; public class BinaryReferencesIndexLoader { @@ -41,7 +41,7 @@ * @throws InvalidBinaryReferencesIndexException if the index is invalid or * malformed. */ - public static ByteBuffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException { + public static Buffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException { switch (readMagic(reader)) { case BinaryReferencesIndexLoaderV1.MAGIC: return BinaryReferencesIndexLoaderV1.loadBinaryReferencesIndex(reader); @@ -52,7 +52,7 @@ } } - public static BinaryReferencesIndex parseBinaryReferencesIndex(ByteBuffer buffer) throws InvalidBinaryReferencesIndexException { + public static BinaryReferencesIndex parseBinaryReferencesIndex(Buffer buffer) throws InvalidBinaryReferencesIndexException { switch (readMagic(buffer)) { case BinaryReferencesIndexLoaderV1.MAGIC: return BinaryReferencesIndexLoaderV1.parseBinaryReferencesIndex(buffer); @@ -67,7 +67,7 @@ return reader.readAtEnd(Integer.BYTES, Integer.BYTES).getInt(); } - private static int readMagic(ByteBuffer buffer) { + private static int readMagic(Buffer buffer) { buffer.position(buffer.limit() - Integer.BYTES); int magic = buffer.getInt(); buffer.rewind(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java (working copy) @@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.segment.file.tar.binaries; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -27,6 +26,7 @@ import java.util.zip.CRC32; import com.google.common.base.Charsets; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; class BinaryReferencesIndexLoaderV1 { @@ -35,8 +35,8 @@ static final int FOOTER_SIZE = 16; - static ByteBuffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException { - ByteBuffer meta = reader.readAtEnd(FOOTER_SIZE, FOOTER_SIZE); + static Buffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException { + Buffer meta = reader.readAtEnd(FOOTER_SIZE, FOOTER_SIZE); int crc32 = meta.getInt(); int count = meta.getInt(); @@ -56,12 +56,12 @@ return reader.readAtEnd(size, size); } - public static BinaryReferencesIndex parseBinaryReferencesIndex(ByteBuffer buffer) throws InvalidBinaryReferencesIndexException { - ByteBuffer data = buffer.slice(); + public static BinaryReferencesIndex parseBinaryReferencesIndex(Buffer buffer) throws InvalidBinaryReferencesIndexException { + Buffer data = buffer.slice(); data.limit(data.limit() - FOOTER_SIZE); buffer.position(buffer.limit() - FOOTER_SIZE); - ByteBuffer meta = buffer.slice(); + Buffer meta = buffer.slice(); int crc32 = meta.getInt(); int count = meta.getInt(); @@ -80,7 +80,7 @@ CRC32 checksum = new CRC32(); data.mark(); - checksum.update(data); + data.update(checksum); data.reset(); if ((int) (checksum.getValue()) != crc32) { @@ -90,7 +90,7 @@ return new BinaryReferencesIndex(parseBinaryReferencesIndex(count, data)); } - private static Map>> parseBinaryReferencesIndex(int count, ByteBuffer buffer) { + private static Map>> parseBinaryReferencesIndex(int count, Buffer buffer) { Map>> result = new HashMap<>(count); for (int i = 0; i < count; i++) { Generation k = parseGeneration(buffer); @@ -100,16 +100,16 @@ return result; } - private static Generation parseGeneration(ByteBuffer buffer) { + private static Generation parseGeneration(Buffer buffer) { int generation = buffer.getInt(); return new Generation(generation, generation, true); } - private static Map> parseEntriesBySegment(ByteBuffer buffer) { + private static Map> parseEntriesBySegment(Buffer buffer) { return parseEntriesBySegment(buffer.getInt(), buffer); } - private static Map> parseEntriesBySegment(int count, ByteBuffer buffer) { + private static Map> parseEntriesBySegment(int count, Buffer buffer) { Map> result = new HashMap<>(count); for (int i = 0; i < count; i++) { UUID k = parseUUID(buffer); @@ -119,17 +119,17 @@ return result; } - private static UUID parseUUID(ByteBuffer buffer) { + private static UUID parseUUID(Buffer buffer) { long msb = buffer.getLong(); long lsb = buffer.getLong(); return new UUID(msb, lsb); } - private static Set parseEntries(ByteBuffer buffer) { + private static Set parseEntries(Buffer buffer) { return parseEntries(buffer.getInt(), buffer); } - private static Set parseEntries(int count, ByteBuffer buffer) { + private static Set parseEntries(int count, Buffer buffer) { Set entries = new HashSet<>(count); for (int i = 0; i < count; i++) { entries.add(parseString(buffer)); @@ -137,11 +137,11 @@ return entries; } - private static String parseString(ByteBuffer buffer) { + private static String parseString(Buffer buffer) { return parseString(buffer.getInt(), buffer); } - private static String parseString(int length, ByteBuffer buffer) { + private static String parseString(int length, Buffer buffer) { byte[] data = new byte[length]; buffer.get(data); return new String(data, Charsets.UTF_8); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java (working copy) @@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.segment.file.tar.binaries; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -27,6 +26,7 @@ import java.util.zip.CRC32; import com.google.common.base.Charsets; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; class BinaryReferencesIndexLoaderV2 { @@ -35,8 +35,8 @@ static final int FOOTER_SIZE = 16; - static ByteBuffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException { - ByteBuffer meta = reader.readAtEnd(FOOTER_SIZE, FOOTER_SIZE); + static Buffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException { + Buffer meta = reader.readAtEnd(FOOTER_SIZE, FOOTER_SIZE); int crc32 = meta.getInt(); int count = meta.getInt(); @@ -56,12 +56,12 @@ return reader.readAtEnd(size, size); } - public static BinaryReferencesIndex parseBinaryReferencesIndex(ByteBuffer buffer) throws InvalidBinaryReferencesIndexException { - ByteBuffer data = buffer.slice(); + public static BinaryReferencesIndex parseBinaryReferencesIndex(Buffer buffer) throws InvalidBinaryReferencesIndexException { + Buffer data = buffer.slice(); data.limit(data.limit() - FOOTER_SIZE); buffer.position(buffer.limit() - FOOTER_SIZE); - ByteBuffer meta = buffer.slice(); + Buffer meta = buffer.slice(); int crc32 = meta.getInt(); int count = meta.getInt(); @@ -80,7 +80,7 @@ CRC32 checksum = new CRC32(); data.mark(); - checksum.update(data); + data.update(checksum); data.reset(); if ((int) (checksum.getValue()) != crc32) { @@ -90,7 +90,7 @@ return new BinaryReferencesIndex(parseBinaryReferencesIndex(count, data)); } - private static Map>> parseBinaryReferencesIndex(int count, ByteBuffer buffer) { + private static Map>> parseBinaryReferencesIndex(int count, Buffer buffer) { Map>> result = new HashMap<>(count); for (int i = 0; i < count; i++) { Generation k = parseGeneration(buffer); @@ -100,18 +100,18 @@ return result; } - private static Generation parseGeneration(ByteBuffer buffer) { + private static Generation parseGeneration(Buffer buffer) { int generation = buffer.getInt(); int full = buffer.getInt(); boolean compacted = buffer.get() != 0; return new Generation(generation, full, compacted); } - private static Map> parseEntriesBySegment(ByteBuffer buffer) { + private static Map> parseEntriesBySegment(Buffer buffer) { return parseEntriesBySegment(buffer.getInt(), buffer); } - private static Map> parseEntriesBySegment(int count, ByteBuffer buffer) { + private static Map> parseEntriesBySegment(int count, Buffer buffer) { Map> result = new HashMap<>(count); for (int i = 0; i < count; i++) { UUID k = parseUUID(buffer); @@ -121,17 +121,17 @@ return result; } - private static UUID parseUUID(ByteBuffer buffer) { + private static UUID parseUUID(Buffer buffer) { long msb = buffer.getLong(); long lsb = buffer.getLong(); return new UUID(msb, lsb); } - private static Set parseEntries(ByteBuffer buffer) { + private static Set parseEntries(Buffer buffer) { return parseEntries(buffer.getInt(), buffer); } - private static Set parseEntries(int count, ByteBuffer buffer) { + private static Set parseEntries(int count, Buffer buffer) { Set entries = new HashSet<>(count); for (int i = 0; i < count; i++) { entries.add(parseString(buffer)); @@ -139,11 +139,11 @@ return entries; } - private static String parseString(ByteBuffer buffer) { + private static String parseString(Buffer buffer) { return parseString(buffer.getInt(), buffer); } - private static String parseString(int length, ByteBuffer buffer) { + private static String parseString(int length, Buffer buffer) { byte[] data = new byte[length]; buffer.get(data); return new String(data, Charsets.UTF_8); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriter.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriter.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriter.java (working copy) @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.segment.file.tar.binaries; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -27,6 +26,7 @@ import java.util.zip.CRC32; import com.google.common.base.Charsets; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; /** * Maintains the transient state of a binary references index, formats it and @@ -129,7 +129,7 @@ } } - ByteBuffer buffer = ByteBuffer.allocate(binaryReferenceSize); + Buffer buffer = Buffer.allocate(binaryReferenceSize); for (Entry>> be : entries.entrySet()) { Generation generation = be.getKey(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntryV1.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntryV1.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntryV1.java (working copy) @@ -17,17 +17,17 @@ package org.apache.jackrabbit.oak.segment.file.tar.index; -import java.nio.ByteBuffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class IndexEntryV1 implements IndexEntry { static final int SIZE = 28; - private final ByteBuffer index; + private final Buffer index; private final int position; - IndexEntryV1(ByteBuffer index, int position) { + IndexEntryV1(Buffer index, int position) { this.index = index; this.position = position; } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntryV2.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntryV2.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntryV2.java (working copy) @@ -17,17 +17,17 @@ package org.apache.jackrabbit.oak.segment.file.tar.index; -import java.nio.ByteBuffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class IndexEntryV2 implements IndexEntry { static final int SIZE = 33; - private final ByteBuffer index; + private final Buffer index; private final int position; - IndexEntryV2(ByteBuffer index, int position) { + IndexEntryV2(Buffer index, int position) { this.index = index; this.position = position; } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV1.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV1.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV1.java (working copy) @@ -17,12 +17,12 @@ package org.apache.jackrabbit.oak.segment.file.tar.index; -import static java.nio.ByteBuffer.wrap; +import static org.apache.jackrabbit.oak.segment.spi.persistence.Buffer.wrap; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.zip.CRC32; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; class IndexLoaderV1 { @@ -36,7 +36,7 @@ } IndexV1 loadIndex(ReaderAtEnd reader) throws InvalidIndexException, IOException { - ByteBuffer meta = reader.readAtEnd(IndexV1.FOOTER_SIZE, IndexV1.FOOTER_SIZE); + Buffer meta = reader.readAtEnd(IndexV1.FOOTER_SIZE, IndexV1.FOOTER_SIZE); int crc32 = meta.getInt(); int count = meta.getInt(); @@ -56,11 +56,11 @@ throw new InvalidIndexException("Invalid size alignment"); } - ByteBuffer entries = reader.readAtEnd(IndexV1.FOOTER_SIZE + count * IndexEntryV1.SIZE, count * IndexEntryV1.SIZE); + Buffer entries = reader.readAtEnd(IndexV1.FOOTER_SIZE + count * IndexEntryV1.SIZE, count * IndexEntryV1.SIZE); CRC32 checksum = new CRC32(); entries.mark(); - checksum.update(entries); + entries.update(checksum); entries.reset(); if (crc32 != (int) checksum.getValue()) { throw new InvalidIndexException("Invalid checksum"); @@ -73,7 +73,7 @@ for (int i = 0; i < count; i++) { entries.get(entry); - ByteBuffer buffer = wrap(entry); + Buffer buffer = wrap(entry); long msb = buffer.getLong(); long lsb = buffer.getLong(); int offset = buffer.getInt(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2.java (working copy) @@ -17,12 +17,12 @@ package org.apache.jackrabbit.oak.segment.file.tar.index; -import static java.nio.ByteBuffer.wrap; +import static org.apache.jackrabbit.oak.segment.spi.persistence.Buffer.wrap; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.zip.CRC32; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; class IndexLoaderV2 { @@ -36,7 +36,7 @@ } IndexV2 loadIndex(ReaderAtEnd reader) throws InvalidIndexException, IOException { - ByteBuffer meta = reader.readAtEnd(IndexV2.FOOTER_SIZE, IndexV2.FOOTER_SIZE); + Buffer meta = reader.readAtEnd(IndexV2.FOOTER_SIZE, IndexV2.FOOTER_SIZE); int crc32 = meta.getInt(); int count = meta.getInt(); @@ -56,11 +56,11 @@ throw new InvalidIndexException("Invalid size alignment"); } - ByteBuffer entries = reader.readAtEnd(IndexV2.FOOTER_SIZE + count * IndexEntryV2.SIZE, count * IndexEntryV2.SIZE); + Buffer entries = reader.readAtEnd(IndexV2.FOOTER_SIZE + count * IndexEntryV2.SIZE, count * IndexEntryV2.SIZE); CRC32 checksum = new CRC32(); entries.mark(); - checksum.update(entries); + entries.update(checksum); entries.reset(); if (crc32 != (int) checksum.getValue()) { throw new InvalidIndexException("Invalid checksum"); @@ -73,7 +73,7 @@ for (int i = 0; i < count; i++) { entries.get(entry); - ByteBuffer buffer = wrap(entry); + Buffer buffer = wrap(entry); long msb = buffer.getLong(); long lsb = buffer.getLong(); int offset = buffer.getInt(); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV1.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV1.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV1.java (working copy) @@ -20,17 +20,18 @@ import static com.google.common.base.Preconditions.checkElementIndex; import static com.google.common.collect.Sets.newHashSetWithExpectedSize; -import java.nio.ByteBuffer; import java.util.Set; import java.util.UUID; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; + class IndexV1 implements Index { static final int FOOTER_SIZE = 16; - private final ByteBuffer entries; + private final Buffer entries; - IndexV1(ByteBuffer entries) { + IndexV1(Buffer entries) { this.entries = entries; } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV2.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV2.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV2.java (working copy) @@ -20,17 +20,18 @@ import static com.google.common.base.Preconditions.checkElementIndex; import static com.google.common.collect.Sets.newHashSetWithExpectedSize; -import java.nio.ByteBuffer; import java.util.Set; import java.util.UUID; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; + class IndexV2 implements Index { static final int FOOTER_SIZE = 16; - private final ByteBuffer entries; + private final Buffer entries; - IndexV2(ByteBuffer entries) { + IndexV2(Buffer entries) { this.entries = entries; } Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexWriter.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexWriter.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexWriter.java (working copy) @@ -19,11 +19,12 @@ import static com.google.common.base.Preconditions.checkArgument; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; import java.util.zip.CRC32; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; + /** * Builds an index incrementally in memory, and serializes its contents into a * sequence of bytes. @@ -106,7 +107,7 @@ int dataSize = entries.size() * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE; int totalSize = ((dataSize + blockSize - 1) / blockSize) * blockSize; - ByteBuffer buffer = ByteBuffer.allocate(totalSize); + Buffer buffer = Buffer.allocate(totalSize); buffer.position(totalSize - dataSize); entries.sort((a, b) -> { Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/memory/MemoryStore.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/memory/MemoryStore.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/memory/MemoryStore.java (working copy) @@ -21,7 +21,6 @@ import static org.apache.jackrabbit.oak.segment.DefaultSegmentWriterBuilder.defaultSegmentWriterBuilder; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Set; import java.util.concurrent.ConcurrentMap; @@ -37,6 +36,7 @@ import org.apache.jackrabbit.oak.segment.SegmentStore; import org.apache.jackrabbit.oak.segment.SegmentTracker; import org.apache.jackrabbit.oak.segment.SegmentWriter; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.stats.NoopStats; import org.jetbrains.annotations.NotNull; @@ -113,7 +113,7 @@ @Override public void writeSegment( SegmentId id, byte[] data, int offset, int length) throws IOException { - ByteBuffer buffer = ByteBuffer.allocate(length); + Buffer buffer = Buffer.allocate(length); buffer.put(data, offset, length); buffer.rewind(); Segment segment = new Segment(tracker, segmentReader, id, buffer); Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/Buffer.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/Buffer.java (nonexistent) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/Buffer.java (working copy) @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.jackrabbit.oak.segment.spi.persistence; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileChannel.MapMode; +import java.nio.channels.WritableByteChannel; +import java.nio.charset.Charset; +import java.util.zip.CRC32; + +public class Buffer { + + private final ByteBuffer buffer; + + private Buffer(ByteBuffer buffer) { + this.buffer = buffer; + } + + public static Buffer map(FileChannel channel, MapMode mode, long position, long size) throws IOException { + return new Buffer(channel.map(mode, position, size)); + } + + public static Buffer wrap(byte[] buffer) { + return new Buffer(ByteBuffer.wrap(buffer)); + } + + public static Buffer wrap(byte[] buffer, int pos, int len) { + return new Buffer(ByteBuffer.wrap(buffer, pos, len)); + } + + public static Buffer allocate(int cap) { + return new Buffer(ByteBuffer.allocate(cap)); + } + + public static Buffer allocateDirect(int cap) { + return new Buffer(ByteBuffer.allocateDirect(cap)); + } + + public int remaining() { + return buffer.remaining(); + } + + public Buffer asReadOnlyBuffer() { + return new Buffer(buffer.asReadOnlyBuffer()); + } + + public Buffer position(int pos) { + ((java.nio.Buffer) buffer).position(pos); + return this; + } + + public int position() { + return buffer.position(); + } + + public Buffer limit(int lim) { + ((java.nio.Buffer) buffer).limit(lim); + return this; + } + + public int limit() { + return buffer.limit(); + } + + public Buffer slice() { + return new Buffer(buffer.slice()); + } + + public int readFully(FileChannel channel, int position) throws IOException { + int result = 0; + while (buffer.remaining() > 0) { + int count = channel.read(buffer, position); + if (count < 0) { + break; + } + result += count; + position += count; + } + return result; + } + + public Buffer flip() { + ((java.nio.Buffer) buffer).flip(); + return this; + } + + public int getInt() { + return buffer.getInt(); + } + + public int getInt(int pos) { + return buffer.getInt(pos); + } + + public Buffer mark() { + ((java.nio.Buffer) buffer).mark(); + return this; + } + + public Buffer get(byte[] b) { + buffer.get(b); + return this; + } + + public Buffer get(byte[] b, int pos, int len) { + buffer.get(b, pos, len); + return this; + } + + public byte get(int pos) { + return buffer.get(pos); + } + + public byte get() { + return buffer.get(); + } + + public Buffer reset() { + ((java.nio.Buffer) buffer).reset(); + return this; + } + + public void update(CRC32 checksum) { + checksum.update(buffer); + } + + public byte[] array() { + return buffer.array(); + } + + public int capacity() { + return buffer.capacity(); + } + + public boolean isDirect() { + return buffer.isDirect(); + } + + public Buffer put(byte[] b) { + buffer.put(b); + return this; + } + + public Buffer put(byte[] buf, int pos, int len) { + buffer.put(buf, pos, len); + return this; + } + + public Buffer put(byte b) { + buffer.put(b); + return this; + } + + public Buffer put(Buffer b) { + buffer.put(b.buffer); + return this; + } + + public Buffer rewind() { + ((java.nio.Buffer) buffer).rewind(); + return this; + } + + public long getLong(int pos) { + return buffer.getLong(pos); + } + + public long getLong() { + return buffer.getLong(); + } + + public short getShort(int pos) { + return buffer.getShort(pos); + } + + public Buffer duplicate() { + return new Buffer(buffer.duplicate()); + } + + public CharBuffer decode(Charset charset) { + return charset.decode(buffer); + } + + public boolean hasRemaining() { + return buffer.hasRemaining(); + } + + public int write(WritableByteChannel channel) throws IOException { + return channel.write(buffer); + } + + public Buffer putInt(int i) { + buffer.putInt(i); + return this; + } + + public Buffer putLong(long l) { + buffer.putLong(l); + return this; + } + + @Override + public int hashCode() { + return buffer.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj == this) { + return true; + } + if (obj instanceof Buffer) { + return buffer.equals(((Buffer) obj).buffer); + } + return false; + } + +} Property changes on: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/Buffer.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java (working copy) @@ -20,7 +20,6 @@ import java.io.Closeable; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.List; import org.jetbrains.annotations.NotNull; @@ -40,7 +39,7 @@ * @return byte buffer containing the segment data or null if the segment doesn't exist */ @Nullable - ByteBuffer readSegment(long msb, long lsb) throws IOException; + Buffer readSegment(long msb, long lsb) throws IOException; /** * Check if the segment exists. @@ -65,7 +64,7 @@ * persisted. */ @Nullable - ByteBuffer getGraph() throws IOException; + Buffer getGraph() throws IOException; /** * Check if the segment graph has been persisted for this archive. @@ -80,7 +79,7 @@ * @return byte buffer representing the binary references structure. */ @NotNull - ByteBuffer getBinaryReferences() throws IOException; + Buffer getBinaryReferences() throws IOException; /** * Get the current length of the archive. Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveWriter.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveWriter.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveWriter.java (working copy) @@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.segment.spi.persistence; import java.io.IOException; -import java.nio.ByteBuffer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -75,7 +74,7 @@ * @return byte buffer containing the segment data or null if segment doesn't exist */ @Nullable - ByteBuffer readSegment(long msb, long lsb) throws IOException; + Buffer readSegment(long msb, long lsb) throws IOException; /** * Check if the segment exists. Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/split/UnclosedSegmentArchiveReader.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/split/UnclosedSegmentArchiveReader.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/split/UnclosedSegmentArchiveReader.java (working copy) @@ -16,28 +16,28 @@ */ package org.apache.jackrabbit.oak.segment.split; +import java.io.IOException; +import java.util.List; + import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexWriter; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.List; - class UnclosedSegmentArchiveReader implements SegmentArchiveReader { private final SegmentArchiveReader delegate; - private static final ByteBuffer EMPTY_BINARY_REF = ByteBuffer.wrap(BinaryReferencesIndexWriter.newBinaryReferencesIndexWriter().write()).asReadOnlyBuffer(); + private static final Buffer EMPTY_BINARY_REF = Buffer.wrap(BinaryReferencesIndexWriter.newBinaryReferencesIndexWriter().write()).asReadOnlyBuffer(); UnclosedSegmentArchiveReader(SegmentArchiveReader delegate) { this.delegate = delegate; } @Override - public @Nullable ByteBuffer readSegment(long msb, long lsb) throws IOException { + public @Nullable Buffer readSegment(long msb, long lsb) throws IOException { return delegate.readSegment(msb, lsb); } @@ -52,7 +52,7 @@ } @Override - public @Nullable ByteBuffer getGraph() throws IOException { + public @Nullable Buffer getGraph() throws IOException { return delegate.getGraph(); } @@ -62,8 +62,8 @@ } @Override - public @NotNull ByteBuffer getBinaryReferences() throws IOException { - ByteBuffer buffer = delegate.getBinaryReferences(); + public @NotNull Buffer getBinaryReferences() throws IOException { + Buffer buffer = delegate.getBinaryReferences(); if (buffer == null) { return EMPTY_BINARY_REF; } else { Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/util/CharsetEncodingUtils.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/util/CharsetEncodingUtils.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/util/CharsetEncodingUtils.java (working copy) @@ -21,7 +21,6 @@ import java.nio.CharBuffer; import java.nio.charset.CharsetEncoder; import java.nio.charset.CodingErrorAction; - import java.nio.charset.StandardCharsets; /** Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/util/ReaderAtEnd.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/util/ReaderAtEnd.java (revision 1848197) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/util/ReaderAtEnd.java (working copy) @@ -18,7 +18,8 @@ package org.apache.jackrabbit.oak.segment.util; import java.io.IOException; -import java.nio.ByteBuffer; + +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; /** * Read raw data from the end of an underlying data source. The data source is @@ -34,10 +35,10 @@ * * @param whence The offset from the end of the data source. * @param amount The amount of data to read, in bytes. - * @return An instance of {@link ByteBuffer}. + * @return An instance of {@link Buffer}. * @throws IOException if an error occurs while reading from the underlying * data source. */ - ByteBuffer readAtEnd(int whence, int amount) throws IOException; + Buffer readAtEnd(int whence, int amount) throws IOException; } Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CacheWeightEstimator.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CacheWeightEstimator.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CacheWeightEstimator.java (working copy) @@ -25,7 +25,6 @@ import static org.junit.Assume.assumeTrue; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Map.Entry; import java.util.UUID; @@ -37,6 +36,7 @@ import org.apache.jackrabbit.oak.segment.CacheWeights.StringCacheWeigher; import org.apache.jackrabbit.oak.segment.file.PriorityCache; import org.apache.jackrabbit.oak.segment.memory.MemoryStore; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Before; import org.junit.Test; @@ -337,7 +337,7 @@ buffer[GC_FULL_GENERATION_OFFSET + 2] = (byte) (generation >> 8); buffer[GC_FULL_GENERATION_OFFSET + 3] = (byte) generation; - ByteBuffer data = ByteBuffer.wrap(buffer); + Buffer data = Buffer.wrap(buffer); SegmentId id = randomSegmentId(false); Segment segment = new Segment(store.getSegmentIdProvider(), store.getReader(), id, data); Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CompactorTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CompactorTest.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CompactorTest.java (working copy) @@ -32,7 +32,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; import java.util.List; import java.util.Random; @@ -42,6 +41,7 @@ import org.apache.jackrabbit.oak.segment.file.GCNodeWriteMonitor; import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException; import org.apache.jackrabbit.oak.segment.file.cancel.Canceller; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; @@ -178,6 +178,7 @@ } private static class FailingSegmentWriter implements SegmentWriter { + @NotNull private final SegmentWriter delegate; @@ -208,13 +209,12 @@ @NotNull @Override - public RecordId writeNode(@NotNull NodeState state, @Nullable ByteBuffer stableIdBytes) - throws IOException { + public RecordId writeNode(@NotNull NodeState state, @Nullable Buffer stableIdBytes) throws IOException { if (state.hasChildNode(failOnName)) { throw new IOException("Encountered node with name " + failOnName); } - return delegate.writeNode(state, stableIdBytes); } + } } Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/NodeRecordTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/NodeRecordTest.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/NodeRecordTest.java (working copy) @@ -24,13 +24,12 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; -import java.nio.ByteBuffer; - import com.google.common.base.Supplier; import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState; import org.apache.jackrabbit.oak.segment.file.FileStore; import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder; import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.junit.Rule; import org.junit.Test; @@ -88,7 +87,7 @@ } } - private static final byte[] asByteArray(ByteBuffer bytes) { + private static final byte[] asByteArray(Buffer bytes) { byte[] buffer = new byte[RecordId.SERIALIZED_RECORD_ID_BYTES]; bytes.get(buffer); return buffer; Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitorTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitorTest.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitorTest.java (working copy) @@ -27,11 +27,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.nio.ByteBuffer; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import org.apache.jackrabbit.api.stats.RepositoryStatistics; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.stats.CounterStats; import org.apache.jackrabbit.oak.stats.HistogramStats; import org.apache.jackrabbit.oak.stats.MeterStats; @@ -84,7 +84,7 @@ @Test public void heapBuffer() { - ByteBuffer buffer = ByteBuffer.allocate(42); + Buffer buffer = Buffer.allocate(42); segmentBufferMonitor.trackAllocation(buffer); assertEquals(0, stats.get(DIRECT_BUFFER_COUNT).getCount()); @@ -103,7 +103,7 @@ @Test public void directBuffer() { - ByteBuffer buffer = ByteBuffer.allocateDirect(42); + Buffer buffer = Buffer.allocateDirect(42); segmentBufferMonitor.trackAllocation(buffer); assertEquals(1, stats.get(DIRECT_BUFFER_COUNT).getCount()); Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java (working copy) @@ -28,7 +28,6 @@ import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -38,6 +37,7 @@ import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitorAdapter; import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.junit.Before; @@ -74,12 +74,12 @@ try (TarWriter writer = new TarWriter(archiveManager, "data00000a.tar")) { writer.writeEntry(msb, lsb, data, 0, data.length, generation(0)); - assertEquals(ByteBuffer.wrap(data), writer.readEntry(msb, lsb)); + assertEquals(Buffer.wrap(data), writer.readEntry(msb, lsb)); } try (TarReader reader = TarReader.open("data00000a.tar", archiveManager)) { assertEquals(getWriteAndReadExpectedSize(), reader.size()); - assertEquals(ByteBuffer.wrap(data), reader.readEntry(msb, lsb)); + assertEquals(Buffer.wrap(data), reader.readEntry(msb, lsb)); } } Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java (working copy) @@ -32,7 +32,6 @@ import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -44,6 +43,7 @@ import org.apache.jackrabbit.oak.segment.file.tar.TarFiles.CleanupResult; import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitorAdapter; import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -121,7 +121,7 @@ } private byte[] readSegment(UUID id) { - ByteBuffer buffer = tarFiles.readSegment(id.getMostSignificantBits(), id.getLeastSignificantBits()); + Buffer buffer = tarFiles.readSegment(id.getMostSignificantBits(), id.getLeastSignificantBits()); if (buffer == null) { return null; } Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderTest.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderTest.java (working copy) @@ -20,7 +20,6 @@ import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -29,6 +28,7 @@ import java.util.zip.CRC32; import com.google.common.base.Charsets; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class BinaryReferencesIndexLoaderTest { @@ -41,17 +41,17 @@ return s.getBytes(Charsets.UTF_8); } - private static int checksum(ByteBuffer buffer) { + private static int checksum(Buffer buffer) { CRC32 checksum = new CRC32(); int position = buffer.position(); - checksum.update(buffer); + buffer.update(checksum); buffer.position(position); return (int) checksum.getValue(); } - private static BinaryReferencesIndex loadIndex(ByteBuffer buffer) throws Exception { - ByteBuffer data = BinaryReferencesIndexLoader.loadBinaryReferencesIndex((whence, length) -> { - ByteBuffer slice = buffer.duplicate(); + private static BinaryReferencesIndex loadIndex(Buffer buffer) throws Exception { + Buffer data = BinaryReferencesIndexLoader.loadBinaryReferencesIndex((whence, length) -> { + Buffer slice = buffer.duplicate(); slice.position(slice.limit() - whence); slice.limit(slice.position() + length); return slice.slice(); @@ -61,7 +61,7 @@ @Test(expected = InvalidBinaryReferencesIndexException.class) public void testUnrecognizedMagicNumber() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES); + Buffer buffer = Buffer.allocate(Integer.BYTES); try { loadIndex(buffer); } catch (InvalidBinaryReferencesIndexException e) { @@ -72,7 +72,7 @@ @Test public void testLoadV1() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(512) + Buffer entries = Buffer.allocate(512) // First generation .putInt(1) .putInt(2) @@ -101,7 +101,7 @@ .putInt(length("2.2.2")).put(bytes("2.2.2")); entries.flip(); - ByteBuffer buffer = ByteBuffer.allocate(entries.remaining() + BinaryReferencesIndexLoaderV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(entries.remaining() + BinaryReferencesIndexLoaderV1.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -144,7 +144,7 @@ @Test public void testLoadV2() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(512) + Buffer entries = Buffer.allocate(512) // First generation .putInt(1).putInt(2).put((byte) 0) .putInt(2) @@ -173,7 +173,7 @@ .putInt(length("2.2.2")).put(bytes("2.2.2")); entries.flip(); - ByteBuffer buffer = ByteBuffer.allocate(entries.remaining() + BinaryReferencesIndexLoaderV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(entries.remaining() + BinaryReferencesIndexLoaderV2.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1Test.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1Test.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1Test.java (working copy) @@ -24,10 +24,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.nio.ByteBuffer; import java.util.zip.CRC32; import com.google.common.base.Charsets; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class BinaryReferencesIndexLoaderV1Test { @@ -40,9 +40,9 @@ return s.getBytes(Charsets.UTF_8); } - private static BinaryReferencesIndex loadIndex(ByteBuffer buffer) throws Exception { - ByteBuffer data = loadBinaryReferencesIndex((whence, length) -> { - ByteBuffer slice = buffer.duplicate(); + private static BinaryReferencesIndex loadIndex(Buffer buffer) throws Exception { + Buffer data = loadBinaryReferencesIndex((whence, length) -> { + Buffer slice = buffer.duplicate(); slice.position(slice.limit() - whence); slice.limit(slice.position() + length); return slice.slice(); @@ -50,7 +50,7 @@ return parseBinaryReferencesIndex(data); } - private static void assertInvalidBinaryReferencesIndexException(ByteBuffer buffer, String message) throws Exception { + private static void assertInvalidBinaryReferencesIndexException(Buffer buffer, String message) throws Exception { try { loadIndex(buffer); } catch (InvalidBinaryReferencesIndexException e) { @@ -59,23 +59,23 @@ } } - private static int checksum(ByteBuffer buffer) { + private static int checksum(Buffer buffer) { CRC32 checksum = new CRC32(); int position = buffer.position(); - checksum.update(buffer); + buffer.update(checksum); buffer.position(position); return (int) checksum.getValue(); } @Test(expected = InvalidBinaryReferencesIndexException.class) public void testInvalidMagicNumber() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(FOOTER_SIZE); + Buffer buffer = Buffer.allocate(FOOTER_SIZE); assertInvalidBinaryReferencesIndexException(buffer, "Invalid magic number"); } @Test(expected = InvalidBinaryReferencesIndexException.class) public void testInvalidCount() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(FOOTER_SIZE); + Buffer buffer = Buffer.allocate(FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(-1) @@ -86,7 +86,7 @@ @Test(expected = InvalidBinaryReferencesIndexException.class) public void testInvalidSize() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(FOOTER_SIZE); + Buffer buffer = Buffer.allocate(FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(0) @@ -97,7 +97,7 @@ @Test(expected = InvalidBinaryReferencesIndexException.class) public void testInvalidChecksum() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(512) + Buffer entries = Buffer.allocate(512) // First generation .putInt(1) .putInt(2) @@ -126,7 +126,7 @@ .putInt(length("2.2.2")).put(bytes("2.2.2")); entries.flip(); - ByteBuffer buffer = ByteBuffer.allocate(entries.remaining() + FOOTER_SIZE); + Buffer buffer = Buffer.allocate(entries.remaining() + FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries) + 1) @@ -139,7 +139,7 @@ @Test public void testParse() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(512) + Buffer entries = Buffer.allocate(512) // First generation .putInt(1) .putInt(2) @@ -168,7 +168,7 @@ .putInt(length("2.2.2")).put(bytes("2.2.2")); entries.flip(); - ByteBuffer buffer = ByteBuffer.allocate(entries.remaining() + FOOTER_SIZE); + Buffer buffer = Buffer.allocate(entries.remaining() + FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2Test.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2Test.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2Test.java (working copy) @@ -24,10 +24,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.nio.ByteBuffer; import java.util.zip.CRC32; import com.google.common.base.Charsets; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class BinaryReferencesIndexLoaderV2Test { @@ -40,9 +40,9 @@ return s.getBytes(Charsets.UTF_8); } - private static BinaryReferencesIndex loadIndex(ByteBuffer buffer) throws Exception { - ByteBuffer data = loadBinaryReferencesIndex((whence, length) -> { - ByteBuffer slice = buffer.duplicate(); + private static BinaryReferencesIndex loadIndex(Buffer buffer) throws Exception { + Buffer data = loadBinaryReferencesIndex((whence, length) -> { + Buffer slice = buffer.duplicate(); slice.position(slice.limit() - whence); slice.limit(slice.position() + length); return slice.slice(); @@ -50,7 +50,7 @@ return parseBinaryReferencesIndex(data); } - private static void assertInvalidBinaryReferencesIndexException(ByteBuffer buffer, String message) throws Exception { + private static void assertInvalidBinaryReferencesIndexException(Buffer buffer, String message) throws Exception { try { loadIndex(buffer); } catch (InvalidBinaryReferencesIndexException e) { @@ -59,23 +59,23 @@ } } - private static int checksum(ByteBuffer buffer) { + private static int checksum(Buffer buffer) { CRC32 checksum = new CRC32(); int position = buffer.position(); - checksum.update(buffer); + buffer.update(checksum); buffer.position(position); return (int) checksum.getValue(); } @Test(expected = InvalidBinaryReferencesIndexException.class) public void testInvalidMagicNumber() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(FOOTER_SIZE); + Buffer buffer = Buffer.allocate(FOOTER_SIZE); assertInvalidBinaryReferencesIndexException(buffer, "Invalid magic number"); } @Test(expected = InvalidBinaryReferencesIndexException.class) public void testInvalidCount() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(FOOTER_SIZE); + Buffer buffer = Buffer.allocate(FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(-1) @@ -86,7 +86,7 @@ @Test(expected = InvalidBinaryReferencesIndexException.class) public void testInvalidSize() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(FOOTER_SIZE); + Buffer buffer = Buffer.allocate(FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(0) @@ -97,7 +97,7 @@ @Test(expected = InvalidBinaryReferencesIndexException.class) public void testInvalidChecksum() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(512) + Buffer entries = Buffer.allocate(512) // First generation .putInt(1).putInt(2).put((byte) 0) .putInt(2) @@ -126,7 +126,7 @@ .putInt(length("2.2.2")).put(bytes("2.2.2")); entries.flip(); - ByteBuffer buffer = ByteBuffer.allocate(entries.remaining() + FOOTER_SIZE); + Buffer buffer = Buffer.allocate(entries.remaining() + FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries) + 1) @@ -139,7 +139,7 @@ @Test public void testParse() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(512) + Buffer entries = Buffer.allocate(512) // First generation .putInt(1).putInt(2).put((byte) 0) .putInt(2) @@ -168,7 +168,7 @@ .putInt(length("2.2.2")).put(bytes("2.2.2")); entries.flip(); - ByteBuffer buffer = ByteBuffer.allocate(entries.remaining() + FOOTER_SIZE); + Buffer buffer = Buffer.allocate(entries.remaining() + FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriterTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriterTest.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriterTest.java (working copy) @@ -23,13 +23,13 @@ import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexWriter.newBinaryReferencesIndexWriter; import static org.junit.Assert.assertEquals; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class BinaryReferencesIndexWriterTest { @@ -53,7 +53,7 @@ byte[] data = writer.write(); - ByteBuffer buffer = loadBinaryReferencesIndex((whence, length) -> ByteBuffer.wrap(data, data.length - whence, length)); + Buffer buffer = loadBinaryReferencesIndex((whence, length) -> Buffer.wrap(data, data.length - whence, length)); BinaryReferencesIndex index = parseBinaryReferencesIndex(buffer); Generation g1 = new Generation(1, 2, false); Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderTest.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderTest.java (working copy) @@ -21,15 +21,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.nio.ByteBuffer; - +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class IndexLoaderTest { - private static Index loadIndex(ByteBuffer buffer) throws Exception { + private static Index loadIndex(Buffer buffer) throws Exception { return newIndexLoader(1).loadIndex((whence, length) -> { - ByteBuffer slice = buffer.duplicate(); + Buffer slice = buffer.duplicate(); slice.position(slice.limit() - whence); slice.limit(slice.position() + length); return slice.slice(); @@ -48,7 +47,7 @@ @Test(expected = InvalidIndexException.class) public void testUnrecognizedMagicNumber() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE); + Buffer buffer = Buffer.allocate(Integer.SIZE); buffer.duplicate().putInt(0xDEADBEEF); try { loadIndex(buffer); @@ -60,7 +59,7 @@ @Test public void testLoadIndexV1() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5) .putLong(6).putLong(7).putInt(8).putInt(9).putInt(10) @@ -77,7 +76,7 @@ @Test public void testLoadIndexV2() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5).putInt(6).put((byte) 0) .putLong(7).putLong(8).putInt(9).putInt(10).putInt(11).putInt(12).put((byte) 1) Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV1Test.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV1Test.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV1Test.java (working copy) @@ -20,27 +20,27 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.nio.ByteBuffer; import java.util.zip.CRC32; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class IndexLoaderV1Test { - private static IndexV1 loadIndex(ByteBuffer buffer) throws Exception { + private static IndexV1 loadIndex(Buffer buffer) throws Exception { return loadIndex(1, buffer); } - private static IndexV1 loadIndex(int blockSize, ByteBuffer buffer) throws Exception { + private static IndexV1 loadIndex(int blockSize, Buffer buffer) throws Exception { return new IndexLoaderV1(blockSize).loadIndex((whence, length) -> { - ByteBuffer slice = buffer.duplicate(); + Buffer slice = buffer.duplicate(); slice.position(slice.limit() - whence); slice.limit(slice.position() + length); return slice.slice(); }); } - private static void assertInvalidIndexException(ByteBuffer buffer, String message) throws Exception { + private static void assertInvalidIndexException(Buffer buffer, String message) throws Exception { try { loadIndex(buffer); } catch (InvalidIndexException e) { @@ -49,7 +49,7 @@ } } - private static void assertInvalidIndexException(int blockSize, ByteBuffer buffer, String message) throws Exception { + private static void assertInvalidIndexException(int blockSize, Buffer buffer, String message) throws Exception { try { loadIndex(blockSize, buffer); } catch (InvalidIndexException e) { @@ -58,17 +58,17 @@ } } - private static int checksum(ByteBuffer buffer) { + private static int checksum(Buffer buffer) { CRC32 checksum = new CRC32(); int position = buffer.position(); - checksum.update(buffer); + buffer.update(checksum); buffer.position(position); return (int) checksum.getValue(); } @Test(expected = InvalidIndexException.class) public void testInvalidMagic() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexV1.FOOTER_SIZE); try { loadIndex(buffer); } catch (InvalidIndexException e) { @@ -79,7 +79,7 @@ @Test(expected = InvalidIndexException.class) public void testInvalidCount() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexV1.FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(0) @@ -90,7 +90,7 @@ @Test(expected = InvalidIndexException.class) public void testInvalidSize() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexV1.FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(1) @@ -101,7 +101,7 @@ @Test(expected = InvalidIndexException.class) public void testInvalidSizeAlignment() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexV1.FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(1) @@ -112,7 +112,7 @@ @Test(expected = InvalidIndexException.class) public void testInvalidChecksum() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5) .putInt(0) @@ -124,12 +124,12 @@ @Test(expected = InvalidIndexException.class) public void testIncorrectEntryOrderingByMsb() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(2 * IndexEntryV1.SIZE); + Buffer entries = Buffer.allocate(2 * IndexEntryV1.SIZE); entries.duplicate() .putLong(1).putLong(0).putInt(0).putInt(1).putInt(0) .putLong(0).putLong(0).putInt(1).putInt(1).putInt(0); - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -142,12 +142,12 @@ @Test(expected = InvalidIndexException.class) public void testIncorrectEntryOrderingByLsb() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(2 * IndexEntryV1.SIZE); + Buffer entries = Buffer.allocate(2 * IndexEntryV1.SIZE); entries.duplicate() .putLong(0).putLong(1).putInt(0).putInt(1).putInt(0) .putLong(0).putLong(0).putInt(1).putInt(1).putInt(0); - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -160,12 +160,12 @@ @Test(expected = InvalidIndexException.class) public void testDuplicateEntry() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(2 * IndexEntryV1.SIZE); + Buffer entries = Buffer.allocate(2 * IndexEntryV1.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(0).putInt(1).putInt(0) .putLong(0).putLong(0).putInt(1).putInt(1).putInt(0); - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -178,11 +178,11 @@ @Test(expected = InvalidIndexException.class) public void testInvalidEntryOffset() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(IndexEntryV1.SIZE); + Buffer entries = Buffer.allocate(IndexEntryV1.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(-1).putInt(1).putInt(0); - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -195,11 +195,11 @@ @Test(expected = InvalidIndexException.class) public void testInvalidEntryOffsetAlignment() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(IndexEntryV1.SIZE); + Buffer entries = Buffer.allocate(IndexEntryV1.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(1).putInt(1).putInt(0); - ByteBuffer index = ByteBuffer.allocate(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer index = Buffer.allocate(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); index.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -207,7 +207,7 @@ .putInt(2 * (IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE)) .putInt(IndexLoaderV1.MAGIC); - ByteBuffer buffer = ByteBuffer.allocate(2 * (IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE)); + Buffer buffer = Buffer.allocate(2 * (IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE)); buffer.mark(); buffer.position(buffer.limit() - IndexEntryV1.SIZE - IndexV1.FOOTER_SIZE); buffer.put(index); @@ -218,11 +218,11 @@ @Test(expected = InvalidIndexException.class) public void testInvalidEntrySize() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(IndexEntryV1.SIZE); + Buffer entries = Buffer.allocate(IndexEntryV1.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(0).putInt(0).putInt(0); - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -235,12 +235,12 @@ @Test public void testLoadIndex() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(2 * IndexEntryV1.SIZE); + Buffer entries = Buffer.allocate(2 * IndexEntryV1.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(0).putInt(1).putInt(0) .putLong(0).putLong(1).putInt(1).putInt(1).putInt(0); - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2Test.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2Test.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2Test.java (working copy) @@ -20,27 +20,27 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.nio.ByteBuffer; import java.util.zip.CRC32; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class IndexLoaderV2Test { - private static IndexV2 loadIndex(ByteBuffer buffer) throws Exception { + private static IndexV2 loadIndex(Buffer buffer) throws Exception { return loadIndex(1, buffer); } - private static IndexV2 loadIndex(int blockSize, ByteBuffer buffer) throws Exception { + private static IndexV2 loadIndex(int blockSize, Buffer buffer) throws Exception { return new IndexLoaderV2(blockSize).loadIndex((whence, length) -> { - ByteBuffer slice = buffer.duplicate(); + Buffer slice = buffer.duplicate(); slice.position(slice.limit() - whence); slice.limit(slice.position() + length); return slice.slice(); }); } - private static void assertInvalidIndexException(ByteBuffer buffer, String message) throws Exception { + private static void assertInvalidIndexException(Buffer buffer, String message) throws Exception { try { loadIndex(buffer); } catch (InvalidIndexException e) { @@ -49,7 +49,7 @@ } } - private static void assertInvalidIndexException(int blockSize, ByteBuffer buffer, String message) throws Exception { + private static void assertInvalidIndexException(int blockSize, Buffer buffer, String message) throws Exception { try { loadIndex(blockSize, buffer); } catch (InvalidIndexException e) { @@ -58,23 +58,23 @@ } } - private static int checksum(ByteBuffer buffer) { + private static int checksum(Buffer buffer) { CRC32 checksum = new CRC32(); int position = buffer.position(); - checksum.update(buffer); + buffer.update(checksum); buffer.position(position); return (int) checksum.getValue(); } @Test(expected = InvalidIndexException.class) public void testInvalidMagic() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexV2.FOOTER_SIZE); assertInvalidIndexException(buffer, "Magic number mismatch"); } @Test(expected = InvalidIndexException.class) public void testInvalidCount() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexV2.FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(0) @@ -85,7 +85,7 @@ @Test(expected = InvalidIndexException.class) public void testInvalidSize() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexV2.FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(1) @@ -96,7 +96,7 @@ @Test(expected = InvalidIndexException.class) public void testInvalidSizeAlignment() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexV2.FOOTER_SIZE); buffer.duplicate() .putInt(0) .putInt(1) @@ -107,7 +107,7 @@ @Test(expected = InvalidIndexException.class) public void testInvalidChecksum() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5).putInt(6).put((byte) 0) .putInt(0) @@ -119,12 +119,12 @@ @Test(expected = InvalidIndexException.class) public void testIncorrectEntryOrderingByMsb() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(2 * IndexEntryV2.SIZE); + Buffer entries = Buffer.allocate(2 * IndexEntryV2.SIZE); entries.duplicate() .putLong(1).putLong(0).putInt(0).putInt(1).putInt(0).putInt(0).put((byte) 0) .putLong(0).putLong(0).putInt(1).putInt(1).putInt(0).putInt(0).put((byte) 0); - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -137,12 +137,12 @@ @Test(expected = InvalidIndexException.class) public void testIncorrectEntryOrderingByLsb() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(2 * IndexEntryV2.SIZE); + Buffer entries = Buffer.allocate(2 * IndexEntryV2.SIZE); entries.duplicate() .putLong(0).putLong(1).putInt(0).putInt(1).putInt(0).putInt(0).put((byte) 0) .putLong(0).putLong(0).putInt(1).putInt(1).putInt(0).putInt(0).put((byte) 0); - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -155,12 +155,12 @@ @Test(expected = InvalidIndexException.class) public void testDuplicateEntry() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(2 * IndexEntryV2.SIZE); + Buffer entries = Buffer.allocate(2 * IndexEntryV2.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(0).putInt(1).putInt(0).putInt(0).put((byte) 0) .putLong(0).putLong(0).putInt(1).putInt(1).putInt(0).putInt(0).put((byte) 0); - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -173,11 +173,11 @@ @Test(expected = InvalidIndexException.class) public void testInvalidEntryOffset() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(IndexEntryV2.SIZE); + Buffer entries = Buffer.allocate(IndexEntryV2.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(-1).putInt(1).putInt(0).putInt(0).put((byte) 0); - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -190,11 +190,11 @@ @Test(expected = InvalidIndexException.class) public void testInvalidEntryOffsetAlignment() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(IndexEntryV2.SIZE); + Buffer entries = Buffer.allocate(IndexEntryV2.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(1).putInt(1).putInt(0).putInt(0).put((byte) 0); - ByteBuffer index = ByteBuffer.allocate(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer index = Buffer.allocate(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); index.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -202,7 +202,7 @@ .putInt(2 * (IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE)) .putInt(IndexLoaderV2.MAGIC); - ByteBuffer buffer = ByteBuffer.allocate(2 * (IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE)); + Buffer buffer = Buffer.allocate(2 * (IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE)); buffer.mark(); buffer.position(buffer.limit() - IndexEntryV2.SIZE - IndexV2.FOOTER_SIZE); buffer.put(index); @@ -213,11 +213,11 @@ @Test(expected = InvalidIndexException.class) public void testInvalidEntrySize() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(IndexEntryV2.SIZE); + Buffer entries = Buffer.allocate(IndexEntryV2.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(0).putInt(0).putInt(0).putInt(0).put((byte) 0); - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) @@ -230,12 +230,12 @@ @Test public void testLoadIndex() throws Exception { - ByteBuffer entries = ByteBuffer.allocate(2 * IndexEntryV2.SIZE); + Buffer entries = Buffer.allocate(2 * IndexEntryV2.SIZE); entries.duplicate() .putLong(0).putLong(0).putInt(0).putInt(1).putInt(0).putInt(0).put((byte) 0) .putLong(0).putLong(1).putInt(1).putInt(1).putInt(0).putInt(0).put((byte) 0); - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE); buffer.duplicate() .put(entries.duplicate()) .putInt(checksum(entries)) Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV1Test.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV1Test.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV1Test.java (working copy) @@ -19,18 +19,18 @@ import static org.junit.Assert.assertEquals; -import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class IndexV1Test { @Test public void testGetUUIDs() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV1.SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV1.SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5) .putLong(6).putLong(7).putInt(8).putInt(9).putInt(10); @@ -42,7 +42,7 @@ @Test public void testFindEntry() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(4 * IndexEntryV1.SIZE); + Buffer buffer = Buffer.allocate(4 * IndexEntryV1.SIZE); buffer.duplicate() .putLong(1).putLong(1).putInt(0).putInt(0).putInt(0) .putLong(1).putLong(3).putInt(0).putInt(0).putInt(0) @@ -61,7 +61,7 @@ @Test public void testSize() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV1.SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV1.SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5); assertEquals(IndexEntryV1.SIZE + IndexV1.FOOTER_SIZE, new IndexV1(buffer).size()); @@ -69,7 +69,7 @@ @Test public void testCount() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV1.SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV1.SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5) .putLong(6).putLong(7).putInt(8).putInt(9).putInt(10); @@ -78,7 +78,7 @@ @Test public void testEntry() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV1.SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV1.SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5); IndexEntryV1 entry = new IndexV1(buffer).entry(0); Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV2Test.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV2Test.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV2Test.java (working copy) @@ -19,18 +19,18 @@ import static org.junit.Assert.assertEquals; -import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.junit.Test; public class IndexV2Test { @Test public void testGetUUIDs() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV2.SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV2.SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5).putInt(6).put((byte) 0) .putLong(7).putLong(8).putInt(9).putInt(10).putInt(11).putInt(12).put((byte) 1); @@ -42,7 +42,7 @@ @Test public void testFindEntry() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(4 * IndexEntryV2.SIZE); + Buffer buffer = Buffer.allocate(4 * IndexEntryV2.SIZE); buffer.duplicate() .putLong(1).putLong(1).putInt(0).putInt(0).putInt(0).putInt(0).put((byte) 0) .putLong(1).putLong(3).putInt(0).putInt(0).putInt(0).putInt(0).put((byte) 0) @@ -61,7 +61,7 @@ @Test public void testSize() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV2.SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV2.SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5).putInt(6).put((byte) 0); assertEquals(IndexEntryV2.SIZE + IndexV2.FOOTER_SIZE, new IndexV2(buffer).size()); @@ -69,7 +69,7 @@ @Test public void testCount() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(2 * IndexEntryV2.SIZE); + Buffer buffer = Buffer.allocate(2 * IndexEntryV2.SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5).putInt(6).put((byte) 0) .putLong(7).putLong(8).putInt(9).putInt(10).putInt(11).putInt(12).put((byte) 1); @@ -78,7 +78,7 @@ @Test public void testEntry() throws Exception { - ByteBuffer buffer = ByteBuffer.allocate(IndexEntryV2.SIZE); + Buffer buffer = Buffer.allocate(IndexEntryV2.SIZE); buffer.duplicate() .putLong(1).putLong(2).putInt(3).putInt(4).putInt(5).putInt(6).put((byte) 1); IndexEntryV2 entry = new IndexV2(buffer).entry(0); Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/StandbyTestUtils.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/StandbyTestUtils.java (revision 1848197) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/StandbyTestUtils.java (working copy) @@ -19,7 +19,6 @@ import static org.mockito.Mockito.mock; -import java.nio.ByteBuffer; import java.util.UUID; import com.google.common.base.Charsets; @@ -32,6 +31,7 @@ import org.apache.jackrabbit.oak.segment.SegmentIdProvider; import org.apache.jackrabbit.oak.segment.SegmentReader; import org.apache.jackrabbit.oak.segment.SegmentStore; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; public class StandbyTestUtils { @@ -50,7 +50,7 @@ long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); SegmentId id = new SegmentId(store, msb, lsb); - ByteBuffer data = ByteBuffer.wrap(buffer); + Buffer data = Buffer.wrap(buffer); return new Segment(idProvider, reader, id, data); } Index: oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/PersistingDiff.java =================================================================== --- oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/PersistingDiff.java (revision 1848197) +++ oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/PersistingDiff.java (working copy) @@ -16,6 +16,15 @@ */ package org.apache.jackrabbit.oak.upgrade; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + import com.google.common.collect.Lists; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder; @@ -24,6 +33,7 @@ import org.apache.jackrabbit.oak.segment.SegmentReader; import org.apache.jackrabbit.oak.segment.SegmentWriter; import org.apache.jackrabbit.oak.segment.file.FileStore; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStateDiff; @@ -32,15 +42,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; - public class PersistingDiff implements NodeStateDiff { private static final Logger LOG = LoggerFactory.getLogger(PersistingDiff.class); @@ -214,7 +215,7 @@ } @Nullable - private static ByteBuffer getStableIdBytes(NodeState state) { + private static Buffer getStableIdBytes(NodeState state) { if (state instanceof SegmentNodeState) { return ((SegmentNodeState) state).getStableIdBytes(); } else {