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:org.apache.hadoop.io.compress.snappy.SnappyCompressor.java

/**
 * Fills specified buffer with compressed data. Returns actual number
 * of bytes of compressed data. A return value of 0 indicates that
 * needsInput() should be called in order to determine if more input
 * data is required.//from  w  ww  . ja  v  a2  s .  c o m
 *
 * @param b   Buffer for the compressed data
 * @param off Start offset of the data
 * @param len Size of the buffer
 * @return The actual number of bytes of compressed data.
 */
@Override
public synchronized int compress(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }

    // Check if there is compressed data
    int n = compressedDirectBuf.remaining();
    if (n > 0) {
        n = Math.min(n, len);
        ((ByteBuffer) compressedDirectBuf).get(b, off, n);
        bytesWritten += n;
        return n;
    }

    // Re-initialize the snappy's output direct-buffer
    compressedDirectBuf.clear();
    compressedDirectBuf.limit(0);
    if (0 == uncompressedDirectBuf.position()) {
        // No compressed data, so we should have !needsInput or !finished
        setInputFromSavedData();
        if (0 == uncompressedDirectBuf.position()) {
            // Called without data; write nothing
            finished = true;
            return 0;
        }
    }

    // Compress data
    n = compressBytesDirect();
    compressedDirectBuf.limit(n);
    uncompressedDirectBuf.clear(); // snappy consumes all buffer input

    // Set 'finished' if snapy has consumed all user-data
    if (0 == userBufLen) {
        finished = true;
    }

    // Get atmost 'len' bytes
    n = Math.min(n, len);
    bytesWritten += n;
    ((ByteBuffer) compressedDirectBuf).get(b, off, n);

    return n;
}

From source file:org.apache.hadoop.io.crypto.aes.AESEncryptor.java

/**
 * Fills specified buffer with compressed data. Returns actual number of bytes
 * of compressed data. A return value of 0 indicates that needsInput() should
 * be called in order to determine if more input data is required.
 * /*  w w  w .  j a v a 2 s  . c om*/
 * @param b Buffer for the compressed data
 * @param off Start offset of the data
 * @param len Size of the buffer
 * @return The actual number of bytes of compressed data.
 */
@Override
public synchronized int encrypt(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }

    // Check if there is compressed data
    int n = compressedDirectBuf.remaining();
    if (n > 0) {
        n = Math.min(n, len);
        ((ByteBuffer) compressedDirectBuf).get(b, off, n);
        bytesWritten += n;
        return n;
    }

    compressedDirectBuf.clear();
    compressedDirectBuf.limit(0);
    if (0 == uncompressedDirectBuf.position()) {
        // No compressed data, so we should have !needsInput or !finished
        setInputFromSavedData();
        if (0 == uncompressedDirectBuf.position()) {
            // Called without data; write nothing
            allInputProcessed = true;
            return 0;
        }
    }

    // Compress data
    try {
        n = cipher.doFinal(uncompressedDirectBuf, uncompressedDirectBufLen, compressedDirectBuf);
    } catch (Exception e) {
        throw new IOException(e);
    }
    uncompressedDirectBuf.clear();
    uncompressedDirectBufLen = 0;

    if (0 == userBufLen) {
        allInputProcessed = true;
    }

    // Get atmost 'len' bytes
    n = Math.min(n, len);
    bytesWritten += n;
    compressedDirectBuf.get(b, off, n);

    return n;
}

From source file:org.apache.hadoop.io.compress.lz4.Lz4Decompressor.java

/**
 * Fills specified buffer with uncompressed data. Returns actual number
 * of bytes of uncompressed data. A return value of 0 indicates that
 * {@link #needsInput()} should be called in order to determine if more
 * input data is required.//ww w.j a  v a  2 s  .c  o m
 *
 * @param b   Buffer for the compressed data
 * @param off Start offset of the data
 * @param len Size of the buffer
 * @return The actual number of bytes of compressed data.
 * @throws IOException
 */
@Override
public synchronized int decompress(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }

    int n = 0;

    // Check if there is uncompressed data
    n = uncompressedDirectBuf.remaining();
    if (n > 0) {
        n = Math.min(n, len);
        ((ByteBuffer) uncompressedDirectBuf).get(b, off, n);
        return n;
    }
    if (compressedDirectBufLen > 0) {
        // Re-initialize the lz4's output direct buffer
        uncompressedDirectBuf.rewind();
        uncompressedDirectBuf.limit(directBufferSize);

        // Decompress data
        n = decompressBytesDirect();
        uncompressedDirectBuf.limit(n);

        if (userBufLen <= 0) {
            finished = true;
        }

        // Get atmost 'len' bytes
        n = Math.min(n, len);
        ((ByteBuffer) uncompressedDirectBuf).get(b, off, n);
    }

    return n;
}

From source file:org.apache.hadoop.io.compress.lz4.Lz4Compressor.java

/**
 * Fills specified buffer with compressed data. Returns actual number
 * of bytes of compressed data. A return value of 0 indicates that
 * needsInput() should be called in order to determine if more input
 * data is required./*  www.ja  v  a 2 s.  c o m*/
 *
 * @param b   Buffer for the compressed data
 * @param off Start offset of the data
 * @param len Size of the buffer
 * @return The actual number of bytes of compressed data.
 */
@Override
public synchronized int compress(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }

    // Check if there is compressed data
    int n = compressedDirectBuf.remaining();
    if (n > 0) {
        n = Math.min(n, len);
        ((ByteBuffer) compressedDirectBuf).get(b, off, n);
        bytesWritten += n;
        return n;
    }

    // Re-initialize the lz4's output direct-buffer
    compressedDirectBuf.clear();
    compressedDirectBuf.limit(0);
    if (0 == uncompressedDirectBuf.position()) {
        // No compressed data, so we should have !needsInput or !finished
        setInputFromSavedData();
        if (0 == uncompressedDirectBuf.position()) {
            // Called without data; write nothing
            finished = true;
            return 0;
        }
    }

    // Compress data
    n = useLz4HC ? compressBytesDirectHC() : compressBytesDirect();
    compressedDirectBuf.limit(n);
    uncompressedDirectBuf.clear(); // lz4 consumes all buffer input

    // Set 'finished' if snapy has consumed all user-data
    if (0 == userBufLen) {
        finished = true;
    }

    // Get atmost 'len' bytes
    n = Math.min(n, len);
    bytesWritten += n;
    ((ByteBuffer) compressedDirectBuf).get(b, off, n);

    return n;
}

From source file:org.apache.hadoop.io.compress.bzip2.Bzip2Compressor.java

@Override
public synchronized int compress(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }//from w  ww  .  j a va 2  s .c om
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }

    // Check if there is compressed data.
    int n = compressedDirectBuf.remaining();
    if (n > 0) {
        n = Math.min(n, len);
        ((ByteBuffer) compressedDirectBuf).get(b, off, n);
        return n;
    }

    // Re-initialize bzip2's output direct buffer.
    compressedDirectBuf.rewind();
    compressedDirectBuf.limit(directBufferSize);

    // Compress the data.
    n = deflateBytesDirect();
    compressedDirectBuf.limit(n);

    // Check if bzip2 has consumed the entire input buffer.
    // Set keepUncompressedBuf properly.
    if (uncompressedDirectBufLen <= 0) { // bzip2 consumed all input
        keepUncompressedBuf = false;
        uncompressedDirectBuf.clear();
        uncompressedDirectBufOff = 0;
        uncompressedDirectBufLen = 0;
    } else {
        keepUncompressedBuf = true;
    }

    // Get at most 'len' bytes.
    n = Math.min(n, len);
    ((ByteBuffer) compressedDirectBuf).get(b, off, n);

    return n;
}

From source file:org.apache.hadoop.io.compress.snappy.SnappyDecompressor.java

/**
 * Fills specified buffer with uncompressed data. Returns actual number
 * of bytes of uncompressed data. A return value of 0 indicates that
 * {@link #needsInput()} should be called in order to determine if more
 * input data is required.//from w ww  .ja  v a2 s. c o  m
 *
 * @param b   Buffer for the compressed data
 * @param off Start offset of the data
 * @param len Size of the buffer
 * @return The actual number of bytes of compressed data.
 * @throws IOException
 */
@Override
public synchronized int decompress(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }

    int n = 0;

    // Check if there is uncompressed data
    n = uncompressedDirectBuf.remaining();
    if (n > 0) {
        n = Math.min(n, len);
        ((ByteBuffer) uncompressedDirectBuf).get(b, off, n);
        return n;
    }
    if (compressedDirectBufLen > 0) {
        // Re-initialize the snappy's output direct buffer
        uncompressedDirectBuf.rewind();
        uncompressedDirectBuf.limit(directBufferSize);

        // Decompress data
        n = decompressBytesDirect();
        uncompressedDirectBuf.limit(n);

        if (userBufLen <= 0) {
            finished = true;
        }

        // Get atmost 'len' bytes
        n = Math.min(n, len);
        ((ByteBuffer) uncompressedDirectBuf).get(b, off, n);
    }

    return n;
}

From source file:org.apache.openejb.math.MathRuntimeException.java

/**
 * Constructs a new <code>ArrayIndexOutOfBoundsException</code> with specified formatted detail message.
 * Message formatting is delegated to {@link MessageFormat}.
 *
 * @param pattern   format specifier//from w w  w  .  ja  v a2s.co  m
 * @param arguments format arguments
 * @return built exception
 */
public static ArrayIndexOutOfBoundsException createArrayIndexOutOfBoundsException(final String pattern,
        final Object... arguments) {
    return new ArrayIndexOutOfBoundsException() {

        /** Serializable version identifier. */
        private static final long serialVersionUID = -3394748305449283486L;

        /** {@inheritDoc} */
        @Override
        public String getMessage() {
            return buildMessage(Locale.US, pattern, arguments);
        }

        /** {@inheritDoc} */
        @Override
        public String getLocalizedMessage() {
            return buildMessage(Locale.getDefault(), pattern, arguments);
        }

    };
}

From source file:org.apache.hadoop.io.crypto.aes.AESDecryptor.java

/**
 * Fills specified buffer with uncompressed data. Returns actual number of
 * bytes of uncompressed data. A return value of 0 indicates that
 * {@link #needsInput()} should be called in order to determine if more input
 * data is required./* w  w  w. j  a  va 2s .c  o m*/
 * 
 * @param b Buffer for the compressed data
 * @param off Start offset of the data
 * @param len Size of the buffer
 * @return The actual number of bytes of compressed data.
 * @throws IOException
 */
@Override
public synchronized int decrypt(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }

    int n = 0;

    // Check if there is uncompressed data
    n = uncompressedDirectBuf.remaining();
    if (n > 0) {
        n = Math.min(n, len);
        ((ByteBuffer) uncompressedDirectBuf).get(b, off, n);
        return n;
    }
    if (compressedDirectBufLen > 0) {
        // Re-initialize the snappy's output direct buffer
        uncompressedDirectBuf.rewind();
        uncompressedDirectBuf.limit(directBufferSize - AESConstants.AES_BLOCK_SIZE);

        // Decompress data
        try {
            n = cipher.doFinal(compressedDirectBuf, compressedDirectBufLen, uncompressedDirectBuf);
        } catch (Exception e) {
            throw new IOException(e);
        }

        compressedDirectBuf.clear();
        compressedDirectBufLen = 0;

        if (userBufLen <= 0) {
            allInputProcessed = true;
        }

        // Get atmost 'len' bytes
        n = Math.min(n, len);
        ((ByteBuffer) uncompressedDirectBuf).get(b, off, n);
    }

    return n;
}

From source file:org.apache.hadoop.io.compress.lzo.LzoDecompressor.java

public synchronized int decompress(byte[] b, int off, int len) throws IOException {
    if (b == null) {
        throw new NullPointerException();
    }//from w w w.java  2  s .c  om
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }

    int n = 0;

    // Check if there is uncompressed data
    n = uncompressedDirectBuf.remaining();
    if (n > 0) {
        n = Math.min(n, len);
        ((ByteBuffer) uncompressedDirectBuf).get(b, off, n);
        return n;
    }

    // Check if there is data to decompress
    if (compressedDirectBufLen <= 0) {
        return 0;
    }

    // Re-initialize the lzo's output direct-buffer
    uncompressedDirectBuf.rewind();
    uncompressedDirectBuf.limit(directBufferSize);

    // Decompress data
    n = decompressBytesDirect(strategy.getDecompressor());
    uncompressedDirectBuf.limit(n);

    // Set 'finished' if lzo has consumed all user-data
    if (userBufLen <= 0) {
        finished = true;
    }

    // Return atmost 'len' bytes
    n = Math.min(n, len);
    ((ByteBuffer) uncompressedDirectBuf).get(b, off, n);

    return n;
}

From source file:com.gpl_compression.lzo.LzoCompressor.java

public synchronized void setInput(byte[] b, int off, int len) {
    if (b == null) {
        throw new NullPointerException();
    }//  w  w  w.  j  a va 2  s . c o m
    if (off < 0 || len < 0 || off > b.length - len) {
        throw new ArrayIndexOutOfBoundsException();
    }
    finished = false;

    if (len > uncompressedDirectBuf.remaining()) {
        // save data; now !needsInput
        this.userBuf = b;
        this.userBufOff = off;
        this.userBufLen = len;
    } else {
        ((ByteBuffer) uncompressedDirectBuf).put(b, off, len);
        uncompressedDirectBufLen = uncompressedDirectBuf.position();
    }
    bytesRead += len;
}