List of usage examples for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException
public ArrayIndexOutOfBoundsException(int index)
From source file:wordnice.api.Nice.java
public static void checkBounds(char[] 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 + ")"); }
From source file:org.dhatim.archive.Archive.java
/** * Get the name of the entry at the specified index in the archive. * @param index The index./*from w w w . ja va2 s . c o m*/ * @return The entry name at that index. */ public String getEntryName(int index) { Set<Map.Entry<String, File>> entrySet = entries.entrySet(); int i = 0; for (Map.Entry<String, File> entry : entrySet) { if (i == index) { return entry.getKey(); } i++; } throw new ArrayIndexOutOfBoundsException(index); }
From source file:com.ngdata.sep.impl.SepConsumer.java
@Override public AdminProtos.ReplicateWALEntryResponse replicateWALEntry(final RpcController controller, final AdminProtos.ReplicateWALEntryRequest request) throws ServiceException { try {// www. j a v a2 s.c o m // TODO Recording of last processed timestamp won't work if two batches of log entries are sent out of order long lastProcessedTimestamp = -1; SepEventExecutor eventExecutor = new SepEventExecutor(listener, executors, 100, sepMetrics); List<AdminProtos.WALEntry> entries = request.getEntryList(); CellScanner cells = ((PayloadCarryingRpcController) controller).cellScanner(); for (final AdminProtos.WALEntry entry : entries) { TableName tableName = (entry.getKey().getWriteTime() < subscriptionTimestamp) ? null : TableName.valueOf(entry.getKey().getTableName().toByteArray()); Multimap<ByteBuffer, KeyValue> keyValuesPerRowKey = ArrayListMultimap.create(); final Map<ByteBuffer, byte[]> payloadPerRowKey = Maps.newHashMap(); int count = entry.getAssociatedCellCount(); for (int i = 0; i < count; i++) { if (!cells.advance()) { throw new ArrayIndexOutOfBoundsException("Expected=" + count + ", index=" + i); } // this signals to us that we simply need to skip over count of cells if (tableName == null) { continue; } Cell cell = cells.current(); ByteBuffer rowKey = ByteBuffer.wrap(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); byte[] payload; KeyValue kv = KeyValueUtil.ensureKeyValue(cell); if (payloadExtractor != null && (payload = payloadExtractor.extractPayload(tableName.toBytes(), kv)) != null) { if (payloadPerRowKey.containsKey(rowKey)) { log.error("Multiple payloads encountered for row " + Bytes.toStringBinary(rowKey) + ", choosing " + Bytes.toStringBinary(payloadPerRowKey.get(rowKey))); } else { payloadPerRowKey.put(rowKey, payload); } } keyValuesPerRowKey.put(rowKey, kv); } for (final ByteBuffer rowKeyBuffer : keyValuesPerRowKey.keySet()) { final List<KeyValue> keyValues = (List<KeyValue>) keyValuesPerRowKey.get(rowKeyBuffer); final SepEvent sepEvent = new SepEvent(tableName.toBytes(), keyValues.get(0).getRow(), keyValues, payloadPerRowKey.get(rowKeyBuffer)); eventExecutor.scheduleSepEvent(sepEvent); lastProcessedTimestamp = Math.max(lastProcessedTimestamp, entry.getKey().getWriteTime()); } } List<Future<?>> futures = eventExecutor.flush(); waitOnSepEventCompletion(futures); if (lastProcessedTimestamp > 0) { sepMetrics.reportSepTimestamp(lastProcessedTimestamp); } return AdminProtos.ReplicateWALEntryResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
From source file:br.prof.salesfilho.oci.image.ImageProcessor.java
/** * @param larger the larger array to be split into sub arrays of size * chunksize/*ww w . ja v a 2 s . c o m*/ * @param subArraySize the size of each sub array * @precond chunksize > 0 && larger != null * @throws ArrayIndexOutOfBoundsException, NullPointerException */ private double[][][] getSplitMatrix(double[][] larger, int subArraySize) throws ArrayIndexOutOfBoundsException, NullPointerException { if (subArraySize <= 0) { throw new ArrayIndexOutOfBoundsException("Chunks must be atleast 1x1"); } int size = larger.length / subArraySize * (larger[0].length / subArraySize); double[][][] subArrays = new double[size][][]; for (int c = 0; c < size; c++) { double[][] sub = new double[subArraySize][subArraySize]; int startx = (subArraySize * (c / subArraySize)) % larger.length; int starty = (subArraySize * c) % larger[0].length; if (starty + subArraySize > larger[0].length) { starty = 0; } for (int row = 0; row < subArraySize; row++) { for (int col = 0; col < subArraySize; col++) { sub[row][col] = larger[startx + row][col + starty]; } } subArrays[c] = sub; } return subArrays; }
From source file:wordnice.api.Nice.java
public static void checkBounds(Object[] 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 + ")"); }
From source file:ClosableCharArrayWriter.java
/** * Sets the size of this writer's accumulated character data. * * @param newSize the new size of this writer's accumulated data * @throws ArrayIndexOutOfBoundsException if new size is negative */// w w w . ja va 2s . c om public synchronized void setSize(int newSize) { if (newSize < 0) { throw new ArrayIndexOutOfBoundsException(newSize); } else if (newSize > buf.length) { buf = copyOf(buf, Math.max(buf.length << 1, newSize)); } count = newSize; }
From source file:Matrix.java
/** * Get a submatrix./*from www . j a v a 2s . c o m*/ * * @param i0 * Initial row index * @param i1 * Final row index * @param j0 * Initial column index * @param j1 * Final column index * @return A(i0:i1,j0:j1) * @exception ArrayIndexOutOfBoundsException * Submatrix indices */ public Matrix getMatrix(int i0, int i1, int j0, int j1) { Matrix X = new Matrix(i1 - i0 + 1, j1 - j0 + 1); double[][] B = X.getArray(); try { for (int i = i0; i <= i1; i++) { for (int j = j0; j <= j1; j++) { B[i - i0][j - j0] = A[i][j]; } } } catch (ArrayIndexOutOfBoundsException e) { throw new ArrayIndexOutOfBoundsException("Submatrix indices"); } return X; }
From source file:wordnice.api.Nice.java
public static void checkBounds(CharSequence 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:org.dhatim.archive.Archive.java
/** * Get the value of the entry at the specified index in the archive. * @param index The index./* ww w .jav a2 s . co m*/ * @return The entry value at that index. */ public byte[] getEntryValue(int index) { Set<Map.Entry<String, File>> entrySet = entries.entrySet(); int i = 0; for (Map.Entry<String, File> entry : entrySet) { if (i == index) { File entryFile = entry.getValue(); if (entryFile != null) { try { return FileUtils.readFile(entryFile); } catch (IOException e) { throw new IllegalStateException( "Unexpected error reading Archive file '" + entryFile.getAbsolutePath() + "'.", e); } } else { return null; } } i++; } throw new ArrayIndexOutOfBoundsException(index); }
From source file:org.freedesktop.dbus.Message.java
/** * Appends a buffer to the buffer list./* w ww.j a v a2 s . c o m*/ */ protected void appendBytes(byte[] buf) { if (null == buf) return; if (this.preallocated > 0) { if (this.paofs + buf.length > this.pabuf.length) throw new ArrayIndexOutOfBoundsException( String.format("Array index out of bounds, paofs=%s, pabuf.length=%s, buf.length=%s.", this.paofs, this.pabuf.length, buf.length)); System.arraycopy(buf, 0, this.pabuf, this.paofs, buf.length); this.paofs += buf.length; this.preallocated -= buf.length; } else { if (this.bufferuse == this.wiredata.length) { if (log.isTraceEnabled()) { log.trace("Resizing " + this.bufferuse); } byte[][] temp = new byte[this.wiredata.length + BUFFERINCREMENT][]; System.arraycopy(this.wiredata, 0, temp, 0, this.wiredata.length); this.wiredata = temp; } this.wiredata[this.bufferuse++] = buf; this.bytecounter += buf.length; } }