本文整理汇总了Java中org.apache.mina.filter.codec.textline.LineDelimiter类的典型用法代码示例。如果您正苦于以下问题:Java LineDelimiter类的具体用法?Java LineDelimiter怎么用?Java LineDelimiter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LineDelimiter类属于org.apache.mina.filter.codec.textline包,在下文中一共展示了LineDelimiter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLineDelimiterParameter
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
private static LineDelimiter getLineDelimiterParameter(TextLineDelimiter delimiter) {
if (delimiter == null) {
return LineDelimiter.DEFAULT;
}
switch (delimiter) {
case DEFAULT:
return LineDelimiter.DEFAULT;
case AUTO:
return LineDelimiter.AUTO;
case UNIX:
return LineDelimiter.UNIX;
case WINDOWS:
return LineDelimiter.WINDOWS;
case MAC:
return LineDelimiter.MAC;
default:
throw new IllegalArgumentException("Unknown textline delimiter: " + delimiter);
}
}
示例2: getLineDelimiterParameter
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
private static LineDelimiter getLineDelimiterParameter(Mina2TextLineDelimiter delimiter) {
if (delimiter == null) {
return LineDelimiter.DEFAULT;
}
switch (delimiter) {
case DEFAULT:
return LineDelimiter.DEFAULT;
case AUTO:
return LineDelimiter.AUTO;
case UNIX:
return LineDelimiter.UNIX;
case WINDOWS:
return LineDelimiter.WINDOWS;
case MAC:
return LineDelimiter.MAC;
default:
throw new IllegalArgumentException("Unknown textline delimiter: " + delimiter);
}
}
示例3: importFromEmailFile
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
public static void importFromEmailFile(String fileName)
{
try
{
FileInputStream in = new FileInputStream(fileName);
SmtpMessageFactory factory = new SmtpMessageFactory(MailsterConstants.DEFAULT_CHARSET, new LineDelimiter("\n"));
MailsterSmtpService smtp = MailsterSWT.getInstance().getSMTPService();
smtp.addReceivedEmail(factory.asSmtpMessage(in, null));
smtp.refreshEmailQueue(false);
in.close();
} catch (Exception e)
{
ErrorDialog dlg = new ErrorDialog(MailsterSWT.getInstance().getShell(), "Exception occured",
"Failed importing email file : " + fileName,
new Status(IStatus.ERROR, "Mailster", "Unable to import file", e), IStatus.ERROR);
dlg.open();
}
}
示例4: SmtpMessageFactory
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
/**
* Creates a new instance with the specified <tt>charset</tt> and
* the specified <tt>delimiter</tt>.
*/
public SmtpMessageFactory(Charset charset, LineDelimiter delimiter)
{
if(charset == null)
{
throw new NullPointerException("charset");
}
this.charset = charset;
if (delimiter == null)
{
throw new NullPointerException("delimiter");
}
// Convert delimiter to IoBuffer.
delimBuf = IoBuffer.allocate(delimiter.getValue().length()).setAutoExpand(true);
try
{
delimBuf.putString(delimiter.getValue(), charset.newEncoder());
}
catch (CharacterCodingException e)
{
throw new RuntimeException(e);
}
delimBuf.flip();
}
示例5: initService
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
private void initService() throws Exception
{
IoBuffer.setUseDirectBuffer(false);
acceptor = new NioSocketAcceptor(
Runtime.getRuntime().availableProcessors() + 1);
config = acceptor.getSessionConfig();
config.setReuseAddress(true);
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
chain.addLast("codec", new ProtocolCodecFilter(
new TextLineCodecFactory(
MailsterConstants.DEFAULT_CHARSET,
LineDelimiter.CRLF,
LineDelimiter.CRLF)));
executor = Executors.newCachedThreadPool(
ThreadFactoryUtilities.createFactory("POP3 Thread"));
chain.addLast("threadPool", new ExecutorFilter(executor));
handler = new Pop3ProtocolHandler(userManager);
}
示例6: MinaCubeClient
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
public MinaCubeClient(String hostname, int port) {
this.hostname = hostname;
this.port = port;
connector = new NioSocketConnector(1);
connector.setConnectTimeoutMillis(2000);
connector.getFilterChain().addLast("logger", new LoggingFilter());
TextLineCodecFactory codecFactory = new TextLineCodecFactory(UTF_8, LineDelimiter.CRLF, LineDelimiter.AUTO);
codecFactory.setDecoderMaxLineLength(4096);
codecFactory.setEncoderMaxLineLength(4096);
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
handler = new ConnectHandler();
connector.setHandler(handler);
}
示例7: start
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
public void start() throws IOException {
// enable for debug
acceptor.getFilterChain().addLast("logger", new LoggingFilter());
TextLineCodecFactory codecFactory = new TextLineCodecFactory(UTF_8, LineDelimiter.CRLF, LineDelimiter.CRLF);
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
acceptor.setHandler(handler);
acceptor.bind(new InetSocketAddress(0) );
acceptor.setCloseOnDeactivation(true);
logger.info("Cube server bound to [{}]", acceptor.getLocalAddress());
}
示例8: startup
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
public void startup() throws Exception {
acceptor = new NioSocketAcceptor();
Mina2TextLineCodecFactory codecFactory = new Mina2TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.UNIX);
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
acceptor.setHandler(new ServerHandler());
acceptor.bind(new InetSocketAddress("127.0.0.1", port));
}
示例9: startMinaServer
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
private void startMinaServer() {
initNotify();
// serverThread = new Thread(new Runnable() {
// @Override
// public void run() {
//
// }
// });
// serverThread.start();
try{
//创建一个非阻塞的server端的Socket
acceptor = new NioSocketAcceptor();
//设置过滤器(使用mina提供的文本换行符编解码器)
acceptor.getFilterChain().addLast(
"codec", new ProtocolCodecFilter(
new TextLineCodecFactory(
Charset.forName("UTF-8"),
LineDelimiter.WINDOWS.getValue(),
LineDelimiter.WINDOWS.getValue()
)
)
);
//自定义的编解码器
//acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new CharsetCodecFactory()));
//设置读取数据的换从区大小
acceptor.getSessionConfig().setReadBufferSize(2048);
//读写通道10秒内无操作进入空闲状态
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
//为接收器设置管理服务
acceptor.setHandler(new ServerHandler());
//绑定端口
acceptor.bind(new InetSocketAddress(PORT));
LogUtils.i("服务器启动成功... 端口号:"+PORT);
}catch (Exception e){
LogUtils.e("服务器异常.."+e);
}
}
示例10: TextLineConsumer
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
/**
* Creates a new instance with the specified <tt>charset</tt>
* the specified <tt>delimiter</tt> and the specified
* {@link IoFilterCodec}. Delimiter
* {@link LineDelimiter#AUTO} is not allowed.
*/
public TextLineConsumer( Charset charset, LineDelimiter delimiter, IoFilterCodec codec )
{
if( charset == null )
{
throw new NullPointerException( "charset" );
}
if( delimiter == null )
{
throw new NullPointerException( "delimiter" );
}
if( delimiter == LineDelimiter.AUTO )
{
throw new IllegalArgumentException("LineDelimiter.AUTO is not allowed");
}
this.codec = codec;
// Convert delimiter to ByteBuffer.
delimBuf = IoBuffer.allocate( 2 ).setAutoExpand( true );
try
{
delimBuf.putString( delimiter.getValue(), charset.newEncoder() );
}
catch (CharacterCodingException e)
{
throw new RuntimeException(e);
}
delimBuf.flip();
}
示例11: TextLineDecoder
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
/**
* Creates a new instance with the specified <tt>charset</tt> and the
* specified <tt>delimiter</tt>.
*/
public TextLineDecoder(Charset charset, LineDelimiter delimiter) {
if (charset == null) {
throw new IllegalArgumentException("charset parameter shuld not be null");
}
if (delimiter == null) {
throw new IllegalArgumentException(
"delimiter parameter should not be null");
}
this.charset = charset;
this.delimiter = delimiter;
// Convert delimiter to ByteBuffer if not done yet.
if (delimBuf == null) {
IoBuffer tmp = IoBuffer.allocate(2).setAutoExpand(true);
try {
tmp.putString(delimiter.getValue(), charset.newEncoder());
} catch (CharacterCodingException cce) {
}
tmp.flip();
delimBuf = tmp;
}
}
示例12: decode
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out)
throws Exception {
Context ctx = getContext(session);
if (LineDelimiter.AUTO.equals(delimiter)) {
decodeAuto(ctx, session, in, out);
} else {
decodeNormal(ctx, session, in, out);
}
}
示例13: startListening
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
protected void startListening(boolean activateSSL)
{
try
{
this.acceptor = new NioSocketAcceptor();
((NioSocketAcceptor)this.acceptor).setReuseAddress(true);
if(activateSSL)
{
//Makes the tcp connection protected with SSL
SslFilter sslFilter = new SslFilter(this.getSSLContext());
this.acceptor.getFilterChain().addLast("ssl", sslFilter);
}
//
//TextLineCodecFactory textLine = new TextLineCodecFactory(Charset.forName("UTF-8"));
TextLineCodecFactory textLine = new TextLineCodecFactory(Charset.forName("UTF-8"),
LineDelimiter.UNIX.getValue(),
"EOF");
textLine.setDecoderMaxLineLength(Integer.MAX_VALUE);
textLine.setEncoderMaxLineLength(Integer.MAX_VALUE);
ProtocolCodecFilter codecFilter = new ProtocolCodecFilter(textLine);
this.acceptor.getFilterChain().addLast( "codec", codecFilter);
//
this.acceptor.getFilterChain().addLast("threadPool", new ExecutorFilter());
//Add Custom filters here
if(this.payloadFilter != null)
{
this.acceptor.getFilterChain().addLast("payloadFilter", this.payloadFilter);
}
if(this.requestFilter != null)
{
this.acceptor.getFilterChain().addLast("requestFilter", this.requestFilter);
}
if(this.transactionFilter != null)
{
this.acceptor.getFilterChain().addLast("transactionFilter", this.transactionFilter);
}
if(this.authenticationFilter != null)
{
this.acceptor.getFilterChain().addLast("authenticationFilter", this.authenticationFilter);
}
//session specific configuration
this.acceptor.getSessionConfig().setBothIdleTime(10);
this.acceptor.setHandler(this.handler);
this.acceptor.bind(new InetSocketAddress(this.port));
log.info("--------------------------------------------");
log.info("Mobile Data Server successfully loaded on port ("+this.port+").....");
log.info("--------------------------------------------");
}
catch(Exception e)
{
log.error(this, e);
this.stop();
throw new RuntimeException(e);
}
}
示例14: main
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
public static void main(String[] args) {
// 创建一个非组设的客户端客户端
IoConnector connector = new NioSocketConnector();
// 设置链接超时时间
connector.setConnectTimeoutMillis(30000);
// 添加过滤器
connector.getFilterChain().addLast( // 添加消息过滤器
"codec",
// Mina自带的根据文本换行符编解码的TextLineCodec过滤器 看到\r\n就认为一个完整的消息结束了
new ProtocolCodecFilter(new TextLineCodecFactory(Charset
.forName("UTF-8"), LineDelimiter.MAC.getValue(),
LineDelimiter.MAC.getValue())));
// 添加业务逻辑处理器类
connector.setHandler(new ClientMessageHandler());
IoSession session = null;
try {
ConnectFuture future = connector.connect(new InetSocketAddress(
HOST, PORT));
future.awaitUninterruptibly(); // 等待连接创建完成
session = future.getSession();
long t1 = System.currentTimeMillis();
StringBuffer sb = new StringBuffer();
for(int i=0;i<200000;i++){
System.out.println(i);
sb.append("ysqysq nginx_ccc [0050d2bf234311e6ba8cac853da49b78 type=nginx_access_log tag=\"mylog\"] /Users/sishuyss/ysq_access/$2016-04-05T11:12:24.230148+08:00/$100.97.184.152 - - [25/May/2016:01:10:07 +0800] \"GET /index.php?disp=dynamic HTTP/1.0\" 301 278 \"http://log.dtstack.com/\" \"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;Alibaba.Security.Heimdall.1142964)\" 121.42.0.85 - - - 0").append(LineDelimiter.UNIX.getValue());
if(i%200==0){
session.write(sb.toString());
sb = new StringBuffer();
}
}
session.write(sb.toString());
System.out.println("time:"+(System.currentTimeMillis()-t1));
} catch (Exception e) {
System.out.println(e.getCause());
logger.info("客户端链接异常...");
}
session.getCloseFuture().awaitUninterruptibly();
logger.info("Mina要关闭了");
connector.dispose();
}
示例15: startup
import org.apache.mina.filter.codec.textline.LineDelimiter; //导入依赖的package包/类
public void startup() throws Exception {
acceptor = new SocketAcceptor();
TextLineCodecFactory codecFactory = new TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.UNIX);
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
acceptor.bind(new InetSocketAddress("127.0.0.1", port), new ServerHandler());
}