idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
138,800
public static String getEntityEncoding ( HttpEntity entity ) { final Header header = entity . getContentEncoding ( ) ; if ( header == null ) return null ; return header . getValue ( ) ; }
Returns entity encoding .
45
4
138,801
public static String getCharset ( HttpEntity entity ) { final String guess = EntityUtils . getContentCharSet ( entity ) ; return guess == null ? HTTP . DEFAULT_CONTENT_CHARSET : guess ; }
Returns entity charset to use .
50
7
138,802
public Tuple < String , Boolean > decodeFormat ( int type , String format ) { boolean quotes = true ; switch ( placeOf ( type ) ) { // derived classes may wish to change the format here based on the place case PLACE : switch ( modeOf ( type ) ) { case EMOTE : quotes = false ; break ; } break ; } return Tuple . newTuple ( format , quotes ) ; }
Determines the format string and whether to use quotes based on the chat type .
87
17
138,803
public int decodeType ( String localtype ) { if ( ChatCodes . USER_CHAT_TYPE . equals ( localtype ) ) { return TELL ; } else if ( ChatCodes . PLACE_CHAT_TYPE . equals ( localtype ) ) { return PLACE ; } else { return 0 ; } }
Decodes the main chat type given the supplied localtype provided by the chat system .
68
17
138,804
public int adjustTypeByMode ( int mode , int type ) { switch ( mode ) { case ChatCodes . DEFAULT_MODE : return type | SPEAK ; case ChatCodes . EMOTE_MODE : return type | EMOTE ; case ChatCodes . THINK_MODE : return type | THINK ; case ChatCodes . SHOUT_MODE : return type | SHOUT ; case ChatCodes . BROADCAST_MODE : return BROADCAST ; // broadcast always looks like broadcast default : return type ; } }
Adjust the chat type based on the mode of the chat message .
113
13
138,805
public Color getOutlineColor ( int type ) { switch ( type ) { case BROADCAST : return BROADCAST_COLOR ; case TELL : return TELL_COLOR ; case TELLFEEDBACK : return TELLFEEDBACK_COLOR ; case INFO : return INFO_COLOR ; case FEEDBACK : return FEEDBACK_COLOR ; case ATTENTION : return ATTENTION_COLOR ; default : return Color . black ; } }
Computes the chat glyph outline color from the chat message type .
93
13
138,806
public SparseMisoSceneModel parseScene ( String path ) throws IOException , SAXException { _model = null ; _digester . push ( this ) ; FileInputStream stream = null ; try { stream = new FileInputStream ( path ) ; _digester . parse ( stream ) ; } finally { StreamUtil . close ( stream ) ; } return _model ; }
Parses the XML file at the specified path into a scene model instance .
81
16
138,807
public static PathMatcher valueOf ( String str ) throws ParseException { try { return valueOf ( new StringReader ( str ) ) ; } catch ( IOException ex ) { throw new IllegalStateException ( "StringReader IO error?" , ex ) ; } }
Read path matcher from string .
56
7
138,808
public static PathMatcher valueOf ( Reader reader ) throws IOException , ParseException { class DescriptiveErrorListener extends BaseErrorListener { public List < String > errors = new ArrayList <> ( ) ; @ Override public void syntaxError ( Recognizer < ? , ? > recognizer , Object offendingSymbol , int line , int charPositionInLine , String msg , org . antlr . v4 . runtime . RecognitionException e ) { LOG . log ( Level . INFO , "Parse error: {0}:{1} -> {2}" , new Object [ ] { line , charPositionInLine , msg } ) ; errors . add ( String . format ( "%d:%d: %s" , line , charPositionInLine , msg ) ) ; } } final DescriptiveErrorListener error_listener = new DescriptiveErrorListener ( ) ; final PathMatcherLexer lexer = new PathMatcherLexer ( CharStreams . fromReader ( reader ) ) ; lexer . removeErrorListeners ( ) ; lexer . addErrorListener ( error_listener ) ; final PathMatcherGrammar parser = new PathMatcherGrammar ( new BufferedTokenStream ( lexer ) ) ; parser . removeErrorListeners ( ) ; parser . addErrorListener ( error_listener ) ; final PathMatcherGrammar . ExprContext expr ; try { expr = parser . expr ( ) ; } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "parser yielded exceptional return" , ex ) ; if ( ! error_listener . errors . isEmpty ( ) ) throw new ParseException ( error_listener . errors , ex ) ; else throw ex ; } if ( ! error_listener . errors . isEmpty ( ) ) { if ( expr . exception != null ) throw new ParseException ( error_listener . errors , expr . exception ) ; throw new ParseException ( error_listener . errors ) ; } else if ( expr . exception != null ) { throw new ParseException ( expr . exception ) ; } return expr . s ; }
Read path matcher from reader .
457
7
138,809
public List < ChannelListener > getChannelListeners ( ) { if ( changes == null ) { return ( List < ChannelListener > ) Collections . EMPTY_LIST ; } List < EventListener > listeners = changes . getListenerList ( AMQP ) ; if ( ( listeners == null ) || listeners . isEmpty ( ) ) { return ( List < ChannelListener > ) Collections . EMPTY_LIST ; } ArrayList < ChannelListener > list = new ArrayList < ChannelListener > ( ) ; for ( EventListener listener : listeners ) { list . add ( ( ChannelListener ) listener ) ; } return list ; }
Returns the list of ChannelListeners registered with this AmqpChannel instance .
129
16
138,810
AmqpChannel openChannel ( ) { if ( readyState == ReadyState . OPEN ) { // If the channel is already open, just bail. return this ; } // try { Object [ ] args = { "" } ; WrappedByteBuffer bodyArg = null ; HashMap < String , Object > headersArg = null ; String methodName = "openChannel" ; String methodId = "20" + "10" ; AmqpMethod amqpMethod = MethodLookup . LookupMethod ( methodId ) ; Object [ ] arguments = { this , amqpMethod , this . id , args , bodyArg , headersArg } ; asyncClient . getStateMachine ( ) . enterState ( "channelReady" , "" , null ) ; asyncClient . enqueueAction ( methodName , "channelWrite" , arguments , null , null ) ; readyState = ReadyState . CONNECTING ; /*} catch (Exception ex) { if (errorHandler != null) { AmqpEvent e = new ChannelEvent(this, Kind.ERROR, ex.getMessage()); errorHandler.error(e); } } */ return this ; }
Creates a Channel to the AMQP server on the given clients connection
241
15
138,811
public AmqpChannel flowChannel ( boolean active ) { isFlowOn = active ; Object [ ] args = { active } ; WrappedByteBuffer bodyArg = null ; HashMap < String , Object > headersArg = null ; String methodId = "20" + "20" ; String methodName = "flowChannel" ; AmqpMethod amqpMethod = MethodLookup . LookupMethod ( methodId ) ; ; Object [ ] arguments = { this , amqpMethod , this . id , args , bodyArg , headersArg } ; if ( client . getReadyState ( ) == ReadyState . OPEN ) { asyncClient . enqueueAction ( methodName , "channelWrite" , arguments , null , null ) ; } return this ; }
This method asks the peer to pause or restart the flow of content data sent by a consumer . This is a simple flow - control mechanism that a peer can use to avoid overflowing its queues or otherwise finding itself receiving more messages than it can process .
160
49
138,812
public AmqpChannel closeChannel ( int replyCode , String replyText , int classId , int methodId1 ) { if ( readyState == ReadyState . CLOSED ) { return this ; } Object [ ] args = { replyCode , replyText , classId , methodId1 } ; WrappedByteBuffer bodyArg = null ; HashMap < String , Object > headersArg = null ; String methodName = "closeChannel" ; String methodId = "20" + "40" ; AmqpMethod amqpMethod = MethodLookup . LookupMethod ( methodId ) ; Object [ ] arguments = { this , amqpMethod , this . id , args , bodyArg , headersArg } ; asyncClient . enqueueAction ( methodName , "channelWrite" , arguments , null , null ) ; return this ; }
This method indicates that the sender wants to close the channel .
177
12
138,813
private AmqpChannel closeOkChannel ( ) { if ( readyState == ReadyState . CLOSED ) { // If the channel has been closed, just bail. return this ; } Object [ ] args = { } ; WrappedByteBuffer bodyArg = null ; HashMap < String , Object > headersArg = null ; String methodName = "closeOkChannel" ; String methodId = "20" + "41" ; AmqpMethod amqpMethod = MethodLookup . LookupMethod ( methodId ) ; ; Object [ ] arguments = { this , amqpMethod , this . id , args , bodyArg , headersArg } ; asyncClient . enqueueAction ( methodName , "channelWrite" , arguments , null , null ) ; return this ; }
Confirms to the peer that a flow command was received and processed .
163
14
138,814
public AmqpChannel deleteQueue ( String queue , boolean ifUnused , boolean ifEmpty , boolean noWait ) { Object [ ] args = { 0 , queue , ifUnused , ifEmpty , noWait } ; WrappedByteBuffer bodyArg = null ; HashMap < String , Object > headersArg = null ; String methodName = "deleteQueue" ; String methodId = "50" + "40" ; AmqpMethod amqpMethod = MethodLookup . LookupMethod ( methodId ) ; Object [ ] arguments = { this , amqpMethod , this . id , args , bodyArg , headersArg } ; boolean hasnowait = false ; for ( int i = 0 ; i < amqpMethod . allParameters . size ( ) ; i ++ ) { String argname = amqpMethod . allParameters . get ( i ) . name ; if ( argname == "noWait" ) { hasnowait = true ; break ; } } asyncClient . enqueueAction ( methodName , "channelWrite" , arguments , null , null ) ; if ( hasnowait && noWait ) { asyncClient . enqueueAction ( "nowait" , null , null , null , null ) ; } return this ; }
This method deletes a queue . When a queue is deleted any pending messages are sent to a dead - letter queue if this is defined in the server configuration and all consumers on the queue are canceled .
265
40
138,815
public AmqpChannel unbindQueue ( String queue , String exchange , String routingKey , AmqpArguments arguments ) { Object [ ] args = { 0 , queue , exchange , routingKey , arguments } ; WrappedByteBuffer bodyArg = null ; HashMap < String , Object > headersArg = null ; String methodName = "unbindQueue" ; String methodId = "50" + "50" ; AmqpMethod amqpMethod = MethodLookup . LookupMethod ( methodId ) ; Object [ ] methodArguments = { this , amqpMethod , this . id , args , bodyArg , headersArg } ; asyncClient . enqueueAction ( methodName , "channelWrite" , methodArguments , null , null ) ; return this ; }
This method unbinds a queue from an exchange .
165
11
138,816
public AmqpChannel qosBasic ( int prefetchSize , int prefetchCount , boolean global ) { Object [ ] args = { prefetchSize , prefetchCount , global } ; WrappedByteBuffer bodyArg = null ; HashMap < String , Object > headersArg = null ; String methodName = "qosBasic" ; String methodId = "60" + "10" ; AmqpMethod amqpMethod = MethodLookup . LookupMethod ( methodId ) ; Object [ ] arguments = { this , amqpMethod , this . id , args , bodyArg , headersArg } ; asyncClient . enqueueAction ( methodName , "channelWrite" , arguments , null , null ) ; return this ; }
This method requests a specific quality of service . The QoS can be specified for the current channel or for all channels on the connection . The particular properties and semantics of a qos method always depend on the content class semantics . Though the qos method could in principle apply to both peers it is currently meaningful only for the server .
156
66
138,817
public AmqpChannel publishBasic ( ByteBuffer body , AmqpProperties properties , String exchange , String routingKey , boolean mandatory , boolean immediate ) { @ SuppressWarnings ( "unchecked" ) Map < String , Object > amqpProps = ( Map < String , Object > ) Collections . EMPTY_MAP ; if ( properties != null ) { amqpProps = properties . getProperties ( ) ; } HashMap < String , Object > props = ( HashMap < String , Object > ) amqpProps ; return publishBasic ( body , props , exchange , routingKey , mandatory , immediate ) ; }
This method publishes a message to a specific exchange . The message will be routed to queues as defined by the exchange configuration and distributed to any active consumers when the transaction if any is committed .
137
37
138,818
public AmqpChannel getBasic ( String queue , boolean noAck ) { Object [ ] args = { 0 , queue , noAck } ; WrappedByteBuffer bodyArg = null ; HashMap < String , Object > headersArg = null ; String methodName = "getBasic" ; String methodId = "60" + "70" ; AmqpMethod amqpMethod = MethodLookup . LookupMethod ( methodId ) ; Object [ ] arguments = { this , amqpMethod , this . id , args , bodyArg , headersArg } ; asyncClient . enqueueAction ( methodName , "channelWrite" , arguments , null , null ) ; return this ; }
Gets messages from the queue and dispatches it to the listener
147
13
138,819
private void fireOnOpen ( ChannelEvent e ) { if ( readyState == ReadyState . OPEN ) { // If the channel has already been opened, then we should not fire // any events. return ; } readyState = ReadyState . OPEN ; List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onOpen ( e ) ; } }
Fired when channel is opened
104
6
138,820
private void fireOnDeclareExchange ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onDeclareExchange ( e ) ; } }
Fired when exchange is declared
70
6
138,821
private void fireOnDeclareQueue ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onDeclareQueue ( e ) ; } }
Fired when Queue is declared
68
7
138,822
private void fireOnBindQueue ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onBindQueue ( e ) ; } }
Fired when Queue is bound
66
7
138,823
private void fireOnConsumeBasic ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onConsumeBasic ( e ) ; } }
Fired on consume basic
68
5
138,824
private void fireOnCommitTransaction ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onCommit ( e ) ; } }
Fired on transaction commit
67
5
138,825
private void fireOnRollbackTransaction ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onRollback ( e ) ; } }
Fired on transaction rollbacked
67
6
138,826
private void fireOnSelectTransaction ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onSelect ( e ) ; } }
Fired on transaction select
65
5
138,827
private void fireOnMessage ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onMessage ( e ) ; } }
Fired on message retreival
64
7
138,828
private void fireOnUnbind ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onUnbind ( e ) ; } }
Fired on Unbind event
66
6
138,829
private void fireOnDeleteQueue ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onDeleteQueue ( e ) ; } }
Fired when queue is deleted
66
6
138,830
private void fireOnDeleteExchange ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onDeleteExchange ( e ) ; } }
Fired when exchange is deleted
68
6
138,831
private void fireOnCancelBasic ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onCancelBasic ( e ) ; } }
Fired on cancel basic
68
5
138,832
private void fireOnGetBasic ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onGetBasic ( e ) ; } }
Fired on get basic
66
5
138,833
private void fireOnPurgeQueue ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onPurgeQueue ( e ) ; } }
Fired on purge queue
68
5
138,834
private void fireOnRecoverBasic ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onRecoverBasic ( e ) ; } }
Fired on recover basic
68
5
138,835
private void fireOnRejectBasic ( ChannelEvent e ) { List < EventListener > listeners = changes . getListenerList ( AMQP ) ; for ( EventListener listener : listeners ) { ChannelListener amqpListener = ( ChannelListener ) listener ; amqpListener . onRejectBasic ( e ) ; } }
Fired on reject basic
68
5
138,836
@ Override public void processConnect ( WebSocketChannel channel , WSURI location , String [ ] protocols ) { LOG . entering ( CLASS_NAME , "connect" , channel ) ; WebSocketCompositeChannel compositeChannel = ( WebSocketCompositeChannel ) channel ; if ( compositeChannel . readyState != ReadyState . CLOSED ) { LOG . warning ( "Attempt to reconnect an existing open WebSocket to a different location" ) ; throw new IllegalStateException ( "Attempt to reconnect an existing open WebSocket to a different location" ) ; } compositeChannel . readyState = ReadyState . CONNECTING ; compositeChannel . requestedProtocols = protocols ; String scheme = compositeChannel . getCompositeScheme ( ) ; if ( scheme . indexOf ( ":" ) >= 0 ) { // qualified scheme: e.g. "java:wse" WebSocketStrategy strategy = strategyMap . get ( scheme ) ; if ( strategy == null ) { throw new IllegalArgumentException ( "Invalid connection scheme: " + scheme ) ; } LOG . finest ( "Turning off fallback since the URL is prefixed with java:" ) ; compositeChannel . connectionStrategies . add ( scheme ) ; } else { String [ ] connectionStrategies = strategyChoices . get ( scheme ) ; if ( connectionStrategies != null ) { for ( String each : connectionStrategies ) { compositeChannel . connectionStrategies . add ( each ) ; } } else { throw new IllegalArgumentException ( "Invalid connection scheme: " + scheme ) ; } } fallbackNext ( compositeChannel , null ) ; }
Connect the WebSocket object to the remote location
342
9
138,837
@ Override public void processTextMessage ( WebSocketChannel channel , String message ) { LOG . entering ( CLASS_NAME , "send" , message ) ; WebSocketCompositeChannel parent = ( WebSocketCompositeChannel ) channel ; if ( parent . readyState != ReadyState . OPEN ) { LOG . warning ( "Attempt to post message on unopened or closed web socket" ) ; throw new IllegalStateException ( "Attempt to post message on unopened or closed web socket" ) ; } WebSocketSelectedChannel selectedChannel = parent . selectedChannel ; selectedChannel . handler . processTextMessage ( selectedChannel , message ) ; }
Writes the message to the WebSocket .
134
9
138,838
public void removeChatGrabber ( JTextComponent comp ) { // remove the component from the list of grabbers comp . removeAncestorListener ( this ) ; _chatGrabbers . remove ( comp ) ; // update the current chat grabbing component _curChatGrabber = _chatGrabbers . isEmpty ( ) ? null : _chatGrabbers . getLast ( ) ; }
Removes the specified component from the list of chat grabbers so that it will no longer be notified of chat - like key events .
80
27
138,839
protected boolean isTypeableTarget ( Component target ) { return target . isShowing ( ) && ( ( ( target instanceof JTextComponent ) && ( ( JTextComponent ) target ) . isEditable ( ) ) || ( target instanceof JComboBox ) || ( target instanceof JTable ) || ( target instanceof JRootPane ) ) ; }
Returns true if the specified target component supports being typed into and thus we shouldn t steal focus away from it if the user starts typing .
77
27
138,840
public void windowLostFocus ( WindowEvent e ) { // un-press any keys that were left down if ( ! _downKeys . isEmpty ( ) ) { long now = System . currentTimeMillis ( ) ; for ( KeyEvent down : _downKeys . values ( ) ) { KeyEvent up = new KeyEvent ( down . getComponent ( ) , KeyEvent . KEY_RELEASED , now , down . getModifiers ( ) , down . getKeyCode ( ) , down . getKeyChar ( ) , down . getKeyLocation ( ) ) ; for ( int ii = 0 , nn = _listeners . size ( ) ; ii < nn ; ii ++ ) { _listeners . get ( ii ) . keyReleased ( up ) ; } } _downKeys . clear ( ) ; } }
documentation inherited from interface WindowFocusListener
174
8
138,841
public static < T > CloseableIterable < T > distinct ( final CloseableIterable < T > iterable ) { return wrap ( Iterables2 . distinct ( iterable ) , iterable ) ; }
If we can assume the closeable iterable is sorted return the distinct elements . This only works if the data provided is sorted .
44
26
138,842
public void delete ( ) { IntBuffer idbuf = BufferUtils . createIntBuffer ( 1 ) ; idbuf . put ( _id ) . rewind ( ) ; AL10 . alDeleteBuffers ( idbuf ) ; _id = 0 ; }
Deletes this buffer rendering it unusable .
54
9
138,843
public void visitObjects ( ObjectVisitor visitor , boolean interestingOnly ) { for ( Iterator < Section > iter = getSections ( ) ; iter . hasNext ( ) ; ) { Section sect = iter . next ( ) ; for ( ObjectInfo oinfo : sect . objectInfo ) { visitor . visit ( oinfo ) ; } if ( ! interestingOnly ) { for ( int oo = 0 ; oo < sect . objectTileIds . length ; oo ++ ) { ObjectInfo info = new ObjectInfo ( ) ; info . tileId = sect . objectTileIds [ oo ] ; info . x = sect . objectXs [ oo ] ; info . y = sect . objectYs [ oo ] ; visitor . visit ( info ) ; } } } }
Informs the supplied visitor of each object in this scene .
169
12
138,844
public void setSection ( Section section ) { _sections . put ( key ( section . x , section . y ) , section ) ; }
Don t call this method! This is only public so that the scene parser can construct a scene from raw data . If only Java supported class friendship .
29
30
138,845
protected final int key ( int x , int y ) { int sx = MathUtil . floorDiv ( x , swidth ) ; int sy = MathUtil . floorDiv ( y , sheight ) ; return ( sx << 16 ) | ( sy & 0xFFFF ) ; }
Returns the key for the specified section .
62
8
138,846
protected final Section getSection ( int x , int y , boolean create ) { int key = key ( x , y ) ; Section sect = _sections . get ( key ) ; if ( sect == null && create ) { short sx = ( short ) ( MathUtil . floorDiv ( x , swidth ) * swidth ) ; short sy = ( short ) ( MathUtil . floorDiv ( y , sheight ) * sheight ) ; _sections . put ( key , sect = new Section ( sx , sy , swidth , sheight ) ) ; // Log.info("Created new section " + sect + "."); } return sect ; }
Returns the section for the specified tile coordinate .
140
9
138,847
public void forEach ( final Function < T , Void > function ) { for ( final ListenerEntry < T > entry : listeners . values ( ) ) { entry . executor . execute ( new Runnable ( ) { @ Override public void run ( ) { try { function . apply ( entry . listener ) ; } catch ( Throwable e ) { log . error ( String . format ( "Listener (%s) threw an exception" , entry . listener ) , e ) ; } } } ) ; } }
Utility - apply the given function to each listener . The function receives the listener as an argument .
108
20
138,848
public String summarizeState ( ) { StringBuilder buf = new StringBuilder ( ) ; buf . append ( "clipVol=" ) . append ( _clipVol ) ; buf . append ( ", disabled=[" ) ; int ii = 0 ; for ( SoundType soundType : _disabledTypes ) { if ( ii ++ > 0 ) { buf . append ( ", " ) ; } buf . append ( soundType ) ; } return buf . append ( "]" ) . toString ( ) ; }
Returns a string summarizing our volume settings and disabled sound types .
102
13
138,849
public boolean shouldPlay ( SoundType type ) { if ( type == null ) { type = DEFAULT ; // let the lazy kids play too } return _clipVol != 0f && isEnabled ( type ) ; }
Is sound on and is the specified soundtype enabled?
44
11
138,850
public void setEnabled ( final SoundType type , final boolean enabled ) { boolean changed ; if ( enabled ) { changed = _disabledTypes . remove ( type ) ; } else { changed = _disabledTypes . add ( type ) ; } if ( changed ) { _enabledObservers . apply ( new ObserverOp < SoundEnabledObserver > ( ) { public boolean apply ( SoundEnabledObserver observer ) { observer . enabledChanged ( type , enabled ) ; return true ; } } ) ; } }
Turns on or off the specified sound type .
104
10
138,851
public boolean play ( SoundType type , String pkgPath , String key , float pan ) { return play ( type , pkgPath , key , 0 , pan ) ; }
Play the specified sound as the specified type of sound immediately with the specified pan value . Note that a sound need not be locked prior to playing .
37
29
138,852
private void addMetaPageInternal ( final MetaHelpPage page ) { log . debug ( "Adding meta-page: {}" , page ) ; metaPages . put ( page . getName ( ) , page ) ; events . publish ( new MetaHelpPageAddedEvent ( page ) ) ; }
Exposed for discovery ; which is before lifecycle has been started .
61
14
138,853
public static void main ( String [ ] args ) { boolean enabled = ( args . length > 0 && args [ 0 ] . equals ( "on" ) ) ; Keyboard . setKeyRepeat ( enabled ) ; }
Tests keyboard functionality .
44
5
138,854
public static Point getSize ( float scale , Mirage image ) { int width = Math . max ( 0 , Math . round ( image . getWidth ( ) * scale ) ) ; int height = Math . max ( 0 , Math . round ( image . getHeight ( ) * scale ) ) ; return new Point ( width , height ) ; }
Computes the width and height to which an image should be scaled .
71
14
138,855
public static Point getCorner ( Point center , Point size ) { return new Point ( center . x - size . x / 2 , center . y - size . y / 2 ) ; }
Computes the upper left corner where the image should be drawn given the center and dimensions to which the image should be scaled .
40
25
138,856
private static DecoratorMap group_map_ ( Map < String , PathMatcher > paths ) { if ( paths . isEmpty ( ) ) return concat ( ) ; return new DecoratorMap ( ) { @ Override public Stream < Consumer < MutableContext > > map ( Stream < Consumer < MutableContext > > in , Context ctx ) { final Map < String , TimeSeriesValueSet > pathMapping = paths . entrySet ( ) . stream ( ) . collect ( Collectors . toMap ( Map . Entry :: getKey , pmEntry -> { return ctx . getTSData ( ) . getCurrentCollection ( ) . get ( p -> pmEntry . getValue ( ) . match ( p . getPath ( ) ) , x -> true ) ; } ) ) ; for ( final Map . Entry < String , TimeSeriesValueSet > pm : pathMapping . entrySet ( ) ) { final String identifier = pm . getKey ( ) ; final List < Consumer < MutableContext > > applications = pm . getValue ( ) . stream ( ) . map ( group -> { Consumer < MutableContext > application = ( nestedCtx ) - > nestedCtx . putGroupAliasByName ( identifier , group :: getGroup ) ; return application ; } ) . collect ( Collectors . toList ( ) ) ; in = in . flatMap ( inApplication -> applications . stream ( ) . map ( inApplication :: andThen ) ) ; } return in ; } } ; }
Create a decorator map from a mapping of GroupMatchers .
317
13
138,857
private static DecoratorMap metric_map_ ( Map < IdentifierPair , MetricMatcher > matchers ) { if ( matchers . isEmpty ( ) ) return concat ( ) ; return new DecoratorMap ( ) { @ Override public Stream < Consumer < MutableContext > > map ( Stream < Consumer < MutableContext > > in , Context ctx ) { final Map < IdentifierPair , List < Map . Entry < MetricMatcher . MatchedName , MetricValue > > > metricMapping = matchers . entrySet ( ) . stream ( ) . collect ( Collectors . toMap ( Map . Entry :: getKey , mmEntry -> mmEntry . getValue ( ) . filter ( ctx ) . collect ( Collectors . toList ( ) ) ) ) ; for ( final Map . Entry < IdentifierPair , List < Map . Entry < MetricMatcher . MatchedName , MetricValue > > > mm : metricMapping . entrySet ( ) ) { final String groupIdentifier = mm . getKey ( ) . getGroup ( ) ; final String metricIdentifier = mm . getKey ( ) . getMetric ( ) ; final List < Consumer < MutableContext > > applications = mm . getValue ( ) . stream ( ) . map ( matchedMetric -> { Consumer < MutableContext > application = ( nestedCtx ) - > { nestedCtx . putGroupAliasByName ( groupIdentifier , matchedMetric . getKey ( ) . getMatchedGroup ( ) :: getGroup ) ; nestedCtx . putMetricAliasByName ( metricIdentifier , matchedMetric . getKey ( ) . getMatchedGroup ( ) :: getGroup , matchedMetric . getKey ( ) :: getMetric ) ; } ; return application ; } ) . collect ( Collectors . toList ( ) ) ; in = in . flatMap ( inApplication -> applications . stream ( ) . map ( inApplication :: andThen ) ) ; } return in ; } } ; }
Create a decorator map from a mapping of metric matchers .
436
13
138,858
private static DecoratorMap concat ( DecoratorMap ... d_maps ) { return ( Stream < Consumer < MutableContext > > in , Context ctx ) -> { for ( DecoratorMap d_map : d_maps ) { in = d_map . map ( in , ctx ) ; } return in ; } ; }
Create a decorator map by chaining zero or more decorator maps .
74
15
138,859
public void add ( Metric m ) { final MetricName key = m . getName ( ) ; metrics_ . put ( key , m ) ; }
Add a new metric to the metric group .
33
9
138,860
@ SuppressWarnings ( "SynchronizationOnLocalVariableOrMethodParameter" ) private void waitForJobCompletion ( final CommandSessionImpl session ) throws InterruptedException { while ( true ) { Job job = session . foregroundJob ( ) ; if ( job == null ) break ; log . debug ( "Waiting for job completion: {}" , job ) ; synchronized ( job ) { if ( job . status ( ) == Job . Status . Foreground ) { job . wait ( ) ; } } } }
Wait for current job if any to complete .
109
9
138,861
protected Object getInstantiatedClass ( String query ) { if ( query . equals ( Constants . ROBOTIUM_SOLO ) ) { return solo ; } else if ( query . equals ( Constants . REMOTE_TEST_CLASS ) ) { return testClass ; } return null ; }
Get the instantiated solo if it is requested
63
9
138,862
protected View getView ( String viewName ) { for ( View view : solo . getCurrentViews ( ) ) { if ( view . toString ( ) . contains ( viewName ) ) { return view ; } } return null ; }
Return a view with the specified name or null
50
9
138,863
public < T > T access ( Class < T > clazz ) { if ( configuration . getClass ( ) . equals ( clazz ) ) { return clazz . cast ( configuration ) ; } try { return clazz . cast ( fieldCache . get ( clazz ) . get ( configuration ) ) ; } catch ( Exception e ) { log . error ( "Could not access field for " + clazz , e ) ; throw new RuntimeException ( e ) ; } }
Access a custom configuration of the given type . The fields of the configuration object are searched for one that is of the given type .
99
26
138,864
public < T > boolean has ( Class < T > clazz ) { return configuration . getClass ( ) . equals ( clazz ) || ( fieldCache . getIfPresent ( clazz ) != null ) ; }
Return true if there is a custom configuration of the given type .
45
13
138,865
public static StreamDecoder createInstance ( URL url ) throws IOException { String path = url . getPath ( ) ; int idx = path . lastIndexOf ( ' ' ) ; if ( idx == - 1 ) { log . warning ( "Missing extension for URL." , "url" , url ) ; return null ; } String extension = path . substring ( idx + 1 ) ; Class < ? extends StreamDecoder > clazz = _extensions . get ( extension ) ; if ( clazz == null ) { log . warning ( "No decoder registered for extension." , "extension" , extension , "url" , url ) ; return null ; } StreamDecoder decoder ; try { decoder = clazz . newInstance ( ) ; } catch ( Exception e ) { log . warning ( "Error instantiating decoder." , "url" , url , e ) ; return null ; } decoder . init ( url . openStream ( ) ) ; return decoder ; }
Creates and initializes a stream decoder for the specified URL .
212
14
138,866
public void setTarget ( JComponent target , KeyTranslator xlate ) { setEnabled ( false ) ; // save off references _target = target ; _xlate = xlate ; }
Initializes the keyboard manager with the supplied target component and key translator and disables the keyboard manager if it is currently active .
39
25
138,867
public void setEnabled ( boolean enabled ) { // report incorrect usage if ( enabled && _target == null ) { log . warning ( "Attempt to enable uninitialized keyboard manager!" , new Exception ( ) ) ; return ; } // ignore NOOPs if ( enabled == _enabled ) { return ; } if ( ! enabled ) { if ( Keyboard . isAvailable ( ) ) { // restore the original key auto-repeat settings Keyboard . setKeyRepeat ( _nativeRepeat ) ; } // clear out all of our key states releaseAllKeys ( ) ; _keys . clear ( ) ; // cease listening to all of our business if ( _window != null ) { _window . removeWindowFocusListener ( this ) ; _window = null ; } _target . removeAncestorListener ( this ) ; // note that we no longer have the focus _focus = false ; } else { // listen to ancestor events so that we can cease our business // if we lose the focus _target . addAncestorListener ( this ) ; // if we're already showing, listen to window focus events, // else we have to wait until the target is added since it // doesn't currently have a window if ( _target . isShowing ( ) && _window == null ) { _window = SwingUtilities . getWindowAncestor ( _target ) ; if ( _window != null ) { _window . addWindowFocusListener ( this ) ; } } // assume the keyboard focus since we were just enabled _focus = true ; if ( Keyboard . isAvailable ( ) ) { // note whether key auto-repeating was enabled _nativeRepeat = Keyboard . isKeyRepeatEnabled ( ) ; // Disable native key auto-repeating so that we can definitively ascertain key // pressed/released events. // Or not, if we've discovered we don't want to. Keyboard . setKeyRepeat ( ! _shouldDisableNativeRepeat ) ; } } // save off our new enabled state _enabled = enabled ; }
Sets whether the keyboard manager processes keyboard input .
412
10
138,868
public void releaseAllKeys ( ) { long now = System . currentTimeMillis ( ) ; Iterator < KeyInfo > iter = _keys . elements ( ) ; while ( iter . hasNext ( ) ) { iter . next ( ) . release ( now ) ; } }
Releases all keys and ceases any hot repeating action that may be going on .
58
16
138,869
protected boolean keyPressed ( KeyEvent e ) { logKey ( "keyPressed" , e ) ; // get the action command associated with this key int keyCode = e . getKeyCode ( ) ; boolean hasCommand = _xlate . hasCommand ( keyCode ) ; if ( hasCommand ) { // get the info object for this key, creating one if necessary KeyInfo info = _keys . get ( keyCode ) ; if ( info == null ) { info = new KeyInfo ( keyCode ) ; _keys . put ( keyCode , info ) ; } // remember the last time this key was pressed info . setPressTime ( RunAnywhere . getWhen ( e ) ) ; } // notify any key observers of the key press notifyObservers ( KeyEvent . KEY_PRESSED , e . getKeyCode ( ) , RunAnywhere . getWhen ( e ) ) ; return hasCommand ; }
Called when Swing notifies us that a key has been pressed while the keyboard manager is active .
193
20
138,870
protected boolean keyTyped ( KeyEvent e ) { logKey ( "keyTyped" , e ) ; // get the action command associated with this key char keyChar = e . getKeyChar ( ) ; boolean hasCommand = _xlate . hasCommand ( keyChar ) ; if ( hasCommand ) { // Okay, we're clearly doing actions based on key typing, so we're going to need native // keyboard repeating turned on. Oh well. if ( _shouldDisableNativeRepeat ) { _shouldDisableNativeRepeat = false ; if ( Keyboard . isAvailable ( ) ) { Keyboard . setKeyRepeat ( ! _shouldDisableNativeRepeat ) ; } } KeyInfo info = _chars . get ( keyChar ) ; if ( info == null ) { info = new KeyInfo ( keyChar ) ; _chars . put ( keyChar , info ) ; } // remember the last time this key was pressed info . setPressTime ( RunAnywhere . getWhen ( e ) ) ; } // notify any key observers of the key press notifyObservers ( KeyEvent . KEY_TYPED , e . getKeyChar ( ) , RunAnywhere . getWhen ( e ) ) ; return hasCommand ; }
Called when Swing notifies us that a key has been typed while the keyboard manager is active .
255
20
138,871
protected boolean keyReleased ( KeyEvent e ) { logKey ( "keyReleased" , e ) ; // get the info object for this key KeyInfo info = _keys . get ( e . getKeyCode ( ) ) ; if ( info != null ) { // remember the last time we received a key release info . setReleaseTime ( RunAnywhere . getWhen ( e ) ) ; } // notify any key observers of the key release notifyObservers ( KeyEvent . KEY_RELEASED , e . getKeyCode ( ) , RunAnywhere . getWhen ( e ) ) ; return ( info != null ) ; }
Called when Swing notifies us that a key has been released while the keyboard manager is active .
132
20
138,872
protected void logKey ( String msg , KeyEvent e ) { if ( DEBUG_EVENTS || _debugTyping . getValue ( ) ) { int keyCode = e . getKeyCode ( ) ; log . info ( msg , "key" , KeyEvent . getKeyText ( keyCode ) ) ; } }
Logs the given message and key .
67
8
138,873
public void paint ( Graphics g , int x , int y , int width , int height ) { // bail out now if we were passed a bogus source image at construct time if ( _tiles == null ) { return ; } int rwid = width - 2 * _w3 , rhei = height - 2 * _h3 ; g . drawImage ( _tiles [ 0 ] , x , y , _w3 , _h3 , null ) ; g . drawImage ( _tiles [ 1 ] , x + _w3 , y , rwid , _h3 , null ) ; g . drawImage ( _tiles [ 2 ] , x + _w3 + rwid , y , _w3 , _h3 , null ) ; y += _h3 ; g . drawImage ( _tiles [ 3 ] , x , y , _w3 , rhei , null ) ; g . drawImage ( _tiles [ 4 ] , x + _w3 , y , rwid , rhei , null ) ; g . drawImage ( _tiles [ 5 ] , x + _w3 + rwid , y , _w3 , rhei , null ) ; y += rhei ; g . drawImage ( _tiles [ 6 ] , x , y , _w3 , _h3 , null ) ; g . drawImage ( _tiles [ 7 ] , x + _w3 , y , rwid , _h3 , null ) ; g . drawImage ( _tiles [ 8 ] , x + _w3 + rwid , y , _w3 , _h3 , null ) ; }
Fills the requested region with the background defined by our source image .
352
14
138,874
public Icon getIcon ( String iconSet , int index ) { try { // see if the tileset is already loaded TileSet set = _icons . get ( iconSet ) ; // load it up if not if ( set == null ) { String path = _config . getProperty ( iconSet + PATH_SUFFIX ) ; if ( StringUtil . isBlank ( path ) ) { throw new Exception ( "No path specified for icon set" ) ; } String metstr = _config . getProperty ( iconSet + METRICS_SUFFIX ) ; if ( StringUtil . isBlank ( metstr ) ) { throw new Exception ( "No metrics specified for icon set" ) ; } int [ ] metrics = StringUtil . parseIntArray ( metstr ) ; if ( metrics == null || metrics . length != 2 ) { throw new Exception ( "Invalid icon set metrics " + "[metrics=" + metstr + "]" ) ; } // load up the tileset if ( _rsrcSet == null ) { set = _tilemgr . loadTileSet ( path , metrics [ 0 ] , metrics [ 1 ] ) ; } else { set = _tilemgr . loadTileSet ( _rsrcSet , path , metrics [ 0 ] , metrics [ 1 ] ) ; } // cache it _icons . put ( iconSet , set ) ; } // fetch the appropriate image and create an image icon return new TileIcon ( set . getTile ( index ) ) ; } catch ( Exception e ) { log . warning ( "Unable to load icon [iconSet=" + iconSet + ", index=" + index + ", error=" + e + "]." ) ; } // return an error icon return new ImageIcon ( ImageUtil . createErrorImage ( 32 , 32 ) ) ; }
Fetches the icon with the specified index from the named icon set .
383
15
138,875
public ByteOrder order ( ByteOrder o ) { // TODO: In the next release, return WrappedByteBuffer - use return _buf.order(o) _isBigEndian = "BIG_ENDIAN" . equals ( o . toString ( ) ) ; _buf . order ( o ) ; return o ; }
Set the byte order for this buffer
70
7
138,876
public WrappedByteBuffer compact ( ) { int remaining = remaining ( ) ; int capacity = capacity ( ) ; if ( capacity == 0 ) { return this ; } if ( remaining <= capacity >>> 2 && capacity > _minimumCapacity ) { int newCapacity = capacity ; int minCapacity = max ( _minimumCapacity , remaining << 1 ) ; for ( ; ; ) { if ( newCapacity >>> 1 < minCapacity ) { break ; } newCapacity >>>= 1 ; } newCapacity = max ( minCapacity , newCapacity ) ; if ( newCapacity == capacity ) { if ( _buf . remaining ( ) == 0 ) { _buf . position ( 0 ) ; _buf . limit ( _buf . capacity ( ) ) ; } else { java . nio . ByteBuffer dup = _buf . duplicate ( ) ; _buf . position ( 0 ) ; _buf . limit ( _buf . capacity ( ) ) ; _buf . put ( dup ) ; } return this ; } // Shrink and compact: // // Save the state. ByteOrder bo = order ( ) ; // // Sanity check. if ( remaining > newCapacity ) { throw new IllegalStateException ( "The amount of the remaining bytes is greater than " + "the new capacity." ) ; } // // Reallocate. java . nio . ByteBuffer oldBuf = _buf ; java . nio . ByteBuffer newBuf = java . nio . ByteBuffer . allocate ( newCapacity ) ; newBuf . put ( oldBuf ) ; _buf = newBuf ; // // Restore the state. _buf . order ( bo ) ; } else { _buf . compact ( ) ; } return this ; }
Compacts the buffer by removing leading bytes up to the buffer position and decrements the limit and position values accordingly .
369
23
138,877
public WrappedByteBuffer fillWith ( byte b , int size ) { _autoExpand ( size ) ; while ( size -- > 0 ) { _buf . put ( b ) ; } return this ; }
Fills the buffer with a specific number of repeated bytes .
44
12
138,878
public int indexOf ( byte b ) { if ( _buf . hasArray ( ) ) { byte [ ] array = _buf . array ( ) ; int arrayOffset = _buf . arrayOffset ( ) ; int startAt = arrayOffset + position ( ) ; int endAt = arrayOffset + limit ( ) ; for ( int i = startAt ; i < endAt ; i ++ ) { if ( array [ i ] == b ) { return i - arrayOffset ; } } return - 1 ; } else { int startAt = _buf . position ( ) ; int endAt = _buf . limit ( ) ; for ( int i = startAt ; i < endAt ; i ++ ) { if ( _buf . get ( i ) == b ) { return i ; } } return - 1 ; } }
Returns the index of the specified byte in the buffer .
171
11
138,879
public WrappedByteBuffer put ( byte [ ] v , int offset , int length ) { _autoExpand ( length ) ; for ( int i = 0 ; i < length ; i ++ ) { _buf . put ( v [ offset + i ] ) ; } return this ; }
Puts segment of a single - byte array into the buffer at the current position .
60
17
138,880
public WrappedByteBuffer putAt ( int index , byte v ) { _checkForWriteAt ( index , 1 ) ; _buf . put ( index , v ) ; return this ; }
Puts a single byte number into the buffer at the specified index .
40
14
138,881
public WrappedByteBuffer putUnsignedAt ( int index , int v ) { _checkForWriteAt ( index , 1 ) ; byte b = ( byte ) ( v & 0xFF ) ; return this . putAt ( index , b ) ; }
Puts an unsigned single byte into the buffer at the specified position .
54
14
138,882
public WrappedByteBuffer putShortAt ( int index , short v ) { _checkForWriteAt ( index , 2 ) ; _buf . putShort ( index , v ) ; return this ; }
Puts a two - byte short into the buffer at the specified index .
42
15
138,883
public WrappedByteBuffer putIntAt ( int index , int v ) { _checkForWriteAt ( index , 4 ) ; _buf . putInt ( index , v ) ; return this ; }
Puts a four - byte int into the buffer at the specified index .
42
15
138,884
public WrappedByteBuffer putLongAt ( int index , long v ) { _checkForWriteAt ( index , 8 ) ; _buf . putLong ( index , v ) ; return this ; }
Puts an eight - byte long into the buffer at the specified index .
42
15
138,885
public WrappedByteBuffer putString ( String v , Charset cs ) { java . nio . ByteBuffer strBuf = cs . encode ( v ) ; _autoExpand ( strBuf . limit ( ) ) ; _buf . put ( strBuf ) ; return this ; }
Puts a string into the buffer at the current position using the character set to encode the string as bytes .
63
22
138,886
public WrappedByteBuffer putPrefixedString ( int fieldSize , String v , Charset cs ) { if ( fieldSize == 0 ) { return this ; } boolean utf16 = cs . name ( ) . startsWith ( "UTF-16" ) ; if ( utf16 && ( fieldSize == 1 ) ) { throw new IllegalArgumentException ( "fieldSize is not even for UTF-16 character set" ) ; } java . nio . ByteBuffer strBuf = cs . encode ( v ) ; _autoExpand ( fieldSize + strBuf . limit ( ) ) ; int len = strBuf . remaining ( ) ; switch ( fieldSize ) { case 1 : put ( ( byte ) len ) ; break ; case 2 : putShort ( ( short ) len ) ; break ; case 4 : putInt ( len ) ; break ; default : throw new IllegalArgumentException ( "Illegal argument, field size should be 1,2 or 4 and fieldSize is: " + fieldSize ) ; } _buf . put ( strBuf ) ; return this ; }
Puts a string into the buffer at the specified index using the character set to encode the string as bytes .
232
22
138,887
public WrappedByteBuffer putBytesAt ( int index , byte [ ] b ) { _checkForWriteAt ( index , b . length ) ; int pos = _buf . position ( ) ; _buf . position ( index ) ; _buf . put ( b , 0 , b . length ) ; _buf . position ( pos ) ; return this ; }
Puts a single - byte array into the buffer at the specified index .
75
15
138,888
public WrappedByteBuffer putBuffer ( WrappedByteBuffer v ) { _autoExpand ( v . remaining ( ) ) ; _buf . put ( v . _buf ) ; return this ; }
Puts a buffer into the buffer at the current position .
42
12
138,889
public WrappedByteBuffer putBufferAt ( int index , WrappedByteBuffer v ) { // TODO: I believe this method incorrectly moves the position! // Can't change it without a code analysis - and this is a public API! int pos = _buf . position ( ) ; _buf . position ( index ) ; _buf . put ( v . _buf ) ; _buf . position ( pos ) ; return this ; }
Puts a buffer into the buffer at the specified index .
90
12
138,890
public byte [ ] getBytes ( int size ) { _checkForRead ( size ) ; byte [ ] dst = new byte [ size ] ; _buf . get ( dst , 0 , size ) ; return dst ; }
Returns a byte array of length size from the buffer from current position
46
13
138,891
public byte [ ] getBytesAt ( int index , int size ) { _checkForReadAt ( index , size ) ; byte [ ] dst = new byte [ size ] ; int i = 0 ; int j = index ; while ( i < size ) { dst [ i ++ ] = _buf . get ( j ++ ) ; } return dst ; }
Returns a byte array of length size from the buffer starting from the specified position .
74
16
138,892
public int getUnsignedMediumInt ( ) { int b1 = getUnsigned ( ) ; int b2 = getUnsigned ( ) ; int b3 = getUnsigned ( ) ; if ( _isBigEndian ) { return ( b1 << 16 ) | ( b2 << 8 ) | b3 ; } else { return ( b3 << 16 ) | ( b2 << 8 ) | b1 ; } }
Returns an unsigned three - byte medium int from the buffer at the current position
90
15
138,893
public long getUnsignedIntAt ( int index ) { _checkForReadAt ( index , 4 ) ; long val = ( long ) ( _buf . getInt ( index ) & 0xffffffff L ) ; return val ; }
Returns an unsigned four - byte int from the buffer at the specified index
50
14
138,894
public String getPrefixedString ( int fieldSize , Charset cs ) { int len = 0 ; switch ( fieldSize ) { case 1 : len = _buf . get ( ) ; break ; case 2 : len = _buf . getShort ( ) ; break ; case 4 : len = _buf . getInt ( ) ; break ; default : throw new IllegalArgumentException ( "Illegal argument, field size should be 1,2 or 4 and fieldSize is: " + fieldSize ) ; } if ( len == 0 ) { return "" ; } int oldLimit = _buf . limit ( ) ; try { _buf . limit ( _buf . position ( ) + len ) ; byte [ ] bytes = new byte [ len ] ; _buf . get ( bytes , 0 , len ) ; String retVal = cs . decode ( java . nio . ByteBuffer . wrap ( bytes ) ) . toString ( ) ; return retVal ; } finally { _buf . limit ( oldLimit ) ; } }
Returns a length - prefixed string from the buffer at the current position .
214
15
138,895
public String getString ( Charset cs ) { // find indexof \0 and create a string for the charset int nullAt = indexOf ( ( byte ) 0 ) ; boolean utf16 = cs . name ( ) . startsWith ( "UTF-16" ) ; if ( utf16 ) { int oldPos = _buf . position ( ) ; boolean nullFound = false ; while ( ! nullFound && ( nullAt != - 1 ) ) { if ( _buf . get ( nullAt + 1 ) == 0 ) { nullFound = true ; break ; } _buf . position ( nullAt + 1 ) ; nullAt = indexOf ( ( byte ) 0 ) ; } if ( ! nullFound ) { throw new IllegalStateException ( "The string being read is not UTF-16" ) ; } _buf . position ( oldPos ) ; } int newLimit ; if ( nullAt != - 1 ) { newLimit = nullAt ; } else { newLimit = _buf . limit ( ) ; } int numBytes = newLimit - _buf . position ( ) ; int oldLimit = _buf . limit ( ) ; try { _buf . limit ( newLimit ) ; byte [ ] bytes = new byte [ numBytes ] ; _buf . get ( bytes , 0 , numBytes ) ; String retVal = cs . decode ( java . nio . ByteBuffer . wrap ( bytes ) ) . toString ( ) ; return retVal ; } finally { _buf . limit ( oldLimit ) ; if ( nullAt != - 1 ) { _buf . get ( ) ; if ( utf16 ) { _buf . get ( ) ; } } } }
Returns a null - terminated string from the buffer at the current position . If the end of buffer if reached before discovering a null terminator byte then the decoded string includes all bytes up to the end of the buffer .
354
44
138,896
public WrappedByteBuffer skip ( int size ) { _autoExpand ( size ) ; _buf . position ( _buf . position ( ) + size ) ; return this ; }
Skips the specified number of bytes from the current position .
38
12
138,897
public String getHexDump ( ) { if ( _buf . position ( ) == _buf . limit ( ) ) { return "empty" ; } StringBuilder hexDump = new StringBuilder ( ) ; for ( int i = _buf . position ( ) ; i < _buf . limit ( ) ; i ++ ) { hexDump . append ( Integer . toHexString ( _buf . get ( i ) & 0xFF ) ) . append ( ' ' ) ; } return hexDump . toString ( ) ; }
Returns a hex dump of this buffer .
115
8
138,898
WrappedByteBuffer expandAt ( int i , int expectedRemaining ) { if ( ( i + expectedRemaining ) <= _buf . limit ( ) ) { return this ; } else { if ( ( i + expectedRemaining ) <= _buf . capacity ( ) ) { _buf . limit ( i + expectedRemaining ) ; } else { // reallocate the underlying byte buffer and keep the original buffer // intact. The resetting of the position is required because, one // could be in the middle of a read of an existing buffer, when they // decide to over write only few bytes but still keep the remaining // part of the buffer unchanged. int newCapacity = _buf . capacity ( ) + ( ( expectedRemaining > INITIAL_CAPACITY ) ? expectedRemaining : INITIAL_CAPACITY ) ; java . nio . ByteBuffer newBuffer = java . nio . ByteBuffer . allocate ( newCapacity ) ; _buf . flip ( ) ; newBuffer . put ( _buf ) ; _buf = newBuffer ; } } return this ; }
Expands the buffer to support the expected number of remaining bytes at the specified index .
229
17
138,899
static void setArrayIndex ( Map < String , String > meta , int level , int index ) { meta . put ( level + ARRAY_IDX_SUFFIX , Integer . toString ( index ) ) ; }
Sets an array index on a map of metadata for a specific level of a nested json tree . Since the json requires that arrays have preserved order it s imported that it is constrained from the flattened to the re - expanded representation .
47
46