NIOJICPConnection connection;
private static Logger log = Logger.getLogger(NIOHTTPHelper.class.getName());
public static ByteBuffer readByteBufferFromHttp(InputStream is) throws IOException {
HTTPRequest request = new HTTPRequest();
request.readFrom(is);
if (is.markSupported()) {
is.mark(2);
if (is.read() != -1) {
is.reset();
throw new IOException("bytes left in stream after constructing HTTPRequest");
}
}
if (request.getMethod().equals("GET")) {
String recipientID = request.getField(RECIPIENT_ID_FIELD);
JICPPacket pkt = new JICPPacket(JICPProtocol.CONNECT_MEDIATOR_TYPE, JICPProtocol.DEFAULT_INFO, recipientID, null);
ByteBuffer b = ByteBuffer.allocateDirect(pkt.getLength());
MyOut out = new MyOut(b);
pkt.writeTo(out);
b.flip();
return b;
} else {
// Read the JICPPacket from the HTTP request payload
byte[] a = request.getPayload();
ByteBuffer b = ByteBuffer.allocateDirect(a.length);
MyOut out = new MyOut(b);
out.write(a, 0, a.length);
b.flip();
return b;