com.github.andyshao.io.MessageWritable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.io;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
/**
*
* Title:
* Descript:
* Copyright: Copryright(c) Nov 5, 2015
* Encoding:UNIX UTF-8
*
* @author Andy.Shao
*
*/
public interface MessageWritable {
/**
* Blocking {@link MessageWritable}
*/
public static final MessageWritable BLOCKING_MESSAGE_WRITABLE = (channel , context) -> {
if ((Boolean) context.get(MessageContext.IS_WAITING_FOR_SENDING)) {
byte[] information = (byte[]) context.get(MessageContext.OUTPUT_MESSAGE_BYTES);
if (information.length != 0) {
ByteBuffer buffer = ByteBuffer.wrap(information);
while (buffer.hasRemaining())
channel.write(buffer);
}
}
};
/**
* write message
* @param channel {@link WritableByteChannel}
* @param context {@link MessageContext}
* @throws IOException any IO error
*/
public void write(WritableByteChannel channel , MessageContext context) throws IOException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy