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() 

Source Link

Document

Constructs an IndexOutOfBoundsException with no detail message.

Usage

From source file:ClosableCharArrayWriter.java

/**
 * Efficiently writes the designated portion of the designated string. 
 *
 * The operation occurs as if by calling
 * <tt>str.getChars(off, off + len, buf, count)</tt>. 
 *
 * @param str the string from which to write
 * @param off the start offset in the string.
 * @param len the number of characters to write.
 * @throws java.io.IOException if an I/O error occurs.
 *      In particular, an <tt>IOException</tt> may be thrown
 *      if this writer has been {@link #close() closed}.
 *///from  w  w  w. j a va 2 s.  c  o m
public synchronized void write(String str, int off, int len) throws IOException {

    checkClosed();

    int strlen = str.length();

    if ((off < 0) || (off > strlen) || (len < 0) || ((off + len) > strlen) || ((off + len) < 0)) {
        throw new IndexOutOfBoundsException();
    } else if (len == 0) {
        return;
    }

    int newcount = count + len;

    if (newcount > buf.length) {
        buf = copyOf(buf, Math.max(buf.length << 1, newcount));
    }

    str.getChars(off, off + len, buf, count);

    count = newcount;
}

From source file:fr.limsi.ARViewer.CharArrayBuffer.java

public String substring(int beginIndex, int endIndex) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException();
    }/*from  w w w  .  jav  a2  s. c  om*/
    if (endIndex > this.len) {
        throw new IndexOutOfBoundsException();
    }
    if (beginIndex > endIndex) {
        throw new IndexOutOfBoundsException();
    }
    return new String(this.buffer, beginIndex, endIndex - beginIndex);
}

From source file:com.glaf.core.util.ByteBufferUtils.java

/**
 * Transfer bytes from one ByteBuffer to another. This function acts as
 * System.arrayCopy() but for ByteBuffers.
 * //w  w  w  .  j  a  va2  s . c  o  m
 * @param src
 *            the source ByteBuffer
 * @param srcPos
 *            starting position in the source ByteBuffer
 * @param dst
 *            the destination ByteBuffer
 * @param dstPos
 *            starting position in the destination ByteBuffer
 * @param length
 *            the number of bytes to copy
 */
public static void arrayCopy(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int length) {
    if (src.hasArray() && dst.hasArray()) {
        System.arraycopy(src.array(), src.arrayOffset() + srcPos, dst.array(), dst.arrayOffset() + dstPos,
                length);
    } else {
        if (src.limit() - srcPos < length || dst.limit() - dstPos < length)
            throw new IndexOutOfBoundsException();

        for (int i = 0; i < length; i++)

            dst.put(dstPos++, src.get(srcPos++));
    }
}

From source file:com.thoughtworks.go.config.merge.MergePipelineConfigs.java

@Override
public PipelineConfig remove(int i) {
    if (i < 0)
        throw new IndexOutOfBoundsException();

    int start = 0;
    for (PipelineConfigs part : this.parts) {
        int end = start + part.size();
        if (i < end)
            return part.remove(i - start);
        start = end;/*from w  w  w  .  j a  va 2  s  .  co  m*/
    }
    throw new IndexOutOfBoundsException();
}

From source file:MiniMap.java

/**
 * @see java.util.Map#values()//w  w  w. j  av a 2s.  c  o  m
 */
public Collection<V> values() {
    return new AbstractList<V>() {
        @Override
        public V get(final int index) {
            if (index > size - 1) {
                throw new IndexOutOfBoundsException();
            }
            int keyIndex = nextKey(0);

            for (int i = 0; i < index; i++) {
                keyIndex = nextKey(keyIndex + 1);
            }

            return values[keyIndex];
        }

        @Override
        public int size() {
            return size;
        }
    };
}

From source file:com.ibm.og.s3.v4.AwsChunkedEncodingInputStream.java

@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
    abortIfNeeded();/*from www  .  java  2 s.c om*/
    if (b == null) {
        throw new NullPointerException();
    } else if (off < 0 || len < 0 || len > b.length - off) {
        throw new IndexOutOfBoundsException();
    } else if (len == 0) {
        return 0;
    }

    if (null == this.currentChunkIterator || !this.currentChunkIterator.hasNext()) {
        if (this.isTerminating) {
            return -1;
        } else {
            this.isTerminating = setUpNextChunk();
        }
    }

    final int count = this.currentChunkIterator.read(b, off, len);
    if (count > 0) {
        this.isAtStart = false;
        if (log.isTraceEnabled()) {
            log.trace(count + " byte read from the stream.");
        }
    }
    return count;
}

From source file:com.replaymod.replaystudio.collection.PacketList.java

@Override
public PacketData get(int index) {
    try {/* w ww. ja v  a2 s  . co m*/
        return listIterator(index).next();
    } catch (NoSuchElementException e) {
        throw new IndexOutOfBoundsException();
    }
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java

protected Object set(InternalEObject object, EReference eReference, int index, EObject value) {
    Object returnValue = null;// w ww  .j a v a 2s. c  o  m
    Vertex vertex = graph.getOrCreateVertex(object);
    Vertex newReferencedVertex = graph.getOrCreateVertex(value);

    // Update the containment reference if needed
    if (eReference.isContainment()) {
        updateContainment(eReference, vertex, newReferencedVertex);
    }

    if (!eReference.isMany()) {
        Iterator<Edge> iterator = vertex.getEdges(Direction.OUT, eReference.getName()).iterator();
        if (iterator.hasNext()) {
            Edge edge = iterator.next();
            Vertex referencedVertex = edge.getVertex(Direction.IN);
            returnValue = reifyVertex(referencedVertex);
            edge.remove();
        }
        vertex.addEdge(eReference.getName(), newReferencedVertex);
    } else {
        Integer size = getSize(vertex, eReference);
        if (index < 0 || index >= size) {
            throw new IndexOutOfBoundsException();
        } else {
            Iterator<Edge> iterator = vertex.query().labels(eReference.getName()).direction(Direction.OUT)
                    .has(POSITION, index).edges().iterator();
            if (iterator.hasNext()) {
                Edge edge = iterator.next();
                Vertex referencedVertex = edge.getVertex(Direction.IN);
                returnValue = reifyVertex(referencedVertex);
                edge.remove();
            }
            Edge edge = vertex.addEdge(eReference.getName(), newReferencedVertex);
            edge.setProperty(POSITION, index);
        }
    }
    return returnValue;
}

From source file:fr.limsi.ARViewer.CharArrayBuffer.java

public String substringTrimmed(int beginIndex, int endIndex) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException();
    }//  w  ww.j a  v a 2 s  . c om
    if (endIndex > this.len) {
        throw new IndexOutOfBoundsException();
    }
    if (beginIndex > endIndex) {
        throw new IndexOutOfBoundsException();
    }
    while (beginIndex < endIndex && isWhitespace(this.buffer[beginIndex])) {
        beginIndex++;
    }
    while (endIndex > beginIndex && isWhitespace(this.buffer[endIndex - 1])) {
        endIndex--;
    }
    return new String(this.buffer, beginIndex, endIndex - beginIndex);
}

From source file:com.buaa.cfs.fs.FSInputChecker.java

/**
 * Read checksum verified bytes from this byte-input stream into the specified byte array, starting at the given
 * offset.//from w ww .  j  a  va  2 s. co m
 * <p>
 * <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>
 * <p>
 * <li> The specified number of bytes have been read,
 * <p>
 * <li> The <code>read</code> method of the underlying stream returns <code>-1</code>, indicating end-of-file.
 * <p>
 * </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.
 *
 * @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.
 *
 * @throws IOException if an I/O error occurs. ChecksumException if any checksum error occurs
 */
@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
    // parameter check
    if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
        throw new IndexOutOfBoundsException();
    } else if (len == 0) {
        return 0;
    }

    int n = 0;
    for (;;) {
        int nread = read1(b, off + n, len - n);
        if (nread <= 0)
            return (n == 0) ? nread : n;
        n += nread;
        if (n >= len)
            return n;
    }
}