プログラミング雑談スレ++
■ このスレッドは過去ログ倉庫に格納されています
0714デフォルトの名無しさん
2013/11/23(土) 20:15:38.10先生、必要な例かどうかはわかりませんが、javaのクラスライブラリ、Stringクラスの例です。
/* Common private utility method used to bounds check the byte array
* and requested offset & length values used by the String(byte[],..)
* constructors.
*/
private static void checkBounds(byte[] bytes, int offset, int length) {
if (length < 0)
throw new StringIndexOutOfBoundsException(length);
if (offset < 0)
throw new StringIndexOutOfBoundsException(offset);
if (offset > bytes.length - length)
throw new StringIndexOutOfBoundsException(offset + length);
}
このチェックは、
public String(byte ascii[], int hibyte, int offset, int count)
public String(byte bytes[], int offset, int length, String charsetName)
public String(byte bytes[], int offset, int length)
から呼ばれているようです。
■ このスレッドは過去ログ倉庫に格納されています