allocate() публичный статический Метод

public static allocate ( int capacity ) : ByteBuffer
capacity int
Результат ByteBuffer
Пример #1
0
        protected ByteBuffer readResponse(int expected)
        {
            ByteBuffer def = ByteBuffer.allocate(8);

            def.order(myOrder);
            readAll(def);
            def.rewind();
            if (def.length() == 0)
            {
                errorReturned = BUFFER_READ_ERROR;
                throw new IOException("Error reading from the buffer server.");
            }

            short version   = def.getShort();
            short _expected = def.getShort();

            if (version != VERSION)
            {
                errorReturned = VERSION_ERROR;
                throw new IOException("Invalid VERSION returned.");
            }
            else if (_expected != expected)
            {
                errorReturned = BUFFER_READ_ERROR;
                //throw new IOException("Error returned from FieldTrip buffer server.");
            }
            else
            {
                errorReturned = NO_ERROR;
            }

            int size = def.getInt();

            ByteBuffer buf = ByteBuffer.allocate(size);

            buf.order(myOrder);
            readAll(buf);
            buf.rewind();
            return(buf);
        }
Пример #2
0
        public void putEvents(BufferEvent[] e)
        {
            ByteBuffer buf;
            int        bufsize = 0;

            for (int i = 0; i < e.Length; i++)
            {
                bufsize += e[i].size();
            }

            buf = ByteBuffer.allocate(8 + bufsize);
            buf.order(myOrder);

            buf.putShort(VERSION).putShort(PUT_EVT).putInt(bufsize);
            for (int i = 0; i < e.Length; i++)
            {
                e[i].serialize(buf);
            }
            buf.rewind();
            writeAll(buf);
            readResponse(PUT_OK);
        }
Пример #3
0
        public Header getHeader()
        {
            ByteBuffer buf;

            buf = ByteBuffer.allocate(8);
            buf.order(myOrder);

            buf = buf.putShort(VERSION);
            buf = buf.putShort(GET_HDR);
            buf = buf.putInt(0);
            buf.rewind();
            writeAll(buf);

            buf = readResponse(GET_OK);
            if (errorReturned == NO_ERROR)
            {
                header = new Header(buf);
            }
            else
            {
                header = new Header(0, 0, 0);
            }
            return(header);
        }