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


Java ArrayIndexOutOfBoundsException类代码示例

本文整理汇总了Java中java.lang.ArrayIndexOutOfBoundsException的典型用法代码示例。如果您正苦于以下问题:Java ArrayIndexOutOfBoundsException类的具体用法?Java ArrayIndexOutOfBoundsException怎么用?Java ArrayIndexOutOfBoundsException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: putString

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
/**
 * Place a string into the message (using UTF-8 encoding)
 */
public void putString(String s) throws ArrayIndexOutOfBoundsException, UnsupportedEncodingException
{
	/* convert the string into a byte array */
	byte[] bytes = s.getBytes("UTF-8"); //$NON-NLS-1$
	int length = bytes.length;
	int endAt = m_index + length + 1;

	if (endAt > m_content.length)
		throw new ArrayIndexOutOfBoundsException(endAt+" > "+m_content.length); //$NON-NLS-1$

	/* copy the string as a byte array */
	System.arraycopy(bytes, 0, m_content, m_index, length);
	m_index += length;

	/* now the null terminator */
	m_content[m_index++] = '\0';
	
	debugAppendString(s);
}
 
开发者ID:BowlerHatLLC,项目名称:feathers-sdk,代码行数:23,代码来源:DMessage.java

示例2: setModificationIteratorInitAt

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
@Override
public void setModificationIteratorInitAt(int index, boolean _modificationIteratorInit) {
    if (index < 0 || index >= 128) {
        throw new ArrayIndexOutOfBoundsException(index + " is out of bounds, array length 128");
    }
    int bitOffset = 240 + index;
    int byteOffset = bitOffset / 8;
    int bitShift = bitOffset & 7;
    int b = bs.readByte(offset + byteOffset);
    if (_modificationIteratorInit) {
        b |= (1 << bitShift);
    } else {
        b &= ~(1 << bitShift);
    }
    bs.writeByte(offset + byteOffset, (byte) b);
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:17,代码来源:ReplicatedGlobalMutableState$$Native.java

示例3: test1

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
public Result test1() {
    int length = 20000;
    int index[] = new int[length];
    byte arr[] = new byte[length];
    try {
        for (int k = 0; k < length; k=+2) {
            arr[index[k] - 10000000] -= index[k];
        }
        return failed("TEST FAILED: ArrayIndexOutOfBoundsException " +
                "wasn't thrown");
    } catch (ArrayIndexOutOfBoundsException ae) {
        return passed();
    } catch (Throwable e) {
        log.add(e);
        return failed("TEST FAILED: unexpected " + e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:18,代码来源:Test9.java

示例4: test2

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
public Result test2() {
    int length = 10000;
    int index[] = new int[length];
    long arr[] = new long[length];
    index[1] = length-1;
    int neg = -1;
    try {
        for (int k = length-1; k>0; k--) {
            arr[index[k] - neg] = 0;
        }
        return failed("TEST FAILED: ArrayIndexOutOfBoundsException " +
                "wasn't thrown");
    } catch (ArrayIndexOutOfBoundsException ae) {
        return passed();
    } catch (Throwable e) {
        log.add(e);
        return failed("TEST FAILED: unexpected " + e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:20,代码来源:Test9.java

示例5: test

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
public int test() {
    log.info("Start Test1 ...");
    try {
        boolean flag = false;
        int limit = 25000;
        Object[] obj = new Object[limit];
        for (int i=0; i<limit; i++) {
            try {
                obj[i] = String.valueOf(i);
            } finally {
                if (i > limit/2) flag = true;
                if (flag) obj = new Object[limit-1];
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        return pass();
    }
    return fail("TEST FAILED: ArrayIndexOutOfBoundsException " +
            " wasn't thrown");
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:21,代码来源:Test1.java

示例6: log

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
public void log(LogType t, String s) {
    try {
        this.queue.add(new LogItem(t, s));
    } catch (ArrayIndexOutOfBoundsException ex) {
        /* At shutdown this throws an exception. */
    }
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:8,代码来源:Logger.java

示例7: setStudent

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
/**
 * Sets the String element in the layout array to a name if it is a valid position 
 * pre: none
 * post: none
 */
public void setStudent(String name, int x, int y) {
    try {
        layout[y][x] = name;
        seatInvalid = false;
    } catch (ArrayIndexOutOfBoundsException e) {
        seatInvalid = true;
        System.out.println("(" + (x + 1) + ", " + (y + 1) + ") is not a valid seat.");
    }
}
 
开发者ID:ErikHumphrey,项目名称:ics4u,代码行数:15,代码来源:SeatingPlan.java

示例8: get

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
private long get(int bytes) throws ArrayIndexOutOfBoundsException
{
	if (m_index+bytes > m_content.length)
		throw new ArrayIndexOutOfBoundsException(m_content.length-m_index+" < "+bytes); //$NON-NLS-1$

	long value = 0;
	for (int i=0; i<bytes; ++i) {
		long byteValue = m_content[m_index++] & 0xff;
		long byteValueShifted = byteValue << (8*i);
		value |= byteValueShifted;
	}

	debugAppendNumber(value, bytes);
	return value;
}
 
开发者ID:BowlerHatLLC,项目名称:feathers-sdk,代码行数:16,代码来源:DMessage.java

示例9: getString

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
/**
 * Heart wrenchingly slow but since we don't have a length so we can't
 * do much better
 */
public String getString() throws ArrayIndexOutOfBoundsException
{
	int startAt = m_index;
	boolean done = false;

	/* scan looking for a terminating null */
	while(!done)
	{
	    int ch = m_content[m_index++];
		if (ch == 0)
			done = true;
		else if (m_index > m_content.length)
			throw new ArrayIndexOutOfBoundsException("no string terminator found @"+m_index); //$NON-NLS-1$
	}

	/* build a new string and return it */
	String s;
	try
	{
		// The player uses UTF-8
		s = new String(m_content, startAt, m_index-startAt-1, "UTF-8"); //$NON-NLS-1$
	}
	catch(UnsupportedEncodingException uee)
	{
		// couldn't convert so let's try the default
		s = new String(m_content, startAt, m_index-startAt-1);
	}
	debugAppendString(s);
	return s;
}
 
开发者ID:BowlerHatLLC,项目名称:feathers-sdk,代码行数:35,代码来源:DMessage.java

示例10: put

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
/**
 * Appends a number to the end of the message
 * @param val the number
 * @param bytes how many bytes should be written
 */
public void put(long val, int bytes) throws ArrayIndexOutOfBoundsException
{
	if (m_index+bytes > m_content.length)
		throw new ArrayIndexOutOfBoundsException(m_content.length-m_index+" < "+bytes); //$NON-NLS-1$

	for (int i=0; i<bytes; ++i)
		m_content[m_index++] = (byte)(val >> 8*i);

	debugAppendNumber(val, bytes);
}
 
开发者ID:BowlerHatLLC,项目名称:feathers-sdk,代码行数:16,代码来源:DMessage.java

示例11: test

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    ArrayIndexOutOfBoundsException object1 = new ArrayIndexOutOfBoundsException();
    harness.check(object1 != null);
    harness.check(object1.toString(), "java.lang.ArrayIndexOutOfBoundsException");

    ArrayIndexOutOfBoundsException object2 = new ArrayIndexOutOfBoundsException("nothing happens");
    harness.check(object2 != null);
    harness.check(object2.toString(), "java.lang.ArrayIndexOutOfBoundsException: nothing happens");

    ArrayIndexOutOfBoundsException object3 = new ArrayIndexOutOfBoundsException(null);
    harness.check(object3 != null);
    harness.check(object3.toString(), "java.lang.ArrayIndexOutOfBoundsException");

    ArrayIndexOutOfBoundsException object4 = new ArrayIndexOutOfBoundsException(0);
    harness.check(object4 != null);
    harness.check(object4.toString(), "java.lang.ArrayIndexOutOfBoundsException: 0");

    ArrayIndexOutOfBoundsException object5 = new ArrayIndexOutOfBoundsException(-1);
    harness.check(object5 != null);
    harness.check(object5.toString(), "java.lang.ArrayIndexOutOfBoundsException: -1");

    ArrayIndexOutOfBoundsException object6 = new ArrayIndexOutOfBoundsException(Integer.MAX_VALUE);
    harness.check(object6 != null);
    harness.check(object6.toString(), "java.lang.ArrayIndexOutOfBoundsException: 2147483647");

}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:33,代码来源:constructor.java

示例12: test

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    // flag that is set when exception is caught
    boolean caught = false;
    try {
        throw new ArrayIndexOutOfBoundsException("ArrayIndexOutOfBoundsException");
    }
    catch (ArrayIndexOutOfBoundsException e) {
        // correct exception was caught
        caught = true;
    }
    harness.check(caught);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:19,代码来源:TryCatch.java

示例13: getModificationIteratorInitAt

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
@Override
public boolean getModificationIteratorInitAt(int index) {
    if (index < 0 || index >= 128) {
        throw new ArrayIndexOutOfBoundsException(index + " is out of bounds, array length 128");
    }
    int bitOffset = 240 + index;
    int byteOffset = bitOffset / 8;
    int bitShift = bitOffset & 7;
    return (bs.readByte(offset + byteOffset) & (1 << bitShift)) != 0;
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Map,代码行数:11,代码来源:ReplicatedGlobalMutableState$$Native.java

示例14: test

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
public int test() {
    log.info("Start Test3 ...");
    int arr[] = new int[limit];
    arr[1] = 1;
    try {
        for(int k=1; k<limit; ) {
            log.info("k=" + k + ": arr[" + (k-1) + "] will be called");
            k=arr[k-1];
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        return pass();
    }
    return fail("TEST FAILED: ArrayIndexOutOfBoundsException wasn't thrown");
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:15,代码来源:Test3.java

示例15: test

import java.lang.ArrayIndexOutOfBoundsException; //导入依赖的package包/类
public int test() {
    log.info("Start Test2 ...");
    try {
        Thread[] threads = new Thread[limit];
        for (i=0; i<limit; i++) {
            if (i == (limit-1))  meth();
            threads[i] = threads[i]; 
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        return pass();
    }
    return fail("TEST FAILED: ArrayIndexOutOfBoundsException " +
            " wasn't thrown");
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:15,代码来源:Test2.java


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