38bbc74551635d2f71057b59bae9cec7df59cf3e
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / io / DataBuffers.java
1 package org.openflow.codec.io;
2
3 import java.nio.ByteBuffer;
4
5 /**
6  * Creates a new IDataBuffer by allocating new space. DataBuffers is responsible
7  * to create buffer class that will used by test cases. currently it instantiate
8  * ByteDataBuffer (java's ByteBuffer) but it can be updated to support other
9  * data buffer in future.
10  *
11  * @author AnilGujele
12  *
13  */
14 public final class DataBuffers {
15     /**
16      * private constructor to protect instantiation
17      */
18     private DataBuffers() {
19
20     }
21
22     /**
23      * get a new data buffer.
24      *
25      * @param capacity
26      *            The new buffer's capacity, in bytes
27      *
28      * @return The new data buffer
29      *
30      * @throws IllegalArgumentException
31      *             If the <tt>capacity</tt> is a negative integer
32      */
33     public static IDataBuffer allocate(int capacity) {
34
35         ByteBuffer bytebuffer = ByteBuffer.allocateDirect(capacity);
36         ByteDataBuffer dataBuffer = new ByteDataBuffer(bytebuffer);
37         return dataBuffer;
38     }
39 }