List of usage examples for java.nio ByteBuffer putShort
public abstract ByteBuffer putShort(short value);
From source file:org.midonet.netlink.rtnetlink.Link.java
static public ByteBuffer describeSetAddrRequest(ByteBuffer buf, Link link, MAC mac) { IfinfoMsg ifi = link.ifi;/*from w ww.j av a2 s . co m*/ buf.put(ifi.family); buf.put((byte) 0); buf.putShort(ifi.type); buf.putInt(ifi.index); buf.putInt(ifi.flags); buf.putInt(ifi.change); NetlinkMessage.writeRawAttribute(buf, Attr.IFLA_ADDRESS, mac.getAddress()); return buf; }
From source file:org.midonet.netlink.rtnetlink.Link.java
static public ByteBuffer describeSetMasterRequest(ByteBuffer buf, Link link, int masterIndex) { IfinfoMsg ifi = link.ifi;//from w ww .j a v a 2 s . c om buf.put(ifi.family); buf.put((byte) 0); buf.putShort(ifi.type); buf.putInt(ifi.index); buf.putInt(ifi.flags); buf.putInt(ifi.change); NetlinkMessage.writeIntAttr(buf, Attr.IFLA_MASTER, masterIndex); return buf; }
From source file:org.apache.usergrid.persistence.map.impl.MapSerializationImpl.java
public static ByteBuffer serializeKeys(UUID ownerUUID, String ownerType, String mapName, String mapKey, int bucketNumber) { List<Object> keys = new ArrayList<>(4); keys.add(0, ownerUUID);//from w ww . j a va 2 s . c om keys.add(1, ownerType); keys.add(2, mapName); keys.add(3, mapKey); if (bucketNumber > 0) { keys.add(4, bucketNumber); } // UUIDs are 16 bytes, allocate the buffer accordingly int size = 16 + ownerType.getBytes().length + mapName.getBytes().length + mapKey.getBytes().length; if (bucketNumber > 0) { // ints are 4 bytes size += 4; } // we always need to add length for the 2 byte short and 1 byte equality size += keys.size() * 3; ByteBuffer stuff = ByteBuffer.allocate(size); for (Object key : keys) { ByteBuffer kb = DataType.serializeValue(key, ProtocolVersion.NEWEST_SUPPORTED); if (kb == null) { kb = ByteBuffer.allocate(0); } stuff.putShort((short) kb.remaining()); stuff.put(kb.slice()); stuff.put((byte) 0); } stuff.flip(); return stuff.duplicate(); }
From source file:com.healthmarketscience.jackcess.impl.OleUtil.java
private static byte[] writePackageStreamHeader(OleBlob.Builder oleBuilder) { byte[] fileNameBytes = getZeroTermStrBytes(oleBuilder.getFileName()); byte[] filePathBytes = getZeroTermStrBytes(oleBuilder.getFilePath()); int headerLen = 6 + fileNameBytes.length + filePathBytes.length; if (oleBuilder.getType() == ContentType.SIMPLE_PACKAGE) { headerLen += 8 + filePathBytes.length; } else {/*from w w w. j a va 2 s .co m*/ headerLen += 2; } byte[] headerBytes = new byte[headerLen]; ByteBuffer bb = PageChannel.wrap(headerBytes); bb.putShort((short) PACKAGE_STREAM_SIGNATURE); bb.put(fileNameBytes); bb.put(filePathBytes); if (oleBuilder.getType() == ContentType.SIMPLE_PACKAGE) { bb.putInt(PS_EMBEDDED_FILE); bb.putInt(filePathBytes.length); bb.put(filePathBytes, 0, filePathBytes.length); bb.putInt((int) oleBuilder.getContentLength()); } else { bb.putInt(PS_LINKED_FILE); bb.putShort((short) LINK_HEADER); } return headerBytes; }
From source file:com.healthmarketscience.jackcess.impl.OleUtil.java
private static byte[] writePackageHeader(OleBlob.Builder oleBuilder, long contentLen) { byte[] prettyNameBytes = getZeroTermStrBytes(oleBuilder.getPrettyName()); String className = oleBuilder.getClassName(); String typeName = oleBuilder.getTypeName(); if (className == null) { className = typeName;//from w w w. j a v a 2s . c om } else if (typeName == null) { typeName = className; } byte[] classNameBytes = getZeroTermStrBytes(className); byte[] typeNameBytes = getZeroTermStrBytes(typeName); int packageHeaderLen = 20 + prettyNameBytes.length + classNameBytes.length; int oleHeaderLen = 24 + typeNameBytes.length; byte[] headerBytes = new byte[packageHeaderLen + oleHeaderLen]; ByteBuffer bb = PageChannel.wrap(headerBytes); // write outer package header bb.putShort((short) PACKAGE_SIGNATURE); bb.putShort((short) packageHeaderLen); bb.putInt(PACKAGE_OBJECT_TYPE); bb.putShort((short) prettyNameBytes.length); bb.putShort((short) classNameBytes.length); int prettyNameOff = bb.position() + 8; bb.putShort((short) prettyNameOff); bb.putShort((short) (prettyNameOff + prettyNameBytes.length)); bb.putInt(-1); bb.put(prettyNameBytes); bb.put(classNameBytes); // put ole header bb.putInt(OLE_VERSION); bb.putInt(OLE_FORMAT); bb.putInt(typeNameBytes.length); bb.put(typeNameBytes); bb.putLong(0L); bb.putInt((int) contentLen); return headerBytes; }
From source file:org.pentaho.di.trans.steps.teradatabulkloader.TeraDataBulkLoaderRoutines.java
/** * Convert varchar./*from w w w .java 2 s. c om*/ * * @param string the string * @return the byte[] */ static byte[] convertVarchar(String string) { ByteBuffer b = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN); short strlen = 0; if (string != null) { strlen = (short) string.length(); b.putShort(strlen); } else { b = ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN); b.putShort((short) 0); return b.array(); } byte[] result = new byte[2 + strlen]; System.arraycopy(b.array(), 0, result, 0, 2); System.arraycopy(string.getBytes(), 0, result, 2, strlen); return result; }
From source file:com.kactech.otj.Utils.java
public static ByteBuffer seal(String msg, String nymID, PublicKey nymKey, SecretKeySpec aesSecret, IvParameterSpec vector) throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { ByteBuffer buff = ByteBuffer.allocate(msg.length() + 500);//donno? buff.order(ByteOrder.BIG_ENDIAN); buff.putShort((short) 1);//asymmetric buff.putInt(1);//array size buff.putInt(nymID.length() + 1);// ww w . j a v a 2s . c o m buff.put(bytes(nymID + '\0', US_ASCII)); // create encoded key and message Cipher cipher; try { cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); } catch (Exception e) { throw new RuntimeException(e); } cipher.init(Cipher.ENCRYPT_MODE, aesSecret, vector); byte[] encrypted = cipher.doFinal(bytes(msg + '\0', UTF8)); try { cipher = Cipher.getInstance(WRAP_ALGO); } catch (Exception e) { throw new RuntimeException(e); } cipher.init(Cipher.WRAP_MODE, nymKey); byte[] encKeyBytes = cipher.wrap(aesSecret); buff.putInt(encKeyBytes.length); buff.put(encKeyBytes); buff.putInt(vector.getIV().length); buff.put(vector.getIV()); buff.put(encrypted); buff.flip(); return buff; }
From source file:org.openhab.binding.ulux.internal.ump.messages.ValueMessage.java
@Override protected void addData(final ByteBuffer buffer) { buffer.putShort(this.editValue); buffer.putShort(this.realValue); }
From source file:org.openhab.binding.ulux.internal.ump.messages.EditValueMessage.java
@Override protected void addData(final ByteBuffer buffer) { buffer.putShort(this.value); }
From source file:backtype.storm.messaging.TaskMessage.java
public ByteBuffer serialize() { ByteBuffer bb = ByteBuffer.allocate(_message.length + 4); bb.putShort((short) _task); bb.putShort(remoteTuple);/* w ww . j a v a 2s. c om*/ bb.put(_message); return bb; }