// Path: src/main/java/com/yahoo/memory4/AllocateDirectWritableMap.java
// static final void checkOffsetAndCapacity(final long offset, final long capacity) {
//   if (((offset) | (capacity - 1L) | (offset + capacity)) < 0) {
//     throw new IllegalArgumentException(
//         "offset: " + offset + ", capacity: " + capacity
//         + ", offset + capacity: " + (offset + capacity));
//   }
// }
// 
// Path: src/main/java/com/yahoo/memory4/ResourceHandler.java
// enum ResourceType { MEMORY_MAPPED_FILE, NATIVE_MEMORY }


import static com.yahoo.memory4.AllocateDirectWritableMap.checkOffsetAndCapacity;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import org.testng.annotations.Test;
import com.yahoo.memory4.ResourceHandler.ResourceType;
  public void simpleMap2() throws Exception {
    File file = new File(getClass().getClassLoader().getResource("GettysburgAddress.txt").getFile());
    try (WritableResourceHandler rh = WritableMemory.map(file)) {
      rh.close();
    }
  }

  @Test
  public void testForce() throws Exception {
    String origStr = "Corectng spellng mistks";
    File origFile = createFile("force_original.txt", origStr); //23
    origFile.setWritable(true, false);
    long origBytes = origFile.length();
    String correctStr = "Correcting spelling mistakes"; //28
    byte[] correctByteArr = correctStr.getBytes(UTF_8);
    long corrBytes = correctByteArr.length;

    try (ResourceHandler rh = Memory.map(origFile, 0, origBytes)) {
      Memory map = rh.get();
      rh.load();
      assertTrue(rh.isLoaded());
      //confirm orig string
      byte[] buf = new byte[(int)origBytes];
      map.getByteArray(0, buf, 0, (int)origBytes);
      String bufStr = new String(buf, UTF_8);
      assertEquals(bufStr, origStr);
    }

    try (WritableResourceHandler wrh = WritableMemory.map(origFile, 0, corrBytes)) { //longer
      WritableMemory wMap = wrh.get();
// Path: src/main/java/com/yahoo/memory4/AllocateDirectWritableMap.java
// static final void checkOffsetAndCapacity(final long offset, final long capacity) {
//   if (((offset) | (capacity - 1L) | (offset + capacity)) < 0) {
//     throw new IllegalArgumentException(
//         "offset: " + offset + ", capacity: " + capacity
//         + ", offset + capacity: " + (offset + capacity));
//   }
// }
// 
// Path: src/main/java/com/yahoo/memory4/ResourceHandler.java
// enum ResourceType { MEMORY_MAPPED_FILE, NATIVE_MEMORY }


// Path: src/test/java/com/yahoo/memory4/AllocateDirectWritableMapTest.java
import static com.yahoo.memory4.AllocateDirectWritableMap.checkOffsetAndCapacity;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import org.testng.annotations.Test;
import com.yahoo.memory4.ResourceHandler.ResourceType;

  public void simpleMap2() throws Exception {
    File file = new File(getClass().getClassLoader().getResource("GettysburgAddress.txt").getFile());
    try (WritableResourceHandler rh = WritableMemory.map(file)) {
      rh.close();
    }
  }

  @Test
  public void testForce() throws Exception {
    String origStr = "Corectng spellng mistks";
    File origFile = createFile("force_original.txt", origStr); //23
    origFile.setWritable(true, false);
    long origBytes = origFile.length();
    String correctStr = "Correcting spelling mistakes"; //28
    byte[] correctByteArr = correctStr.getBytes(UTF_8);
    long corrBytes = correctByteArr.length;

    try (ResourceHandler rh = Memory.map(origFile, 0, origBytes)) {
      Memory map = rh.get();
      rh.load();
      assertTrue(rh.isLoaded());
      //confirm orig string
      byte[] buf = new byte[(int)origBytes];
      map.getByteArray(0, buf, 0, (int)origBytes);
      String bufStr = new String(buf, UTF_8);
      assertEquals(bufStr, origStr);
    }

    try (WritableResourceHandler wrh = WritableMemory.map(origFile, 0, corrBytes)) { //longer
      WritableMemory wMap = wrh.get();
      ResourceType type = wrh.getResourceType();