// Path: src/main/java/jocket/net/JocketFile.java
// public class JocketFile implements Const {
// 
//   private final MappedByteBuffer buf;
// 
//   private final RandomAccessFile io;
// 
//   private final JocketReader reader;
// 
//   private final JocketWriter writer;
// 
//   private final File file;
// 
//   /**
//    * Creates a new exchange file and associated reader and writer.
//    */
//   public JocketFile(int maxPackets, int capacity) throws IOException {
//     this(createTempFile(), true, maxPackets, capacity);
//   }
// 
//   /**
//    * Opens and wrap specified exchange file with a reader and writer.
//    */
//   public JocketFile(File file) throws IOException {
//     this(file, false, -1, -1);
//   }
// 
//   private JocketFile(File file, boolean create, int maxPackets, int capacity) throws IOException {
//     if (!create && !file.exists())
//       throw new FileNotFoundException("File does not exist");
// 
//     this.file = file;
//     this.io = new RandomAccessFile(file, "rw");
// 
//     if (create) {
//       int size = capacity + PACKET_INFO + maxPackets * LEN_PACKET_INFO;
//       io.setLength(0);
// 
//       // append data instead of just setting the size: in case we are using
//       // a real filesystem, this could avoid getting a fragmented file
//       // (or not)
//       for (int i = 0; i < size; i += 1024) {
//         io.write(new byte[1024]);
//       }
//       io.setLength(size);
//     }
// 
//     FileChannel channel = io.getChannel();
//     buf = channel.map(MapMode.READ_WRITE, 0, io.length());
//     buf.order(ByteOrder.nativeOrder());
//     buf.load();
//     channel.close();
// 
//     if (create) {
//       buf.putInt(META_MAX_PACKETS, maxPackets);
//       buf.putInt(META_CAPACITY, capacity);
//       buf.force();
//     }
//     else {
//       maxPackets = buf.getInt(META_MAX_PACKETS);
//     }
// 
//     reader = new JocketReader(buf, maxPackets);
//     writer = new JocketWriter(buf, maxPackets);
// 
//     file.deleteOnExit();
//   }
// 
//   public JocketReader reader() {
//     return reader;
//   }
// 
//   public JocketWriter writer() {
//     return writer;
//   }
// 
//   public String getPath() {
//     return file.getAbsolutePath();
//   }
// 
//   /**
//    * Deletes the file to make it harder to sniff stream. Can be called (at
//    * least under linux) after both endpoints have opened the file.
//    */
//   public void deleteFile() {
//     file.delete();
//   }
// 
//   private static File createTempFile() throws IOException {
//     try {
//       // under linux, try to use tmpfs
//       File dir = new File("/dev/shm");
//       if (dir.exists()) {
//         File file =
//           new File(dir, "jocket-" + new Random().nextInt(Integer.MAX_VALUE));
//         new FileOutputStream(file).close();
//         return file;
//       }
//     }
//     catch (Exception ex) {
//     }
//     System.err.println("Could not create file in /dev/shm");
//     return File.createTempFile("jocket", "");
//   }
// 
//   public MappedByteBuffer getBuffer() {
//     return buf;
//   }
// 
//   public static void unmap(MappedByteBuffer buffer)
//   {
//     sun.misc.Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
//     cleaner.clean();
//   }
// }


import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import jocket.net.JocketFile;
    return buf.get(pos);
  }

  public void put(int pos, byte val) {
    buf.put(pos, val);
  }

  public void position(int pos) {
    buf.position(pos);
  }

  public void put(byte[] data, int off, int bytes) {
    buf.put(data, off, bytes);
  }

  public void get(byte[] data, int off, int available) {
    buf.get(data, off, available);
  }

  public ByteBuffer getBuffer() {
    return buf;
  }

  public void limit(int limit) {
    buf.limit(limit);
  }

  @Override
  public void unmap() {
    if (buf instanceof MappedByteBuffer)
// Path: src/main/java/jocket/net/JocketFile.java
// public class JocketFile implements Const {
// 
//   private final MappedByteBuffer buf;
// 
//   private final RandomAccessFile io;
// 
//   private final JocketReader reader;
// 
//   private final JocketWriter writer;
// 
//   private final File file;
// 
//   /**
//    * Creates a new exchange file and associated reader and writer.
//    */
//   public JocketFile(int maxPackets, int capacity) throws IOException {
//     this(createTempFile(), true, maxPackets, capacity);
//   }
// 
//   /**
//    * Opens and wrap specified exchange file with a reader and writer.
//    */
//   public JocketFile(File file) throws IOException {
//     this(file, false, -1, -1);
//   }
// 
//   private JocketFile(File file, boolean create, int maxPackets, int capacity) throws IOException {
//     if (!create && !file.exists())
//       throw new FileNotFoundException("File does not exist");
// 
//     this.file = file;
//     this.io = new RandomAccessFile(file, "rw");
// 
//     if (create) {
//       int size = capacity + PACKET_INFO + maxPackets * LEN_PACKET_INFO;
//       io.setLength(0);
// 
//       // append data instead of just setting the size: in case we are using
//       // a real filesystem, this could avoid getting a fragmented file
//       // (or not)
//       for (int i = 0; i < size; i += 1024) {
//         io.write(new byte[1024]);
//       }
//       io.setLength(size);
//     }
// 
//     FileChannel channel = io.getChannel();
//     buf = channel.map(MapMode.READ_WRITE, 0, io.length());
//     buf.order(ByteOrder.nativeOrder());
//     buf.load();
//     channel.close();
// 
//     if (create) {
//       buf.putInt(META_MAX_PACKETS, maxPackets);
//       buf.putInt(META_CAPACITY, capacity);
//       buf.force();
//     }
//     else {
//       maxPackets = buf.getInt(META_MAX_PACKETS);
//     }
// 
//     reader = new JocketReader(buf, maxPackets);
//     writer = new JocketWriter(buf, maxPackets);
// 
//     file.deleteOnExit();
//   }
// 
//   public JocketReader reader() {
//     return reader;
//   }
// 
//   public JocketWriter writer() {
//     return writer;
//   }
// 
//   public String getPath() {
//     return file.getAbsolutePath();
//   }
// 
//   /**
//    * Deletes the file to make it harder to sniff stream. Can be called (at
//    * least under linux) after both endpoints have opened the file.
//    */
//   public void deleteFile() {
//     file.delete();
//   }
// 
//   private static File createTempFile() throws IOException {
//     try {
//       // under linux, try to use tmpfs
//       File dir = new File("/dev/shm");
//       if (dir.exists()) {
//         File file =
//           new File(dir, "jocket-" + new Random().nextInt(Integer.MAX_VALUE));
//         new FileOutputStream(file).close();
//         return file;
//       }
//     }
//     catch (Exception ex) {
//     }
//     System.err.println("Could not create file in /dev/shm");
//     return File.createTempFile("jocket", "");
//   }
// 
//   public MappedByteBuffer getBuffer() {
//     return buf;
//   }
// 
//   public static void unmap(MappedByteBuffer buffer)
//   {
//     sun.misc.Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
//     cleaner.clean();
//   }
// }


// Path: src/main/java/jocket/impl/DefaultAccessor.java
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import jocket.net.JocketFile;

    return buf.get(pos);
  }

  public void put(int pos, byte val) {
    buf.put(pos, val);
  }

  public void position(int pos) {
    buf.position(pos);
  }

  public void put(byte[] data, int off, int bytes) {
    buf.put(data, off, bytes);
  }

  public void get(byte[] data, int off, int available) {
    buf.get(data, off, available);
  }

  public ByteBuffer getBuffer() {
    return buf;
  }

  public void limit(int limit) {
    buf.limit(limit);
  }

  @Override
  public void unmap() {
    if (buf instanceof MappedByteBuffer)
      JocketFile.unmap((MappedByteBuffer) buf);