MNEMONIC-501: Create sync() methods in ChunkBuffer that accepts offset and length
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/ChunkBuffer.java b/mnemonic-core/src/main/java/org/apache/mnemonic/ChunkBuffer.java
index 6d79943..a97bd99 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/ChunkBuffer.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/ChunkBuffer.java
@@ -73,13 +73,34 @@
       alloc.syncToNonVolatileMemory(m_dchunk.get() + m_offset, m_size, false);
     } else {
       throw new UnsupportedOperationException("The ChunkBuffer does not backed by a non-volatile allocator");
-      }
     }
+  }
+
+  public void syncToNonVolatileMemory(long offset, int length) {
+    if (offset < 0 || length < 0 || offset + length > this.m_size) {
+      throw new OutOfBoundsException("The requested offset and length are out of bounds for this buffer: length = "
+          + length + " , offset = " + offset);
+    }
+    if (m_dchunk.getAllocator() instanceof NonVolatileMemAllocator) {
+      NonVolatileMemAllocator alloc = (NonVolatileMemAllocator) m_dchunk.getAllocator();
+      alloc.syncToNonVolatileMemory(m_dchunk.get() + m_offset + offset, length, false);
+    } else {
+      throw new UnsupportedOperationException("The ChunkBuffer does not backed by a non-volatile allocator");
+    }
+  }
 
   public void syncToVolatileMemory() {
     m_dchunk.getAllocator().syncToVolatileMemory(m_dchunk.get() + m_offset, m_size, false);
   }
 
+  public void syncToVolatileMemory(long offset, int length) {
+    if (offset < 0 || length < 0 || offset + length > this.m_size) {
+      throw new OutOfBoundsException("The requested offset and length are out of bounds for this buffer: length = "
+          + length + " , offset = " + offset);
+    }
+    m_dchunk.getAllocator().syncToVolatileMemory(m_dchunk.get() + m_offset + offset, length, false);
+  }
+
   public void syncToLocal() {
     if (m_dchunk.getAllocator() instanceof NonVolatileMemAllocator) {
       NonVolatileMemAllocator alloc = (NonVolatileMemAllocator) m_dchunk.getAllocator();
@@ -89,5 +110,18 @@
     }
   }
 
+  public void syncToLocal(long offset, int length) {
+    if (offset < 0 || length < 0 || offset + length > this.m_size) {
+      throw new OutOfBoundsException("The requested offset and length are out of bounds for this buffer: length = "
+          + length + " , offset = " + offset);
+    }
+    if (m_dchunk.getAllocator() instanceof NonVolatileMemAllocator) {
+      NonVolatileMemAllocator alloc = (NonVolatileMemAllocator) m_dchunk.getAllocator();
+      alloc.syncToLocal(m_dchunk.get() + m_offset + offset, length, false);
+    } else {
+      throw new UnsupportedOperationException("The ChunkBuffer does not backed by a non-volatile allocator");
+    }
+  }
+
 }