idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
37,500
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfTunnelPart ( ) { if ( _GenericApplicationPropertyOfTunnelPart == null ) { _GenericApplicationPropertyOfTunnelPart = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfTunnelPart ; }
Gets the value of the genericApplicationPropertyOfTunnelPart property .
37,501
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfParameterizedTexture ( ) { if ( _GenericApplicationPropertyOfParameterizedTexture == null ) { _GenericApplicationPropertyOfParameterizedTexture = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfParameterizedTexture ; }
Gets the value of the genericApplicationPropertyOfParameterizedTexture property .
37,502
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfWaterClosureSurface ( ) { if ( _GenericApplicationPropertyOfWaterClosureSurface == null ) { _GenericApplicationPropertyOfWaterClosureSurface = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfWaterClosureSurface ; }
Gets the value of the genericApplicationPropertyOfWaterClosureSurface property .
37,503
public List < AbstractGriddedSurfaceType . Row > getRow ( ) { if ( row == null ) { row = new ArrayList < AbstractGriddedSurfaceType . Row > ( ) ; } return this . row ; }
Gets the value of the row property .
37,504
public List < PostalCodeElement . PostalCodeNumber > getPostalCodeNumber ( ) { if ( postalCodeNumber == null ) { postalCodeNumber = new ArrayList < PostalCodeElement . PostalCodeNumber > ( ) ; } return this . postalCodeNumber ; }
Gets the value of the postalCodeNumber property .
37,505
public List < PostalCodeElement . PostalCodeNumberExtension > getPostalCodeNumberExtension ( ) { if ( postalCodeNumberExtension == null ) { postalCodeNumberExtension = new ArrayList < PostalCodeElement . PostalCodeNumberExtension > ( ) ; } return this . postalCodeNumberExtension ; }
Gets the value of the postalCodeNumberExtension property .
37,506
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfHollowSpace ( ) { if ( _GenericApplicationPropertyOfHollowSpace == null ) { _GenericApplicationPropertyOfHollowSpace = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfHollowSpace ; }
Gets the value of the genericApplicationPropertyOfHollowSpace property .
37,507
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfBridgeFurniture ( ) { if ( _GenericApplicationPropertyOfBridgeFurniture == null ) { _GenericApplicationPropertyOfBridgeFurniture = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfBridgeFurniture ; }
Gets the value of the genericApplicationPropertyOfBridgeFurniture property .
37,508
public List < JAXBElement < AbstractRingPropertyType > > getInterior ( ) { if ( interior == null ) { interior = new ArrayList < JAXBElement < AbstractRingPropertyType > > ( ) ; } return this . interior ; }
Gets the value of the interior property .
37,509
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfBridgeConstructionElement ( ) { if ( _GenericApplicationPropertyOfBridgeConstructionElement == null ) { _GenericApplicationPropertyOfBridgeConstructionElement = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfBridgeConstructionElement ; }
Gets the value of the genericApplicationPropertyOfBridgeConstructionElement property .
37,510
public List < JAXBElement < ? extends AbstractCurveType > > get_Curve ( ) { if ( _Curve == null ) { _Curve = new ArrayList < JAXBElement < ? extends AbstractCurveType > > ( ) ; } return this . _Curve ; }
Gets the value of the curve property .
37,511
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfTexture ( ) { if ( _GenericApplicationPropertyOfTexture == null ) { _GenericApplicationPropertyOfTexture = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfTexture ; }
Gets the value of the genericApplicationPropertyOfTexture property .
37,512
public List < SubPremiseType . SubPremiseName > getSubPremiseName ( ) { if ( subPremiseName == null ) { subPremiseName = new ArrayList < SubPremiseType . SubPremiseName > ( ) ; } return this . subPremiseName ; }
Gets the value of the subPremiseName property .
37,513
public List < SubPremiseType . SubPremiseNumber > getSubPremiseNumber ( ) { if ( subPremiseNumber == null ) { subPremiseNumber = new ArrayList < SubPremiseType . SubPremiseNumber > ( ) ; } return this . subPremiseNumber ; }
Gets the value of the subPremiseNumber property .
37,514
public List < SubPremiseType . SubPremiseNumberPrefix > getSubPremiseNumberPrefix ( ) { if ( subPremiseNumberPrefix == null ) { subPremiseNumberPrefix = new ArrayList < SubPremiseType . SubPremiseNumberPrefix > ( ) ; } return this . subPremiseNumberPrefix ; }
Gets the value of the subPremiseNumberPrefix property .
37,515
public List < SubPremiseType . SubPremiseNumberSuffix > getSubPremiseNumberSuffix ( ) { if ( subPremiseNumberSuffix == null ) { subPremiseNumberSuffix = new ArrayList < SubPremiseType . SubPremiseNumberSuffix > ( ) ; } return this . subPremiseNumberSuffix ; }
Gets the value of the subPremiseNumberSuffix property .
37,516
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfWallSurface ( ) { if ( _GenericApplicationPropertyOfWallSurface == null ) { _GenericApplicationPropertyOfWallSurface = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfWallSurface ; }
Gets the value of the genericApplicationPropertyOfWallSurface property .
37,517
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfWindow ( ) { if ( _GenericApplicationPropertyOfWindow == null ) { _GenericApplicationPropertyOfWindow = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfWindow ; }
Gets the value of the genericApplicationPropertyOfWindow property .
37,518
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfFloorSurface ( ) { if ( _GenericApplicationPropertyOfFloorSurface == null ) { _GenericApplicationPropertyOfFloorSurface = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfFloorSurface ; }
Gets the value of the genericApplicationPropertyOfFloorSurface property .
37,519
public List < JAXBElement < ? extends AbstractSolidType > > get_Solid ( ) { if ( _Solid == null ) { _Solid = new ArrayList < JAXBElement < ? extends AbstractSolidType > > ( ) ; } return this . _Solid ; }
Gets the value of the solid property .
37,520
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfWaterBody ( ) { if ( _GenericApplicationPropertyOfWaterBody == null ) { _GenericApplicationPropertyOfWaterBody = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfWaterBody ; }
Gets the value of the genericApplicationPropertyOfWaterBody property .
37,521
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfAbstractTunnel ( ) { if ( _GenericApplicationPropertyOfAbstractTunnel == null ) { _GenericApplicationPropertyOfAbstractTunnel = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfAbstractTunnel ; }
Gets the value of the genericApplicationPropertyOfAbstractTunnel property .
37,522
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfBuildingFurniture ( ) { if ( _GenericApplicationPropertyOfBuildingFurniture == null ) { _GenericApplicationPropertyOfBuildingFurniture = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfBuildingFurniture ; }
Gets the value of the genericApplicationPropertyOfBuildingFurniture property .
37,523
public List < JAXBElement < Object > > get_GenericApplicationPropertyOfRailway ( ) { if ( _GenericApplicationPropertyOfRailway == null ) { _GenericApplicationPropertyOfRailway = new ArrayList < JAXBElement < Object > > ( ) ; } return this . _GenericApplicationPropertyOfRailway ; }
Gets the value of the genericApplicationPropertyOfRailway property .
37,524
public List < JAXBElement < ? extends AbstractPositionalAccuracyType > > get_PositionalAccuracy ( ) { if ( _PositionalAccuracy == null ) { _PositionalAccuracy = new ArrayList < JAXBElement < ? extends AbstractPositionalAccuracyType > > ( ) ; } return this . _PositionalAccuracy ; }
Unordered set of estimates of the impact of this coordinate operation on point position accuracy . Gives position error estimates for target coordinates of this coordinate operation assuming no errors in source coordinates . Gets the value of the positionalAccuracy property .
37,525
public final static byte [ ] toByteArray ( String uid ) { byte [ ] result = new byte [ 16 ] ; char [ ] chars = uid . toCharArray ( ) ; int r = 0 ; for ( int i = 0 ; i < chars . length ; ++ i ) { if ( chars [ i ] == '-' ) { continue ; } int h1 = Character . digit ( chars [ i ] , 16 ) ; ++ i ; int h2 = Character . digit ( chars [ i ] , 16 ) ; result [ ( r ++ ) ] = ( byte ) ( ( h1 << 4 | h2 ) & 0xFF ) ; } return result ; }
Returns a byte array for the given uuid or guid .
37,526
public static String getPrettyFormatted ( String str ) { return String . format ( "%s-%s-%s-%s-%s" , new Object [ ] { str . substring ( 0 , 8 ) , str . substring ( 8 , 12 ) , str . substring ( 12 , 16 ) , str . substring ( 16 , 20 ) , str . substring ( 20 ) } ) ; }
Returns a nice neat formatted string .
37,527
@ SuppressWarnings ( "unchecked" ) public void setWriterPostProcessor ( String writerPostProcessor ) { if ( writePostProcessors == null ) { writePostProcessors = new LinkedList < > ( ) ; } try { writePostProcessors . add ( ( Class < IPostProcessor > ) Class . forName ( writerPostProcessor ) ) ; } catch ( Exception e ) { log . debug ( "Write post process implementation: {} was not found" , writerPostProcessor ) ; } }
Sets a writer post processor .
37,528
@ SuppressWarnings ( "unchecked" ) public void setWriterPostProcessors ( Set < String > writerPostProcessors ) { if ( writePostProcessors == null ) { writePostProcessors = new LinkedList < > ( ) ; } for ( String writerPostProcessor : writerPostProcessors ) { try { writePostProcessors . add ( ( Class < IPostProcessor > ) Class . forName ( writerPostProcessor ) ) ; } catch ( Exception e ) { log . debug ( "Write post process implementation: {} was not found" , writerPostProcessor ) ; } } }
Sets a group of writer post processors .
37,529
public int getBitRate ( ) { int result ; switch ( audioVersionId ) { case 1 : return - 1 ; case 0 : case 2 : if ( layerDescription == 3 ) { result = BITRATES [ 3 ] [ bitRateIndex ] ; } else if ( layerDescription == 2 || layerDescription == 1 ) { result = BITRATES [ 4 ] [ bitRateIndex ] ; } else { return - 1 ; } break ; case 3 : if ( layerDescription == 3 ) { result = BITRATES [ 0 ] [ bitRateIndex ] ; } else if ( layerDescription == 2 ) { result = BITRATES [ 1 ] [ bitRateIndex ] ; } else if ( layerDescription == 1 ) { result = BITRATES [ 2 ] [ bitRateIndex ] ; } else { return - 1 ; } break ; default : return - 1 ; } return result * 1000 ; }
Getter for bitrate
37,530
public int frameSize ( ) { switch ( layerDescription ) { case 3 : return ( 12 * getBitRate ( ) / getSampleRate ( ) + ( paddingBit ? 1 : 0 ) ) * 4 ; case 2 : case 1 : if ( audioVersionId == 3 ) { return 144 * getBitRate ( ) / getSampleRate ( ) + ( paddingBit ? 1 : 0 ) ; } else { return 72 * getBitRate ( ) / getSampleRate ( ) + ( paddingBit ? 1 : 0 ) ; } default : return - 1 ; } }
Calculate the size of a MP3 frame for this header .
37,531
public void setMetaCue ( IMetaCue [ ] cuePoints ) { Map < String , Object > cues = new HashMap < String , Object > ( ) ; this . cuePoints = cuePoints ; int j = 0 ; for ( j = 0 ; j < this . cuePoints . length ; j ++ ) { cues . put ( String . valueOf ( j ) , this . cuePoints [ j ] ) ; } this . put ( "cuePoints" , cues ) ; }
Sets the Meta Cue Points
37,532
public static void dumpBox ( Container box ) { log . debug ( "Dump box: {}" , box ) ; for ( Box bx : box . getBoxes ( ) ) { log . debug ( "{} child: {}" , box , bx . getType ( ) ) ; } }
Dumps the children of a container box .
37,533
private void createPreStreamingTags ( int timestamp , boolean clear ) { log . debug ( "Creating pre-streaming tags" ) ; if ( clear ) { firstTags . clear ( ) ; } ITag tag = null ; IoBuffer body = null ; if ( hasVideo ) { body = IoBuffer . allocate ( 41 ) ; body . setAutoExpand ( true ) ; body . put ( PREFIX_VIDEO_CONFIG_FRAME ) ; if ( videoDecoderBytes != null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Video decoder bytes: {}" , HexDump . byteArrayToHexString ( videoDecoderBytes ) ) ; } body . put ( videoDecoderBytes ) ; } tag = new Tag ( IoConstants . TYPE_VIDEO , timestamp , body . position ( ) , null , 0 ) ; body . flip ( ) ; tag . setBody ( body ) ; firstTags . add ( tag ) ; } if ( hasAudio ) { if ( audioDecoderBytes != null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Audio decoder bytes: {}" , HexDump . byteArrayToHexString ( audioDecoderBytes ) ) ; } body = IoBuffer . allocate ( audioDecoderBytes . length + 3 ) ; body . setAutoExpand ( true ) ; body . put ( PREFIX_AUDIO_CONFIG_FRAME ) ; body . put ( audioDecoderBytes ) ; body . put ( ( byte ) 0x06 ) ; tag = new Tag ( IoConstants . TYPE_AUDIO , timestamp , body . position ( ) , null , 0 ) ; body . flip ( ) ; tag . setBody ( body ) ; firstTags . add ( tag ) ; } else { log . info ( "Audio decoder bytes were not available" ) ; } } }
Tag sequence MetaData Video config Audio config remaining audio and video
37,534
public ITag readTag ( ) { ITag tag = null ; if ( log . isTraceEnabled ( ) ) { log . trace ( "Read tag - prevFrameSize {} audio: {} video: {}" , new Object [ ] { prevFrameSize , audioCount , videoCount } ) ; } if ( ! frames . isEmpty ( ) ) { try { lock . acquire ( ) ; if ( ! firstTags . isEmpty ( ) ) { return firstTags . removeFirst ( ) ; } MP4Frame frame = frames . get ( currentFrame ) ; if ( frame != null ) { log . debug ( "Playback #{} {}" , currentFrame , frame ) ; int sampleSize = frame . getSize ( ) ; int time = ( int ) Math . round ( frame . getTime ( ) * 1000.0 ) ; long samplePos = frame . getOffset ( ) ; byte type = frame . getType ( ) ; int pad = 5 ; if ( type == TYPE_AUDIO ) { pad = 2 ; } ByteBuffer data = ByteBuffer . allocate ( sampleSize + pad ) ; try { if ( type == TYPE_VIDEO ) { if ( frame . isKeyFrame ( ) ) { data . put ( PREFIX_VIDEO_KEYFRAME ) ; } else { data . put ( PREFIX_VIDEO_FRAME ) ; } int timeOffset = prevVideoTS != - 1 ? time - prevVideoTS : 0 ; data . put ( ( byte ) ( ( timeOffset >>> 16 ) & 0xff ) ) ; data . put ( ( byte ) ( ( timeOffset >>> 8 ) & 0xff ) ) ; data . put ( ( byte ) ( timeOffset & 0xff ) ) ; if ( log . isTraceEnabled ( ) ) { byte [ ] prefix = new byte [ 5 ] ; int p = data . position ( ) ; data . position ( 0 ) ; data . get ( prefix ) ; data . position ( p ) ; log . trace ( "{}" , prefix ) ; } videoCount ++ ; prevVideoTS = time ; } else { data . put ( PREFIX_AUDIO_FRAME ) ; audioCount ++ ; } dataSource . position ( samplePos ) ; dataSource . read ( data ) ; } catch ( IOException e ) { log . error ( "Error on channel position / read" , e ) ; } IoBuffer payload = IoBuffer . wrap ( data . array ( ) ) ; tag = new Tag ( type , time , payload . limit ( ) , payload , prevFrameSize ) ; currentFrame ++ ; prevFrameSize = tag . getBodySize ( ) ; } } catch ( InterruptedException e ) { log . warn ( "Exception acquiring lock" , e ) ; } finally { lock . release ( ) ; } } else { log . warn ( "No frames are available for the requested item" ) ; } return tag ; }
Packages media data for return to providers
37,535
private void ensureAvailable ( int index ) { if ( data . get ( index ) != null ) { return ; } if ( client == null ) { throw new RuntimeException ( "no remoting client configured" ) ; } Object result ; int start = index ; int count ; if ( mode . equals ( MODE_ONDEMAND ) ) { count = 1 ; } else if ( mode . equals ( MODE_FETCHALL ) ) { count = totalCount - cursor ; } else if ( mode . equals ( MODE_PAGE ) ) { count = 1 ; for ( int i = 1 ; i < pageSize ; i ++ ) { if ( this . data . get ( start + i ) == null ) { count += 1 ; } } } else { count = 1 ; } result = client . invokeMethod ( serviceName + ".getRecords" , new Object [ ] { id , start + 1 , count } ) ; if ( ! ( result instanceof RecordSetPage ) ) { throw new RuntimeException ( "expected RecordSetPage but got " + result ) ; } RecordSetPage page = ( RecordSetPage ) result ; if ( page . getCursor ( ) != start + 1 ) { throw new RuntimeException ( "expected offset " + ( start + 1 ) + " but got " + page . getCursor ( ) ) ; } List < List < Object > > data = page . getData ( ) ; if ( data . size ( ) != count ) { throw new RuntimeException ( "expected " + count + " results but got " + data . size ( ) ) ; } for ( int i = 0 ; i < count ; i ++ ) { this . data . add ( start + i , data . get ( i ) ) ; } }
Make sure the passed item has been fetched from the server .
37,536
public List < Object > getItemAt ( int index ) { if ( index < 0 || index >= totalCount ) { return null ; } ensureAvailable ( index ) ; return data . get ( index ) ; }
Return a specified item from the recordset . If the item is not available yet it will be received from the server .
37,537
public int getNumberAvailable ( ) { int result = 0 ; for ( int i = 0 ; i < data . size ( ) ; i ++ ) { if ( data . get ( i ) != null ) { result += 1 ; } } return result ; }
Get the number of items already received from the server .
37,538
public Map < String , Object > serialize ( ) { Map < String , Object > serverInfo = new HashMap < String , Object > ( ) ; serverInfo . put ( "totalCount" , totalCount ) ; serverInfo . put ( "cursor" , cursor ) ; serverInfo . put ( "serviceName" , serviceName ) ; serverInfo . put ( "columnNames" , columns ) ; serverInfo . put ( "version" , version ) ; serverInfo . put ( "id" , id ) ; serverInfo . put ( "initialData" , data ) ; return serverInfo ; }
Return Map that can be serialized as result .
37,539
public static Document stringToDoc ( String str ) throws IOException { if ( StringUtils . isNotEmpty ( str ) ) { try ( Reader reader = new StringReader ( str ) ) { DocumentBuilder db = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) ; Document doc = db . parse ( new InputSource ( reader ) ) ; return doc ; } catch ( Exception ex ) { log . debug ( "String: {}" , str ) ; throw new IOException ( String . format ( "Error converting from string to doc %s" , ex . getMessage ( ) ) ) ; } } else { throw new IOException ( "Error - could not convert empty string to doc" ) ; } }
Converts string representation of XML into Document
37,540
public static String docToString1 ( Document dom ) { StringWriter sw = new StringWriter ( ) ; DOM2Writer . serializeAsXML ( dom , sw ) ; return sw . toString ( ) ; }
Convert a DOM tree into a String using Dom2Writer
37,541
public static String docToString2 ( Document domDoc ) throws IOException { try { TransformerFactory transFact = TransformerFactory . newInstance ( ) ; Transformer trans = transFact . newTransformer ( ) ; trans . setOutputProperty ( OutputKeys . INDENT , "no" ) ; StringWriter sw = new StringWriter ( ) ; Result result = new StreamResult ( sw ) ; trans . transform ( new DOMSource ( domDoc ) , result ) ; return sw . toString ( ) ; } catch ( Exception ex ) { throw new IOException ( String . format ( "Error converting from doc to string %s" , ex . getMessage ( ) ) ) ; } }
Convert a DOM tree into a String using transform
37,542
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public static Object convert ( Object source , Class < ? > target ) throws ConversionException { if ( target == null ) { throw new ConversionException ( "Unable to perform conversion, target was null" ) ; } if ( source == null ) { if ( target . isPrimitive ( ) ) { throw new ConversionException ( String . format ( "Unable to convert null to primitive value of %s" , target ) ) ; } return source ; } else if ( ( source instanceof Float && ( ( Float ) source ) . isNaN ( ) ) || ( source instanceof Double && ( ( Double ) source ) . isNaN ( ) ) ) { return source ; } if ( target . isInstance ( source ) ) { return source ; } if ( target . isAssignableFrom ( source . getClass ( ) ) ) { return source ; } if ( target . isArray ( ) ) { return convertToArray ( source , target ) ; } if ( target . equals ( String . class ) ) { return source . toString ( ) ; } if ( target . isPrimitive ( ) ) { return convertToWrappedPrimitive ( source , primitiveMap . get ( target ) ) ; } if ( wrapperMap . containsKey ( target ) ) { return convertToWrappedPrimitive ( source , target ) ; } if ( target . equals ( Map . class ) ) { return convertBeanToMap ( source ) ; } if ( target . equals ( List . class ) || target . equals ( Collection . class ) ) { if ( source . getClass ( ) . equals ( LinkedHashMap . class ) ) { return convertMapToList ( ( LinkedHashMap < ? , ? > ) source ) ; } else if ( source . getClass ( ) . isArray ( ) ) { return convertArrayToList ( ( Object [ ] ) source ) ; } } if ( target . equals ( Set . class ) && source . getClass ( ) . isArray ( ) ) { return convertArrayToSet ( ( Object [ ] ) source ) ; } if ( target . equals ( Set . class ) && source instanceof List ) { return new HashSet ( ( List ) source ) ; } if ( source instanceof Map ) { return convertMapToBean ( ( Map ) source , target ) ; } throw new ConversionException ( String . format ( "Unable to preform conversion from %s to %s" , source , target ) ) ; }
Convert source to given class
37,543
public static Object convertToArray ( Object source , Class < ? > target ) throws ConversionException { try { Class < ? > targetType = target . getComponentType ( ) ; if ( source . getClass ( ) . isArray ( ) ) { Object targetInstance = Array . newInstance ( targetType , Array . getLength ( source ) ) ; for ( int i = 0 ; i < Array . getLength ( source ) ; i ++ ) { Array . set ( targetInstance , i , convert ( Array . get ( source , i ) , targetType ) ) ; } return targetInstance ; } if ( source instanceof Collection < ? > ) { Collection < ? > sourceCollection = ( Collection < ? > ) source ; Object targetInstance = Array . newInstance ( target . getComponentType ( ) , sourceCollection . size ( ) ) ; Iterator < ? > it = sourceCollection . iterator ( ) ; int i = 0 ; while ( it . hasNext ( ) ) { Array . set ( targetInstance , i ++ , convert ( it . next ( ) , targetType ) ) ; } return targetInstance ; } throw new ConversionException ( "Unable to convert to array" ) ; } catch ( Exception ex ) { throw new ConversionException ( "Error converting to array" , ex ) ; } }
Convert to array
37,544
public static Object convertToWrappedPrimitive ( Object source , Class < ? > wrapper ) { if ( source == null || wrapper == null ) { return null ; } if ( wrapper . isInstance ( source ) ) { return source ; } if ( wrapper . isAssignableFrom ( source . getClass ( ) ) ) { return source ; } if ( source instanceof Number ) { return convertNumberToWrapper ( ( Number ) source , wrapper ) ; } else { if ( Number . class . isAssignableFrom ( wrapper ) ) { if ( ! source . toString ( ) . matches ( NUMERIC_TYPE ) ) { throw new ConversionException ( String . format ( "Unable to convert string %s its not a number type: %s" , source , wrapper ) ) ; } } return convertStringToWrapper ( source . toString ( ) , wrapper ) ; } }
Convert to wrapped primitive
37,545
public static Object convertStringToWrapper ( String str , Class < ? > wrapper ) { log . trace ( "String: {} to wrapper: {}" , str , wrapper ) ; if ( wrapper . equals ( String . class ) ) { return str ; } else if ( wrapper . equals ( Boolean . class ) ) { return Boolean . valueOf ( str ) ; } else if ( wrapper . equals ( Double . class ) ) { return Double . valueOf ( str ) ; } else if ( wrapper . equals ( Long . class ) ) { return Long . valueOf ( str ) ; } else if ( wrapper . equals ( Float . class ) ) { return Float . valueOf ( str ) ; } else if ( wrapper . equals ( Integer . class ) ) { return Integer . valueOf ( str ) ; } else if ( wrapper . equals ( Short . class ) ) { return Short . valueOf ( str ) ; } else if ( wrapper . equals ( Byte . class ) ) { return Byte . valueOf ( str ) ; } throw new ConversionException ( String . format ( "Unable to convert string to: %s" , wrapper ) ) ; }
Convert string to primitive wrapper like Boolean or Float
37,546
public static Object convertNumberToWrapper ( Number num , Class < ? > wrapper ) { if ( wrapper . equals ( String . class ) ) { return num . toString ( ) ; } else if ( wrapper . equals ( Boolean . class ) ) { return Boolean . valueOf ( num . intValue ( ) == 1 ) ; } else if ( wrapper . equals ( Double . class ) ) { return Double . valueOf ( num . doubleValue ( ) ) ; } else if ( wrapper . equals ( Long . class ) ) { return Long . valueOf ( num . longValue ( ) ) ; } else if ( wrapper . equals ( Float . class ) ) { return Float . valueOf ( num . floatValue ( ) ) ; } else if ( wrapper . equals ( Integer . class ) ) { return Integer . valueOf ( num . intValue ( ) ) ; } else if ( wrapper . equals ( Short . class ) ) { return Short . valueOf ( num . shortValue ( ) ) ; } else if ( wrapper . equals ( Byte . class ) ) { return Byte . valueOf ( num . byteValue ( ) ) ; } throw new ConversionException ( String . format ( "Unable to convert number to: %s" , wrapper ) ) ; }
Convert number to primitive wrapper like Boolean or Float
37,547
public static List < Method > findMethodsByNameAndNumParams ( Object object , String method , int numParam ) { LinkedList < Method > list = new LinkedList < Method > ( ) ; Method [ ] methods = object . getClass ( ) . getMethods ( ) ; for ( Method m : methods ) { String methodName = m . getName ( ) ; if ( ignoredMethodNames . indexOf ( methodName ) > - 1 ) { log . debug ( "Skipping method: {}" , methodName ) ; continue ; } if ( log . isDebugEnabled ( ) ) { Class < ? > [ ] params = m . getParameterTypes ( ) ; log . debug ( "Method name: {} parameter count: {}" , methodName , params . length ) ; for ( Class < ? > param : params ) { log . debug ( "Parameter: {}" , param ) ; } } if ( m . getParameterTypes ( ) . length != numParam ) { log . debug ( "Param length not the same" ) ; continue ; } if ( ! methodName . equals ( method ) ) { log . trace ( "Method name not the same" ) ; continue ; } list . add ( m ) ; } return list ; }
Find method by name and number of parameters
37,548
public static Object [ ] convertParams ( Object [ ] source , Class < ? > [ ] target ) throws ConversionException { Object [ ] converted = new Object [ target . length ] ; for ( int i = 0 ; i < target . length ; i ++ ) { converted [ i ] = convert ( source [ i ] , target [ i ] ) ; } return converted ; }
Convert parameters using methods of this utility class
37,549
public static Class < ? > [ ] convertParams ( Object [ ] source ) { Class < ? > [ ] converted = null ; if ( source != null ) { converted = new Class < ? > [ source . length ] ; for ( int i = 0 ; i < source . length ; i ++ ) { if ( source [ i ] != null ) { converted [ i ] = source [ i ] . getClass ( ) ; } else { converted [ i ] = null ; } } } else { converted = new Class < ? > [ 0 ] ; } if ( log . isTraceEnabled ( ) ) { log . trace ( "Converted parameters: {}" , Arrays . toString ( converted ) ) ; } return converted ; }
Convert parameters using methods of this utility class . Special handling is afforded to classes that implement IConnection .
37,550
public static Object convertMapToBean ( Map < String , ? extends Object > source , Class < ? > target ) throws ConversionException { Object bean = newInstance ( target ) ; if ( bean == null ) { bean = newInstance ( target . getName ( ) ) ; if ( bean == null ) { throw new ConversionException ( "Unable to create bean using empty constructor" ) ; } } try { BeanUtils . populate ( bean , source ) ; } catch ( Exception e ) { throw new ConversionException ( "Error populating bean" , e ) ; } return bean ; }
Convert map to bean
37,551
public static Set < ? > convertArrayToSet ( Object [ ] source ) { Set < Object > set = new HashSet < Object > ( ) ; for ( Object element : source ) { set . add ( element ) ; } return set ; }
Convert array to set removing duplicates
37,552
private ITag createFileMeta ( ) { log . debug ( "createFileMeta" ) ; IoBuffer in = IoBuffer . allocate ( 1024 ) ; in . setAutoExpand ( true ) ; Output out = new Output ( in ) ; out . writeString ( "onMetaData" ) ; Map < Object , Object > props = new HashMap < Object , Object > ( ) ; props . put ( "audiocodecid" , IoConstants . FLAG_FORMAT_MP3 ) ; props . put ( "canSeekToEnd" , true ) ; if ( metaData != null ) { if ( metaData . artist != null ) { props . put ( "artist" , metaData . artist ) ; } if ( metaData . album != null ) { props . put ( "album" , metaData . album ) ; } if ( metaData . songName != null ) { props . put ( "songName" , metaData . songName ) ; } if ( metaData . genre != null ) { props . put ( "genre" , metaData . genre ) ; } if ( metaData . year != null ) { props . put ( "year" , metaData . year ) ; } if ( metaData . track != null ) { props . put ( "track" , metaData . track ) ; } if ( metaData . comment != null ) { props . put ( "comment" , metaData . comment ) ; } if ( metaData . duration != null ) { props . put ( "duration" , metaData . duration ) ; } if ( metaData . channels != null ) { props . put ( "channels" , metaData . channels ) ; } if ( metaData . sampleRate != null ) { props . put ( "samplerate" , metaData . sampleRate ) ; } if ( metaData . hasCoverImage ( ) ) { Map < Object , Object > covr = new HashMap < > ( 1 ) ; covr . put ( "covr" , new Object [ ] { metaData . getCovr ( ) } ) ; props . put ( "tags" , covr ) ; } metaData = null ; } log . debug ( "Metadata properties map: {}" , props ) ; if ( ! props . containsKey ( "duration" ) ) { if ( frameMeta != null ) { props . put ( "duration" , frameMeta . timestamps [ frameMeta . timestamps . length - 1 ] / 1000.0 ) ; } else { log . debug ( "Frame meta was null" ) ; } } if ( dataRate > 0 ) { props . put ( "audiodatarate" , dataRate ) ; } out . writeMap ( props ) ; in . flip ( ) ; ITag result = new Tag ( IoConstants . TYPE_METADATA , 0 , in . limit ( ) , null , prevSize ) ; result . setBody ( in ) ; return result ; }
Creates file metadata object
37,553
protected void writeArbitraryObject ( Object object ) { log . debug ( "writeObject" ) ; Class < ? > objectClass = object . getClass ( ) ; if ( ! objectClass . isAnnotationPresent ( Anonymous . class ) ) { buf . put ( AMF . TYPE_CLASS_OBJECT ) ; putString ( buf , Serializer . getClassName ( objectClass ) ) ; } else { buf . put ( AMF . TYPE_OBJECT ) ; } for ( Field field : objectClass . getFields ( ) ) { String fieldName = field . getName ( ) ; log . debug ( "Field: {} class: {}" , field , objectClass ) ; if ( ! serializeField ( objectClass , fieldName , field , null ) ) { continue ; } Object value ; try { value = field . get ( object ) ; } catch ( IllegalAccessException err ) { continue ; } putString ( buf , fieldName ) ; Serializer . serialize ( this , field , null , object , value ) ; } buf . put ( AMF . END_OF_OBJECT_SEQUENCE ) ; }
Writes an arbitrary object to the output .
37,554
protected static byte [ ] encodeString ( String string ) { Element element = getStringCache ( ) . get ( string ) ; byte [ ] encoded = ( element == null ? null : ( byte [ ] ) element . getObjectValue ( ) ) ; if ( encoded == null ) { ByteBuffer buf = AMF . CHARSET . encode ( string ) ; encoded = new byte [ buf . limit ( ) ] ; buf . get ( encoded ) ; getStringCache ( ) . put ( new Element ( string , encoded ) ) ; } return encoded ; }
Encode string .
37,555
public static void putString ( IoBuffer buf , String string ) { final byte [ ] encoded = encodeString ( string ) ; if ( encoded . length < AMF . LONG_STRING_LENGTH ) { buf . put ( ( byte ) ( ( encoded . length >> 8 ) & 0xff ) ) ; buf . put ( ( byte ) ( encoded . length & 0xff ) ) ; } else { buf . putInt ( encoded . length ) ; } buf . put ( encoded ) ; }
Write out string
37,556
public void writeHeader ( ) throws IOException , ConverterException { if ( append ) { return ; } try { CompoundTag ebml = TagFactory . < CompoundTag > create ( "EBML" ) . add ( TagFactory . < UnsignedIntegerTag > create ( "EBMLVersion" ) . setValue ( 1 ) ) . add ( TagFactory . < UnsignedIntegerTag > create ( "EBMLReadVersion" ) . setValue ( 1 ) ) . add ( TagFactory . < UnsignedIntegerTag > create ( "EBMLMaxIDLength" ) . setValue ( 4 ) ) . add ( TagFactory . < UnsignedIntegerTag > create ( "EBMLMaxSizeLength" ) . setValue ( 8 ) ) . add ( TagFactory . < StringTag > create ( "DocType" ) . setValue ( "webm" ) ) . add ( TagFactory . < UnsignedIntegerTag > create ( "DocTypeVersion" ) . setValue ( 3 ) ) . add ( TagFactory . < UnsignedIntegerTag > create ( "DocTypeReadVersion" ) . setValue ( 2 ) ) ; byte [ ] hb = ebml . encode ( ) ; bytesWritten += hb . length ; dataFile . write ( hb ) ; } catch ( IOException | ConverterException e ) { log . error ( "Failed to write header" , e ) ; throw e ; } }
method to write webm header to the new file
37,557
public void writeTag ( Tag tag ) throws IOException { byte [ ] hb = tag . encode ( ) ; bytesWritten += hb . length ; dataFile . write ( hb ) ; }
will write tag bytesWritten counter will be increased by the number of bytes actually written
37,558
public void close ( ) throws IOException { if ( dataFile != null ) { if ( ! append ) { dataFile . seek ( 0 ) ; try ( RandomAccessFile rf = new RandomAccessFile ( file , "rw" ) ) { rf . getChannel ( ) . transferFrom ( dataFile . getChannel ( ) , 0 , dataFile . length ( ) ) ; } } try { dataFile . close ( ) ; dataFile = null ; } catch ( Throwable th ) { } } }
Will close all opened resources and finalize the write process
37,559
private void createPreStreamingTags ( ) { log . debug ( "Creating pre-streaming tags" ) ; if ( audioDecoderBytes != null ) { IoBuffer body = IoBuffer . allocate ( audioDecoderBytes . length + 3 ) ; body . put ( new byte [ ] { ( byte ) 0xaf , ( byte ) 0 } ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Audio decoder bytes: {}" , HexDump . byteArrayToHexString ( audioDecoderBytes ) ) ; } body . put ( audioDecoderBytes ) ; body . put ( ( byte ) 0x06 ) ; ITag tag = new Tag ( IoConstants . TYPE_AUDIO , 0 , body . position ( ) , null , prevFrameSize ) ; body . flip ( ) ; tag . setBody ( body ) ; firstTags . add ( tag ) ; } else { log . warn ( "Audio decoder bytes were not available" ) ; } }
Tag sequence MetaData Audio config remaining audio
37,560
public ITag readTag ( ) { ITag tag = null ; try { lock . acquire ( ) ; if ( ! firstTags . isEmpty ( ) ) { log . debug ( "Returning pre-tag" ) ; return firstTags . removeFirst ( ) ; } MP4Frame frame = frames . get ( currentFrame ) ; log . debug ( "Playback {}" , frame ) ; int sampleSize = frame . getSize ( ) ; int time = ( int ) Math . round ( frame . getTime ( ) * 1000.0 ) ; long samplePos = frame . getOffset ( ) ; byte type = frame . getType ( ) ; ByteBuffer data = ByteBuffer . allocate ( sampleSize + 2 ) ; try { data . put ( MP4Reader . PREFIX_AUDIO_FRAME ) ; dataSource . position ( samplePos ) ; dataSource . read ( data ) ; } catch ( IOException e ) { log . error ( "Error on channel position / read" , e ) ; } IoBuffer payload = IoBuffer . wrap ( data . array ( ) ) ; tag = new Tag ( type , time , payload . limit ( ) , payload , prevFrameSize ) ; currentFrame ++ ; prevFrameSize = tag . getBodySize ( ) ; } catch ( InterruptedException e ) { log . warn ( "Exception acquiring lock" , e ) ; } finally { lock . release ( ) ; } return tag ; }
Packages media data for return to providers .
37,561
public static void serializeAsXML ( Node node , Writer writer ) { PrintWriter out = new PrintWriter ( writer ) ; print ( node , out ) ; out . flush ( ) ; }
Serialize this node into the writer as XML .
37,562
private static void print ( Node node , PrintWriter out ) { if ( node == null ) { return ; } boolean hasChildren = false ; int type = node . getNodeType ( ) ; NodeList children = null ; switch ( type ) { case Node . DOCUMENT_NODE : children = node . getChildNodes ( ) ; if ( children != null ) { int numChildren = children . getLength ( ) ; for ( int i = 0 ; i < numChildren ; i ++ ) { print ( children . item ( i ) , out ) ; } } break ; case Node . ELEMENT_NODE : out . print ( '<' ) ; out . print ( node . getNodeName ( ) ) ; if ( node . hasAttributes ( ) ) { NamedNodeMap attrs = node . getAttributes ( ) ; int len = ( attrs != null ) ? attrs . getLength ( ) : 0 ; for ( int a = 0 ; a < len ; a ++ ) { Attr attr = ( Attr ) attrs . item ( a ) ; out . print ( ' ' ) ; out . print ( attr . getNodeName ( ) ) ; out . print ( "=\"" ) ; out . print ( attr . getValue ( ) ) ; out . print ( '\"' ) ; } } children = node . getChildNodes ( ) ; if ( children != null ) { int numChildren = children . getLength ( ) ; hasChildren = ( numChildren > 0 ) ; if ( hasChildren ) { out . print ( '>' ) ; } for ( int i = 0 ; i < numChildren ; i ++ ) { print ( children . item ( i ) , out ) ; } } else { hasChildren = false ; } if ( ! hasChildren ) { out . print ( "/>" ) ; } break ; case Node . ENTITY_REFERENCE_NODE : out . print ( '&' ) ; out . print ( node . getNodeName ( ) ) ; out . print ( ';' ) ; break ; case Node . CDATA_SECTION_NODE : out . print ( "<![CDATA[" ) ; out . print ( node . getNodeValue ( ) ) ; out . print ( "]]>" ) ; break ; case Node . TEXT_NODE : out . print ( node . getNodeValue ( ) ) ; break ; default : if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Unknown type: " + type ) ; } } if ( type == Node . ELEMENT_NODE && hasChildren ) { out . print ( "</" ) ; out . print ( node . getNodeName ( ) ) ; out . print ( '>' ) ; hasChildren = false ; } }
Dumps DOM node
37,563
@ SuppressWarnings ( "rawtypes" ) protected static boolean writeBasic ( Output out , Object basic ) { if ( basic == null ) { out . writeNull ( ) ; } else if ( basic instanceof Boolean ) { out . writeBoolean ( ( Boolean ) basic ) ; } else if ( basic instanceof Number ) { out . writeNumber ( ( Number ) basic ) ; } else if ( basic instanceof String ) { out . writeString ( ( String ) basic ) ; } else if ( basic instanceof Enum ) { out . writeString ( ( ( Enum ) basic ) . name ( ) ) ; } else if ( basic instanceof Date ) { out . writeDate ( ( Date ) basic ) ; } else { return false ; } return true ; }
Writes a primitive out as an object
37,564
public static boolean writeComplex ( Output out , Object complex ) { log . trace ( "writeComplex" ) ; if ( writeListType ( out , complex ) ) { return true ; } else if ( writeArrayType ( out , complex ) ) { return true ; } else if ( writeXMLType ( out , complex ) ) { return true ; } else if ( writeCustomType ( out , complex ) ) { return true ; } else if ( writeObjectType ( out , complex ) ) { return true ; } else { return false ; } }
Writes a complex type object out
37,565
protected static boolean writeListType ( Output out , Object listType ) { log . trace ( "writeListType" ) ; if ( listType instanceof List < ? > ) { writeList ( out , ( List < ? > ) listType ) ; } else { return false ; } return true ; }
Writes Lists out as a data type
37,566
protected static void writeList ( Output out , List < ? > list ) { if ( ! list . isEmpty ( ) ) { int size = list . size ( ) ; if ( size < 100 ) { out . writeArray ( list ) ; return ; } int nullCount = 0 ; for ( int i = 0 ; i < size ; i ++ ) { if ( list . get ( i ) == null ) { nullCount ++ ; } } if ( nullCount > ( size * 0.8 ) ) { out . writeMap ( list ) ; } else { out . writeArray ( list ) ; } } else { out . writeArray ( new Object [ ] { } ) ; } }
Writes a List out as an Object
37,567
protected static void writeIterator ( Output out , Iterator < Object > it ) { log . trace ( "writeIterator" ) ; LinkedList < Object > list = new LinkedList < Object > ( ) ; while ( it . hasNext ( ) ) { list . addLast ( it . next ( ) ) ; } out . writeArray ( list ) ; }
Writes an iterator out to the output
37,568
protected static boolean writeXMLType ( Output out , Object xml ) { log . trace ( "writeXMLType" ) ; if ( xml instanceof Document ) { writeDocument ( out , ( Document ) xml ) ; } else { return false ; } return true ; }
Writes an xml type out to the output
37,569
@ SuppressWarnings ( "all" ) protected static boolean writeObjectType ( Output out , Object obj ) { if ( obj instanceof ObjectMap || obj instanceof BeanMap ) { out . writeObject ( ( Map ) obj ) ; } else if ( obj instanceof Map ) { out . writeMap ( ( Map ) obj ) ; } else if ( obj instanceof RecordSet ) { out . writeRecordSet ( ( RecordSet ) obj ) ; } else { out . writeObject ( obj ) ; } return true ; }
Write typed object to the output
37,570
protected static boolean writeCustomType ( Output out , Object obj ) { if ( out . isCustom ( obj ) ) { out . writeCustom ( obj ) ; return true ; } else { return false ; } }
Writes a custom data to the output
37,571
public static boolean serializeField ( String keyName , Field field , Method getter ) { log . trace ( "serializeField - keyName: {} field: {} method: {}" , new Object [ ] { keyName , field , getter } ) ; if ( "class" . equals ( keyName ) ) { return false ; } if ( field != null ) { if ( Modifier . isTransient ( field . getModifiers ( ) ) ) { log . trace ( "Skipping {} because its transient" , keyName ) ; return false ; } else if ( field . isAnnotationPresent ( DontSerialize . class ) ) { log . trace ( "Skipping {} because its marked with @DontSerialize" , keyName ) ; return false ; } } if ( getter != null && getter . isAnnotationPresent ( DontSerialize . class ) ) { log . trace ( "Skipping {} because its marked with @DontSerialize" , keyName ) ; return false ; } log . trace ( "Serialize field: {}" , field ) ; return true ; }
Checks whether the field should be serialized or not
37,572
public static String getClassName ( Class < ? > objectClass ) { RemoteClass annotation = objectClass . getAnnotation ( RemoteClass . class ) ; if ( annotation != null ) { return annotation . alias ( ) ; } String className = objectClass . getName ( ) ; if ( className . startsWith ( "org.red5.compatibility." ) ) { className = className . substring ( 23 ) ; if ( "flex.messaging.messages.AsyncMessageExt" . equals ( className ) ) { className = "DSA" ; } else if ( "flex.messaging.messages.CommandMessageExt" . equals ( className ) ) { className = "DSC" ; } else if ( "flex.messaging.messages.AcknowledgeMessageExt" . equals ( className ) ) { className = "DSK" ; } } log . debug ( "Classname: {}" , className ) ; return className ; }
Handles classes by name also provides shortened class aliases where appropriate .
37,573
protected void storeReference ( Object obj ) { refMap . put ( new IdentityWrapper ( obj ) , Short . valueOf ( refId ++ ) ) ; }
Store an object into a map
37,574
private void updateSize ( IoBuffer data ) { this . widthInfo = data . getShort ( ) ; this . heightInfo = data . getShort ( ) ; this . width = this . widthInfo & 0xfff ; this . height = this . heightInfo & 0xfff ; this . blockWidth = this . widthInfo & 0xf000 ; this . blockWidth = ( this . blockWidth >> 12 ) + 1 ; this . blockWidth <<= 4 ; this . blockHeight = this . heightInfo & 0xf000 ; this . blockHeight = ( this . blockHeight >> 12 ) + 1 ; this . blockHeight <<= 4 ; int xblocks = this . width / this . blockWidth ; if ( ( this . width % this . blockWidth ) != 0 ) { xblocks += 1 ; } int yblocks = this . height / this . blockHeight ; if ( ( this . height % this . blockHeight ) != 0 ) { yblocks += 1 ; } this . blockCount = xblocks * yblocks ; int blockSize = maxCompressedSize ( this . blockWidth * this . blockHeight * 3 ) ; int totalBlockSize = blockSize * this . blockCount ; if ( this . totalBlockDataSize != totalBlockSize ) { log . info ( "Allocating memory for {} compressed blocks." , this . blockCount ) ; this . blockDataSize = blockSize ; this . totalBlockDataSize = totalBlockSize ; this . blockData = new byte [ blockSize * this . blockCount ] ; this . blockSize = new int [ blockSize * this . blockCount ] ; for ( int idx = 0 ; idx < this . blockCount ; idx ++ ) { this . blockSize [ idx ] = 0 ; } } }
Update total block size
37,575
public byte readDataType ( ) { if ( buf . hasRemaining ( ) ) { do { currentDataType = buf . get ( ) ; log . trace ( "Data type: {}" , currentDataType ) ; 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 ; case AMF . TYPE_UNSUPPORTED : case AMF . TYPE_MOVIECLIP : case AMF . TYPE_RECORDSET : return ( byte ) ( currentDataType + DataTypes . CUSTOM_AMF_MASK ) ; case AMF . TYPE_AMF3_OBJECT : log . debug ( "Switch to AMF3" ) ; return DataTypes . CORE_SWITCH ; } } while ( hasMoreProperties ( ) ) ; log . trace ( "No more data types available" ) ; return DataTypes . CORE_END_OBJECT ; } return DataTypes . CORE_NULL ; }
Reads the data type .
37,576
public Boolean readBoolean ( ) { return ( buf . get ( ) == AMF . VALUE_TRUE ) ? Boolean . TRUE : Boolean . FALSE ; }
Reads a boolean .
37,577
public Number readNumber ( ) { int remaining = buf . remaining ( ) ; log . debug ( "readNumber from {} bytes" , remaining ) ; if ( remaining >= 8 ) { double d = buf . getDouble ( ) ; log . debug ( "Number: {}" , d ) ; return d ; } if ( log . isDebugEnabled ( ) ) { log . debug ( "Remaining not big enough for number - offset: {} limit: {} {}" , buf . position ( ) , buf . limit ( ) , Hex . encodeHexString ( buf . array ( ) ) ) ; } return 0 ; }
Reads a Number . In ActionScript 1 and 2 Number type represents all numbers both floats and integers .
37,578
public String getString ( ) { log . trace ( "getString - currentDataType: {}" , currentDataType ) ; byte lastDataType = currentDataType ; if ( currentDataType != AMF . TYPE_STRING ) { currentDataType = AMF . TYPE_STRING ; } String result = readString ( ) ; currentDataType = lastDataType ; return result ; }
Reads string from buffer
37,579
private final String bufferToString ( byte [ ] str ) { String string = null ; if ( str != null ) { string = AMF . CHARSET . decode ( ByteBuffer . wrap ( str ) ) . toString ( ) ; log . debug ( "String: {}" , string ) ; } else { log . warn ( "ByteBuffer was null attempting to read String" ) ; } return string ; }
Converts the bytes into a string .
37,580
public Map < String , Object > readKeyValues ( ) { Map < String , Object > result = new HashMap < String , Object > ( ) ; readKeyValues ( result ) ; return result ; }
Read key - value pairs . This is required for the RecordSet deserializer .
37,581
protected void readKeyValues ( Map < String , Object > result ) { while ( hasMoreProperties ( ) ) { String name = readPropertyName ( ) ; log . debug ( "property: {}" , name ) ; Object property = Deserializer . deserialize ( this , Object . class ) ; log . debug ( "val: {}" , property ) ; result . put ( name , property ) ; if ( hasMoreProperties ( ) ) { skipPropertySeparator ( ) ; } else { break ; } } }
Read key - value pairs into Map object
37,582
@ SuppressWarnings ( "all" ) protected Object newInstance ( String className ) { log . debug ( "Loading class: {}" , className ) ; Object instance = null ; Class < ? > clazz = null ; if ( "" . equals ( className ) || className == null ) return instance ; try { if ( className . length ( ) == 3 ) { className = classAliases . get ( className ) ; } if ( className . startsWith ( "flex." ) ) { className = "org.red5.compatibility." + className ; log . debug ( "Modified classname: {}" , className ) ; } if ( ! classAllowed ( className ) ) { log . error ( "Class creation is not allowed {}" , className ) ; } else { clazz = Thread . currentThread ( ) . getContextClassLoader ( ) . loadClass ( className ) ; instance = clazz . newInstance ( ) ; } } catch ( InstantiationException iex ) { try { clazz . getConstructor ( null ) ; log . error ( "Error loading class: {}" , className ) ; } catch ( NoSuchMethodException nse ) { log . error ( "Error loading class: {}; this can be resolved by adding a default constructor to your class" , className ) ; } log . debug ( "Exception was: {}" , iex ) ; } catch ( Exception ex ) { log . error ( "Error loading class: {}" , className ) ; log . debug ( "Exception was: {}" , ex ) ; } return instance ; }
Creates a new instance of the className parameter and returns as an Object
37,583
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) protected Object readBean ( Object bean ) { log . debug ( "readBean: {}" , bean ) ; storeReference ( bean ) ; Class theClass = bean . getClass ( ) ; while ( hasMoreProperties ( ) ) { String name = readPropertyName ( ) ; Type type = getPropertyType ( bean , name ) ; log . debug ( "property: {} type: {}" , name , type ) ; Object property = Deserializer . deserialize ( this , type ) ; log . debug ( "val: {}" , property ) ; if ( property != null ) { try { if ( type instanceof Class ) { Class t = ( Class ) type ; if ( ! t . isAssignableFrom ( property . getClass ( ) ) ) { property = ConversionUtils . convert ( property , t ) ; } } final Field field = theClass . getField ( name ) ; field . set ( bean , property ) ; } catch ( Exception ex2 ) { try { BeanUtils . setProperty ( bean , name , property ) ; } catch ( Exception ex ) { log . error ( "Error mapping property: {} ({})" , name , property ) ; } } } else { log . debug ( "Skipping null property: {}" , name ) ; } if ( hasMoreProperties ( ) ) { skipPropertySeparator ( ) ; } else { break ; } } return bean ; }
Reads the input as a bean and returns an object
37,584
protected Map < String , Object > readSimpleObject ( ) { log . debug ( "readSimpleObject" ) ; Map < String , Object > result = new ObjectMap < > ( ) ; readKeyValues ( result ) ; storeReference ( result ) ; return result ; }
Reads the input as a map and returns a Map
37,585
public Object readObject ( ) { String className ; if ( currentDataType == AMF . TYPE_CLASS_OBJECT ) { className = getString ( ) ; log . debug ( "readObject: {}" , className ) ; if ( className != null ) { log . debug ( "read class object" ) ; Object result = null ; Object instance ; if ( className . equals ( "RecordSet" ) ) { result = new RecordSet ( this ) ; storeReference ( result ) ; } else if ( className . equals ( "RecordSetPage" ) ) { result = new RecordSetPage ( this ) ; storeReference ( result ) ; } else if ( ! classAllowed ( className ) ) { log . debug ( "Class creation is not allowed {}" , className ) ; result = readSimpleObject ( ) ; } else { instance = newInstance ( className ) ; if ( instance != null ) { result = readBean ( instance ) ; } else { log . debug ( "Forced to use simple object for class {}" , className ) ; result = readSimpleObject ( ) ; } } return result ; } } return readSimpleObject ( ) ; }
Reads start object
37,586
public boolean hasMoreProperties ( ) { if ( buf . remaining ( ) >= 3 ) { byte [ ] threeBytes = new byte [ 3 ] ; int pos = buf . position ( ) ; buf . get ( threeBytes ) ; if ( Arrays . equals ( AMF . END_OF_OBJECT_SEQUENCE , threeBytes ) ) { log . trace ( "End of object" ) ; return false ; } buf . position ( pos ) ; return true ; } return true ; }
Returns a boolean stating whether there are more properties
37,587
@ SuppressWarnings ( { "unchecked" } ) public static IMeta mergeMeta ( IMetaData < ? , ? > metaData1 , IMetaData < ? , ? > metaData2 ) { Map < String , Object > map1 = ( ( Map < String , Object > ) metaData1 ) ; Set < Entry < String , Object > > set1 = map1 . entrySet ( ) ; Map < String , Object > map2 = ( ( Map < String , Object > ) metaData2 ) ; Set < Entry < String , Object > > set2 = map2 . entrySet ( ) ; Map < String , Object > rep = new HashMap < String , Object > ( ) ; for ( Entry < String , Object > entry1 : set1 ) { String key1 = entry1 . getKey ( ) ; if ( map2 . containsKey ( key1 ) ) { Object value1 = map1 . get ( key1 ) ; Object value2 = map2 . get ( key1 ) ; if ( value1 instanceof Double ) { if ( Double . valueOf ( value1 . toString ( ) ) . doubleValue ( ) < Double . valueOf ( value2 . toString ( ) ) . doubleValue ( ) ) { rep . put ( key1 , value2 ) ; } } else if ( value1 instanceof Integer ) { if ( Integer . valueOf ( value1 . toString ( ) ) . intValue ( ) < Integer . valueOf ( value2 . toString ( ) ) . intValue ( ) ) { rep . put ( key1 , value2 ) ; } } else if ( value1 instanceof Long ) { if ( Long . valueOf ( value1 . toString ( ) ) . longValue ( ) < Long . valueOf ( value2 . toString ( ) ) . longValue ( ) ) { rep . put ( key1 , value2 ) ; } } if ( value1 instanceof Boolean ) { if ( ! Boolean . valueOf ( value1 . toString ( ) ) && Boolean . valueOf ( value2 . toString ( ) ) ) { rep . put ( key1 , value2 ) ; } } } } set1 . removeAll ( rep . entrySet ( ) ) ; set1 . addAll ( rep . entrySet ( ) ) ; set1 . addAll ( set2 ) ; return metaData1 ; }
Merges the two Meta objects
37,588
public void readData ( InputStream inputStream ) throws IOException { if ( inputStream == null ) { return ; } data = ParserUtils . parseBinary ( inputStream , ( int ) size . getValue ( ) ) ; }
method to read tag data from inputStream given
37,589
protected void addParameters ( StringBuilder result ) { result . append ( "ts=" ) ; result . append ( timestamp ) ; result . append ( ",headers=" ) ; result . append ( headers ) ; result . append ( ",body=" ) ; result . append ( body ) ; result . append ( ",messageId=" ) ; result . append ( messageId ) ; result . append ( ",timeToLive=" ) ; result . append ( timeToLive ) ; result . append ( ",clientId=" ) ; result . append ( clientId ) ; result . append ( ",destination=" ) ; result . append ( destination ) ; }
Add message properties to string .
37,590
public void writeHeader ( ) throws IOException { ByteBuffer buf = ByteBuffer . allocate ( HEADER_LENGTH + 4 ) ; FLVHeader flvHeader = new FLVHeader ( ) ; flvHeader . setFlagAudio ( audioCodecId != - 1 ? true : false ) ; flvHeader . setFlagVideo ( videoCodecId != - 1 ? true : false ) ; flvHeader . write ( buf ) ; createOutputFile ( ) ; bytesWritten = fileChannel . write ( buf ) ; assert ( ( HEADER_LENGTH + 4 ) - bytesWritten == 0 ) ; log . debug ( "Header size: {} bytes written: {}" , ( HEADER_LENGTH + 4 ) , bytesWritten ) ; buf . clear ( ) ; buf = null ; }
Writes the header bytes
37,591
private void createOutputFile ( ) throws IOException { this . fileChannel = Files . newByteChannel ( Paths . get ( filePath ) , StandardOpenOption . CREATE , StandardOpenOption . WRITE , StandardOpenOption . TRUNCATE_EXISTING ) ; }
Create the stream output file ; the flv itself .
37,592
private void createDataFile ( ) throws IOException { Path path = Paths . get ( filePath + ".ser" ) ; if ( Files . deleteIfExists ( path ) ) { log . debug ( "Previous flv data file existed and was removed" ) ; } this . dataChannel = Files . newByteChannel ( path , StandardOpenOption . CREATE_NEW , StandardOpenOption . WRITE , StandardOpenOption . READ ) ; }
Create the stream data file .
37,593
private void createRepairDataFile ( ) throws IOException { Path path = Paths . get ( filePath + ".ser" ) ; this . dataChannel = Files . newByteChannel ( path , StandardOpenOption . READ ) ; }
Create the stream data file for repair .
37,594
private static int [ ] readInfoFile ( File tmpFile ) { int [ ] info = new int [ 8 ] ; try ( RandomAccessFile infoFile = new RandomAccessFile ( tmpFile , "r" ) ) { info [ 0 ] = infoFile . readInt ( ) ; info [ 1 ] = infoFile . readInt ( ) ; info [ 2 ] = infoFile . readInt ( ) ; info [ 3 ] = infoFile . readInt ( ) ; info [ 4 ] = infoFile . readInt ( ) ; info [ 5 ] = infoFile . readInt ( ) ; info [ 6 ] = infoFile . readInt ( ) ; info [ 7 ] = infoFile . readInt ( ) ; } catch ( Exception e ) { log . warn ( "Exception reading flv file information data" , e ) ; } return info ; }
Read flv file information from pre - finalization file .
37,595
private void updateInfoFile ( ) { try ( RandomAccessFile infoFile = new RandomAccessFile ( filePath + ".info" , "rw" ) ) { infoFile . writeInt ( audioCodecId ) ; infoFile . writeInt ( videoCodecId ) ; infoFile . writeInt ( duration ) ; infoFile . writeInt ( audioDataSize ) ; infoFile . writeInt ( soundRate ) ; infoFile . writeInt ( soundSize ) ; infoFile . writeInt ( soundType ? 1 : 0 ) ; infoFile . writeInt ( videoDataSize ) ; } catch ( Exception e ) { log . warn ( "Exception writing flv file information data" , e ) ; } }
Write or update flv file information into the pre - finalization file .
37,596
public void close ( ) { log . debug ( "close" ) ; boolean locked = false ; try { locked = lock . tryAcquire ( 500L , TimeUnit . MILLISECONDS ) ; if ( locked ) { finalizeFlv ( ) ; } } catch ( InterruptedException e ) { log . warn ( "Exception acquiring lock" , e ) ; } finally { if ( locked ) { lock . release ( ) ; } if ( executor != null && ! executor . isTerminated ( ) ) { executor . shutdown ( ) ; } } }
Ends the writing process then merges the data file with the flv file header and metadata .
37,597
public static boolean repair ( String path , Integer audioId , Integer videoId ) throws InterruptedException { boolean result = false ; FLVWriter writer = null ; log . debug ( "Serial file path: " + path ) ; System . out . println ( "Serial file path: " + path ) ; if ( path . endsWith ( ".ser" ) ) { File ser = new File ( path ) ; if ( ser . exists ( ) && ser . canRead ( ) ) { ser = null ; String flvPath = path . substring ( 0 , path . lastIndexOf ( '.' ) ) ; log . debug ( "Flv file path: " + flvPath ) ; System . out . println ( "Flv file path: " + flvPath ) ; File inf = new File ( flvPath + ".info" ) ; if ( inf . exists ( ) && inf . canRead ( ) ) { inf = null ; writer = new FLVWriter ( true , flvPath ) ; } else { log . debug ( "Info file was not found or could not be read, using dummy data" ) ; System . err . println ( "Info file was not found or could not be read, using dummy data" ) ; writer = new FLVWriter ( true , flvPath ) ; int acid = audioId == null ? 11 : audioId , vcid = videoId == null ? 7 : videoId ; writer . setAudioCodecId ( acid ) ; writer . setVideoCodecId ( vcid ) ; writer . setDuration ( Integer . MAX_VALUE ) ; writer . setSoundRate ( 16000 ) ; writer . setSoundSize ( 16 ) ; } } else { log . error ( "Serial file was not found or could not be read" ) ; System . err . println ( "Serial file was not found or could not be read" ) ; } } else { log . error ( "Provide the path to your .ser file" ) ; System . err . println ( "Serial file was not found or could not be read" ) ; } if ( writer != null ) { Future < ? > future = writer . submit ( writer . new FLVFinalizer ( ) ) ; try { future . get ( ) ; log . debug ( "File repair completed" ) ; System . out . println ( "File repair completed" ) ; result = true ; } catch ( Exception e ) { log . warn ( "Exception while finalizing: {}" , path , e ) ; } } return result ; }
Allows repair of flv files if . info and . ser files still exist .
37,598
private Future < ? > submit ( FLVFinalizer flvFinalizer ) { if ( executor != null && ! executor . isTerminated ( ) ) { return executor . submit ( flvFinalizer ) ; } return null ; }
Submits a finalizer internally .
37,599
public static void main ( String [ ] args ) throws InterruptedException { if ( args == null || args [ 0 ] == null ) { System . err . println ( "Provide the path to your .ser file" ) ; } else { repair ( args [ 0 ] , args . length > 1 && args [ 1 ] != null ? Integer . valueOf ( args [ 1 ] ) : null , args . length > 2 && args [ 2 ] != null ? Integer . valueOf ( args [ 2 ] ) : null ) ; } System . exit ( 0 ) ; }
Exposed to allow repair of flv files if . info and . ser files still exist .