// 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;
package jocket.impl;



public class DefaultAccessor implements ByteBufferAccessor {

  private final ByteBuffer buf;

  public DefaultAccessor(ByteBuffer buf) {
    this.buf = buf;
  }

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

  public int getInt(int pos) {
    return buf.getInt(pos);
  }

  public int capacity() {
    return buf.capacity();
  }

  public byte get(int pos) {
    return buf.get(pos);
  }

  public void put(int pos, byte val) {
// 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;

package jocket.impl;



public class DefaultAccessor implements ByteBufferAccessor {

  private final ByteBuffer buf;

  public DefaultAccessor(ByteBuffer buf) {
    this.buf = buf;
  }

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

  public int getInt(int pos) {
    return buf.getInt(pos);
  }

  public int capacity() {
    return buf.capacity();
  }

  public byte get(int pos) {
    return buf.get(pos);
  }

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