Added openflow-codec and openflowj_netty from openflowplugin
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / io / DataBuffers.java
diff --git a/third-party/openflow-codec/src/main/java/org/openflow/codec/io/DataBuffers.java b/third-party/openflow-codec/src/main/java/org/openflow/codec/io/DataBuffers.java
new file mode 100644 (file)
index 0000000..38bbc74
--- /dev/null
@@ -0,0 +1,39 @@
+package org.openflow.codec.io;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Creates a new IDataBuffer by allocating new space. DataBuffers is responsible
+ * to create buffer class that will used by test cases. currently it instantiate
+ * ByteDataBuffer (java's ByteBuffer) but it can be updated to support other
+ * data buffer in future.
+ *
+ * @author AnilGujele
+ *
+ */
+public final class DataBuffers {
+    /**
+     * private constructor to protect instantiation
+     */
+    private DataBuffers() {
+
+    }
+
+    /**
+     * get a new data buffer.
+     *
+     * @param capacity
+     *            The new buffer's capacity, in bytes
+     *
+     * @return The new data buffer
+     *
+     * @throws IllegalArgumentException
+     *             If the <tt>capacity</tt> is a negative integer
+     */
+    public static IDataBuffer allocate(int capacity) {
+
+        ByteBuffer bytebuffer = ByteBuffer.allocateDirect(capacity);
+        ByteDataBuffer dataBuffer = new ByteDataBuffer(bytebuffer);
+        return dataBuffer;
+    }
+}