Java 类org.apache.mina.filter.codec.textline.LineDelimiter 实例源码

项目:Camel    文件:MinaComponent.java   
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);
    }
}
项目:Camel    文件:Mina2Producer.java   
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);
    }
}
项目:Camel    文件:Mina2Consumer.java   
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);
    }
}
项目:Mailster    文件:ImportExportUtilities.java   
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();
    }
}
项目:Mailster    文件:SmtpMessageFactory.java   
/**
   * 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();
  }
项目:Mailster    文件:MailsterPop3Service.java   
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);
  }
项目:maxcube-java    文件:MinaCubeClient.java   
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);
}
项目:maxcube-java    文件:CubeClientTest.java   
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());
}
项目:Camel    文件:Mina2ClientModeTcpTextlineDelimiterTest.java   
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));
}
项目:itheima    文件:MinaService.java   
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);
        }
    }
项目:Mailster    文件:TextLineConsumer.java   
/**
   * 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();
  }
项目:hadoop-logdriver    文件:TextLineDecoder.java   
/**
 * 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;
  }
}
项目:hadoop-logdriver    文件:TextLineDecoder.java   
/**
 * {@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);
  }
}
项目:OpenMobster    文件:Server.java   
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);
    }
}
项目:jlogstash-input-plugin    文件:MyClient.java   
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();    
}
项目:Camel    文件:MinaClientModeTcpTextlineDelimiterTest.java   
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());
}
项目:dsc-it100-java    文件:IT100Encoder.java   
public IT100Encoder() {
    super(Charset.forName("US-ASCII"), LineDelimiter.CRLF);
}
项目:dsc-it100-java    文件:IT100Decoder.java   
public IT100Decoder() {
    super(Charset.forName("US-ASCII"), LineDelimiter.CRLF);
}
项目:Mailster    文件:SmtpMessageFactory.java   
/**
 * Creates a new instance with the current default {@link Charset}, 
 * the {@link LineDelimiter#CRLF} delimiter.
 */
public SmtpMessageFactory()
{
    this(Charset.defaultCharset(), LineDelimiter.CRLF);
}
项目:Mailster    文件:SmtpMessageFactory.java   
/**
 * Creates a new instance with the specified <tt>charset</tt> 
 * and the {@link LineDelimiter#CRLF} delimiter.
 */
public SmtpMessageFactory(Charset charset)
{
    this(charset, LineDelimiter.CRLF);
}
项目:MailsterSMTP    文件:SMTPCodecFactory.java   
/**
 * Creates a new instance using the configuration.
 */
protected SMTPCodecFactory(Charset charset, int dataDeferredSize)
{
    encoder = new TextLineEncoder(charset, LineDelimiter.CRLF);
    decoder = new SMTPDecoder(charset, dataDeferredSize);
}
项目:Mailster    文件:TextLineConsumer.java   
/**
 * Creates a new instance with the current default {@link Charset}, 
 * the {@link LineDelimiter#DEFAULT} delimiter and the specified
 * {@link IoFilterCodec}.
 */
public TextLineConsumer( IoFilterCodec codec )
{
    this( Charset.defaultCharset(), LineDelimiter.DEFAULT , codec);
}
项目:Mailster    文件:TextLineConsumer.java   
/**
 * Creates a new instance with the specified <tt>charset</tt>
 * the {@link LineDelimiter#DEFAULT} delimiter and the specified
 * {@link IoFilterCodec}.
 */
public TextLineConsumer( Charset charset, IoFilterCodec codec )
{
    this( charset, LineDelimiter.DEFAULT , codec );
}
项目:hadoop-logdriver    文件:TextLineDecoder.java   
/**
 * Creates a new instance with the current default {@link Charset} and
 * {@link LineDelimiter#AUTO} delimiter.
 */
public TextLineDecoder() {
  this(LineDelimiter.AUTO);
}
项目:hadoop-logdriver    文件:TextLineDecoder.java   
/**
 * Creates a new instance with the current default {@link Charset} and the
 * specified <tt>delimiter</tt>.
 */
public TextLineDecoder(String delimiter) {
  this(new LineDelimiter(delimiter));
}
项目:hadoop-logdriver    文件:TextLineDecoder.java   
/**
 * Creates a new instance with the current default {@link Charset} and the
 * specified <tt>delimiter</tt>.
 */
public TextLineDecoder(LineDelimiter delimiter) {
  this(Charset.defaultCharset(), delimiter);
}
项目:hadoop-logdriver    文件:TextLineDecoder.java   
/**
 * Creates a new instance with the spcified <tt>charset</tt> and
 * {@link LineDelimiter#AUTO} delimiter.
 */
public TextLineDecoder(Charset charset) {
  this(charset, LineDelimiter.AUTO);
}
项目:hadoop-logdriver    文件:TextLineDecoder.java   
/**
 * Creates a new instance with the spcified <tt>charset</tt> and the specified
 * <tt>delimiter</tt>.
 */
public TextLineDecoder(Charset charset, String delimiter) {
  this(charset, new LineDelimiter(delimiter));
}
项目:hadoop-logdriver    文件:TextLineCodecFactory.java   
/**
 * Creates a new instance with the specified {@link Charset}. The encoder uses
 * a UNIX {@link LineDelimiter} and the decoder uses the AUTO
 * {@link LineDelimiter}.
 * 
 * @param charset
 *          The charset to use in the encoding and decoding
 */
public TextLineCodecFactory(Charset charset) {
  encoder = new TextLineEncoder(charset, LineDelimiter.UNIX);
  decoder = new TextLineDecoder(charset, LineDelimiter.AUTO);
}
项目:hadoop-logdriver    文件:TextLineCodecFactory.java   
/**
 * Creates a new instance of TextLineCodecFactory. This constructor provides
 * more flexibility for the developer.
 * 
 * @param charset
 *          The charset to use in the encoding and decoding
 * @param encodingDelimiter
 *          The line delimeter for the encoder
 * @param decodingDelimiter
 *          The line delimeter for the decoder
 */
public TextLineCodecFactory(Charset charset, LineDelimiter encodingDelimiter,
    LineDelimiter decodingDelimiter) {
  encoder = new TextLineEncoder(charset, encodingDelimiter);
  decoder = new TextLineDecoder(charset, decodingDelimiter);
}