java.util.Arrays.checkOffsetAndCount()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中java.util.Arrays.checkOffsetAndCount()方法的一些代码示例,展示了Arrays.checkOffsetAndCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Arrays.checkOffsetAndCount()方法的具体详情如下:
包路径:java.util.Arrays
类名称:Arrays
方法名:checkOffsetAndCount

Arrays.checkOffsetAndCount介绍

[英]Checks that the range described by offset and count doesn't exceed arrayLength.
[中]检查偏移量和计数描述的范围是否不超过arrayLength。

代码示例

代码示例来源:origin: robovm/robovm

@Override public synchronized int read(byte[] buffer, int byteOffset, int byteCount) {
  Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
  // Are there any bytes available?
  if (this.pos >= this.count) {
    return -1;
  }
  if (byteCount == 0) {
    return 0;
  }
  int copylen = this.count - pos < byteCount ? this.count - pos : byteCount;
  System.arraycopy(this.buf, pos, buffer, byteOffset, copylen);
  pos += copylen;
  return copylen;
}

代码示例来源:origin: robovm/robovm

@Override public synchronized int read(byte[] buffer, int byteOffset, int byteCount) {
  if (buffer == null) {
    throw new NullPointerException("buffer == null");
  }
  Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
  if (byteCount == 0) {
    return 0;
  }
  int copylen = count - pos < byteCount ? count - pos : byteCount;
  for (int i = 0; i < copylen; ++i) {
    buffer[byteOffset + i] = (byte) this.buffer.charAt(pos + i);
  }
  pos += copylen;
  return copylen;
}

代码示例来源:origin: robovm/robovm

/**
 * Update this {@code Adler32} checksum with the contents of {@code buf},
 * starting from {@code offset} and reading {@code byteCount} bytes of data.
 */
public void update(byte[] buf, int offset, int byteCount) {
  Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
  adler = updateImpl(buf, offset, byteCount, adler);
}

代码示例来源:origin: robovm/robovm

@Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
  Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
  if (byteCount == 0) {
    return 0;
  }
  checkReadPrimitiveTypes();
  return primitiveData.read(buffer, byteOffset, byteCount);
}

代码示例来源:origin: robovm/robovm

/**
 * Update this {@code CRC32} checksum with the contents of {@code buf},
 * starting from {@code offset} and reading {@code byteCount} bytes of data.
 */
public void update(byte[] buf, int offset, int byteCount) {
  Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
  tbytes += byteCount;
  crc = updateImpl(buf, offset, byteCount, crc);
}

代码示例来源:origin: robovm/robovm

final void append0(char[] chars, int offset, int length) {
  Arrays.checkOffsetAndCount(chars.length, offset, length);
  int newCount = count + length;
  if (newCount > value.length) {
    enlargeBuffer(newCount);
  }
  System.arraycopy(chars, offset, value, count, length);
  count = newCount;
}

代码示例来源:origin: robovm/robovm

@Override
  public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
    Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
    if (!channel.isBlocking()) {
      throw new IllegalBlockingModeException();
    }
    ByteBuffer buf = ByteBuffer.wrap(buffer, byteOffset, byteCount);
    return channel.read(buf);
  }
}

代码示例来源:origin: robovm/robovm

@Override
public final CharBuffer get(char[] dst, int dstOffset, int charCount) {
  Arrays.checkOffsetAndCount(dst.length, dstOffset, charCount);
  if (charCount > remaining()) {
    throw new BufferUnderflowException();
  }
  int newPosition = position + charCount;
  sequence.toString().getChars(position, newPosition, dst, dstOffset);
  position = newPosition;
  return this;
}

代码示例来源:origin: robovm/robovm

@Override
public void write(byte[] buffer, int offset, int byteCount) throws IOException {
  Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
  ByteBuffer buf = ByteBuffer.wrap(buffer, offset, byteCount);
  if (!channel.isBlocking()) {
    throw new IllegalBlockingModeException();
  }
  channel.write(buf);
}

代码示例来源:origin: robovm/robovm

/**
 * Compresses {@code byteCount} bytes of data from {@code buf} starting at
 * {@code offset} and writes it to the underlying stream.
 * @throws IOException
 *             If an error occurs during writing.
 */
@Override public void write(byte[] buffer, int offset, int byteCount) throws IOException {
  if (done) {
    throw new IOException("attempt to write after finish");
  }
  Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
  if (!def.needsInput()) {
    throw new IOException();
  }
  def.setInput(buffer, offset, byteCount);
  deflate();
}

代码示例来源:origin: robovm/robovm

/**
 * Sets the dictionary to be used for compression by this {@code Deflater}.
 * This method can only be called if this {@code Deflater} supports the writing
 * of ZLIB headers. This is the default, but can be overridden
 * using {@link #Deflater(int, boolean)}.
 */
public synchronized void setDictionary(byte[] buf, int offset, int byteCount) {
  checkOpen();
  Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
  setDictionaryImpl(buf, offset, byteCount, streamHandle);
}

代码示例来源:origin: robovm/robovm

private native int deflateImpl(byte[] buf, int offset, int byteCount, long handle, int flushParm);

代码示例来源:origin: robovm/robovm

/**
 * Sets the preset dictionary to be used for inflation to a subsequence of {@code dictionary}
 * starting at {@code offset} and continuing for {@code byteCount} bytes. See {@link
 * #needsDictionary} for details.
 */
public synchronized void setDictionary(byte[] dictionary, int offset, int byteCount) {
  checkOpen();
  Arrays.checkOffsetAndCount(dictionary.length, offset, byteCount);
  setDictionaryImpl(dictionary, offset, byteCount, streamHandle);
}

代码示例来源:origin: robovm/robovm

/**
 * Sets the current input to to be decompressed. This method should only be
 * called if {@link #needsInput} returns {@code true}.
 */
public synchronized void setInput(byte[] buf, int offset, int byteCount) {
  checkOpen();
  Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
  inRead = 0;
  inLength = byteCount;
  setInputImpl(buf, offset, byteCount, streamHandle);
}

代码示例来源:origin: robovm/robovm

/**
 * Writes to the decompressing output stream. The {@code bytes} array should contain
 * compressed input. The corresponding uncompressed data will be written to the underlying
 * stream.
 *
 * @throws IOException if an I/O error occurs, or the stream has been closed
 * @throws ZipException if a zip exception occurs.
 * @throws NullPointerException if {@code b == null}.
 * @throws IndexOutOfBoundsException if {@code off < 0 || len < 0 || off + len > b.length}
 */
@Override
public void write(byte[] bytes, int offset, int byteCount) throws IOException, ZipException {
  checkClosed();
  Arrays.checkOffsetAndCount(bytes.length, offset, byteCount);
  inf.setInput(bytes, offset, byteCount);
  write();
}

代码示例来源:origin: robovm/robovm

/**
 * Copies {@code count} {@code boolean}s from the memory pointed to by this
 * {@link BooleanPtr} to {@code dst} starting at offset {@code offset}.
 * 
 * @param dst the destination.
 * @param offset the offset within the destination array to start copying
 *            to.
 * @param count the number of elements to copy.
 */
public void get(boolean[] dst, int offset, int count) {
  Arrays.checkOffsetAndCount(dst.length, offset, count);
  long h = getHandle();
  for (int i = 0; i < count; i++) {
    dst[i + offset] = VM.getByte(h++) != 0;
  }
}

代码示例来源:origin: robovm/robovm

/**
   * Copies {@code count} {@code boolean}s from {@code src} starting at offset
   * {@code offset} to the memory pointed to by this {@link BooleanPtr}.
   * 
   * @param src the source.
   * @param offset the offset within the source array to start copying from.
   * @param count the number of elements to copy.
   */
  public void set(boolean[] src, int offset, int count) {
    Arrays.checkOffsetAndCount(src.length, offset, count);
    long h = getHandle();
    for (int i = 0; i < count; i++) {
      VM.setByte(h++, (byte) (src[i + offset] ? 1 : 0));
    }
  }
}

代码示例来源:origin: robovm/robovm

/**
 * Sets the input buffer the {@code Deflater} will use to extract uncompressed bytes
 * for later compression.
 */
public synchronized void setInput(byte[] buf, int offset, int byteCount) {
  checkOpen();
  Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
  inLength = byteCount;
  inRead = 0;
  if (inputBuffer == null) {
    setLevelsImpl(compressLevel, strategy, streamHandle);
  }
  inputBuffer = buf;
  setInputImpl(buf, offset, byteCount, streamHandle);
}

代码示例来源:origin: robovm/robovm

public long read(ByteBuffer[] buffers, int offset, int length) throws IOException {
  Arrays.checkOffsetAndCount(buffers.length, offset, length);
  checkOpen();
  checkReadable();
  return transferIoVec(new IoVec(buffers, offset, length, IoVec.Direction.READV));
}

代码示例来源:origin: robovm/robovm

public long write(ByteBuffer[] buffers, int offset, int length) throws IOException {
  Arrays.checkOffsetAndCount(buffers.length, offset, length);
  checkOpen();
  checkWritable();
  return transferIoVec(new IoVec(buffers, offset, length, IoVec.Direction.WRITEV));
}

相关文章