List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException()
From source file:ClosableByteArrayOutputStream.java
/** * Writes the specified portion of the designated octet sequence. <p> * * @param b the data./*from w w w . j av a 2 s . com*/ * @param off the start offset in the data. * @param len the number of bytes to write. * @throws java.io.IOException if an I/O error occurs. * In particular, an <tt>IOException</tt> may be thrown * if this output stream has been {@link #close() closed}. */ public synchronized void write(byte b[], int off, int len) throws IOException { checkClosed(); if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } int newcount = count + len; if (newcount > buf.length) { buf = copyOf(buf, Math.max(buf.length << 1, newcount)); } System.arraycopy(b, off, buf, count, len); count = newcount; }
From source file:com.hadoop.compression.fourmc.FourMcOutputStream.java
@Override public void write(byte[] b, int off, int len) throws IOException { // exactly like the case of LzopOutputStream this is a bit complex // to be able to handle custom needs of block compression and related block indexes // Sanity checks if (compressor.finished()) { throw new IOException("write beyond end of stream"); }//from w w w . jav a2 s.co m if (b == null) { throw new NullPointerException(); } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } long limlen = compressor.getBytesRead(); if (len + limlen > FourMcCodec.FOURMC_MAX_BLOCK_SIZE && limlen > 0) { finish(); compressor.reset(); } if (len > FourMcCodec.FOURMC_MAX_BLOCK_SIZE) { do { int bufLen = Math.min(len, FourMcCodec.FOURMC_MAX_BLOCK_SIZE); compressor.setInput(b, off, bufLen); finish(); compressor.reset(); off += bufLen; len -= bufLen; } while (len > 0); return; } // Give data to the compressor compressor.setInput(b, off, len); if (!compressor.needsInput()) { do { compress(); } while (!compressor.needsInput()); } }
From source file:com.hadoop.compression.fourmc.FourMzOutputStream.java
@Override public void write(byte[] b, int off, int len) throws IOException { // exactly like the case of LzopOutputStream this is a bit complex // to be able to handle custom needs of block compression and related block indexes // Sanity checks if (compressor.finished()) { throw new IOException("write beyond end of stream"); }/*from w w w. j a v a2 s . c o m*/ if (b == null) { throw new NullPointerException(); } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } long limlen = compressor.getBytesRead(); if (len + limlen > FourMzCodec.FOURMC_MAX_BLOCK_SIZE && limlen > 0) { finish(); compressor.reset(); } if (len > FourMzCodec.FOURMC_MAX_BLOCK_SIZE) { do { int bufLen = Math.min(len, FourMzCodec.FOURMC_MAX_BLOCK_SIZE); compressor.setInput(b, off, bufLen); finish(); compressor.reset(); off += bufLen; len -= bufLen; } while (len > 0); return; } // Give data to the compressor compressor.setInput(b, off, len); if (!compressor.needsInput()) { do { compress(); } while (!compressor.needsInput()); } }
From source file:CopyOnWriteArrayList.java
/** * Replaces the held array with a copy of the <tt>n</tt> elements * of the provided array, starting at position <tt>first</tt>. To * copy an entire array, call with arguments (array, 0, * array.length).//from w w w . ja v a 2s . co m * @param toCopyIn the array. A copy of the indicated elements of * this array is used as the internal array. * @param first The index of first position of the array to * start copying from. * @param n the number of elements to copy. This will be the new size of * the list. */ private void copyIn(Object[] toCopyIn, int first, int n) { int limit = first + n; if (limit > toCopyIn.length) throw new IndexOutOfBoundsException(); Object[] newElements = copyOfRange(toCopyIn, first, limit, Object[].class); synchronized (this) { setArray(newElements); } }
From source file:com.amazonaws.auth.AwsChunkedEncodingInputStream.java
@Override public int read(byte[] b, int off, int len) throws IOException { abortIfNeeded();/*from w ww.j av a2 s.co m*/ if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } if (null == currentChunkIterator || !currentChunkIterator.hasNext()) { if (isTerminating) return -1; else { isTerminating = setUpNextChunk(); } } int count = currentChunkIterator.read(b, off, len); if (count > 0) { isAtStart = false; if (log.isDebugEnabled()) log.debug(count + " byte read from the stream."); } return count; }
From source file:com.ponysdk.ui.server.basic.PTabLayoutPanel.java
public void selectTab(final int index) { if (index >= getWidgetCount()) throw new IndexOutOfBoundsException(); this.selectedItemIndex = index; final Update update = new Update(ID); update.put(PROPERTY.SELECTED_INDEX, index); Txn.get().getTxnContext().save(update); }
From source file:fr.limsi.ARViewer.CharArrayBuffer.java
public void setLength(int len) { if (len < 0 || len > this.buffer.length) { throw new IndexOutOfBoundsException(); }//from www . j a v a 2 s. c om this.len = len; }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java
protected Object set(InternalEObject object, EAttribute eAttribute, int index, Object value) { Object returnValue = null;/*from w ww .j av a2 s. c o m*/ Vertex vertex = graph.getOrCreateVertex(object); if (!eAttribute.isMany()) { Object property = vertex.getProperty(eAttribute.getName()); returnValue = parseProperty(eAttribute, property); vertex.setProperty(eAttribute.getName(), serializeToProperty(eAttribute, value)); } else { Integer size = getSize(vertex, eAttribute); if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(); } else { String propertyName = eAttribute.getName() + SEPARATOR + index; returnValue = vertex.getProperty(propertyName); vertex.setProperty(propertyName, serializeToProperty(eAttribute, value)); } } return returnValue; }
From source file:com.github.rvesse.airline.restrictions.common.PartialRestriction.java
@Override public String[] getContentBlock(int blockNumber) { if (this.hint != null) { return this.hint.getContentBlock(blockNumber); } else {//from www . ja v a 2 s .co m throw new IndexOutOfBoundsException(); } }
From source file:com.norconex.commons.lang.io.ByteArrayOutputStream.java
/** * Write the bytes to byte array./*from w ww .j a v a 2 s .c om*/ * @param b the bytes to write * @param off The start offset * @param len The number of bytes to write */ @Override public void write(byte[] b, int off, int len) { if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } synchronized (this) { int bytesLeftToWrite = len; int lastOff = off; while (bytesLeftToWrite > 0) { int currentRoomLeft = bufferCapacity - currentBufferIndex; int lengthToWrite = Math.min(bytesLeftToWrite, currentRoomLeft); System.arraycopy(b, lastOff, currentBuffer, currentBufferIndex, lengthToWrite); currentBufferIndex += lengthToWrite; lastOff += lengthToWrite; bytesLeftToWrite -= lengthToWrite; if (currentBufferIndex == bufferCapacity) { addNewBuffer(); } totalCount += lengthToWrite; } } }