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

Source Link

Document

Constructs an ArrayIndexOutOfBoundsException with no detail message.

Usage

From source file:edu.vt.middleware.ldap.search.PeopleSearch.java

/**
 * This provides command line access to a <code>PeopleSearch</code>.
 *
 * @param  args  <code>String[]</code>
 *
 * @throws  Exception  if an error occurs
 *///from   w  w  w .ja  v a  2 s .  c  o  m
public static void main(final String[] args) throws Exception {
    final PeopleSearch ps = createFromSpringContext("/peoplesearch-context.xml", "peopleSearch");
    final Query query = new Query();
    final List<String> attrs = new ArrayList<String>();

    try {
        for (int i = 0; i < args.length; i++) {
            if ("-query".equals(args[i])) {
                query.setRawQuery(args[++i]);
            } else {
                attrs.add(args[i]);
            }
        }

        if (query.getRawQuery() == null) {
            throw new ArrayIndexOutOfBoundsException();
        }

        if (!attrs.isEmpty()) {
            query.setQueryAttributes(attrs.toArray(new String[0]));
        }
        ps.search(query, OutputFormat.LDIF, new BufferedWriter(new OutputStreamWriter(System.out)));

    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("Usage: java " + PeopleSearch.class.getName() + " -query <query> <attributes>");
        System.exit(1);
    }
}

From source file:com.lfv.lanzius.Main.java

public static void main(String[] args) {

    /*/*from  w w w.ja v  a 2  s.  co m*/
     * debug levels:
     * error - Runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. See also Internationalization.
     * warn  - Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. See also Internationalization.
     * info  - Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. See also Internationalization.
     * debug - detailed information on the flow through the system. Expect these to be written to logs only.
     */

    Log log = null;
    DOMConfigurator conf = new DOMConfigurator();
    DOMConfigurator.configure("data/properties/loggingproperties.xml");
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");

    try {
        if (args.length >= 1) {
            // Help
            if (args[0].startsWith("-h")) {
                printUsage();
                return;
            }
            // List devices
            else if (args[0].startsWith("-l")) {
                AudioTest.listDevices();
                return;
            }
            // Test seleted device
            else if (args[0].startsWith("-d")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "warn");
                try {
                    String option = "all";
                    if (args.length >= 4)
                        option = args[3];

                    if (option.equals("loop:direct"))
                        AudioTest.testDevicesDirect(Integer.parseInt(args[1]), Integer.parseInt(args[2]));
                    else {
                        if (option.indexOf("debug") != -1)
                            System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "debug");

                        AudioTest.testDevices(Integer.parseInt(args[1]), Integer.parseInt(args[2]), option,
                                (args.length >= 5) ? args[4] : null, (args.length >= 6) ? args[5] : null,
                                (args.length >= 7) ? args[6] : null);
                    }
                } catch (Exception ex) {
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println(
                            "  yada.jar -d output_device input_device <option> <jitter_buffer> <output_buffer> <input_buffer>");
                    System.out.println("  option:");
                    System.out.println("    all(default)");
                    System.out.println("    clip");
                    System.out.println("    loop:jspeex");
                    System.out.println("    loop:null");
                    System.out.println("    loop:direct");
                    System.out.println("    loopdebug:jspeex");
                    System.out.println("    loopdebug:null");
                    System.out.println("  jitter_buffer:");
                    System.out.println("    size of jitter buffer in packets (1-20)");
                    System.out.println("  output_buffer:");
                    System.out.println("    size of output buffer in packets (1.0-4.0)");
                    System.out.println("  input_buffer:");
                    System.out.println("    size of input buffer in packets (1.0-4.0)");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                //System.out.println("Exiting...");
                return;
            } else if (args[0].startsWith("-m")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "warn");
                try {
                    AudioTest.testMicrophoneLevel(Integer.parseInt(args[1]));
                } catch (Exception ex) {
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println("  yada.jar -m input_device");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                return;
            } else if (args[0].startsWith("-s")) {
                Packet.randomSeed = 9182736455L ^ System.currentTimeMillis();
                if (args.length > 2 && args[1].startsWith("-configuration")) {
                    String configFilename = args[2];
                    if (args.length > 4 && args[3].startsWith("-exercise")) {
                        String exerciseFilename = args[4];

                        LanziusServer.start(configFilename, exerciseFilename);
                    } else {
                        LanziusServer.start(configFilename);
                    }
                } else {
                    LanziusServer.start();
                }
                return;
            } else if (args[0].startsWith("-f")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty(
                        "org.apache.commons.logging.simplelog.log.com.lfv.lanzius.application.FootSwitchController",
                        "debug");
                try {
                    System.out.println("Starting footswitch controller test using device " + args[1]);
                    try {
                        boolean inverted = false;
                        if (args.length >= 3)
                            inverted = args[2].toLowerCase().startsWith("inv");
                        FootSwitchController c = new FootSwitchController(null, args[1],
                                Constants.PERIOD_FTSW_CONNECTED, inverted);
                        c.start();
                        Thread.sleep(30000);
                    } catch (UnsatisfiedLinkError err) {
                        if (args.length > 1)
                            System.out.println("UnsatisfiedLinkError: " + err.getMessage());
                        else
                            throw new ArrayIndexOutOfBoundsException();
                        System.out.println("Missing ftsw library (ftsw.dll or libftsw.so)");
                        if (!args[1].equalsIgnoreCase("ftdi"))
                            System.out
                                    .println("Missing rxtxSerial library (rxtxSerial.dll or librxtxSerial.so)");
                        if (AudioTest.showStackTrace)
                            err.printStackTrace();
                    }
                } catch (Exception ex) {
                    if (ex instanceof NoSuchPortException)
                        System.out.println("The serial port " + args[1] + " does not exist!");
                    else if (ex instanceof PortInUseException)
                        System.out.println("The serial port " + args[1] + " is already in use!");
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println("  yada.jar -f interface <invert>");
                    System.out.println("  interface:");
                    System.out.println("    ftdi");
                    System.out.println("    comport (COMx or /dev/ttyx)");
                    System.out.println("  invert:");
                    System.out.println("    true");
                    System.out.println("    false (default)");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                return;
            } else if (args[0].startsWith("-c")) {
                Packet.randomSeed = 7233103157L ^ System.currentTimeMillis();
                if (args.length >= 2) {
                    try {
                        int id = Integer.valueOf(args[1]);
                        if (id <= 0)
                            throw new NumberFormatException();
                        Controller c = Controller.getInstance();
                        if (args.length >= 3) {
                            if (args[2].equalsIgnoreCase("test")) {
                                c.setAutoTester(true);
                            }
                        }
                        c.init(id);
                        return;
                    } catch (NumberFormatException ex) {
                        printUsage();
                    }
                } else {
                    Controller.getInstance().init(0);
                }
            } else
                printUsage();
        } else
            printUsage();
    } catch (Throwable t) {
        if (log == null)
            log = LogFactory.getLog(Main.class);
        log.error("Unhandled exception or error", t);
    }
}

From source file:Main.java

public static int[] copyOfRange(int[] original, int start, int end) {
    if (start <= end) {
        if (original.length >= start && 0 <= start) {
            int length = end - start;
            int copyLength = Math.min(length, original.length - start);
            int[] copy = new int[length];
            System.arraycopy(original, start, copy, 0, copyLength);
            return copy;
        }/*from  w  ww  .  ja  v a  2  s  .  co  m*/
        throw new ArrayIndexOutOfBoundsException();
    }
    throw new IllegalArgumentException();
}

From source file:Main.java

/**
 * Split a byte array <tt>input</tt> into two arrays at <tt>index</tt>,
 * i.e. the first array will have the lower <tt>index</tt> bytes, the
 * second one the higher <tt>input.length - index</tt> bytes.
 *
 * @param input the byte array to be split
 * @param index the index where the byte array is split
 * @return the splitted input array as an array of two byte arrays
 * @throws ArrayIndexOutOfBoundsException if <tt>index</tt> is out of bounds
 *///from   w  ww  . j  av a2s  .c  o  m
public static byte[][] split(byte[] input, int index) throws ArrayIndexOutOfBoundsException {
    if (index > input.length) {
        throw new ArrayIndexOutOfBoundsException();
    }
    byte[][] result = new byte[2][];
    result[0] = new byte[index];
    result[1] = new byte[input.length - index];
    System.arraycopy(input, 0, result[0], 0, index);
    System.arraycopy(input, index, result[1], 0, input.length - index);
    return result;
}

From source file:Main.java

public static void checkOffsetAndCount(long arrayLength, long offset, long count) {
    if ((offset | count) < 0 || offset > arrayLength || arrayLength - offset < count) {
        throw new ArrayIndexOutOfBoundsException();
    }/* w  w w  .  j  a  v a2 s.co  m*/
}

From source file:Main.java

public static <T> List<T> sub(T[] source, int first, int last) {
    if (first < 0 || last < 0 || first >= source.length || last >= source.length)
        throw new ArrayIndexOutOfBoundsException();
    List<T> result = new ArrayList<T>();

    for (int i = first; i <= last; i++)
        result.add(source[i]);// www  .j a va  2 s  .c  om
    return result;
}

From source file:AssociativeArray.java

public void put(Object key, Object value) {
    if (index >= pairs.length)
        throw new ArrayIndexOutOfBoundsException();
    pairs[index++] = new Object[] { key, value };
}

From source file:com.cloudera.crunch.Pair.java

public Object get(int index) {
    switch (index) {
    case 0:/* ww  w .j  a v a  2  s. co  m*/
        return first;
    case 1:
        return second;
    default:
        throw new ArrayIndexOutOfBoundsException();
    }
}

From source file:Bag.java

/**
 * Retrieves an element/*from  w  ww  . ja v a  2s. c  om*/
 * 
 * @param index
 * @return the indexed element
 */
public T get(int index) {
    if (index >= size) {
        throw new ArrayIndexOutOfBoundsException();
    }
    return data[index];
}

From source file:com.cloudera.crunch.Tuple3.java

public Object get(int index) {
    switch (index) {
    case 0://  www  . j  a va  2s. c  om
        return first;
    case 1:
        return second;
    case 2:
        return third;
    default:
        throw new ArrayIndexOutOfBoundsException();
    }
}