idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
13,300
public String childValue ( String name , String namespace ) { for ( XNElement e : children ) { if ( Objects . equals ( e . name , name ) && Objects . equals ( e . namespace , namespace ) ) { return e . content ; } } return null ; }
Returns the content of the first child which has the given name .
13,301
public void copyFrom ( XNElement other ) { content = other . content ; userObject = other . userObject ; for ( Map . Entry < XAttributeName , String > me : other . attributes . entrySet ( ) ) { XAttributeName an = new XAttributeName ( me . getKey ( ) . name , me . getKey ( ) . namespace , me . getKey ( ) . prefix ) ; attributes . put ( an , me . getValue ( ) ) ; } for ( XNElement c : children ) { XNElement c0 = c . copy ( ) ; c0 . parent = this ; children . add ( c0 ) ; } }
Copy the attributes and child elements from the other element .
13,302
protected Pair < String , String > createPrefix ( Map < String , String > nss , String currentNamespace , String currentPrefix ) { if ( currentNamespace == null ) { return Pair . of ( null , null ) ; } String pf = nss . get ( currentNamespace ) ; if ( pf != null ) { return Pair . of ( pf , null ) ; } int nsc = 0 ; pf = currentPrefix ; if ( pf == null ) { pf = "ns" + nsc ; } outer : while ( ! Thread . currentThread ( ) . isInterrupted ( ) ) { for ( Map . Entry < String , String > e : nss . entrySet ( ) ) { if ( Objects . equals ( e . getValue ( ) , pf ) ) { nsc ++ ; pf = "ns" + nsc ; continue outer ; } } break ; } nss . put ( currentNamespace , pf ) ; StringBuilder xmlns = new StringBuilder ( ) ; xmlns . append ( " xmlns" ) . append ( pf != null && pf . length ( ) > 0 ? ":" : "" ) . append ( pf != null && pf . length ( ) > 0 ? pf : "" ) . append ( "='" ) . append ( sanitize ( currentNamespace ) ) . append ( "'" ) ; ; return Pair . of ( pf , xmlns . toString ( ) ) ; }
Generate a new prefix if the current is empty or already exists but with a different URI .
13,303
public String get ( String attributeName ) { String attr = attributes . get ( new XAttributeName ( attributeName , null , null ) ) ; if ( attr == null ) { for ( XAttributeName n : attributes . keySet ( ) ) { if ( Objects . equals ( n . name , attributeName ) ) { return attributes . get ( n ) ; } } } return attr ; }
Retrieve the first attribute which has the given local attribute name .
13,304
public String get ( String attributeName , String attributeNamespace ) { return attributes . get ( new XAttributeName ( attributeName , attributeNamespace , null ) ) ; }
Retrieve the specific attribute .
13,305
public boolean getBoolean ( String attribute ) { String s = get ( attribute ) ; if ( "true" . equals ( s ) || "1" . equals ( s ) ) { return true ; } else if ( "false" . equals ( s ) || "0" . equals ( s ) ) { return false ; } throw new IllegalArgumentException ( "Attribute " + attribute + " is non-boolean" ) ; }
Retrieve a value of a boolean attribute . Throws IllegalArgumentException if the attribute is missing or not of type boolean .
13,306
public double getDouble ( String name , String namespace ) { return Double . parseDouble ( get ( name , namespace ) ) ; }
Returns the attribute as a double value .
13,307
public double getDouble ( String name , String namespace , double defaultValue ) { String v = get ( name , namespace ) ; return v != null ? Double . parseDouble ( v ) : defaultValue ; }
Returns the attribute as a double value or the default .
13,308
public long getLong ( String attribute , String namespace ) { return Long . parseLong ( get ( attribute , namespace ) ) ; }
Retrieve an integer attribute or throw an exception if not exists .
13,309
public boolean hasName ( String name , String namespace ) { return hasName ( name ) && Objects . equals ( this . namespace , namespace ) ; }
Test if this XElement has the given name and namespace .
13,310
public int intValue ( String name , String namespace ) { String s = childValue ( name , namespace ) ; if ( s != null ) { return Integer . parseInt ( s ) ; } throw new IllegalArgumentException ( this + ": content: " + name ) ; }
Returns an integer value of the supplied child or throws an exception if missing .
13,311
public long longValue ( String name , String namespace ) { String s = childValue ( name , namespace ) ; if ( s != null ) { return Long . parseLong ( s ) ; } throw new IllegalArgumentException ( this + ": content: " + name ) ; }
Returns a long value of the supplied child or throws an exception if missing .
13,312
public void save ( Writer stream ) throws IOException { final PrintWriter out = new PrintWriter ( new BufferedWriter ( stream ) ) ; try { out . println ( "<?xml version='1.0' encoding='UTF-8'?>" ) ; toStringRep ( "" , new HashMap < String , String > ( ) , new XNAppender ( ) { public XNAppender append ( Object o ) { out . print ( o ) ; return this ; } public int length ( ) { return 0 ; } } , null ) ; } finally { out . flush ( ) ; } }
Save this XML into the given writer . Does not close the writer .
13,313
public void save ( XMLStreamWriter stream ) throws XMLStreamException { stream . writeStartDocument ( "UTF-8" , "1.0" ) ; saveInternal ( stream ) ; stream . writeEndDocument ( ) ; }
Save the tree into the given XML stream writer .
13,314
protected void saveInternal ( XMLStreamWriter stream ) throws XMLStreamException { if ( namespace != null ) { stream . writeStartElement ( prefix , namespace , name ) ; } else { stream . writeStartElement ( name ) ; } for ( Map . Entry < XAttributeName , String > a : attributes . entrySet ( ) ) { XAttributeName an = a . getKey ( ) ; if ( an . namespace != null ) { stream . writeAttribute ( an . prefix , an . namespace , an . name , a . getValue ( ) ) ; } else { stream . writeAttribute ( an . name , a . getValue ( ) ) ; } } if ( content != null ) { stream . writeCharacters ( content ) ; } else { for ( XNElement e : children ) { e . saveInternal ( stream ) ; } } stream . writeEndElement ( ) ; }
Store the element s content and recursively call itself for children .
13,315
public void set ( Object ... nameValues ) { if ( nameValues . length % 2 != 0 ) { throw new IllegalArgumentException ( "Names and values must be in pairs" ) ; } for ( int i = 0 ; i < nameValues . length ; i += 2 ) { set ( ( String ) nameValues [ i ] , nameValues [ i + 1 ] ) ; } }
Set a multitude of attribute names and values .
13,316
public void set ( String name , String namespace , Object value ) { if ( value != null ) { if ( value instanceof Date ) { attributes . put ( new XAttributeName ( name , namespace , null ) , formatDateTime ( ( Date ) value ) ) ; } else { attributes . put ( new XAttributeName ( name , namespace , null ) , value . toString ( ) ) ; } } else { attributes . remove ( new XAttributeName ( name , namespace , null ) ) ; } }
Set an attribute value identified by a local name and namespace .
13,317
@ SuppressWarnings ( "unchecked" ) public < T > T set ( T newUserObject ) { T result = ( T ) userObject ; userObject = newUserObject ; return result ; }
Replace the associated user object with a new object .
13,318
DecodeAux make_decode_tree ( ) { int top = 0 ; DecodeAux t = new DecodeAux ( ) ; int [ ] ptr0 = t . ptr0 = new int [ entries * 2 ] ; int [ ] ptr1 = t . ptr1 = new int [ entries * 2 ] ; int [ ] codelist = make_words ( c . lengthlist , c . entries ) ; if ( codelist == null ) return ( null ) ; for ( int i = 0 ; i < entries ; i ++ ) { if ( c . lengthlist [ i ] > 0 ) { int ptr = 0 ; int j ; for ( j = 0 ; j < c . lengthlist [ i ] - 1 ; j ++ ) { int bit = ( codelist [ i ] >>> j ) & 1 ; if ( bit == 0 ) { if ( ptr0 [ ptr ] == 0 ) { ptr0 [ ptr ] = ++ top ; } ptr = ptr0 [ ptr ] ; } else { if ( ptr1 [ ptr ] == 0 ) { ptr1 [ ptr ] = ++ top ; } ptr = ptr1 [ ptr ] ; } } if ( ( ( codelist [ i ] >>> j ) & 1 ) == 0 ) { ptr0 [ ptr ] = - i ; } else { ptr1 [ ptr ] = - i ; } } } t . tabn = Util . ilog ( entries ) - 4 ; if ( t . tabn < 5 ) t . tabn = 5 ; int n = 1 << t . tabn ; t . tab = new int [ n ] ; t . tabl = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int p = 0 ; int j = 0 ; for ( j = 0 ; j < t . tabn && ( p > 0 || j == 0 ) ; j ++ ) { if ( ( i & ( 1 << j ) ) != 0 ) { p = ptr1 [ p ] ; } else { p = ptr0 [ p ] ; } } t . tab [ i ] = p ; t . tabl [ i ] = j ; } return ( t ) ; }
build the decode helper tree from the codewords
13,319
public void stopPlayback ( ) { if ( isNotStoppingNorStopped ( ) ) { setIsStopping ( ) ; while ( ! isStopped ( ) ) { try { Thread . sleep ( 1 ) ; } catch ( InterruptedException ex ) { } } stopLine ( ) ; } }
Stopps the playback . Will wait until stopp is done
13,320
public void pausePlayback ( ) { if ( isNotPausingNorPaused ( ) && isNotStoppingNorStopped ( ) ) { setIsPausing ( ) ; while ( ! isPaused ( ) && ! isStopped ( ) ) { try { Thread . sleep ( 1 ) ; } catch ( InterruptedException ex ) { } } stopLine ( ) ; } else if ( isPaused ( ) ) { startLine ( ) ; setIsPlaying ( ) ; } }
Halts the playback Will wait until playback halted
13,321
public ISynchronizationPoint < IOException > start ( byte priority , WorkProgress progress , long work ) { JoinPoint < IOException > jp = new JoinPoint < > ( ) ; jp . addToJoin ( 1 ) ; processDirectory ( "" , root , rootObject , jp , priority , progress , work ) ; jp . start ( ) ; return jp ; }
Start the directory analysis .
13,322
public static < N extends Number > int getRHD ( N number ) { String numberAsString = String . valueOf ( number ) ; return numberAsString . substring ( numberAsString . lastIndexOf ( '.' ) + 1 ) . length ( ) ; }
Returns the number of places after the decimal separator of the given number .
13,323
public static < O extends Object > void notEmpty ( Iterable < O > coll ) { if ( ! validation ) return ; notNull ( coll ) ; if ( ! coll . iterator ( ) . hasNext ( ) ) throw new ParameterException ( ErrorCode . EMPTY ) ; }
Checks if the given iterable object is empty .
13,324
public static < O extends Object > void notEmpty ( O [ ] arr ) { if ( ! validation ) return ; notNull ( arr ) ; if ( arr . length == 0 ) throw new ParameterException ( ErrorCode . EMPTY ) ; }
Checks if the given array is empty .
13,325
public static < T extends Object > void bigger ( Comparable < T > value , T reference ) { if ( ! validation ) return ; Validate . notNull ( value ) ; Validate . notNull ( reference ) ; if ( value . compareTo ( reference ) <= 0 ) throw new ParameterException ( ErrorCode . RANGEVIOLATION , "Parameter is smaller or equal " + reference ) ; }
Checks if the given value is bigger than the reference value .
13,326
public static < T , V extends Object > void type ( V value , Class < T > type ) { if ( ! validation ) return ; notNull ( value ) ; notNull ( type ) ; if ( ! type . isAssignableFrom ( value . getClass ( ) ) ) { throw new TypeException ( type . getCanonicalName ( ) ) ; } }
Checks if a given value has a specific type .
13,327
public static < T , V extends Object > void type ( Collection < V > valueColl , Class < T > type ) { for ( V value : valueColl ) type ( value , type ) ; }
Checks if the elements of a given collection have a specific type .
13,328
public static void notPositive ( Integer value ) { if ( ! validation ) return ; notNull ( value ) ; if ( value > 0 ) throw new ParameterException ( ErrorCode . POSITIVE ) ; }
Checks if the given integer is NOT positive .
13,329
public static void notNegative ( Integer value ) { if ( ! validation ) return ; Validate . notNull ( value ) ; if ( value < 0 ) throw new ParameterException ( ErrorCode . NEGATIVE ) ; }
Checks if the given integer is NOT negative .
13,330
public static void positive ( Long value ) { if ( ! validation ) return ; notNull ( value ) ; if ( value <= 0 ) throw new ParameterException ( ErrorCode . NOTPOSITIVE ) ; }
Checks if the given long value is positive .
13,331
public static void notPositive ( Long value ) { if ( ! validation ) return ; notNull ( value ) ; if ( value > 0 ) throw new ParameterException ( ErrorCode . POSITIVE ) ; }
Checks if the given long is NOT positive .
13,332
public static void notPositive ( Long value , String message ) { if ( ! validation ) return ; notNull ( value ) ; notNull ( message ) ; if ( value > 0 ) throw new ParameterException ( ErrorCode . POSITIVE , message ) ; }
Checks if the given long value is NOT positive .
13,333
public static void notNegative ( Long value ) { if ( ! validation ) return ; notNull ( value ) ; if ( value < 0 ) throw new ParameterException ( ErrorCode . NEGATIVE ) ; }
Checks if the given long value is NOT negative .
13,334
public static void positive ( Double value ) { if ( ! validation ) return ; notNull ( value ) ; if ( value <= 0 ) throw new ParameterException ( ErrorCode . NOTPOSITIVE ) ; }
Checks if the given double value is positive .
13,335
public static void notPositive ( Double value ) { if ( ! validation ) return ; notNull ( value ) ; if ( value > 0 ) throw new ParameterException ( ErrorCode . POSITIVE ) ; }
Checks if the given double is NOT positive .
13,336
public static Integer isInteger ( String value ) { Validate . notNull ( value ) ; Validate . notEmpty ( value ) ; Integer intValue = null ; try { intValue = Integer . parseInt ( value ) ; } catch ( NumberFormatException e ) { throw new TypeException ( "Integer" ) ; } return intValue ; }
Checks if the given String is an integer value .
13,337
public static Double isDouble ( String value ) { Validate . notNull ( value ) ; Validate . notEmpty ( value ) ; Double doubleValue = null ; try { doubleValue = Double . parseDouble ( value ) ; } catch ( NumberFormatException e ) { throw new TypeException ( "Double" ) ; } return doubleValue ; }
Checks if the given String is a double value .
13,338
public static File directory ( File file ) { Validate . exists ( file ) ; if ( ! file . isDirectory ( ) ) throw new ParameterException ( "\"" + file + "\" is not a directory!" ) ; return file ; }
Checks if the given file exists and is a directory .
13,339
public static File noDirectory ( File file ) { Validate . exists ( file ) ; if ( file . isDirectory ( ) ) throw new ParameterException ( "\"" + file + "\" is a directory!" ) ; return file ; }
Checks if the given file exists and is not a directory .
13,340
protected void notifyDispatcher ( ) { if ( threads != null ) { synchronized ( threads ) { threads . notifyAll ( ) ; for ( Thread thread : threads ) { ( ( DispatcherThread ) thread ) . setChanged ( true ) ; } } } }
Notification about queue change
13,341
public static UserAgent newUserAgent ( Settings settings ) { UserAgent . Factory factory = Factories . newInstance ( settings , Keys . UA_FACTORY_KEY ) ; return factory . newUserAgent ( settings ) ; }
Creates a new UserAgent with the given configuration ; the UserAgent must be started .
13,342
public static ServiceAgent newServiceAgent ( Settings settings ) { ServiceAgent . Factory factory = Factories . newInstance ( settings , Keys . SA_FACTORY_KEY ) ; return factory . newServiceAgent ( settings ) ; }
Creates a new ServiceAgent with the given configuration ; the ServiceAgent must be started .
13,343
protected void validate ( File file , ValidationOptions option ) { if ( ! file . exists ( ) ) { this . errors . addError ( "file <{}> does not exist in file system" , file . getAbsolutePath ( ) ) ; } else if ( ! file . isFile ( ) ) { this . errors . addError ( "file <{}> is not a file" , file . getAbsolutePath ( ) ) ; } if ( file . isHidden ( ) ) { this . errors . addError ( "file <{}> is a hidden file" , file . getAbsolutePath ( ) ) ; } else { switch ( option ) { case AS_SOURCE : if ( ! file . canRead ( ) ) { this . errors . addError ( "file <{}> is not readable" , file . getAbsolutePath ( ) ) ; } break ; case AS_SOURCE_AND_TARGET : if ( ! file . canRead ( ) ) { this . errors . addError ( "file <{}> is not readable" , file . getAbsolutePath ( ) ) ; } if ( ! file . canWrite ( ) ) { this . errors . addError ( "file <{}> is not writable" , file . getAbsolutePath ( ) ) ; } break ; case AS_TARGET : if ( ! file . canWrite ( ) ) { this . errors . addError ( "file <{}> is not writable" , file . getAbsolutePath ( ) ) ; } break ; } } }
Does the actual validation .
13,344
private void insertionSort ( int left , int right ) { for ( int p = left + 1 ; p <= right ; p ++ ) { byte [ ] tmpRange = ranges [ p ] ; String tmpFilename = filenames [ p ] ; int j ; for ( j = p ; j > left && KeyUtils . compareKey ( tmpRange , ranges [ j - 1 ] ) < 0 ; j -- ) { ranges [ j ] = ranges [ j - 1 ] ; filenames [ j ] = filenames [ j - 1 ] ; } ranges [ j ] = tmpRange ; filenames [ j ] = tmpFilename ; } }
Internal insertion sort routine for subarrays of ranges that is used by quicksort .
13,345
protected void swap ( int i , int j ) { byte [ ] ltemp = ranges [ i ] ; ranges [ i ] = ranges [ j ] ; ranges [ j ] = ltemp ; String tempFilename = filenames [ i ] ; filenames [ i ] = filenames [ j ] ; filenames [ j ] = tempFilename ; }
Swaps the elements of the ith position with the elements of the jth position of all three arrays .
13,346
public void postStartSetUp ( ) throws SQLException { PostStartContribution poll ; while ( ( poll = postStartContributions . poll ( ) ) != null ) { poll . apply ( this ) ; } }
Invoked after server has started up . Here the database can connect to himself .
13,347
private boolean bucketsEmpty ( ) { for ( int i = 0 ; i < numberOfBuckets ; i ++ ) { if ( bucketContainer . getBucket ( i ) . elementsInBucket > 0 ) { return false ; } } return true ; }
checks if the buckets are empty . Returns true only if all buckets are empty .
13,348
protected List < ServiceInfo > matchServices ( ServiceType serviceType , String language , Scopes scopes , String filter ) { if ( logger . isLoggable ( Level . FINEST ) ) logger . finest ( "DirectoryAgent " + this + " matching ServiceType " + serviceType + ", language " + language + ", scopes " + scopes + ", filter " + filter ) ; return services . match ( serviceType , language , scopes , new FilterParser ( ) . parse ( filter ) ) ; }
Matches the services of this directory agent against the given arguments .
13,349
public Data get ( Key key ) { synchronized ( cache ) { Pair < Data , Long > p = cache . get ( key ) ; if ( p != null ) { p . setValue2 ( Long . valueOf ( System . currentTimeMillis ( ) ) ) ; return p . getValue1 ( ) ; } p = new Pair < > ( provider . provide ( key ) , Long . valueOf ( System . currentTimeMillis ( ) ) ) ; cache . put ( key , p ) ; return p . getValue1 ( ) ; } }
Get a data or create it using the provider .
13,350
public void write ( BitOutputStream os ) throws IOException { os . writeRawULong ( sampleNumber , SEEKPOINT_SAMPLE_NUMBER_LEN ) ; os . writeRawULong ( streamOffset , SEEKPOINT_STREAM_OFFSET_LEN ) ; os . writeRawUInt ( frameSamples , SEEKPOINT_FRAME_SAMPLES_LEN ) ; }
Write out an individual seek point .
13,351
public final void addSubLoader ( AbstractClassLoader loader ) { if ( subLoaders == null ) subLoaders = new ArrayList < > ( ) ; subLoaders . add ( loader ) ; }
Add a class loader from a resource contained by this class loader for example an inner jar file .
13,352
public static ISynchronizationPoint < NoException > getClassLoadingSP ( String name ) { synchronized ( classLoadingSP ) { Pair < Thread , JoinPoint < NoException > > p = classLoadingSP . get ( name ) ; if ( p == null ) { JoinPoint < NoException > jp = new JoinPoint < NoException > ( ) ; jp . addToJoin ( 1 ) ; jp . start ( ) ; classLoadingSP . put ( name , new Pair < Thread , JoinPoint < NoException > > ( Thread . currentThread ( ) , jp ) ) ; return null ; } if ( p . getValue1 ( ) == Thread . currentThread ( ) ) { p . getValue2 ( ) . addToJoin ( 1 ) ; return null ; } return p . getValue2 ( ) ; } }
Get the synchronized object for loading the given class .
13,353
public static void releaseClassLoadingSP ( String name ) { synchronized ( classLoadingSP ) { Pair < Thread , JoinPoint < NoException > > sp = classLoadingSP . get ( name ) ; JoinPoint < NoException > jp = sp . getValue2 ( ) ; jp . joined ( ) ; if ( jp . isUnblocked ( ) ) classLoadingSP . remove ( name ) ; } }
Release the synchronized object for loading the given class .
13,354
public final IO . Readable open ( String path , byte priority ) throws IOException { Object pointer = getResourcePointer ( path ) ; AbstractClassLoader cl = this ; if ( pointer == null ) { if ( subLoaders != null ) for ( AbstractClassLoader sub : subLoaders ) { pointer = sub . getResourcePointer ( path ) ; if ( pointer != null ) { cl = sub ; break ; } } if ( pointer == null ) throw new FileNotFoundException ( path ) ; } return cl . openResourcePointer ( pointer , priority ) ; }
Open a resource .
13,355
public final Iterable < URL > getResourcesURL ( String name ) { URL url = loadResourceURL ( name ) ; if ( subLoaders == null ) return url != null ? Collections . singletonList ( url ) : null ; CompoundCollection < URL > list = new CompoundCollection < > ( ) ; if ( url != null ) list . addSingleton ( url ) ; for ( AbstractClassLoader sub : subLoaders ) { Iterable < URL > urls = sub . getResourcesURL ( name ) ; if ( urls != null ) list . add ( urls ) ; } return list ; }
Search for all resources with the same path .
13,356
private long findFrame ( RandomAccessInputStream raf , int offset ) throws IOException { long loc = - 1 ; raf . seek ( offset ) ; while ( loc == - 1 ) { byte test = raf . readByte ( ) ; if ( ( test & 0xFF ) == 0xFF ) { test = raf . readByte ( ) ; if ( ( test & 0xE0 ) == 0xE0 ) { return raf . getFilePointer ( ) - 2 ; } } } return - 1 ; }
Searches through the file and finds the first occurrence of an mpeg frame . Returns the location of the header of the frame .
13,357
private void readHeader ( RandomAccessInputStream raf , long location ) throws IOException { byte [ ] head = new byte [ HEADER_SIZE ] ; raf . seek ( location ) ; if ( raf . read ( head ) != HEADER_SIZE ) { throw new IOException ( "Error reading MPEG frame header." ) ; } version = ( head [ 1 ] & 0x18 ) >> 3 ; layer = ( head [ 1 ] & 0x06 ) >> 1 ; crced = ( head [ 1 ] & 0x01 ) == 0 ; bitRate = findBitRate ( ( head [ 2 ] & 0xF0 ) >> 4 , version , layer ) ; sampleRate = findSampleRate ( ( head [ 2 ] & 0x0C ) >> 2 , version ) ; channelMode = ( head [ 3 ] & 0xC0 ) >> 6 ; copyrighted = ( head [ 3 ] & 0x08 ) != 0 ; original = ( head [ 3 ] & 0x04 ) != 0 ; emphasis = head [ 3 ] & 0x03 ; }
Read in all the information found in the mpeg header .
13,358
private int findBitRate ( int bitrateIndex , int version , int layer ) { int ind = - 1 ; if ( version == MPEG_V_1 ) { if ( layer == MPEG_L_1 ) { ind = 0 ; } else if ( layer == MPEG_L_2 ) { ind = 1 ; } else if ( layer == MPEG_L_3 ) { ind = 2 ; } } else if ( ( version == MPEG_V_2 ) || ( version == MPEG_V_25 ) ) { if ( layer == MPEG_L_1 ) { ind = 3 ; } else if ( ( layer == MPEG_L_2 ) || ( layer == MPEG_L_3 ) ) { ind = 4 ; } } if ( ( ind != - 1 ) && ( bitrateIndex >= 0 ) && ( bitrateIndex <= 15 ) ) { return bitrateTable [ bitrateIndex ] [ ind ] ; } return - 1 ; }
Based on the bitrate index found in the header try to find and set the bitrate from the table .
13,359
private int findSampleRate ( int sampleIndex , int version ) { int ind = - 1 ; switch ( version ) { case MPEG_V_1 : ind = 0 ; break ; case MPEG_V_2 : ind = 1 ; break ; case MPEG_V_25 : ind = 2 ; } if ( ( ind != - 1 ) && ( sampleIndex >= 0 ) && ( sampleIndex <= 3 ) ) { return sampleTable [ sampleIndex ] [ ind ] ; } return - 1 ; }
Based on the sample rate index found in the header attempt to lookup and set the sample rate from the table .
13,360
public String getEmphasis ( ) { String str = null ; if ( ( emphasis >= 0 ) && ( emphasis < emphasisLabels . length ) ) { str = emphasisLabels [ emphasis ] ; } return str ; }
Returns the emphasis . I don t know what this means it just does it ...
13,361
private boolean checkHeader ( RandomAccessInputStream raf ) throws FileNotFoundException , IOException { boolean retval = false ; if ( raf . length ( ) > TAG_SIZE ) { raf . seek ( raf . length ( ) - TAG_SIZE ) ; byte [ ] buf = new byte [ 3 ] ; if ( raf . read ( buf ) != 3 ) { throw new IOException ( "Error encountered reading ID3 header" ) ; } else { String result = new String ( buf , 0 , 3 , ENC_TYPE ) ; retval = result . equals ( TAG_START ) ; } } return retval ; }
Checks whether a header for the id3 tag exists yet
13,362
private void readTag ( RandomAccessInputStream raf ) throws FileNotFoundException , IOException { raf . seek ( raf . length ( ) - TAG_SIZE ) ; byte [ ] buf = new byte [ TAG_SIZE ] ; raf . read ( buf , 0 , TAG_SIZE ) ; String tag = new String ( buf , 0 , TAG_SIZE , ENC_TYPE ) ; int start = TAG_START . length ( ) ; title = tag . substring ( start , start += TITLE_SIZE ) ; artist = tag . substring ( start , start += ARTIST_SIZE ) ; album = tag . substring ( start , start += ALBUM_SIZE ) ; year = tag . substring ( start , start += YEAR_SIZE ) ; comment = tag . substring ( start , start += COMMENT_SIZE ) ; track = ( int ) tag . charAt ( TRACK_LOCATION ) ; genre = ( int ) tag . charAt ( GENRE_LOCATION ) ; }
Reads the data from the id3v1 tag
13,363
public void writeTag ( RandomAccessFile raf ) throws FileNotFoundException , IOException { if ( headerExists ) raf . seek ( raf . length ( ) - TAG_SIZE ) ; else raf . seek ( raf . length ( ) ) ; raf . write ( Helpers . getBytesFromString ( TAG_START , TAG_START . length ( ) , ENC_TYPE ) ) ; raf . write ( Helpers . getBytesFromString ( title , TITLE_SIZE , ENC_TYPE ) ) ; raf . write ( Helpers . getBytesFromString ( artist , ARTIST_SIZE , ENC_TYPE ) ) ; raf . write ( Helpers . getBytesFromString ( album , ALBUM_SIZE , ENC_TYPE ) ) ; raf . write ( Helpers . getBytesFromString ( year , YEAR_SIZE , ENC_TYPE ) ) ; raf . write ( Helpers . getBytesFromString ( comment , COMMENT_SIZE , ENC_TYPE ) ) ; raf . write ( ( byte ) track ) ; raf . write ( ( byte ) genre ) ; headerExists = true ; }
Writes the information in this tag to the file specified in the constructor . If a tag does not exist one will be created . If a tag already exists it will be overwritten .
13,364
public void removeTag ( RandomAccessFile raf ) throws FileNotFoundException , IOException { if ( headerExists ) { raf . setLength ( raf . length ( ) - TAG_SIZE ) ; headerExists = false ; } }
Removes the id3v1 tag from the file specified in the constructor by reducing the file size
13,365
public void setTitle ( String newTitle ) { if ( newTitle . length ( ) > TITLE_SIZE ) { title = newTitle . substring ( 0 , TITLE_SIZE ) ; } else { title = newTitle ; } }
Set the title field of the tag . The maximum size of the String is 30 . If the size exceeds the maximum size the String will be truncated .
13,366
public void setArtist ( String newArtist ) { if ( newArtist . length ( ) > ARTIST_SIZE ) { artist = newArtist . substring ( 0 , ARTIST_SIZE ) ; } else { artist = newArtist ; } }
Set the artist field of the tag . The maximum size of the String is 30 . If the size exceeds the maximum size the String will be truncated .
13,367
public void setAlbum ( String newAlbum ) { if ( newAlbum . length ( ) > ALBUM_SIZE ) { album = newAlbum . substring ( 0 , ALBUM_SIZE ) ; } else { album = newAlbum ; } }
Set the album field of the tag . The maximum size of the String is 30 . If the size exceeds the maximum size the String will be truncated .
13,368
public void setYear ( String newYear ) { if ( newYear . length ( ) > YEAR_SIZE ) { year = newYear . substring ( 0 , YEAR_SIZE ) ; } else { year = newYear ; } }
Set the year field of the tag . The maximum size of the String is 4 . If the size exceeds the maximum size the String will be truncated .
13,369
public void setComment ( String newComment ) { if ( comment . length ( ) > COMMENT_SIZE ) { comment = newComment . substring ( 0 , COMMENT_SIZE ) ; } else { comment = newComment ; } }
Set the comment field of the tag . The maximum size of the String is 30 . If the size exceeds the maximum size the String will be truncated .
13,370
public void ensureSize ( int maxPartitionOrder ) { if ( capacityByOrder >= maxPartitionOrder ) return ; parameters = new int [ ( 1 << maxPartitionOrder ) ] ; rawBits = new int [ ( 1 << maxPartitionOrder ) ] ; capacityByOrder = maxPartitionOrder ; }
Ensure enough menory has been allocated .
13,371
public static boolean cs_lusol ( int order , Scs A , float [ ] b , float tol ) { float [ ] x ; Scss S ; Scsn N ; int n ; boolean ok ; if ( ! Scs_util . CS_CSC ( A ) || b == null ) return ( false ) ; n = A . n ; S = Scs_sqr . cs_sqr ( order , A , false ) ; N = Scs_lu . cs_lu ( A , S , tol ) ; x = new float [ n ] ; ok = ( S != null && N != null ) ; if ( ok ) { Scs_ipvec . cs_ipvec ( N . pinv , b , x , n ) ; Scs_lsolve . cs_lsolve ( N . L , x ) ; Scs_usolve . cs_usolve ( N . U , x ) ; Scs_ipvec . cs_ipvec ( S . q , x , b , n ) ; } return ( ok ) ; }
Solves Ax = b where A is square and nonsingular . b overwritten with solution . Partial pivoting if tol = 1 . f
13,372
public static boolean matches ( Collection < PathPattern > patterns , List < String > path ) { for ( PathPattern pattern : patterns ) if ( pattern . matches ( path ) ) return true ; return false ; }
Return true if the given path elements match at least one of the given pattern .
13,373
public static OutputStream get ( IO . Writable io ) { if ( io instanceof IOFromOutputStream ) return ( ( IOFromOutputStream ) io ) . getOutputStream ( ) ; if ( io instanceof IO . WritableByteStream ) return new ByteStream ( ( IO . WritableByteStream ) io ) ; return new Writable ( io ) ; }
Create an OutputStream based on the given writable IO .
13,374
public void close ( ) { LOGGER . entering ( CLASS_NAME , "close" ) ; synchronized ( lock ) { if ( serviceAgent != null ) { serviceRegistration . unregister ( ) ; if ( LOGGER . isLoggable ( Level . FINER ) ) LOGGER . finer ( "Service Agent " + this + " stopping..." ) ; serviceAgent . stop ( ) ; if ( LOGGER . isLoggable ( Level . FINE ) ) LOGGER . fine ( "Service Agent " + this + " stopped successfully" ) ; } } LOGGER . exiting ( CLASS_NAME , "close" ) ; }
Shuts down the user agent if one exists .
13,375
static void checkProperties ( Map < String , Object > properties , String [ ] disallowedProperties ) { if ( properties == null || properties . isEmpty ( ) ) { return ; } HashSet < String > disallowed = new HashSet < > ( properties . keySet ( ) ) ; disallowed . retainAll ( Arrays . asList ( disallowedProperties ) ) ; if ( ! disallowed . isEmpty ( ) ) { throw new IllegalArgumentException ( "The following properties are reserved for this type of entity: " + Arrays . asList ( disallowedProperties ) ) ; } }
If the properties map contains a key from the disallowed properties throw an exception .
13,376
static void updateProperties ( Element e , Map < String , Object > properties , String [ ] disallowedProperties ) { if ( properties == null ) { return ; } Set < String > disallowed = new HashSet < > ( Arrays . asList ( disallowedProperties ) ) ; Spliterator < Property < ? > > sp = Spliterators . spliteratorUnknownSize ( e . properties ( ) , Spliterator . NONNULL & Spliterator . IMMUTABLE ) ; Property < ? > [ ] toRemove = StreamSupport . stream ( sp , false ) . filter ( ( p ) -> ! disallowed . contains ( p . key ( ) ) && ! properties . containsKey ( p . key ( ) ) ) . toArray ( Property [ ] :: new ) ; for ( Property < ? > p : toRemove ) { p . remove ( ) ; } properties . forEach ( ( p , v ) -> { if ( ! disallowed . contains ( p ) ) { e . property ( p , v ) ; } } ) ; }
Updates the properties of the element disregarding any changes of the disallowed properties
13,377
static Constants . Type getType ( Vertex v ) { return Constants . Type . valueOf ( ( String ) v . property ( __type . name ( ) ) . value ( ) ) ; }
Gets the type of the entity that the provided vertex represents .
13,378
private void examineNode ( Node node , boolean attributesOnly ) { while ( node != null && node . getNodeType ( ) == Node . COMMENT_NODE ) { node = node . getNextSibling ( ) ; } if ( node != null ) { NamedNodeMap attributes = node . getAttributes ( ) ; if ( attributes != null ) { for ( int i = 0 ; i < attributes . getLength ( ) ; i ++ ) { Node attribute = attributes . item ( i ) ; storeAttribute ( ( Attr ) attribute ) ; } } if ( ! attributesOnly ) { NodeList chields = node . getChildNodes ( ) ; for ( int i = 0 ; i < chields . getLength ( ) ; i ++ ) { Node chield = chields . item ( i ) ; if ( chield . getNodeType ( ) == Node . ELEMENT_NODE ) examineNode ( chield , false ) ; } } } }
A single node is read the namespace attributes are extracted and stored .
13,379
protected Entity getEntity ( ) throws ConverterException { final String _entity = getConfig ( "entity" ) ; if ( _entity == null ) { throw new ConverterException ( "collection.converter.entity.cannot.be.null" ) ; } final Entity entity = PresentationManager . getPm ( ) . getEntity ( _entity ) ; if ( entity == null ) { throw new ConverterException ( "collection.converter.entity.cannot.be.null" ) ; } return entity ; }
Getter for entity property . Must be defined .
13,380
public float getValueAsFloat ( String field ) throws IOException { int hash = Arrays . hashCode ( field . getBytes ( ) ) ; return getValueAsFloat ( structure . valueHash2Index . get ( hash ) ) ; }
Returns the value belonging to the given field as int
13,381
public char getValueAsChar ( int index ) throws IOException { if ( index >= structure . valueSizes . size ( ) ) { throw new IOException ( "Index " + index + " is out of range." ) ; } return Bytes . toChar ( value , structure . valueByteOffsets . get ( index ) ) ; }
Returns the value belonging to the given field as char
13,382
public byte getValueAsByte ( int index ) throws IOException { if ( index >= structure . valueSizes . size ( ) ) { throw new IOException ( "Index " + index + " is out of range." ) ; } return value [ index ] ; }
Returns the value belonging to the given field as byte
13,383
public char getKeyAsChar ( int index ) throws IOException { if ( index >= structure . keySizes . size ( ) ) { throw new IOException ( "Index " + index + " is out of range." ) ; } return Bytes . toChar ( key , structure . keyByteOffsets . get ( index ) ) ; }
Returns the key belonging to the given field as char
13,384
public byte getKeyAsByte ( int index ) throws IOException { if ( index >= structure . keySizes . size ( ) ) { throw new IOException ( "Index " + index + " is out of range." ) ; } return key [ structure . keyByteOffsets . get ( index ) ] ; }
Returns the key belonging to the given field as byte
13,385
private void writeBuffer ( ) throws IOException { bufferedWriter . flip ( ) ; dataFile . write ( writeOffset , bufferedWriter ) ; writeOffset += bufferedWriter . limit ( ) ; bufferedWriter . clear ( ) ; readNextChunkFromFile ( ) ; }
writes the remaining bytes in bufferedWriter to the given FileChannel
13,386
public static ApiVersion getMythVersion ( String baseUri , long connectTimeout , TimeUnit timeUnit ) throws IOException { OkHttpClient client = new OkHttpClient ( ) ; client . setConnectTimeout ( connectTimeout , timeUnit ) ; return getMythVersion ( baseUri , client ) ; }
Gets the api version of the given backend
13,387
public static boolean isServerReachable ( String baseUrl , long connectTimeout , TimeUnit timeUnit ) throws IOException { OkHttpClient client = new OkHttpClient ( ) ; client . setConnectTimeout ( connectTimeout , timeUnit ) ; return isServerReachable ( baseUrl , client ) ; }
Check if the server is reachable
13,388
private void readExtendedHeader ( RandomAccessInputStream raf ) throws IOException , ID3v2FormatException { raf . seek ( EXT_HEAD_LOCATION ) ; byte [ ] buf = new byte [ 4 ] ; if ( raf . read ( buf ) != buf . length ) { throw new IOException ( "Error reading extended header:size" ) ; } size = Helpers . convertDWordToInt ( buf , 0 ) ; if ( size < MIN_SIZE ) { throw new ID3v2FormatException ( "The extended header size data is less than the minimum required size (" + size + '<' + MIN_SIZE + ")." ) ; } numFlagBytes = raf . read ( ) ; buf = new byte [ numFlagBytes + 1 ] ; if ( raf . read ( buf ) != buf . length ) { throw new IOException ( "Error reading extended header:flags" ) ; } parseFlags ( buf ) ; }
Read the information in the file s extended header
13,389
private void parseFlags ( byte [ ] flags ) throws ID3v2FormatException { int bytesRead = 1 ; update = ( flags [ 0 ] & 0x80 ) != 0 ; if ( update ) bytesRead ++ ; crced = ( flags [ 0 ] & 0x40 ) != 0 ; if ( crced ) { bytesRead ++ ; for ( int i = 0 ; i < crc . length ; i ++ ) crc [ i ] = flags [ bytesRead ++ ] ; } if ( ( flags [ 0 ] & 0x80 ) != 0 ) { bytesRead ++ ; byte b = flags [ bytesRead ] ; maxTagSize = ( b & 0xC0 ) >> 6 ; textEncode = ( b & 0x20 ) != 0 ; maxTextSize = ( b & 0x18 ) >> 3 ; imageEncode = ( b & 0x04 ) != 0 ; imageRestrict = ( b & 0x03 ) ; bytesRead ++ ; } if ( bytesRead != numFlagBytes ) { throw new ID3v2FormatException ( "The number of found flag bytes in the extended header is not equal to the number specified in the extended header." ) ; } }
Parse the extended header flag bytes
13,390
private byte [ ] getFlagBytes ( ) { byte [ ] b = new byte [ numFlagBytes ] ; int bytesCopied = 1 ; b [ 0 ] = 0 ; if ( update ) { b [ 0 ] |= 0x80 ; b [ bytesCopied ++ ] = 0 ; } if ( crced ) { b [ 0 ] |= 0x40 ; b [ bytesCopied ++ ] = ( byte ) crc . length ; System . arraycopy ( crc , 0 , b , bytesCopied , crc . length ) ; bytesCopied += crc . length ; } if ( ( maxTagSize != - 1 ) || textEncode || ( maxTextSize != - 1 ) || imageEncode || ( imageRestrict != - 1 ) ) { b [ 0 ] |= 0x20 ; b [ bytesCopied ++ ] = 0x01 ; byte restrict = 0 ; if ( maxTagSize != - 1 ) restrict |= ( byte ) ( ( maxTagSize & 0x3 ) << 6 ) ; if ( textEncode ) restrict |= 0x20 ; if ( maxTextSize != - 1 ) restrict |= ( byte ) ( ( maxTextSize & 0x3 ) << 3 ) ; if ( imageEncode ) restrict |= 0x04 ; if ( imageRestrict != - 1 ) restrict |= ( byte ) ( imageRestrict & 0x3 ) ; b [ bytesCopied ++ ] = restrict ; } return b ; }
A helper function for the getBytes method that returns a byte array representing the extended flags field of the extended header .
13,391
public byte [ ] getBytes ( ) { byte [ ] b = new byte [ size ] ; int bytesCopied = 0 ; System . arraycopy ( Helpers . convertIntToDWord ( size ) , 0 , b , bytesCopied , 4 ) ; bytesCopied += 4 ; b [ bytesCopied ++ ] = ( byte ) numFlagBytes ; System . arraycopy ( getFlagBytes ( ) , 0 , b , bytesCopied , numFlagBytes ) ; bytesCopied += numFlagBytes ; return b ; }
Return an array of bytes representing this extended header in the standard format to be written to a file .
13,392
public int getMaxFrames ( ) { int retval = - 1 ; if ( ( maxTagSize >= 0 ) && ( maxTagSize < MAX_TAG_FRAMES_TABLE . length ) ) { retval = MAX_TAG_FRAMES_TABLE [ maxTagSize ] ; } return retval ; }
Returns the maximum number of frames if set . If unset returns - 1
13,393
public int getMaxTagSize ( ) { int retval = - 1 ; if ( ( maxTagSize >= 0 ) && ( maxTagSize < MAX_TAG_SIZE_TABLE . length ) ) { retval = MAX_TAG_SIZE_TABLE [ maxTagSize ] ; } return retval ; }
Returns the maximum tag size or - 1 if unset
13,394
public int getMaxTextSize ( ) { int retval = - 1 ; if ( ( maxTextSize >= 0 ) && ( maxTextSize < MAX_TEXT_SIZE_TABLE . length ) ) { retval = MAX_TEXT_SIZE_TABLE [ maxTextSize ] ; } return retval ; }
Returns the maximum length of a string if set or - 1
13,395
public void clear ( ) { this . errors . clearErrorMessages ( ) ; ; this . warnings . clear ( ) ; this . infos . clear ( ) ; this . scDir = 0 ; this . scDirUnreadable = 0 ; this . scFiles = 0 ; this . scFilesUnreadable = 0 ; }
Clears errors and warnings automatically called for new scans .
13,396
void doInfo ( ) { this . infos . add ( "scanned directories: " + this . scDir ) ; this . infos . add ( "unreadable directories: " + this . scDirUnreadable ) ; this . infos . add ( "found files: " + this . scFiles ) ; this . infos . add ( "unreadable files: " + this . scFilesUnreadable ) ; }
Generate a few strings with collected information about the scan .
13,397
protected List < FileSource > doScan ( File fDir ) { List < FileSource > ret = new ArrayList < > ( ) ; if ( fDir != null && fDir . exists ( ) && ! fDir . isHidden ( ) ) { for ( final File entry : fDir . listFiles ( ) ) { if ( entry . isHidden ( ) ) { continue ; } if ( ! entry . isDirectory ( ) ) { this . scFiles ++ ; if ( entry . canRead ( ) ) { ret . add ( new FileSource ( entry , this . source . getSetRootPath ( ) ) ) ; } else { this . scFilesUnreadable ++ ; this . warnings . add ( "found file <" + entry . getAbsolutePath ( ) + "> but cannot read, ignore" ) ; } } else if ( entry . isDirectory ( ) ) { this . scDir ++ ; if ( entry . canRead ( ) ) { ret . addAll ( this . doScan ( entry ) ) ; } else { this . scDirUnreadable ++ ; this . warnings . add ( "found directory <" + entry . getAbsolutePath ( ) + "> but cannot read, ignore" ) ; } } } } return ret ; }
Does the actual scan of a directory .
13,398
public boolean concatenateAligned ( BitOutputStream src ) { int bitsToAdd = src . totalBits - src . totalConsumedBits ; if ( bitsToAdd == 0 ) return true ; if ( outBits != src . consumedBits ) return false ; if ( ! ensureSize ( bitsToAdd ) ) return false ; if ( outBits == 0 ) { System . arraycopy ( src . buffer , src . consumedBlurbs , buffer , outBlurbs , ( src . outBlurbs - src . consumedBlurbs + ( ( src . outBits != 0 ) ? 1 : 0 ) ) ) ; } else if ( outBits + bitsToAdd > BITS_PER_BLURB ) { buffer [ outBlurbs ] <<= ( BITS_PER_BLURB - outBits ) ; buffer [ outBlurbs ] |= ( src . buffer [ src . consumedBlurbs ] & ( ( 1 << ( BITS_PER_BLURB - outBits ) ) - 1 ) ) ; System . arraycopy ( src . buffer , src . consumedBlurbs + 1 , buffer , outBlurbs + 11 , ( src . outBlurbs - src . consumedBlurbs - 1 + ( ( src . outBits != 0 ) ? 1 : 0 ) ) ) ; } else { buffer [ outBlurbs ] <<= bitsToAdd ; buffer [ outBlurbs ] |= ( src . buffer [ src . consumedBlurbs ] & ( ( 1 << bitsToAdd ) - 1 ) ) ; } outBits = src . outBits ; totalBits += bitsToAdd ; outBlurbs = totalBits / BITS_PER_BLURB ; return true ; }
Concatinate one InputBitStream to the end of this one .
13,399
public void writeZeroes ( int bits ) throws IOException { if ( bits == 0 ) return ; if ( ! ensureSize ( bits ) ) throw new IOException ( "Memory Allocation Error" ) ; totalBits += bits ; while ( bits > 0 ) { int n = Math . min ( BITS_PER_BLURB - outBits , bits ) ; buffer [ outBlurbs ] <<= n ; bits -= n ; outBits += n ; if ( outBits == BITS_PER_BLURB ) { outBlurbs ++ ; outBits = 0 ; } } }
Write zero bits .