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


Java Arrays.boundsCheck方法代码示例

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


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

示例1: charToByteArray

import com.sun.squawk.util.Arrays; //导入方法依赖的package包/类
/**
 * Convert a byte array to a char array
 *
 * @param  buffer          The byte array buffer
 * @param  offset          The offset
 * @param  length          The length
 * @param  enc             The character encoding
 * @return                 A new char array
 * @exception UnsupportedEncodingException  If the encoding is not known
 */
public static byte[] charToByteArray(char[] buffer, int offset, int length, String enc) throws UnsupportedEncodingException {
    Arrays.boundsCheck(buffer.length, offset, length);
    //Because most cases use ISO8859_1 encoding, we can optimize this case.
    if (isISO8859_1(enc)) {
        if (length < 0) {
            throw new IndexOutOfBoundsException();
        }
        byte[] value = new byte[length];
        for(int i=0; i<length; i++) {
            //c = buffer[i+offset];
            //value[i] = (c <= 255) ? (byte)c : (byte)'?'; TCK doesn't like seeing this '?'
            value[i] = (byte)buffer[i+offset];
        }
        return value;
    } else if (ISO8859_1_ONLY_SUPPORTED) {
        throw new UnsupportedEncodingException("ISO8859_1_ONLY_SUPPORTED: " + enc);
    } else {
        return charToByteArray0(buffer, offset, length, enc);
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:31,代码来源:Helper.java

示例2: write

import com.sun.squawk.util.Arrays; //导入方法依赖的package包/类
public void write(byte b[], int off, int len) throws IOException {
    Arrays.boundsCheck(b.length, off, len);
    if (len == 0) {
        return;
    }
    int old;
    if (err) {
        old = VM.setStream(VM.STREAM_STDERR);
    } else {
        old = VM.setStream(VM.STREAM_STDOUT);
    }
    VM.printBytes(b, off, len);
    VM.setStream(old);
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:15,代码来源:System.java

示例3: printBytes

import com.sun.squawk.util.Arrays; //导入方法依赖的package包/类
/**
 * Prints bytes (as C chars) to the VM stream.
 *
 * @param      b     the data.
 * @param      off   the start offset in the data.
 * @param      len   the number of bytes to write.
 */
public static void printBytes(byte b[], int off, int len) {
    if (b == null) {
        throw new NullPointerException();
    }
    Arrays.boundsCheck(b.length, off, len);
    if (len == 0) {
        return;
    }
    executeCIO(-1, ChannelConstants.INTERNAL_PRINTBYTES, -1, off, len, 0, 0, 0, 0, b, null);
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:18,代码来源:VM.java

示例4: write

import com.sun.squawk.util.Arrays; //导入方法依赖的package包/类
/**
 * Write a portion of an array of characters.
 *
 * <p> Ordinarily this method stores characters from the given array into
 * this stream's buffer, flushing the buffer to the underlying stream as
 * needed.  If the requested length is at least as large as the buffer,
 * however, then this method will flush the buffer and write the characters
 * directly to the underlying stream.  Thus redundant
 * <code>BufferedWriter</code>s will not copy data unnecessarily.
 *
 * @param  cbuf  A character array
 * @param  off   Offset from which to start reading characters
 * @param  len   Number of characters to write
 *
 * @exception  IOException  If an I/O error occurs
 */
public void write(char cbuf[], int off, int len) throws IOException {
    synchronized (lock) {
        ensureOpen();
        Arrays.boundsCheck(cbuf.length, off, len);
        if (len == 0) {
            return;
        }

        if (len >= nChars) {
            /* If the request length exceeds the size of the output buffer,
            flush the buffer and then write the data directly.  In this
            way buffered streams will cascade harmlessly. */
            flushBuffer();
            out.write(cbuf, off, len);
            return;
        }

        int b = off, t = off + len;
        while (b < t) {
            int d = min(nChars - nextChar, t - b);
            System.arraycopy(cbuf, b, cb, nextChar, d);
            b += d;
            nextChar += d;
            if (nextChar >= nChars) {
                flushBuffer();
            }
        }
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:46,代码来源:BufferedWriter.java

示例5: read

import com.sun.squawk.util.Arrays; //导入方法依赖的package包/类
/**
 * Read characters into a portion of an array.
 *
 * <p> This method implements the general contract of the corresponding
 * <code>{@link Reader#read(char[], int, int) read}</code> method of the
 * <code>{@link Reader}</code> class.  As an additional convenience, it
 * attempts to read as many characters as possible by repeatedly invoking
 * the <code>read</code> method of the underlying stream.  This iterated
 * <code>read</code> continues until one of the following conditions becomes
 * true: <ul>
 *
 *   <li> The specified number of characters have been read,
 *
 *   <li> The <code>read</code> method of the underlying stream returns
 *   <code>-1</code>, indicating end-of-file, or
 *
 *   <li> The <code>ready</code> method of the underlying stream
 *   returns <code>false</code>, indicating that further input requests
 *   would block.
 *
 * </ul> If the first <code>read</code> on the underlying stream returns
 * <code>-1</code> to indicate end-of-file then this method returns
 * <code>-1</code>.  Otherwise this method returns the number of characters
 * actually read.
 *
 * <p> Subclasses of this class are encouraged, but not required, to
 * attempt to read as many characters as possible in the same fashion.
 *
 * <p> Ordinarily this method takes characters from this stream's character
 * buffer, filling it from the underlying stream as necessary.  If,
 * however, the buffer is empty, the mark is not valid, and the requested
 * length is at least as large as the buffer, then this method will read
 * characters directly from the underlying stream into the given array.
 * Thus redundant <code>BufferedReader</code>s will not copy data
 * unnecessarily.
 *
 * @param      cbuf  Destination buffer
 * @param      off   Offset at which to start storing characters
 * @param      len   Maximum number of characters to read
 *
 * @return     The number of characters read, or -1 if the end of the
 *             stream has been reached
 *
 * @exception  IOException  If an I/O error occurs
 */
public int read(char cbuf[], int off, int len) throws IOException {
    synchronized (lock) {
    ensureOpen();
    Arrays.boundsCheck(cbuf.length, off, len);
    if (len == 0) {
        return 0;
    }

    int n = read1(cbuf, off, len);
    if (n <= 0) return n;
    while ((n < len) && in.ready()) {
    int n1 = read1(cbuf, off + n, len - n);
    if (n1 <= 0) break;
    n += n1;
    }
    return n;
}
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:64,代码来源:BufferedReader.java

示例6: read

import com.sun.squawk.util.Arrays; //导入方法依赖的package包/类
/**
 * Reads bytes from this byte-input stream into the specified byte array,
 * starting at the given offset.
 *
 * <p> This method implements the general contract of the corresponding
 * <code>{@link InputStream#read(byte[], int, int) read}</code> method of
 * the <code>{@link InputStream}</code> class.  As an additional
 * convenience, it attempts to read as many bytes as possible by repeatedly
 * invoking the <code>read</code> method of the underlying stream.  This
 * iterated <code>read</code> continues until one of the following
 * conditions becomes true: <ul>
 *
 *   <li> The specified number of bytes have been read,
 *
 *   <li> The <code>read</code> method of the underlying stream returns
 *   <code>-1</code>, indicating end-of-file, or
 *
 *   <li> The <code>available</code> method of the underlying stream
 *   returns zero, indicating that further input requests would block.
 *
 * </ul> If the first <code>read</code> on the underlying stream returns
 * <code>-1</code> to indicate end-of-file then this method returns
 * <code>-1</code>.  Otherwise this method returns the number of bytes
 * actually read.
 *
 * <p> Subclasses of this class are encouraged, but not required, to
 * attempt to read as many bytes as possible in the same fashion.
 *
 * @param      b     destination buffer.
 * @param      off   offset at which to start storing bytes.
 * @param      len   maximum number of bytes to read.
 * @return     the number of bytes read, or <code>-1</code> if the end of
 *             the stream has been reached.
 * @exception  IOException  if an I/O error occurs.
 */
public synchronized int read(byte b[], int off, int len)
    throws IOException
{
    ensureOpen();
    Arrays.boundsCheck(b.length, off, len);
    if (len == 0) {
        return 0;
    }

    int n = read1(b, off, len);
    if (n <= 0) return n;
    while ((n < len) && (in.available() > 0)) {
        int n1 = read1(b, off + n, len - n);
        if (n1 <= 0) break;
        n += n1;
    }
    return n;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:54,代码来源:BufferedInputStream.java

示例7: write

import com.sun.squawk.util.Arrays; //导入方法依赖的package包/类
/**
 * Writes <code>len</code> bytes from the specified byte array
 * starting at offset <code>off</code> to this output stream.
 * <p>
 * If <code>b</code> is <code>null</code>, a
 * <code>NullPointerException</code> is thrown.
 * <p>
 * If <code>off</code> is negative, or <code>len</code> is negative, or
 * <code>off+len</code> is greater than the length of the array
 * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
 *
 * @param      b     the data.
 * @param      off   the start offset in the data.
 * @param      len   the number of bytes to write.
 * @exception  IOException  if an I/O error occurs. In particular,
 *             an <code>IOException</code> is thrown if the output
 *             stream is closed.
 */
public void write(byte b[], int off, int len) throws IOException {
    Arrays.boundsCheck(b.length, off, len);
    if (len == 0) {
        return;
    }
    int old;
    if (parent.err) {
        old = VM.setStream(VM.STREAM_STDERR);
    } else {
        old = VM.setStream(VM.STREAM_STDOUT);
    }
    VM.printBytes(b, off, len);
    VM.setStream(old);
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:33,代码来源:Protocol.java


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