idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
21,500
public JBBPTextWriter Byte ( final int value ) throws IOException { ensureValueMode ( ) ; String convertedByExtras = null ; for ( final Extra e : this . extras ) { convertedByExtras = e . doConvertByteToStr ( this , value & 0xFF ) ; if ( convertedByExtras != null ) { break ; } } if ( convertedByExtras == null ) { printValueString ( JBBPUtils . ensureMinTextLength ( JBBPUtils . ulong2str ( value & 0xFF , this . radix , CHAR_BUFFER ) , this . maxCharsRadixForByte , '0' , 0 ) ) ; } else { printValueString ( convertedByExtras ) ; } return this ; }
Print byte value .
21,501
public JBBPTextWriter Byte ( final String value ) throws IOException { for ( int i = 0 ; i < value . length ( ) ; i ++ ) { this . Byte ( value . charAt ( i ) ) ; } return this ; }
Print byte array defined as string .
21,502
public JBBPTextWriter Byte ( final byte [ ] array , int off , int len ) throws IOException { ensureValueMode ( ) ; while ( len -- > 0 ) { Byte ( array [ off ++ ] ) ; } return this ; }
Print values from byte array .
21,503
public JBBPTextWriter AddExtras ( final Extra ... extras ) { JBBPUtils . assertNotNull ( extras , "Extras must not be null" ) ; for ( final Extra e : extras ) { JBBPUtils . assertNotNull ( e , "Extras must not be null" ) ; this . extras . add ( 0 , e ) ; } return this ; }
Add extras to context .
21,504
public JBBPTextWriter DelExtras ( final Extra ... extras ) { JBBPUtils . assertNotNull ( extras , "Extras must not be null" ) ; for ( final Extra e : extras ) { JBBPUtils . assertNotNull ( e , "Extras must not be null" ) ; this . extras . remove ( e ) ; } return this ; }
Remove extras from context
21,505
public JBBPTextWriter SetTabSpaces ( final int numberOfSpacesPerTab ) { if ( numberOfSpacesPerTab <= 0 ) { throw new IllegalArgumentException ( "Tab must contains positive number of space chars [" + numberOfSpacesPerTab + ']' ) ; } final int currentIdentSteps = this . indent / this . spacesInTab ; this . spacesInTab = numberOfSpacesPerTab ; this . indent = currentIdentSteps * this . spacesInTab ; return this ; }
Set number of spaces per tab .
21,506
public final JBBPTextWriter Radix ( final int radix ) { if ( radix < 2 || radix > 36 ) { throw new IllegalArgumentException ( "Unsupported radix value [" + radix + ']' ) ; } this . radix = radix ; this . maxCharsRadixForByte = JBBPUtils . ulong2str ( 0xFFL , this . radix , CHAR_BUFFER ) . length ( ) ; this . maxCharsRadixForShort = JBBPUtils . ulong2str ( 0xFFFFL , this . radix , CHAR_BUFFER ) . length ( ) ; this . maxCharsRadixForInt = JBBPUtils . ulong2str ( 0xFFFFFFFFL , this . radix , CHAR_BUFFER ) . length ( ) ; this . maxCharsRadixForLong = JBBPUtils . ulong2str ( 0xFFFFFFFFFFFFFFFFL , this . radix , CHAR_BUFFER ) . length ( ) ; return this ; }
Set radix .
21,507
public JBBPTextWriter Short ( final int value ) throws IOException { ensureValueMode ( ) ; String convertedByExtras = null ; for ( final Extra e : this . extras ) { convertedByExtras = e . doConvertShortToStr ( this , value & 0xFFFF ) ; if ( convertedByExtras != null ) { break ; } } if ( convertedByExtras == null ) { final long valueToWrite ; if ( this . byteOrder == JBBPByteOrder . LITTLE_ENDIAN ) { valueToWrite = JBBPUtils . reverseByteOrder ( value , 2 ) ; } else { valueToWrite = value ; } printValueString ( JBBPUtils . ensureMinTextLength ( JBBPUtils . ulong2str ( valueToWrite & 0xFFFFL , this . radix , CHAR_BUFFER ) , this . maxCharsRadixForShort , '0' , 0 ) ) ; } else { printValueString ( convertedByExtras ) ; } return this ; }
Print short value .
21,508
public JBBPTextWriter Float ( final float value ) throws IOException { ensureValueMode ( ) ; String convertedByExtras = null ; for ( final Extra e : this . extras ) { convertedByExtras = e . doConvertFloatToStr ( this , value ) ; if ( convertedByExtras != null ) { break ; } } if ( convertedByExtras == null ) { final float valueToWrite ; if ( this . byteOrder == JBBPByteOrder . LITTLE_ENDIAN ) { valueToWrite = Float . intBitsToFloat ( ( int ) JBBPFieldInt . reverseBits ( Float . floatToIntBits ( value ) ) ) ; } else { valueToWrite = value ; } printValueString ( JBBPUtils . ensureMinTextLength ( JBBPUtils . float2str ( valueToWrite , this . radix ) , this . maxCharsRadixForShort , '0' , 0 ) ) ; } else { printValueString ( convertedByExtras ) ; } return this ; }
Print float value .
21,509
public JBBPTextWriter Double ( final double value ) throws IOException { ensureValueMode ( ) ; String convertedByExtras = null ; for ( final Extra e : this . extras ) { convertedByExtras = e . doConvertDoubleToStr ( this , value ) ; if ( convertedByExtras != null ) { break ; } } if ( convertedByExtras == null ) { final double valueToWrite ; if ( this . byteOrder == JBBPByteOrder . LITTLE_ENDIAN ) { valueToWrite = Double . longBitsToDouble ( JBBPFieldLong . reverseBits ( Double . doubleToLongBits ( value ) ) ) ; } else { valueToWrite = value ; } printValueString ( JBBPUtils . ensureMinTextLength ( JBBPUtils . double2str ( valueToWrite , this . radix ) , this . maxCharsRadixForShort , '0' , 0 ) ) ; } else { printValueString ( convertedByExtras ) ; } return this ; }
Print double value .
21,510
public JBBPTextWriter Short ( final String value ) throws IOException { for ( int i = 0 ; i < value . length ( ) ; i ++ ) { this . Short ( value . charAt ( i ) ) ; } return this ; }
Print char codes of string as short array .
21,511
public JBBPTextWriter Short ( final short [ ] values , int off , int len ) throws IOException { while ( len -- > 0 ) { this . Short ( values [ off ++ ] ) ; } return this ; }
Print values from short array
21,512
public JBBPTextWriter Float ( final float [ ] values , int off , int len ) throws IOException { while ( len -- > 0 ) { this . Float ( values [ off ++ ] ) ; } return this ; }
Print values from float array
21,513
public JBBPTextWriter Double ( final double [ ] values , int off , int len ) throws IOException { while ( len -- > 0 ) { this . Double ( values [ off ++ ] ) ; } return this ; }
Print values from double array
21,514
public JBBPTextWriter Int ( final int value ) throws IOException { ensureValueMode ( ) ; String convertedByExtras = null ; for ( final Extra e : this . extras ) { convertedByExtras = e . doConvertIntToStr ( this , value ) ; if ( convertedByExtras != null ) { break ; } } if ( convertedByExtras == null ) { final long valueToWrite ; if ( this . byteOrder == JBBPByteOrder . LITTLE_ENDIAN ) { valueToWrite = JBBPUtils . reverseByteOrder ( value , 4 ) ; } else { valueToWrite = value ; } printValueString ( JBBPUtils . ensureMinTextLength ( JBBPUtils . ulong2str ( valueToWrite & 0xFFFFFFFFL , this . radix , CHAR_BUFFER ) , this . maxCharsRadixForInt , '0' , 0 ) ) ; } else { printValueString ( convertedByExtras ) ; } return this ; }
Print integer value
21,515
public JBBPTextWriter Int ( final int [ ] values , int off , int len ) throws IOException { while ( len -- > 0 ) { this . Int ( values [ off ++ ] ) ; } return this ; }
Print values from integer array .
21,516
public JBBPTextWriter Long ( final long value ) throws IOException { ensureValueMode ( ) ; String convertedByExtras = null ; for ( final Extra e : this . extras ) { convertedByExtras = e . doConvertLongToStr ( this , value ) ; if ( convertedByExtras != null ) { break ; } } if ( convertedByExtras == null ) { final long valueToWrite ; if ( this . byteOrder == JBBPByteOrder . LITTLE_ENDIAN ) { valueToWrite = JBBPUtils . reverseByteOrder ( value , 8 ) ; } else { valueToWrite = value ; } printValueString ( JBBPUtils . ensureMinTextLength ( JBBPUtils . ulong2str ( valueToWrite , this . radix , CHAR_BUFFER ) , this . maxCharsRadixForLong , '0' , 0 ) ) ; } else { printValueString ( convertedByExtras ) ; } return this ; }
Print long value
21,517
public JBBPTextWriter Long ( final long [ ] values , int off , int len ) throws IOException { while ( len -- > 0 ) { this . Long ( values [ off ++ ] ) ; } return this ; }
print values from long array .
21,518
public JBBPTextWriter SetHR ( final String prefix , final int length , final char ch ) { this . prefixHR = prefix == null ? "" : prefix ; this . hrChar = ch ; this . hrLength = length ; return this ; }
Change parameters for horizontal rule .
21,519
public JBBPTextWriter HR ( ) throws IOException { if ( this . flagCommentsAllowed ) { this . ensureNewLineMode ( ) ; this . writeIndent ( ) ; this . write ( this . prefixHR ) ; for ( int i = 0 ; i < this . hrLength ; i ++ ) { this . write ( this . hrChar ) ; } } this . BR ( ) ; return this ; }
Print horizontal rule . If comments are disabled then only next line will be added .
21,520
public JBBPTextWriter Comment ( final String ... comment ) throws IOException { if ( this . flagCommentsAllowed ) { if ( comment != null ) { for ( final String c : comment ) { if ( c == null ) { continue ; } if ( c . indexOf ( '\n' ) >= 0 ) { final String [ ] splitted = c . split ( "\\n" , - 1 ) ; for ( final String s : splitted ) { this . ensureCommentMode ( ) ; this . write ( s ) ; } } else { this . ensureCommentMode ( ) ; this . write ( c ) ; } } this . prevLineCommentsStartPosition = 0 ; } } else { ensureNewLineMode ( ) ; } return this ; }
Print comments . Wilt aligning of line start for multi - line comment . Comments will be printed only if they are allowed .
21,521
public JBBPTextWriter Obj ( final int objId , final Object ... obj ) throws IOException { if ( this . extras . isEmpty ( ) ) { throw new IllegalStateException ( "There is not any registered extras" ) ; } for ( final Object c : obj ) { String str = null ; for ( final Extra e : this . extras ) { str = e . doConvertObjToStr ( this , objId , c ) ; if ( str != null ) { break ; } } if ( str != null ) { ensureValueMode ( ) ; printValueString ( str ) ; } } return this ; }
Print objects .
21,522
public JBBPTextWriter Obj ( final int objId , final Object [ ] array , int off , int len ) throws IOException { while ( len -- > 0 ) { this . Obj ( objId , array [ off ++ ] ) ; } return this ; }
Print objects from array .
21,523
private void writeChar ( final char chr ) throws IOException { switch ( chr ) { case '\t' : this . Tab ( ) ; break ; case '\n' : { this . out . write ( this . lineSeparator ) ; this . lineNumber ++ ; this . prevMode = this . mode ; this . mode = MODE_START_LINE ; this . linePosition = 0 ; for ( final Extra e : extras ) { e . onNewLine ( this , this . lineNumber ) ; } } break ; case '\r' : break ; default : { if ( ! Character . isISOControl ( chr ) ) { this . out . write ( chr ) ; this . linePosition ++ ; if ( this . mode == MODE_START_LINE ) { this . mode = this . prevMode ; } } } break ; } }
Main method writing a char into wrapped writer .
21,524
public static JBBPOut BeginBin ( final JBBPByteOrder byteOrder , final JBBPBitOrder bitOrder ) { return new JBBPOut ( new ByteArrayOutputStream ( ) , byteOrder , bitOrder ) ; }
Start a DSL session for defined both byte outOrder and bit outOrder parameters .
21,525
public static JBBPOut BeginBin ( final OutputStream out , final JBBPByteOrder byteOrder , final JBBPBitOrder bitOrder ) { return new JBBPOut ( out , byteOrder , bitOrder ) ; }
Start a DSL session for a defined stream with defined parameters .
21,526
public JBBPOut Skip ( int numberOfBytes ) throws IOException { assertNotEnded ( ) ; if ( this . processCommands ) { if ( numberOfBytes < 0 ) { throw new IllegalArgumentException ( "Value is negative" ) ; } this . Align ( ) ; while ( numberOfBytes > 0 ) { this . outStream . write ( 0 ) ; numberOfBytes -- ; } } return this ; }
Skip number of bytes in the stream zero bytes will be written and also will be aligned inside bit cache even if the value is 0 .
21,527
public JBBPOut ByteOrder ( final JBBPByteOrder value ) throws IOException { assertNotEnded ( ) ; JBBPUtils . assertNotNull ( value , "Byte order must not be null" ) ; if ( this . processCommands ) { this . byteOrder = value ; } return this ; }
Define the byte outOrder for next session operations .
21,528
public JBBPOut Bit ( final boolean value ) throws IOException { assertNotEnded ( ) ; if ( this . processCommands ) { this . outStream . writeBits ( value ? 1 : 0 , JBBPBitNumber . BITS_1 ) ; } return this ; }
Write a bit into the session .
21,529
public JBBPOut Bit ( final byte value ) throws IOException { assertNotEnded ( ) ; if ( this . processCommands ) { this . _writeBits ( JBBPBitNumber . BITS_1 , value ) ; } return this ; }
Write the lowest bit from a byte value .
21,530
public JBBPOut Bits ( final JBBPBitNumber numberOfBits , final int value ) throws IOException { assertNotEnded ( ) ; JBBPUtils . assertNotNull ( numberOfBits , "Number of bits must not be null" ) ; if ( this . processCommands ) { _writeBits ( numberOfBits , value ) ; } return this ; }
Write bits from a value into the output stream
21,531
public JBBPOut Byte ( final int ... value ) throws IOException { assertNotEnded ( ) ; assertArrayNotNull ( value ) ; if ( this . processCommands ) { for ( final int v : value ) { _writeByte ( v ) ; } } return this ; }
Write the lower byte of an integer value into the session stream .
21,532
public JBBPOut Byte ( final byte [ ] value ) throws IOException { assertNotEnded ( ) ; assertArrayNotNull ( value ) ; if ( this . processCommands ) { this . outStream . write ( value ) ; } return this ; }
Write a byte array into the session stream .
21,533
public JBBPOut Utf8 ( final String str ) throws IOException { assertNotEnded ( ) ; assertStringNotNull ( str ) ; if ( this . processCommands ) { this . outStream . write ( JBBPUtils . strToUtf8 ( str ) ) ; } return this ; }
Write chars of a String as encoded Utf8 byte array . There will not be aby information about string length .
21,534
public JBBPOut Bool ( final boolean value , final JBBPBitOrder bitOrder ) throws IOException { assertNotEnded ( ) ; if ( this . processCommands ) { this . outStream . write ( value ? bitOrder == JBBPBitOrder . MSB0 ? 0x80 : 1 : 0 ) ; } return this ; }
Write a boolean value into the session stream as a byte .
21,535
public JBBPOut Bool ( final boolean ... value ) throws IOException { assertNotEnded ( ) ; assertArrayNotNull ( value ) ; if ( this . processCommands ) { for ( final boolean b : value ) { this . outStream . write ( b ? 1 : 0 ) ; } } return this ; }
Write boolean values from an array into the session stream as bytes .
21,536
public JBBPOut Short ( final short [ ] value ) throws IOException { assertNotEnded ( ) ; assertArrayNotNull ( value ) ; if ( this . processCommands ) { for ( final short v : value ) { this . _writeShort ( v ) ; } } return this ; }
Write short values from an array
21,537
public JBBPOut Int ( final int ... value ) throws IOException { assertNotEnded ( ) ; assertArrayNotNull ( value ) ; if ( this . processCommands ) { for ( final int v : value ) { _writeInt ( v ) ; } } return this ; }
Write each integer value from an integer array into the session stream .
21,538
public JBBPOut Float ( final float ... value ) throws IOException { assertNotEnded ( ) ; assertArrayNotNull ( value ) ; if ( this . processCommands ) { for ( final float f : value ) { _writeFloat ( f ) ; } } return this ; }
Write a float value array as integer bits into the stream .
21,539
public JBBPOut Double ( final double ... value ) throws IOException { assertNotEnded ( ) ; assertArrayNotNull ( value ) ; if ( this . processCommands ) { for ( final double d : value ) { _writeDouble ( d ) ; } } return this ; }
Write a double value array as long bits into the stream .
21,540
public JBBPOut Long ( final long ... value ) throws IOException { assertNotEnded ( ) ; assertArrayNotNull ( value ) ; if ( this . processCommands ) { for ( final long l : value ) { _writeLong ( l ) ; } } return this ; }
Write each long value from a long value array into the session stream .
21,541
public JBBPOut Var ( final JBBPOutVarProcessor processor , final Object ... args ) throws IOException { assertNotEnded ( ) ; JBBPUtils . assertNotNull ( processor , "Var processor must not be null" ) ; if ( this . processCommands ) { this . processCommands = processor . processVarOut ( this , this . outStream , args ) ; } return this ; }
Output data externally .
21,542
public JBBPIntegerValueEvaluator make ( final String expression , final List < JBBPNamedFieldInfo > namedFields , final byte [ ] compiledScript ) { final JBBPIntegerValueEvaluator result ; if ( JBBPExpressionEvaluator . hasExpressionOperators ( expression ) ) { result = new JBBPExpressionEvaluator ( expression , namedFields , compiledScript ) ; } else { int index = - 1 ; if ( expression . startsWith ( "$" ) ) { result = new JBBPOnlyFieldEvaluator ( expression . substring ( 1 ) , index ) ; } else { for ( int i = namedFields . size ( ) - 1 ; i >= 0 ; i -- ) { final JBBPNamedFieldInfo field = namedFields . get ( i ) ; if ( expression . equals ( field . getFieldPath ( ) ) ) { index = i ; break ; } } if ( index < 0 ) { result = new JBBPExpressionEvaluator ( expression , namedFields , compiledScript ) ; } else { JBBPCompilerUtils . assertFieldIsNotArrayOrInArray ( namedFields . get ( index ) , namedFields , compiledScript ) ; result = new JBBPOnlyFieldEvaluator ( null , index ) ; } } } return result ; }
Make an appropriate evaluator for an expression text .
21,543
private static void assertName ( final String name , final JBBPToken token ) { if ( name . indexOf ( '.' ) >= 0 ) { throw new JBBPCompilationException ( "Detected disallowed char '.' in name [" + name + ']' , token ) ; } }
The Method check that a field name supports business rules .
21,544
private static void registerNamedField ( final String normalizedName , final int structureBorder , final int offset , final List < JBBPNamedFieldInfo > namedFields , final JBBPToken token ) { for ( int i = namedFields . size ( ) - 1 ; i >= structureBorder ; i -- ) { final JBBPNamedFieldInfo info = namedFields . get ( i ) ; if ( info . getFieldPath ( ) . equals ( normalizedName ) ) { throw new JBBPCompilationException ( "Duplicated named field detected [" + normalizedName + ']' , token ) ; } } namedFields . add ( new JBBPNamedFieldInfo ( normalizedName , normalizedName , offset ) ) ; }
Register a name field info item in a named field list .
21,545
private static int writePackedInt ( final OutputStream out , final int value ) throws IOException { final byte [ ] packedInt = JBBPUtils . packInt ( value ) ; out . write ( packedInt ) ; return packedInt . length ; }
Write an integer value in packed form into an output stream .
21,546
private static int prepareCodeForToken ( final JBBPToken token , final JBBPCustomFieldTypeProcessor customTypeFieldProcessor ) { int result = - 1 ; switch ( token . getType ( ) ) { case ATOM : { final JBBPFieldTypeParameterContainer descriptor = token . getFieldTypeParameters ( ) ; result = descriptor . getByteOrder ( ) == JBBPByteOrder . LITTLE_ENDIAN ? FLAG_LITTLE_ENDIAN : 0 ; final boolean hasExpressionAsExtraNumber = descriptor . hasExpressionAsExtraData ( ) ; result |= token . getArraySizeAsString ( ) == null ? 0 : ( token . isVarArrayLength ( ) ? FLAG_ARRAY | FLAG_WIDE | ( EXT_FLAG_EXPRESSION_OR_WHOLESTREAM << 8 ) : FLAG_ARRAY ) ; result |= hasExpressionAsExtraNumber ? FLAG_WIDE | ( EXT_FLAG_EXTRA_AS_EXPRESSION << 8 ) : 0 ; result |= token . getFieldTypeParameters ( ) . isSpecialField ( ) ? FLAG_WIDE | ( EXT_FLAG_EXTRA_DIFF_TYPE << 8 ) : 0 ; result |= token . getFieldName ( ) == null ? 0 : FLAG_NAMED ; final String name = descriptor . getTypeName ( ) . toLowerCase ( Locale . ENGLISH ) ; switch ( name ) { case "skip" : case "val" : result |= CODE_SKIP ; break ; case "align" : result |= CODE_ALIGN ; break ; case "bit" : result |= CODE_BIT ; break ; case "var" : result |= CODE_VAR ; break ; case "bool" : case JBBPFieldString . TYPE_NAME : result |= CODE_BOOL ; break ; case "ubyte" : result |= CODE_UBYTE ; break ; case "byte" : result |= CODE_BYTE ; break ; case "ushort" : result |= CODE_USHORT ; break ; case "short" : result |= CODE_SHORT ; break ; case "int" : case JBBPFieldFloat . TYPE_NAME : result |= CODE_INT ; break ; case "long" : case JBBPFieldDouble . TYPE_NAME : result |= CODE_LONG ; break ; case "reset$$" : result |= CODE_RESET_COUNTER ; break ; default : boolean unsupportedType = true ; if ( customTypeFieldProcessor != null ) { for ( final String s : customTypeFieldProcessor . getCustomFieldTypes ( ) ) { if ( name . equals ( s ) ) { result |= CODE_CUSTOMTYPE ; unsupportedType = false ; break ; } } } if ( unsupportedType ) { throw new JBBPCompilationException ( "Unsupported type [" + descriptor . getTypeName ( ) + ']' , token ) ; } break ; } } break ; case COMMENT : { } break ; case STRUCT_START : { result = token . getArraySizeAsString ( ) == null ? 0 : ( token . isVarArrayLength ( ) ? FLAG_ARRAY | FLAG_WIDE | ( EXT_FLAG_EXPRESSION_OR_WHOLESTREAM << 8 ) : FLAG_ARRAY ) ; result |= token . getFieldName ( ) == null ? 0 : FLAG_NAMED ; result |= CODE_STRUCT_START ; } break ; case STRUCT_END : { result = CODE_STRUCT_END ; } break ; default : throw new Error ( "Unsupported type detected, contact developer! [" + token . getType ( ) + ']' ) ; } return result ; }
The Method prepares a byte - code for a token field type and modifiers .
21,547
private static String convertFieldValueToString ( final JBBPAbstractArrayField < ? > field ) { final StringBuilder result ; if ( field instanceof JBBPFieldArrayBit ) { final JBBPFieldArrayBit array = ( JBBPFieldArrayBit ) field ; result = new StringBuilder ( array . size ( ) ) ; for ( final byte b : array . getArray ( ) ) { result . append ( ( char ) ( b & 0xFF ) ) ; } } else if ( field instanceof JBBPFieldArrayByte ) { final JBBPFieldArrayByte array = ( JBBPFieldArrayByte ) field ; result = new StringBuilder ( array . size ( ) ) ; for ( final byte b : array . getArray ( ) ) { result . append ( ( char ) ( b & 0xFF ) ) ; } } else if ( field instanceof JBBPFieldArrayUByte ) { final JBBPFieldArrayUByte array = ( JBBPFieldArrayUByte ) field ; result = new StringBuilder ( array . size ( ) ) ; for ( final byte b : array . getArray ( ) ) { result . append ( ( char ) ( b & 0xFF ) ) ; } } else if ( field instanceof JBBPFieldArrayShort ) { final JBBPFieldArrayShort array = ( JBBPFieldArrayShort ) field ; result = new StringBuilder ( array . size ( ) ) ; for ( final short b : array . getArray ( ) ) { result . append ( ( char ) b ) ; } } else if ( field instanceof JBBPFieldArrayUShort ) { final JBBPFieldArrayUShort array = ( JBBPFieldArrayUShort ) field ; result = new StringBuilder ( array . size ( ) ) ; for ( final short b : array . getArray ( ) ) { result . append ( ( char ) b ) ; } } else { result = null ; } return result == null ? null : result . toString ( ) ; }
Convert an array field into its string representation .
21,548
private static void setFieldValue ( final Object classInstance , final Field classField , final JBBPAbstractField binField , final Object value ) { try { classField . set ( classInstance , value ) ; } catch ( IllegalArgumentException ex ) { throw new JBBPMapperException ( "Can't set value to a mapping field" , binField , classInstance . getClass ( ) , classField , ex ) ; } catch ( IllegalAccessException ex ) { throw new JBBPMapperException ( "Can't get access to a mapping field" , binField , classInstance . getClass ( ) , classField , ex ) ; } }
Set a value to a field of a class instance . Can t be used for static fields!
21,549
private static Object getFieldValue ( final Object classInstance , final Field classField ) { try { return classField . get ( classInstance ) ; } catch ( IllegalArgumentException ex ) { throw new JBBPMapperException ( "Can't set get value from a mapping field" , null , classInstance . getClass ( ) , classField , ex ) ; } catch ( IllegalAccessException ex ) { throw new JBBPMapperException ( "Can't get access to a mapping field" , null , classInstance . getClass ( ) , classField , ex ) ; } }
Get a value of a field from a class instance .
21,550
private static void mapArrayField ( final Object mappingClassInstance , final Field mappingField , final JBBPAbstractArrayField < ? > arrayField , final boolean invertBitOrder ) { try { if ( arrayField instanceof JBBPFieldArrayLong && mappingField . getType ( ) . getComponentType ( ) == double . class ) { final long [ ] longarray = ( long [ ] ) arrayField . getValueArrayAsObject ( invertBitOrder ) ; final double [ ] doublearray = new double [ longarray . length ] ; for ( int i = 0 ; i < longarray . length ; i ++ ) { doublearray [ i ] = Double . longBitsToDouble ( longarray [ i ] ) ; } mappingField . set ( mappingClassInstance , doublearray ) ; } else if ( arrayField instanceof JBBPFieldArrayInt && mappingField . getType ( ) . getComponentType ( ) == float . class ) { final int [ ] intarray = ( int [ ] ) arrayField . getValueArrayAsObject ( invertBitOrder ) ; final float [ ] floatarray = new float [ intarray . length ] ; for ( int i = 0 ; i < intarray . length ; i ++ ) { floatarray [ i ] = Float . intBitsToFloat ( intarray [ i ] ) ; } mappingField . set ( mappingClassInstance , floatarray ) ; } else if ( arrayField instanceof JBBPFieldArrayUShort && mappingField . getType ( ) . getComponentType ( ) == char . class ) { final short [ ] shortarray = ( short [ ] ) arrayField . getValueArrayAsObject ( invertBitOrder ) ; final char [ ] chararray = new char [ shortarray . length ] ; for ( int i = 0 ; i < shortarray . length ; i ++ ) { chararray [ i ] = ( char ) shortarray [ i ] ; } mappingField . set ( mappingClassInstance , chararray ) ; } else { mappingField . set ( mappingClassInstance , arrayField . getValueArrayAsObject ( invertBitOrder ) ) ; } } catch ( IllegalAccessException ex ) { throw new JBBPMapperException ( "Can't get access to a mapping field" , arrayField , mappingClassInstance . getClass ( ) , mappingField , ex ) ; } catch ( IllegalArgumentException ex ) { throw new JBBPMapperException ( "Can't set argument to a mapping field" , arrayField , mappingClassInstance . getClass ( ) , mappingField , ex ) ; } }
Map a parsed array to an array field in mapping class .
21,551
private static < T > T allocateMemoryForClass ( final JBBPFieldStruct root , final Class < T > klazz ) { try { return CLASS_INSTANTIATOR . makeClassInstance ( klazz ) ; } catch ( InstantiationException ex ) { throw new JBBPMapperException ( "Can't make an instance of a class" , root , klazz , null , ex ) ; } }
Makes an instance of a class without call of its constructor just allocate memory
21,552
public static < T > T newInstance ( final Class < T > klazz ) { try { return klazz . getConstructor ( ) . newInstance ( ) ; } catch ( Exception ex ) { throw new Error ( String . format ( "Can't create instance of %s for error %s" , klazz . getCanonicalName ( ) , ex . getMessage ( ) ) , ex ) ; } }
Create class instance through default constructor call
21,553
public static Object newInstanceForClassName ( final String className ) { try { return newInstance ( Class . forName ( className ) ) ; } catch ( Exception ex ) { throw new Error ( String . format ( "Can't create instance of %s for error %s" , className , ex . getMessage ( ) ) , ex ) ; } }
Find class for name and make an instance through call of the default constructor .
21,554
private static Object [ ] makeStubForConstructor ( final Class < ? > [ ] constructorParamTypes ) { if ( constructorParamTypes . length == 0 ) { return EMPTY_OBJECT_ARRAY ; } final Object [ ] result = new Object [ constructorParamTypes . length ] ; for ( int i = 0 ; i < constructorParamTypes . length ; i ++ ) { final Class < ? > arg = constructorParamTypes [ i ] ; final Object obj ; if ( arg . isArray ( ) ) { obj = null ; } else { if ( arg == byte . class ) { obj = ( byte ) 0 ; } else if ( arg == char . class ) { obj = 'a' ; } else if ( arg == short . class ) { obj = ( short ) 0 ; } else if ( arg == boolean . class ) { obj = Boolean . FALSE ; } else if ( arg == int . class ) { obj = 0 ; } else if ( arg == long . class ) { obj = 0L ; } else if ( arg == double . class ) { obj = 0.0d ; } else if ( arg == float . class ) { obj = 0.0f ; } else { obj = null ; } } result [ i ] = obj ; } return result ; }
Make stub arguments for a constructor .
21,555
private static Constructor < ? > findConstructorForInnerClass ( final Class < ? > klazz , final Class < ? > declaringClass ) { final Constructor < ? > [ ] constructors = klazz . getDeclaredConstructors ( ) ; if ( constructors . length == 1 ) { return constructors [ 0 ] ; } for ( final Constructor < ? > c : constructors ) { final Class < ? > [ ] params = c . getParameterTypes ( ) ; if ( params . length == 1 && params [ 0 ] == declaringClass ) { return c ; } } return constructors [ 0 ] ; }
Find a constructor for an inner class .
21,556
private static Constructor < ? > findConstructorForStaticClass ( final Class < ? > klazz ) { final Constructor < ? > [ ] constructors = klazz . getDeclaredConstructors ( ) ; if ( constructors . length == 1 ) { return constructors [ 0 ] ; } for ( final Constructor < ? > c : constructors ) { final Class < ? > [ ] params = c . getParameterTypes ( ) ; if ( params . length == 0 ) { return c ; } } return constructors [ 0 ] ; }
Find a constructor for a static class .
21,557
public JBBPDslBuilder Custom ( final String type , final String name ) { return this . Custom ( type , name , null ) ; }
Add named custom variable .
21,558
public JBBPDslBuilder Custom ( final String type , final String name , final String param ) { final ItemCustom custom = new ItemCustom ( type , name , this . byteOrder ) ; custom . bitLenExpression = param == null ? null : assertExpressionChars ( param ) ; this . addItem ( custom ) ; return this ; }
Add named parametric custom variable .
21,559
public JBBPDslBuilder Struct ( final String name ) { final Item item = new Item ( BinType . STRUCT , name , this . byteOrder ) ; this . addItem ( item ) ; this . openedStructCounter ++ ; return this ; }
Create new named struct .
21,560
public JBBPDslBuilder StructArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . STRUCT_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; this . openedStructCounter ++ ; return this ; }
Create named structure array which size calculated by expression .
21,561
public JBBPDslBuilder Val ( final String name , final String expression ) { final Item item = new ItemVal ( assertTextNotNullAndTrimmedNotEmpty ( name ) , assertExpressionChars ( assertTextNotNullAndTrimmedNotEmpty ( expression ) ) . trim ( ) ) ; this . addItem ( item ) ; return this ; }
Add virtual field which not be read but its value will be calculated by expression
21,562
public JBBPDslBuilder CustomArray ( final String type , final String size ) { return this . CustomArray ( type , null , size , null ) ; }
Create anonymous custom type array with fixed size .
21,563
public JBBPDslBuilder CloseStruct ( final boolean closeAllOpened ) { if ( this . openedStructCounter == 0 ) { throw new IllegalStateException ( "There is not any opened struct" ) ; } this . addItem ( new ItemStructEnd ( closeAllOpened ) ) ; this . openedStructCounter = closeAllOpened ? 0 : this . openedStructCounter - 1 ; return this ; }
Add directive to close currently opened structure or all opened structures .
21,564
public JBBPDslBuilder Bits ( final String name , final JBBPBitNumber bits ) { final Item item = new Item ( BinType . BIT , name , this . byteOrder ) ; item . bitNumber = bits ; this . addItem ( item ) ; return this ; }
Add named fixed length bit field .
21,565
public JBBPDslBuilder Bits ( final String name , final String bitLenExpression ) { final Item item = new Item ( BinType . BIT , name , this . byteOrder ) ; item . bitLenExpression = assertExpressionChars ( bitLenExpression ) ; this . addItem ( item ) ; return this ; }
Add named bit field which length calculated by expression .
21,566
public JBBPDslBuilder BitArray ( final JBBPBitNumber bits , final int size ) { return this . BitArray ( null , bits , arraySizeToString ( size ) ) ; }
Add anonymous fixed length bit array .
21,567
public JBBPDslBuilder BitArray ( final String name , final JBBPBitNumber bits , final int size ) { return this . BitArray ( name , bits , arraySizeToString ( size ) ) ; }
Add named fixed length bit array .
21,568
public JBBPDslBuilder BitArray ( final String name , final String bitLenExpression , final int size ) { return this . BitArray ( name , bitLenExpression , arraySizeToString ( size ) ) ; }
Add named fixed length bit array size of one bit field is calculated by expression .
21,569
public JBBPDslBuilder BitArray ( final String name , final JBBPBitNumber bits , final String sizeExpression ) { final Item item = new Item ( BinType . BIT_ARRAY , name , this . byteOrder ) ; item . bitNumber = bits ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named bit array with size calculated through expression .
21,570
public JBBPDslBuilder BitArray ( final String name , final String bitLenExpression , final String sizeExpression ) { final Item item = new Item ( BinType . BIT_ARRAY , name , this . byteOrder ) ; item . bitLenExpression = assertExpressionChars ( bitLenExpression ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named bit array where each bit length is calculated through expression .
21,571
public JBBPDslBuilder BoolArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . BOOL_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named boolean array which length calculated through expression .
21,572
public JBBPDslBuilder Bool ( final String name ) { final Item item = new Item ( BinType . BOOL , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named boolean field .
21,573
public JBBPDslBuilder Byte ( final String name ) { final Item item = new Item ( BinType . BYTE , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named signed byte field .
21,574
public JBBPDslBuilder ByteArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . BYTE_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named byte array which size calculated through expression .
21,575
public JBBPDslBuilder UByte ( final String name ) { final Item item = new Item ( BinType . UBYTE , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named unsigned byte field .
21,576
public JBBPDslBuilder UByteArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . UBYTE_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named unsigned byte array which size calculated through expression .
21,577
public JBBPDslBuilder Short ( final String name ) { final Item item = new Item ( BinType . SHORT , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named signed short field .
21,578
public JBBPDslBuilder ShortArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . SHORT_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named fixed signed short array which size calculated through expression .
21,579
public JBBPDslBuilder UShort ( final String name ) { final Item item = new Item ( BinType . USHORT , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named unsigned short field .
21,580
public JBBPDslBuilder UShortArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . USHORT_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named fixed unsigned short array which size calculated through expression .
21,581
public JBBPDslBuilder Int ( final String name ) { final Item item = new Item ( BinType . INT , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named integer field .
21,582
public JBBPDslBuilder IntArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . INT_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named integer array with size calculated through expression .
21,583
public JBBPDslBuilder Long ( final String name ) { final Item item = new Item ( BinType . LONG , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named long field .
21,584
public JBBPDslBuilder LongArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . LONG_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named long array which size calculated through expression .
21,585
public JBBPDslBuilder Float ( final String name ) { final Item item = new Item ( BinType . FLOAT , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named float field
21,586
public JBBPDslBuilder FloatArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . FLOAT_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named float array which size calculated through expression .
21,587
public JBBPDslBuilder Double ( final String name ) { final Item item = new Item ( BinType . DOUBLE , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named double field .
21,588
public JBBPDslBuilder Comment ( final String text ) { this . addItem ( new ItemComment ( text == null ? "" : text , false ) ) ; return this ; }
Add comment in case that a field followed by the comment the comment will be placed on the same line as field definition .
21,589
public JBBPDslBuilder NewLineComment ( final String text ) { this . addItem ( new ItemComment ( text == null ? "" : text , true ) ) ; return this ; }
Add comment which will be placed on new line .
21,590
public JBBPDslBuilder DoubleArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . DOUBLE_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named double array field which size calculated trough expression .
21,591
public JBBPDslBuilder String ( final String name ) { final Item item = new Item ( BinType . STRING , name , this . byteOrder ) ; this . addItem ( item ) ; return this ; }
Add named string field .
21,592
public JBBPDslBuilder StringArray ( final String name , final String sizeExpression ) { final Item item = new Item ( BinType . STRING_ARRAY , name , this . byteOrder ) ; item . sizeExpression = assertExpressionChars ( sizeExpression ) ; this . addItem ( item ) ; return this ; }
Add named string array which size calculated through expression .
21,593
public JBBPDslBuilder ByteOrder ( final JBBPByteOrder order ) { this . byteOrder = order == null ? JBBPByteOrder . BIG_ENDIAN : order ; return this ; }
Set byte order for next fields
21,594
protected BinFieldContainer collectAnnotatedFields ( final Class < ? > annotatedClass ) { final Bin defautBin = annotatedClass . getAnnotation ( Bin . class ) ; final DslBinCustom defaultBinCustom = annotatedClass . getAnnotation ( DslBinCustom . class ) ; final BinFieldContainer result ; if ( defautBin != null ) { result = new BinFieldContainer ( annotatedClass , defautBin , true , null ) ; } else if ( defaultBinCustom != null ) { result = new BinFieldContainer ( annotatedClass , defaultBinCustom , true , null ) ; } else { result = new BinFieldContainer ( annotatedClass , null ) ; } final Class < ? > superclazz = annotatedClass . getSuperclass ( ) ; if ( superclazz != null && superclazz != Object . class ) { final BinFieldContainer parentFields = collectAnnotatedFields ( superclazz ) ; if ( ! parentFields . fields . isEmpty ( ) ) { result . addAllFromContainer ( parentFields ) ; } } for ( final Field f : annotatedClass . getDeclaredFields ( ) ) { if ( ( f . getModifiers ( ) & ( Modifier . NATIVE | Modifier . STATIC | Modifier . FINAL | Modifier . PRIVATE | Modifier . TRANSIENT ) ) == 0 ) { final Bin fieldBinAnno = f . getAnnotation ( Bin . class ) ; final DslBinCustom fieldBinCustomAnno = f . getAnnotation ( DslBinCustom . class ) ; if ( fieldBinAnno != null || defautBin != null || defaultBinCustom != null || fieldBinCustomAnno != null ) { validateAnnotatedField ( defautBin , fieldBinAnno , defaultBinCustom , fieldBinCustomAnno , f ) ; final Class < ? > type = f . getType ( ) . isArray ( ) ? f . getType ( ) . getComponentType ( ) : f . getType ( ) ; if ( type . isPrimitive ( ) || type == String . class ) { if ( fieldBinAnno != null || fieldBinCustomAnno != null ) { if ( fieldBinAnno != null ) { result . addBinField ( fieldBinAnno , true , f ) ; } else { result . addBinCustomField ( fieldBinCustomAnno , true , f ) ; } } else { if ( defautBin != null ) { result . addBinField ( defautBin , false , f ) ; } else { result . addBinCustomField ( defaultBinCustom , false , f ) ; } } } else { final BinFieldContainer container = collectAnnotatedFields ( type ) ; if ( ! container . fields . isEmpty ( ) ) { if ( fieldBinAnno != null ) { container . bin = fieldBinAnno ; container . fieldLocalAnnotation = true ; } else if ( fieldBinCustomAnno != null ) { container . binCustom = fieldBinCustomAnno ; container . fieldLocalAnnotation = true ; } container . field = f ; result . addContainer ( container ) ; } } } } } result . sort ( ) ; if ( ! result . fields . isEmpty ( ) ) { result . addContainer ( BinFieldContainer . END_STRUCT ) ; } return result ; }
Allows to collect all fields which can be used for scripting .
21,595
public boolean [ ] readBoolArray ( final int items ) throws IOException { int pos = 0 ; byte [ ] buffer ; if ( items < 0 ) { buffer = new byte [ INITIAL_ARRAY_BUFFER_SIZE ] ; while ( true ) { final int read = this . read ( buffer , pos , buffer . length - pos ) ; if ( read < 0 ) { break ; } pos += read ; if ( buffer . length == pos ) { final byte [ ] newbuffer = new byte [ buffer . length << 1 ] ; System . arraycopy ( buffer , 0 , newbuffer , 0 , buffer . length ) ; buffer = newbuffer ; } } } else { buffer = new byte [ items ] ; int len = items ; while ( len > 0 ) { final int read = this . read ( buffer , pos , len ) ; if ( read < 0 ) { throw new EOFException ( "Have read only " + pos + " bit portions instead of " + items ) ; } pos += read ; len -= read ; } } final boolean [ ] result = new boolean [ pos ] ; for ( int i = 0 ; i < pos ; i ++ ) { result [ i ] = buffer [ i ] != 0 ; } return result ; }
Read array of boolean values .
21,596
public byte [ ] readByteArray ( final int items , final JBBPByteOrder byteOrder ) throws IOException { final byte [ ] result = _readArray ( items , null ) ; if ( byteOrder == JBBPByteOrder . LITTLE_ENDIAN ) { JBBPUtils . reverseArray ( result ) ; } return result ; }
Read number of bytes for the stream . Invert their order if byte order is LITTLE_ENDIAN
21,597
public short [ ] readShortArray ( final int items , final JBBPByteOrder byteOrder ) throws IOException { int pos = 0 ; if ( items < 0 ) { short [ ] buffer = new short [ INITIAL_ARRAY_BUFFER_SIZE ] ; while ( hasAvailableData ( ) ) { final int next = readUnsignedShort ( byteOrder ) ; if ( buffer . length == pos ) { final short [ ] newbuffer = new short [ buffer . length << 1 ] ; System . arraycopy ( buffer , 0 , newbuffer , 0 , buffer . length ) ; buffer = newbuffer ; } buffer [ pos ++ ] = ( short ) next ; } if ( buffer . length == pos ) { return buffer ; } final short [ ] result = new short [ pos ] ; System . arraycopy ( buffer , 0 , result , 0 , pos ) ; return result ; } else { final short [ ] buffer = new short [ items ] ; for ( int i = 0 ; i < items ; i ++ ) { buffer [ i ] = ( short ) readUnsignedShort ( byteOrder ) ; } return buffer ; } }
Read number of short items from the input stream .
21,598
public int [ ] readIntArray ( final int items , final JBBPByteOrder byteOrder ) throws IOException { int pos = 0 ; if ( items < 0 ) { int [ ] buffer = new int [ INITIAL_ARRAY_BUFFER_SIZE ] ; while ( hasAvailableData ( ) ) { final int next = readInt ( byteOrder ) ; if ( buffer . length == pos ) { final int [ ] newbuffer = new int [ buffer . length << 1 ] ; System . arraycopy ( buffer , 0 , newbuffer , 0 , buffer . length ) ; buffer = newbuffer ; } buffer [ pos ++ ] = next ; } if ( buffer . length == pos ) { return buffer ; } final int [ ] result = new int [ pos ] ; System . arraycopy ( buffer , 0 , result , 0 , pos ) ; return result ; } else { final int [ ] buffer = new int [ items ] ; for ( int i = 0 ; i < items ; i ++ ) { buffer [ i ] = readInt ( byteOrder ) ; } return buffer ; } }
Read number of integer items from the input stream .
21,599
public float [ ] readFloatArray ( final int items , final JBBPByteOrder byteOrder ) throws IOException { int pos = 0 ; if ( items < 0 ) { float [ ] buffer = new float [ INITIAL_ARRAY_BUFFER_SIZE ] ; while ( hasAvailableData ( ) ) { final float next = readFloat ( byteOrder ) ; if ( buffer . length == pos ) { final float [ ] newbuffer = new float [ buffer . length << 1 ] ; System . arraycopy ( buffer , 0 , newbuffer , 0 , buffer . length ) ; buffer = newbuffer ; } buffer [ pos ++ ] = next ; } if ( buffer . length == pos ) { return buffer ; } final float [ ] result = new float [ pos ] ; System . arraycopy ( buffer , 0 , result , 0 , pos ) ; return result ; } else { final float [ ] buffer = new float [ items ] ; for ( int i = 0 ; i < items ; i ++ ) { buffer [ i ] = readFloat ( byteOrder ) ; } return buffer ; } }
Read number of float items from the input stream .