Example usage for java.lang IndexOutOfBoundsException IndexOutOfBoundsException

List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException

Introduction

In this page you can find the example usage for java.lang IndexOutOfBoundsException IndexOutOfBoundsException.

Prototype

public IndexOutOfBoundsException(int index) 

Source Link

Document

Constructs a new IndexOutOfBoundsException class with an argument indicating the illegal index.

Usage

From source file:com.hypersocket.ui.ReaderInputStream.java

/**
 * Read the specified number of bytes into an array.
 *
 * @param b the byte array to read into/*  w ww.jav a  2 s .  c  o  m*/
 * @param off the offset to start reading bytes into
 * @param len the number of bytes to read
 * @return the number of bytes read or <code>-1</code>
 *         if the end of the stream has been reached
 * @throws IOException if an I/O error occurs
 */
@Override
public int read(final byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException("Byte array must not be null");
    }
    if (len < 0 || off < 0 || (off + len) > b.length) {
        throw new IndexOutOfBoundsException("Array Size=" + b.length + ", offset=" + off + ", length=" + len);
    }
    int read = 0;
    if (len == 0) {
        return 0; // Always return 0 if len == 0
    }
    while (len > 0) {
        if (encoderOut.hasRemaining()) {
            final int c = Math.min(encoderOut.remaining(), len);
            encoderOut.get(b, off, c);
            off += c;
            len -= c;
            read += c;
        } else {
            fillBuffer();
            if (endOfInput && !encoderOut.hasRemaining()) {
                break;
            }
        }
    }
    return read == 0 && endOfInput ? -1 : read;
}

From source file:com.netxforge.oss2.xml.event.Correlation.java

/**
 * /*from ww w.  j a v  a  2  s.  co  m*/
 * 
 * @param index
 * @param vCuei
 * @throws java.lang.IndexOutOfBoundsException if the index
 * given is outside the bounds of the collection
 */
public void setCuei(final int index, final java.lang.String vCuei) throws java.lang.IndexOutOfBoundsException {
    // check bounds for index
    if (index < 0 || index >= this._cueiList.size()) {
        throw new IndexOutOfBoundsException(
                "setCuei: Index value '" + index + "' not in range [0.." + (this._cueiList.size() - 1) + "]");
    }

    this._cueiList.set(index, vCuei);
}

From source file:jopt.csp.util.SortableIntList.java

private void checkRange(int index) {
    if (index < 0 || index >= size) {
        throw new IndexOutOfBoundsException("Should be at least 0 and less than " + size + ", found " + index);
    }//from  ww w. j a  v  a  2 s . co  m
}

From source file:com.jkoolcloud.tnt4j.streams.fields.StreamFieldType.java

/**
 * Gets the field enumeration object based on the enumeration's ordinal value.
 *
 * @param ordinal/*from  w w w .ja  va  2s .c o m*/
 *            enumeration ordinal value
 * @return field type enumeration object
 * @throws IndexOutOfBoundsException
 *             if ordinal value is outside the range of enumeration ordinal values
 */
public static StreamFieldType getType(int ordinal) {
    StreamFieldType[] enums = StreamFieldType.values();
    if (ordinal < 0 || ordinal >= enums.length) {
        throw new IndexOutOfBoundsException(StreamsResources.getStringFormatted(
                StreamsResources.RESOURCE_BUNDLE_NAME, "StreamFieldType.invalid.ordinal", ordinal,
                (enums.length - 1), StreamFieldType.class.getSimpleName()));
    }
    return enums[ordinal];
}

From source file:ch5ImageReader.java

private void checkIndex(int imageIndex) {
    if (imageIndex >= streammd.numberImages) {
        String argString = "imageIndex >= number of images";
        throw new IndexOutOfBoundsException(argString);
    }/*from www  .jav a 2  s .c  o  m*/
    if (imageIndex < minIndex) {
        String argString = "imageIndex < minIndex";
        throw new IndexOutOfBoundsException(argString);
    }
}

From source file:io.horizondb.io.buffers.AbstractBuffer.java

/**
 * {@inheritDoc}//from  ww w.jav  a  2  s . c om
 */
@Override
public Buffer readerIndex(int readerIndex) {

    if (this.writerIndex < readerIndex || readerIndex < 0) {

        @SuppressWarnings("boxing")
        String msg = String.format("readerIndex: %d " + "(expected: 0 <= readerIndex <= writerIndex(%d))",
                readerIndex, this.writerIndex);

        throw new IndexOutOfBoundsException(msg);
    }

    this.readerIndex = readerIndex;

    return this;
}

From source file:de.loercher.localpress.core.api.LocalPressController.java

@RequestMapping(value = "/**/**", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void defaultRequest() {
    throw new IndexOutOfBoundsException("There is no resource on this path.");
}

From source file:cn.com.sinosoft.util.exception.NestableDelegate.java

/**
 * Returns the index, numbered from 0, of the first <code>Throwable</code>
 * that matches the specified type, or a subclass, in the chain of <code>Throwable</code>s
 * with an index greater than or equal to the specified index.
 * The method returns -1 if the specified type is not found in the chain.
 * <p>//from  w w w.ja v a2s  . c o  m
 * NOTE: From v2.1, we have clarified the <code>Nestable</code> interface
 * such that this method matches subclasses.
 * If you want to NOT match subclasses, please use
 * {@link ExceptionUtils#indexOfThrowable(Throwable, Class, int)}
 * (which is avaiable in all versions of lang).
 * An alternative is to use the public static flag {@link #matchSubclasses}
 * on <code>NestableDelegate</code>, however this is not recommended.
 *
 * @param type  the type to find, subclasses match, null returns -1
 * @param fromIndex the index, numbered from 0, of the starting position in
 * the chain to be searched
 * @return index of the first occurrence of the type in the chain, or -1 if
 * the type is not found
 * @throws IndexOutOfBoundsException if the <code>fromIndex</code> argument
 * is negative or not less than the count of <code>Throwable</code>s in the
 * chain
 * @since 2.0
 */
public int indexOfThrowable(Class type, int fromIndex) {
    if (type == null) {
        return -1;
    }
    if (fromIndex < 0) {
        throw new IndexOutOfBoundsException("The start index was out of bounds: " + fromIndex);
    }
    Throwable[] throwables = ExceptionUtils.getThrowables(this.nestable);
    if (fromIndex >= throwables.length) {
        throw new IndexOutOfBoundsException(
                "The start index was out of bounds: " + fromIndex + " >= " + throwables.length);
    }
    if (matchSubclasses) {
        for (int i = fromIndex; i < throwables.length; i++) {
            if (type.isAssignableFrom(throwables[i].getClass())) {
                return i;
            }
        }
    } else {
        for (int i = fromIndex; i < throwables.length; i++) {
            if (type.equals(throwables[i].getClass())) {
                return i;
            }
        }
    }
    return -1;
}

From source file:com.kunckle.jetpower.core.base.repository.impl.BaseRepositorySupport.java

/**
 * //ww w.  j  ava  2 s  .com
 *
 * @param pageAdapter ?
 * @return null
 * @throws IndexOutOfBoundsException
 */
@Override
@SuppressWarnings("unchecked")
public Page<E> findAll(PageAdapter pageAdapter) {
    Query query = getSession().createQuery(
            "from " + entityClass.getSimpleName() + " " + pageAdapter.getPageSortAdapter().getPrepQL());
    pageAdapter.setCountOfElements(count());
    if (pageAdapter.exists() && pageAdapter.getPageNumber() != 0) {
        throw new IndexOutOfBoundsException("?");
    } else if (pageAdapter.getCountOfElements() == 0) {
        return null;
    }
    query.setFirstResult(pageAdapter.getPageOffset() * pageAdapter.getPageSize());
    query.setMaxResults(pageAdapter.getPageSize());
    return new Page<E>(pageAdapter, query.list());
}

From source file:edu.cornell.med.icb.goby.modes.TabToColumnInfoMode.java

/**
 * Get a specific column details based on the order of the input filenames given.
 * @param index the index of results to retrieve
 * @return the details for the specified index
 * @throws IndexOutOfBoundsException if index provided is too large
 *///from   w  w  w . j  av a  2s . c o  m
public Map<String, ColumnType> getDetailsAtIndex(final int index) throws IndexOutOfBoundsException {
    if (index < 0) {
        throw new IndexOutOfBoundsException("Index must be >= 0");
    }
    final int maxIndex = filenameToDetailsMap.size() - 1;
    if (index > maxIndex) {
        throw new IndexOutOfBoundsException("Index" + index + " should have been <= " + maxIndex);
    }

    final String[] inputFilenamesAsArray = inputFilenames.toArray(new String[inputFilenames.size()]);
    return filenameToDetailsMap.get(inputFilenamesAsArray[index]);
}