java.nio.CharBuffer#capacity ( )源码实例Demo

下面列出了java.nio.CharBuffer#capacity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: edslite   文件: EditableSecureBuffer.java
/**
 * Return the char at the specified offset within the buffer.
 */
@Override
public char charAt(int where) {
    if(VERBOSE_LOG) Logger.debug(TAG + ": in charAt");
    CharBuffer cb = _sb.getCharBuffer();
    if(cb == null)
        return ' ';
    cb.clear();
    int len = cb.capacity() - mGapLength;
    if (where < 0) {
        throw new IndexOutOfBoundsException("charAt: " + where + " < 0");
    } else if (where >= len) {
        throw new IndexOutOfBoundsException("charAt: " + where + " >= length " + len);
    }

    if (where >= mGapStart)
        return cb.charAt(where + mGapLength);
    else
        return cb.charAt(where);
}
 
源代码2 项目: staedi   文件: StreamEvent.java
static CharBuffer put(CharBuffer buffer, CharArraySequence data) {
    final int length = data.length();

    if (buffer == null || buffer.capacity() < length) {
        buffer = CharBuffer.allocate(length);
    }

    buffer.clear();

    if (length > 0) {
        data.putToBuffer(buffer);
    }

    buffer.flip();

    return buffer;
}
 
源代码3 项目: dragonwell8_jdk   文件: Chars.java
/**
 * Randomize the char buffer's position and limit.
 */
static CharBuffer randomizeRange(CharBuffer cb) {
    int mid = cb.capacity() >>> 1;
    int start = RAND.nextInt(mid + 1); // from 0 to mid
    int end = mid + RAND.nextInt(cb.capacity() - mid + 1); // from mid to capacity
    cb.position(start);
    cb.limit(end);
    return cb;
}
 
源代码4 项目: openjdk-jdk9   文件: Chars.java
/**
 * Randomize the char buffer's position and limit.
 */
static CharBuffer randomizeRange(CharBuffer cb) {
    int mid = cb.capacity() >>> 1;
    int start = RAND.nextInt(mid + 1); // from 0 to mid
    int end = mid + RAND.nextInt(cb.capacity() - mid + 1); // from mid to capacity
    cb.position(start);
    cb.limit(end);
    return cb;
}
 
源代码5 项目: jdk8u-jdk   文件: Chars.java
/**
 * Randomize the char buffer's position and limit.
 */
static CharBuffer randomizeRange(CharBuffer cb) {
    int mid = cb.capacity() >>> 1;
    int start = RAND.nextInt(mid);
    int end = mid + RAND.nextInt(mid);
    cb.position(start);
    cb.limit(end);
    return cb;
}
 
源代码6 项目: nats.java   文件: FileAuthHandler.java
/**
 * getJWT should return the user JWT associated with this connection.
 * This can return null for challenge only authentication, but for account/user
 * JWT-based authentication you need to return the JWT bytes here.
 * 
 * @return the user JWT
 */ 
public char[] getJWT() {
    try {
        char[] jwtChars = null;
        String fileToUse = this.jwtFile;

        if (this.credsFile != null) {
            fileToUse = this.credsFile;
        }

        // If no file is provided, assume this is challenge only authentication
        // and simply return null here.
        if (fileToUse == null) {
            return null;
        }

        byte[] data = Files.readAllBytes(Paths.get(fileToUse));
        ByteBuffer bb = ByteBuffer.wrap(data);
        CharBuffer chars = StandardCharsets.UTF_8.decode(bb);
        jwtChars = this.extract(chars, 1); // jwt is always first
        // Clear things up as best we can
        chars.clear();
        for (int i=0; i<chars.capacity();i++) {
            chars.put('\0');
        }
        bb.clear();
        for (int i=0;i<data.length;i++) {
            data[i] = 0;
        }

        return jwtChars;
    } catch (Exception exp) {
        throw new IllegalStateException("problem reading jwt", exp);
    }
}
 
源代码7 项目: hottub   文件: Chars.java
/**
 * Randomize the char buffer's position and limit.
 */
static CharBuffer randomizeRange(CharBuffer cb) {
    int mid = cb.capacity() >>> 1;
    int start = RAND.nextInt(mid);
    int end = mid + RAND.nextInt(mid);
    cb.position(start);
    cb.limit(end);
    return cb;
}