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_...
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 ( ...
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 =...
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: {}" ,...
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 ) ; storeR...
Read Vector&lt ; Integer&gt ; 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 (...
Read Vector&lt ; uint&gt ; 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: {}"...
Read Vector&lt ; Number&gt ; 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: {}"...
Read Vector&lt ; Object&gt ; 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 ( ( ...
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 ( ...
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_E...
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 ( ) , numByt...
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 . B...
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 = i...
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 . isTraceEnab...
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...
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 . posit...
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 ) ...
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 . buffer...
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 = (...
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 ...
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 ;...
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 ( ...
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 | ...
Write a Vector&lt ; int&gt ; .
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 | ...
Write a Vector&lt ; uint&gt ; .
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 ) ; pu...
Write a Vector&lt ; Number&gt ; .
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 ) ; pu...
Write a Vector&lt ; Object&gt ; .
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 ) ; r...
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 ) ;...
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 ( ...
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 ) { re...
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 , maxRam...
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 = s...
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 - ...
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 ( ) + "] ...
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 && mAnimatio...
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 != nu...
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 ...
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 ? registr...
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...
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 ( tru...
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 ( ) ) ; repor...
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" ) ; Bugs...
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 < getCh...
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 .