Exemple #1
0
 public SerialBuffer(bool version)
 {
     writeBuffer = new SynchronizedBuffer();
     if (version)
     {
         readBuffer = ByteBuffer.Allocate(DEFAULT_READ_BUFFER_SIZE);
     }
     else
     {
         readBufferCompatible = new byte[DEFAULT_READ_BUFFER_SIZE];
     }
 }
Exemple #2
0
        //-----------------------------------------------------------------------

        /**
         * Returns a synchronized buffer backed by the given buffer.
         * Much like the synchronized collections returned by
         * {@link java.util.Collections}, you must manually synchronize on
         * the returned buffer's iterator to avoid non-deterministic behavior:
         *
         * <pre>
         * Buffer b = BufferUtils.synchronizedBuffer(myBuffer);
         * synchronized (b) {
         *     Iterator i = b.iterator();
         *     while (i.hasNext()) {
         *         process (i.next());
         *     }
         * }
         * </pre>
         *
         * @param buffer  the buffer to synchronize, must not be null
         * @return a synchronized buffer backed by that buffer
         * @throws IllegalArgumentException  if the Buffer is null
         */
        public static Buffer synchronizedBuffer(Buffer buffer)
        {
            return(SynchronizedBuffer.decorate(buffer));
        }