当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuf.bytesBefore方法代码示例

本文整理汇总了Java中io.netty.buffer.ByteBuf.bytesBefore方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.bytesBefore方法的具体用法?Java ByteBuf.bytesBefore怎么用?Java ByteBuf.bytesBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.bytesBefore方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decodeProcess

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private String[] decodeProcess ( final ByteBuf msg )
{
    // split by colon
    final int spaceIndex = msg.bytesBefore ( COLON );
    if ( spaceIndex < 0 )
    {
        throw new CodecException ( "Unable to find process name" );
    }

    final String process = msg.readSlice ( spaceIndex ).toString ( StandardCharsets.US_ASCII );
    msg.skipBytes ( 1 ); // COLON
    if ( msg.isReadable () )
    {
        msg.skipBytes ( 1 ); // SPACE
    }

    final Matcher m = PROCESS_PATTERN.matcher ( process );
    if ( m.matches () )
    {
        return new String[] { m.group ( 1 ), m.group ( 2 ) };
    }

    return new String[] { process };
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:SyslogCodec.java

示例2: decodeHostname

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private String decodeHostname ( final ByteBuf msg )
{
    // split by first space
    final int spaceIndex = msg.bytesBefore ( Constants.SP );
    if ( spaceIndex < 0 )
    {
        throw new CodecException ( "Unable to find hostname" );
    }

    final String hostname = msg.readSlice ( spaceIndex ).toString ( StandardCharsets.US_ASCII );

    msg.skipBytes ( 1 ); // SPACE

    return hostname;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:16,代码来源:SyslogCodec.java

示例3: parseTimestamp

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public Calendar parseTimestamp ( final ByteBuf data )
{
    final int index = data.bytesBefore ( this.endMarker );
    if ( index < 0 )
    {
        throw new CodecException ( "Unable to find timestamp" );
    }

    final String timestampString = data.readSlice ( index ).toString ( this.charset );

    logger.debug ( "Timestamp string: '{}'", timestampString );

    final Matcher m = this.pattern.matcher ( timestampString );
    if ( !m.matches () )
    {
        throw new CodecException ( "Timestamp string does not match pattern: " + this.pattern.pattern () );
    }

    final int year = Integer.parseInt ( m.group ( "year" ) );
    final int month = Integer.parseInt ( m.group ( "month" ) ) - 1;
    final int day = Integer.parseInt ( m.group ( "day" ) );
    final int hour = Integer.parseInt ( m.group ( "hour" ) );
    final int minute = Integer.parseInt ( m.group ( "minute" ) );
    final int second = Integer.parseInt ( m.group ( "second" ) );
    final int ms = Integer.parseInt ( m.group ( "subsec" ) ) / 1000;

    TimeZone timezone = TimeZone.getDefault ();
    final String tz = m.group ( "tz" );
    if ( !tz.isEmpty () )
    {
        // FIXME: implement
        if ( "Z".equals ( tz ) )
        {
            timezone = TimeZone.getTimeZone ( "UTC" );
        }
        else
        {
            timezone = TimeZone.getTimeZone ( "GMT" + tz );
        }
    }

    final Calendar c = new GregorianCalendar ( year, month, day, hour, minute, second );
    c.setTimeZone ( timezone );
    c.set ( Calendar.MILLISECOND, ms );

    // skip marker byte
    data.skipBytes ( 1 );

    return c;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:52,代码来源:PatternTimestampParser.java

示例4: readCString

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static String readCString(ByteBuf src, Charset charset) {
  int len = src.bytesBefore(ZERO);
  String s = src.readCharSequence(len, charset).toString();
  src.readByte();
  return s;
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:7,代码来源:Util.java

示例5: readCStringUTF8

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static String readCStringUTF8(ByteBuf src) {
  int len = src.bytesBefore(ZERO);
  String s = src.readCharSequence(len, UTF_8).toString();
  src.readByte();
  return s;
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:7,代码来源:Util.java


注:本文中的io.netty.buffer.ByteBuf.bytesBefore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。