List of usage examples for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException
public ArrayIndexOutOfBoundsException(int index)
From source file:com.sababado.network.AsyncServiceCallTask.java
@Override protected Bundle doInBackground(Void... args) { mRunning = true;//from w w w . j av a2 s. co m log(LOG_TYPE_DEBUG, "****in AsyncServiceCallTask do in Background"); int attempts = 0; if (!UtilNetwork.isNetworkAvailable(mContext)) { Bundle responseBundle = new Bundle(); responseBundle.putString(EXTRA_ERR_MSG, "Sorry, there is limited or no connectivity. Please try again later."); responseBundle.putInt(EXTRA_ERR_CODE, ERR_CODE_NO_NETWORK); return responseBundle; } //get names and values String[] paramNames = mService.getAllParamNames(); String[] paramValues = mService.getAllParamValues(); //build parameter list String paramString = ""; if (paramNames != null && paramNames.length > 0) { try { //this assumes there is a 1 to 1 number of names and values List<NameValuePair> nvPairs = new LinkedList<NameValuePair>(); for (int i = 0; i < paramNames.length; i++) { nvPairs.add(new BasicNameValuePair(paramNames[i], paramValues[i])); } paramString = URLEncodedUtils.format(nvPairs, "utf-8"); } catch (ArrayIndexOutOfBoundsException e) { String message = "Failed paring param names and values (Index out of bounds). Make sure the there are the same number of param names and values."; log(LOG_TYPE_ERROR, message); throw new ArrayIndexOutOfBoundsException(message); } } String url = mService.getUrl(); //format the url string if (paramString.length() > 0) { //format url to have parameters only if there are parameters to add. if (!url.endsWith("?")) url += "?"; url += paramString; } log(LOG_TYPE_DEBUG, "Url: " + url); HttpResponse response = null; //while under the maximum number of attempts... while (attempts < MAX_ATTEMPTS) { try { log(LOG_TYPE_DEBUG, (attempts + 1) + "/" + MAX_ATTEMPTS + ": Creating Http Client"); //create the HttpClient HttpClient client = new DefaultHttpClient(); //set the request switch (mService.getCallType()) { case Service.CALL_TYPE_GET: log(LOG_TYPE_DEBUG, "Making GET Call"); HttpGet getRequest = new HttpGet(url); response = client.execute(getRequest); break; case Service.CALL_TYPE_POST: log(LOG_TYPE_DEBUG, "Making POST Call"); HttpPost postRequest = new HttpPost(url); response = client.execute(postRequest); break; case Service.CALL_TYPE_PUT: log(LOG_TYPE_DEBUG, "Making PUT Call"); HttpPut putRequest = new HttpPut(url); response = client.execute(putRequest); break; case Service.CALL_TYPE_DELETE: log(LOG_TYPE_DEBUG, "Making DELETE Call"); HttpDelete deleteRequest = new HttpDelete(url); response = client.execute(deleteRequest); break; default: throw new RuntimeException( "Invalid Call type, please see Service.CALL_TYPE_* for possible types."); } } catch (IOException e) { attempts++; publishProgress("IOException: Retrying, attempt " + (attempts + 1), e.getMessage()); } if (response != null) break; } //check if exceeded max number of attempts if (attempts == MAX_ATTEMPTS) { //max number of attempts exceeded, error Bundle responseBundle = new Bundle(); //responseBundle.putString(EXTRA_ERR_MSG, "Failed "+MAX_ATTEMPTS+" attempts, please retry later."); responseBundle.putString(EXTRA_ERR_MSG, "Could not connect to the server, please try again later"); responseBundle.putInt(EXTRA_ERR_CODE, ERR_CODE_MAX_ATTEMPTS_REACHED); return responseBundle; } return parseResponse(response); }
From source file:org.epochx.ge.representation.GECandidateProgram.java
/** * Sets each codon from the startIndex. If the number of codons takes the * indexes beyond the length of the current codons then the new codons will * be added to the end of the list of codons. However if the first index is * greater than the length of the current set of codons then an * ArrayIndexOutOfBoundsException will be thrown. All caches will be * cleared./*from w w w . ja va 2 s . com*/ * * @param startIndex the index from which the codons should be replaced or * otherwise set. * @param newCodons the codons that should be stored at the specified * positions. * @throws ArrayIndexOutOfBoundsException If the first index is beyond the * end of the current list of codons. */ public void setCodons(final int startIndex, final List<Integer> newCodons) { // If more than one beyond the end of current codons. if (startIndex > codons.size()) { throw new ArrayIndexOutOfBoundsException(startIndex); } for (int i = 0; i < newCodons.size(); i++) { final int c = newCodons.get(i); if (i + startIndex < codons.size()) { codons.set(i + startIndex, c); } else { appendCodon(c); } } }
From source file:org.dcache.util.histograms.HistogramMetadata.java
/** * @param index the actual index corresponding to the position in * the array of data comprising the histogram. * @param timestamp associated with the current update. * @return the updated count for the index *//* w w w .j a va 2s . c o m*/ public int updateCountForBin(int index, long timestamp) { if (index < 0 || numBins <= index) { throw new ArrayIndexOutOfBoundsException("bin " + index + " does not" + " exist"); } index = rotatedIndex(index); ++binCounts[index]; binTimestamps[index] = timestamp; return binCounts[index]; }
From source file:com.idylwood.utils.MathUtils.java
final public static double[] multiply(final double[] first, final double[] second) { final int len = first.length; if (len != second.length) throw new ArrayIndexOutOfBoundsException("Tried to multiply two vectors of unequal length!"); final double ret[] = new double[len]; for (int i = len; i-- != 0;) ret[i] = first[i] * second[i];//www .ja v a 2s . c om return ret; }
From source file:net.java.sip.communicator.impl.protocol.jabber.OperationSetServerStoredAccountInfoJabberImpl.java
/** * Adds the specified detail to the list of details ready to be saved online * for this account. If such a detail already exists its max instance number * is consulted and if it allows it - a second instance is added or otherwise * and illegal argument exception is thrown. An IllegalArgumentException is * also thrown in case the class of the specified detail is not supported by * the underlying implementation, i.e. its class name was not returned by the * getSupportedDetailTypes() method.//from w w w . j av a 2s. c om * <p> * @param detail the detail that we'd like registered on the server. * <p> * @throws IllegalArgumentException if such a detail already exists and its * max instances number has been attained or if the underlying * implementation does not support setting details of the corresponding * class. * @throws java.lang.ArrayIndexOutOfBoundsException if the number of * instances currently registered by the application is already equal to the * maximum number of supported instances (@see getMaxDetailInstances()) */ public void addDetail(ServerStoredDetails.GenericDetail detail) throws IllegalArgumentException, ArrayIndexOutOfBoundsException { if (!isDetailClassSupported(detail.getClass())) { throw new IllegalArgumentException("implementation does not support such details " + detail.getClass()); } Iterator<GenericDetail> iter = getDetails(detail.getClass()); int currentDetailsSize = 0; while (iter.hasNext()) { currentDetailsSize++; iter.next(); } if (currentDetailsSize > getMaxDetailInstances(detail.getClass())) { throw new ArrayIndexOutOfBoundsException("Max count for this detail is already reached"); } infoRetreiver.getCachedContactDetails(uin).add(detail); }
From source file:org.apache.jmeter.util.keystore.JmeterKeyStore.java
public String getAlias(int index) { int length = this.names.length; if (length == 0 && index == 0) { // i.e. is == null return null; }//from www.j a v a 2 s . com if (index >= length || index < 0) { throw new ArrayIndexOutOfBoundsException(index); } return this.names[index]; }
From source file:org.anarres.lzo.hadoop.codec.LzoCompressor.java
@Override public void setInput(byte[] b, int off, int len) { // logState("Before setInput"); 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 (inputHoldoverBuffer != null) throw new IllegalStateException("Cannot accept input while holdover is present."); inputHoldoverBuffer = b;//from w w w.j a va 2 s . co m inputHoldoverBufferPos = off; inputHoldoverBufferLen = len; compact(); inputByteCount += len; // Unfortunately, we have to do this here. This is so, so, so wrong. // logState("After setInput"); }
From source file:org.freeinternals.format.classfile.ClassFile.java
/** * Get part of the class byte array. The array begins at the specified * {@code startIndex} and extends to the byte at {@code startIndex}+ * {@code length}.//from w w w.j av a 2 s.co m * * @param startIndex * The start index * @param length * The length of the array * @return Part of the class byte array */ public byte[] getClassByteArray(final int startIndex, final int length) { if ((startIndex < 0) || (length < 1)) { throw new IllegalArgumentException( "startIndex or length is not valid. startIndex = " + startIndex + ", length = " + length); } if (startIndex + length - 1 > this.classByteArray.length) { throw new ArrayIndexOutOfBoundsException("The last item index is bigger than class byte array size."); } byte[] data = new byte[length]; System.arraycopy(this.classByteArray, startIndex, data, 0, length); return data; }
From source file:wordnice.api.Nice.java
public static ArrayIndexOutOfBoundsException bounds(int x) throws ArrayIndexOutOfBoundsException { throw new ArrayIndexOutOfBoundsException(x); }
From source file:wordnice.api.Nice.java
public static void checkBounds(byte[] arr, int offset, int length) throws ArrayIndexOutOfBoundsException, IllegalArgumentException { if (arr == null) throw Nice.illegal("Null array!"); if (length < 0) throw new ArrayIndexOutOfBoundsException("Length (" + length + ") < 0"); if (offset < 0) throw new ArrayIndexOutOfBoundsException("Offset (" + offset + ") < 0"); if (offset + length > arr.length) throw new ArrayIndexOutOfBoundsException( "Offset+Length (" + (offset + length) + ") > Array length (" + arr.length + ")"); }