org.voovan.network.messagesplitter.LineMessageSplitter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of voovan-network Show documentation
Show all versions of voovan-network Show documentation
Voovan is a java framwork and it not depends on any third-party framework.
package org.voovan.network.messagesplitter;
import org.voovan.network.IoSession;
import org.voovan.network.MessageSplitter;
import java.nio.ByteBuffer;
/**
* 按换行对消息分割
*
* @author helyho
*
* Voovan Framework.
* WebSite: https://github.com/helyho/Voovan
* Licence: Apache v2 License
*/
public class LineMessageSplitter implements MessageSplitter {
@Override
public int canSplite(IoSession session,ByteBuffer byteBuffer) {
byteBuffer.position(byteBuffer.limit()-1);
byte lastByte = byteBuffer.get();
byteBuffer.position(0);
if(byteBuffer.limit() > 1 && lastByte == '\n'){
return byteBuffer.limit();
}
return -1;
}
}