Package java.nio

Examples of java.nio.ShortBuffer


     */
    public static ShortBuffer createShortBuffer(final short... data) {
        if (data == null) {
            return null;
        }
        final ShortBuffer buff = createShortBuffer(data.length);
        buff.clear();
        buff.put(data);
        buff.flip();
        return buff;
    }
View Full Code Here


        if (buf == null) {
            return null;
        }
        buf.rewind();

        final ShortBuffer copy;
        if (buf.isDirect()) {
            copy = createShortBuffer(buf.limit());
        } else {
            copy = createShortBufferOnHeap(buf.limit());
        }
        copy.put(buf);

        return copy;
    }
View Full Code Here

        // increment index
        _index += length * 2;

        // Convert to short buffer.
        final ShortBuffer value;
        final boolean contentCopyRequired;
        if (direct) {
            if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
                value = buf.asShortBuffer();
                contentCopyRequired = false;
            } else {
                value = BufferUtils.createShortBuffer(length);
                contentCopyRequired = true;
            }
        } else {
            value = BufferUtils.createShortBufferOnHeap(length);
            contentCopyRequired = true;
        }
        if (contentCopyRequired) {
            value.put(buf.asShortBuffer());
            value.rewind();
        }
        return value;
    }
View Full Code Here

        }
        return ret;
    }

    public ShortBuffer readShortBuffer(final String name, final ShortBuffer defVal) throws IOException {
        ShortBuffer ret = defVal;
        try {
            final Element tmpEl = findChildElement(_currentElem, name);
            if (tmpEl == null) {
                return defVal;
            }

            final int size = Integer.parseInt(tmpEl.getAttribute("size"));
            final ShortBuffer tmp = BufferUtils.createShortBuffer(size);
            if (size > 0) {
                final String[] strings = tmpEl.getAttribute("data").split("\\s+");
                for (final String s : strings) {
                    tmp.put(Short.valueOf(s));
                }
                tmp.flip();
            }
            ret = tmp;
        } catch (final Exception e) {
            final IOException ex = new IOException();
            ex.initCause(e);
View Full Code Here

        return _buffer;
    }

    @Override
    public IntBuffer asIntBuffer() {
        final ShortBuffer source = getBuffer().duplicate();
        source.rewind();
        final IntBuffer buff = BufferUtils.createIntBufferOnHeap(source.limit());
        for (int i = 0, max = source.limit(); i < max; i++) {
            buff.put(source.get() & 0xFFFF);
        }
        buff.flip();
        return buff;
    }
View Full Code Here

        setCJKSupport(os2_Table);

        ByteBuffer head_Table = getTableBuffer(headTag);
        int upem = -1;
        if (head_Table != null && head_Table.capacity() >= 18) {
            ShortBuffer sb = head_Table.asShortBuffer();
            upem = sb.get(9) & 0xffff;
        }
        setStrikethroughMetrics(os2_Table, upem);

        ByteBuffer post_Table = getTableBuffer(postTag);
        setUnderlineMetrics(post_Table, upem);
View Full Code Here

        if (os_2Table == null || os_2Table.capacity() < 30 || upem < 0) {
            stSize = .05f;
            stPos = -.4f;
            return;
        }
        ShortBuffer sb = os_2Table.asShortBuffer();
        stSize = sb.get(13) / (float)upem;
        stPos = -sb.get(14) / (float)upem;
    }
View Full Code Here

        if (postTable == null || postTable.capacity() < 12 || upem < 0) {
            ulSize = .05f;
            ulPos = .1f;
            return;
        }
        ShortBuffer sb = postTable.asShortBuffer();
        ulSize = sb.get(5) / (float)upem;
        ulPos = -sb.get(4) / (float)upem;
    }
View Full Code Here

        byte[] name = new byte[256];
        ByteBuffer buffer = getTableBuffer(nameTag);

        if (buffer != null) {
            ShortBuffer sbuffer = buffer.asShortBuffer();
            sbuffer.get(); // format - not needed.
            short numRecords = sbuffer.get();
            /* The name table uses unsigned shorts. Many of these
             * are known small values that fit in a short.
             * The values that are sizes or offsets into the table could be
             * greater than 32767, so read and store those as ints
             */
            int stringPtr = sbuffer.get() & 0xffff;
            for (int i=0; i<numRecords; i++) {
                short platformID = sbuffer.get();
                if (platformID != MS_PLATFORM_ID) {
                    sbuffer.position(sbuffer.position()+5);
                    continue; // skip over this record.
                }
                short encodingID = sbuffer.get();
                short langID     = sbuffer.get();
                short nameID     = sbuffer.get();
                int nameLen    = ((int) sbuffer.get()) & 0xffff;
                int namePtr    = (((int) sbuffer.get()) & 0xffff) + stringPtr;

                switch (nameID) {

                case FAMILY_NAME_ID:

View Full Code Here

        String foundName = null;
        byte[] name = new byte[1024];

        ByteBuffer buffer = getTableBuffer(nameTag);
        if (buffer != null) {
            ShortBuffer sbuffer = buffer.asShortBuffer();
            sbuffer.get(); // format - not needed.
            short numRecords = sbuffer.get();

            /* The name table uses unsigned shorts. Many of these
             * are known small values that fit in a short.
             * The values that are sizes or offsets into the table could be
             * greater than 32767, so read and store those as ints
             */
            int stringPtr = ((int) sbuffer.get()) & 0xffff;

            for (int i=0; i<numRecords; i++) {
                short platformID = sbuffer.get();
                if (platformID != MS_PLATFORM_ID) {
                    sbuffer.position(sbuffer.position()+5);
                    continue; // skip over this record.
                }
                short encodingID = sbuffer.get();
                short langID     = sbuffer.get();
                short nameID     = sbuffer.get();
                int   nameLen    = ((int) sbuffer.get()) & 0xffff;
                int   namePtr    = (((int) sbuffer.get()) & 0xffff) + stringPtr;
                if (nameID == findNameID &&
                    ((foundName == null && langID == ENGLISH_LOCALE_ID)
                     || langID == findLocaleID)) {
                    buffer.position(namePtr);
                    buffer.get(name, 0, nameLen);
View Full Code Here

TOP

Related Classes of java.nio.ShortBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.