idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
37,600 | protected int storeReference ( Object obj ) { int newRefId = refId . getAndIncrement ( ) ; refMap . put ( Integer . valueOf ( newRefId ) , obj ) ; return newRefId ; } | Store an object into a map . |
37,601 | protected void storeReference ( int refId , Object newRef ) { refMap . put ( Integer . valueOf ( refId ) , newRef ) ; } | Replace a referenced object with another one . This is used by the AMF3 deserializer to handle circular references . |
37,602 | private HeaderBitField createHeaderField ( ) throws IOException { HeaderBitField field = new HeaderBitField ( ) ; field . add ( nextByte ( ) ) ; field . add ( nextByte ( ) ) ; field . add ( nextByte ( ) ) ; return field ; } | Creates a bit field for the MPEG frame header . |
37,603 | private static void skipStream ( InputStream in , long count ) throws IOException { long size = count ; long skipped = 0 ; while ( size > 0 && skipped >= 0 ) { skipped = in . skip ( size ) ; if ( skipped != - 1 ) { size -= skipped ; } } } | Skips the given number of bytes from the specified input stream . |
37,604 | private static int calculateBitRate ( int mpegVer , int layer , int code ) { int [ ] arr = null ; if ( mpegVer == AudioFrame . MPEG_V1 ) { switch ( layer ) { case AudioFrame . LAYER_1 : arr = BIT_RATE_MPEG1_L1 ; break ; case AudioFrame . LAYER_2 : arr = BIT_RATE_MPEG1_L2 ; break ; case AudioFrame . LAYER_3 : arr = BIT_RATE_MPEG1_L3 ; break ; } } else { if ( layer == AudioFrame . LAYER_1 ) { arr = BIT_RATE_MPEG2_L1 ; } else { arr = BIT_RATE_MPEG2_L2 ; } } return arr [ code ] ; } | Calculates the bit rate based on the given parameters . |
37,605 | private static int calculateFrameLength ( int layer , int bitRate , int sampleRate , int padding ) { if ( layer == AudioFrame . LAYER_1 ) { return ( 12 * bitRate / sampleRate + padding ) * 4 ; } else { return 144 * bitRate / sampleRate + padding ; } } | Calculates the length of an MPEG frame based on the given parameters . |
37,606 | private static float calculateDuration ( int layer , int sampleRate ) { int sampleCount = ( layer == AudioFrame . LAYER_1 ) ? SAMPLE_COUNT_L1 : SAMPLE_COUNT_L2 ; return ( 1000.0f / sampleRate ) * sampleCount ; } | Calculates the duration of a MPEG frame based on the given parameters . |
37,607 | private static int [ ] [ ] createSampleRateTable ( ) { int [ ] [ ] arr = new int [ 4 ] [ ] ; arr [ AudioFrame . MPEG_V1 ] = SAMPLE_RATE_MPEG1 ; arr [ AudioFrame . MPEG_V2 ] = SAMPLE_RATE_MPEG2 ; arr [ AudioFrame . MPEG_V2_5 ] = SAMPLE_RATE_MPEG2_5 ; return arr ; } | Creates the complete array for the sample rate mapping . |
37,608 | public void write ( IoBuffer buffer ) { buffer . put ( signature ) ; buffer . put ( version ) ; buffer . put ( ( byte ) ( FLV_HEADER_FLAG_HAS_AUDIO * ( flagAudio ? 1 : 0 ) + FLV_HEADER_FLAG_HAS_VIDEO * ( flagVideo ? 1 : 0 ) ) ) ; buffer . putInt ( 9 ) ; buffer . putInt ( 0 ) ; buffer . flip ( ) ; } | Writes the FLVHeader to IoBuffer . |
37,609 | public byte readDataType ( ) { log . trace ( "readDataType - amf3_mode: {}" , amf3_mode ) ; byte coreType = AMF3 . TYPE_UNDEFINED ; if ( buf != null ) { currentDataType = buf . get ( ) ; log . debug ( "Current data type: {}" , currentDataType ) ; switch ( currentDataType ) { case AMF . TYPE_AMF3_OBJECT : log . trace ( "Got AMF3 object indicator" ) ; amf3_mode = 1 ; currentDataType = buf . get ( ) ; break ; case AMF3 . TYPE_VECTOR_INT : case AMF3 . TYPE_VECTOR_UINT : case AMF3 . TYPE_VECTOR_NUMBER : case AMF3 . TYPE_VECTOR_OBJECT : log . trace ( "Assuming Vector type" ) ; amf3_mode = 1 ; break ; } if ( amf3_mode == 0 ) { switch ( currentDataType ) { case AMF . TYPE_NULL : case AMF . TYPE_UNDEFINED : return DataTypes . CORE_NULL ; case AMF . TYPE_NUMBER : return DataTypes . CORE_NUMBER ; case AMF . TYPE_BOOLEAN : return DataTypes . CORE_BOOLEAN ; case AMF . TYPE_STRING : case AMF . TYPE_LONG_STRING : return DataTypes . CORE_STRING ; case AMF . TYPE_CLASS_OBJECT : case AMF . TYPE_OBJECT : return DataTypes . CORE_OBJECT ; case AMF . TYPE_MIXED_ARRAY : return DataTypes . CORE_MAP ; case AMF . TYPE_ARRAY : return DataTypes . CORE_ARRAY ; case AMF . TYPE_DATE : return DataTypes . CORE_DATE ; case AMF . TYPE_XML : return DataTypes . CORE_XML ; case AMF . TYPE_REFERENCE : return DataTypes . OPT_REFERENCE ; } } log . debug ( "Current data type (after amf checks): {}" , currentDataType ) ; switch ( currentDataType ) { case AMF3 . TYPE_UNDEFINED : case AMF3 . TYPE_NULL : coreType = DataTypes . CORE_NULL ; break ; case AMF3 . TYPE_INTEGER : case AMF3 . TYPE_NUMBER : coreType = DataTypes . CORE_NUMBER ; break ; case AMF3 . TYPE_BOOLEAN_TRUE : case AMF3 . TYPE_BOOLEAN_FALSE : coreType = DataTypes . CORE_BOOLEAN ; break ; case AMF3 . TYPE_STRING : coreType = DataTypes . CORE_STRING ; break ; case AMF3 . TYPE_XML : case AMF3 . TYPE_XML_DOCUMENT : coreType = DataTypes . CORE_XML ; break ; case AMF3 . TYPE_OBJECT : coreType = DataTypes . CORE_OBJECT ; break ; case AMF3 . TYPE_ARRAY : coreType = DataTypes . CORE_ARRAY ; break ; case AMF3 . TYPE_DATE : coreType = DataTypes . CORE_DATE ; break ; case AMF3 . TYPE_BYTEARRAY : coreType = DataTypes . CORE_BYTEARRAY ; break ; case AMF3 . TYPE_VECTOR_INT : coreType = DataTypes . CORE_VECTOR_INT ; break ; case AMF3 . TYPE_VECTOR_UINT : coreType = DataTypes . CORE_VECTOR_UINT ; break ; case AMF3 . TYPE_VECTOR_NUMBER : coreType = DataTypes . CORE_VECTOR_NUMBER ; break ; case AMF3 . TYPE_VECTOR_OBJECT : coreType = DataTypes . CORE_VECTOR_OBJECT ; break ; default : log . info ( "Unknown datatype: {}" , currentDataType ) ; coreType = DataTypes . CORE_SKIP ; break ; } log . debug ( "Core type: {}" , coreType ) ; } else { log . error ( "Why is buf null?" ) ; } return coreType ; } | Reads the data type |
37,610 | public Number readNumber ( ) { if ( buf . hasRemaining ( ) ) { int remaining = buf . remaining ( ) ; if ( log . isTraceEnabled ( ) ) { log . trace ( "Remaining bytes for Number: {}" , remaining ) ; } Number v ; if ( currentDataType == AMF3 . TYPE_NUMBER ) { if ( remaining >= 8 ) { v = buf . getDouble ( ) ; } else { v = buf . getInt ( ) ; } } else { v = readInteger ( ) ; } if ( log . isTraceEnabled ( ) ) { log . trace ( "readNumber - value: {}" , v ) ; } return v ; } else { log . warn ( "No remaining bytes for buffer readNumber" ) ; } return null ; } | Reads a Number |
37,611 | public String readString ( int length ) { log . debug ( "readString - length: {}" , length ) ; int limit = buf . limit ( ) ; final ByteBuffer strBuf = buf . buf ( ) ; strBuf . limit ( strBuf . position ( ) + length ) ; final String string = AMF . CHARSET . decode ( strBuf ) . toString ( ) ; log . debug ( "String: {}" , string ) ; buf . limit ( limit ) ; byte b = buf . get ( ) ; if ( b != 0 ) { buf . position ( buf . position ( ) - 1 ) ; } return string ; } | Reads a string of a set length . This does not use the string reference table . |
37,612 | public ByteArray readByteArray ( ) { int type = readInteger ( ) ; if ( ( type & 1 ) == 0 ) { return ( ByteArray ) getReference ( type >> 1 ) ; } type >>= 1 ; ByteArray result = new ByteArray ( buf , type ) ; storeReference ( result ) ; return result ; } | Read ByteArray object . |
37,613 | @ SuppressWarnings ( "unchecked" ) public Vector < Integer > readVectorInt ( ) { log . debug ( "readVectorInt" ) ; int type = readInteger ( ) ; if ( ( type & 1 ) == 0 ) { return ( Vector < Integer > ) getReference ( type >> 1 ) ; } int len = type >> 1 ; Vector < Integer > array = new Vector < Integer > ( len ) ; storeReference ( array ) ; @ SuppressWarnings ( "unused" ) int ref2 = readInteger ( ) ; for ( int j = 0 ; j < len ; ++ j ) { array . add ( buf . getInt ( ) ) ; } return array ; } | Read Vector< ; Integer> ; object . |
37,614 | @ SuppressWarnings ( "unchecked" ) public Vector < Long > readVectorUInt ( ) { log . debug ( "readVectorUInt" ) ; int type = readInteger ( ) ; if ( ( type & 1 ) == 0 ) { return ( Vector < Long > ) getReference ( type >> 1 ) ; } int len = type >> 1 ; Vector < Long > array = new Vector < Long > ( len ) ; storeReference ( array ) ; @ SuppressWarnings ( "unused" ) int ref2 = readInteger ( ) ; for ( int j = 0 ; j < len ; ++ j ) { long value = ( buf . get ( ) & 0xff ) << 24L ; value += ( buf . get ( ) & 0xff ) << 16L ; value += ( buf . get ( ) & 0xff ) << 8L ; value += ( buf . get ( ) & 0xff ) ; array . add ( value ) ; } return array ; } | Read Vector< ; uint> ; object . |
37,615 | @ SuppressWarnings ( "unchecked" ) public Vector < Double > readVectorNumber ( ) { log . debug ( "readVectorNumber" ) ; int type = readInteger ( ) ; log . debug ( "Type: {}" , type ) ; if ( ( type & 1 ) == 0 ) { return ( Vector < Double > ) getReference ( type >> 1 ) ; } int len = type >> 1 ; log . debug ( "Length: {}" , len ) ; Vector < Double > array = new Vector < Double > ( len ) ; storeReference ( array ) ; int ref2 = readInteger ( ) ; log . debug ( "Ref2: {}" , ref2 ) ; for ( int j = 0 ; j < len ; ++ j ) { Double d = buf . getDouble ( ) ; log . debug ( "Double: {}" , d ) ; array . add ( d ) ; } return array ; } | Read Vector< ; Number> ; object . |
37,616 | @ SuppressWarnings ( "unchecked" ) public Vector < Object > readVectorObject ( ) { log . debug ( "readVectorObject" ) ; int type = readInteger ( ) ; log . debug ( "Type: {}" , type ) ; if ( ( type & 1 ) == 0 ) { return ( Vector < Object > ) getReference ( type >> 1 ) ; } int len = type >> 1 ; log . debug ( "Length: {}" , len ) ; Vector < Object > array = new Vector < Object > ( len ) ; storeReference ( array ) ; int ref2 = readInteger ( ) ; log . debug ( "Ref2: {}" , ref2 ) ; buf . skip ( 1 ) ; Object object = null ; for ( int j = 0 ; j < len ; ++ j ) { byte objectType = buf . get ( ) ; log . debug ( "Object type: {}" , objectType ) ; switch ( objectType ) { case AMF3 . TYPE_UNDEFINED : case AMF3 . TYPE_NULL : object = null ; break ; case AMF3 . TYPE_STRING : object = readString ( ) ; break ; case AMF3 . TYPE_NUMBER : object = readNumber ( ) ; break ; case AMF3 . TYPE_INTEGER : object = readInteger ( ) ; break ; case AMF3 . TYPE_BYTEARRAY : object = readByteArray ( ) ; break ; case AMF3 . TYPE_VECTOR_INT : object = readVectorInt ( ) ; break ; case AMF3 . TYPE_VECTOR_UINT : object = readVectorUInt ( ) ; break ; case AMF3 . TYPE_VECTOR_NUMBER : object = readVectorNumber ( ) ; break ; case AMF3 . TYPE_VECTOR_OBJECT : object = readVectorObject ( ) ; break ; default : object = readObject ( ) ; } array . add ( object ) ; } log . debug ( "Vector: {}" , array ) ; return array ; } | Read Vector< ; Object> ; object . |
37,617 | private int readInteger ( ) { int b = buf . get ( ) ; if ( buf . hasRemaining ( ) ) { int n = 0 ; int result = 0 ; while ( ( b & 0x80 ) != 0 && n < 3 ) { result <<= 7 ; result |= ( b & 0x7f ) ; b = buf . get ( ) ; n ++ ; } if ( n < 3 ) { result <<= 7 ; result |= b ; } else { result <<= 8 ; result |= b & 0x0ff ; if ( ( result & 0x10000000 ) != 0 ) { result |= 0xe0000000 ; } } return result ; } return b ; } | Parser of AMF3 compressed integer data type |
37,618 | @ SuppressWarnings ( "unused" ) private int readAMF3IntegerNew ( ) { int b = buf . get ( ) & 0xFF ; if ( b < 128 ) { return b ; } int value = ( b & 0x7F ) << 7 ; b = buf . get ( ) & 0xFF ; if ( b < 128 ) { return ( value | b ) ; } value = ( value | b & 0x7F ) << 7 ; b = buf . get ( ) & 0xFF ; if ( b < 128 ) { return ( value | b ) ; } value = ( value | b & 0x7F ) << 8 ; b = buf . get ( ) & 0xFF ; return ( value | b ) ; } | Read UInt29 style |
37,619 | public void process ( InputStream input ) throws IOException , ConverterException { while ( 0 != input . available ( ) ) { Tag tag = ParserUtils . parseTag ( input ) ; TagHandler handler = getHandler ( tag ) ; if ( null == handler ) { skipHandler . handle ( tag , input ) ; } else { handler . handle ( tag , input ) ; } } } | Method to process the input stream given will stop as soon as input stream will be empty |
37,620 | public final static void writeReverseInt ( IoBuffer out , int value ) { out . putInt ( ( int ) ( ( value & 0xFF ) << 24 | ( ( value >> 8 ) & 0x00FF ) << 16 | ( ( value >>> 16 ) & 0x000000FF ) << 8 | ( ( value >>> 24 ) & 0x000000FF ) ) ) ; } | Writes integer in reverse order |
37,621 | public final static void writeMediumInt ( ByteBuffer out , int value ) { out . put ( ( byte ) ( ( value >>> 16 ) & 0xff ) ) ; out . put ( ( byte ) ( ( value >>> 8 ) & 0xff ) ) ; out . put ( ( byte ) ( value & 0xff ) ) ; } | Writes medium integer |
37,622 | public final static int readReverseInt ( IoBuffer in ) { int value = in . getInt ( ) ; value = ( ( value & 0xFF ) << 24 | ( ( value >> 8 ) & 0x00FF ) << 16 | ( ( value >>> 16 ) & 0x000000FF ) << 8 | ( ( value >>> 24 ) & 0x000000FF ) ) ; return value ; } | Reads reverse int |
37,623 | public final static void debug ( Logger log , String msg , IoBuffer buf ) { if ( log . isDebugEnabled ( ) ) { log . debug ( msg ) ; log . debug ( "Size: {}" , buf . remaining ( ) ) ; log . debug ( "Data:\n{}" , HexDump . formatHexDump ( buf . getHexDump ( ) ) ) ; log . debug ( "\n{}\n" , toString ( buf ) ) ; } } | Format debug message |
37,624 | public V put ( T name , V value ) { return item . put ( name , value ) ; } | Change a property of the proxied object . |
37,625 | public static String parseString ( InputStream inputStream , final int size ) throws IOException { if ( 0 == size ) { return "" ; } byte [ ] buffer = new byte [ size ] ; int numberOfReadsBytes = inputStream . read ( buffer , 0 , size ) ; assert numberOfReadsBytes == size ; return new String ( buffer , "UTF-8" ) ; } | method used to parse string |
37,626 | public static double parseFloat ( InputStream inputStream , final int size ) throws IOException { byte [ ] buffer = new byte [ size ] ; int numberOfReadsBytes = inputStream . read ( buffer , 0 , size ) ; assert numberOfReadsBytes == size ; ByteBuffer byteBuffer = ByteBuffer . wrap ( buffer ) . order ( ByteOrder . BIG_ENDIAN ) ; if ( 8 == size ) { return byteBuffer . getDouble ( ) ; } return byteBuffer . getFloat ( ) ; } | method used to parse float and double |
37,627 | public static byte [ ] parseBinary ( InputStream inputStream , final int size ) throws IOException { byte value [ ] = new byte [ size ] ; int i = value . length ; while ( i != 0 ) { i -= inputStream . read ( value , value . length - i , i ) ; } return value ; } | method to parse byte array |
37,628 | public static byte [ ] getBytes ( long val , long size ) { byte [ ] res = new byte [ ( int ) size ] ; long bv = val ; for ( int i = ( int ) size - 1 ; i >= 0 ; -- i ) { res [ i ] = ( byte ) ( bv & 0xFF ) ; bv >>= BIT_IN_BYTE ; } return res ; } | method to encode long as byte array of given size |
37,629 | public static void skip ( long size , InputStream input ) throws IOException { while ( size > 0 ) { size -= input . skip ( size ) ; } } | method to skip given amount of bytes in stream |
37,630 | public static void writeMediumInt ( IoBuffer out , int value ) { byte [ ] bytes = new byte [ 3 ] ; bytes [ 0 ] = ( byte ) ( ( value >>> 16 ) & 0x000000FF ) ; bytes [ 1 ] = ( byte ) ( ( value >>> 8 ) & 0x000000FF ) ; bytes [ 2 ] = ( byte ) ( value & 0x00FF ) ; out . put ( bytes ) ; } | Writes a Medium Int to the output buffer |
37,631 | public static int readUnsignedMediumInt ( IoBuffer in ) { byte [ ] bytes = new byte [ 3 ] ; in . get ( bytes ) ; int val = 0 ; val += ( bytes [ 0 ] & 0xFF ) * 256 * 256 ; val += ( bytes [ 1 ] & 0xFF ) * 256 ; val += ( bytes [ 2 ] & 0xFF ) ; return val ; } | Reads an unsigned Medium Int from the in buffer |
37,632 | public static int readMediumInt ( IoBuffer in ) { byte [ ] bytes = new byte [ 3 ] ; in . get ( bytes ) ; int val = 0 ; val += bytes [ 0 ] * 256 * 256 ; val += bytes [ 1 ] * 256 ; val += bytes [ 2 ] ; if ( val < 0 ) { val += 256 ; } return val ; } | Reads a Medium Int to the in buffer |
37,633 | public final static int put ( IoBuffer out , IoBuffer in , int numBytesMax ) { if ( log . isTraceEnabled ( ) ) { log . trace ( "Put\nin buffer: {}\nout buffer: {}\nmax bytes: {}" , new Object [ ] { out , in , numBytesMax } ) ; } int numBytesRead = 0 ; if ( in != null ) { int limit = Math . min ( in . limit ( ) , numBytesMax ) ; byte [ ] inBuf = new byte [ limit ] ; log . trace ( "Bulk get size: {}" , limit ) ; in . get ( inBuf ) ; byte [ ] outBuf = consumeBytes ( inBuf , numBytesMax ) ; out . put ( outBuf ) ; numBytesRead = outBuf . length ; log . trace ( "In pos: {}" , in . position ( ) ) ; } log . trace ( "Bytes put: {}" , numBytesRead ) ; return numBytesRead ; } | Puts an input buffer in an output buffer and returns number of bytes written . |
37,634 | public final static byte [ ] consumeBytes ( byte [ ] in , int numBytesMax ) { int limit = Math . min ( in . length , numBytesMax ) ; byte [ ] out = new byte [ limit ] ; System . arraycopy ( in , 0 , out , 0 , limit ) ; return out ; } | Consumes bytes from an input buffer and returns them in an output buffer . |
37,635 | protected void prepareIO ( ) { Input input = new Input ( data ) ; input . enforceAMF3 ( ) ; dataInput = new DataInput ( input ) ; Output output = new Output ( data ) ; output . enforceAMF3 ( ) ; dataOutput = new DataOutput ( output ) ; } | Create internal objects used for reading and writing . |
37,636 | public void compress ( ) { IoBuffer tmp = IoBuffer . allocate ( 0 ) ; tmp . setAutoExpand ( true ) ; byte [ ] tmpData = new byte [ data . limit ( ) ] ; data . position ( 0 ) ; data . get ( tmpData ) ; try ( DeflaterOutputStream deflater = new DeflaterOutputStream ( tmp . asOutputStream ( ) , new Deflater ( Deflater . BEST_COMPRESSION ) ) ) { deflater . write ( tmpData ) ; deflater . finish ( ) ; } catch ( IOException e ) { tmp . free ( ) ; throw new RuntimeException ( "could not compress data" , e ) ; } data . free ( ) ; data = tmp ; data . flip ( ) ; prepareIO ( ) ; } | Compress contents using zlib . |
37,637 | public void uncompress ( ) { data . position ( 0 ) ; byte [ ] buffer = new byte [ 8192 ] ; IoBuffer tmp = IoBuffer . allocate ( 0 ) ; tmp . setAutoExpand ( true ) ; try ( InflaterInputStream inflater = new InflaterInputStream ( data . asInputStream ( ) ) ) { while ( inflater . available ( ) > 0 ) { int decompressed = inflater . read ( buffer ) ; if ( decompressed <= 0 ) { break ; } tmp . put ( buffer , 0 , decompressed ) ; } } catch ( IOException e ) { tmp . free ( ) ; throw new RuntimeException ( "could not uncompress data" , e ) ; } data . free ( ) ; data = tmp ; data . flip ( ) ; prepareIO ( ) ; } | Decompress contents using zlib . |
37,638 | @ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public static < T > T deserialize ( Input in , Type target ) { if ( BLACK_LIST == null ) { try { loadBlackList ( ) ; } catch ( IOException e ) { throw new RuntimeException ( "Failed to init black-list" ) ; } } byte type = in . readDataType ( ) ; if ( log . isTraceEnabled ( ) ) { log . trace ( "Type: {} target: {}" , type , ( target != null ? target . toString ( ) : "Target not specified" ) ) ; } else if ( log . isDebugEnabled ( ) ) { log . debug ( "Datatype: {}" , DataTypes . toStringValue ( type ) ) ; } Object result = null ; switch ( type ) { case DataTypes . CORE_NULL : result = in . readNull ( ) ; break ; case DataTypes . CORE_BOOLEAN : result = in . readBoolean ( ) ; break ; case DataTypes . CORE_NUMBER : result = in . readNumber ( ) ; break ; case DataTypes . CORE_STRING : try { if ( target != null && ( ( Class ) target ) . isEnum ( ) ) { log . warn ( "Enum target specified" ) ; String name = in . readString ( ) ; result = Enum . valueOf ( ( Class ) target , name ) ; } else { result = in . readString ( ) ; } } catch ( RuntimeException e ) { log . error ( "failed to deserialize {}" , target , e ) ; throw e ; } break ; case DataTypes . CORE_DATE : result = in . readDate ( ) ; break ; case DataTypes . CORE_ARRAY : result = in . readArray ( target ) ; break ; case DataTypes . CORE_MAP : result = in . readMap ( ) ; break ; case DataTypes . CORE_XML : result = in . readXML ( ) ; break ; case DataTypes . CORE_OBJECT : result = in . readObject ( ) ; break ; case DataTypes . CORE_BYTEARRAY : result = in . readByteArray ( ) ; break ; case DataTypes . CORE_VECTOR_INT : result = in . readVectorInt ( ) ; break ; case DataTypes . CORE_VECTOR_UINT : result = in . readVectorUInt ( ) ; break ; case DataTypes . CORE_VECTOR_NUMBER : result = in . readVectorNumber ( ) ; break ; case DataTypes . CORE_VECTOR_OBJECT : result = in . readVectorObject ( ) ; break ; case DataTypes . OPT_REFERENCE : result = in . readReference ( ) ; break ; case DataTypes . CORE_END_OBJECT : log . debug ( "End-of-object detected" ) ; break ; default : result = in . readCustom ( ) ; break ; } return ( T ) result ; } | Deserializes the input parameter and returns an Object which must then be cast to a core data type |
37,639 | public static boolean classAllowed ( String className ) { for ( String name : BLACK_LIST ) { if ( className . startsWith ( name ) ) { return false ; } } return true ; } | Checks to see if a given class is blacklisted or not . |
37,640 | private long getRemainingBytes ( ) { if ( in != null ) { if ( ! useLoadBuf ) { return in . remaining ( ) ; } try { if ( channel . isOpen ( ) ) { return channelSize - channel . position ( ) + in . remaining ( ) ; } else { return in . remaining ( ) ; } } catch ( Exception e ) { log . error ( "Error getRemainingBytes" , e ) ; } } return 0 ; } | Get the remaining bytes that could be read from a file or ByteBuffer . |
37,641 | public long getTotalBytes ( ) { if ( ! useLoadBuf ) { return in . capacity ( ) ; } try { return channelSize ; } catch ( Exception e ) { log . error ( "Error getTotalBytes" , e ) ; return 0 ; } } | Get the total readable bytes in a file or ByteBuffer . |
37,642 | private long getCurrentPosition ( ) { long pos ; if ( ! useLoadBuf ) { return in . position ( ) ; } try { if ( in != null ) { pos = ( channel . position ( ) - in . remaining ( ) ) ; } else { pos = channel . position ( ) ; } return pos ; } catch ( Exception e ) { log . error ( "Error getCurrentPosition" , e ) ; return 0 ; } } | Get the current position in a file or ByteBuffer . |
37,643 | private void setCurrentPosition ( long pos ) { if ( pos == Long . MAX_VALUE ) { pos = file . length ( ) ; } if ( ! useLoadBuf ) { in . position ( ( int ) pos ) ; return ; } try { if ( pos >= ( channel . position ( ) - in . limit ( ) ) && pos < channel . position ( ) ) { in . position ( ( int ) ( pos - ( channel . position ( ) - in . limit ( ) ) ) ) ; } else { channel . position ( pos ) ; fillBuffer ( bufferSize , true ) ; } } catch ( Exception e ) { log . error ( "Error setCurrentPosition" , e ) ; } } | Modifies current position . |
37,644 | private void fillBuffer ( long amount , boolean reload ) { try { if ( amount > bufferSize ) { amount = bufferSize ; } log . debug ( "Buffering amount: {} buffer size: {}" , amount , bufferSize ) ; if ( channelSize - channel . position ( ) < amount ) { amount = channelSize - channel . position ( ) ; } if ( in == null ) { switch ( bufferType ) { case HEAP : in = IoBuffer . allocate ( bufferSize , false ) ; break ; case DIRECT : in = IoBuffer . allocate ( bufferSize , true ) ; break ; default : in = IoBuffer . allocate ( bufferSize ) ; } channel . read ( in . buf ( ) ) ; in . flip ( ) ; useLoadBuf = true ; } if ( ! useLoadBuf ) { return ; } if ( reload || in . remaining ( ) < amount ) { if ( ! reload ) { in . compact ( ) ; } else { in . clear ( ) ; } channel . read ( in . buf ( ) ) ; in . flip ( ) ; } } catch ( Exception e ) { log . error ( "Error fillBuffer" , e ) ; } } | Load enough bytes from channel to buffer . After the loading process the caller can make sure the amount in buffer is of size amount if we haven t reached the end of channel . |
37,645 | public static void setBufferType ( String bufferType ) { int bufferTypeHash = bufferType . hashCode ( ) ; switch ( bufferTypeHash ) { case 3198444 : FLVReader . bufferType = BufferType . HEAP ; break ; case - 1331586071 : FLVReader . bufferType = BufferType . DIRECT ; break ; case 3005871 : default : FLVReader . bufferType = BufferType . AUTO ; } } | Setter for buffer type . |
37,646 | private ITag readTagHeader ( ) throws UnsupportedDataTypeException { fillBuffer ( 15 ) ; int previousTagSize = in . getInt ( ) ; byte dataType = in . get ( ) ; if ( log . isTraceEnabled ( ) ) { log . trace ( "Bits: {}" , Integer . toBinaryString ( dataType ) ) ; } dataType = ( byte ) ( dataType & 31 ) ; byte filter = ( byte ) ( ( dataType & 63 ) >> 5 ) ; byte reserved = ( byte ) ( ( dataType & 127 ) >> 6 ) ; log . debug ( "Reserved: {}, Filter: {}, Datatype: {}" , reserved , filter , dataType ) ; switch ( dataType ) { case 8 : log . debug ( "Found audio" ) ; break ; case 9 : log . debug ( "Found video" ) ; break ; case 15 : case 18 : log . debug ( "Found meta/script data" ) ; break ; default : log . debug ( "Invalid data type detected ({}), reading ahead\n current position: {} limit: {}" , dataType , in . position ( ) , in . limit ( ) ) ; throw new UnsupportedDataTypeException ( "Invalid data type detected (" + dataType + ")" ) ; } int bodySize = IOUtils . readUnsignedMediumInt ( in ) ; int timestamp = IOUtils . readExtendedMediumInt ( in ) ; int streamId = IOUtils . readUnsignedMediumInt ( in ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Data type: {} timestamp: {} stream id: {} body size: {} previous tag size: {}" , new Object [ ] { dataType , timestamp , streamId , bodySize , previousTagSize } ) ; } return new Tag ( dataType , timestamp , bodySize , null , previousTagSize ) ; } | Read only header part of a tag . |
37,647 | public static int getDuration ( File flvFile ) { int duration = 0 ; RandomAccessFile flv = null ; try { flv = new RandomAccessFile ( flvFile , "r" ) ; long flvLength = Math . max ( flvFile . length ( ) , flv . length ( ) ) ; log . debug ( "File length: {}" , flvLength ) ; if ( flvLength > 13 ) { flv . seek ( flvLength - 4 ) ; int lastTagSize = flv . readInt ( ) ; log . debug ( "Last tag size: {}" , lastTagSize ) ; if ( lastTagSize > 0 && ( lastTagSize < flvLength ) ) { flv . seek ( flvLength - lastTagSize ) ; duration = flv . readInt ( ) ; duration = ( duration >>> 8 ) | ( ( duration & 0x000000ff ) << 24 ) ; } else { flv . seek ( 13 ) ; byte tagType = flv . readByte ( ) ; if ( tagType == ITag . TYPE_METADATA ) { ByteBuffer buf = ByteBuffer . allocate ( 3 ) ; flv . getChannel ( ) . read ( buf ) ; int bodySize = IOUtils . readMediumInt ( buf ) ; log . debug ( "Metadata body size: {}" , bodySize ) ; flv . skipBytes ( 4 ) ; flv . skipBytes ( 3 ) ; buf . clear ( ) ; buf = ByteBuffer . allocate ( bodySize ) ; flv . getChannel ( ) . read ( buf ) ; IoBuffer ioBuf = IoBuffer . wrap ( buf ) ; Input input = new Input ( ioBuf ) ; String metaType = Deserializer . deserialize ( input , String . class ) ; log . debug ( "Metadata type: {}" , metaType ) ; Map < String , ? > meta = Deserializer . deserialize ( input , Map . class ) ; Object tmp = meta . get ( "duration" ) ; if ( tmp != null ) { if ( tmp instanceof Double ) { duration = ( ( Double ) tmp ) . intValue ( ) ; } else { duration = Integer . valueOf ( ( String ) tmp ) ; } } input = null ; meta . clear ( ) ; meta = null ; ioBuf . clear ( ) ; ioBuf . free ( ) ; ioBuf = null ; } } } } catch ( IOException e ) { log . warn ( "Exception getting file duration" , e ) ; } finally { try { if ( flv != null ) { flv . close ( ) ; } } catch ( IOException e ) { } flv = null ; } return duration ; } | Returns the last tag s timestamp as the files duration . |
37,648 | public int compareTo ( MP4Frame that ) { int ret = 0 ; if ( this . time > that . getTime ( ) ) { ret = 1 ; } else if ( this . time < that . getTime ( ) ) { ret = - 1 ; } else if ( Double . doubleToLongBits ( time ) == Double . doubleToLongBits ( that . getTime ( ) ) && this . offset > that . getOffset ( ) ) { ret = 1 ; } else if ( Double . doubleToLongBits ( time ) == Double . doubleToLongBits ( that . getTime ( ) ) && this . offset < that . getOffset ( ) ) { ret = - 1 ; } return ret ; } | The frames are expected to be sorted by their timestamp |
37,649 | private void writePrimitiveByteArray ( byte [ ] bytes ) { writeAMF3 ( ) ; this . buf . put ( AMF3 . TYPE_BYTEARRAY ) ; if ( hasReference ( bytes ) ) { putInteger ( getReferenceId ( bytes ) << 1 ) ; return ; } storeReference ( bytes ) ; int length = bytes . length ; putInteger ( length << 1 | 0x1 ) ; this . buf . put ( bytes ) ; } | Use the specialized BYTEARRAY type . |
37,650 | public void writeVectorInt ( Vector < Integer > vector ) { log . debug ( "writeVectorInt: {}" , vector ) ; writeAMF3 ( ) ; buf . put ( AMF3 . TYPE_VECTOR_INT ) ; if ( hasReference ( vector ) ) { putInteger ( getReferenceId ( vector ) << 1 ) ; return ; } storeReference ( vector ) ; putInteger ( vector . size ( ) << 1 | 1 ) ; buf . put ( ( byte ) 0x00 ) ; for ( Integer v : vector ) { buf . putInt ( v ) ; } if ( log . isDebugEnabled ( ) ) { int pos = buf . position ( ) ; buf . position ( 0 ) ; StringBuilder sb = new StringBuilder ( ) ; HexDump . dumpHex ( sb , buf . array ( ) ) ; log . debug ( "\n{}" , sb ) ; buf . position ( pos ) ; } } | Write a Vector< ; int> ; . |
37,651 | public void writeVectorUInt ( Vector < Long > vector ) { log . debug ( "writeVectorUInt: {}" , vector ) ; writeAMF3 ( ) ; buf . put ( AMF3 . TYPE_VECTOR_UINT ) ; if ( hasReference ( vector ) ) { putInteger ( getReferenceId ( vector ) << 1 ) ; return ; } storeReference ( vector ) ; putInteger ( vector . size ( ) << 1 | 1 ) ; buf . put ( ( byte ) 0x00 ) ; for ( Long v : vector ) { UnsignedInt uint = new UnsignedInt ( v ) ; byte [ ] arr = uint . getBytes ( ) ; buf . put ( arr ) ; } } | Write a Vector< ; uint> ; . |
37,652 | public void writeVectorNumber ( Vector < Double > vector ) { log . debug ( "writeVectorNumber: {}" , vector ) ; buf . put ( AMF3 . TYPE_VECTOR_NUMBER ) ; if ( hasReference ( vector ) ) { putInteger ( getReferenceId ( vector ) << 1 ) ; return ; } storeReference ( vector ) ; putInteger ( vector . size ( ) << 1 | 1 ) ; putInteger ( 0 ) ; buf . put ( ( byte ) 0x00 ) ; for ( Double v : vector ) { buf . putDouble ( v ) ; } } | Write a Vector< ; Number> ; . |
37,653 | public void writeVectorObject ( Vector < Object > vector ) { log . debug ( "writeVectorObject: {}" , vector ) ; buf . put ( AMF3 . TYPE_VECTOR_OBJECT ) ; if ( hasReference ( vector ) ) { putInteger ( getReferenceId ( vector ) << 1 ) ; return ; } storeReference ( vector ) ; putInteger ( vector . size ( ) << 1 | 1 ) ; putInteger ( 0 ) ; buf . put ( ( byte ) 0x01 ) ; for ( Object v : vector ) { Serializer . serialize ( this , v ) ; } } | Write a Vector< ; Object> ; . |
37,654 | public void close ( ) throws IOException { if ( fis != null ) { try { fis . close ( ) ; fis = null ; } catch ( Throwable th ) { } } } | Will close all opened resources |
37,655 | void logInfo ( String tag , String msg ) { log ( Log . INFO , tag , msg ) ; } | Log with level info . |
37,656 | public void put ( String key , T object ) { if ( ramMode . equals ( DualCacheRamMode . ENABLE_WITH_REFERENCE ) ) { ramCacheLru . put ( key , object ) ; } String ramSerialized = null ; if ( ramMode . equals ( DualCacheRamMode . ENABLE_WITH_SPECIFIC_SERIALIZER ) ) { ramSerialized = ramSerializer . toString ( object ) ; ramCacheLru . put ( key , ramSerialized ) ; } if ( diskMode . equals ( DualCacheDiskMode . ENABLE_WITH_SPECIFIC_SERIALIZER ) ) { try { dualCacheLock . lockDiskEntryWrite ( key ) ; DiskLruCache . Editor editor = diskLruCache . edit ( key ) ; if ( ramSerializer == diskSerializer ) { editor . set ( 0 , ramSerialized ) ; } else { editor . set ( 0 , diskSerializer . toString ( object ) ) ; } editor . commit ( ) ; } catch ( IOException e ) { logger . logError ( e ) ; } finally { dualCacheLock . unLockDiskEntryWrite ( key ) ; } } } | Put an object in cache . |
37,657 | public T get ( String key ) { Object ramResult = null ; String diskResult = null ; DiskLruCache . Snapshot snapshotObject = null ; boolean isRamSerialized = ramMode . equals ( DualCacheRamMode . ENABLE_WITH_SPECIFIC_SERIALIZER ) ; boolean isRamReferenced = ramMode . equals ( DualCacheRamMode . ENABLE_WITH_REFERENCE ) ; if ( isRamSerialized || isRamReferenced ) { ramResult = ramCacheLru . get ( key ) ; } if ( ramResult == null ) { loggerHelper . logEntryForKeyIsNotInRam ( key ) ; if ( diskMode . equals ( DualCacheDiskMode . ENABLE_WITH_SPECIFIC_SERIALIZER ) ) { try { dualCacheLock . lockDiskEntryWrite ( key ) ; snapshotObject = diskLruCache . get ( key ) ; } catch ( IOException e ) { logger . logError ( e ) ; } finally { dualCacheLock . unLockDiskEntryWrite ( key ) ; } if ( snapshotObject != null ) { loggerHelper . logEntryForKeyIsOnDisk ( key ) ; try { diskResult = snapshotObject . getString ( 0 ) ; } catch ( IOException e ) { logger . logError ( e ) ; } } else { loggerHelper . logEntryForKeyIsNotOnDisk ( key ) ; } } T objectFromStringDisk = null ; if ( diskResult != null ) { objectFromStringDisk = diskSerializer . fromString ( diskResult ) ; if ( ramMode . equals ( DualCacheRamMode . ENABLE_WITH_REFERENCE ) ) { if ( diskMode . equals ( DualCacheDiskMode . ENABLE_WITH_SPECIFIC_SERIALIZER ) ) { ramCacheLru . put ( key , objectFromStringDisk ) ; } } else if ( ramMode . equals ( DualCacheRamMode . ENABLE_WITH_SPECIFIC_SERIALIZER ) ) { if ( diskSerializer == ramSerializer ) { ramCacheLru . put ( key , diskResult ) ; } else { ramCacheLru . put ( key , ramSerializer . toString ( objectFromStringDisk ) ) ; } } return objectFromStringDisk ; } } else { loggerHelper . logEntryForKeyIsInRam ( key ) ; if ( ramMode . equals ( DualCacheRamMode . ENABLE_WITH_REFERENCE ) ) { return ( T ) ramResult ; } else if ( ramMode . equals ( DualCacheRamMode . ENABLE_WITH_SPECIFIC_SERIALIZER ) ) { return ramSerializer . fromString ( ( String ) ramResult ) ; } } return null ; } | Return the object of the corresponding key from the cache . In no object is available return null . |
37,658 | public void delete ( String key ) { if ( ! ramMode . equals ( DualCacheRamMode . DISABLE ) ) { ramCacheLru . remove ( key ) ; } if ( ! diskMode . equals ( DualCacheDiskMode . DISABLE ) ) { try { dualCacheLock . lockDiskEntryWrite ( key ) ; diskLruCache . remove ( key ) ; } catch ( IOException e ) { logger . logError ( e ) ; } finally { dualCacheLock . unLockDiskEntryWrite ( key ) ; } } } | Delete the corresponding object in cache . |
37,659 | public void invalidateDisk ( ) { if ( ! diskMode . equals ( DualCacheDiskMode . DISABLE ) ) { try { dualCacheLock . lockFullDiskWrite ( ) ; diskLruCache . delete ( ) ; openDiskLruCache ( diskCacheFolder ) ; } catch ( IOException e ) { logger . logError ( e ) ; } finally { dualCacheLock . unLockFullDiskWrite ( ) ; } } } | Remove all objects from Disk . |
37,660 | public boolean contains ( String key ) { if ( ! ramMode . equals ( DualCacheRamMode . DISABLE ) && ramCacheLru . snapshot ( ) . containsKey ( key ) ) { return true ; } try { dualCacheLock . lockDiskEntryWrite ( key ) ; if ( ! diskMode . equals ( DualCacheDiskMode . DISABLE ) && diskLruCache . get ( key ) != null ) { return true ; } } catch ( IOException e ) { logger . logError ( e ) ; } finally { dualCacheLock . unLockDiskEntryWrite ( key ) ; } return false ; } | Test if an object is present in cache . |
37,661 | public DualCache < T > build ( ) { if ( ramMode == null ) { throw new IllegalStateException ( "No ram mode set" ) ; } if ( diskMode == null ) { throw new IllegalStateException ( "No disk mode set" ) ; } DualCache < T > cache = new DualCache < > ( appVersion , new Logger ( logEnabled ) , ramMode , ramSerializer , maxRamSizeBytes , sizeOf , diskMode , diskSerializer , maxDiskSizeBytes , diskFolder ) ; boolean isRamDisable = cache . getRAMMode ( ) . equals ( DualCacheRamMode . DISABLE ) ; boolean isDiskDisable = cache . getDiskMode ( ) . equals ( DualCacheDiskMode . DISABLE ) ; if ( isRamDisable && isDiskDisable ) { throw new IllegalStateException ( "The ram cache layer and the disk cache layer are " + "disable. You have to use at least one of those " + "layers." ) ; } return cache ; } | Builder the cache . Exception will be thrown if it can not be created . |
37,662 | public int read ( ) throws IOException { byte [ ] buf = new byte [ 1 ] ; int res = this . read ( buf , 0 , 1 ) ; if ( res != - 1 ) { return 0xFF & buf [ 0 ] ; } return res ; } | Read a byte |
37,663 | public int read ( byte [ ] b , int off , int len ) throws IOException { if ( currentEntry != null ) { if ( currentFileSize == currentEntry . getSize ( ) ) { return - 1 ; } else if ( ( currentEntry . getSize ( ) - currentFileSize ) < len ) { len = ( int ) ( currentEntry . getSize ( ) - currentFileSize ) ; } } int br = super . read ( b , off , len ) ; if ( br != - 1 ) { if ( currentEntry != null ) { currentFileSize += br ; } bytesRead += br ; } return br ; } | Checks if the bytes being read exceed the entry size and adjusts the byte array length . Updates the byte counters |
37,664 | public TarEntry getNextEntry ( ) throws IOException { closeCurrentEntry ( ) ; byte [ ] header = new byte [ TarConstants . HEADER_BLOCK ] ; byte [ ] theader = new byte [ TarConstants . HEADER_BLOCK ] ; int tr = 0 ; while ( tr < TarConstants . HEADER_BLOCK ) { int res = read ( theader , 0 , TarConstants . HEADER_BLOCK - tr ) ; if ( res < 0 ) { break ; } System . arraycopy ( theader , 0 , header , tr , res ) ; tr += res ; } boolean eof = true ; for ( byte b : header ) { if ( b != 0 ) { eof = false ; break ; } } if ( ! eof ) { currentEntry = new TarEntry ( header ) ; } return currentEntry ; } | Returns the next entry in the tar file |
37,665 | protected void skipPad ( ) throws IOException { if ( bytesRead > 0 ) { int extra = ( int ) ( bytesRead % TarConstants . DATA_BLOCK ) ; if ( extra > 0 ) { long bs = 0 ; while ( bs < TarConstants . DATA_BLOCK - extra ) { long res = skip ( TarConstants . DATA_BLOCK - extra - bs ) ; bs += res ; } } } } | Skips the pad at the end of each tar entry file content |
37,666 | public static int getLongOctalBytes ( long value , byte [ ] buf , int offset , int length ) { byte [ ] temp = new byte [ length + 1 ] ; getOctalBytes ( value , temp , 0 , length + 1 ) ; System . arraycopy ( temp , 0 , buf , offset , length ) ; return offset + length ; } | Write an octal long integer to a header buffer . |
37,667 | public void write ( int b ) throws IOException { out . write ( b ) ; bytesWritten += 1 ; if ( currentEntry != null ) { currentFileSize += 1 ; } } | Writes a byte to the stream and updates byte counters |
37,668 | public void write ( byte [ ] b , int off , int len ) throws IOException { if ( currentEntry != null && ! currentEntry . isDirectory ( ) ) { if ( currentEntry . getSize ( ) < currentFileSize + len ) { throw new IOException ( "The current entry[" + currentEntry . getName ( ) + "] size[" + currentEntry . getSize ( ) + "] is smaller than the bytes[" + ( currentFileSize + len ) + "] being written." ) ; } } out . write ( b , off , len ) ; bytesWritten += len ; if ( currentEntry != null ) { currentFileSize += len ; } } | Checks if the bytes being written exceed the current entry size . |
37,669 | public void putNextEntry ( TarEntry entry ) throws IOException { closeCurrentEntry ( ) ; byte [ ] header = new byte [ TarConstants . HEADER_BLOCK ] ; entry . writeEntryHeader ( header ) ; write ( header ) ; currentEntry = entry ; } | Writes the next tar entry header on the stream |
37,670 | protected void pad ( ) throws IOException { if ( bytesWritten > 0 ) { int extra = ( int ) ( bytesWritten % TarConstants . DATA_BLOCK ) ; if ( extra > 0 ) { write ( new byte [ TarConstants . DATA_BLOCK - extra ] ) ; } } } | Pads the last content block |
37,671 | @ SuppressWarnings ( "unused" ) public void setIndicatorWidth ( int indicatorWidth ) { mIndicatorWidth = indicatorWidth ; mIndicatorRectangle . set ( getPaddingLeft ( ) , getPaddingTop ( ) , getPaddingLeft ( ) + mIndicatorWidth , getMeasuredHeight ( ) - getPaddingBottom ( ) ) ; requestLayout ( ) ; } | Set indicator width |
37,672 | @ SuppressWarnings ( "unused" ) public void resetView ( ) { if ( mForwardAnimatorSet != null && mForwardAnimatorSet . isRunning ( ) ) { mForwardAnimatorSet . end ( ) ; } if ( mReverseAnimatorSet != null && mReverseAnimatorSet . isRunning ( ) ) { mReverseAnimatorSet . end ( ) ; } if ( mAnimationView != null && mAnimationView . isPlaying ( ) ) { mAnimationView . stopAnimation ( ) ; } if ( mBaseContainer != null ) { mBaseContainer . setVisibility ( VISIBLE ) ; } if ( mAnimationView != null ) { mAnimationView . setAnimated ( false ) ; } if ( mContextView != null ) { mContextView . setVisibility ( GONE ) ; } } | Reset view to initial state |
37,673 | @ SuppressWarnings ( "unused" ) public void showContextView ( ) { if ( ( mForwardAnimatorSet != null && mForwardAnimatorSet . isRunning ( ) ) || ( mAnimationView != null && mAnimationView . isPlaying ( ) ) || ( mReverseAnimatorSet != null && mReverseAnimatorSet . isRunning ( ) ) ) { return ; } if ( mBaseContainer != null ) { mBaseContainer . setVisibility ( GONE ) ; } if ( mAnimationView != null ) { mAnimationView . setAnimated ( true ) ; } if ( mContextView != null ) { mContextView . setVisibility ( VISIBLE ) ; } } | Show context view |
37,674 | @ SuppressWarnings ( "unused" ) public void showBaseView ( ) { if ( ( mForwardAnimatorSet != null && mForwardAnimatorSet . isRunning ( ) ) || ( mAnimationView != null && mAnimationView . isPlaying ( ) ) || ( mReverseAnimatorSet != null && mReverseAnimatorSet . isRunning ( ) ) ) { return ; } if ( mBaseContainer != null ) { mBaseContainer . setVisibility ( VISIBLE ) ; } if ( mAnimationView != null ) { mAnimationView . setAnimated ( false ) ; } if ( mContextView != null ) { mContextView . setVisibility ( GONE ) ; } } | Show base view |
37,675 | public static float normalize ( float val , float minVal , float maxVal ) { if ( val < minVal || val > maxVal ) throw new IllegalArgumentException ( "Value must be between min and max values. [val, min, max]: [" + val + "," + minVal + ", " + maxVal + "]" ) ; return ( val - minVal ) / ( maxVal - minVal ) ; } | Normalize value between minimum and maximum . |
37,676 | public static float enlarge ( float startValue , float endValue , float time ) { if ( startValue > endValue ) throw new IllegalArgumentException ( "Start size can't be larger than end size." ) ; return startValue + ( endValue - startValue ) * time ; } | Enlarge value from startValue to endValue |
37,677 | public static float reduce ( float startValue , float endValue , float time ) { if ( startValue < endValue ) throw new IllegalArgumentException ( "End size can't be larger than start size." ) ; return endValue + ( startValue - endValue ) * ( 1 - time ) ; } | Reduce value from startValue to endValue |
37,678 | public void configureTasks ( ScheduledTaskRegistrar taskRegistrar ) { BugsnagScheduledTaskExceptionHandler bugsnagErrorHandler = new BugsnagScheduledTaskExceptionHandler ( bugsnag ) ; TaskScheduler registrarScheduler = taskRegistrar . getScheduler ( ) ; TaskScheduler taskScheduler = registrarScheduler != null ? registrarScheduler : beanLocator . resolveTaskScheduler ( ) ; if ( taskScheduler != null ) { configureExistingTaskScheduler ( taskScheduler , bugsnagErrorHandler ) ; } else { ScheduledExecutorService executorService = beanLocator . resolveScheduledExecutorService ( ) ; taskScheduler = createNewTaskScheduler ( executorService , bugsnagErrorHandler ) ; taskRegistrar . setScheduler ( taskScheduler ) ; } } | Add bugsnag error handling to a task scheduler |
37,679 | private void populateContextData ( Report report , ILoggingEvent event ) { Map < String , String > propertyMap = event . getMDCPropertyMap ( ) ; if ( propertyMap != null ) { for ( Map . Entry < String , String > entry : propertyMap . entrySet ( ) ) { report . addToTab ( "Context" , entry . getKey ( ) , entry . getValue ( ) ) ; } } } | Adds logging context values to the given report meta data |
37,680 | private Severity calculateSeverity ( ILoggingEvent event ) { if ( event . getLevel ( ) . equals ( Level . ERROR ) ) { return Severity . ERROR ; } else if ( event . getLevel ( ) . equals ( Level . WARN ) ) { return Severity . WARNING ; } return Severity . INFO ; } | Calculates the severity based on the logging event |
37,681 | public void setEndpoint ( String endpoint ) { this . endpoint = endpoint ; if ( bugsnag != null ) { bugsnag . setEndpoints ( endpoint , null ) ; } } | Internal use only Should only be used via the logback . xml file |
37,682 | List < String > split ( String value ) { if ( value == null ) { return Collections . emptyList ( ) ; } String [ ] parts = value . split ( "," , - 1 ) ; return Arrays . asList ( parts ) ; } | Splits the given string on commas |
37,683 | private boolean isExcludedLogger ( String loggerName ) { for ( Pattern excludedLoggerPattern : EXCLUDED_LOGGER_PATTERNS ) { if ( excludedLoggerPattern . matcher ( loggerName ) . matches ( ) ) { return true ; } } return false ; } | Whether or not a logger is excluded from generating Bugsnag reports |
37,684 | public static String getHostnameValue ( ) { if ( ! hostnameInitialised ) { synchronized ( LOCK ) { if ( ! hostnameInitialised ) { hostname = lookupHostname ( ) ; hostnameInitialised = true ; } } } return hostname ; } | Memoises the hostname as lookup can be expensive |
37,685 | protected List < Exception > getExceptions ( ) { List < Exception > exceptions = new ArrayList < Exception > ( ) ; exceptions . add ( exception ) ; Throwable currentThrowable = exception . getThrowable ( ) . getCause ( ) ; while ( currentThrowable != null ) { exceptions . add ( new Exception ( config , currentThrowable ) ) ; currentThrowable = currentThrowable . getCause ( ) ; } return exceptions ; } | Get the exceptions for the report . |
37,686 | public Report addToTab ( String tabName , String key , Object value ) { diagnostics . metaData . addToTab ( tabName , key , value ) ; return this ; } | Add a key value pair to a metadata tab . |
37,687 | public Report setAppInfo ( String key , Object value ) { diagnostics . app . put ( key , value ) ; return this ; } | Add some application info on the report . |
37,688 | public Report setDeviceInfo ( String key , Object value ) { diagnostics . device . put ( key , value ) ; return this ; } | Set device information on the report . |
37,689 | public Report setUser ( String id , String email , String name ) { diagnostics . user . put ( "id" , id ) ; diagnostics . user . put ( "email" , email ) ; diagnostics . user . put ( "name" , name ) ; return this ; } | Helper method to set all the user attributes . |
37,690 | protected void disableSessionDelivery ( ) { bugsnag . setSessionDelivery ( new Delivery ( ) { public void deliver ( Serializer serializer , Object object , Map < String , String > headers ) { } public void close ( ) { } } ) ; } | Prevents sessions from being delivered |
37,691 | protected void flushAllSessions ( ) { try { Field field = bugsnag . getClass ( ) . getDeclaredField ( "sessionTracker" ) ; field . setAccessible ( true ) ; Object sessionTracker = field . get ( bugsnag ) ; field = sessionTracker . getClass ( ) . getDeclaredField ( "enqueuedSessionCounts" ) ; field . setAccessible ( true ) ; Collection sessionCounts = ( Collection ) field . get ( sessionTracker ) ; Method method = sessionTracker . getClass ( ) . getDeclaredMethod ( "flushSessions" , Date . class ) ; method . setAccessible ( true ) ; Calendar calendar = Calendar . getInstance ( ) ; calendar . add ( Calendar . MINUTE , 2 ) ; method . invoke ( sessionTracker , calendar . getTime ( ) ) ; while ( sessionCounts . size ( ) > 0 ) { Thread . sleep ( 1000 ) ; } } catch ( java . lang . Exception ex ) { LOGGER . error ( "failed to flush sessions" , ex ) ; } } | Flushes sessions from the Bugsnag object |
37,692 | public void writeToStream ( OutputStream stream , Object object ) throws SerializationException { try { mapper . writeValue ( stream , object ) ; } catch ( IOException ex ) { throw new SerializationException ( "Exception during serialization" , ex ) ; } } | Write the object to the stream . |
37,693 | public Bugsnag bugsnag ( ) { Bugsnag bugsnag = new Bugsnag ( "YOUR-API-KEY" ) ; bugsnag . setReleaseStage ( "staging" ) ; bugsnag . setAppVersion ( "1.0.1" ) ; bugsnag . addCallback ( new Callback ( ) { public void beforeNotify ( Report report ) { report . addToTab ( "diagnostics" , "timestamp" , new Date ( ) ) ; report . addToTab ( "customer" , "name" , "acme-inc" ) ; report . addToTab ( "customer" , "paying" , true ) ; report . addToTab ( "customer" , "spent" , 1234 ) ; report . setUserName ( "User Name" ) ; report . setUserEmail ( "user@example.com" ) ; report . setUserId ( "12345" ) ; } } ) ; return bugsnag ; } | Define singleton bean bugsnag which can be injected into any Spring managed class with |
37,694 | public void close ( ) { LOGGER . debug ( "Closing connection to Bugsnag" ) ; if ( config . delivery != null ) { config . delivery . close ( ) ; } ExceptionHandler . disable ( this ) ; } | Close the connection to Bugsnag and unlink the exception handler . |
37,695 | public static void addThreadMetaData ( String tabName , String key , Object value ) { THREAD_METADATA . get ( ) . addToTab ( tabName , key , value ) ; } | Add a key value pair to a metadata tab just for this thread . |
37,696 | @ SuppressWarnings ( "checkstyle:emptycatchblock" ) void excludeLoggers ( ) { try { BugsnagAppender . addExcludedLoggerPattern ( "org.apache.catalina.core.ContainerBase." + "\\[Tomcat.*\\][.]\\[.*\\][.]\\[/.*\\][.]\\[.*\\]" ) ; BugsnagAppender . addExcludedLoggerPattern ( "org.eclipse.jetty.server.HttpChannel" ) ; BugsnagAppender . addExcludedLoggerPattern ( "io.undertow.request" ) ; } catch ( NoClassDefFoundError ignored ) { } } | If using Logback stop any configured appender from creating Bugsnag reports for Spring log messages as they effectively duplicate error reports for unhandled exceptions . |
37,697 | protected void onMeasure ( int widthMeasureSpec , int heightMeasureSpec ) { try { int mode = MeasureSpec . getMode ( heightMeasureSpec ) ; if ( mode == MeasureSpec . UNSPECIFIED || mode == MeasureSpec . AT_MOST ) { super . onMeasure ( widthMeasureSpec , heightMeasureSpec ) ; int height = 0 ; for ( int i = 0 ; i < getChildCount ( ) ; i ++ ) { View child = getChildAt ( i ) ; if ( child != null ) { child . measure ( widthMeasureSpec , MeasureSpec . makeMeasureSpec ( 0 , MeasureSpec . UNSPECIFIED ) ) ; int h = child . getMeasuredHeight ( ) ; if ( h > height ) { height = h ; } } } heightMeasureSpec = MeasureSpec . makeMeasureSpec ( height , MeasureSpec . EXACTLY ) ; } super . onMeasure ( widthMeasureSpec , heightMeasureSpec ) ; } catch ( RuntimeException e ) { Log . e ( TAG , "Exception during WrapContentViewPager onMeasure " + e . toString ( ) ) ; } } | Allows to redraw the view size to wrap the content of the bigger child . |
37,698 | private void setWidth ( int width ) { contentParams . width = options . fullScreenPeek ( ) ? screenWidth : width ; content . setLayoutParams ( contentParams ) ; } | Sets the width of the view in PX . |
37,699 | private void setHeight ( int height ) { contentParams . height = options . fullScreenPeek ( ) ? screenHeight : height ; content . setLayoutParams ( contentParams ) ; } | Sets the height of the view in PX . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.