当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.arrayOffset方法代码示例

本文整理汇总了Java中java.nio.ByteBuffer.arrayOffset方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.arrayOffset方法的具体用法?Java ByteBuffer.arrayOffset怎么用?Java ByteBuffer.arrayOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.arrayOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readFully

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Read data from the input stream to the given byte buffer until there are no bytes remaining in the buffer or the
 * end of the stream has been reached.
 *
 * @param inputStream Input stream to read from
 * @param destinationBuffer The buffer into which bytes are to be transferred (it must be backed by an array)
 *
 * @throws IOException If an I/O error occurs
 */
public static final void readFully(InputStream inputStream, ByteBuffer destinationBuffer) throws IOException {
    if (!destinationBuffer.hasArray())
        throw new IllegalArgumentException("destinationBuffer must be backed by an array");
    int initialOffset = destinationBuffer.arrayOffset() + destinationBuffer.position();
    byte[] array = destinationBuffer.array();
    int length = destinationBuffer.remaining();
    int totalBytesRead = 0;
    do {
        int bytesRead = inputStream.read(array, initialOffset + totalBytesRead, length - totalBytesRead);
        if (bytesRead == -1)
            break;
        totalBytesRead += bytesRead;
    } while (length > totalBytesRead);
    destinationBuffer.position(destinationBuffer.position() + totalBytesRead);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:25,代码来源:Utils.java

示例2: decodeArrayLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
    byte[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();

    char[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();

    CoderResult cr = CoderResult.UNDERFLOW;
    if ((dl - dp) < (sl - sp)) {
        sl = sp + (dl - dp);
        cr = CoderResult.OVERFLOW;
    }

    while (sp < sl) {
        char c = decode(sa[sp]);
        if (c == UNMAPPABLE_DECODING) {
            return withResult(CoderResult.unmappableForLength(1),
                       src, sp, dst, dp);
        }
        da[dp++] = c;
        sp++;
    }
    return withResult(cr, src, sp, dst, dp);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:SingleByte.java

示例3: compare

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public int compare(ByteBuffer buffer1, byte[] buffer2, int offset2, int length2)
{
    Object obj1;
    long offset1;
    if (buffer1.hasArray())
    {
        obj1 = buffer1.array();
        offset1 = BYTE_ARRAY_BASE_OFFSET + buffer1.arrayOffset();
    }
    else
    {
        obj1 = null;
        offset1 = theUnsafe.getLong(buffer1, DIRECT_BUFFER_ADDRESS_OFFSET);
    }
    int length1;
    {
        int position = buffer1.position();
        int limit = buffer1.limit();
        length1 = limit - position;
        offset1 += position;
    }
    return compareTo(obj1, offset1, length1, buffer2, BYTE_ARRAY_BASE_OFFSET + offset2, length2);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:24,代码来源:FastByteOperations.java

示例4: decodeArrayLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult decodeArrayLoop(ByteBuffer src,
                                    CharBuffer dst)
{
    byte[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    char[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            byte b = sa[sp];
            if (dp >= dl)
                return CoderResult.OVERFLOW;
            da[dp++] = (char)(b & 0xff);
            sp++;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ISO_8859_1.java

示例5: deserialize

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
@SneakyThrows
public T deserialize(ByteBuffer buffer) {
    byte[] array;
    if (buffer.hasArray() && buffer.arrayOffset() == 0 && buffer.position() == 0 && buffer.limit() == buffer.capacity()) {
        array = buffer.array();
    } else {
        array = new byte[buffer.remaining()];
        buffer.get(array);
    }

    return deserializationSchema.deserialize(array);
}
 
开发者ID:pravega,项目名称:flink-connectors,代码行数:14,代码来源:FlinkPravegaUtils.java

示例6: decodeArrayLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
    byte[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();

    char[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();

    try {
        while (sp < sl && dp < dl) {
            // inline the decodeSingle/Double() for better performance
            int inSize = 1;
            int b1 = sa[sp] & 0xff;
            char c = b2cSB[b1];
            if (c == UNMAPPABLE_DECODING) {
                if (sl - sp < 2)
                    return crMalformedOrUnderFlow(b1);
                int b2 = sa[sp + 1] & 0xff;
                if (b2 < b2Min || b2 > b2Max ||
                    (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
                    return crMalformedOrUnmappable(b1, b2);
                }
                inSize++;
            }
            da[dp++] = c;
            sp += inSize;
        }
        return (sp >= sl) ? CoderResult.UNDERFLOW
                          : CoderResult.OVERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:DoubleByte.java

示例7: encode

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public BytesRef encode(char[] buffer, int offset, int length) {
  final ByteBuffer bb = charset.encode(CharBuffer.wrap(buffer, offset, length));
  if (bb.hasArray()) {
    return new BytesRef(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining());
  } else {
    // normally it should always have an array, but who knows?
    final byte[] b = new byte[bb.remaining()];
    bb.get(b);
    return new BytesRef(b);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:IdentityEncoder.java

示例8: encodeLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();

    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();

    try {
        while (sp < sl) {
            char c = sa[sp];
            if (c <= '\u007f')
                return CoderResult.unmappableForLength(1);
            int ncode = encodeDouble(c);
            if (ncode != 0 && c != '\u0000' ) {
                da[dp++] = (byte) ((ncode  >> 8) & 0x7f);
                da[dp++] = (byte) (ncode & 0x7f);
                sp++;
                continue;
            }
            return CoderResult.unmappableForLength(1);
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:X11GB2312.java

示例9: writeFrame

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void writeFrame(Http2Frame frame) throws IOException {
    ByteBufferReference[] refs = new FramesEncoder().encodeFrame(frame);
    //System.err.println("TestServer: Writing frame " + frame.toString());
    int c = 0;
    for (ByteBufferReference ref : refs) {
        ByteBuffer buf = ref.get();
        byte[] ba = buf.array();
        int start = buf.arrayOffset() + buf.position();
        c += buf.remaining();
        os.write(ba, start, buf.remaining());
    }
    os.flush();
    //System.err.printf("TestServer: wrote %d bytes\n", c);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Http2TestServerConnection.java

示例10: toByteArray

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * gets the contents of this stream as a byte[]. The stream should not be written to past this
 * point until it has been reset.
 */
public final byte[] toByteArray() {
  ByteBuffer bb = toByteBuffer();
  if (bb.hasArray() && bb.arrayOffset() == 0 && bb.limit() == bb.capacity()) {
    return bb.array();
  } else {
    // create a new buffer of just the right size and copy the old buffer into it
    ByteBuffer tmp = ByteBuffer.allocate(bb.remaining());
    tmp.put(bb);
    tmp.flip();
    this.buffer = tmp;
    return this.buffer.array();
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:HeapDataOutputStream.java

示例11: encodeLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            char c = sa[sp];
            if (dl - dp < 1)
                return CoderResult.OVERFLOW;

            if (!canEncode(c))
                return CoderResult.unmappableForLength(1);
            sp++;
            if (c >= 0x2761){
                da[dp++] = table[c - 0x2761]; // table lookup
            } else {
                da[dp++] = (byte)(c + 0x20 - 0x2700); // direct map
            }
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:X11Dingbats.java

示例12: encodeArrayLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            char c = sa[sp];
            if (Character.isSurrogate(c)) {
                if (sgp.parse(c, sa, sp, sl) < 0)
                    return sgp.error();
                return sgp.unmappableResult();
            }
            if (c >= '\uFFFE')
                return CoderResult.unmappableForLength(1);
            if (dl - dp < 1)
                return CoderResult.OVERFLOW;

            char e = index2.charAt(index1[(c & mask1) >> shift]
                                   + (c & mask2));

            // If output byte is zero because input char is zero
            // then character is mappable, o.w. fail
            if (e == '\u0000' && c != '\u0000')
                return CoderResult.unmappableForLength(1);

            sp++;
            da[dp++] = (byte)e;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:43,代码来源:SingleByteEncoder.java

示例13: encodeArrayLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    int outputSize = 0;             // size of output

    try {
        while (sp < sl) {
            int index;
            int theBytes;
            char c = sa[sp];
            if (Surrogate.is(c)) {
                if (sgp.parse(c, sa, sp, sl) < 0)
                    return sgp.error();
                return sgp.unmappableResult();
            }
            if (c >= '\uFFFE')
                return CoderResult.unmappableForLength(1);

            index = index1[((c & mask1) >> shift)]
                            + (c & mask2);
            if (index < 15000)
                theBytes = (int)(index2.charAt(index));
            else
                theBytes = (int)(index2a.charAt(index-15000));
            b1 = (byte)((theBytes & 0x0000ff00)>>8);
            b2 = (byte)(theBytes & 0x000000ff);

            if (b1 == 0x00 && b2 == 0x00
                && c != '\u0000') {
                    return CoderResult.unmappableForLength(1);
            }

            if (b1 == 0) {
                if (dl - dp < 1)
                    return CoderResult.OVERFLOW;
                da[dp++] = (byte) b2;
            } else {
                if (dl - dp < 2)
                    return CoderResult.OVERFLOW;
                da[dp++] = (byte) b1;
                da[dp++] = (byte) b2;
            }
            sp++;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:DBCS_IBM_ASCII_Encoder.java

示例14: decodeArrayLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
    byte[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    char[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            int b1, b2;
            b1 = sa[sp];
            int inputSize = 1;
            int v = 0;
            char outputChar = REPLACE_CHAR;

            if (b1 < 0)
                b1 += 256;

            if (b1 == SO) {  // Shift out
                // For SO characters - simply validate the state and if OK
                //    update the state and go to the next byte

                if (currentState != SBCS)
                    return CoderResult.malformedForLength(1);
                else
                    currentState = DBCS;
            } else if (b1 == SI) {
                // For SI characters - simply validate the state and if OK
                //    update the state and go to the next byte

                if (currentState != DBCS) {
                    return CoderResult.malformedForLength(1);
                } else {
                    currentState = SBCS;
                }
            } else {
                if (currentState == SBCS) {
                    outputChar = singleByteToChar.charAt(b1);
                } else {
                if (sl - sp < 2)
                    return CoderResult.UNDERFLOW;
                b2 = sa[sp + 1];
                if (b2 < 0)
                    b2 += 256;

                inputSize++;

                // Check validity of dbcs ebcdic byte pair values
                if ((b1 != 0x40 || b2 != 0x40) &&
                  (b2 < 0x41 || b2 > 0xfe)) {
                  return CoderResult.malformedForLength(2);
                }

                // Lookup in the two level index
                v = b1 * 256 + b2;
                outputChar = index2.charAt(index1[((v & mask1) >> shift)]
                                            + (v & mask2));
                }
                if (outputChar == '\uFFFD')
                    return CoderResult.unmappableForLength(inputSize);

                if (dl - dp < 1)
                    return CoderResult.OVERFLOW;
                da[dp++] = outputChar;
            }
            sp += inputSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:79,代码来源:DBCS_IBM_EBCDIC_Decoder.java

示例15: encodeArrayLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult encodeArrayLoop(CharBuffer src,
                                    ByteBuffer dst)
{
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();

    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    int dlASCII = dp + Math.min(sl - sp, dl - dp);

    // ASCII only loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];
    while (sp < sl) {
        char c = sa[sp];
        if (c < 0x80) {
            // Have at most seven bits
            if (dp >= dl)
                return overflow(src, sp, dst, dp);
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            if (dl - dp < 2)
                return overflow(src, sp, dst, dp);
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            // Have a surrogate pair
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp, sl);
            if (uc < 0) {
                updatePositions(src, sp, dst, dp);
                return sgp.error();
            }
            if (dl - dp < 4)
                return overflow(src, sp, dst, dp);
            da[dp++] = (byte)(0xf0 | ((uc >> 18)));
            da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
            da[dp++] = (byte)(0x80 | ((uc >>  6) & 0x3f));
            da[dp++] = (byte)(0x80 | (uc & 0x3f));
            sp++;  // 2 chars
        } else {
            // 3 bytes, 16 bits
            if (dl - dp < 3)
                return overflow(src, sp, dst, dp);
            da[dp++] = (byte)(0xe0 | ((c >> 12)));
            da[dp++] = (byte)(0x80 | ((c >>  6) & 0x3f));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        }
        sp++;
    }
    updatePositions(src, sp, dst, dp);
    return CoderResult.UNDERFLOW;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:58,代码来源:UTF_8.java


注:本文中的java.nio.ByteBuffer.arrayOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。