order() public method

public order ( ByteOrder _byteorder ) : ByteBuffer
_byteorder ByteOrder
return ByteBuffer
Example #1
0
        protected ByteBuffer readResponse(int expected)
        {
            ByteBuffer def = ByteBuffer.allocate(8);

            def.order(myOrder);
            readAll(def);
            def.rewind();

            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);
        }
Example #2
0
        public void flushEvents()
        {
            ByteBuffer buf = ByteBuffer.allocate(8);

            buf.order(myOrder);

            buf.putShort(VERSION).putShort(FLUSH_EVT).putInt(0).rewind();
            writeAll(buf);
            buf = readResponse(FLUSH_OK);
        }
Example #3
0
        protected ByteBuffer preparePutData(int nChans, int nSamples, int type)
        {
            int bufsize = DataType.wordSize[type] * nSamples * nChans;

            ByteBuffer buf = ByteBuffer.allocate(8 + 16 + bufsize);

            buf.order(myOrder);
            buf.putShort(VERSION).putShort(PUT_DAT).putInt(16 + bufsize);
            buf.putInt(nChans).putInt(nSamples).putInt(type).putInt(bufsize);
            return(buf);
        }
Example #4
0
        public void flushData()
        {
            ByteBuffer buf = ByteBuffer.allocate(8);

            buf.order(myOrder);

            buf.putShort(VERSION).putShort(FLUSH_DAT).putInt(0).rewind();
            lock (this) {
                writeAll(buf);
                buf = readResponse(FLUSH_OK);
            }
        }