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:org.cloudfoundry.client.lib.io.DynamicInputStream.java

@Override
public int read(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }/*from   w  w w. jav a 2 s .com*/
    if (off < 0 || len < 0 || len > (b.length - off)) {
        throw new IndexOutOfBoundsException();
    }
    if (len == 0) {
        return 0;
    }
    return doRead(b, off, len, true);
}

From source file:api.util.JsonArrayList.java

@Override
public void add(int index, T element) {
    if (index != size())
        throw new UnsupportedOperationException();
    try {//  w  w w. java  2s.  c  o  m
        array.put(index, write(element));
    } catch (JSONException e) {
        throw new IndexOutOfBoundsException();
    }
}

From source file:edu.dfci.cccb.mev.domain.MatrixData.java

/**
 * Gets the matrix values as a single dimmensional array row by row
 * /*from   ww  w  .ja  v a 2  s.co  m*/
 * @return
 */
@JsonView
public List<Double> values() {
    return new AbstractList<Double>() {

        /* (non-Javadoc)
         * @see java.util.AbstractList#get(int) */
        @Override
        public Double get(int index) {
            if (data == null)
                throw new IndexOutOfBoundsException();
            try {
                return data.getEntry(index / data.getColumnDimension(), index % data.getColumnDimension());
            } catch (OutOfRangeException e) {
                throw new IndexOutOfBoundsException();
            }
        }

        /* (non-Javadoc)
         * @see java.util.AbstractCollection#size() */
        @Override
        public int size() {
            return data == null ? 0 : data.getColumnDimension() * data.getRowDimension();
        }
    };
}

From source file:net.daporkchop.porkselfbot.command.base.CommandGET.java

@Override
public void excecute(MessageReceivedEvent evt, String[] a, String message) {
    try {/*from   www .  j a  v a  2 s . c om*/
        YMLParser yml = new YMLParser();
        yml.loadRaw(message.substring(6));
        String url = yml.get("url", null);

        if (url == null) {
            throw new IndexOutOfBoundsException();
            //sends the error message
        }

        UrlValidator validator = new UrlValidator();
        if (validator.isValid(url)) {
            String data = HTTPUtils.performGetRequest(HTTPUtils.constantURL(url));

            String toSend = "GET result from `" + url + "`:\n\n```html\n" + data + "\n```";

            if (toSend.length() < 2000) {
                evt.getMessage().editMessage(toSend).queue();
            } else {
                evt.getMessage().editMessage("*Output too long!*").queue();
            }
        } else {
            evt.getMessage().editMessage("Invalid URL: `" + url + "`").queue();
        }
    } catch (IndexOutOfBoundsException e) {
        this.sendErrorMessage(evt, "Not enough arguments!");
    } catch (IOException e) {
        this.sendErrorMessage(evt, "IOException lol");
    } catch (YAMLException e) {
        evt.getMessage().editMessage("Bad YML formatting!").queue();
    }
}

From source file:api.util.JsonArrayList.java

@Override
public T set(int index, T element) {
    if (index >= size())
        throw new IndexOutOfBoundsException();
    try {/* w  w  w  . ja  v a2 s  .  com*/
        Object was = array.opt(index);
        array.put(index, write(element));
        return read(was);
    } catch (JSONException e) {
        throw new IndexOutOfBoundsException();
    }
}

From source file:FastMultiByteArrayInputStream.java

@Override
public int read(final byte b[], int off, int len) {
    if (b == null) {
        throw new NullPointerException();
    } else if (off < 0 || len < 0 || len > b.length - off) {
        throw new IndexOutOfBoundsException();
    }//  w  w  w  .  j  av  a  2  s  .  c o  m
    if (_pos >= _count) {
        return -1;
    }
    if (_pos + len > _count) {
        len = _count - _pos;
    }
    if (len <= 0) {
        return 0;
    }
    final int limit = _pos + len;
    for (int n = _pos; n < limit;) {
        final byte[] block = getCurBlock(n);
        final int numleft = _blocksize - _curBlockOffset;
        final int copylen = Math.min(limit - n, numleft);
        System.arraycopy(block, _curBlockOffset, b, off, copylen);
        _curBlockOffset += copylen;
        off += copylen;
        n += copylen;
    }
    _pos += len;
    return len;
}

From source file:net.daporkchop.porkselfbot.command.base.CommandPOST.java

@Override
public void excecute(MessageReceivedEvent evt, String[] args, String message) {
    try {/*from  ww w .j a  v  a  2  s . c  o  m*/
        YMLParser yml = new YMLParser();
        yml.loadRaw(message.substring(7));
        String url = yml.get("url", null);
        String content = yml.get("content", null);

        if (url == null) {
            throw new IndexOutOfBoundsException();
            //sends the error message
        }

        boolean doAuth = yml.getBoolean("doAuth", false);
        String contentType = yml.get("contentType", "text/plain");
        String authKey = yml.get("authKey", null);

        UrlValidator validator = new UrlValidator();
        if (validator.isValid(url)) {
            URL urI = HTTPUtils.constantURL(url);

            if (doAuth) {
                if (authKey == null) {
                    evt.getMessage().editMessage("Auth key not given!").queue();
                    return;
                }

                String data = HTTPUtils.performPostRequestWithAuth(urI, content, contentType, authKey);

                String toSend = "POST result from `" + url + "` (with auth):\n\n```html\n" + data + "\n```";

                if (toSend.length() < 2000) {
                    evt.getMessage().editMessage(toSend).queue();
                } else {
                    evt.getMessage().editMessage("*Output too long!*").queue();
                }
            } else {
                String data = HTTPUtils.performPostRequest(urI, content, contentType);

                String toSend = "POST result from `" + url + "`:\n\n```html\n" + data + "\n```";

                if (toSend.length() < 2000) {
                    evt.getMessage().editMessage(toSend).queue();
                } else {
                    evt.getMessage().editMessage("*Output too long!*").queue();
                }
            }
        } else {
            evt.getMessage().editMessage("Invalid URL: `" + url + "`").queue();
        }
    } catch (IndexOutOfBoundsException e) {
        this.sendErrorMessage(evt, "Not enough arguments!");
    } catch (IOException e) {
        this.sendErrorMessage(evt, "IOException lol");
    } catch (YAMLException e) {
        evt.getMessage().editMessage("Bad YML formatting!").queue();
    }
}

From source file:com.github.jknack.handlebars.internal.FastStringWriter.java

@Override
public void write(final char[] buffer, final int off, final int len) throws IOException {
    if (off < 0 || off > buffer.length || len < 0 || off + len > buffer.length || off + len < 0) {
        throw new IndexOutOfBoundsException();
    } else if (len == 0) {
        return;//w ww  .  ja va  2  s. c  o  m
    }
    this.buffer.append(buffer, off, len);
}

From source file:com.github.rvesse.airline.restrictions.common.NotEmptyRestriction.java

@Override
public String[] getContentBlock(int blockNumber) {
    if (blockNumber != 0)
        throw new IndexOutOfBoundsException();

    return new String[] { "This options value cannot be empty" };
}

From source file:ca.farrelltonsolar.classic.ChargeControllers.java

public boolean setCurrent(int position) {
    if (position >= devices.size()) {
        throw new IndexOutOfBoundsException();
    }// w  ww  . j ava  2s .  c o  m
    synchronized (devices) {
        for (int index = 0; index < devices.size(); index++) {
            ChargeController cc = devices.get(index);
            if (cc.isCurrent() && index == position) {
                return false; // already current
            } else {
                cc.setIsCurrent(false);
            }
        }
        ChargeControllerInfo cc = devices.get(position);
        if (cc.deviceType() != DeviceType.Unknown) {
            devices.get(position).setIsCurrent(true);
        } else {
            return false; // can't do it, unknown device
        }
    }
    return true;
}