Example usage for java.lang Integer SIZE

List of usage examples for java.lang Integer SIZE

Introduction

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

Prototype

int SIZE

To view the source code for java.lang Integer SIZE.

Click Source Link

Document

The number of bits used to represent an int value in two's complement binary form.

Usage

From source file:org.callimachusproject.auth.CookieAuthenticationManager.java

private String getPassword(int hour, String username, String iri, String nonce) throws IOException {
    int size = secret.length + username.length() + iri.length() + nonce.length();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(size * 2);
    baos.write(secret);//  w  w w  .java  2s  . c o m
    for (int i = 0, n = Integer.SIZE / Byte.SIZE; i < n; i++) {
        baos.write((byte) hour);
        hour >>= Byte.SIZE;
    }
    baos.write(getIdentifier().getBytes("UTF-8"));
    baos.write(username.getBytes("UTF-8"));
    baos.write(iri.getBytes("UTF-8"));
    baos.write(nonce.getBytes("UTF-8"));
    return new String(Hex.encodeHex(DigestUtils.md5(baos.toByteArray())));
}

From source file:org.apache.hadoop.hive.serde2.compression.SnappyCompDe.java

private int writePrimitives(int[] primitives, ByteBuffer output) throws IOException {
    int bytesWritten = Snappy.rawCompress(primitives, 0, primitives.length * Integer.SIZE / Byte.SIZE,
            output.array(), output.arrayOffset() + output.position());
    output.position(output.position() + bytesWritten);
    return bytesWritten;
}

From source file:org.callimachusproject.auth.DigestPasswordAccessor.java

private String getDaypass(int day, String email, String secret) {
    if (secret == null)
        return null;
    byte[] random = readBytes(secret);
    byte[] id = email.getBytes(Charset.forName("UTF-8"));
    byte[] seed = new byte[random.length + id.length + Integer.SIZE / Byte.SIZE];
    System.arraycopy(random, 0, seed, 0, random.length);
    System.arraycopy(id, 0, seed, random.length, id.length);
    for (int i = random.length + id.length; i < seed.length; i++) {
        seed[i] = (byte) day;
        day >>= Byte.SIZE;/*from   www .  j a  v a 2 s  .  c o  m*/
    }
    return new PasswordGenerator(seed).nextPassword();
}

From source file:org.eclipse.january.dataset.DTypeUtils.java

/**
 * @param dtype//from  w ww. j  av a2s.  c  o m
 * @param isize
 *            number of elements in an item
 * @return length of single item in bytes
 */
public static int getItemBytes(final int dtype, final int isize) {
    int size;

    switch (dtype) {
    case Dataset.BOOL:
        size = 1; // How is this defined?
        break;
    case Dataset.INT8:
    case Dataset.ARRAYINT8:
        size = Byte.SIZE / 8;
        break;
    case Dataset.INT16:
    case Dataset.ARRAYINT16:
    case Dataset.RGB:
        size = Short.SIZE / 8;
        break;
    case Dataset.INT32:
    case Dataset.ARRAYINT32:
        size = Integer.SIZE / 8;
        break;
    case Dataset.INT64:
    case Dataset.ARRAYINT64:
        size = Long.SIZE / 8;
        break;
    case Dataset.FLOAT32:
    case Dataset.ARRAYFLOAT32:
    case Dataset.COMPLEX64:
        size = Float.SIZE / 8;
        break;
    case Dataset.FLOAT64:
    case Dataset.ARRAYFLOAT64:
    case Dataset.COMPLEX128:
        size = Double.SIZE / 8;
        break;
    default:
        size = 0;
        break;
    }

    return size * isize;
}

From source file:org.kiji.schema.FormattedEntityId.java

/**
 * Decode a byte array containing an hbase row key into an ordered list corresponding to
 * the key format in the layout file.//from w ww  .  j  a  v  a  2  s.  c  o m
 *
 * @param format The row key format as specified in the layout file.
 * @param hbaseRowKey A byte array containing the hbase row key.
 * @return An ordered list of component values in the key.
 */
private static List<Object> makeKijiRowKey(RowKeyFormat2 format, byte[] hbaseRowKey) {
    if (hbaseRowKey.length == 0) {
        throw new EntityIdException("Invalid hbase row key");
    }
    List<Object> kijiRowKey = new ArrayList<Object>();
    // skip over the hash
    int pos = format.getSalt().getHashSize();
    // we are suppressing materialization, so the components cannot be retrieved.
    int kijiRowElem = 0;
    if (format.getSalt().getSuppressKeyMaterialization()) {
        if (pos < hbaseRowKey.length) {
            throw new EntityIdException("Extra bytes in key after hash when materialization is" + "suppressed");
        }
        return null;
    }
    ByteBuffer buf;

    while (kijiRowElem < format.getComponents().size() && pos < hbaseRowKey.length) {
        switch (format.getComponents().get(kijiRowElem).getType()) {
        case STRING:
            // Read the row key until we encounter a Null (0) byte or end.
            int endpos = pos;
            while (endpos < hbaseRowKey.length && (hbaseRowKey[endpos] != (byte) 0)) {
                endpos += 1;
            }
            String str = null;
            try {
                str = new String(hbaseRowKey, pos, endpos - pos, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                LOG.error(e.toString());
                throw new EntityIdException(String.format("UnsupportedEncoding for component %d", kijiRowElem));
            }
            kijiRowKey.add(str);
            pos = endpos + 1;
            break;
        case INTEGER:
            // Toggle highest order bit to return to original 2's complement.
            hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE);
            try {
                buf = ByteBuffer.wrap(hbaseRowKey, pos, Integer.SIZE / Byte.SIZE);
            } catch (IndexOutOfBoundsException e) {
                throw new EntityIdException("Malformed hbase Row Key");
            }
            kijiRowKey.add(Integer.valueOf(buf.getInt()));
            pos = pos + Integer.SIZE / Byte.SIZE;
            break;
        case LONG:
            // Toggle highest order bit to return to original 2's complement.
            hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE);
            try {
                buf = ByteBuffer.wrap(hbaseRowKey, pos, Long.SIZE / Byte.SIZE);
            } catch (IndexOutOfBoundsException e) {
                throw new EntityIdException("Malformed hbase Row Key");
            }
            kijiRowKey.add(Long.valueOf(buf.getLong()));
            pos = pos + Long.SIZE / Byte.SIZE;
            break;
        default:
            throw new RuntimeException("Invalid code path");
        }
        kijiRowElem += 1;
    }

    // Fail if there are extra bytes in hbase row key.
    if (pos < hbaseRowKey.length) {
        throw new EntityIdException("Extra bytes in hbase row key cannot be mapped to any " + "component");
    }

    // Fail if we encounter nulls before it is legal to do so.
    if (kijiRowElem < format.getNullableStartIndex()) {
        throw new EntityIdException("Too few components decoded from hbase row key. Component " + "number "
                + kijiRowElem + " cannot be null");
    }

    // finish up with nulls for everything that wasn't in the key
    for (; kijiRowElem < format.getComponents().size(); kijiRowElem++) {
        kijiRowKey.add(null);
    }

    return kijiRowKey;
}

From source file:com.moz.fiji.schema.FormattedEntityId.java

/**
 * Decode a byte array containing an hbase row key into an ordered list corresponding to
 * the key format in the layout file./* w  w w .  j  ava  2  s . c  o  m*/
 *
 * @param format The row key format as specified in the layout file.
 * @param hbaseRowKey A byte array containing the hbase row key.
 * @return An ordered list of component values in the key.
 */
private static List<Object> makeFijiRowKey(RowKeyFormat2 format, byte[] hbaseRowKey) {
    if (hbaseRowKey.length == 0) {
        throw new EntityIdException("Invalid hbase row key");
    }
    List<Object> fijiRowKey = new ArrayList<Object>();
    // skip over the hash
    int pos = format.getSalt().getHashSize();
    // we are suppressing materialization, so the components cannot be retrieved.
    int fijiRowElem = 0;
    if (format.getSalt().getSuppressKeyMaterialization()) {
        if (pos < hbaseRowKey.length) {
            throw new EntityIdException("Extra bytes in key after hash when materialization is" + "suppressed");
        }
        return null;
    }
    ByteBuffer buf;

    while (fijiRowElem < format.getComponents().size() && pos < hbaseRowKey.length) {
        switch (format.getComponents().get(fijiRowElem).getType()) {
        case STRING:
            // Read the row key until we encounter a Null (0) byte or end.
            int endpos = pos;
            while (endpos < hbaseRowKey.length && (hbaseRowKey[endpos] != (byte) 0)) {
                endpos += 1;
            }
            String str = null;
            try {
                str = new String(hbaseRowKey, pos, endpos - pos, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                LOG.error(e.toString());
                throw new EntityIdException(String.format("UnsupportedEncoding for component %d", fijiRowElem));
            }
            fijiRowKey.add(str);
            pos = endpos + 1;
            break;
        case INTEGER:
            // Toggle highest order bit to return to original 2's complement.
            hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE);
            try {
                buf = ByteBuffer.wrap(hbaseRowKey, pos, Integer.SIZE / Byte.SIZE);
            } catch (IndexOutOfBoundsException e) {
                throw new EntityIdException("Malformed hbase Row Key");
            }
            fijiRowKey.add(Integer.valueOf(buf.getInt()));
            pos = pos + Integer.SIZE / Byte.SIZE;
            break;
        case LONG:
            // Toggle highest order bit to return to original 2's complement.
            hbaseRowKey[pos] = (byte) ((int) hbaseRowKey[pos] ^ (int) Byte.MIN_VALUE);
            try {
                buf = ByteBuffer.wrap(hbaseRowKey, pos, Long.SIZE / Byte.SIZE);
            } catch (IndexOutOfBoundsException e) {
                throw new EntityIdException("Malformed hbase Row Key");
            }
            fijiRowKey.add(Long.valueOf(buf.getLong()));
            pos = pos + Long.SIZE / Byte.SIZE;
            break;
        default:
            throw new RuntimeException("Invalid code path");
        }
        fijiRowElem += 1;
    }

    // Fail if there are extra bytes in hbase row key.
    if (pos < hbaseRowKey.length) {
        throw new EntityIdException("Extra bytes in hbase row key cannot be mapped to any " + "component");
    }

    // Fail if we encounter nulls before it is legal to do so.
    if (fijiRowElem < format.getNullableStartIndex()) {
        throw new EntityIdException("Too few components decoded from hbase row key. Component " + "number "
                + fijiRowElem + " cannot be null");
    }

    // finish up with nulls for everything that wasn't in the key
    for (; fijiRowElem < format.getComponents().size(); fijiRowElem++) {
        fijiRowKey.add(null);
    }

    return fijiRowKey;
}

From source file:org.apache.hadoop.hive.serde2.compression.SnappyCompDe.java

/**
 * Decompress a set of columns from a ByteBuffer and update the position of the buffer.
 *
 * @param input A ByteBuffer with `position` indicating the starting point of the compressed chunk.
 * @param chunkSize The length of the compressed chunk to be decompressed from the input buffer.
 *
 * @return The set of columns.//from w w w  .ja  va  2s .  c  o m
 */
@Override
public ColumnBuffer[] decompress(ByteBuffer input, int chunkSize) {
    int startPos = input.position();
    try {
        // Read the footer.
        int footerSize = input.getInt(startPos + chunkSize - 4);
        Iterator<Integer> compressedSize = Arrays
                .asList(ArrayUtils.toObject(Snappy.uncompressIntArray(input.array(),
                        input.arrayOffset() + startPos + chunkSize - Integer.SIZE / Byte.SIZE - footerSize,
                        footerSize)))
                .iterator();

        // Read the header.
        int[] dataType = readIntegers(compressedSize.next(), input);
        int numOfCols = dataType.length;

        // Read the columns.
        ColumnBuffer[] outputCols = new ColumnBuffer[numOfCols];
        for (int colNum = 0; colNum < numOfCols; colNum++) {
            byte[] nulls = readBytes(compressedSize.next(), input);

            switch (TTypeId.findByValue(dataType[colNum])) {
            case BOOLEAN_TYPE: {
                int numRows = input.getInt();
                byte[] vals = readBytes(compressedSize.next(), input);
                BitSet bsBools = BitSet.valueOf(vals);

                boolean[] bools = new boolean[numRows];
                for (int rowNum = 0; rowNum < numRows; rowNum++) {
                    bools[rowNum] = bsBools.get(rowNum);
                }

                TBoolColumn column = new TBoolColumn(Arrays.asList(ArrayUtils.toObject(bools)),
                        ByteBuffer.wrap(nulls));
                outputCols[colNum] = new ColumnBuffer(TColumn.boolVal(column));
                break;
            }
            case TINYINT_TYPE: {
                byte[] vals = readBytes(compressedSize.next(), input);
                TByteColumn column = new TByteColumn(Arrays.asList(ArrayUtils.toObject(vals)),
                        ByteBuffer.wrap(nulls));
                outputCols[colNum] = new ColumnBuffer(TColumn.byteVal(column));
                break;
            }
            case SMALLINT_TYPE: {
                short[] vals = readShorts(compressedSize.next(), input);
                TI16Column column = new TI16Column(Arrays.asList(ArrayUtils.toObject(vals)),
                        ByteBuffer.wrap(nulls));
                outputCols[colNum] = new ColumnBuffer(TColumn.i16Val(column));
                break;
            }
            case INT_TYPE: {
                int[] vals = readIntegers(compressedSize.next(), input);
                TI32Column column = new TI32Column(Arrays.asList(ArrayUtils.toObject(vals)),
                        ByteBuffer.wrap(nulls));
                outputCols[colNum] = new ColumnBuffer(TColumn.i32Val(column));
                break;
            }
            case BIGINT_TYPE: {
                long[] vals = readLongs(compressedSize.next(), input);
                TI64Column column = new TI64Column(Arrays.asList(ArrayUtils.toObject(vals)),
                        ByteBuffer.wrap(nulls));
                outputCols[colNum] = new ColumnBuffer(TColumn.i64Val(column));
                break;
            }
            case DOUBLE_TYPE: {
                double[] vals = readDoubles(compressedSize.next(), input);
                TDoubleColumn column = new TDoubleColumn(Arrays.asList(ArrayUtils.toObject(vals)),
                        ByteBuffer.wrap(nulls));
                outputCols[colNum] = new ColumnBuffer(TColumn.doubleVal(column));
                break;
            }
            case BINARY_TYPE: {
                int[] rowSize = readIntegers(compressedSize.next(), input);

                ByteBuffer flattenedData = ByteBuffer.wrap(readBytes(compressedSize.next(), input));
                ByteBuffer[] vals = new ByteBuffer[rowSize.length];

                for (int rowNum = 0; rowNum < rowSize.length; rowNum++) {
                    vals[rowNum] = ByteBuffer.wrap(flattenedData.array(), flattenedData.position(),
                            rowSize[rowNum]);
                    flattenedData.position(flattenedData.position() + rowSize[rowNum]);
                }

                TBinaryColumn column = new TBinaryColumn(Arrays.asList(vals), ByteBuffer.wrap(nulls));
                outputCols[colNum] = new ColumnBuffer(TColumn.binaryVal(column));
                break;
            }
            case STRING_TYPE: {
                int[] rowSize = readIntegers(compressedSize.next(), input);

                ByteBuffer flattenedData = ByteBuffer.wrap(readBytes(compressedSize.next(), input));

                String[] vals = new String[rowSize.length];

                for (int rowNum = 0; rowNum < rowSize.length; rowNum++) {
                    vals[rowNum] = new String(flattenedData.array(), flattenedData.position(), rowSize[rowNum],
                            StandardCharsets.UTF_8);
                    flattenedData.position(flattenedData.position() + rowSize[rowNum]);
                }

                TStringColumn column = new TStringColumn(Arrays.asList(vals), ByteBuffer.wrap(nulls));
                outputCols[colNum] = new ColumnBuffer(TColumn.stringVal(column));
                break;
            }
            default:
                throw new IllegalStateException(
                        "Unrecognized column type: " + TTypeId.findByValue(dataType[colNum]));
            }
        }
        input.position(startPos + chunkSize);
        return outputCols;
    } catch (IOException e) {
        e.printStackTrace();
        return (ColumnBuffer[]) null;
    }
}

From source file:org.cellprofiler.subimager.ImageWriterHandler.java

private byte[] convertImage(NDImage ndimage, PixelType pixelType, boolean toBigEndian) {
    double[] inputDouble = ndimage.getBuffer();
    switch (pixelType) {
    case INT8:// ww w .  j  av a 2  s. com
        return convertToIntegerType(inputDouble, Byte.MIN_VALUE, Byte.MAX_VALUE, Byte.SIZE / 8, toBigEndian);
    case UINT8:
        return convertToIntegerType(inputDouble, 0, (1L << Byte.SIZE) - 1, Byte.SIZE / 8, toBigEndian);
    case INT16:
        return convertToIntegerType(inputDouble, Short.MIN_VALUE, Short.MAX_VALUE, Short.SIZE / 8, toBigEndian);
    case UINT16:
        return convertToIntegerType(inputDouble, 0, (1L << Short.SIZE) - 1, Short.SIZE / 8, toBigEndian);
    case INT32:
        return convertToIntegerType(inputDouble, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.SIZE / 8,
                toBigEndian);
    case UINT32:
        return convertToIntegerType(inputDouble, 0, (1L << Integer.SIZE) - 1, Integer.SIZE / 8, toBigEndian);
    case FLOAT: {
        int bpp = Float.SIZE / 8;
        byte[] buffer = new byte[inputDouble.length * bpp];
        for (int i = 0; i < inputDouble.length; i++) {
            DataTools.unpackBytes(Float.floatToIntBits((float) inputDouble[i]), buffer, i * bpp, bpp,
                    !toBigEndian);
        }
        return buffer;
    }
    case DOUBLE: {
        int bpp = Double.SIZE / 8;
        byte[] buffer = new byte[inputDouble.length * bpp];
        for (int i = 0; i < inputDouble.length; i++) {
            DataTools.unpackBytes(Double.doubleToLongBits(inputDouble[i]), buffer, i * bpp, bpp, !toBigEndian);
        }
        return buffer;
    }
    default:
        throw new UnsupportedOperationException("The pixel type, " + pixelType.getValue()
                + ", should have been explicitly handled by the caller and an error should have been reported to the web client.");
    }
}

From source file:org.apache.hadoop.hbase.ipc.ScheduleHBaseServer.java

/**
 * Initiate the table priorities./*from  w w  w.  j  av a2  s  . com*/
 */
private void initPriority() {
    try {
        handleFreshInter = conf.getInt("hbase.schedule.refreshinter", 7);
        move = Integer.SIZE - handleFreshInter;
        HTableDescriptor[] tableDs = CheckMeta.getTables();
        int pri = defaultPri;
        for (HTableDescriptor des : tableDs) {
            byte[] prib = des.getValue(Bytes.toBytes(pri_string));
            if (prib != null) {
                try {
                    pri = Integer.parseInt(Bytes.toString((prib)));
                } catch (Exception e) {
                    LOG.error("table priority error :" + Bytes.toString(prib) + " table name:"
                            + des.getNameAsString());
                }
            }
            tablePriMap.put(des.getNameAsString(), pri);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    for (Long id : scannerPriMap.keySet()) {
        if (scannersMap.get(String.valueOf(id)) == null) {
            scannerPriMap.remove(id);
        }
    }
    for (Long id : scannerPriMapInteger.keySet()) {
        if (scannersMap.get(String.valueOf(id)) == null) {
            scannerPriMapInteger.remove(id);
        }
    }

    for (String regionName : regionPriMap.keySet()) {
        this.initRegionPri(regionName, true);
    }

    // List<HRegionInfo> infos = ((HRegionServer) this.instance)
    // .getOnlineRegions();
    // for (HRegionInfo info : infos) {
    // //System.out.println(Bytes.toString(info.getEncodedName() ));
    // Integer pri = this.tablePriMap.get(info.getTableDesc().getName());
    // if (pri != null) {
    // this.regionPriMap.put(info.getEncodedNameAsBytes(), pri);
    // } else if (info.isMetaRegion()) {
    // this.regionPriMap.put(info.getEncodedNameAsBytes(),
    // this.highestPri);
    // } else if (info.isRootRegion()) {
    // this.regionPriMap.put(info.getEncodedNameAsBytes(),
    // this.highestPri);
    // } else {
    // this.regionPriMap.put(info.getEncodedNameAsBytes(),
    // this.defaultPri);
    // }
    // }
}

From source file:de.rwhq.btree.InnerNode.java

public int getMaxNumberOfKeys() {
    int size = rawPage.bufferForReading(0).limit() - Header.size();

    // size first page id
    size -= Integer.SIZE / 8;

    return size / (Integer.SIZE / 8 + keySerializer.getSerializedLength());
}