Example usage for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException

List of usage examples for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException

Introduction

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

Prototype

public ArrayIndexOutOfBoundsException(int index) 

Source Link

Document

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

Usage

From source file:org.anarres.lzo.hadoop.codec.LzoCompressor.java

@Override
public int compress(byte[] b, int off, int len) throws IOException {
    // logState("Before compress");
    if (b == null)
        throw new NullPointerException();
    if (off < 0 || len < 0 || off > b.length - len)
        throw new ArrayIndexOutOfBoundsException(
                "Illegal range in buffer: Buffer length=" + b.length + ", offset=" + off + ", length=" + len);

    if (outputBufferLen.value == 0) {
        byte[] compressBuffer;
        int compressBufferPos;
        int compressBufferLen;

        // Do compression.
        if (inputBufferLen > 0) {
            compressBuffer = inputBuffer;
            compressBufferPos = 0;/*from  w  ww  .  java 2 s  .  co m*/
            compressBufferLen = inputBufferLen;
            inputBufferLen = 0;
        } else if (inputHoldoverBuffer != null) {
            compressBuffer = inputHoldoverBuffer;
            compressBufferPos = inputHoldoverBufferPos;
            // If this is ever less than inputBuffer.length, then we should have copied it into the input buffer.
            compressBufferLen = Math.min(inputBuffer.length, inputHoldoverBufferLen);
            assert compressBufferLen == inputBuffer.length : "Compressing less than one block of holdover.";
            inputHoldoverBufferPos += compressBufferLen;
            inputHoldoverBufferLen -= compressBufferLen;
        } else {
            throw new IllegalStateException("compress() called with no input.");
        }
        compact();

        // A sane implementation would do this here, but Hadoop breaks if we do.
        // inputByteCount += compressBufferLen;
        outputBufferPos = 0;
        outputBufferLen.value = outputBuffer.length;
        try {
            int code = compressor.compress(compressBuffer, compressBufferPos, compressBufferLen, outputBuffer,
                    outputBufferPos, outputBufferLen);
            if (code != LzoTransformer.LZO_E_OK) {
                logState("LZO error: " + code);
                // FileUtils.writeByteArrayToFile(new File("bytes.out"), Arrays.copyOfRange(compressBuffer, compressBufferPos, compressBufferPos + compressBufferLen));
                throw new IllegalArgumentException(compressor.toErrorString(code));
            }
        } catch (IndexOutOfBoundsException e) {
            logState("IndexOutOfBoundsException: " + e);
            // FileUtils.writeByteArrayToFile(new File("bytes.out"), Arrays.copyOfRange(compressBuffer, compressBufferPos, compressBufferPos + compressBufferLen));
            throw new IOException(e);
        }
        // LOG.info(compressBufferLen + "(" + Integer.toHexString(compressBufferLen) + ") -> " + outputBufferLen + "(" + Integer.toHexString(outputBufferLen.value) + ")");
    }

    len = Math.min(len, outputBufferLen.value);
    System.arraycopy(outputBuffer, outputBufferPos, b, off, len);
    outputBufferPos += len;
    outputBufferLen.value -= len;

    outputByteCount += len;

    // logState("After compress; len=" + len);
    return len;
}

From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java

@Override
public Iterable<IScan1D> subsetByScanAcquisitionTime(double startSat, double stopSat) {
    final int startIndex = getIndexFor(startSat);
    if (startIndex < 0) {
        throw new ArrayIndexOutOfBoundsException(startIndex);
    }//from   w w w  . j a  va2 s  . com
    final int stopIndex = getIndexFor(stopSat);
    if (stopIndex > getNumberOfScans() - 1) {
        throw new ArrayIndexOutOfBoundsException(stopIndex);
    }
    final Iterator<IScan1D> iter = new Iterator<IScan1D>() {
        private int currentPos = startIndex;

        @Override
        public boolean hasNext() {
            return this.currentPos < stopIndex;
        }

        @Override
        public IScan1D next() {
            return getScan(this.currentPos++);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Can not remove scans with iterator!");
        }
    };
    return new Iterable<IScan1D>() {
        @Override
        public Iterator<IScan1D> iterator() {
            return iter;
        }
    };
}

From source file:Matrix.java

/**
 * Get a submatrix.// w w w .  ja  v a 2  s  .c  o  m
 * 
 * @param r
 *            Array of row indices.
 * @param c
 *            Array of column indices.
 * @return A(r(:),c(:))
 * @exception ArrayIndexOutOfBoundsException
 *                Submatrix indices
 */

public Matrix getMatrix(int[] r, int[] c) {
    Matrix X = new Matrix(r.length, c.length);
    double[][] B = X.getArray();
    try {
        for (int i = 0; i < r.length; i++) {
            for (int j = 0; j < c.length; j++) {
                B[i][j] = A[r[i]][c[j]];
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Submatrix indices");
    }
    return X;
}

From source file:wordnice.api.Nice.java

public static void checkBounds(ByteSequence obj, int offset, int length)
        throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
    if (obj == null)
        throw Nice.illegal("Null sequence!");
    if (length < 0)
        throw new ArrayIndexOutOfBoundsException("Length (" + length + ") < 0");
    if (offset < 0)
        throw new ArrayIndexOutOfBoundsException("Offset (" + offset + ") < 0");
    if (offset + length > obj.length())
        throw new ArrayIndexOutOfBoundsException(
                "Offset+Length (" + (offset + length) + ") > Array length (" + obj.length() + ")");
}

From source file:Matrix.java

/**
 * Get a submatrix./*w ww .  j a v  a  2 s.  co m*/
 * 
 * @param i0
 *            Initial row index
 * @param i1
 *            Final row index
 * @param c
 *            Array of column indices.
 * @return A(i0:i1,c(:))
 * @exception ArrayIndexOutOfBoundsException
 *                Submatrix indices
 */

public Matrix getMatrix(int i0, int i1, int[] c) {
    Matrix X = new Matrix(i1 - i0 + 1, c.length);
    double[][] B = X.getArray();
    try {
        for (int i = i0; i <= i1; i++) {
            for (int j = 0; j < c.length; j++) {
                B[i - i0][j] = A[i][c[j]];
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Submatrix indices");
    }
    return X;
}

From source file:com.bah.culvert.adapter.RemotingIterator.java

@Override
public Result next() {
    /*// w w  w .ja  va 2  s.  c  o m
     * Add results to a result queue if we're out, if not just return what's
     * there.
     */
    if (resultQueue.size() > 0) {
        return resultQueue.poll();
    } else {
        List<Result> results = remoteTable.remoteExec(remoteStart, remoteEnd, NextResultGetter.class,
                conf.get(QUERY_ID_SETTING));
        List<Throwable> exceptions = new ArrayList<Throwable>(0);

        resultQueue.addAll(results);

        if (exceptions.size() > 0) {
            throw MultiRuntimeException.get(exceptions);
        }
        if (resultQueue.size() == 0) {
            throw new ArrayIndexOutOfBoundsException("No more results available from remote servers");
        }
        return resultQueue.poll();
    }
}

From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java

@Override
public Iterable<IScan1D> subsetByScanIndex(final int startIndex, final int stopIndex) {
    if (startIndex < 0) {
        throw new ArrayIndexOutOfBoundsException(startIndex);
    }//  w w  w . j a va 2 s .co m
    if (stopIndex > getNumberOfScans() - 1) {
        throw new ArrayIndexOutOfBoundsException(stopIndex);
    }
    final Iterator<IScan1D> iter = new Iterator<IScan1D>() {
        private int currentPos = startIndex;

        @Override
        public boolean hasNext() {
            return this.currentPos < stopIndex;
        }

        @Override
        public IScan1D next() {
            return getScan(this.currentPos++);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Can not remove scans with iterator!");
        }
    };
    return new Iterable<IScan1D>() {
        @Override
        public Iterator<IScan1D> iterator() {
            return iter;
        }
    };
}

From source file:Matrix.java

/**
 * Get a submatrix.//from   ww w  .j a  va  2s  . c o m
 * 
 * @param r
 *            Array of row indices.
 * @param j0
 *            Initial column index
 * @param j1
 *            Final column index
 * @return A(r(:),j0:j1)
 * @exception ArrayIndexOutOfBoundsException
 *                Submatrix indices
 */

public Matrix getMatrix(int[] r, int j0, int j1) {
    Matrix X = new Matrix(r.length, j1 - j0 + 1);
    double[][] B = X.getArray();
    try {
        for (int i = 0; i < r.length; i++) {
            for (int j = j0; j <= j1; j++) {
                B[i][j - j0] = A[r[i]][j];
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Submatrix indices");
    }
    return X;
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.ByteDataset.java

/**
 * Sets the value at a particular point to the passed value. Note, this will automatically expand the dataset if the
 * given position is outside its bounds and make it discontiguous.
 *
 * @param value//from   ww w.  j  a va2  s  .  co  m
 * @param pos
 */
public void setItem(final byte value, final int... pos) { // PRIM_TYPE
    try {
        if (!isPositionInShape(pos)) {
            int[] nshape = shape.clone();

            for (int i = 0; i < pos.length; i++)
                if (pos[i] >= nshape[i])
                    nshape[i] = pos[i] + 1;

            allocateArray(nshape);
        }
        setAbs(get1DIndex(pos), value);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                String.format("Dimensionalities of requested position, %d, and dataset, %d, are incompatible",
                        pos.length, shape.length));
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Index out of bounds - need to make dataset extendible");
    }
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.LongDataset.java

/**
 * Sets the value at a particular point to the passed value. Note, this will automatically expand the dataset if the
 * given position is outside its bounds and make it discontiguous.
 *
 * @param value/*from   w w w. ja  v  a 2  s  . c  o m*/
 * @param pos
 */
public void setItem(final long value, final int... pos) { // PRIM_TYPE
    try {
        if (!isPositionInShape(pos)) {
            int[] nshape = shape.clone();

            for (int i = 0; i < pos.length; i++)
                if (pos[i] >= nshape[i])
                    nshape[i] = pos[i] + 1;

            allocateArray(nshape);
        }
        setAbs(get1DIndex(pos), value);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                String.format("Dimensionalities of requested position, %d, and dataset, %d, are incompatible",
                        pos.length, shape.length));
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException("Index out of bounds - need to make dataset extendible");
    }
}