idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
2,900
private int beforeHookInsertLine ( TestMethod method , int codeLineIndex ) { if ( ! isLineLastStament ( method , codeLineIndex ) ) { return - 1 ; } for ( int i = codeLineIndex ; i > 0 ; i -- ) { CodeLine thisLine = method . getCodeBody ( ) . get ( i ) ; CodeLine prevLine = method . getCodeBody ( ) . get ( i - 1 ) ; assert prevLine . getEndLine ( ) <= thisLine . getEndLine ( ) ; if ( prevLine . getEndLine ( ) != thisLine . getStartLine ( ) ) { return thisLine . getStartLine ( ) ; } } return method . getCodeBody ( ) . get ( 0 ) . getStartLine ( ) ; }
Returns - 1 if beforeHook for the codeLineIndex should not be inserted
2,901
private int afterHookInsertLine ( TestMethod method , int codeLineIndex ) { if ( ! isLineLastStament ( method , codeLineIndex ) ) { return - 1 ; } CodeLine codeLine = method . getCodeBody ( ) . get ( codeLineIndex ) ; return codeLine . getEndLine ( ) + 1 ; }
Returns - 1 if afterHook for the codeLineIndex should not be inserted
2,902
private boolean insertCodeBodyHook ( TestMethod method , CtMethod ctMethod , String classQualifiedName , String methodSimpleName , String methodArgClassesStr ) throws CannotCompileException { String hookClassName = HookMethodDef . class . getCanonicalName ( ) ; String initializeSrc = hookInitializeSrc ( ) ; boolean transformed = false ; for ( int i = method . getCodeBody ( ) . size ( ) - 1 ; i >= 0 ; i -- ) { int hookedLine = method . getCodeBody ( ) . get ( i ) . getStartLine ( ) ; int afterHookInsertedLine = afterHookInsertLine ( method , i ) ; if ( afterHookInsertedLine != - 1 ) { int actualAfterHookInsertedLine = ctMethod . insertAt ( afterHookInsertedLine , false , null ) ; ctMethod . insertAt ( afterHookInsertedLine , String . format ( "%s%s.afterCodeLineHook(\"%s\",\"%s\",\"%s\",\"%s\",%d, %d);" , initializeSrc , hookClassName , classQualifiedName , methodSimpleName , methodSimpleName , methodArgClassesStr , hookedLine , actualAfterHookInsertedLine ) ) ; transformed = true ; } int beforeHookInsertedLine = beforeHookInsertLine ( method , i ) ; if ( beforeHookInsertedLine != - 1 ) { int actualBeforeHookInsertedLine = ctMethod . insertAt ( beforeHookInsertedLine , false , null ) ; ctMethod . insertAt ( beforeHookInsertedLine , String . format ( "%s%s.beforeCodeLineHook(\"%s\",\"%s\",\"%s\",\"%s\",%d, %d);" , initializeSrc , hookClassName , classQualifiedName , methodSimpleName , methodSimpleName , methodArgClassesStr , hookedLine , actualBeforeHookInsertedLine ) ) ; transformed = true ; } } return transformed ; }
- returns true this method actually transform ctMethod body
2,903
public SrcTree generate ( String [ ] srcFiles , Charset srcCharset , String [ ] classPathEntries ) { CollectRootRequestor rootRequestor = new CollectRootRequestor ( ) ; parseAST ( srcFiles , srcCharset , classPathEntries , rootRequestor ) ; CollectSubRequestor subRequestor = new CollectSubRequestor ( rootRequestor . getRootClassTable ( ) ) ; parseAST ( srcFiles , srcCharset , classPathEntries , subRequestor ) ; AdditionalTestDocsSetter setter = new AdditionalTestDocsSetter ( rootRequestor . getRootClassTable ( ) , subRequestor . getSubClassTable ( ) , rootRequestor . getRootMethodTable ( ) , subRequestor . getSubMethodTable ( ) ) ; setter . set ( additionalTestDocs ) ; CollectCodeRequestor codeRequestor = new CollectCodeRequestor ( subRequestor . getSubClassTable ( ) , rootRequestor . getRootMethodTable ( ) , subRequestor . getSubMethodTable ( ) , subRequestor . getFieldTable ( ) ) ; parseAST ( srcFiles , srcCharset , classPathEntries , codeRequestor ) ; SrcTree result = new SrcTree ( ) ; result . setRootClassTable ( rootRequestor . getRootClassTable ( ) ) ; result . setSubClassTable ( subRequestor . getSubClassTable ( ) ) ; result . setRootMethodTable ( rootRequestor . getRootMethodTable ( ) ) ; result . setSubMethodTable ( subRequestor . getSubMethodTable ( ) ) ; result . setFieldTable ( subRequestor . getFieldTable ( ) ) ; return result ; }
all class containing sub directories even if the class is in a named package
2,904
public QueryAtom bind ( QueryBinding binding ) { List < QueryArgument > args = new ArrayList < QueryArgument > ( ) ; for ( QueryArgument arg : this . args ) { if ( binding . isBound ( arg ) ) { args . add ( binding . get ( arg ) ) ; } else { args . add ( arg ) ; } } return new QueryAtom ( type , args ) ; }
A convenience method to clone the QueryAtom instance while inserting a new binding .
2,905
public void start ( BundleContext bundleContext ) throws Exception { try { super . start ( bundleContext ) ; } catch ( Throwable e ) { String errorMessage = "Problem when starting Kura module " + getClass ( ) . getName ( ) + ":" ; log . warn ( errorMessage , e ) ; System . err . println ( errorMessage ) ; e . printStackTrace ( ) ; throw e ; } }
CAMEL - 9314 )
2,906
protected void activate ( ComponentContext componentContext , Map < String , Object > properties ) throws Exception { m_properties = properties ; start ( componentContext . getBundleContext ( ) ) ; updated ( properties ) ; }
CAMEL - 9351 )
2,907
public boolean waitForExpectedCondition ( ExpectedCondition < ? > condition , int timeout ) { WebDriver driver = getWebDriver ( ) ; boolean conditionMet = true ; try { new WebDriverWait ( driver , timeout ) . until ( condition ) ; } catch ( TimeoutException e ) { conditionMet = false ; } return conditionMet ; }
Waits until the expectations are full filled or timeout runs out
2,908
public void waitAndAssertForExpectedCondition ( ExpectedCondition < ? > condition , int timeout ) { if ( ! waitForExpectedCondition ( condition , timeout ) ) { fail ( String . format ( "Element does not meet condition %1$s" , condition . toString ( ) ) ) ; } }
Waits until the expectations are met and throws an assert if not
2,909
public void checkAndAssertForExpectedCondition ( ExpectedCondition < ? > condition ) { if ( ! waitForExpectedCondition ( condition , 0 ) ) { fail ( String . format ( "Element does not meet condition %1$s" , condition . toString ( ) ) ) ; } }
Checks if the expectations are met and throws an assert if not
2,910
public void waitAndSwitchToNewBrowserWindow ( int timeout ) { final Set < String > handles = SenBotContext . getSeleniumDriver ( ) . getWindowHandles ( ) ; mainWindowHandle . set ( SenBotContext . getSeleniumDriver ( ) . getWindowHandles ( ) . iterator ( ) . next ( ) ) ; if ( getWebDriver ( ) instanceof InternetExplorerDriver ) { try { Thread . sleep ( 1000 ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } String newWindow = ( new WebDriverWait ( getWebDriver ( ) , timeout ) ) . until ( new ExpectedCondition < String > ( ) { public String apply ( WebDriver input ) { if ( input . getWindowHandles ( ) . size ( ) > 1 ) { Iterator < String > iterator = input . getWindowHandles ( ) . iterator ( ) ; String found = iterator . next ( ) ; found = iterator . next ( ) ; return found ; } return null ; } } ) ; assertTrue ( ! newWindow . equals ( mainWindowHandle . get ( ) ) ) ; assertTrue ( ! newWindow . isEmpty ( ) ) ; popupWindowHandle . set ( newWindow ) ; SenBotContext . getSeleniumDriver ( ) . switchTo ( ) . window ( newWindow ) ; }
Waits for a new browser window to pop up and switches to it
2,911
public void remove ( String name ) throws IOException , IllegalArgumentException { checkWritable ( ) ; final FatLfnDirectoryEntry entry = getEntry ( name ) ; if ( entry == null ) return ; unlinkEntry ( entry ) ; final ClusterChain cc = new ClusterChain ( fat , entry . realEntry . getStartCluster ( ) , false ) ; cc . setChainLength ( 0 ) ; updateLFN ( ) ; }
Remove the entry with the given name from this directory .
2,912
void unlinkEntry ( FatLfnDirectoryEntry entry ) { final ShortName sn = entry . realEntry . getShortName ( ) ; if ( sn . equals ( ShortName . DOT ) || sn . equals ( ShortName . DOT_DOT ) ) throw new IllegalArgumentException ( "the dot entries can not be removed" ) ; final String lowerName = entry . getName ( ) . toLowerCase ( Locale . ROOT ) ; assert ( this . longNameIndex . containsKey ( lowerName ) ) ; this . longNameIndex . remove ( lowerName ) ; assert ( this . shortNameIndex . containsKey ( sn ) ) ; this . shortNameIndex . remove ( sn ) ; this . usedNames . remove ( sn . asSimpleString ( ) . toLowerCase ( Locale . ROOT ) ) ; assert ( this . usedNames . contains ( lowerName ) ) ; this . usedNames . remove ( lowerName ) ; if ( entry . isFile ( ) ) { this . entryToFile . remove ( entry . realEntry ) ; } else { this . entryToDirectory . remove ( entry . realEntry ) ; } }
Unlinks the specified entry from this directory without actually deleting it .
2,913
void linkEntry ( FatLfnDirectoryEntry entry ) throws IOException { checkUniqueName ( entry . getName ( ) ) ; final ShortName sn = makeShortName ( entry . getName ( ) ) ; entry . realEntry . setShortName ( sn ) ; this . longNameIndex . put ( entry . getName ( ) . toLowerCase ( Locale . ROOT ) , entry ) ; this . shortNameIndex . put ( entry . realEntry . getShortName ( ) , entry ) ; updateLFN ( ) ; }
Links the specified entry to this directory updating the entrie s short name .
2,914
public String getVolumeLabel ( ) { checkClosed ( ) ; final String fromDir = rootDirStore . getLabel ( ) ; if ( fromDir == null && fatType != FatType . FAT32 ) { return ( ( Fat16BootSector ) bs ) . getVolumeLabel ( ) ; } else { return fromDir ; } }
Returns the volume label of this file system .
2,915
public void setVolumeLabel ( String label ) throws ReadOnlyException , IOException { checkClosed ( ) ; checkReadOnly ( ) ; rootDirStore . setLabel ( label ) ; if ( fatType != FatType . FAT32 ) { ( ( Fat16BootSector ) bs ) . setVolumeLabel ( label ) ; } }
Sets the volume label for this file system .
2,916
public void flush ( ) throws IOException { checkClosed ( ) ; if ( bs . isDirty ( ) ) { bs . write ( ) ; } for ( int i = 0 ; i < bs . getNrFats ( ) ; i ++ ) { fat . writeCopy ( bs . getFatOffset ( i ) ) ; } rootDir . flush ( ) ; if ( fsiSector != null ) { fsiSector . setFreeClusterCount ( fat . getFreeClusterCount ( ) ) ; fsiSector . setLastAllocatedCluster ( fat . getLastAllocatedCluster ( ) ) ; fsiSector . write ( ) ; } }
Flush all changed structures to the device .
2,917
public long getTotalSpace ( ) { checkClosed ( ) ; if ( fatType == FatType . FAT32 ) { return bs . getNrTotalSectors ( ) * bs . getBytesPerSector ( ) ; } return - 1 ; }
The total size of this file system .
2,918
public QueryResult execute ( Query query ) throws QueryEngineException { if ( ! ( query instanceof QueryImpl ) ) { throw new QueryEngineException ( "Couldn't cast Query to QueryImpl." ) ; } QueryImpl q = ( QueryImpl ) query ; resvarsLoop : for ( QueryArgument arg : q . getResultVars ( ) ) { for ( QueryAtomGroup g : q . getAtomGroups ( ) ) { for ( QueryAtom a : g . getAtoms ( ) ) { if ( a . getArguments ( ) . contains ( arg ) ) { continue resvarsLoop ; } } } } Queue < QueryResultImpl > results = new LinkedList < > ( ) ; for ( QueryAtomGroup g : q . getAtomGroups ( ) ) { QueryAtomGroupImpl group = ( QueryAtomGroupImpl ) g ; List < QueryAtomGroupImpl > components = findComponents ( group ) ; Queue < QueryResultImpl > componentResults = new LinkedList < > ( ) ; boolean groupAsk = true ; for ( QueryAtomGroupImpl component : components ) { QueryAtomGroupImpl preorderedGroup = preorder ( component ) ; QueryResultImpl result = new QueryResultImpl ( query ) ; if ( eval ( q , preorderedGroup , result , new QueryBindingImpl ( ) , BoundChecking . CHECK_BOUND ) ) { if ( query . isSelectDistinct ( ) ) { result = eliminateDuplicates ( result ) ; } componentResults . add ( result ) ; } else { groupAsk = false ; break ; } } if ( groupAsk ) { results . add ( combineResults ( componentResults , query . getType ( ) == SELECT_DISTINCT ) ) ; } else { QueryResultImpl ret = new QueryResultImpl ( query ) ; ret . setAsk ( false ) ; results . add ( ret ) ; } } return unionResults ( q , results , query . getType ( ) == SELECT_DISTINCT ) ; }
Execute a sparql - dl query and generate the result set .
2,919
private List < QueryAtomGroupImpl > findComponents ( QueryAtomGroupImpl group ) { List < QueryAtom > atoms = new LinkedList < > ( ) ; atoms . addAll ( group . getAtoms ( ) ) ; List < QueryAtomGroupImpl > components = new LinkedList < > ( ) ; if ( atoms . isEmpty ( ) ) { components . add ( group ) ; return components ; } QueryAtomGroupImpl component = new QueryAtomGroupImpl ( ) ; for ( QueryAtom atom : atoms ) { boolean noVar = true ; for ( QueryArgument arg : atom . getArguments ( ) ) { if ( arg . isVar ( ) ) { noVar = false ; break ; } } if ( noVar ) { component . addAtom ( atom ) ; } } component . getAtoms ( ) . forEach ( atoms :: remove ) ; if ( ! component . isEmpty ( ) ) { components . add ( component ) ; } UnionFind < QueryArgument > unionFind = new UnionFind < > ( ) ; for ( QueryAtom atom : atoms ) { QueryArgument firstVar = null ; for ( QueryArgument arg : atom . getArguments ( ) ) { if ( arg . isVar ( ) ) { if ( firstVar == null ) { firstVar = arg ; } else { unionFind . union ( firstVar , arg ) ; } } } } while ( ! atoms . isEmpty ( ) ) { component = new QueryAtomGroupImpl ( ) ; QueryAtom nextAtom = atoms . get ( 0 ) ; atoms . remove ( nextAtom ) ; component . addAtom ( nextAtom ) ; QueryArgument args = null ; for ( QueryArgument arg : nextAtom . getArguments ( ) ) { if ( arg . isVar ( ) ) { args = unionFind . find ( arg ) ; break ; } } for ( QueryAtom atom : atoms ) { QueryArgument args2 = null ; for ( QueryArgument arg : atom . getArguments ( ) ) { if ( arg . isVar ( ) ) { args2 = unionFind . find ( arg ) ; break ; } } if ( args . equals ( args2 ) ) { component . addAtom ( atom ) ; } } for ( QueryAtom atom : component . getAtoms ( ) ) { atoms . remove ( atom ) ; } components . add ( component ) ; } return components ; }
Split the query into individual components if possible to avoid cross - products in later evaluation . The first component will contain all atoms with no variables if there exist some .
2,920
private QueryResultImpl combineResults ( Queue < QueryResultImpl > results , boolean distinct ) { while ( results . size ( ) > 1 ) { QueryResultImpl a = results . remove ( ) ; QueryResultImpl b = results . remove ( ) ; results . add ( combineResults ( a , b , distinct ) ) ; } return results . remove ( ) ; }
Combine the results of the individual components with the cartesian product .
2,921
private QueryResultImpl combineResults ( QueryResultImpl a , QueryResultImpl b , boolean distinct ) { QueryResultImpl result = new QueryResultImpl ( a . getQuery ( ) ) ; for ( QueryBindingImpl bindingA : a . getBindings ( ) ) { for ( QueryBindingImpl bindingB : b . getBindings ( ) ) { QueryBindingImpl binding = new QueryBindingImpl ( ) ; binding . set ( bindingA ) ; binding . set ( bindingB ) ; result . add ( binding ) ; } } if ( distinct ) { return eliminateDuplicates ( result ) ; } return result ; }
Combine two results with the cartesian product .
2,922
private QueryResultImpl eliminateDuplicates ( QueryResultImpl result ) { QueryResultImpl ret = new QueryResultImpl ( result . getQuery ( ) ) ; Set < QueryBindingImpl > distinctSet = new HashSet < > ( result . getBindings ( ) ) ; distinctSet . forEach ( ret :: add ) ; return ret ; }
Eliminate duplicate bindings .
2,923
private static StackLine getStackLine ( SrcTree srcTree , String classQualifiedName , String methodSimpleName , int line ) { StackLine rootStackLine = getStackLine ( srcTree . getRootMethodTable ( ) , classQualifiedName , methodSimpleName , line ) ; if ( rootStackLine != null ) { return rootStackLine ; } StackLine subStackLine = getStackLine ( srcTree . getSubMethodTable ( ) , classQualifiedName , methodSimpleName , line ) ; if ( subStackLine != null ) { return subStackLine ; } return null ; }
null means method does not exists in srcTree
2,924
public WebElement fillFormField_locator ( String locator , String value ) { WebElement fieldEl = seleniumElementService . translateLocatorToWebElement ( locator ) ; fieldEl . clear ( ) ; fieldEl . sendKeys ( getReferenceService ( ) . namespaceString ( value ) ) ; return fieldEl ; }
Fill out a form field with the passed value
2,925
public void toBus ( String channel , Object payload , Header ... headers ) { producerTemplate . sendBodyAndHeaders ( "amqp:" + channel , encodedPayload ( payload ) , arguments ( headers ) ) ; }
Connector channels API
2,926
public void cacheIncludeAndIgnore ( WebElement table ) { if ( getIgnoreByMatches ( ) == null ) { setIgnoreByMatches ( new ArrayList < WebElement > ( ) ) ; for ( By by : getIgnoreRowsMatching ( ) ) { getIgnoreByMatches ( ) . addAll ( table . findElements ( by ) ) ; } } if ( getIncludeByMatches ( ) == null ) { setIncludeByMatches ( new ArrayList < WebElement > ( ) ) ; for ( By by : getIncludeOnlyRowsMatching ( ) ) { getIncludeByMatches ( ) . addAll ( table . findElements ( by ) ) ; } } }
Does the table comparison
2,927
public static < T > T getBean ( Class < T > clazz ) { return getSenBotContext ( ) . context . getBean ( clazz ) ; }
Gets the bean class
2,928
public static File getOrCreateFile ( String url , boolean createIfNotFound ) throws IOException { File file = null ; if ( url . contains ( ResourceUtils . CLASSPATH_URL_PREFIX ) ) { url = url . replaceAll ( ResourceUtils . CLASSPATH_URL_PREFIX , "" ) ; if ( url . startsWith ( "/" ) ) { url = url . substring ( 1 ) ; } URL resource = SenBotContext . class . getClassLoader ( ) . getResource ( "" ) ; if ( resource == null ) { throw new IOException ( "creating a new folder on the classpath is not allowed" ) ; } else { file = new File ( resource . getFile ( ) + "/" + url ) ; } } else { file = new File ( url ) ; } if ( createIfNotFound && ! file . exists ( ) ) { file . mkdirs ( ) ; } return file ; }
Get a File on the class path or file system or create it if it does not exist
2,929
public void setChainLength ( int nrClusters ) throws IOException { if ( nrClusters < 0 ) throw new IllegalArgumentException ( "negative cluster count" ) ; if ( ( this . startCluster == 0 ) && ( nrClusters == 0 ) ) { } else if ( ( this . startCluster == 0 ) && ( nrClusters > 0 ) ) { final long [ ] chain = fat . allocNew ( nrClusters ) ; this . startCluster = chain [ 0 ] ; } else { final long [ ] chain = fat . getChain ( startCluster ) ; if ( nrClusters != chain . length ) { if ( nrClusters > chain . length ) { int count = nrClusters - chain . length ; while ( count > 0 ) { fat . allocAppend ( getStartCluster ( ) ) ; count -- ; } } else { if ( nrClusters > 0 ) { fat . setEof ( chain [ nrClusters - 1 ] ) ; for ( int i = nrClusters ; i < chain . length ; i ++ ) { fat . setFree ( chain [ i ] ) ; } } else { for ( int i = 0 ; i < chain . length ; i ++ ) { fat . setFree ( chain [ i ] ) ; } this . startCluster = 0 ; } } } } }
Sets the length of this cluster chain in clusters .
2,930
public void moveTo ( FatLfnDirectory target , String newName ) throws IOException , ReadOnlyException { checkWritable ( ) ; if ( ! target . isFreeName ( newName ) ) { throw new IOException ( "the name \"" + newName + "\" is already in use" ) ; } this . parent . unlinkEntry ( this ) ; this . parent = target ; this . fileName = newName ; this . parent . linkEntry ( this ) ; }
Moves this entry to a new directory under the specified name .
2,931
private Pin getPin ( ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( " Pin Id > " + iled ) ; } Pin ret = getPinPerFieldName ( ) ; if ( ret == null ) { ret = getPinPerPinAddress ( ) ; if ( ret == null ) { ret = getPinPerPinName ( ) ; } } if ( ret == null ) { throw new IllegalArgumentException ( "Cannot find gpio [" + this . iled + "] " ) ; } return ret ; }
Hack to retrieve the correct Pin from RaspiPin . class lib
2,932
public long getStartCluster ( ) { if ( type == FatType . FAT32 ) { return ( LittleEndian . getUInt16 ( data , 0x14 ) << 16 ) | LittleEndian . getUInt16 ( data , 0x1a ) ; } else { return LittleEndian . getUInt16 ( data , 0x1a ) ; } }
Returns the start of the file in clusters .
2,933
void setStartCluster ( long startCluster ) { if ( startCluster > Integer . MAX_VALUE ) throw new AssertionError ( ) ; if ( this . type == FatType . FAT32 ) { LittleEndian . setInt16 ( data , 0x1a , ( int ) ( startCluster & 0xffff ) ) ; LittleEndian . setInt16 ( data , 0x14 , ( int ) ( ( startCluster >> 16 ) & 0xffff ) ) ; } else { LittleEndian . setInt16 ( data , 0x1a , ( int ) startCluster ) ; } }
Sets the startCluster .
2,934
public static Packet decompress ( final Packet packet ) throws IOException { final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream ( packet . getData ( ) ) ; final GZIPInputStream gzipInputStream = new GZIPInputStream ( byteArrayInputStream ) ; final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; final byte buffer [ ] = new byte [ INFLATE_BUFFER_SIZE ] ; int bytesInflated ; while ( ( bytesInflated = gzipInputStream . read ( buffer ) ) >= 0 ) { byteArrayOutputStream . write ( buffer , 0 , bytesInflated ) ; } return new Packet ( packet . getPacketType ( ) , packet . getPacketID ( ) , byteArrayOutputStream . toByteArray ( ) ) ; }
Decompresses given Packet
2,935
public static Packet compress ( final Packet packet ) throws IOException { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; final GZIPOutputStream gzipOutputStream = new GZIPOutputStream ( byteArrayOutputStream ) { { def . setLevel ( Deflater . BEST_COMPRESSION ) ; } } ; gzipOutputStream . write ( packet . getData ( ) ) ; gzipOutputStream . close ( ) ; return new Packet ( packet . getPacketType ( ) , packet . getPacketID ( ) , byteArrayOutputStream . toByteArray ( ) ) ; }
Compresses given Packet . Note that this can increase the total size when used incorrectly
2,936
public String getViewsString ( ) { if ( views == null || views . isEmpty ( ) ) return "" ; char delim = ',' ; StringBuilder buf = new StringBuilder ( ) ; for ( String value : views ) buf . append ( delim ) . append ( value ) ; return buf . substring ( 1 ) ; }
Used for generating the config UI .
2,937
public TLSBuilder withTrustStore ( final String trustStoreType , final InputStream trustStoreStream , final char [ ] trustStorePassword ) { return withKeyStore ( trustStoreType , trustStoreStream , trustStorePassword ) ; }
Sets trust store
2,938
public SSLSocket buildSocket ( ) throws KeyStoreException , CertificateException , NoSuchAlgorithmException , IOException , UnrecoverableKeyException , KeyManagementException { if ( host == null ) throw new IllegalStateException ( "Cannot create socket without host" ) ; final SSLSocket s = ( SSLSocket ) build ( ) . getSocketFactory ( ) . createSocket ( host , port ) ; s . setEnabledProtocols ( TLS . getUsable ( TLS . TLS_PROTOCOLS , s . getSupportedProtocols ( ) ) ) ; s . setEnabledCipherSuites ( TLS . getUsable ( TLS . TLS_CIPHER_SUITES , s . getSupportedCipherSuites ( ) ) ) ; return s ; }
Builds a new Socket
2,939
public SSLServerSocket buildServerSocket ( ) throws CertificateException , UnrecoverableKeyException , NoSuchAlgorithmException , KeyStoreException , KeyManagementException , IOException { final SSLServerSocket s = ( SSLServerSocket ) build ( ) . getServerSocketFactory ( ) . createServerSocket ( port ) ; s . setEnabledProtocols ( TLS . getUsable ( TLS . TLS_PROTOCOLS , s . getSupportedProtocols ( ) ) ) ; s . setEnabledCipherSuites ( TLS . getUsable ( TLS . TLS_CIPHER_SUITES , s . getSupportedCipherSuites ( ) ) ) ; return s ; }
Builds a new ServerSocket
2,940
public void write ( final DataOutputStream out ) throws IOException { out . writeByte ( packetType . ordinal ( ) ) ; out . writeShort ( packetID ) ; out . writeInt ( dataLength ) ; out . write ( data ) ; }
Writes Packet into DataOutputStream
2,941
public static Packet fromStream ( final DataInputStream in ) throws IOException { final Packet . PacketType packetType = Packet . PacketType . fastValues [ in . readByte ( ) ] ; final short packetID = in . readShort ( ) ; final int dataLength = in . readInt ( ) ; final byte [ ] data = new byte [ dataLength ] ; in . readFully ( data ) ; return new Packet ( packetType , packetID , data ) ; }
Reads a Packet from raw input data
2,942
public synchronized byte [ ] readBytes ( ) throws IOException { final int dataLength = dataInputStream . readInt ( ) ; final byte [ ] data = new byte [ dataLength ] ; final int dataRead = dataInputStream . read ( data , 0 , dataLength ) ; if ( dataRead != dataLength ) throw new IOException ( "Not enough data available" ) ; return data ; }
Reads byte array into output
2,943
static String [ ] getUsable ( final List < String > available , final String [ ] supported ) { final List < String > filtered = new ArrayList < String > ( available . size ( ) ) ; final List < String > supportedList = Arrays . asList ( supported ) ; for ( final String s : available ) { if ( supportedList . contains ( s ) ) filtered . add ( s ) ; } final String [ ] filteredArray = new String [ filtered . size ( ) ] ; filtered . toArray ( filteredArray ) ; return filteredArray ; }
Returns intersection of available and supported
2,944
public synchronized void addHandler ( final short packetID , final PacketHandler packetHandler ) { if ( registry . containsKey ( packetID ) ) throw new IllegalArgumentException ( "Handler for ID: " + packetID + " already exists" ) ; registry . put ( packetID , packetHandler ) ; }
Adds a new handler for this specific Packet ID
2,945
public synchronized PacketBuilder withByte ( final byte b ) { checkBuilt ( ) ; try { dataOutputStream . writeByte ( b ) ; } catch ( final IOException e ) { logger . error ( "Unable to add byte: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return this ; }
Adds a byte
2,946
public synchronized PacketBuilder withBytes ( final byte [ ] b ) { checkBuilt ( ) ; try { dataOutputStream . writeInt ( b . length ) ; dataOutputStream . write ( b ) ; } catch ( final IOException e ) { logger . error ( "Unable to add bytes: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return this ; }
Adds byte array
2,947
public synchronized PacketBuilder withInt ( final int i ) { checkBuilt ( ) ; try { dataOutputStream . writeInt ( i ) ; } catch ( final IOException e ) { logger . error ( "Unable to add integer: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return this ; }
Adds an integer
2,948
public synchronized PacketBuilder withString ( final String s ) { try { withBytes ( s . getBytes ( "utf-8" ) ) ; } catch ( final UnsupportedEncodingException e ) { logger . error ( "UTF-8 encoding is not supported" ) ; } return this ; }
Adds a String
2,949
public synchronized PacketBuilder withBoolean ( final boolean b ) { checkBuilt ( ) ; try { dataOutputStream . writeBoolean ( b ) ; } catch ( final IOException e ) { logger . error ( "Unable to add boolean: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return this ; }
Adds a boolean
2,950
public synchronized PacketBuilder withFloat ( final float f ) { checkBuilt ( ) ; try { dataOutputStream . writeFloat ( f ) ; } catch ( final IOException e ) { logger . error ( "Unable to add float: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return this ; }
Adds a float
2,951
public synchronized PacketBuilder withDouble ( final double d ) { checkBuilt ( ) ; try { dataOutputStream . writeDouble ( d ) ; } catch ( final IOException e ) { logger . error ( "Unable to add double: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return this ; }
Adds a double
2,952
public synchronized PacketBuilder withLong ( final long l ) { checkBuilt ( ) ; try { dataOutputStream . writeLong ( l ) ; } catch ( final IOException e ) { logger . error ( "Unable to add long: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return this ; }
Adds a long
2,953
public synchronized PacketBuilder withShort ( final short s ) { checkBuilt ( ) ; try { dataOutputStream . writeShort ( s ) ; } catch ( final IOException e ) { logger . error ( "Unable to add short: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return this ; }
Adds a short
2,954
public synchronized Packet build ( ) { checkBuilt ( ) ; isBuilt = true ; try { dataOutputStream . close ( ) ; } catch ( final IOException e ) { logger . error ( "Unable to build packet: {} : {}" , e . getClass ( ) , e . getMessage ( ) ) ; } return new Packet ( packetType , packetID , byteArrayOutputStream . toByteArray ( ) ) ; }
Builds Packet with given data
2,955
public void setTargetNormal ( double nx , double ny , double nz ) { double h , f , c , vx , vy , hvx ; vx = ny ; vy = - nx ; c = nz ; h = ( 1 - c ) / ( 1 - c * c ) ; hvx = h * vx ; f = ( c < 0 ) ? - c : c ; if ( f < 1.0 - 1.0E-4 ) { m00 = c + hvx * vx ; m01 = hvx * vy ; m02 = - vy ; m10 = hvx * vy ; m11 = c + h * vy * vy ; m12 = vx ; m20 = vy ; m21 = - vx ; m22 = c ; } else { m00 = 1 ; m01 = 0 ; m02 = 0 ; m10 = 0 ; m11 = 1 ; m12 = 0 ; m20 = 0 ; m21 = 0 ; if ( c > 0 ) { m22 = 1 ; } else { m22 = - 1 ; } } }
Assumes target normal is normalized
2,956
public void insertPointAfter ( PolygonPoint a , PolygonPoint newPoint ) { int index = _points . indexOf ( a ) ; if ( index != - 1 ) { newPoint . setNext ( a . getNext ( ) ) ; newPoint . setPrevious ( a ) ; a . getNext ( ) . setPrevious ( newPoint ) ; a . setNext ( newPoint ) ; _points . add ( index + 1 , newPoint ) ; } else { throw new RuntimeException ( "Tried to insert a point into a Polygon after a point not belonging to the Polygon" ) ; } }
Will insert a point in the polygon after given point
2,957
public void addPoint ( PolygonPoint p ) { p . setPrevious ( _last ) ; p . setNext ( _last . getNext ( ) ) ; _last . setNext ( p ) ; _points . add ( p ) ; }
Will add a point after the last point added
2,958
public void prepareTriangulation ( TriangulationContext < ? > tcx ) { int hint = _points . size ( ) ; if ( _steinerPoints != null ) { hint += _steinerPoints . size ( ) ; } if ( _holes != null ) { for ( Polygon p : _holes ) { hint += p . pointCount ( ) ; } } HashMap < TriangulationPoint , TriangulationPoint > uniquePts = new HashMap < TriangulationPoint , TriangulationPoint > ( hint ) ; TriangulationPoint . mergeInstances ( uniquePts , _points ) ; if ( _steinerPoints != null ) { TriangulationPoint . mergeInstances ( uniquePts , _steinerPoints ) ; } if ( _holes != null ) { for ( Polygon p : _holes ) { TriangulationPoint . mergeInstances ( uniquePts , p . _points ) ; } } if ( m_triangles == null ) { m_triangles = new ArrayList < DelaunayTriangle > ( _points . size ( ) ) ; } else { m_triangles . clear ( ) ; } for ( int i = 0 ; i < _points . size ( ) - 1 ; i ++ ) { tcx . newConstraint ( _points . get ( i ) , _points . get ( i + 1 ) ) ; } tcx . newConstraint ( _points . get ( 0 ) , _points . get ( _points . size ( ) - 1 ) ) ; if ( _holes != null ) { for ( Polygon p : _holes ) { for ( int i = 0 ; i < p . _points . size ( ) - 1 ; i ++ ) { tcx . newConstraint ( p . _points . get ( i ) , p . _points . get ( i + 1 ) ) ; } tcx . newConstraint ( p . _points . get ( 0 ) , p . _points . get ( p . _points . size ( ) - 1 ) ) ; } } tcx . addPoints ( uniquePts . keySet ( ) ) ; }
Merge equals points . Creates constraints and populates the context with points .
2,959
public static void warmup ( ) { Polygon poly = PolygonGenerator . RandomCircleSweep2 ( 50 , 50000 ) ; TriangulationProcess process = new TriangulationProcess ( ) ; process . triangulate ( poly ) ; }
Will do a warmup run to let the JVM optimize the triangulation code
2,960
private void markNeighbor ( TriangulationPoint p1 , TriangulationPoint p2 , DelaunayTriangle t ) { if ( ( p1 == points [ 2 ] && p2 == points [ 1 ] ) || ( p1 == points [ 1 ] && p2 == points [ 2 ] ) ) { neighbors [ 0 ] = t ; } else if ( ( p1 == points [ 0 ] && p2 == points [ 2 ] ) || ( p1 == points [ 2 ] && p2 == points [ 0 ] ) ) { neighbors [ 1 ] = t ; } else if ( ( p1 == points [ 0 ] && p2 == points [ 1 ] ) || ( p1 == points [ 1 ] && p2 == points [ 0 ] ) ) { neighbors [ 2 ] = t ; } else { logger . error ( "Neighbor error, please report!" ) ; } }
Update neighbor pointers
2,961
public void clear ( ) { DelaunayTriangle t ; for ( int i = 0 ; i < 3 ; i ++ ) { t = neighbors [ i ] ; if ( t != null ) { t . clearNeighbor ( this ) ; } } clearNeighbors ( ) ; points [ 0 ] = points [ 1 ] = points [ 2 ] = null ; }
Clears all references to all other triangles and points
2,962
public DelaunayTriangle neighborCW ( TriangulationPoint point ) { if ( point == points [ 0 ] ) { return neighbors [ 1 ] ; } else if ( point == points [ 1 ] ) { return neighbors [ 2 ] ; } return neighbors [ 0 ] ; }
The neighbor clockwise to given point
2,963
public DelaunayTriangle neighborCCW ( TriangulationPoint point ) { if ( point == points [ 0 ] ) { return neighbors [ 2 ] ; } else if ( point == points [ 1 ] ) { return neighbors [ 0 ] ; } return neighbors [ 1 ] ; }
The neighbor counter - clockwise to given point
2,964
public DelaunayTriangle neighborAcross ( TriangulationPoint opoint ) { if ( opoint == points [ 0 ] ) { return neighbors [ 0 ] ; } else if ( opoint == points [ 1 ] ) { return neighbors [ 1 ] ; } return neighbors [ 2 ] ; }
The neighbor across to given point
2,965
public void legalize ( TriangulationPoint oPoint , TriangulationPoint nPoint ) { if ( oPoint == points [ 0 ] ) { points [ 1 ] = points [ 0 ] ; points [ 0 ] = points [ 2 ] ; points [ 2 ] = nPoint ; } else if ( oPoint == points [ 1 ] ) { points [ 2 ] = points [ 1 ] ; points [ 1 ] = points [ 0 ] ; points [ 0 ] = nPoint ; } else if ( oPoint == points [ 2 ] ) { points [ 0 ] = points [ 2 ] ; points [ 2 ] = points [ 1 ] ; points [ 1 ] = nPoint ; } else { logger . error ( "legalization error" ) ; throw new RuntimeException ( "legalization bug" ) ; } }
Legalize triangle by rotating clockwise around oPoint
2,966
public void markNeighborEdges ( ) { for ( int i = 0 ; i < 3 ; i ++ ) { if ( cEdge [ i ] ) { switch ( i ) { case 0 : if ( neighbors [ 0 ] != null ) neighbors [ 0 ] . markConstrainedEdge ( points [ 1 ] , points [ 2 ] ) ; break ; case 1 : if ( neighbors [ 1 ] != null ) neighbors [ 1 ] . markConstrainedEdge ( points [ 0 ] , points [ 2 ] ) ; break ; case 2 : if ( neighbors [ 2 ] != null ) neighbors [ 2 ] . markConstrainedEdge ( points [ 0 ] , points [ 1 ] ) ; break ; } } } }
Finalize edge marking
2,967
public void markConstrainedEdge ( TriangulationPoint p , TriangulationPoint q ) { if ( ( q == points [ 0 ] && p == points [ 1 ] ) || ( q == points [ 1 ] && p == points [ 0 ] ) ) { cEdge [ 2 ] = true ; } else if ( ( q == points [ 0 ] && p == points [ 2 ] ) || ( q == points [ 2 ] && p == points [ 0 ] ) ) { cEdge [ 1 ] = true ; } else if ( ( q == points [ 1 ] && p == points [ 2 ] ) || ( q == points [ 2 ] && p == points [ 1 ] ) ) { cEdge [ 0 ] = true ; } }
Mark edge as constrained
2,968
public int edgeIndex ( TriangulationPoint p1 , TriangulationPoint p2 ) { if ( points [ 0 ] == p1 ) { if ( points [ 1 ] == p2 ) { return 2 ; } else if ( points [ 2 ] == p2 ) { return 1 ; } } else if ( points [ 1 ] == p1 ) { if ( points [ 2 ] == p2 ) { return 0 ; } else if ( points [ 0 ] == p2 ) { return 2 ; } } else if ( points [ 2 ] == p1 ) { if ( points [ 0 ] == p2 ) { return 1 ; } else if ( points [ 1 ] == p2 ) { return 0 ; } } return - 1 ; }
Get the neighbor that share this edge
2,969
public Future < Notice > report ( Throwable e ) { Notice notice = this . buildNotice ( e ) ; return this . send ( notice ) ; }
Asynchronously reports an exception to Airbrake .
2,970
public Future < Notice > send ( Notice notice ) { notice = this . filterNotice ( notice ) ; CompletableFuture < Notice > future = this . asyncSender . send ( notice ) ; final Notice finalNotice = notice ; future . whenComplete ( ( value , exception ) -> { this . applyHooks ( finalNotice ) ; } ) ; return future ; }
Asynchronously sends a Notice to Airbrake .
2,971
public Notice reportSync ( Throwable e ) { Notice notice = this . buildNotice ( e ) ; return this . sendSync ( notice ) ; }
Sychronously reports an exception to Airbrake .
2,972
public Notice sendSync ( Notice notice ) { notice = this . filterNotice ( notice ) ; notice = this . syncSender . send ( notice ) ; this . applyHooks ( notice ) ; return notice ; }
Synchronously sends a Notice to Airbrake .
2,973
protected void updateText ( ) { super . updateText ( ) ; _exampleInfo [ 3 ] . setText ( "[PageUp] Next model" ) ; _exampleInfo [ 4 ] . setText ( "[PageDown] Previous model" ) ; _exampleInfo [ 5 ] . setText ( "[1] Generate polygon type A " ) ; _exampleInfo [ 6 ] . setText ( "[2] Generate polygon type B " ) ; }
Update text information .
2,974
public static void mergeInstances ( Map < TriangulationPoint , TriangulationPoint > uniquePts , List < TriangulationPoint > ptList ) { for ( int idPoint = 0 ; idPoint < ptList . size ( ) ; idPoint ++ ) { TriangulationPoint pt = ptList . get ( idPoint ) ; TriangulationPoint uniquePt = uniquePts . get ( pt ) ; if ( uniquePt == null ) { uniquePts . put ( pt , pt ) ; } else { ptList . set ( idPoint , uniquePt ) ; } } }
Replace points in ptList for all equals object in uniquePts .
2,975
public static void updateTextureCoordinates ( Mesh mesh , List < DelaunayTriangle > triangles , double scale , double angle ) { TriangulationPoint vertex ; FloatBuffer tcBuf ; float width , maxX , minX , maxY , minY , x , y , xn , yn ; maxX = Float . NEGATIVE_INFINITY ; minX = Float . POSITIVE_INFINITY ; maxY = Float . NEGATIVE_INFINITY ; minY = Float . POSITIVE_INFINITY ; for ( DelaunayTriangle t : triangles ) { for ( int i = 0 ; i < 3 ; i ++ ) { vertex = t . points [ i ] ; x = vertex . getXf ( ) ; y = vertex . getYf ( ) ; maxX = x > maxX ? x : maxX ; minX = x < minX ? x : minX ; maxY = y > maxY ? y : maxY ; minY = y < minY ? x : minY ; } } width = maxX - minX > maxY - minY ? maxX - minX : maxY - minY ; width *= scale ; tcBuf = prepareTextureCoordinateBuffer ( mesh , 0 , 2 * 3 * triangles . size ( ) ) ; tcBuf . rewind ( ) ; for ( DelaunayTriangle t : triangles ) { for ( int i = 0 ; i < 3 ; i ++ ) { vertex = t . points [ i ] ; x = vertex . getXf ( ) - ( maxX - minX ) / 2 ; y = vertex . getYf ( ) - ( maxY - minY ) / 2 ; xn = ( float ) ( x * Math . cos ( angle ) - y * Math . sin ( angle ) ) ; yn = ( float ) ( y * Math . cos ( angle ) + x * Math . sin ( angle ) ) ; tcBuf . put ( xn / width ) ; tcBuf . put ( yn / width ) ; } } }
For now very primitive!
2,976
private void buildSkyBox ( ) { _skybox = new Skybox ( "skybox" , 300 , 300 , 300 ) ; try { SimpleResourceLocator sr2 = new SimpleResourceLocator ( ExampleBase . class . getClassLoader ( ) . getResource ( "org/poly2tri/examples/geotools/textures/" ) ) ; ResourceLocatorTool . addResourceLocator ( ResourceLocatorTool . TYPE_TEXTURE , sr2 ) ; } catch ( final URISyntaxException ex ) { ex . printStackTrace ( ) ; } final String dir = "" ; final Texture stars = TextureManager . load ( dir + "stars.gif" , Texture . MinificationFilter . Trilinear , Image . Format . GuessNoCompression , true ) ; _skybox . setTexture ( Skybox . Face . North , stars ) ; _skybox . setTexture ( Skybox . Face . West , stars ) ; _skybox . setTexture ( Skybox . Face . South , stars ) ; _skybox . setTexture ( Skybox . Face . East , stars ) ; _skybox . setTexture ( Skybox . Face . Up , stars ) ; _skybox . setTexture ( Skybox . Face . Down , stars ) ; _skybox . getTexture ( Skybox . Face . North ) . setWrap ( WrapMode . Repeat ) ; for ( Face f : Face . values ( ) ) { FloatBufferData fbd = _skybox . getFace ( f ) . getMeshData ( ) . getTextureCoords ( ) . get ( 0 ) ; fbd . getBuffer ( ) . clear ( ) ; fbd . getBuffer ( ) . put ( 0 ) . put ( 4 ) ; fbd . getBuffer ( ) . put ( 0 ) . put ( 0 ) ; fbd . getBuffer ( ) . put ( 4 ) . put ( 0 ) ; fbd . getBuffer ( ) . put ( 4 ) . put ( 4 ) ; } _node . attachChild ( _skybox ) ; }
Builds the sky box .
2,977
public void addSection ( GSection section ) { section . setPosition ( sectionList . size ( ) ) ; LinearLayout . LayoutParams params = new LinearLayout . LayoutParams ( ViewGroup . LayoutParams . MATCH_PARENT , ( int ) ( 48 * density ) ) ; sectionList . add ( section ) ; sections . addView ( section . getView ( ) , params ) ; }
Method used for customize layout
2,978
public void setFileSize ( ) { if ( arr [ DatenFilm . FILM_GROESSE ] . isEmpty ( ) ) arr [ DatenFilm . FILM_GROESSE ] = FileSize . laengeString ( arr [ DatenFilm . FILM_URL ] ) ; }
Determine file size from remote location .
2,979
private void processFromFile ( String source , ListeFilme listeFilme ) { notifyProgress ( source , PROGRESS_MAX ) ; try ( InputStream in = selectDecompressor ( source , new FileInputStream ( source ) ) ; JsonParser jp = new JsonFactory ( ) . createParser ( in ) ) { readData ( jp , listeFilme ) ; } catch ( FileNotFoundException ex ) { Log . errorLog ( 894512369 , "FilmListe existiert nicht: " + source ) ; listeFilme . clear ( ) ; } catch ( Exception ex ) { Log . errorLog ( 945123641 , ex , "FilmListe: " + source ) ; listeFilme . clear ( ) ; } }
Read a locally available filmlist .
2,980
private void processFromWeb ( URL source , ListeFilme listeFilme ) { Request . Builder builder = new Request . Builder ( ) . url ( source ) ; builder . addHeader ( "User-Agent" , Config . getUserAgent ( ) ) ; InputStreamProgressMonitor monitor = new InputStreamProgressMonitor ( ) { private int oldProgress = 0 ; public void progress ( long bytesRead , long size ) { final int iProgress = ( int ) ( bytesRead * 100 / size ) ; if ( iProgress != oldProgress ) { oldProgress = iProgress ; notifyProgress ( source . toString ( ) , iProgress ) ; } } } ; try ( Response response = MVHttpClient . getInstance ( ) . getHttpClient ( ) . newCall ( builder . build ( ) ) . execute ( ) ; ResponseBody body = response . body ( ) ) { if ( response . isSuccessful ( ) ) { try ( InputStream input = new ProgressMonitorInputStream ( body . byteStream ( ) , body . contentLength ( ) , monitor ) ) { try ( InputStream is = selectDecompressor ( source . toString ( ) , input ) ; JsonParser jp = new JsonFactory ( ) . createParser ( is ) ) { readData ( jp , listeFilme ) ; } } } } catch ( Exception ex ) { Log . errorLog ( 945123641 , ex , "FilmListe: " + source ) ; listeFilme . clear ( ) ; } }
Download a process a filmliste from the web .
2,981
public boolean addWithCheck ( DatenFilmlisteUrl filmliste ) { for ( DatenFilmlisteUrl datenUrlFilmliste : this ) { if ( datenUrlFilmliste . arr [ DatenFilmlisteUrl . FILM_UPDATE_SERVER_URL_NR ] . equals ( filmliste . arr [ DatenFilmlisteUrl . FILM_UPDATE_SERVER_URL_NR ] ) ) { return false ; } } return add ( filmliste ) ; }
ist die Liste mit den URLs zum Download einer Filmliste
2,982
private void insertDefaultActiveServers ( ) { listeFilmlistenUrls_akt . add ( new DatenFilmlisteUrl ( "http://m.picn.de/f/Filmliste-akt.xz" , DatenFilmlisteUrl . SERVER_ART_AKT ) ) ; listeFilmlistenUrls_akt . add ( new DatenFilmlisteUrl ( "http://m1.picn.de/f/Filmliste-akt.xz" , DatenFilmlisteUrl . SERVER_ART_AKT ) ) ; listeFilmlistenUrls_akt . add ( new DatenFilmlisteUrl ( "http://m2.picn.de/f/Filmliste-akt.xz" , DatenFilmlisteUrl . SERVER_ART_AKT ) ) ; listeFilmlistenUrls_akt . add ( new DatenFilmlisteUrl ( "http://download10.onlinetvrecorder.com/mediathekview/Filmliste-akt.xz" , DatenFilmlisteUrl . SERVER_ART_AKT ) ) ; listeFilmlistenUrls_akt . add ( new DatenFilmlisteUrl ( "http://mediathekview.jankal.me/Filmliste-akt.xz" , DatenFilmlisteUrl . SERVER_ART_AKT ) ) ; listeFilmlistenUrls_akt . add ( new DatenFilmlisteUrl ( "http://verteiler1.mediathekview.de/Filmliste-akt.xz" , DatenFilmlisteUrl . SERVER_ART_AKT ) ) ; listeFilmlistenUrls_akt . add ( new DatenFilmlisteUrl ( "http://verteiler2.mediathekview.de/Filmliste-akt.xz" , DatenFilmlisteUrl . SERVER_ART_AKT ) ) ; listeFilmlistenUrls_akt . add ( new DatenFilmlisteUrl ( "http://verteiler3.mediathekview.de/Filmliste-akt.xz" , DatenFilmlisteUrl . SERVER_ART_AKT ) ) ; }
Add our default full list servers .
2,983
private void insertDefaultDifferentialListServers ( ) { listeFilmlistenUrls_diff . add ( new DatenFilmlisteUrl ( "http://m.picn.de/f/Filmliste-diff.xz" , DatenFilmlisteUrl . SERVER_ART_DIFF ) ) ; listeFilmlistenUrls_diff . add ( new DatenFilmlisteUrl ( "http://m1.picn.de/f/Filmliste-diff.xz" , DatenFilmlisteUrl . SERVER_ART_DIFF ) ) ; listeFilmlistenUrls_diff . add ( new DatenFilmlisteUrl ( "http://m2.picn.de/f/Filmliste-diff.xz" , DatenFilmlisteUrl . SERVER_ART_DIFF ) ) ; listeFilmlistenUrls_diff . add ( new DatenFilmlisteUrl ( "http://download10.onlinetvrecorder.com/mediathekview/Filmliste-diff.xz" , DatenFilmlisteUrl . SERVER_ART_DIFF ) ) ; listeFilmlistenUrls_diff . add ( new DatenFilmlisteUrl ( "http://mediathekview.jankal.me/Filmliste-diff.xz" , DatenFilmlisteUrl . SERVER_ART_DIFF ) ) ; listeFilmlistenUrls_diff . add ( new DatenFilmlisteUrl ( "http://verteiler1.mediathekview.de/Filmliste-diff.xz" , DatenFilmlisteUrl . SERVER_ART_DIFF ) ) ; listeFilmlistenUrls_diff . add ( new DatenFilmlisteUrl ( "http://verteiler2.mediathekview.de/Filmliste-diff.xz" , DatenFilmlisteUrl . SERVER_ART_DIFF ) ) ; listeFilmlistenUrls_diff . add ( new DatenFilmlisteUrl ( "http://verteiler3.mediathekview.de/Filmliste-diff.xz" , DatenFilmlisteUrl . SERVER_ART_DIFF ) ) ; }
Add our default diff list servers .
2,984
public void updateURLsFilmlisten ( final boolean updateFullList ) { ListeFilmlistenUrls tmp = new ListeFilmlistenUrls ( ) ; if ( updateFullList ) { getDownloadUrlsFilmlisten ( Const . ADRESSE_FILMLISTEN_SERVER_AKT , tmp , Config . getUserAgent ( ) , DatenFilmlisteUrl . SERVER_ART_AKT ) ; if ( ! tmp . isEmpty ( ) ) { listeFilmlistenUrls_akt = tmp ; } else if ( listeFilmlistenUrls_akt . isEmpty ( ) ) { insertDefaultActiveServers ( ) ; } listeFilmlistenUrls_akt . sort ( ) ; } else { getDownloadUrlsFilmlisten ( Const . ADRESSE_FILMLISTEN_SERVER_DIFF , tmp , Config . getUserAgent ( ) , DatenFilmlisteUrl . SERVER_ART_DIFF ) ; if ( ! tmp . isEmpty ( ) ) { listeFilmlistenUrls_diff = tmp ; } else if ( listeFilmlistenUrls_diff . isEmpty ( ) ) { insertDefaultDifferentialListServers ( ) ; } listeFilmlistenUrls_diff . sort ( ) ; } if ( tmp . isEmpty ( ) ) { Log . errorLog ( 491203216 , new String [ ] { "Es ist ein Fehler aufgetreten!" , "Es konnten keine Updateserver zum aktualisieren der Filme" , "gefunden werden." } ) ; } }
Update the download server URLs .
2,985
private void parseServerEntry ( XMLStreamReader parser , ListeFilmlistenUrls listeFilmlistenUrls , String art ) { String serverUrl = "" ; String prio = "" ; int event ; try { while ( parser . hasNext ( ) ) { event = parser . next ( ) ; if ( event == XMLStreamConstants . START_ELEMENT ) { switch ( parser . getLocalName ( ) ) { case "URL" : serverUrl = parser . getElementText ( ) ; break ; case "Prio" : prio = parser . getElementText ( ) ; break ; } } if ( event == XMLStreamConstants . END_ELEMENT ) { if ( parser . getLocalName ( ) . equals ( "Server" ) ) { if ( ! serverUrl . equals ( "" ) ) { if ( prio . equals ( "" ) ) { prio = DatenFilmlisteUrl . FILM_UPDATE_SERVER_PRIO_1 ; } listeFilmlistenUrls . addWithCheck ( new DatenFilmlisteUrl ( serverUrl , prio , art ) ) ; } break ; } } } } catch ( XMLStreamException ignored ) { } }
Parse the server XML file .
2,986
private void buildColorMap ( ) { final NodeList styleData = doc . getElementsByTagName ( "tt:style" ) ; for ( int i = 0 ; i < styleData . getLength ( ) ; i ++ ) { final Node subnode = styleData . item ( i ) ; if ( subnode . hasAttributes ( ) ) { final NamedNodeMap attrMap = subnode . getAttributes ( ) ; final Node idNode = attrMap . getNamedItem ( "xml:id" ) ; final Node colorNode = attrMap . getNamedItem ( "tts:color" ) ; if ( idNode != null && colorNode != null ) { colorMap . put ( idNode . getNodeValue ( ) , colorNode . getNodeValue ( ) ) ; } } } }
Build a map of used colors within the TTML file .
2,987
public boolean parse ( Path ttmlFilePath ) { boolean ret ; try { final DocumentBuilderFactory dbf = DocumentBuilderFactory . newInstance ( ) ; dbf . setNamespaceAware ( true ) ; final DocumentBuilder db = dbf . newDocumentBuilder ( ) ; doc = db . parse ( ttmlFilePath . toFile ( ) ) ; final NodeList metaData = doc . getElementsByTagName ( "ebuttm:documentEbuttVersion" ) ; if ( metaData != null ) { final Node versionNode = metaData . item ( 0 ) ; if ( versionNode == null || ! versionNode . getTextContent ( ) . equalsIgnoreCase ( "v1.0" ) ) { throw new Exception ( "Unknown TTML file version" ) ; } } else { throw new Exception ( "Unknown File Format" ) ; } buildColorMap ( ) ; buildFilmList ( ) ; ret = true ; } catch ( Exception ex ) { Log . errorLog ( 912036478 , new String [ ] { ex . getLocalizedMessage ( ) , "File: " + ttmlFilePath } ) ; ret = false ; } return ret ; }
Parse the TTML file into internal representation .
2,988
public boolean parseXmlFlash ( Path ttmlFilePath ) { boolean ret ; try { final DocumentBuilderFactory dbf = DocumentBuilderFactory . newInstance ( ) ; dbf . setNamespaceAware ( true ) ; final DocumentBuilder db = dbf . newDocumentBuilder ( ) ; doc = db . parse ( ttmlFilePath . toFile ( ) ) ; final NodeList metaData = doc . getElementsByTagName ( "tt" ) ; final NodeList colorNote = doc . getElementsByTagName ( "style" ) ; if ( metaData != null ) { final Node node = metaData . item ( 0 ) ; if ( node . hasAttributes ( ) ) { final NamedNodeMap attrMap = node . getAttributes ( ) ; final Node xmlns = attrMap . getNamedItem ( "xmlns" ) ; if ( xmlns != null ) { final String s = xmlns . getNodeValue ( ) ; if ( ! s . equals ( "http://www.w3.org/2006/04/ttaf1" ) && ! s . equals ( "http://www.w3.org/ns/ttml" ) ) { throw new Exception ( "Unknown TTML file version" ) ; } } } else { throw new Exception ( "Unknown File Format" ) ; } } else { throw new Exception ( "Unknown File Format" ) ; } if ( colorNote != null ) { if ( colorNote . getLength ( ) == 0 ) { this . color = "#FFFFFF" ; } else { final Node node = colorNote . item ( 0 ) ; if ( node . hasAttributes ( ) ) { final NamedNodeMap attrMap = node . getAttributes ( ) ; final Node col = attrMap . getNamedItem ( "tts:color" ) ; if ( col != null ) { if ( ! col . getNodeValue ( ) . isEmpty ( ) ) { this . color = col . getNodeValue ( ) ; } } } else { throw new Exception ( "Unknown File Format" ) ; } } } else { throw new Exception ( "Unknown File Format" ) ; } buildFilmListFlash ( ) ; ret = true ; } catch ( Exception ex ) { Log . errorLog ( 46231470 , new String [ ] { ex . getLocalizedMessage ( ) , "File: " + ttmlFilePath } ) ; ret = false ; } return ret ; }
Parse the XML Subtitle File for Flash Player into internal representation .
2,989
public void toSrt ( Path srtFile ) { try ( FileOutputStream fos = new FileOutputStream ( srtFile . toFile ( ) ) ; OutputStreamWriter osw = new OutputStreamWriter ( fos , Charset . forName ( "UTF-8" ) ) ; PrintWriter writer = new PrintWriter ( osw ) ) { long counter = 1 ; for ( Subtitle title : subtitleList ) { writer . println ( counter ) ; writer . println ( srtFormat . format ( title . begin ) + " + srtFormat . format ( title . end ) ) ; for ( StyledString entry : title . listOfStrings ) { if ( ! entry . color . isEmpty ( ) ) { writer . print ( "<font color=\"" + entry . color + "\">" ) ; } writer . print ( entry . text ) ; if ( ! entry . color . isEmpty ( ) ) { writer . print ( "</font>" ) ; } writer . println ( ) ; } writer . println ( "" ) ; counter ++ ; } } catch ( Exception ex ) { Log . errorLog ( 201036470 , ex , "File: " + srtFile ) ; } }
Convert internal representation into SubRip Text Format and save to file .
2,990
private static long getFileSizeFromUrl ( String url ) { if ( ! url . toLowerCase ( ) . startsWith ( "http" ) ) { return - 1 ; } final Request request = new Request . Builder ( ) . url ( url ) . head ( ) . build ( ) ; long respLength = - 1 ; try ( Response response = MVHttpClient . getInstance ( ) . getReducedTimeOutClient ( ) . newCall ( request ) . execute ( ) ; ResponseBody body = response . body ( ) ) { if ( response . isSuccessful ( ) ) respLength = body . contentLength ( ) ; } catch ( IOException ignored ) { respLength = - 1 ; } if ( respLength < 1_000_000 ) { respLength = - 1 ; } return respLength ; }
Return the size of a URL in bytes .
2,991
private static String removeWindowsTrailingDots ( String fileName ) { while ( ! fileName . isEmpty ( ) && ( fileName . endsWith ( "." ) || fileName . endsWith ( " " ) ) ) { fileName = fileName . substring ( 0 , fileName . length ( ) - 1 ) ; } return fileName ; }
Remove stray trailing dots from string when we are on Windows OS .
2,992
public static String removeIllegalCharacters ( final String input , boolean isPath ) { String ret = input ; switch ( Functions . getOs ( ) ) { case MAC : case LINUX : ret = removeStartingDots ( ret ) ; ret = ret . replaceAll ( isPath ? REGEXP_ILLEGAL_CHARACTERS_OTHERS_PATH : REGEXP_ILLEGAL_CHARACTERS_OTHERS , "_" ) ; break ; case WIN64 : case WIN32 : ret = removeWindowsTrailingDots ( ret ) ; ret = ret . replaceAll ( isPath ? REGEXP_ILLEGAL_CHARACTERS_WINDOWS_PATH : REGEXP_ILLEGAL_CHARACTERS_WINDOWS , "_" ) ; break ; default : ret = removeStartingDots ( ret ) ; ret = ret . replaceAll ( isPath ? REGEXP_ILLEGAL_CHARACTERS_WINDOWS_PATH : REGEXP_ILLEGAL_CHARACTERS_WINDOWS , "_" ) ; break ; } return ret ; }
Remove illegal characters from String based on current OS .
2,993
public static String replaceLeerDateiname ( String name , boolean isPath , boolean userReplace , boolean onlyAscii ) { String ret = name ; boolean isWindowsPath = false ; if ( SystemInfo . isWindows ( ) && isPath && ret . length ( ) > 1 && ret . charAt ( 1 ) == ':' ) { isWindowsPath = true ; ret = ret . replaceFirst ( ":" , "" ) ; } if ( userReplace ) { ret = ReplaceList . replace ( ret , isPath ) ; } if ( onlyAscii ) { ret = convertToASCIIEncoding ( ret , isPath ) ; } else { ret = convertToNativeEncoding ( ret , isPath ) ; } if ( isWindowsPath ) { if ( ret . length ( ) == 1 ) { ret = ret + ":" ; } else if ( ret . length ( ) > 1 ) { ret = ret . charAt ( 0 ) + ":" + ret . substring ( 1 ) ; } } return ret ; }
Entferne verbotene Zeichen aus Dateiname .
2,994
public static OperatingSystemType getOs ( ) { OperatingSystemType os = OperatingSystemType . UNKNOWN ; if ( System . getProperty ( "os.name" ) . toLowerCase ( ) . contains ( "windows" ) ) { if ( System . getenv ( "ProgramFiles(x86)" ) != null ) { os = OperatingSystemType . WIN64 ; } else if ( System . getenv ( "ProgramFiles" ) != null ) { os = OperatingSystemType . WIN32 ; } } else if ( SystemInfo . isLinux ( ) ) { os = OperatingSystemType . LINUX ; } else if ( System . getProperty ( "os.name" ) . toLowerCase ( ) . contains ( "freebsd" ) ) { os = OperatingSystemType . LINUX ; } else if ( SystemInfo . isMacOSX ( ) ) { os = OperatingSystemType . MAC ; } return os ; }
Detect and return the currently used operating system .
2,995
public int diffInSekunden ( ) { final int ret = new Long ( ( this . getTime ( ) - new Datum ( ) . getTime ( ) ) / ( 1000 ) ) . intValue ( ) ; return Math . abs ( ret ) ; }
Liefert den Betrag der Zeitdifferenz zu jetzt .
2,996
public void filmlisteSchreibenJsonCompressed ( String datei , ListeFilme listeFilme ) { final String tempFile = datei + "_temp" ; filmlisteSchreibenJson ( tempFile , listeFilme ) ; try { Log . sysLog ( "Komprimiere Datei: " + datei ) ; if ( datei . endsWith ( Const . FORMAT_XZ ) ) { final Path xz = testNativeXz ( ) ; if ( xz != null ) { Process p = new ProcessBuilder ( xz . toString ( ) , "-9" , tempFile ) . start ( ) ; final int exitCode = p . waitFor ( ) ; if ( exitCode == 0 ) { Files . move ( Paths . get ( tempFile + ".xz" ) , Paths . get ( datei ) , StandardCopyOption . REPLACE_EXISTING ) ; } } else compressFile ( tempFile , datei ) ; } Files . deleteIfExists ( Paths . get ( tempFile ) ) ; } catch ( IOException | InterruptedException ex ) { Log . sysLog ( "Komprimieren fehlgeschlagen" ) ; } }
Write film data and compress with LZMA2 .
2,997
public synchronized void deleteAllFilms ( String sender ) { removeIf ( film -> film . arr [ DatenFilm . FILM_SENDER ] . equalsIgnoreCase ( sender ) ) ; }
Delete all films from specified sender .
2,998
public synchronized boolean isTooOldForDiff ( ) { if ( isEmpty ( ) ) { return true ; } try { final String dateMaxDiff_str = new SimpleDateFormat ( "yyyy.MM.dd__" ) . format ( new Date ( ) ) + Const . TIME_MAX_AGE_FOR_DIFF + ":00:00" ; final Date dateMaxDiff = new SimpleDateFormat ( "yyyy.MM.dd__HH:mm:ss" ) . parse ( dateMaxDiff_str ) ; final Date dateFilmliste = getAgeAsDate ( ) ; if ( dateFilmliste != null ) { return dateFilmliste . getTime ( ) < dateMaxDiff . getTime ( ) ; } } catch ( Exception ignored ) { } return true ; }
Check if Filmlist is too old for using a diff list .
2,999
public boolean isOlderThan ( int sekunden ) { int ret = getAge ( ) ; if ( ret != 0 ) { Log . sysLog ( "Die Filmliste ist " + ret / 60 + " Minuten alt" ) ; } return ret > sekunden ; }
Check if list is older than specified parameter .