本文整理汇总了Java中java.nio.ByteBuffer.putChar方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.putChar方法的具体用法?Java ByteBuffer.putChar怎么用?Java ByteBuffer.putChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.putChar方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: charArrayTobyte
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Char array tobyte byte [ ].
*
* @param values the values
* @return the byte [ ]
*/
public static byte[] charArrayTobyte(char[] values)
{
int byteLength = values.length * 2;
ByteBuffer bf = ByteBuffer.allocate( byteLength );
for ( char v : values )
{
bf.putChar( v );
}
byte[] byteArray = bf.array();
byte[] returnbyte = new byte[byteLength];
for(int i=0;i < byteLength; i++)
{
returnbyte[i] = byteArray[(byteLength-1)-i];
}
return returnbyte;
}
示例2: AudioPacket
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public AudioPacket(char seq, int timestamp, int ssrc, byte[] encodedAudio)
{
this.seq = seq;
this.ssrc = ssrc;
this.timestamp = timestamp;
this.encodedAudio = encodedAudio;
ByteBuffer buffer = ByteBuffer.allocate(RTP_HEADER_BYTE_LENGTH + encodedAudio.length);
buffer.put(RTP_VERSION_PAD_EXTEND_INDEX, RTP_VERSION_PAD_EXTEND); //0
buffer.put(RTP_PAYLOAD_INDEX, RTP_PAYLOAD_TYPE); //1
buffer.putChar(SEQ_INDEX, seq); //2 - 3
buffer.putInt(TIMESTAMP_INDEX, timestamp); //4 - 7
buffer.putInt(SSRC_INDEX, ssrc); //8 - 11
System.arraycopy(encodedAudio, 0, buffer.array(), RTP_HEADER_BYTE_LENGTH, encodedAudio.length);//12 - n
this.rawPacket = buffer.array();
}
示例3: writeSample
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public void writeSample(char left, char right) {
if (writeAvailableBytes() < 4) {
throw new BufferOverflowException();
}
ByteBuffer bb = ByteBuffer.wrap(buffer);
bb.order(order);
bb.putChar(writePos, left);
bb.putChar(writePos + 2, right);
writePos += 4;
readAvailable += 4;
if (writePos >= buffer.length) {
writePos = 0;
}
}
示例4: serialize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void serialize(ByteBuffer buffer) {
switch (getJavaKind()) {
case Byte:
case Boolean:
buffer.put((byte) primitive);
break;
case Short:
buffer.putShort((short) primitive);
break;
case Char:
buffer.putChar((char) primitive);
break;
case Int:
buffer.putInt(asInt());
break;
case Long:
buffer.putLong(asLong());
break;
case Float:
buffer.putFloat(asFloat());
break;
case Double:
buffer.putDouble(asDouble());
break;
default:
throw new IllegalArgumentException("unexpected kind " + getJavaKind());
}
}
示例5: putOne
import java.nio.ByteBuffer; //导入方法依赖的package包/类
void putOne(ByteBuffer b, PrimitiveType t) {
switch (t) {
case BYTE: b.put((byte)0); break;
case CHAR: b.putChar('0'); break;
case SHORT: b.putShort((short)0); break;
case INT: b.putInt(0); break;
case LONG: b.putLong(0); break;
case FLOAT: b.putFloat(0); break;
case DOUBLE: b.putDouble(0); break;
}
}
示例6: write
import java.nio.ByteBuffer; //导入方法依赖的package包/类
void write(ByteBuffer buffer) {
buffer.putChar(firstChar);
if (payloadLen >= 126) {
if (payloadLen < 65536) {
buffer.putChar((char) payloadLen);
} else {
buffer.putLong(payloadLen);
}
}
if (mask) {
buffer.putInt(maskingKey);
}
}
示例7: createPacket
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Generates a NetBIOS name query request.
* https://tools.ietf.org/html/rfc1002
* Section 4.2.12
*/
static byte[] createPacket(int transId) {
ByteBuffer os = ByteBuffer.allocate(50);
char broadcastFlag = 0x0010;
char questionCount = 1;
char answerResourceCount = 0;
char authorityResourceCount = 0;
char additionalResourceCount = 0;
os.putChar((char) transId);
os.putChar(broadcastFlag);
os.putChar(questionCount);
os.putChar(answerResourceCount);
os.putChar(authorityResourceCount);
os.putChar(additionalResourceCount);
// Length of name. 16 bytes of name encoded to 32 bytes.
os.put((byte) 0x20);
// '*' character encodes to 2 bytes.
os.put((byte) 0x43);
os.put((byte) 0x4b);
// Write the remaining 15 nulls which encode to 30* 0x41
for (int i = 0; i < 30; i++) {
os.put((byte) 0x41);
}
// Length of next segment.
os.put((byte) 0);
// Question type: Node status
os.putChar((char) 0x21);
// Question class: Internet
os.putChar((char) 0x01);
return os.array();
}
示例8: putChar
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static ByteBuffer putChar(ByteBuffer buf, char value) {
buf.putChar(value);
writeByteBuffer(buf);
return buf;
}
示例9: getMarschaledBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] getMarschaledBytes() throws UnsupportedEncodingException, BufferOverflowException {
ByteBuffer bb = ByteBuffer.allocate(16384);
bb.put((byte) 0x0); //version
bb.putLong(logtime); //8
bb.putInt(mVerbosityLevel); //4
bb.putInt(mLevel.getInt());
bb.putInt(mRessourceId);
if (mMessage == null || mMessage.length() == 0) {
bb.putInt(0);
} else {
marschalString(mMessage, bb);
}
if (mArgs == null || mArgs.length == 0) {
bb.putInt(0);
} else {
bb.putInt(mArgs.length);
for (Object o : mArgs) {
if (o instanceof String) {
bb.putChar('s');
marschalString((String) o, bb);
} else if (o instanceof Integer) {
bb.putChar('i');
bb.putInt((Integer) o);
} else if (o instanceof Float) {
bb.putChar('f');
bb.putFloat((Float) o);
} else if (o instanceof Double) {
bb.putChar('d');
bb.putDouble((Double) o);
} else if (o instanceof Long) {
bb.putChar('l');
bb.putLong((Long) o);
} else if (o == null) {
bb.putChar('0');
} else {
VpnStatus.logDebug("Unknown object for LogItem marschaling " + o);
bb.putChar('s');
marschalString(o.toString(), bb);
}
}
}
int pos = bb.position();
bb.rewind();
return Arrays.copyOf(bb.array(), pos);
}
示例10: write
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private boolean write(byte b, String string, ByteBuffer buf)
{
if ((b == 'C') || (b == 'c'))
{
buf.put(Byte.decode(string));
return true;
}
else if ((b == 'D') || (b == 'd'))
{
buf.putInt(Integer.decode(string));
return true;
}
else if ((b == 'H') || (b == 'h'))
{
buf.putShort(Short.decode(string));
return true;
}
else if ((b == 'F') || (b == 'f'))
{
buf.putDouble(Double.parseDouble(string));
return true;
}
else if ((b == 'S') || (b == 's'))
{
final int len = string.length();
for (int i = 0; i < len; i++)
{
buf.putChar(string.charAt(i));
}
buf.putChar('\000');
return true;
}
else if ((b == 'B') || (b == 'b') || (b == 'X') || (b == 'x'))
{
buf.put(new BigInteger(string).toByteArray());
return true;
}
else if ((b == 'Q') || (b == 'q'))
{
buf.putLong(Long.decode(string));
return true;
}
return false;
}