idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
11,600 | public boolean hasCategory ( final String conceptURI ) { return Iterables . any ( getCategories ( ) , new Predicate < TopicAnnotation > ( ) { @ Override public boolean apply ( TopicAnnotation ta ) { return ta . getTopicReference ( ) . equals ( conceptURI ) ; } } ) ; } | Returns true if the contents has been categorized with a category identified by the URI passed by parameter | 67 | 18 |
11,601 | public static SQLiteDatabase create ( CursorFactory factory ) { // This is a magic string with special meaning for SQLite. return openDatabase ( com . couchbase . lite . internal . database . sqlite . SQLiteDatabaseConfiguration . MEMORY_DB_PATH , factory , CREATE_IF_NECESSARY ) ; } | Create a memory backed SQLite database . Its contents will be destroyed when the database is closed . | 71 | 19 |
11,602 | public long replace ( String table , String nullColumnHack , ContentValues initialValues ) { try { return insertWithOnConflict ( table , nullColumnHack , initialValues , CONFLICT_REPLACE ) ; } catch ( SQLException e ) { DLog . e ( TAG , "Error inserting " + initialValues , e ) ; return - 1 ; } } | Convenience method for replacing a row in the database . | 79 | 12 |
11,603 | private static byte [ ] decodeBase64Digest ( String base64Digest ) { String expectedPrefix = "sha1-" ; if ( ! base64Digest . startsWith ( expectedPrefix ) ) { throw new IllegalArgumentException ( base64Digest + " did not start with " + expectedPrefix ) ; } base64Digest = base64Digest . replaceFirst ( expectedPrefix , "... | Decode base64 d getDigest into a byte array that is suitable for use as a blob key . | 139 | 22 |
11,604 | protected void fireTrigger ( final ReplicationTrigger trigger ) { Log . d ( Log . TAG_SYNC , "%s [fireTrigger()] => " + trigger , this ) ; // All state machine triggers need to happen on the replicator thread synchronized ( executor ) { if ( ! executor . isShutdown ( ) ) { executor . submit ( new Runnable ( ) { @ Overr... | Fire a trigger to the state machine | 180 | 7 |
11,605 | protected void start ( ) { try { if ( ! db . isOpen ( ) ) { String msg = String . format ( Locale . ENGLISH , "Db: %s is not open, abort replication" , db ) ; parentReplication . setLastError ( new Exception ( msg ) ) ; fireTrigger ( ReplicationTrigger . STOP_IMMEDIATE ) ; return ; } db . addActiveReplication ( parentR... | Start the replication process . | 268 | 5 |
11,606 | protected void close ( ) { this . authenticating = false ; // cancel pending futures for ( Future future : pendingFutures ) { future . cancel ( false ) ; CancellableRunnable runnable = cancellables . get ( future ) ; if ( runnable != null ) { runnable . cancel ( ) ; cancellables . remove ( future ) ; } } // shutdown Sc... | Close all resources associated with this replicator . | 212 | 9 |
11,607 | @ InterfaceAudience . Private protected void checkSession ( ) { if ( getAuthenticator ( ) != null ) { Authorizer auth = ( Authorizer ) getAuthenticator ( ) ; auth . setRemoteURL ( remote ) ; auth . setLocalUUID ( db . publicUUID ( ) ) ; } if ( getAuthenticator ( ) != null && getAuthenticator ( ) instanceof SessionCooki... | Before doing anything else determine whether we have an active login session . | 122 | 13 |
11,608 | @ InterfaceAudience . Private private void refreshRemoteCheckpointDoc ( ) { Log . i ( Log . TAG_SYNC , "%s: Refreshing remote checkpoint to get its _rev..." , this ) ; Future future = sendAsyncRequest ( "GET" , "_local/" + remoteCheckpointDocID ( ) , null , new RemoteRequestCompletion ( ) { @ Override public void onCom... | Variant of - fetchRemoveCheckpointDoc that s used while replication is running to reload the checkpoint to get its current revision number if there was an error saving it . | 273 | 34 |
11,609 | protected void stop ( ) { this . authenticating = false ; // clear batcher batcher . clear ( ) ; // set non-continuous setLifecycle ( Replication . Lifecycle . ONESHOT ) ; // cancel if middle of retry cancelRetryFuture ( ) ; // cancel all pending future tasks. while ( ! pendingFutures . isEmpty ( ) ) { Future future = ... | Actual work of stopping the replication process . | 172 | 9 |
11,610 | private void notifyChangeListeners ( final Replication . ChangeEvent changeEvent ) { if ( changeListenerNotifyStyle == ChangeListenerNotifyStyle . SYNC ) { for ( ChangeListener changeListener : changeListeners ) { try { changeListener . changed ( changeEvent ) ; } catch ( Exception e ) { Log . e ( Log . TAG_SYNC , "Unk... | Notify all change listeners of a ChangeEvent | 214 | 9 |
11,611 | private void scheduleRetryFuture ( ) { Log . v ( Log . TAG_SYNC , "%s: Failed to xfer; will retry in %d sec" , this , RETRY_DELAY_SECONDS ) ; synchronized ( executor ) { if ( ! executor . isShutdown ( ) ) { this . retryFuture = executor . schedule ( new Runnable ( ) { public void run ( ) { retryIfReady ( ) ; } } , RETR... | helper function to schedule retry future . no in iOS code . | 126 | 14 |
11,612 | private void cancelRetryFuture ( ) { if ( retryFuture != null && ! retryFuture . isDone ( ) ) { retryFuture . cancel ( true ) ; } retryFuture = null ; } | helper function to cancel retry future . not in iOS code . | 45 | 14 |
11,613 | protected void retryReplicationIfError ( ) { Log . d ( TAG , "retryReplicationIfError() state=" + stateMachine . getState ( ) + ", error=" + this . error + ", isContinuous()=" + isContinuous ( ) + ", isTransientError()=" + Utils . isTransientError ( this . error ) ) ; // Make sure if state is IDLE, this method should b... | Retry replication if previous attempt ends with error | 218 | 9 |
11,614 | void dumpUnsafe ( Printer printer , boolean verbose ) { printer . println ( "Connection #" + mConnectionId + ":" ) ; if ( verbose ) { printer . println ( " connectionPtr: 0x" + Long . toHexString ( mConnectionPtr ) ) ; } printer . println ( " isPrimaryConnection: " + mIsPrimaryConnection ) ; printer . println ( " onlyA... | Dumps debugging information about this connection in the case where the caller might not actually own the connection . | 117 | 20 |
11,615 | void collectDbStatsUnsafe ( ArrayList < com . couchbase . lite . internal . database . sqlite . SQLiteDebug . DbStats > dbStatsList ) { dbStatsList . add ( getMainDbStatsUnsafe ( 0 , 0 , 0 ) ) ; } | Collects statistics about database connection memory usage in the case where the caller might not actually own the connection . | 60 | 21 |
11,616 | protected void execute ( ) { Log . v ( Log . TAG_SYNC , "%s: RemoteRequest execute() called, url: %s" , this , url ) ; executeRequest ( factory . getOkHttpClient ( ) , request ( ) ) ; Log . v ( Log . TAG_SYNC , "%s: RemoteRequest execute() finished, url: %s" , this , url ) ; } | Execute remote request | 86 | 4 |
11,617 | protected RequestBody setCompressedBody ( byte [ ] bodyBytes ) { if ( bodyBytes . length < MIN_JSON_LENGTH_TO_COMPRESS ) return null ; byte [ ] encodedBytes = Utils . compressByGzip ( bodyBytes ) ; if ( encodedBytes == null || encodedBytes . length >= bodyBytes . length ) return null ; return RequestBody . create ( JSO... | Generate gzipped body | 88 | 6 |
11,618 | int indexOf ( byte [ ] data , int dataLength , byte [ ] pattern , int dataOffset ) { int [ ] failure = computeFailure ( pattern ) ; int j = 0 ; if ( data . length == 0 ) return - 1 ; //final int dataLength = data.length; final int patternLength = pattern . length ; for ( int i = dataOffset ; i < dataLength ; i ++ ) { w... | Finds the first occurrence of the pattern in the text . | 148 | 12 |
11,619 | private static int [ ] computeFailure ( byte [ ] pattern ) { int [ ] failure = new int [ pattern . length ] ; int j = 0 ; for ( int i = 1 ; i < pattern . length ; i ++ ) { while ( j > 0 && pattern [ j ] != pattern [ i ] ) j = failure [ j - 1 ] ; if ( pattern [ j ] == pattern [ i ] ) j ++ ; failure [ i ] = j ; } return ... | Computes the failure function using a boot - strapping process where the pattern is matched against itself . | 101 | 20 |
11,620 | @ InterfaceAudience . Public public List < String > getAllDatabaseNames ( ) { String [ ] databaseFiles = directoryFile . list ( new FilenameFilter ( ) { @ Override public boolean accept ( File dir , String filename ) { if ( filename . endsWith ( Manager . kDBExtension ) ) { return true ; } return false ; } } ) ; List <... | An array of the names of all existing databases . | 173 | 10 |
11,621 | @ InterfaceAudience . Public public void close ( ) { synchronized ( lockDatabases ) { Log . d ( Database . TAG , "Closing " + this ) ; // Close all database: // Snapshot of the current open database to avoid concurrent modification as // the database will be forgotten (removed from the databases map) when it is closed:... | Releases all resources used by the Manager instance and closes all its databases . | 202 | 15 |
11,622 | @ InterfaceAudience . Public public boolean replaceDatabase ( String databaseName , String databaseDir ) { Database db = getDatabase ( databaseName , false ) ; if ( db == null ) return false ; File dir = new File ( databaseDir ) ; if ( ! dir . exists ( ) ) { Log . w ( Database . TAG , "Database file doesn't exist at pa... | Replaces or installs a database from a file . | 449 | 10 |
11,623 | @ InterfaceAudience . Private public Future runAsync ( String databaseName , final AsyncTask function ) throws CouchbaseLiteException { final Database database = getDatabase ( databaseName ) ; return runAsync ( new Runnable ( ) { @ Override public void run ( ) { function . run ( database ) ; } } ) ; } | Asynchronously dispatches a callback to run on a background thread . The callback will be passed Database instance . There is not currently a known reason to use it it may not make sense on the Android API but it was added for the purpose of having a consistent API with iOS . | 71 | 56 |
11,624 | @ Override public void startedPart ( Map headers ) { if ( _docReader != null ) throw new IllegalStateException ( "_docReader is already defined" ) ; Log . v ( TAG , "%s: Starting new document; headers =%s" , this , headers ) ; _docReader = new MultipartDocumentReader ( db ) ; _docReader . setHeaders ( headers ) ; _docR... | This method is called when a part s headers have been parsed before its data is parsed . | 95 | 18 |
11,625 | @ Override public void finishedPart ( ) { if ( _docReader == null ) throw new IllegalStateException ( "_docReader is not defined" ) ; _docReader . finish ( ) ; _onDocument . onDocument ( _docReader . getDocumentProperties ( ) , _docReader . getDocumentSize ( ) ) ; _docReader = null ; Log . v ( TAG , "%s: Finished docum... | This method is called when a part is complete . | 93 | 10 |
11,626 | @ InterfaceAudience . Public public Document getDocument ( ) { if ( getDocumentId ( ) == null ) { return null ; } assert ( database != null ) ; Document document = database . getDocument ( getDocumentId ( ) ) ; document . loadCurrentRevisionFrom ( this ) ; return document ; } | The document this row was mapped from . This will be nil if a grouping was enabled in the query because then the result rows don t correspond to individual documents . | 65 | 32 |
11,627 | @ InterfaceAudience . Public public String getDocumentId ( ) { // Get the doc id from either the embedded document contents, or the '_id' value key. // Failing that, there's no document linking, so use the regular old _sourceDocID String docID = null ; if ( documentRevision != null ) docID = documentRevision . getDocID... | The ID of the document described by this view row . This is not necessarily the same as the document that caused this row to be emitted ; see the discussion of the . sourceDocumentID property for details . | 160 | 41 |
11,628 | @ InterfaceAudience . Public public String getDocumentRevisionId ( ) { // Get the revision id from either the embedded document contents, // or the '_rev' or 'rev' value key: String rev = null ; if ( documentRevision != null ) rev = documentRevision . getRevID ( ) ; if ( rev == null ) { if ( value instanceof Map ) { Ma... | The revision ID of the document this row was mapped from . | 145 | 12 |
11,629 | public void add ( final AtomicAction action ) { if ( action instanceof Action ) { Action a = ( Action ) action ; peforms . addAll ( a . peforms ) ; backouts . addAll ( a . backouts ) ; cleanUps . addAll ( a . cleanUps ) ; } else { add ( new ActionBlock ( ) { @ Override public void execute ( ) throws ActionException { a... | Adds an action as a step of thid one . | 154 | 11 |
11,630 | public void add ( ActionBlock perform , ActionBlock backout , ActionBlock cleanup ) { peforms . add ( perform != null ? perform : nullAction ) ; backouts . add ( backout != null ? backout : nullAction ) ; cleanUps . add ( cleanup != null ? cleanup : nullAction ) ; } | Adds an action as a step of this one . The action has three components each optional . | 67 | 18 |
11,631 | public void run ( ) throws ActionException { try { perform ( ) ; try { cleanup ( ) ; // Ignore exception } catch ( ActionException e ) { } lastError = null ; } catch ( ActionException e ) { // (perform: has already backed out whatever it did) lastError = e ; throw e ; } } | Performs all the actions in order . If any action fails backs out the previously performed actions in reverse order . If the actions succeeded cleans them up in reverse order . The lastError property is set to the exception thrown by the failed perform block . The failedStep property is set to the index of the failed p... | 69 | 64 |
11,632 | private void doAction ( List < ActionBlock > actions ) throws ActionException { try { actions . get ( nextStep ) . execute ( ) ; } catch ( ActionException e ) { throw e ; } catch ( Exception e ) { throw new ActionException ( "Exception raised by step: " + nextStep , e ) ; } } | Subroutine that calls an action block from either performs backOuts or cleanUps . | 69 | 19 |
11,633 | @ Override public boolean setVersion ( String version ) { // Update the version column in the database. This is a little weird looking because we want // to avoid modifying the database if the version didn't change, and because the row might // not exist yet. SQLiteStorageEngine storage = store . getStorageEngine ( ) ;... | Updates the version of the view . A change in version means the delegate s map block has changed its semantics so the _index should be deleted . | 374 | 30 |
11,634 | @ Override public long getLastSequenceIndexed ( ) { String sql = "SELECT lastSequence FROM views WHERE name=?" ; String [ ] args = { name } ; Cursor cursor = null ; long result = - 1 ; try { cursor = store . getStorageEngine ( ) . rawQuery ( sql , args ) ; if ( cursor . moveToNext ( ) ) { result = cursor . getLong ( 0 ... | The last sequence number that has been indexed . | 142 | 9 |
11,635 | private static boolean groupTogether ( Object key1 , Object key2 , int groupLevel ) { if ( groupLevel == 0 || ! ( key1 instanceof List ) || ! ( key2 instanceof List ) ) { return key1 . equals ( key2 ) ; } @ SuppressWarnings ( "unchecked" ) List < Object > key1List = ( List < Object > ) key1 ; @ SuppressWarnings ( "unch... | Are key1 and key2 grouped together at this groupLevel? | 303 | 13 |
11,636 | public static Object groupKey ( Object key , int groupLevel ) { if ( groupLevel > 0 && ( key instanceof List ) && ( ( ( List < Object > ) key ) . size ( ) > groupLevel ) ) { return ( ( List < Object > ) key ) . subList ( 0 , groupLevel ) ; } else { return key ; } } | Returns the prefix of the key to use in the result row at this groupLevel | 76 | 16 |
11,637 | @ InterfaceAudience . Public public int getTotalRows ( ) { try { updateIndex ( ) ; } catch ( CouchbaseLiteException e ) { Log . e ( Log . TAG_VIEW , "Update index failed when getting the total rows" , e ) ; } return getCurrentTotalRows ( ) ; } | Get total number of rows in the view . The view s index will be updated if needed before returning the value . | 68 | 23 |
11,638 | @ InterfaceAudience . Public public static double totalValues ( List < Object > values ) { double total = 0 ; for ( Object object : values ) { if ( object instanceof Number ) { Number number = ( Number ) object ; total += number . doubleValue ( ) ; } else { Log . w ( Log . TAG_VIEW , "Warning non-numeric value found in... | Utility function to use in reduce blocks . Totals an array of Numbers . | 95 | 16 |
11,639 | @ InterfaceAudience . Private protected Status updateIndexes ( List < View > views ) throws CouchbaseLiteException { List < ViewStore > storages = new ArrayList < ViewStore > ( ) ; for ( View view : views ) { storages . add ( view . viewStore ) ; } return viewStore . updateIndexes ( storages ) ; } | Update multiple view indexes at once . | 79 | 7 |
11,640 | @ InterfaceAudience . Private public List < QueryRow > query ( QueryOptions options ) throws CouchbaseLiteException { if ( options == null ) options = new QueryOptions ( ) ; if ( groupOrReduce ( options ) ) return viewStore . reducedQuery ( options ) ; else return viewStore . regularQuery ( options ) ; } | Queries the view . Does NOT first update the index . | 71 | 12 |
11,641 | public static Printer create ( Printer printer , String prefix ) { if ( prefix == null || prefix . equals ( "" ) ) { return printer ; } return new PrefixPrinter ( printer , prefix ) ; } | Creates a new PrefixPrinter . | 45 | 9 |
11,642 | public void deleteCookie ( Cookie cookie ) { cookies . remove ( cookie . name ( ) ) ; deletePersistedCookie ( cookie . name ( ) ) ; } | Non - standard helper method to delete cookie | 35 | 8 |
11,643 | public static int getDefaultPageSize ( ) { synchronized ( sLock ) { if ( sDefaultPageSize == 0 ) { try { Class clazz = Class . forName ( "android.os.StatFs" ) ; Method m = clazz . getMethod ( "getBlockSize" ) ; Object statFsObj = clazz . getConstructor ( String . class ) . newInstance ( "/data" ) ; Integer value = ( In... | Gets the default page size to use when creating a database . | 157 | 13 |
11,644 | private static String byteArrayToHexString ( byte [ ] bytes ) { StringBuilder sb = new StringBuilder ( bytes . length * 2 ) ; for ( byte element : bytes ) { int v = element & 0xff ; if ( v < 16 ) { sb . append ( ' ' ) ; } sb . append ( Integer . toHexString ( v ) ) ; } return sb . toString ( ) ; } | Using some super basic byte array < ; - > ; hex conversions so we don t have to rely on any large Base64 libraries . Can be overridden if you like! | 92 | 37 |
11,645 | @ InterfaceAudience . Public public SavedRevision createRevision ( Map < String , Object > properties ) throws CouchbaseLiteException { boolean allowConflict = false ; return document . putProperties ( properties , revisionInternal . getRevID ( ) , allowConflict ) ; } | Creates and saves a new revision with the given properties . This will fail with a 412 error if the receiver is not the current revision of the document . | 61 | 31 |
11,646 | @ Override @ InterfaceAudience . Public public Map < String , Object > getProperties ( ) { Map < String , Object > properties = revisionInternal . getProperties ( ) ; if ( ! checkedProperties ) { if ( properties == null ) { if ( loadProperties ( ) == true ) { properties = revisionInternal . getProperties ( ) ; } } chec... | The contents of this revision of the document . Any keys in the dictionary that begin with _ such as _id and _rev contain CouchbaseLite metadata . | 103 | 32 |
11,647 | public Object jsonObject ( ) { if ( json == null ) { return null ; } if ( cached == null ) { Object tmp = null ; if ( json [ 0 ] == ' ' ) { tmp = new LazyJsonObject < String , Object > ( json ) ; } else if ( json [ 0 ] == ' ' ) { tmp = new LazyJsonArray < Object > ( json ) ; } else { try { // NOTE: This if-else conditi... | values are requested | 292 | 3 |
11,648 | public void queueObjects ( List < T > objects ) { if ( objects == null || objects . size ( ) == 0 ) return ; boolean readyToProcess = false ; synchronized ( mutex ) { Log . v ( Log . TAG_BATCHER , "%s: queueObjects called with %d objects (current inbox size = %d)" , this , objects . size ( ) , inbox . size ( ) ) ; inbo... | Adds multiple objects to the queue . | 234 | 7 |
11,649 | public void flushAll ( boolean waitForAllToFinish ) { Log . v ( Log . TAG_BATCHER , "%s: flushing all objects (wait=%b)" , this , waitForAllToFinish ) ; synchronized ( mutex ) { isFlushing = true ; unschedule ( ) ; } while ( true ) { ScheduledFuture future = null ; synchronized ( mutex ) { if ( inbox . size ( ) == 0 ) ... | Sends _all_ the queued objects at once to the processor block . After this method returns all inbox objects will be processed . | 328 | 27 |
11,650 | private void scheduleBatchProcess ( boolean immediate ) { synchronized ( mutex ) { if ( inbox . size ( ) == 0 ) return ; // Schedule the processing. To improve latency, if we haven't processed anything // in at least our delay time, rush these object(s) through a minimum delay: long suggestedDelay = 0 ; if ( ! immediat... | Schedule batch process based on capacity inbox size and last processed time . | 225 | 14 |
11,651 | private void scheduleWithDelay ( long delay ) { synchronized ( mutex ) { if ( scheduled && delay < scheduledDelay ) { if ( isPendingFutureReadyOrInProcessing ( ) ) { // Ignore as there is one batch currently in processing or ready to be processed: Log . v ( Log . TAG_BATCHER , "%s: scheduleWithDelay: %d ms, ignored as ... | Schedule the batch processing with the delay . If there is one batch currently in processing the schedule will be ignored as after the processing is done the next batch will be rescheduled . | 311 | 37 |
11,652 | private void unschedule ( ) { synchronized ( mutex ) { if ( pendingFuture != null && ! pendingFuture . isDone ( ) && ! pendingFuture . isCancelled ( ) ) { Log . v ( Log . TAG_BATCHER , "%s: cancelling the pending future ..." , this ) ; pendingFuture . cancel ( false ) ; } scheduled = false ; } } | Unschedule the scheduled batch processing . | 82 | 8 |
11,653 | private boolean isPendingFutureReadyOrInProcessing ( ) { synchronized ( mutex ) { if ( pendingFuture != null && ! pendingFuture . isDone ( ) && ! pendingFuture . isCancelled ( ) ) { return pendingFuture . getDelay ( TimeUnit . MILLISECONDS ) <= 0 ; } return false ; } } | Check if the current pending future is ready to be processed or in processing . | 74 | 15 |
11,654 | private void processNow ( ) { List < T > toProcess ; boolean scheduleNextBatchImmediately = false ; synchronized ( mutex ) { int count = inbox . size ( ) ; Log . v ( Log . TAG_BATCHER , "%s: processNow() called, inbox size: %d" , this , count ) ; if ( count == 0 ) return ; else if ( count <= capacity ) { toProcess = ne... | This method is called by the work executor to do the batch process . The inbox items up to the batcher capacity will be taken out to process . The next batch will be rescheduled if there are still some items left in the inbox . | 345 | 50 |
11,655 | private String getRequestHeaderContentType ( ) { String contentType = getRequestHeaderValue ( "Content-Type" ) ; if ( contentType != null ) { // remove parameter (Content-Type := type "/" subtype *[";" parameter] ) int index = contentType . indexOf ( ' ' ) ; if ( index > 0 ) contentType = contentType . substring ( 0 , ... | get Content - Type from URLConnection | 103 | 7 |
11,656 | private void setResponseLocation ( URL url ) { String location = url . getPath ( ) ; String query = url . getQuery ( ) ; if ( query != null ) { int startOfQuery = location . indexOf ( query ) ; if ( startOfQuery > 0 ) { location = location . substring ( 0 , startOfQuery ) ; } } connection . getResHeader ( ) . add ( "Lo... | Router + Handlers | 93 | 5 |
11,657 | private static void convertCBLQueryRowsToMaps ( Map < String , Object > allDocsResult ) { List < Map < String , Object > > rowsAsMaps = new ArrayList < Map < String , Object > > ( ) ; List < QueryRow > rows = ( List < QueryRow > ) allDocsResult . get ( "rows" ) ; if ( rows != null ) { for ( QueryRow row : rows ) { rows... | This is a hack to deal with the fact that there is currently no custom serializer for QueryRow . Instead just convert everything to generic Maps . | 128 | 29 |
11,658 | @ Override public void changed ( Database . ChangeEvent event ) { synchronized ( changesLock ) { if ( isTimeout ) return ; lastChangesTimestamp = System . currentTimeMillis ( ) ; // Stop timeout timer: stopTimeout ( ) ; // In race condition, new doc or update doc is fired before starting to observe the // DatabaseChang... | Implementation of ChangeListener | 548 | 5 |
11,659 | public void cancel ( ) { final OnCancelListener listener ; synchronized ( this ) { if ( mIsCanceled ) { return ; } mIsCanceled = true ; mCancelInProgress = true ; listener = mOnCancelListener ; } try { if ( listener != null ) { listener . onCancel ( ) ; } } finally { synchronized ( this ) { mCancelInProgress = false ; ... | Cancels the operation and signals the cancellation listener . If the operation has not yet started then it will be canceled as soon as it does . | 97 | 29 |
11,660 | public void setOnCancelListener ( OnCancelListener listener ) { synchronized ( this ) { waitForCancelFinishedLocked ( ) ; if ( mOnCancelListener == listener ) { return ; } mOnCancelListener = listener ; if ( ! mIsCanceled || listener == null ) { return ; } } listener . onCancel ( ) ; } | Sets the cancellation listener to be called when canceled . | 80 | 11 |
11,661 | @ InterfaceAudience . Public public void waitForRows ( ) throws CouchbaseLiteException { start ( ) ; while ( true ) { try { queryFuture . get ( ) ; break ; } catch ( InterruptedException e ) { continue ; } catch ( Exception e ) { lastError = e ; throw new CouchbaseLiteException ( e , Status . INTERNAL_SERVER_ERROR ) ; ... | Blocks until the intial async query finishes . After this call either . rows or . error will be non - nil . | 89 | 24 |
11,662 | @ InterfaceAudience . Public public QueryEnumerator getRows ( ) { start ( ) ; if ( rows == null ) { return null ; } else { // Have to return a copy because the enumeration has to start at item #0 every time return new QueryEnumerator ( rows ) ; } } | Gets the results of the Query . The value will be null until the initial Query completes . | 65 | 19 |
11,663 | @ InterfaceAudience . Public public SavedRevision getCurrentRevision ( ) { if ( currentRevision == null ) currentRevision = getRevision ( null ) ; return currentRevision ; } | Get the current revision | 43 | 4 |
11,664 | @ InterfaceAudience . Public public Map < String , Object > getProperties ( ) { return getCurrentRevision ( ) == null ? null : getCurrentRevision ( ) . getProperties ( ) ; } | The contents of the current revision of the document . This is shorthand for self . currentRevision . properties . Any keys in the dictionary that begin with _ such as _id and _rev contain CouchbaseLite metadata . | 45 | 45 |
11,665 | @ InterfaceAudience . Public public boolean delete ( ) throws CouchbaseLiteException { return getCurrentRevision ( ) == null ? false : getCurrentRevision ( ) . deleteDocument ( ) != null ; } | Deletes this document by adding a deletion revision . This will be replicated to other databases . | 45 | 18 |
11,666 | @ InterfaceAudience . Public public void purge ( ) throws CouchbaseLiteException { Map < String , List < String > > docsToRevs = new HashMap < String , List < String > > ( ) ; List < String > revs = new ArrayList < String > ( ) ; revs . add ( "*" ) ; docsToRevs . put ( documentId , revs ) ; database . purgeRevisions ( ... | Purges this document from the database ; this is more than deletion it forgets entirely about it . The purge will NOT be replicated to other databases . | 109 | 30 |
11,667 | @ InterfaceAudience . Public public SavedRevision getRevision ( String revID ) { if ( revID != null && currentRevision != null && revID . equals ( currentRevision . getId ( ) ) ) return currentRevision ; RevisionInternal revisionInternal = database . getDocument ( getId ( ) , revID , true ) ; return getRevisionFromRev ... | The revision with the specified ID . | 86 | 7 |
11,668 | @ InterfaceAudience . Public public long getLength ( ) { Number length = ( Number ) metadata . get ( "length" ) ; if ( length != null ) { return length . longValue ( ) ; } else { return 0 ; } } | Get the length in bytes of the contents . | 51 | 9 |
11,669 | @ InterfaceAudience . Private protected static Map < String , Object > installAttachmentBodies ( Map < String , Object > attachments , Database database ) throws CouchbaseLiteException { Map < String , Object > updatedAttachments = new HashMap < String , Object > ( ) ; for ( String name : attachments . keySet ( ) ) { O... | Goes through an _attachments dictionary and replaces any values that are Attachment objects with proper JSON metadata dicts . It registers the attachment bodies with the blob store and sets the metadata getDigest and follows properties accordingly . | 364 | 45 |
11,670 | private void initSupportExecutor ( ) { if ( supportExecutor == null || supportExecutor . isShutdown ( ) ) { supportExecutor = Executors . newSingleThreadExecutor ( new ThreadFactory ( ) { @ Override public Thread newThread ( Runnable r ) { String maskedRemote = URLUtils . sanitizeURL ( remote ) ; return new Thread ( r ... | create single thread supportExecutor for push replication | 104 | 9 |
11,671 | @ InterfaceAudience . Public public List < String > getAttachmentNames ( ) { Map < String , Object > attachmentMetadata = getAttachmentMetadata ( ) ; if ( attachmentMetadata == null ) { return new ArrayList < String > ( ) ; } return new ArrayList < String > ( attachmentMetadata . keySet ( ) ) ; } | The names of all attachments | 75 | 5 |
11,672 | @ InterfaceAudience . Public public List < Attachment > getAttachments ( ) { Map < String , Object > attachmentMetadata = getAttachmentMetadata ( ) ; if ( attachmentMetadata == null ) { return new ArrayList < Attachment > ( ) ; } List < Attachment > result = new ArrayList < Attachment > ( attachmentMetadata . size ( ) ... | All attachments as Attachment objects . | 146 | 7 |
11,673 | @ InterfaceAudience . Public public void setUserProperties ( Map < String , Object > userProperties ) { Map < String , Object > newProps = new HashMap < String , Object > ( ) ; newProps . putAll ( userProperties ) ; for ( String key : properties . keySet ( ) ) { if ( key . startsWith ( "_" ) ) { newProps . put ( key , ... | Sets the userProperties of the Revision . Set replaces all properties except for those with keys prefixed with _ . | 112 | 24 |
11,674 | @ InterfaceAudience . Private protected void addAttachment ( Attachment attachment , String name ) { Map < String , Object > attachments = ( Map < String , Object > ) properties . get ( "_attachments" ) ; if ( attachments == null ) { attachments = new HashMap < String , Object > ( ) ; } attachments . put ( name , attac... | Creates or updates an attachment . The attachment data will be written to the database when the revision is saved . | 105 | 22 |
11,675 | protected void beginReplicating ( ) { Log . v ( TAG , "submit startReplicating()" ) ; executor . submit ( new Runnable ( ) { @ Override public void run ( ) { if ( isRunning ( ) ) { Log . v ( TAG , "start startReplicating()" ) ; initPendingSequences ( ) ; initDownloadsToInsert ( ) ; startChangeTracker ( ) ; } // start r... | Actual work of starting the replication process . | 100 | 9 |
11,676 | @ Override @ InterfaceAudience . Private protected void processInbox ( RevisionList inbox ) { Log . d ( TAG , "processInbox called" ) ; if ( db == null || ! db . isOpen ( ) ) { Log . w ( Log . TAG_SYNC , "%s: Database is null or closed. Unable to continue. db name is %s." , this , db . getName ( ) ) ; return ; } if ( c... | Process a bunch of remote revisions from the _changes feed at once | 735 | 13 |
11,677 | protected void pullBulkRevisions ( List < RevisionInternal > bulkRevs ) { int nRevs = bulkRevs . size ( ) ; if ( nRevs == 0 ) { return ; } Log . d ( TAG , "%s bulk-fetching %d remote revisions..." , this , nRevs ) ; Log . d ( TAG , "%s bulk-fetching remote revisions: %s" , this , bulkRevs ) ; if ( ! canBulkGet ) { pull... | Get a bunch of revisions in one bulk request . Will use _bulk_get if possible . | 763 | 20 |
11,678 | private void queueDownloadedRevision ( RevisionInternal rev ) { if ( revisionBodyTransformationBlock != null ) { // Add 'file' properties to attachments pointing to their bodies: for ( Map . Entry < String , Map < String , Object > > entry : ( ( Map < String , Map < String , Object > > ) rev . getProperties ( ) . get (... | This invokes the tranformation block if one is installed and queues the resulting CBL_Revision | 546 | 21 |
11,679 | protected void pullBulkWithAllDocs ( final List < RevisionInternal > bulkRevs ) { // http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API ++ httpConnectionCount ; final RevisionList remainingRevs = new RevisionList ( bulkRevs ) ; Collection < String > keys = CollectionUtils . transform ( bulkRevs , new CollectionUtils... | This is compatible with CouchDB but it only works for revs of generation 1 without attachments . | 804 | 19 |
11,680 | @ InterfaceAudience . Private protected void queueRemoteRevision ( RevisionInternal rev ) { if ( rev . isDeleted ( ) ) { deletedRevsToPull . add ( rev ) ; } else { revsToPull . add ( rev ) ; } } | Add a revision to the appropriate queue of revs to individually GET | 55 | 13 |
11,681 | private static boolean isAllowed ( char c , String allow ) { return ( c >= ' ' && c <= ' ' ) || ( c >= ' ' && c <= ' ' ) || ( c >= ' ' && c <= ' ' ) || "_-!.~'()*" . indexOf ( c ) != NOT_FOUND || ( allow != null && allow . indexOf ( c ) != NOT_FOUND ) ; } | Returns true if the given character is allowed . | 91 | 9 |
11,682 | public boolean mutateAttachments ( CollectionUtils . Functor < Map < String , Object > , Map < String , Object > > functor ) { { Map < String , Object > properties = getProperties ( ) ; Map < String , Object > editedProperties = null ; Map < String , Object > attachments = ( Map < String , Object > ) properties . get (... | Returns YES if any changes were made . | 329 | 8 |
11,683 | public void appendData ( byte [ ] data ) throws IOException , SymmetricKeyException { if ( data == null ) return ; appendData ( data , 0 , data . length ) ; } | Appends data to the blob . Call this when new data is available . | 41 | 15 |
11,684 | public void finish ( ) throws IOException , SymmetricKeyException { if ( outStream != null ) { if ( encryptor != null ) outStream . write ( encryptor . encrypt ( null ) ) ; // FileOutputStream is also closed cascadingly outStream . close ( ) ; outStream = null ; // Only create the key if we got all the data successfull... | Call this after all the data has been added . | 114 | 10 |
11,685 | public void cancel ( ) { try { // FileOutputStream is also closed cascadingly if ( outStream != null ) { outStream . close ( ) ; outStream = null ; } // Clear encryptor: encryptor = null ; } catch ( IOException e ) { Log . w ( Log . TAG_BLOB_STORE , "Exception closing buffered output stream" , e ) ; } tempFile . delete... | Call this to cancel before finishing the data . | 92 | 9 |
11,686 | public boolean install ( ) { if ( tempFile == null ) return true ; // already installed // Move temp file to correct location in blob store: String destPath = store . getRawPathForKey ( blobKey ) ; File destPathFile = new File ( destPath ) ; if ( tempFile . renameTo ( destPathFile ) ) // If the move fails, assume it me... | Installs a finished blob into the store . | 120 | 9 |
11,687 | @ Override @ InterfaceAudience . Public public QueryRow next ( ) { if ( nextRow >= rows . size ( ) ) { return null ; } return rows . get ( nextRow ++ ) ; } | Gets the next QueryRow from the results or null if there are no more results . | 43 | 18 |
11,688 | Map < String , Object > getProperties ( ) { // This is basically the inverse of -[CBLManager parseReplicatorProperties:...] Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( "continuous" , isContinuous ( ) ) ; props . put ( "create_target" , shouldCreateTarget ( ) ) ; props . put ( "fi... | Currently only used for test | 291 | 5 |
11,689 | @ InterfaceAudience . Public public void start ( ) { if ( replicationInternal == null ) { initReplicationInternal ( ) ; } else { if ( replicationInternal . stateMachine . isInState ( ReplicationState . INITIAL ) ) { // great, it's ready to be started, nothing to do } else if ( replicationInternal . stateMachine . isInS... | Starts the replication asynchronously . | 226 | 8 |
11,690 | @ InterfaceAudience . Public public void setContinuous ( boolean isContinous ) { if ( isContinous ) { this . lifecycle = Lifecycle . CONTINUOUS ; replicationInternal . setLifecycle ( Lifecycle . CONTINUOUS ) ; } else { this . lifecycle = Lifecycle . ONESHOT ; replicationInternal . setLifecycle ( Lifecycle . ONESHOT ) ;... | Set whether this replication is continous | 86 | 7 |
11,691 | @ InterfaceAudience . Public public void setAuthenticator ( Authenticator authenticator ) { properties . put ( ReplicationField . AUTHENTICATOR , authenticator ) ; replicationInternal . setAuthenticator ( authenticator ) ; } | Set the Authenticator used for authenticating with the Sync Gateway | 47 | 12 |
11,692 | @ InterfaceAudience . Public public void setCreateTarget ( boolean createTarget ) { properties . put ( ReplicationField . CREATE_TARGET , createTarget ) ; replicationInternal . setCreateTarget ( createTarget ) ; } | Set whether the target database be created if it doesn t already exist? | 47 | 14 |
11,693 | @ Override public void changed ( ChangeEvent event ) { // forget cached IDs (Should be executed in workExecutor) final long lastSeqPushed = ( isPull ( ) || replicationInternal . lastSequence == null ) ? - 1L : Long . valueOf ( replicationInternal . lastSequence ) ; if ( lastSeqPushed >= 0 && lastSeqPushed != _lastSeque... | This is called back for changes from the ReplicationInternal . Simply propagate the events back to all listeners . | 205 | 21 |
11,694 | @ InterfaceAudience . Public public void setFilter ( String filterName ) { properties . put ( ReplicationField . FILTER_NAME , filterName ) ; replicationInternal . setFilter ( filterName ) ; } | Set the filter to be used by this replication | 44 | 9 |
11,695 | @ InterfaceAudience . Public public void setDocIds ( List < String > docIds ) { properties . put ( ReplicationField . DOC_IDS , docIds ) ; replicationInternal . setDocIds ( docIds ) ; } | Sets the documents to specify as part of the replication . | 53 | 12 |
11,696 | public void setFilterParams ( Map < String , Object > filterParams ) { properties . put ( ReplicationField . FILTER_PARAMS , filterParams ) ; replicationInternal . setFilterParams ( filterParams ) ; } | Set parameters to pass to the filter function . | 51 | 9 |
11,697 | @ InterfaceAudience . Public public void setChannels ( List < String > channels ) { properties . put ( ReplicationField . CHANNELS , channels ) ; replicationInternal . setChannels ( channels ) ; } | Set the list of Sync Gateway channel names | 45 | 8 |
11,698 | private void initWithKey ( byte [ ] key ) throws SymmetricKeyException { if ( key == null ) throw new SymmetricKeyException ( "Key cannot be null" ) ; if ( key . length != KEY_SIZE ) throw new SymmetricKeyException ( "Key size is not " + KEY_SIZE + "bytes" ) ; keyData = key ; } | Initialize the object with a raw key of 32 bytes size . | 80 | 13 |
11,699 | public byte [ ] encryptData ( byte [ ] data ) throws SymmetricKeyException { Encryptor encryptor = createEncryptor ( ) ; byte [ ] encrypted = encryptor . encrypt ( data ) ; byte [ ] trailer = encryptor . encrypt ( null ) ; if ( encrypted == null || trailer == null ) throw new SymmetricKeyException ( "Cannot encrypt dat... | Encrypt the byte array data | 105 | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.