Example usage for java.nio ByteBuffer getInt

List of usage examples for java.nio ByteBuffer getInt

Introduction

In this page you can find the example usage for java.nio ByteBuffer getInt.

Prototype

public abstract int getInt(int index);

Source Link

Document

Returns the int at the specified index.

Usage

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asIntBuffer().put(99471142);/*from   ww  w  . ja  va 2 s .  c  o  m*/
    System.out.println(bb.getInt(0));
}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asIntBuffer().put(99471142);//from w  ww . j a va  2  s  .c  o m

    System.out.println(bb.getInt(0));
}

From source file:Main.java

public static long getUnsignedInt(ByteBuffer bb, int position) {
    return ((long) bb.getInt(position) & 0xffffffffL);
}

From source file:Main.java

public static long getUnsignedInt(final ByteBuffer pByteBuffer, final int pPosition) {
    return pByteBuffer.getInt(pPosition) & 0xFFFFFFFFL;
}

From source file:Main.java

private static Rect getRectByByte(byte[] org) {
    Rect rect = new Rect();
    ByteBuffer byteBuffer = ByteBuffer.wrap(org).order(ByteOrder.nativeOrder());
    rect.set(byteBuffer.getInt(3 * 4), byteBuffer.getInt(5 * 4), byteBuffer.getInt(4 * 4),
            byteBuffer.getInt(6 * 4));//  w  w w  .jav  a 2  s . c o m
    return rect;
}

From source file:Main.java

public static int byteArrayToInt(byte[] bytes, int offset) {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    return bb.getInt(offset);
}

From source file:org.bimserver.utils.BinUtils.java

public static int readInt(byte[] bytes, int index) {
    ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    return byteBuffer.getInt(index);
}

From source file:org.bimserver.utils.BinUtils.java

public static int byteArrayToInt(byte[] value, int index) {
    ByteBuffer byteBuffer = ByteBuffer.wrap(value);
    return byteBuffer.getInt(index);
}

From source file:com.healthmarketscience.jackcess.impl.ComplexColumnSupport.java

/**
 * Creates a ComplexColumnInfo for a complex column.
 *///from  w ww .j a va 2s.c  om
public static ComplexColumnInfo<? extends ComplexValue> create(ColumnImpl column, ByteBuffer buffer, int offset)
        throws IOException {
    int complexTypeId = buffer.getInt(offset + column.getFormat().OFFSET_COLUMN_COMPLEX_ID);

    DatabaseImpl db = column.getDatabase();
    TableImpl complexColumns = db.getSystemComplexColumns();
    IndexCursor cursor = CursorBuilder.createCursor(complexColumns.getPrimaryKeyIndex());
    if (!cursor.findFirstRowByEntry(complexTypeId)) {
        throw new IOException("Could not find complex column info for complex column with id " + complexTypeId);
    }
    Row cColRow = cursor.getCurrentRow();
    int tableId = cColRow.getInt(COL_TABLE_ID);
    if (tableId != column.getTable().getTableDefPageNumber()) {
        throw new IOException("Found complex column for table " + tableId + " but expected table "
                + column.getTable().getTableDefPageNumber());
    }
    int flatTableId = cColRow.getInt(COL_FLAT_TABLE_ID);
    int typeObjId = cColRow.getInt(COL_COMPLEX_TYPE_OBJECT_ID);

    TableImpl typeObjTable = db.getTable(typeObjId);
    TableImpl flatTable = db.getTable(flatTableId);

    if ((typeObjTable == null) || (flatTable == null)) {
        throw new IOException("Could not find supporting tables (" + typeObjId + ", " + flatTableId
                + ") for complex column with id " + complexTypeId);
    }

    // we inspect the structore of the "type table" to determine what kind of
    // complex info we are dealing with
    if (isMultiValueColumn(typeObjTable)) {
        return new MultiValueColumnInfoImpl(column, complexTypeId, typeObjTable, flatTable);
    } else if (isAttachmentColumn(typeObjTable)) {
        return new AttachmentColumnInfoImpl(column, complexTypeId, typeObjTable, flatTable);
    } else if (isVersionHistoryColumn(typeObjTable)) {
        return new VersionHistoryColumnInfoImpl(column, complexTypeId, typeObjTable, flatTable);
    }

    LOG.warn("Unsupported complex column type " + typeObjTable.getName());
    return new UnsupportedColumnInfoImpl(column, complexTypeId, typeObjTable, flatTable);
}

From source file:Main.java

public static long getCommentLength(final FileChannel fileChannel) throws IOException {
    // End of central directory record (EOCD)
    // Offset    Bytes     Description[23]
    // 0           4       End of central directory signature = 0x06054b50
    // 4           2       Number of this disk
    // 6           2       Disk where central directory starts
    // 8           2       Number of central directory records on this disk
    // 10          2       Total number of central directory records
    // 12          4       Size of central directory (bytes)
    // 16          4       Offset of start of central directory, relative to start of archive
    // 20          2       Comment length (n)
    // 22          n       Comment
    // For a zip with no archive comment, the
    // end-of-central-directory record will be 22 bytes long, so
    // we expect to find the EOCD marker 22 bytes from the end.

    final long archiveSize = fileChannel.size();
    if (archiveSize < ZIP_EOCD_REC_MIN_SIZE) {
        throw new IOException("APK too small for ZIP End of Central Directory (EOCD) record");
    }/*from w w  w.  j  a v a 2s. c o m*/
    // ZIP End of Central Directory (EOCD) record is located at the very end of the ZIP archive.
    // The record can be identified by its 4-byte signature/magic which is located at the very
    // beginning of the record. A complication is that the record is variable-length because of
    // the comment field.
    // The algorithm for locating the ZIP EOCD record is as follows. We search backwards from
    // end of the buffer for the EOCD record signature. Whenever we find a signature, we check
    // the candidate record's comment length is such that the remainder of the record takes up
    // exactly the remaining bytes in the buffer. The search is bounded because the maximum
    // size of the comment field is 65535 bytes because the field is an unsigned 16-bit number.
    final long maxCommentLength = Math.min(archiveSize - ZIP_EOCD_REC_MIN_SIZE, UINT16_MAX_VALUE);
    final long eocdWithEmptyCommentStartPosition = archiveSize - ZIP_EOCD_REC_MIN_SIZE;
    for (int expectedCommentLength = 0; expectedCommentLength <= maxCommentLength; expectedCommentLength++) {
        final long eocdStartPos = eocdWithEmptyCommentStartPosition - expectedCommentLength;

        final ByteBuffer byteBuffer = ByteBuffer.allocate(4);
        fileChannel.position(eocdStartPos);
        fileChannel.read(byteBuffer);
        byteBuffer.order(ByteOrder.LITTLE_ENDIAN);

        if (byteBuffer.getInt(0) == ZIP_EOCD_REC_SIG) {
            final ByteBuffer commentLengthByteBuffer = ByteBuffer.allocate(2);
            fileChannel.position(eocdStartPos + ZIP_EOCD_COMMENT_LENGTH_FIELD_OFFSET);
            fileChannel.read(commentLengthByteBuffer);
            commentLengthByteBuffer.order(ByteOrder.LITTLE_ENDIAN);

            final int actualCommentLength = commentLengthByteBuffer.getShort(0);
            if (actualCommentLength == expectedCommentLength) {
                return actualCommentLength;
            }
        }
    }
    throw new IOException("ZIP End of Central Directory (EOCD) record not found");
}