Пример #1
0
            protected int replaceNaN(ShortBuffer shortBuffer, short value)
            {
                int length    = shortBuffer.remaining();
                int numValues = 0;

                if (this.tmpBuffer == null || this.tmpBuffer.length < shortBuffer.remaining())
                {
                    this.tmpBuffer = new short[length];
                }

                shortBuffer.get(this.tmpBuffer, 0, length);
                shortBuffer.flip();

                for (int i = 0; i < length; i++)
                {
                    if (isNoValueShort(this.tmpBuffer[i]))
                    {
                        this.tmpBuffer[i] = value;
                    }
                    else
                    {
                        numValues++;
                    }
                }

                shortBuffer.put(this.tmpBuffer, 0, length);
                shortBuffer.flip();

                return(numValues);
            }
Пример #2
0
        /**
         * Returns a copy of the specified buffer, with the specified new size. The new size must be greater than or equal
         * to the specified buffer's size. If the new size is greater than the specified buffer's size, this returns a new
         * buffer which is partially filled with the contents of the specified buffer. The returned buffer is a backed by a
         * direct ByteBuffer if and only if the specified buffer is direct.
         *
         * @param buffer  the buffer to copy.
         * @param newSize the new buffer's size, in shorts.
         *
         * @return the new buffer, with the specified size.
         *
         * @throws ArgumentException if the buffer is null, if the new size is negative, or if the new size is less
         *                                  than the buffer's remaing elements.
         */
        public static ShortBuffer copyOf(ShortBuffer buffer, int newSize)
        {
            if (newSize < 0 || newSize < buffer.remaining())
            {
                String message = Logging.getMessage("generic.SizeOutOfRange", newSize);
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            ShortBuffer newBuffer = newShortBuffer(newSize, buffer.isDirect());

            int pos = buffer.position(); // Save the input buffer's current position.

            try
            {
                newBuffer.put(buffer);
                newBuffer.rewind();
            }
            finally
            {
                buffer.position(pos); // Restore the input buffer's original position.
            }

            return(newBuffer);
        }
Пример #3
0
        public static ShortBuffer allocateDirectBuffer(ShortBuffer buffer)
        {
            if (buffer.Direct)
            {
                return(buffer);
            }

            return(allocateDirectBuffer(buffer.remaining() << 1).asShortBuffer());
        }