本文整理汇总了Java中org.apache.mina.common.ByteBuffer.put方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.put方法的具体用法?Java ByteBuffer.put怎么用?Java ByteBuffer.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.common.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void encode(IoSession session, Object message,
ProtocolEncoderOutput out) throws Exception {
if(!(message instanceof byte[])){
throw new Exception("must send byte[]");
}
byte[] payload=(byte[]) message;
ByteBuffer buf = ByteBuffer.allocate(payload.length, false);
buf.put(payload);
buf.flip();
out.write(buf);
if (isDebugEnabled)
LOGGER.debug(TairUtil.toHex(payload));
}
示例2: reduceBufferToFit
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void reduceBufferToFit()
{
if (payload != null && (payload.remaining() < payload.capacity() / 2))
{
int size = payload.limit();
ByteBuffer newPayload = ByteBuffer.allocate(size);
newPayload.put(payload);
newPayload.flip();
//reduce reference count on payload
payload.release();
payload = newPayload;
}
}
示例3: writeFrames
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static void writeFrames(ByteBuffer buffer, final int channel, AMQBody body1, AMQBody body2, AMQBody body3)
{
buffer.put(body1.getFrameType());
EncodingUtils.writeUnsignedShort(buffer, channel);
EncodingUtils.writeUnsignedInteger(buffer, body1.getSize());
body1.writePayload(buffer);
buffer.put(FRAME_END_BYTE);
buffer.put(body2.getFrameType());
EncodingUtils.writeUnsignedShort(buffer, channel);
EncodingUtils.writeUnsignedInteger(buffer, body2.getSize());
body2.writePayload(buffer);
buffer.put(FRAME_END_BYTE);
buffer.put(body3.getFrameType());
EncodingUtils.writeUnsignedShort(buffer, channel);
EncodingUtils.writeUnsignedInteger(buffer, body3.getSize());
body3.writePayload(buffer);
buffer.put(FRAME_END_BYTE);
}
示例4: writeShortStringBytes
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static void writeShortStringBytes(ByteBuffer buffer, String s)
{
if (s != null)
{
byte[] encodedString = new byte[s.length()];
char[] cha = s.toCharArray();
for (int i = 0; i < cha.length; i++)
{
encodedString[i] = (byte) cha[i];
}
// TODO: check length fits in an unsigned byte
writeUnsignedByte(buffer, (short)encodedString.length);
buffer.put(encodedString);
}
else
{
// really writing out unsigned byte
buffer.put((byte) 0);
}
}
示例5: writeUnsignedInteger
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static void writeUnsignedInteger(ByteBuffer buffer, long l)
{
// TODO: Is this comparison safe? Do I need to cast RHS to long?
if (l < Integer.MAX_VALUE)
{
buffer.putInt((int) l);
}
else
{
int iv = (int) l;
// FIXME: This *may* go faster if we build this into a local 4-byte array and then
// put the array in a single call.
buffer.put((byte) (0xFF & (iv >> 24)));
buffer.put((byte) (0xFF & (iv >> 16)));
buffer.put((byte) (0xFF & (iv >> 8)));
buffer.put((byte) (0xFF & iv));
}
}
示例6: toString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
/**
* Turns a <code>org.apache.mina.common.ByteBuffer</code> into a hexadecimal
* string.
*
* @param buf The <code>org.apache.mina.common.ByteBuffer</code> to convert.
* @return The hexadecimal representation of <code>buf</code>
*/
public static String toString(final ByteBuffer buf) {
buf.flip();
final byte arr[] = new byte[buf.remaining()];
buf.get(arr);
String ret = toString(arr);
buf.flip();
buf.put(arr);
return ret;
}
示例7: toString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
/**
* Turns a {@link org.apache.mina.common.ByteBuffer ByteBuffer}
* into a hexadecimal string.
*
* @param buf The <code>ByteBuffer</code> to convert.
* @return The hexadecimal representation of <code>buf</code>.
*/
public static String toString(final ByteBuffer buf) {
buf.flip();
final byte[] arr = new byte[buf.remaining()];
buf.get(arr);
final String ret = toString(arr);
buf.flip();
buf.put(arr);
return ret;
}
示例8: toByteBuffer
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
private ByteBuffer toByteBuffer(Object message) throws CharacterCodingException, NoTypeConversionAvailableException {
// try to convert it to a byte array
byte[] value = context.getTypeConverter().tryConvertTo(byte[].class, message);
if (value != null) {
ByteBuffer answer = ByteBuffer.allocate(value.length).setAutoExpand(false);
answer.put(value);
return answer;
}
// fallback to use a byte buffer converter
return context.getTypeConverter().mandatoryConvertTo(ByteBuffer.class, message);
}
示例9: writePayload
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void writePayload(ByteBuffer buffer)
{
if (payload != null)
{
if(payload.isDirect() || payload.isReadOnly())
{
ByteBuffer copy = payload.duplicate();
buffer.put(copy.rewind());
}
else
{
buffer.put(payload.array(),payload.arrayOffset(),payload.limit());
}
}
}
示例10: send
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public synchronized void send(java.nio.ByteBuffer msg)
{
_log.debug("sending data:");
ByteBuffer mina = ByteBuffer.allocate(msg.limit());
mina.put(msg);
mina.flip();
_lastWrite = _session.write(mina);
_log.debug("sent data:");
}
示例11: writeBytes
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static void writeBytes(ByteBuffer buffer, byte[] data)
{
if (data != null)
{
// TODO: check length fits in an unsigned byte
writeUnsignedInteger(buffer, (long)data.length);
buffer.put(data);
}
else
{
// really writing out unsigned byte
//buffer.put((byte) 0);
writeUnsignedInteger(buffer, 0L);
}
}
示例12: deliver
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void deliver(Packet packet) throws UnauthorizedException {
if (isClosed()) {
backupDeliverer.deliver(packet);
}
else {
ByteBuffer buffer = ByteBuffer.allocate(4096);
buffer.setAutoExpand(true);
boolean errorDelivering = false;
try {
// OF-464: if the connection has been dropped, fail over to backupDeliverer (offline)
if (!ioSession.isConnected()) {
throw new IOException("Connection reset/closed by peer");
}
XMLWriter xmlSerializer =
new XMLWriter(new ByteBufferWriter(buffer, encoder.get()), new OutputFormat());
xmlSerializer.write(packet.getElement());
xmlSerializer.flush();
if (flashClient) {
buffer.put((byte) '\0');
}
buffer.flip();
ioSession.write(buffer);
}
catch (Exception e) {
Log.debug("Error delivering packet:\n" + packet, e);
errorDelivering = true;
}
if (errorDelivering) {
close();
// Retry sending the packet again. Most probably if the packet is a
// Message it will be stored offline
backupDeliverer.deliver(packet);
}
else {
session.incrementServerPacketCount();
}
}
}
示例13: writeFrame
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static void writeFrame(ByteBuffer buffer, final int channel, AMQBody body)
{
buffer.put(body.getFrameType());
EncodingUtils.writeUnsignedShort(buffer, channel);
EncodingUtils.writeUnsignedInteger(buffer, body.getSize());
body.writePayload(buffer);
buffer.put(FRAME_END_BYTE);
}
示例14: writeBooleans
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3,
boolean value4, boolean value5)
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
if (value1)
{
packedValue = (byte) (packedValue | (byte) (1 << 1));
}
if (value2)
{
packedValue = (byte) (packedValue | (byte) (1 << 2));
}
if (value3)
{
packedValue = (byte) (packedValue | (byte) (1 << 3));
}
if (value4)
{
packedValue = (byte) (packedValue | (byte) (1 << 4));
}
if (value5)
{
packedValue = (byte) (packedValue | (byte) (1 << 5));
}
buffer.put(packedValue);
}
示例15: writeUnsignedShort
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static void writeUnsignedShort(ByteBuffer buffer, int s)
{
// TODO: Is this comparison safe? Do I need to cast RHS to long?
if (s < Short.MAX_VALUE)
{
buffer.putShort((short) s);
}
else
{
short sv = (short) s;
buffer.put((byte) (0xFF & (sv >> 8)));
buffer.put((byte) (0xFF & sv));
}
}