List of usage examples for java.nio ByteBuffer putInt
public abstract ByteBuffer putInt(int value);
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionUDPDstPortMatchMsg(short dst_port) { ByteBuffer ipv6ext_udp_dstport_msg = ByteBuffer.allocate(6); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, OF_Match_Types.MATCH_OF_UDP_DST.getValue(), 0, 2); ipv6ext_udp_dstport_msg.putInt(nxm_header); ipv6ext_udp_dstport_msg.putShort(dst_port); return (ipv6ext_udp_dstport_msg.array()); }
From source file:com.healthmarketscience.jackcess.IndexData.java
/** * Writes the index definitions into a table definition buffer. * @param buffer Buffer to write to/*from w ww.j a v a2s .com*/ * @param indexes List of IndexBuilders to write definitions for */ protected static void writeDefinitions(TableCreator creator, ByteBuffer buffer) throws IOException { ByteBuffer rootPageBuffer = creator.getPageChannel().createPageBuffer(); writeDataPage(rootPageBuffer, SimpleIndexData.NEW_ROOT_DATA_PAGE, creator.getTdefPageNumber(), creator.getFormat()); for (IndexBuilder idx : creator.getIndexes()) { buffer.putInt(MAGIC_INDEX_NUMBER); // seemingly constant magic value // write column information (always MAX_COLUMNS entries) List<IndexBuilder.Column> idxColumns = idx.getColumns(); for (int i = 0; i < MAX_COLUMNS; ++i) { short columnNumber = COLUMN_UNUSED; byte flags = 0; if (i < idxColumns.size()) { // determine column info IndexBuilder.Column idxCol = idxColumns.get(i); flags = idxCol.getFlags(); // find actual table column number for (Column col : creator.getColumns()) { if (col.getName().equalsIgnoreCase(idxCol.getName())) { columnNumber = col.getColumnNumber(); break; } } if (columnNumber == COLUMN_UNUSED) { // should never happen as this is validated before throw new IllegalArgumentException("Column with name " + idxCol.getName() + " not found"); } } buffer.putShort(columnNumber); // table column number buffer.put(flags); // column flags (e.g. ordering) } TableCreator.IndexState idxState = creator.getIndexState(idx); buffer.put(idxState.getUmapRowNumber()); // umap row ByteUtil.put3ByteInt(buffer, creator.getUmapPageNumber()); // umap page // write empty root index page creator.getPageChannel().writePage(rootPageBuffer, idxState.getRootPageNumber()); buffer.putInt(idxState.getRootPageNumber()); buffer.putInt(0); // unknown buffer.put(idx.getFlags()); // index flags (unique, etc.) ByteUtil.forward(buffer, 5); // unknown } }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionSrcIPv6MatchMsg(byte[] srcIpv6) { ByteBuffer ipv6ext_ipv6_msg = ByteBuffer.allocate(20); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.IPV6EXT, IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_SRC.getValue(), 0, 16); ipv6ext_ipv6_msg.putInt(nxm_header); ipv6ext_ipv6_msg.put(srcIpv6);/*w ww . j a va2s . c o m*/ return (ipv6ext_ipv6_msg.array()); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionDstIPv6MatchMsg(byte[] dstIpv6) { ByteBuffer ipv6ext_ipv6_msg = ByteBuffer.allocate(20); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.IPV6EXT, IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_DST.getValue(), 0, 16); ipv6ext_ipv6_msg.putInt(nxm_header); ipv6ext_ipv6_msg.put(dstIpv6);//ww w . j a va2s . c o m return (ipv6ext_ipv6_msg.array()); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionSrcIPv6MatchwithMaskMsg(byte[] srcIpv6, short masklen) { ByteBuffer ipv6ext_ipv6_msg = ByteBuffer.allocate(36); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.IPV6EXT, IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_SRC.getValue(), 1, 32); ipv6ext_ipv6_msg.putInt(nxm_header); ipv6ext_ipv6_msg.put(srcIpv6);/* w ww . j a va 2s .com*/ byte[] ipv6_mask = getIPv6NetworkMaskinBytes(masklen); ipv6ext_ipv6_msg.put(ipv6_mask); return (ipv6ext_ipv6_msg.array()); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionDstIPv6MatchwithMaskMsg(byte[] dstIpv6, short masklen) { ByteBuffer ipv6ext_ipv6_msg = ByteBuffer.allocate(36); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.IPV6EXT, IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_DST.getValue(), 1, 32); ipv6ext_ipv6_msg.putInt(nxm_header); ipv6ext_ipv6_msg.put(dstIpv6);/*from www .ja v a 2 s. co m*/ byte[] ipv6_mask = getIPv6NetworkMaskinBytes(masklen); ipv6ext_ipv6_msg.put(ipv6_mask); return (ipv6ext_ipv6_msg.array()); }
From source file:com.healthmarketscience.jackcess.Table.java
/** * @param buffer Buffer to write to/*from w w w . ja va 2 s . c om*/ * @param columns List of Columns in the table */ private static void writeTableDefinitionHeader(TableCreator creator, ByteBuffer buffer, int totalTableDefSize) throws IOException { List<Column> columns = creator.getColumns(); //Start writing the tdef writeTablePageHeader(buffer); buffer.putInt(totalTableDefSize); //Length of table def buffer.putInt(MAGIC_TABLE_NUMBER); // seemingly constant magic value buffer.putInt(0); //Number of rows buffer.putInt(0); //Last Autonumber buffer.put((byte) 1); // this makes autonumbering work in access for (int i = 0; i < 15; i++) { //Unknown buffer.put((byte) 0); } buffer.put(Table.TYPE_USER); //Table type buffer.putShort((short) columns.size()); //Max columns a row will have buffer.putShort(Column.countVariableLength(columns)); //Number of variable columns in table buffer.putShort((short) columns.size()); //Number of columns in table buffer.putInt(creator.getLogicalIndexCount()); //Number of logical indexes in table buffer.putInt(creator.getIndexCount()); //Number of indexes in table buffer.put((byte) 0); //Usage map row number ByteUtil.put3ByteInt(buffer, creator.getUmapPageNumber()); //Usage map page number buffer.put((byte) 1); //Free map row number ByteUtil.put3ByteInt(buffer, creator.getUmapPageNumber()); //Free map page number if (LOG.isDebugEnabled()) { int position = buffer.position(); buffer.rewind(); LOG.debug("Creating new table def block:\n" + ByteUtil.toHexString(buffer, creator.getFormat().SIZE_TDEF_HEADER)); buffer.position(position); } }
From source file:com.healthmarketscience.jackcess.impl.ColumnImpl.java
/** * Writes the column definitions into a table definition buffer. * @param buffer Buffer to write to/*from w w w .j a va 2s . c o m*/ */ protected static void writeDefinitions(TableCreator creator, ByteBuffer buffer) throws IOException { List<ColumnBuilder> columns = creator.getColumns(); short fixedOffset = (short) 0; short variableOffset = (short) 0; // we specifically put the "long variable" values after the normal // variable length values so that we have a better chance of fitting it // all (because "long variable" values can go in separate pages) short longVariableOffset = countNonLongVariableLength(columns); for (ColumnBuilder col : columns) { buffer.put(col.getType().getValue()); buffer.putInt(TableImpl.MAGIC_TABLE_NUMBER); //constant magic number buffer.putShort(col.getColumnNumber()); //Column Number if (col.isVariableLength()) { if (!col.getType().isLongValue()) { buffer.putShort(variableOffset++); } else { buffer.putShort(longVariableOffset++); } } else { buffer.putShort((short) 0); } buffer.putShort(col.getColumnNumber()); //Column Number again if (col.getType().isTextual()) { // this will write 4 bytes (note we don't support writing dbs which // use the text code page) writeSortOrder(buffer, col.getTextSortOrder(), creator.getFormat()); } else { // note scale/precision not stored for calculated numeric fields if (col.getType().getHasScalePrecision() && !col.isCalculated()) { buffer.put(col.getPrecision()); // numeric precision buffer.put(col.getScale()); // numeric scale } else { buffer.put((byte) 0x00); //unused buffer.put((byte) 0x00); //unused } buffer.putShort((short) 0); //Unknown } buffer.put(getColumnBitFlags(col)); // misc col flags // note access doesn't seem to allow unicode compression for calced fields if (col.isCalculated()) { buffer.put(CALCULATED_EXT_FLAG_MASK); } else if (col.isCompressedUnicode()) { //Compressed buffer.put(COMPRESSED_UNICODE_EXT_FLAG_MASK); } else { buffer.put((byte) 0); } buffer.putInt(0); //Unknown, but always 0. //Offset for fixed length columns if (col.isVariableLength()) { buffer.putShort((short) 0); } else { buffer.putShort(fixedOffset); fixedOffset += col.getType().getFixedSize(col.getLength()); } if (!col.getType().isLongValue()) { short length = col.getLength(); if (col.isCalculated()) { // calced columns have additional value overhead if (!col.getType().isVariableLength() || col.getType().getHasScalePrecision()) { length = CalculatedColumnUtil.CALC_FIXED_FIELD_LEN; } else { length += CalculatedColumnUtil.CALC_EXTRA_DATA_LEN; } } buffer.putShort(length); //Column length } else { buffer.putShort((short) 0x0000); // unused } } for (ColumnBuilder col : columns) { TableImpl.writeName(buffer, col.getName(), creator.getCharset()); } }
From source file:org.apache.bookkeeper.client.BookieWriteLedgerTest.java
/** * Verify that attempts to use addEntry() variant that does not require specifying entry id * on LedgerHandleAdv results in error./*from www. j av a2 s . c o m*/ * * @throws Exception */ @Test public void testLedgerCreateAdvAndWriteNonAdv() throws Exception { long ledgerId = 0xABCDEF; lh = bkc.createLedgerAdv(ledgerId, 3, 3, 2, digestType, ledgerPassword, null); ByteBuffer entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); try { lh.addEntry(entry.array()); fail("expected IllegalOpException"); } catch (BKException.BKIllegalOpException e) { // pass, expected } finally { lh.close(); bkc.deleteLedger(ledgerId); } }
From source file:com.healthmarketscience.jackcess.Table.java
/** * Create the usage map definition page buffer. The "used pages" map is in * row 0, the "pages with free space" map is in row 1. Index usage maps are * in subsequent rows./*from w ww.j a va 2 s.co m*/ */ private static void createUsageMapDefinitionBuffer(TableCreator creator) throws IOException { // 2 table usage maps plus 1 for each index int umapNum = 2 + creator.getIndexCount(); JetFormat format = creator.getFormat(); int usageMapRowLength = format.OFFSET_USAGE_MAP_START + format.USAGE_MAP_TABLE_BYTE_LENGTH; int freeSpace = format.DATA_PAGE_INITIAL_FREE_SPACE - (umapNum * getRowSpaceUsage(usageMapRowLength, format)); // for now, don't handle writing that many indexes if (freeSpace < 0) { throw new IOException("FIXME attempting to write too many indexes"); } int umapPageNumber = creator.getUmapPageNumber(); PageChannel pageChannel = creator.getPageChannel(); ByteBuffer rtn = pageChannel.createPageBuffer(); rtn.put(PageTypes.DATA); rtn.put((byte) 0x1); //Unknown rtn.putShort((short) freeSpace); //Free space in page rtn.putInt(0); //Table definition rtn.putInt(0); //Unknown rtn.putShort((short) umapNum); //Number of records on this page // write two rows of usage map definitions for the table int rowStart = findRowEnd(rtn, 0, format) - usageMapRowLength; for (int i = 0; i < 2; ++i) { rtn.putShort(getRowStartOffset(i, format), (short) rowStart); if (i == 0) { // initial "usage pages" map definition rtn.put(rowStart, UsageMap.MAP_TYPE_REFERENCE); } else { // initial "pages with free space" map definition rtn.put(rowStart, UsageMap.MAP_TYPE_INLINE); } rowStart -= usageMapRowLength; } if (creator.hasIndexes()) { for (int i = 0; i < creator.getIndexes().size(); ++i) { IndexBuilder idx = creator.getIndexes().get(i); // allocate root page for the index int rootPageNumber = pageChannel.allocateNewPage(); int umapRowNum = i + 2; // stash info for later use TableCreator.IndexState idxState = creator.getIndexState(idx); idxState.setRootPageNumber(rootPageNumber); idxState.setUmapRowNumber((byte) umapRowNum); idxState.setUmapPageNumber(umapPageNumber); // index map definition, including initial root page rtn.putShort(getRowStartOffset(umapRowNum, format), (short) rowStart); rtn.put(rowStart, UsageMap.MAP_TYPE_INLINE); rtn.putInt(rowStart + 1, rootPageNumber); rtn.put(rowStart + 5, (byte) 1); rowStart -= usageMapRowLength; } } pageChannel.writePage(rtn, umapPageNumber); }