Example usage for java.lang NegativeArraySizeException NegativeArraySizeException

List of usage examples for java.lang NegativeArraySizeException NegativeArraySizeException

Introduction

In this page you can find the example usage for java.lang NegativeArraySizeException NegativeArraySizeException.

Prototype

public NegativeArraySizeException(String s) 

Source Link

Document

Constructs a NegativeArraySizeException with the specified detail message.

Usage

From source file:com.john.main.Utils.java

static float[] copyOf(float[] original, int newLength) {
    if (newLength < 0) {
        throw new NegativeArraySizeException(Integer.toString(newLength));
    }/*from ww w. j av  a  2  s . co  m*/
    return copyOfRange(original, 0, newLength);
}

From source file:cn.iie.haiep.hbase.value.Bytes.java

/**
 * Read byte-array written with a WritableableUtils.vint prefix.
 * @param in Input to read from./*  ww  w. jav  a  2 s . c  om*/
 * @return byte array read off <code>in</code>
 * @throws IOException e
 */
public static byte[] readByteArray(final DataInput in) throws IOException {
    int len = WritableUtils.readVInt(in);
    if (len < 0) {
        throw new NegativeArraySizeException(Integer.toString(len));
    }
    byte[] result = new byte[len];
    in.readFully(result, 0, len);
    return result;
}

From source file:org.openecomp.sdnc.sli.SliPluginUtils.SvcLogicContextList.java

private static int getCtxListIndex(String key, String prefix, int list_size) {
    int index = getCtxListIndex(key, prefix);
    if (index >= list_size) {
        throw new IllegalArgumentException(
                "Context memory list \"" + prefix + "[]\" contains an index >= the size of the list",
                new ArrayIndexOutOfBoundsException(
                        "index \"" + index + "\" is outside the bounds of the context memory list \"" + prefix
                                + "[]. List Length = " + list_size));
    } else if (index < 0) {
        throw new IllegalArgumentException("Context memory list \"" + prefix + "[]\" contains a negative index",
                new NegativeArraySizeException("index \"" + index + "\" of context memory list is negative"));
    }/*from w ww . j a  va  2  s. c om*/

    return index;
}

From source file:com.github.xbn.text.StringUtil.java

/**
   <p>Creates a string where every element is the same character.</p>
        /*from w  w  w.j a  v  a  2  s .  com*/
 * @param  length  The length of the returned string.
 * @param  char_toDup  The character to duplicate.
 * @param  length_varName  Descriptive name of {@code length}. <i>Should</i> not be {@code null} or empty.
 * @return  <code>new String(new char[length]).java.lang.String#replace(CharSequence, CharSequence)(&quot;\0&quot;, (new Character(char_toDup)).toString())</code>
 * @see  <code><a href="http://stackoverflow.com/questions/1235179/simple-way-to-repeat-a-string-in-java/4903603#4903603">http://stackoverflow.com/questions/1235179/simple-way-to-repeat-a-string-in-java/4903603#4903603</a></code>
 * @exception  NegativeArraySizeException  If {@code length} is less than zero.
 */
public static final String getStringOfLengthAllCharsEqualTo(int length, char char_toDup,
        String length_varName) {
    try {
        return new String(new char[length]).replace("\0", (new Character(char_toDup)).toString());
    } catch (NegativeArraySizeException nasx) {
        throw new NegativeArraySizeException(length_varName + "=" + length);
    }
}

From source file:net.sourceforge.jencrypt.FileEncrypter.java

private long decryptArchive(String inputFile, String outputFolder) throws Exception {

    String fileFormatErrorMessage = "Archive '" + inputFile + "' does not conform to the jEncrypt file format.";
    long fileCounter = 0;
    FileInputStream fis = getInputFileStream(inputFile);
    Set<PosixFilePermission> perms = null;

    byte[] initializationVectorBytes = new byte[CryptoWrapper.AES_BLOCK_SIZE_IN_BYTES];
    byte[] saltBytes = new byte[config.getSaltSize()];
    byte[] pathSizeBytes = new byte[4];
    boolean pathIsFolder = false;

    outputFolder += File.separator;

    try {/* www .java 2s  .c o m*/

        int nrOfBytesRead = fis.read(saltBytes);
        nrOfBytesRead += fis.read(initializationVectorBytes);

        if (nrOfBytesRead == (CryptoWrapper.AES_BLOCK_SIZE_IN_BYTES + config.getSaltSize())) {
            createCryptoWrappers(initializationVectorBytes, saltBytes);
        } else {
            throw new IllegalStateException(fileFormatErrorMessage);
        }

        while ((fis.read(pathSizeBytes)) > 0) {

            // get size of path
            byte[] pathSizeBytesDec = cryptoWrapperFileNamesAndSizes.cipherBytes(pathSizeBytes,
                    Cipher.DECRYPT_MODE);
            // 4 byte pathsize
            int pathSize = Utils.byteArrayToInt(pathSizeBytesDec);

            // If pathSize > 50MB give warning
            if (pathSize > 50000000) {
                logger.warning("Warning: file to decrypt has a full path name of "
                        + Utils.humanReadableByteCount(pathSize) + ".", true);
            }

            // get path string
            byte path[] = new byte[pathSize];
            fis.read(path);
            byte[] pathDec = cryptoWrapperFileNamesAndSizes.cipherBytes(path, Cipher.DECRYPT_MODE);
            String pathStr = new String(pathDec);

            // If the path in the archive ends in a Unix file separator then
            // it's a folder
            pathIsFolder = (pathStr.charAt(pathStr.length() - 1) == Utils.UNIX_SEPARATOR);

            // Remove single, double dot path steps and end separator
            pathStr = FilenameUtils.normalizeNoEndSeparator(pathStr);

            // get permissions for file or directory
            byte[] filePermissions = new byte[2];
            fis.read(filePermissions);
            byte[] filePermissionsDec = cryptoWrapperFileNamesAndSizes.cipherBytes(filePermissions,
                    Cipher.DECRYPT_MODE);
            perms = Utils.byteToPerms(filePermissionsDec);

            // If the current item is a folder
            if (pathIsFolder) {
                File f = new File(outputFolder + pathStr);
                if (!f.mkdir()) {
                    logger.warning("Error: Unable to create folder '" + pathStr + "'", true);
                }
                if (fileSystemIsPosixCompliant)
                    setPosixFilePermissions(f, perms);
            } else {

                // get filesize
                byte b[] = new byte[8];
                fis.read(b);
                byte[] fileSizeDec = cryptoWrapperFileNamesAndSizes.cipherBytes(b, Cipher.DECRYPT_MODE);
                // 8 byte filesize
                long fileSize = Utils.byteArrayToLong(fileSizeDec);

                File fout = new File(outputFolder + pathStr);

                OutputStream os = null;
                String message = "";
                ProgressInfo progressInfo = null;

                if (fout.exists()) {
                    logger.warning("Skipping '" + fout.getName() + "'. File already exists.", true);
                    // Use dummy output stream to ensure the cipher counter
                    // (AES CTR mode) will be incremented and have the
                    // correct value for the decryption of the next file.
                    os = new DummyOutputStream();
                } else {
                    os = new FileOutputStream(fout);
                    message = getCipherMessage(pathStr, Cipher.DECRYPT_MODE);
                    progressInfo = new FileProgressInfo(message, fileSize,
                            cryptoWrapperFileContent.getReadBufferSize());
                }

                cryptoWrapperFileContent.doCipherOperation(fis, os, fileSize, Cipher.DECRYPT_MODE,
                        progressInfo);
                os.close();
                if (fileSystemIsPosixCompliant)
                    setPosixFilePermissions(fout, perms);

                // If a file was written to FileOutputStream
                if (progressInfo != null) {
                    // Increment file counter
                    ++fileCounter;
                    // Ensure next progress info starts on a new line
                    System.out.println();
                }
            }
        }
    } catch (NegativeArraySizeException e) {
        throw new NegativeArraySizeException(fileFormatErrorMessage);
    }
    return fileCounter;

}

From source file:org.esa.s3tbx.olci.radiometry.rayleigh.RayleighAux.java

static double[] getLineSpace(double start, double end, int interval) {
    if (interval < 0) {
        throw new NegativeArraySizeException("Array must not have negative index");
    }/* w w w. j a  v a2  s.  c  o  m*/
    double[] temp = new double[interval];
    double steps = (end - start) / (interval - 1);
    for (int i = 0; i < temp.length; i++) {
        temp[i] = steps * i;
    }
    return temp;
}