本文整理匯總了Java中org.apache.mina.core.buffer.IoBuffer.getPrefixedString方法的典型用法代碼示例。如果您正苦於以下問題:Java IoBuffer.getPrefixedString方法的具體用法?Java IoBuffer.getPrefixedString怎麽用?Java IoBuffer.getPrefixedString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.getPrefixedString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doDecode
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
if (in.prefixedDataAvailable(prefixLength, maxDataLength)) {
String msg = in.getPrefixedString(prefixLength, charset.newDecoder());
out.write(msg);
return true;
}
return false;
}
示例2: decodeString
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private String decodeString ( final IoSession session, final IoBuffer data ) throws CharacterCodingException
{
final String result = data.getPrefixedString ( Sessions.getCharsetDecoder ( session ) );
if ( result.isEmpty () )
{
return null;
}
else
{
return result;
}
}
示例3: decodeBrowserAddEntry
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private BrowseAdded.Entry decodeBrowserAddEntry ( final IoBuffer data, final IoSession session ) throws ProtocolCodecException
{
final short register = (short)data.getUnsignedShort ();
// FIXME: validate if short works
final byte b = data.get ();
final DataType dataType = DataType.fromByte ( b );
if ( dataType == null )
{
throw new ProtocolCodecException ( String.format ( "Data type %s is unkown", b ) );
}
final Set<BrowseAdded.Entry.Flags> flags = data.getEnumSet ( BrowseAdded.Entry.Flags.class );
final CharsetDecoder decoder = Sessions.getCharsetDecoder ( session );
try
{
final String name = data.getPrefixedString ( decoder );
final String description = data.getPrefixedString ( decoder );
final String unit = data.getPrefixedString ( decoder );
return new BrowseAdded.Entry ( register, name, description, unit, dataType, flags );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
}
示例4: processWelcome
import org.apache.mina.core.buffer.IoBuffer; //導入方法依賴的package包/類
private boolean processWelcome ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
final int len = messageLength ( data );
if ( len < 0 )
{
return false;
}
final EnumSet<Welcome.Features> features = data.getEnumSetShort ( Welcome.Features.class );
logger.debug ( "Features: {}", features );
final CharsetDecoder decoder = this.defaultCharset.newDecoder ();
final int count = data.getUnsignedShort ();
final Map<String, String> properties = new HashMap<String, String> ( count );
for ( int i = 0; i < count; i++ )
{
try
{
final String key = data.getPrefixedString ( decoder );
final String value = data.getPrefixedString ( decoder );
properties.put ( key, value );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
}
if ( features.contains ( Welcome.Features.LITTLE_ENDIAN ) )
{
logger.info ( "Setting little endian" );
Sessions.setLittleEndian ( session );
}
out.write ( new Welcome ( features, properties ) );
return true;
}