signature:
public class Schema { /** * Specify natural parent of an element in this schema .
 * @ param name Name of the child element
 * @ param parentName Name of the parent element */
public void parent ( String name , String parentName ) { } }

implementation: ElementType child = getElementType ( name ) ; ElementType parent = getElementType ( parentName ) ; if ( child == null ) { throw new Error ( "No child " + name + " for parent " + parentName ) ; } if ( parent == null ) { throw new Error ( "No parent " + parentName + " for child " + name ) ; } child . setParent ( parent ) ;


signature:
public class Schema { /** * Get an ElementType by name .
 * @ param name Name ( Qname ) of the element type
 * @ return The corresponding ElementType */
@ SuppressLint ( "DefaultLocale" ) public ElementType getElementType ( String name ) { } }

implementation: return ( ElementType ) ( theElementTypes . get ( name . toLowerCase ( ) ) ) ;


signature:
public class Schema { /** * Get an entity value by name .
 * @ param name Name of the entity
 * @ return The corresponding character , or 0 if none */
public int getEntity ( String name ) { } }

implementation:
// System . err . println ( " % % Looking up entity " + name ) ;
Integer ch = ( Integer ) theEntities . get ( name ) ; if ( ch == null ) return 0 ; return ch . intValue ( ) ;


signature:
public class ImageChooserManager { /** * TODO : on Android M we need to ask the WRITE _ EXTERNAL _ STORAGE permission explicitly */
private boolean takePicture ( ) { } }

implementation:
try { // Create an image file name ( must be in " public area " or the camera app might not be able to access the file )
File imagePath = Environment . getExternalStoragePublicDirectory ( Environment . DIRECTORY_PICTURES ) ; File imageFile = MediaUtils . createUniqueFile ( imagePath , CAPTURED_IMAGE_TEMPLATE , false ) ; imagePath . mkdirs ( ) ; if ( imagePath . exists ( ) && imageFile . createNewFile ( ) ) { setOriginalFile ( imageFile . getAbsolutePath ( ) ) ; Uri uriForCamera ; if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP ) { // There are compatibility issues with FileProvider Uris on lower versions
uriForCamera = Uri . fromFile ( imageFile ) ; } else { uriForCamera = FileProvider . getUriForFile ( mActivity , "com.onegravity.rteditor.fileprovider" , imageFile ) ; } Intent intent = new Intent ( MediaStore . ACTION_IMAGE_CAPTURE ) . putExtra ( MediaStore . EXTRA_OUTPUT , uriForCamera ) ; startActivity ( intent ) ; } else { Toast . makeText ( mActivity , "Can't take picture without an sdcard" , Toast . LENGTH_SHORT ) . show ( ) ; return false ; } } catch ( Exception e ) { Log . e ( getClass ( ) . getSimpleName ( ) , e . getMessage ( ) , e ) ; } return true ;


signature:
public class UrlValidator { /** * Returns true if the authority is properly formatted . An authority is the combination
 * of hostname and port . A < code > null < / code > authority value is considered invalid .
 * Note : this implementation validates the domain unless a RegexValidator was provided .
 * If a RegexValidator was supplied and it matches , then the authority is regarded
 * as valid with no further checks , otherwise the method checks against the
 * AUTHORITY _ PATTERN and the DomainValidator ( ALLOW _ LOCAL _ URLS )
 * @ param authority Authority value to validate , alllows IDN
 * @ return true if authority ( hostname and port ) is valid . */
protected boolean isValidAuthority ( String authority ) { } }

implementation:
if ( authority == null ) { return false ; } // check manual authority validation if specified
if ( authorityValidator != null && authorityValidator . isValid ( authority ) ) { return true ; } // convert to ASCII if possible
final String authorityASCII = DomainValidator . unicodeToASCII ( authority ) ; Matcher authorityMatcher = AUTHORITY_PATTERN . matcher ( authorityASCII ) ; if ( ! authorityMatcher . matches ( ) ) { return false ; } String hostLocation = authorityMatcher . group ( PARSE_AUTHORITY_HOST_IP ) ; // check if authority is hostname or IP address :
// try a hostname first since that ' s much more likely
DomainValidator domainValidator = DomainValidator . getInstance ( isOn ( ALLOW_LOCAL_URLS ) ) ; if ( ! domainValidator . isValid ( hostLocation ) ) { // try an IP address
InetAddressValidator inetAddressValidator = InetAddressValidator . getInstance ( ) ; if ( ! inetAddressValidator . isValid ( hostLocation ) ) { // isn ' t either one , so the URL is invalid
return false ; } } String port = authorityMatcher . group ( PARSE_AUTHORITY_PORT ) ; if ( port != null && ! PORT_PATTERN . matcher ( port ) . matches ( ) ) { return false ; } String extra = authorityMatcher . group ( PARSE_AUTHORITY_EXTRA ) ; if ( extra != null && extra . trim ( ) . length ( ) > 0 ) { return false ; } return true ;


signature:
public class UrlValidator { /** * Returns true if the path is valid . A < code > null < / code > value is considered invalid .
 * @ param path Path value to validate .
 * @ return true if path is valid . */
protected boolean isValidPath ( String path ) { } }

implementation: if ( path == null ) { return false ; } if ( ! PATH_PATTERN . matcher ( path ) . matches ( ) ) { return false ; } int slash2Count = countToken ( "//" , path ) ; if ( isOff ( ALLOW_2_SLASHES ) && ( slash2Count > 0 ) ) { return false ; } int slashCount = countToken ( "/" , path ) ; int dot2Count = countToken ( ".." , path ) ; if ( dot2Count > 0 && ( slashCount - slash2Count - 1 ) <= dot2Count ) { return false ; } return true ;


signature:
public class Effects { /** * This important method makes sure that all paragraph effects are applied to whole paragraphs .
 * While it ' s optimized for performance it ' s still an expensive operation so it shouldn ' t be
 * called too often .
 * @ param exclude if an Effect has just been applied , there ' s no need to cleanup that Effect . */
public static void cleanupParagraphs ( RTEditText editor , Effect ... exclude ) { } }

implementation: cleanupParagraphs ( editor , Effects . ALIGNMENT , exclude ) ; cleanupParagraphs ( editor , Effects . INDENTATION , exclude ) ; cleanupParagraphs ( editor , Effects . BULLET , exclude ) ; cleanupParagraphs ( editor , Effects . NUMBER , exclude ) ;


signature:
public class RTMediaFactoryImpl { /** * Returns the absolute file path for a certain RTMediaType .
 * The media type specific path as provided by RTMediaType is appended to
 * the storage path ( e . g . < storage area > / images for image files ) . */
protected String getAbsolutePath ( RTMediaType mediaType ) { } }

implementation: File mediaPath = new File ( mStoragePath . getAbsolutePath ( ) , mediaType . mediaPath ( ) ) ; if ( ! mediaPath . exists ( ) ) { mediaPath . mkdirs ( ) ; } return mediaPath . getAbsolutePath ( ) ;


signature:
public class RTMediaFactoryImpl { /** * Use case 1 : Inserting media objects into the rich text editor .
 * This default implementation copies all files into the dedicated media
 * storage area . */
@ Override /* @ inheritDoc */
public RTImage createImage ( RTMediaSource mediaSource ) { } }

implementation: File targetFile = loadMedia ( mediaSource ) ; return targetFile == null ? null : new RTImageImpl ( targetFile . getAbsolutePath ( ) ) ;


signature:
public class CharacterEffect { /** * Apply this effect to the selection .
 * If value is Null then the effect will be removed from the current selection .
 * @ param editor The editor to apply the effect to ( current selection )
 * @ param value The value to apply ( depends on the Effect ) */
public void applyToSelection ( RTEditText editor , V value ) { } }

implementation:
Selection selection = getSelection ( editor ) ; // SPAN _ INCLUSIVE _ INCLUSIVE is default for empty spans
int flags = selection . isEmpty ( ) ? Spanned . SPAN_INCLUSIVE_INCLUSIVE : Spanned . SPAN_EXCLUSIVE_INCLUSIVE ; Spannable str = editor . getText ( ) ; for ( RTSpan < V > span : getSpans ( str , selection , SpanCollectMode . SPAN_FLAGS ) ) { boolean sameSpan = span . getValue ( ) . equals ( value ) ; int spanStart = str . getSpanStart ( span ) ; if ( spanStart < selection . start ( ) ) { // process preceding spans
if ( sameSpan ) { // we have a preceding span - - > use SPAN _ EXCLUSIVE _ INCLUSIVE instead of SPAN _ INCLUSIVE _ INCLUSIVE
flags = Spanned . SPAN_EXCLUSIVE_INCLUSIVE ; selection . offset ( selection . start ( ) - spanStart , 0 ) ; } else { str . setSpan ( newSpan ( span . getValue ( ) ) , spanStart , selection . start ( ) , Spanned . SPAN_EXCLUSIVE_EXCLUSIVE ) ; } } int spanEnd = str . getSpanEnd ( span ) ; if ( spanEnd > selection . end ( ) ) { // process succeeding spans
if ( sameSpan ) { selection . offset ( 0 , spanEnd - selection . end ( ) ) ; } else { str . setSpan ( newSpan ( span . getValue ( ) ) , selection . end ( ) , spanEnd , Spanned . SPAN_EXCLUSIVE_INCLUSIVE ) ; } } str . removeSpan ( span ) ; } if ( value != null ) { RTSpan < V > newSpan = newSpan ( value ) ; if ( newSpan != null ) { str . setSpan ( newSpan , selection . start ( ) , selection . end ( ) , flags ) ; } }


signature:
public class EmailValidator { /** * < p > Checks if a field has a valid e - mail address . < / p >
 * @ param email The value validation is being performed on . A < code > null < / code >
 * value is considered invalid .
 * @ return true if the email address is valid . */
public boolean isValid ( String email ) { } }

implementation:
if ( email == null ) { return false ; } if ( email . endsWith ( "." ) ) { // check this first - it ' s cheap !
return false ; } // Check the whole email address structure
Matcher emailMatcher = EMAIL_PATTERN . matcher ( email ) ; if ( ! emailMatcher . matches ( ) ) { return false ; } if ( ! isValidUser ( emailMatcher . group ( 1 ) ) ) { return false ; } if ( ! isValidDomain ( emailMatcher . group ( 2 ) ) ) { return false ; } return true ;


signature:
public class EmailValidator { /** * Returns true if the domain component of an email address is valid .
 * @ param domain being validated , may be in IDN format
 * @ return true if the email address ' s domain is valid . */
protected boolean isValidDomain ( String domain ) { } }

implementation:
// see if domain is an IP address in brackets
Matcher ipDomainMatcher = IP_DOMAIN_PATTERN . matcher ( domain ) ; if ( ipDomainMatcher . matches ( ) ) { InetAddressValidator inetAddressValidator = InetAddressValidator . getInstance ( ) ; return inetAddressValidator . isValid ( ipDomainMatcher . group ( 1 ) ) ; } // Domain is symbolic name
DomainValidator domainValidator = DomainValidator . getInstance ( allowLocal ) ; return domainValidator . isValid ( domain ) || domainValidator . isValidTld ( domain ) ;


signature:
public class RTEditorMovementMethod { /** * TODO finding links doesn ' t work with right alignment and potentially other formatting options */
private int getCharIndexAt ( TextView textView , MotionEvent event ) { } }

implementation:
// get coordinates
int x = ( int ) event . getX ( ) ; int y = ( int ) event . getY ( ) ; x -= textView . getTotalPaddingLeft ( ) ; y -= textView . getTotalPaddingTop ( ) ; x += textView . getScrollX ( ) ; y += textView . getScrollY ( ) ; /* * Fail - fast check of the line bound .
 * If we ' re not within the line bound no character was touched */
Layout layout = textView . getLayout ( ) ; int line = layout . getLineForVertical ( y ) ; synchronized ( sLineBounds ) { layout . getLineBounds ( line , sLineBounds ) ; if ( ! sLineBounds . contains ( x , y ) ) { return - 1 ; } } // retrieve line text
Spanned text = ( Spanned ) textView . getText ( ) ; int lineStart = layout . getLineStart ( line ) ; int lineEnd = layout . getLineEnd ( line ) ; int lineLength = lineEnd - lineStart ; if ( lineLength == 0 ) { return - 1 ; } Spanned lineText = ( Spanned ) text . subSequence ( lineStart , lineEnd ) ; // compute leading margin and subtract it from the x coordinate
int margin = 0 ; LeadingMarginSpan [ ] marginSpans = lineText . getSpans ( 0 , lineLength , LeadingMarginSpan . class ) ; if ( marginSpans != null ) { for ( LeadingMarginSpan span : marginSpans ) { margin += span . getLeadingMargin ( true ) ; } } x -= margin ; // retrieve text widths
float [ ] widths = new float [ lineLength ] ; TextPaint paint = textView . getPaint ( ) ; paint . getTextWidths ( lineText , 0 , lineLength , widths ) ; // scale text widths by relative font size ( absolute size / default size )
final float defaultSize = textView . getTextSize ( ) ; float scaleFactor = 1f ; AbsoluteSizeSpan [ ] absSpans = lineText . getSpans ( 0 , lineLength , AbsoluteSizeSpan . class ) ; if ( absSpans != null ) { for ( AbsoluteSizeSpan span : absSpans ) { int spanStart = lineText . getSpanStart ( span ) ; int spanEnd = lineText . getSpanEnd ( span ) ; scaleFactor = span . getSize ( ) / defaultSize ; int start = Math . max ( lineStart , spanStart ) ; int end = Math . min ( lineEnd , spanEnd ) ; for ( int i = start ; i < end ; i ++ ) { widths [ i ] *= scaleFactor ; } } } // find index of touched character
float startChar = 0 ; float endChar = 0 ; for ( int i = 0 ; i < lineLength ; i ++ ) { startChar = endChar ; endChar += widths [ i ] ; if ( endChar >= x ) { // which " end " is closer to x , the start or the end of the character ?
int index = lineStart + ( x - startChar < endChar - x ? i : i + 1 ) ; // Logger . e ( Logger . LOG _ TAG , " Found character : " + ( text . length ( ) > index ? text . charAt ( index ) : " " ) ) ;
return index ; } } return - 1 ;


signature:
public class RTOperationManager { /** * Call this when an operation is performed to add it to the undo stack .
 * @ param editor The rich text editor the operation was performed on
 * @ param op The Operation that was performed */
synchronized void executed ( RTEditText editor , Operation op ) { } }

implementation:
Stack < Operation > undoStack = getUndoStack ( editor ) ; Stack < Operation > redoStack = getRedoStack ( editor ) ; // if operations are executed in a quick succession we " merge " them to have but one
// - > saves memory and makes more sense from a user perspective ( each key stroke an undo ? - > no way )
while ( ! undoStack . empty ( ) && op . canMerge ( undoStack . peek ( ) ) ) { Operation previousOp = undoStack . pop ( ) ; op . merge ( previousOp ) ; } push ( op , undoStack ) ; redoStack . clear ( ) ;


signature:
public class RTOperationManager { /** * Re - do the last undone operation for a specific rich text editor
 * @ param editor Re - do an operation for this rich text editor */
synchronized void redo ( RTEditText editor ) { } }

implementation: Stack < Operation > redoStack = getRedoStack ( editor ) ; if ( ! redoStack . empty ( ) ) { Stack < Operation > undoStack = getUndoStack ( editor ) ; Operation op = redoStack . pop ( ) ; push ( op , undoStack ) ; op . redo ( editor ) ; while ( ! redoStack . empty ( ) && op . canMerge ( redoStack . peek ( ) ) ) { op = redoStack . pop ( ) ; push ( op , undoStack ) ; op . redo ( editor ) ; } }


signature:
public class RTOperationManager { /** * Flush all operations for a specific rich text editor ( method unused at the moment )
 * @ param editor This rich text editor ' s operations will be flushed */
synchronized void flushOperations ( RTEditText editor ) { } }

implementation: Stack < Operation > undoStack = getUndoStack ( editor ) ; Stack < Operation > redoStack = getRedoStack ( editor ) ; undoStack . clear ( ) ; redoStack . clear ( ) ;


signature:
public class RTOperationManager { /** * * * * * * Private Methods * * * * * */
private void push ( Operation op , Stack < Operation > stack ) { } }

implementation: if ( stack . size ( ) >= MAX_NR_OF_OPERATIONS ) { stack . remove ( 0 ) ; } stack . push ( op ) ;


signature:
public class ConverterTextToHtml { /** * A memory optimized algorithm for String . replaceAll */
private static String replaceAll ( String source , String search , String replace ) { } }

implementation: if ( USE_REPLACE_ALL ) { return source . replaceAll ( search , replace ) ; } else { Pattern p = Pattern . compile ( search ) ; Matcher m = p . matcher ( source ) ; StringBuffer sb = new StringBuffer ( ) ; boolean atLeastOneFound = false ; while ( m . find ( ) ) { m . appendReplacement ( sb , replace ) ; atLeastOneFound = true ; } if ( atLeastOneFound ) { m . appendTail ( sb ) ; return sb . toString ( ) ; } else { return source ; } }


signature:
public class BitmapManager { /** * Get thread status and create one if specified . */
private synchronized ThreadStatus getOrCreateThreadStatus ( Thread t ) { } }

implementation: ThreadStatus status = mThreadStatus . get ( t ) ; if ( status == null ) { status = new ThreadStatus ( ) ; mThreadStatus . put ( t , status ) ; } return status ;


signature:
public class BitmapManager { /** * The following three methods are used to keep track of
 * BitmapFaction . Options used for decoding and cancelling . */
private synchronized void setDecodingOptions ( Thread t , BitmapFactory . Options options ) { } }

implementation: getOrCreateThreadStatus ( t ) . mOptions = options ;


signature:
public class BitmapManager { /** * The following three methods are used to keep track of which thread is
 * being disabled for bitmap decoding . */
public synchronized boolean canThreadDecoding ( Thread t ) { } }

implementation:
ThreadStatus status = mThreadStatus . get ( t ) ; if ( status == null ) { // allow decoding by default
return true ; } return ( status . mState != State . CANCEL ) ;


signature:
public class BitmapManager { /** * The real place to delegate bitmap decoding to BitmapFactory . */
public Bitmap decodeFileDescriptor ( FileDescriptor fd , BitmapFactory . Options options ) { } }

implementation: if ( options . mCancel ) { return null ; } Thread thread = Thread . currentThread ( ) ; if ( ! canThreadDecoding ( thread ) ) { return null ; } setDecodingOptions ( thread , options ) ; Bitmap b = BitmapFactory . decodeFileDescriptor ( fd , null , options ) ; removeDecodingOptions ( thread ) ; return b ;


signature:
public class FontManager { /** * Use this method to preload fonts asynchronously e . g . when the app starts up . */
public static void preLoadFonts ( final Context context ) { } }

implementation: new Thread ( ( ) -> { synchronized ( ASSET_FONTS_BY_NAME ) { getAssetFonts ( context ) ; } synchronized ( SYSTEM_FONTS_BY_NAME ) { getSystemFonts ( ) ; } } ) . start ( ) ;


signature:
public class FontManager { /** * Retrieve the fonts from the asset and the system folder .
 * @ return A Map mapping the name of the font to the Typeface .
 * If the name can ' t be retrieved the file name will be used ( e . g . arial . ttf ) . */
public static SortedSet < RTTypeface > getFonts ( Context context ) { } }

implementation:
/* * Fonts from the assets folder */
Map < String , String > assetFonts = getAssetFonts ( context ) ; AssetManager assets = context . getResources ( ) . getAssets ( ) ; for ( String fontName : assetFonts . keySet ( ) ) { String filePath = assetFonts . get ( fontName ) ; if ( ! ALL_FONTS . contains ( fontName ) ) { try { Typeface typeface = Typeface . createFromAsset ( assets , filePath ) ; ALL_FONTS . add ( new RTTypeface ( fontName , typeface ) ) ; } catch ( Exception e ) { // this can happen if we don ' t have access to the font or it ' s not a font or . . .
} } } /* * Fonts from the system */
Map < String , String > systemFonts = getSystemFonts ( ) ; for ( String fontName : systemFonts . keySet ( ) ) { String filePath = systemFonts . get ( fontName ) ; if ( ! ALL_FONTS . contains ( fontName ) ) { try { Typeface typeface = Typeface . createFromFile ( filePath ) ; ALL_FONTS . add ( new RTTypeface ( fontName , typeface ) ) ; } catch ( Exception e ) { // this can happen if we don ' t have access to the font or it ' s not a font or . . .
} } } return ALL_FONTS ;


signature:
public class FontManager { /** * Retrieve the fonts from the asset folder .
 * @ return A Map mapping name of the font to the file path .
 * If the name can ' t be retrieved the file name will be used ( e . g . arial . ttf ) . */
private static Map < String , String > getAssetFonts ( Context context ) { } }

implementation:
synchronized ( ASSET_FONTS_BY_NAME ) { /* * Let ' s do this only once because it ' s expensive and the result won ' t change in any case . */
if ( ASSET_FONTS_BY_NAME . isEmpty ( ) ) { AssetManager assets = context . getResources ( ) . getAssets ( ) ; Collection < String > fontFiles = AssetIndex . getAssetIndex ( context ) ; if ( fontFiles == null || fontFiles . isEmpty ( ) ) { fontFiles = listFontFiles ( context . getResources ( ) ) ; } for ( String filePath : fontFiles ) { if ( filePath . toLowerCase ( Locale . getDefault ( ) ) . endsWith ( "ttf" ) ) { String fontName = TTFAnalyzer . getFontName ( assets , filePath ) ; if ( fontName == null ) { fontName = getFileName ( filePath ) ; } ASSET_FONTS_BY_NAME . put ( fontName , filePath ) ; } } } return ASSET_FONTS_BY_NAME ; }


signature:
public class FontManager { /** * Retrieve the fonts from the system folders .
 * @ return A Map mapping name of the font to the file path .
 * If the name can ' t be retrieved the file name will be used ( e . g . arial . ttf ) . */
private static Map < String , String > getSystemFonts ( ) { } }

implementation: synchronized ( SYSTEM_FONTS_BY_NAME ) { for ( String fontDir : FONT_DIRS ) { File dir = new File ( fontDir ) ; if ( ! dir . exists ( ) ) continue ; File [ ] files = dir . listFiles ( ) ; if ( files == null ) continue ; for ( File file : files ) { String filePath = file . getAbsolutePath ( ) ; if ( ! SYSTEM_FONTS_BY_PATH . containsKey ( filePath ) ) { String fontName = TTFAnalyzer . getFontName ( file . getAbsolutePath ( ) ) ; if ( fontName == null ) { fontName = getFileName ( filePath ) ; } SYSTEM_FONTS_BY_PATH . put ( filePath , fontName ) ; SYSTEM_FONTS_BY_NAME . put ( fontName , filePath ) ; } } } return SYSTEM_FONTS_BY_NAME ; }


signature:
public class IOUtils { /** * Get contents of an < code > InputStream < / code > as a < code > byte [ ] < / code > .
 * Use this method instead of < code > toByteArray ( InputStream ) < / code >
 * when < code > InputStream < / code > size is known .
 * < b > NOTE : < / b > the method checks that the length can safely be cast to an int without truncation
 * before using { @ link IOUtils # toByteArray ( java . io . InputStream , int ) } to read into the byte array .
 * ( Arrays can have no more than Integer . MAX _ VALUE entries anyway )
 * @ param input the < code > InputStream < / code > to read from
 * @ param size the size of < code > InputStream < / code >
 * @ return the requested byte array
 * @ throws IOException if an I / O error occurs or < code > InputStream < / code > size differ from parameter size
 * @ throws IllegalArgumentException if size is less than zero or size is greater than Integer . MAX _ VALUE
 * @ see IOUtils # toByteArray ( java . io . InputStream , int )
 * @ since 2.1 */
public static byte [ ] toByteArray ( InputStream input , long size ) throws IOException { } }

implementation: if ( size > Integer . MAX_VALUE ) { throw new IllegalArgumentException ( "Size cannot be greater than Integer max value: " + size ) ; } return toByteArray ( input , ( int ) size ) ;


signature:
public class IOUtils { /** * Get the contents of an < code > InputStream < / code > as a < code > byte [ ] < / code > .
 * Use this method instead of < code > toByteArray ( InputStream ) < / code >
 * when < code > InputStream < / code > size is known
 * @ param input the < code > InputStream < / code > to read from
 * @ param size the size of < code > InputStream < / code >
 * @ return the requested byte array
 * @ throws IOException if an I / O error occurs or < code > InputStream < / code > size differ from parameter size
 * @ throws IllegalArgumentException if size is less than zero
 * @ since 2.1 */
public static byte [ ] toByteArray ( InputStream input , int size ) throws IOException { } }

implementation: if ( size < 0 ) { throw new IllegalArgumentException ( "Size must be equal or greater than zero: " + size ) ; } if ( size == 0 ) { return new byte [ 0 ] ; } byte [ ] data = new byte [ size ] ; int offset = 0 ; int readed ; while ( offset < size && ( readed = input . read ( data , offset , size - offset ) ) != EOF ) { offset += readed ; } if ( offset != size ) { throw new IOException ( "Unexpected readed size. current: " + offset + ", excepted: " + size ) ; } return data ;


signature:
public class IOUtils { /** * Get the contents of a < code > Reader < / code > as a < code > byte [ ] < / code >
 * using the specified character encoding .
 * This method buffers the input internally , so there is no need to use a
 * < code > BufferedReader < / code > .
 * @ param input the < code > Reader < / code > to read from
 * @ param encoding the encoding to use , null means platform default
 * @ return the requested byte array
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.3 */
public static byte [ ] toByteArray ( Reader input , Charset encoding ) throws IOException { } }

implementation: ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; copy ( input , output , encoding ) ; return output . toByteArray ( ) ;


signature:
public class IOUtils { /** * Get the contents of a < code > Reader < / code > as a < code > byte [ ] < / code >
 * using the specified character encoding .
 * Character encoding names can be found at
 * < a href = " http : / / www . iana . org / assignments / character - sets " > IANA < / a > .
 * This method buffers the input internally , so there is no need to use a
 * < code > BufferedReader < / code > .
 * @ param input the < code > Reader < / code > to read from
 * @ param encoding the encoding to use , null means platform default
 * @ return the requested byte array
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O error occurs
 * @ throws UnsupportedCharsetException thrown instead of { @ link UnsupportedEncodingException } in version 2.2 if the encoding is not
 * supported .
 * @ since 1.1 */
public static byte [ ] toByteArray ( Reader input , String encoding ) throws IOException { } }

implementation: return toByteArray ( input , Charsets . toCharset ( encoding ) ) ;


signature:
public class IOUtils { /** * Get the contents of a < code > URL < / code > as a < code > byte [ ] < / code > .
 * @ param url the < code > URL < / code > to read
 * @ return the requested byte array
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O exception occurs
 * @ since 2.4 */
public static byte [ ] toByteArray ( URL url ) throws IOException { } }

implementation: URLConnection conn = url . openConnection ( ) ; try { return IOUtils . toByteArray ( conn ) ; } finally { close ( conn ) ; }


signature:
public class IOUtils { /** * Get the contents of a < code > URLConnection < / code > as a < code > byte [ ] < / code > .
 * @ param urlConn the < code > URLConnection < / code > to read
 * @ return the requested byte array
 * @ throws NullPointerException if the urlConn is null
 * @ throws IOException if an I / O exception occurs
 * @ since 2.4 */
public static byte [ ] toByteArray ( URLConnection urlConn ) throws IOException { } }

implementation: InputStream inputStream = urlConn . getInputStream ( ) ; try { return IOUtils . toByteArray ( inputStream ) ; } finally { inputStream . close ( ) ; }


signature:
public class IOUtils { /** * Get the contents of an < code > InputStream < / code > as a character array
 * using the specified character encoding .
 * This method buffers the input internally , so there is no need to use a
 * < code > BufferedInputStream < / code > .
 * @ param is the < code > InputStream < / code > to read from
 * @ param encoding the encoding to use , null means platform default
 * @ return the requested character array
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.3 */
public static char [ ] toCharArray ( InputStream is , Charset encoding ) throws IOException { } }

implementation: CharArrayWriter output = new CharArrayWriter ( ) ; copy ( is , output , encoding ) ; return output . toCharArray ( ) ;


signature:
public class IOUtils { /** * Get the contents of an < code > InputStream < / code > as a character array
 * using the specified character encoding .
 * Character encoding names can be found at
 * < a href = " http : / / www . iana . org / assignments / character - sets " > IANA < / a > .
 * This method buffers the input internally , so there is no need to use a
 * < code > BufferedInputStream < / code > .
 * @ param is the < code > InputStream < / code > to read from
 * @ param encoding the encoding to use , null means platform default
 * @ return the requested character array
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O error occurs
 * @ throws UnsupportedCharsetException thrown instead of { @ link UnsupportedEncodingException } in version 2.2 if the encoding is not
 * supported .
 * @ since 1.1 */
public static char [ ] toCharArray ( InputStream is , String encoding ) throws IOException { } }

implementation: return toCharArray ( is , Charsets . toCharset ( encoding ) ) ;


signature:
public class IOUtils { /** * Get the contents of a < code > Reader < / code > as a character array .
 * This method buffers the input internally , so there is no need to use a
 * < code > BufferedReader < / code > .
 * @ param input the < code > Reader < / code > to read from
 * @ return the requested character array
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O error occurs
 * @ since 1.1 */
public static char [ ] toCharArray ( Reader input ) throws IOException { } }

implementation: CharArrayWriter sw = new CharArrayWriter ( ) ; copy ( input , sw ) ; return sw . toCharArray ( ) ;


signature:
public class IOUtils { /** * Get the contents of an < code > InputStream < / code > as a list of Strings ,
 * one entry per line , using the specified character encoding .
 * This method buffers the input internally , so there is no need to use a
 * < code > BufferedInputStream < / code > .
 * @ param input the < code > InputStream < / code > to read from , not null
 * @ param encoding the encoding to use , null means platform default
 * @ return the list of Strings , never null
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.3 */
public static List < String > readLines ( InputStream input , Charset encoding ) throws IOException { } }

implementation: InputStreamReader reader = new InputStreamReader ( input , Charsets . toCharset ( encoding ) ) ; return readLines ( reader ) ;


signature:
public class IOUtils { /** * Get the contents of an < code > InputStream < / code > as a list of Strings ,
 * one entry per line , using the specified character encoding .
 * Character encoding names can be found at
 * < a href = " http : / / www . iana . org / assignments / character - sets " > IANA < / a > .
 * This method buffers the input internally , so there is no need to use a
 * < code > BufferedInputStream < / code > .
 * @ param input the < code > InputStream < / code > to read from , not null
 * @ param encoding the encoding to use , null means platform default
 * @ return the list of Strings , never null
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O error occurs
 * @ throws UnsupportedCharsetException thrown instead of { @ link UnsupportedEncodingException } in version 2.2 if the encoding is not
 * supported .
 * @ since 1.1 */
public static List < String > readLines ( InputStream input , String encoding ) throws IOException { } }

implementation: return readLines ( input , Charsets . toCharset ( encoding ) ) ;


signature:
public class IOUtils { /** * Return an Iterator for the lines in an < code > InputStream < / code > , using
 * the character encoding specified ( or default encoding if null ) .
 * < code > LineIterator < / code > holds a reference to the open
 * < code > InputStream < / code > specified here . When you have finished with
 * the iterator you should close the stream to free internal resources .
 * This can be done by closing the stream directly , or by calling
 * The recommended usage pattern is :
 * < pre >
 * try {
 * LineIterator it = IOUtils . lineIterator ( stream , charset ) ;
 * while ( it . hasNext ( ) ) {
 * String line = it . nextLine ( ) ;
 * / / / do something with line
 * } finally {
 * IOUtils . closeQuietly ( stream ) ;
 * < / pre >
 * @ param input the < code > InputStream < / code > to read from , not null
 * @ param encoding the encoding to use , null means platform default
 * @ return an Iterator of the lines in the reader , never null
 * @ throws IllegalArgumentException if the input is null
 * @ throws IOException if an I / O error occurs , such as if the encoding is invalid
 * @ since 2.3 */
public static LineIterator lineIterator ( InputStream input , Charset encoding ) throws IOException { } }

implementation: return new LineIterator ( new InputStreamReader ( input , Charsets . toCharset ( encoding ) ) ) ;


signature:
public class IOUtils { /** * Return an Iterator for the lines in an < code > InputStream < / code > , using
 * the character encoding specified ( or default encoding if null ) .
 * < code > LineIterator < / code > holds a reference to the open
 * < code > InputStream < / code > specified here . When you have finished with
 * the iterator you should close the stream to free internal resources .
 * This can be done by closing the stream directly , or by calling
 * { @ link LineIterator # close ( ) } or { @ link LineIterator # closeQuietly ( LineIterator ) } .
 * The recommended usage pattern is :
 * < pre >
 * try {
 * LineIterator it = IOUtils . lineIterator ( stream , " UTF - 8 " ) ;
 * while ( it . hasNext ( ) ) {
 * String line = it . nextLine ( ) ;
 * / / / do something with line
 * } finally {
 * IOUtils . closeQuietly ( stream ) ;
 * < / pre >
 * @ param input the < code > InputStream < / code > to read from , not null
 * @ param encoding the encoding to use , null means platform default
 * @ return an Iterator of the lines in the reader , never null
 * @ throws IllegalArgumentException if the input is null
 * @ throws IOException if an I / O error occurs , such as if the encoding is invalid
 * @ throws UnsupportedCharsetException thrown instead of { @ link UnsupportedEncodingException } in version 2.2 if the encoding is not
 * supported .
 * @ since 1.2 */
public static LineIterator lineIterator ( InputStream input , String encoding ) throws IOException { } }

implementation: return lineIterator ( input , Charsets . toCharset ( encoding ) ) ;


signature:
public class IOUtils { /** * Writes bytes from a < code > byte [ ] < / code > to chars on a < code > Writer < / code >
 * using the default character encoding of the platform .
 * This method uses { @ link String # String ( byte [ ] ) } .
 * @ param data the byte array to write , do not modify during output ,
 * null ignored
 * @ param output the < code > Writer < / code > to write to
 * @ throws NullPointerException if output is null
 * @ throws IOException if an I / O error occurs
 * @ since 1.1 */
public static void write ( byte [ ] data , Writer output ) throws IOException { } }

implementation: write ( data , output , Charset . defaultCharset ( ) ) ;


signature:
public class IOUtils { /** * Writes bytes from a < code > byte [ ] < / code > to chars on a < code > Writer < / code >
 * using the specified character encoding .
 * This method uses { @ link String # String ( byte [ ] , String ) } .
 * @ param data the byte array to write , do not modify during output ,
 * null ignored
 * @ param output the < code > Writer < / code > to write to
 * @ param encoding the encoding to use , null means platform default
 * @ throws NullPointerException if output is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.3 */
public static void write ( byte [ ] data , Writer output , Charset encoding ) throws IOException { } }

implementation: if ( data != null ) { output . write ( new String ( data , Charsets . toCharset ( encoding ) ) ) ; }


signature:
public class IOUtils { /** * Writes chars from a < code > char [ ] < / code > to bytes on an
 * < code > OutputStream < / code > using the specified character encoding .
 * This method uses { @ link String # String ( char [ ] ) } and
 * { @ link String # getBytes ( String ) } .
 * @ param data the char array to write , do not modify during output ,
 * null ignored
 * @ param output the < code > OutputStream < / code > to write to
 * @ param encoding the encoding to use , null means platform default
 * @ throws NullPointerException if output is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.3 */
public static void write ( char [ ] data , OutputStream output , Charset encoding ) throws IOException { } }

implementation: if ( data != null ) { output . write ( new String ( data ) . getBytes ( Charsets . toCharset ( encoding ) ) ) ; }


signature:
public class IOUtils { /** * Writes chars from a < code > CharSequence < / code > to bytes on an
 * < code > OutputStream < / code > using the default character encoding of the
 * platform .
 * This method uses { @ link String # getBytes ( ) } .
 * @ param data the < code > CharSequence < / code > to write , null ignored
 * @ param output the < code > OutputStream < / code > to write to
 * @ throws NullPointerException if output is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.0 */
public static void write ( CharSequence data , OutputStream output ) throws IOException { } }


signature:
public class IOUtils { /** * Writes chars from a < code > CharSequence < / code > to bytes on an
 * < code > OutputStream < / code > using the specified character encoding .
 * This method uses { @ link String # getBytes ( String ) } .
 * @ param data the < code > CharSequence < / code > to write , null ignored
 * @ param output the < code > OutputStream < / code > to write to
 * @ param encoding the encoding to use , null means platform default
 * @ throws NullPointerException if output is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.3 */
public static void write ( CharSequence data , OutputStream output , Charset encoding ) throws IOException { } }

implementation: if ( data != null ) { write ( data . toString ( ) , output , encoding ) ; }


signature:
public class IOUtils { /** * Writes chars from a < code > StringBuffer < / code > to a < code > Writer < / code > .
 * @ param data the < code > StringBuffer < / code > to write , null ignored
 * @ param output the < code > Writer < / code > to write to
 * @ throws NullPointerException if output is null
 * @ throws IOException if an I / O error occurs
 * @ since 1.1
 * @ deprecated replaced by write ( CharSequence , Writer ) */
@ Deprecated public static void write ( StringBuffer data , Writer output ) throws IOException { } }

implementation: if ( data != null ) { output . write ( data . toString ( ) ) ; }


signature:
public class IOUtils { /** * Writes chars from a < code > StringBuffer < / code > to bytes on an
 * < code > OutputStream < / code > using the default character encoding of the
 * platform .
 * This method uses { @ link String # getBytes ( ) } .
 * @ param data the < code > StringBuffer < / code > to write , null ignored
 * @ param output the < code > OutputStream < / code > to write to
 * @ throws NullPointerException if output is null
 * @ throws IOException if an I / O error occurs
 * @ since 1.1
 * @ deprecated replaced by write ( CharSequence , OutputStream ) */
@ Deprecated public static void write ( StringBuffer data , OutputStream output ) throws IOException { } }

implementation: write ( data , output , ( String ) null ) ;


signature:
public class IOUtils { /** * Writes chars from a < code > StringBuffer < / code > to bytes on an
 * < code > OutputStream < / code > using the specified character encoding .
 * Character encoding names can be found at
 * < a href = " http : / / www . iana . org / assignments / character - sets " > IANA < / a > .
 * This method uses { @ link String # getBytes ( String ) } .
 * @ param data the < code > StringBuffer < / code > to write , null ignored
 * @ param output the < code > OutputStream < / code > to write to
 * @ param encoding the encoding to use , null means platform default
 * @ throws NullPointerException if output is null
 * @ throws IOException if an I / O error occurs
 * @ throws UnsupportedCharsetException thrown instead of { @ link UnsupportedEncodingException } in version 2.2 if the encoding is not
 * supported .
 * @ since 1.1
 * @ deprecated replaced by write ( CharSequence , OutputStream , String ) */
@ Deprecated public static void write ( StringBuffer data , OutputStream output , String encoding ) throws IOException { } }

implementation: if ( data != null ) { output . write ( data . toString ( ) . getBytes ( Charsets . toCharset ( encoding ) ) ) ; }


signature:
public class IOUtils { /** * Writes the < code > toString ( ) < / code > value of each item in a collection to
 * an < code > OutputStream < / code > line by line , using the default character
 * encoding of the platform and the specified line ending .
 * @ param lines the lines to write , null entries produce blank lines
 * @ param lineEnding the line separator to use , null is system default
 * @ param output the < code > OutputStream < / code > to write to , not null , not closed
 * @ throws NullPointerException if the output is null
 * @ throws IOException if an I / O error occurs
 * @ since 1.1 */
public static void writeLines ( Collection < ? > lines , String lineEnding , OutputStream output ) throws IOException { } }

implementation: writeLines ( lines , lineEnding , output , Charset . defaultCharset ( ) ) ;


signature:
public class IOUtils { /** * Writes the < code > toString ( ) < / code > value of each item in a collection to
 * an < code > OutputStream < / code > line by line , using the specified character
 * encoding and the specified line ending .
 * @ param lines the lines to write , null entries produce blank lines
 * @ param lineEnding the line separator to use , null is system default
 * @ param output the < code > OutputStream < / code > to write to , not null , not closed
 * @ param encoding the encoding to use , null means platform default
 * @ throws NullPointerException if the output is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.3 */
public static void writeLines ( Collection < ? > lines , String lineEnding , OutputStream output , Charset encoding ) throws IOException { } }

implementation: if ( lines == null ) { return ; } if ( lineEnding == null ) { lineEnding = LINE_SEPARATOR ; } Charset cs = Charsets . toCharset ( encoding ) ; for ( Object line : lines ) { if ( line != null ) { output . write ( line . toString ( ) . getBytes ( cs ) ) ; } output . write ( lineEnding . getBytes ( cs ) ) ; }


signature:
public class IOUtils { /** * Writes the < code > toString ( ) < / code > value of each item in a collection to
 * an < code > OutputStream < / code > line by line , using the specified character
 * encoding and the specified line ending .
 * Character encoding names can be found at
 * < a href = " http : / / www . iana . org / assignments / character - sets " > IANA < / a > .
 * @ param lines the lines to write , null entries produce blank lines
 * @ param lineEnding the line separator to use , null is system default
 * @ param output the < code > OutputStream < / code > to write to , not null , not closed
 * @ param encoding the encoding to use , null means platform default
 * @ throws NullPointerException if the output is null
 * @ throws IOException if an I / O error occurs
 * @ throws UnsupportedCharsetException thrown instead of { @ link UnsupportedEncodingException } in version 2.2 if the encoding is not
 * supported .
 * @ since 1.1 */
public static void writeLines ( Collection < ? > lines , String lineEnding , OutputStream output , String encoding ) throws IOException { } }

implementation: writeLines ( lines , lineEnding , output , Charsets . toCharset ( encoding ) ) ;


signature:
public class IOUtils { /** * Writes the < code > toString ( ) < / code > value of each item in a collection to
 * a < code > Writer < / code > line by line , using the specified line ending .
 * @ param lines the lines to write , null entries produce blank lines
 * @ param lineEnding the line separator to use , null is system default
 * @ param writer the < code > Writer < / code > to write to , not null , not closed
 * @ throws NullPointerException if the input is null
 * @ throws IOException if an I / O error occurs
 * @ since 1.1 */
public static void writeLines ( Collection < ? > lines , String lineEnding , Writer writer ) throws IOException { } }

implementation: if ( lines == null ) { return ; } if ( lineEnding == null ) { lineEnding = LINE_SEPARATOR ; } for ( Object line : lines ) { if ( line != null ) { writer . write ( line . toString ( ) ) ; } writer . write ( lineEnding ) ; }


signature:
public class IOUtils { /** * Copy some or all chars from a large ( over 2GB ) < code > InputStream < / code > to an
 * < code > OutputStream < / code > , optionally skipping input chars .
 * This method uses the provided buffer , so there is no need to use a
 * < code > BufferedReader < / code > .
 * @ param input the < code > Reader < / code > to read from
 * @ param output the < code > Writer < / code > to write to
 * @ param inputOffset : number of chars to skip from input before copying
 * - ve values are ignored
 * @ param length : number of chars to copy . - ve means all
 * @ param buffer the buffer to be used for the copy
 * @ return the number of chars copied
 * @ throws NullPointerException if the input or output is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.2 */
public static long copyLarge ( Reader input , Writer output , final long inputOffset , final long length , char [ ] buffer ) throws IOException { } }

implementation:
if ( inputOffset > 0 ) { skipFully ( input , inputOffset ) ; } if ( length == 0 ) { return 0 ; } int bytesToRead = buffer . length ; if ( length > 0 && length < buffer . length ) { bytesToRead = ( int ) length ; } int read ; long totalRead = 0 ; while ( bytesToRead > 0 && EOF != ( read = input . read ( buffer , 0 , bytesToRead ) ) ) { output . write ( buffer , 0 , read ) ; totalRead += read ; if ( length > 0 ) { // only adjust length if not reading to the end
// Note the cast must work because buffer . length is an integer
bytesToRead = ( int ) Math . min ( length - totalRead , buffer . length ) ; } } return totalRead ;


signature:
public class IOUtils { /** * Compare the contents of two Readers to determine if they are equal or
 * not .
 * This method buffers the input internally using
 * < code > BufferedReader < / code > if they are not already buffered .
 * @ param input1 the first reader
 * @ param input2 the second reader
 * @ return true if the content of the readers are equal or they both don ' t
 * exist , false otherwise
 * @ throws NullPointerException if either input is null
 * @ throws IOException if an I / O error occurs
 * @ since 1.1 */
public static boolean contentEquals ( Reader input1 , Reader input2 ) throws IOException { } }

implementation: input1 = toBufferedReader ( input1 ) ; input2 = toBufferedReader ( input2 ) ; int ch = input1 . read ( ) ; while ( EOF != ch ) { int ch2 = input2 . read ( ) ; if ( ch != ch2 ) { return false ; } ch = input1 . read ( ) ; } int ch2 = input2 . read ( ) ; return ch2 == EOF ;


signature:
public class IOUtils { /** * Compare the contents of two Readers to determine if they are equal or
 * not , ignoring EOL characters .
 * This method buffers the input internally using
 * < code > BufferedReader < / code > if they are not already buffered .
 * @ param input1 the first reader
 * @ param input2 the second reader
 * @ return true if the content of the readers are equal ( ignoring EOL differences ) , false otherwise
 * @ throws NullPointerException if either input is null
 * @ throws IOException if an I / O error occurs
 * @ since 2.2 */
public static boolean contentEqualsIgnoreEOL ( Reader input1 , Reader input2 ) throws IOException { } }

implementation: BufferedReader br1 = toBufferedReader ( input1 ) ; BufferedReader br2 = toBufferedReader ( input2 ) ; String line1 = br1 . readLine ( ) ; String line2 = br2 . readLine ( ) ; while ( line1 != null && line2 != null && line1 . equals ( line2 ) ) { line1 = br1 . readLine ( ) ; line2 = br2 . readLine ( ) ; } return line1 == null ? line2 == null ? true : false : line1 . equals ( line2 ) ;


signature:
public class NumericEntityEscaper { /** * { @ inheritDoc } */
@ Override public boolean translate ( final int codepoint , final Writer out ) throws IOException { } }

implementation: if ( between ) { if ( codepoint < below || codepoint > above ) { return false ; } } else { if ( codepoint >= below && codepoint <= above ) { return false ; } } out . write ( "&#" ) ; out . write ( Integer . toString ( codepoint , 10 ) ) ; out . write ( ';' ) ; return true ;


signature:
public class Parser { /** * Sets up instance variables that haven ' t been set by setFeature */
private void setup ( ) { } }

implementation: if ( theSchema == null ) theSchema = new HTMLSchema ( ) ; if ( theScanner == null ) theScanner = new HTMLScanner ( ) ; if ( theAutoDetector == null ) { theAutoDetector = new AutoDetector ( ) { public Reader autoDetectingReader ( InputStream i ) { return new InputStreamReader ( i ) ; } } ; } theStack = new Element ( theSchema . getElementType ( "<root>" ) , defaultAttributes ) ; thePCDATA = new Element ( theSchema . getElementType ( "<pcdata>" ) , defaultAttributes ) ; theNewElement = null ; theAttributeName = null ; thePITarget = null ; theSaved = null ; theEntity = 0 ; virginStack = true ; theDoctypeName = theDoctypePublicId = theDoctypeSystemId = null ;


signature:
public class Parser { /** * Buffer both the InputStream and the Reader */
private Reader getReader ( InputSource s ) throws SAXException , IOException { } }

implementation:
Reader r = s . getCharacterStream ( ) ; InputStream i = s . getByteStream ( ) ; String encoding = s . getEncoding ( ) ; String publicid = s . getPublicId ( ) ; String systemid = s . getSystemId ( ) ; if ( r == null ) { if ( i == null ) i = getInputStream ( publicid , systemid ) ; // i = new BufferedInputStream ( i ) ;
if ( encoding == null ) { r = theAutoDetector . autoDetectingReader ( i ) ; } else { try { r = new InputStreamReader ( i , encoding ) ; } catch ( UnsupportedEncodingException e ) { r = new InputStreamReader ( i ) ; } } } // r = new BufferedReader ( r ) ;
return r ;


signature:
public class Parser { /** * Get an InputStream based on a publicid and a systemid */
private InputStream getInputStream ( String publicid , String systemid ) throws IOException , SAXException { } }

implementation: URL basis = new URL ( "file" , "" , System . getProperty ( "user.dir" ) + "/." ) ; URL url = new URL ( basis , systemid ) ; URLConnection c = url . openConnection ( ) ; return c . getInputStream ( ) ;


signature:
public class Parser { /** * needs to support chars past U + FFFF */
@ Override public void adup ( char [ ] buff , int offset , int length ) throws SAXException { } }

implementation: if ( theNewElement != null && theAttributeName != null ) { theNewElement . setAttribute ( theAttributeName , null , theAttributeName ) ; theAttributeName = null ; }


signature:
public class Parser { /** * with a semicolon . */
private String expandEntities ( String src ) { } }

implementation:
int refStart = - 1 ; int len = src . length ( ) ; char [ ] dst = new char [ len ] ; int dstlen = 0 ; for ( int i = 0 ; i < len ; i ++ ) { char ch = src . charAt ( i ) ; dst [ dstlen ++ ] = ch ; if ( ch == '&' && refStart == - 1 ) { // start of a ref excluding &
refStart = dstlen ; } else if ( refStart == - 1 ) { // not in a ref
} else if ( Character . isLetter ( ch ) || Character . isDigit ( ch ) || ch == '#' ) { // valid entity char
} else if ( ch == ';' ) { // properly terminated ref
int ent = lookupEntity ( dst , refStart , dstlen - refStart - 1 ) ; if ( ent > 0xFFFF ) { ent -= 0x10000 ; dst [ refStart - 1 ] = ( char ) ( ( ent >> 10 ) + 0xD800 ) ; dst [ refStart ] = ( char ) ( ( ent & 0x3FF ) + 0xDC00 ) ; dstlen = refStart + 1 ; } else if ( ent != 0 ) { dst [ refStart - 1 ] = ( char ) ent ; dstlen = refStart ; } refStart = - 1 ; } else { // improperly terminated ref
refStart = - 1 ; } } return new String ( dst , 0 , dstlen ) ;


signature:
public class Parser { /** * deferring to the schema for named ones . */
private int lookupEntity ( char [ ] buff , int offset , int length ) { } }

implementation:
int result = 0 ; if ( length < 1 ) return result ; // length ) + " ] " ) ;
if ( buff [ offset ] == '#' ) { if ( length > 1 && ( buff [ offset + 1 ] == 'x' || buff [ offset + 1 ] == 'X' ) ) { try { return Integer . parseInt ( new String ( buff , offset + 2 , length - 2 ) , 16 ) ; } catch ( NumberFormatException e ) { return 0 ; } } try { return Integer . parseInt ( new String ( buff , offset + 1 , length - 1 ) , 10 ) ; } catch ( NumberFormatException e ) { return 0 ; } } return theSchema . getEntity ( new String ( buff , offset , length ) ) ;


signature:
public class Parser { /** * e is the next element to be started , if we know what it is */
private void restart ( Element e ) throws SAXException { } }

implementation: while ( theSaved != null && theStack . canContain ( theSaved ) && ( e == null || theSaved . canContain ( e ) ) ) { Element next = theSaved . next ( ) ; push ( theSaved ) ; theSaved = next ; }


signature:
public class Parser { /** * Pop the stack irrevocably */
private void pop ( ) throws SAXException { } }

implementation:
if ( theStack == null ) return ; // empty stack
String name = theStack . name ( ) ; String localName = theStack . localName ( ) ; String namespace = theStack . namespace ( ) ; String prefix = prefixOf ( name ) ; if ( ! namespaces ) namespace = localName = "" ; theContentHandler . endElement ( namespace , localName , name ) ; if ( foreign ( prefix , namespace ) ) { theContentHandler . endPrefixMapping ( prefix ) ; // " ] for elements to " + namespace ) ;
} Attributes atts = theStack . atts ( ) ; for ( int i = atts . getLength ( ) - 1 ; i >= 0 ; i -- ) { String attNamespace = atts . getURI ( i ) ; String attPrefix = prefixOf ( atts . getQName ( i ) ) ; if ( foreign ( attPrefix , attNamespace ) ) { theContentHandler . endPrefixMapping ( attPrefix ) ; // " ] for attributes to " + attNamespace ) ;
} } theStack = theStack . next ( ) ;


signature:
public class Parser { /** * Pop the stack restartably */
private void restartablyPop ( ) throws SAXException { } }

implementation: Element popped = theStack ; pop ( ) ; if ( restartElements && ( popped . flags ( ) & Schema . F_RESTART ) != 0 ) { popped . anonymize ( ) ; popped . setNext ( theSaved ) ; theSaved = popped ; }


signature:
public class Parser { /** * Get the prefix from a QName */
private String prefixOf ( String name ) { } }

implementation: int i = name . indexOf ( ':' ) ; String prefix = "" ; if ( i != - 1 ) prefix = name . substring ( 0 , i ) ; return prefix ;


signature:
public class Parser { /** * Return true if we have a foreign name */
private boolean foreign ( String prefix , String namespace ) { } }

implementation:
// " for foreignness - - " ) ;
boolean foreign = ! ( prefix . equals ( "" ) || namespace . equals ( "" ) || namespace . equals ( theSchema . getURI ( ) ) ) ; return foreign ;


signature:
public class Parser { /** * Parsing the complete XML Document Type Definition is way too complex , but
 * for many simple cases we can extract something useful from it .
 * doctypedecl : : = ' < ! DOCTYPE ' S Name ( S ExternalID ) ? S ? ( ' [ ' intSubset ' ] '
 * S ? ) ? ' > ' DeclSep : : = PEReference | S intSubset : : = ( markupdecl |
 * DeclSep ) * markupdecl : : = elementdecl | AttlistDecl | EntityDecl |
 * NotationDecl | PI | Comment ExternalID : : = ' SYSTEM ' S SystemLiteral |
 * ' PUBLIC ' S PubidLiteral S SystemLiteral */
@ Override public void decl ( char [ ] buff , int offset , int length ) throws SAXException { } }

implementation:
String s = new String ( buff , offset , length ) ; String name = null ; String systemid = null ; String publicid = null ; String [ ] v = split ( s ) ; if ( v . length > 0 && "DOCTYPE" . equalsIgnoreCase ( v [ 0 ] ) ) { if ( theDoctypeIsPresent ) return ; // one doctype only !
theDoctypeIsPresent = true ; if ( v . length > 1 ) { name = v [ 1 ] ; if ( v . length > 3 && "SYSTEM" . equals ( v [ 2 ] ) ) { systemid = v [ 3 ] ; } else if ( v . length > 3 && "PUBLIC" . equals ( v [ 2 ] ) ) { publicid = v [ 3 ] ; if ( v . length > 4 ) { systemid = v [ 4 ] ; } else { systemid = "" ; } } } } publicid = trimquotes ( publicid ) ; systemid = trimquotes ( systemid ) ; if ( name != null ) { publicid = cleanPublicid ( publicid ) ; theLexicalHandler . startDTD ( name , publicid , systemid ) ; theLexicalHandler . endDTD ( ) ; theDoctypeName = name ; theDoctypePublicId = publicid ; if ( theScanner instanceof Locator ) { // Must resolve systemid
theDoctypeSystemId = ( ( Locator ) theScanner ) . getSystemId ( ) ; try { theDoctypeSystemId = new URL ( new URL ( theDoctypeSystemId ) , systemid ) . toString ( ) ; } catch ( Exception ignore ) { } } }


signature:
public class Parser { /** * If the String is quoted , trim the quotes . */
private static String trimquotes ( String in ) { } }

implementation: if ( in == null ) return in ; int length = in . length ( ) ; if ( length == 0 ) return in ; char s = in . charAt ( 0 ) ; char e = in . charAt ( length - 1 ) ; if ( s == e && ( s == '\'' || s == '"' ) ) { in = in . substring ( 1 , in . length ( ) - 1 ) ; } return in ;


signature:
public class Parser { /** * Recognises quotes around a phrase and doesn ' t split it . */
private static String [ ] split ( String val ) throws IllegalArgumentException { } }

implementation:
val = val . trim ( ) ; if ( val . length ( ) == 0 ) { return new String [ 0 ] ; } else { ArrayList < String > l = new ArrayList < String > ( ) ; int s = 0 ; int e = 0 ; boolean sq = false ; // single quote
boolean dq = false ; // double quote
char lastc = 0 ; int len = val . length ( ) ; for ( e = 0 ; e < len ; e ++ ) { char c = val . charAt ( e ) ; if ( ! dq && c == '\'' && lastc != '\\' ) { sq = ! sq ; if ( s < 0 ) s = e ; } else if ( ! sq && c == '\"' && lastc != '\\' ) { dq = ! dq ; if ( s < 0 ) s = e ; } else if ( ! sq && ! dq ) { if ( Character . isWhitespace ( c ) ) { if ( s >= 0 ) l . add ( val . substring ( s , e ) ) ; s = - 1 ; } else if ( s < 0 && c != ' ' ) { s = e ; } } lastc = c ; } l . add ( val . substring ( s , e ) ) ; return ( String [ ] ) l . toArray ( new String [ 0 ] ) ; }


signature:
public class Parser { /** * so that the argument can be safely pushed */
private void rectify ( Element e ) throws SAXException { } }

implementation:
Element sp ; while ( true ) { for ( sp = theStack ; sp != null ; sp = sp . next ( ) ) { if ( sp . canContain ( e ) ) break ; } if ( sp != null ) break ; ElementType parentType = e . parent ( ) ; if ( parentType == null ) break ; Element parent = new Element ( parentType , defaultAttributes ) ; // parent . name ( ) ) ;
parent . setNext ( e ) ; e = parent ; } if ( sp == null ) return ; // don ' t know what to do
while ( theStack != sp ) { if ( theStack == null || theStack . next ( ) == null || theStack . next ( ) . next ( ) == null ) break ; restartablyPop ( ) ; } while ( e != null ) { Element nexte = e . next ( ) ; if ( ! e . name ( ) . equals ( "<pcdata>" ) ) push ( e ) ; e = nexte ; restart ( e ) ; } theNewElement = null ;


signature:
public class Parser { /** * canonicalize case . */
private String makeName ( char [ ] buff , int offset , int length ) { } }

implementation:
StringBuffer dst = new StringBuffer ( length + 2 ) ; boolean seenColon = false ; boolean start = true ; // String src = new String ( buff , offset , length ) ; / / DEBUG
for ( ; length -- > 0 ; offset ++ ) { char ch = buff [ offset ] ; if ( Character . isLetter ( ch ) || ch == '_' ) { start = false ; dst . append ( ch ) ; } else if ( Character . isDigit ( ch ) || ch == '-' || ch == '.' ) { if ( start ) dst . append ( '_' ) ; start = false ; dst . append ( ch ) ; } else if ( ch == ':' && ! seenColon ) { seenColon = true ; if ( start ) dst . append ( '_' ) ; start = true ; dst . append ( translateColons ? '_' : ch ) ; } } int dstLength = dst . length ( ) ; if ( dstLength == 0 || dst . charAt ( dstLength - 1 ) == ':' ) dst . append ( '_' ) ; return dst . toString ( ) . intern ( ) ;


signature:
public class RTManager { /** * Called to retrieve per - instance state before being killed so that the
 * state can be restored in the constructor .
 * @ param outState Bundle in which to place your saved state . */
public void onSaveInstanceState ( Bundle outState ) { } }

implementation: outState . putString ( "mToolbarVisibility" , mToolbarVisibility . name ( ) ) ; outState . putBoolean ( "mToolbarIsVisible" , mToolbarIsVisible ) ; outState . putInt ( "mActiveEditor" , mActiveEditor ) ; if ( mLinkSelection != null ) { outState . putSerializable ( "mLinkSelection" , mLinkSelection ) ; }


signature:
public class RTManager { /** * Perform any final cleanup before the component is destroyed .
 * @ param isSaved True if the text is saved , False if it ' s dismissed . This is
 * needed to decide whether media ( images etc . ) are to be
 * deleted . */
public void onDestroy ( boolean isSaved ) { } }

implementation: EventBus . getDefault ( ) . unregister ( this ) ; for ( RTEditText editor : mEditors . values ( ) ) { editor . unregister ( ) ; editor . onDestroy ( isSaved ) ; } mEditors . clear ( ) ; for ( RTToolbar toolbar : mToolbars . values ( ) ) { toolbar . removeToolbarListener ( ) ; } mToolbars . clear ( ) ; mRTApi = null ;


signature:
public class RTManager { /** * Register a rich text editor .
 * Before using the editor it needs to be registered to an RTManager .
 * Using means any calls to the editor ( setText will fail if the editor isn ' t registered ) !
 * MUST be called from the ui thread .
 * @ param editor The rich text editor to register . */
public void registerEditor ( RTEditText editor , boolean useRichTextEditing ) { } }

implementation: mEditors . put ( editor . getId ( ) , editor ) ; editor . register ( this , mRTApi ) ; editor . setRichTextEditing ( useRichTextEditing , false ) ; updateToolbarVisibility ( ) ;


signature:
public class RTManager { /** * Unregister a rich text editor .
 * This method may be called before the component is destroyed to stop any
 * interaction with the editor . Not doing so may result in ( asynchronous )
 * calls coming through when the Activity / Fragment is already stopping its
 * operation .
 * Must be called from the ui thread .
 * Important : calling this method is obsolete once the onDestroy ( boolean ) is
 * called
 * @ param editor The rich text editor to unregister . */
public void unregisterEditor ( RTEditText editor ) { } }

implementation: mEditors . remove ( editor . getId ( ) ) ; editor . unregister ( ) ; updateToolbarVisibility ( ) ;


signature:
public class RTManager { /** * Register a toolbar .
 * Only after doing that can it be used in conjunction with a rich text editor .
 * Must be called from the ui thread .
 * @ param toolbarContainer The ViewGroup containing the toolbar .
 * This container is used to show / hide the toolbar if needed ( e . g . if the RTEditText field loses / gains focus ) .
 * We can ' t use the toolbar itself because there could be multiple and they could be embedded in a complex layout hierarchy .
 * @ param toolbar The toolbar to register . */
public void registerToolbar ( ViewGroup toolbarContainer , RTToolbar toolbar ) { } }

implementation: mToolbars . put ( toolbar . getId ( ) , toolbar ) ; toolbar . setToolbarListener ( this ) ; toolbar . setToolbarContainer ( toolbarContainer ) ; updateToolbarVisibility ( ) ;


signature:
public class RTManager { /** * Unregister a toolbar .
 * This method may be called before the component is destroyed to
 * stop any interaction with the toolbar . Not doing so may result
 * in ( asynchronous ) calls coming through when the Activity / Fragment
 * is already stopping its operation .
 * Must be called from the ui thread .
 * Important : calling this method is obsolete once the
 * onDestroy ( boolean ) is called
 * @ param toolbar The toolbar to unregister . */
public void unregisterToolbar ( RTToolbar toolbar ) { } }

implementation: mToolbars . remove ( toolbar . getId ( ) ) ; toolbar . removeToolbarListener ( ) ; updateToolbarVisibility ( ) ;


signature:
public class RTManager { /** * * * * * * RTToolbarListener * * * * * */
@ Override /* @ inheritDoc */
public < V , C extends RTSpan < V > > void onEffectSelected ( Effect < V , C > effect , V value ) { } }

implementation: RTEditText editor = getActiveEditor ( ) ; if ( editor != null ) { editor . applyEffect ( effect , value ) ; }


signature:
public class RTManager { /** * / * called from onEventMainThread ( MediaEvent ) */
private void insertImage ( final RTEditText editor , final RTImage image ) { } }

implementation:
if ( image != null && editor != null ) { Selection selection = new Selection ( editor ) ; Editable str = editor . getText ( ) ; // Unicode Character ' OBJECT REPLACEMENT CHARACTER ' ( U + FFFC )
// see http : / / www . fileformat . info / info / unicode / char / fffc / index . htm
str . insert ( selection . start ( ) , "\uFFFC" ) ; try { // now add the actual image and inform the RTOperationManager about the operation
Spannable oldSpannable = editor . cloneSpannable ( ) ; ImageSpan imageSpan = new ImageSpan ( image , false ) ; str . setSpan ( imageSpan , selection . start ( ) , selection . end ( ) + 1 , Spanned . SPAN_EXCLUSIVE_EXCLUSIVE ) ; int selStartAfter = editor . getSelectionStart ( ) ; int selEndAfter = editor . getSelectionEnd ( ) ; editor . onAddMedia ( image ) ; Spannable newSpannable = editor . cloneSpannable ( ) ; mOPManager . executed ( editor , new RTOperationManager . TextChangeOperation ( oldSpannable , newSpannable , selection . start ( ) , selection . end ( ) , selStartAfter , selEndAfter ) ) ; } catch ( OutOfMemoryError e ) { str . delete ( selection . start ( ) , selection . end ( ) + 1 ) ; mRTApi . makeText ( R . string . rte_add_image_error , Toast . LENGTH_LONG ) . show ( ) ; } }


signature:
public class RTManager { /** * * * * * * RTEditTextListener * * * * * */
@ Override public void onRestoredInstanceState ( RTEditText editor ) { } }

implementation:
/* * We need to process pending sticky MediaEvents once the editors are registered with the
 * RTManager and are fully restored . */
MediaEvent event = EventBus . getDefault ( ) . getStickyEvent ( MediaEvent . class ) ; if ( event != null ) { onEventMainThread ( event ) ; }


signature:
public class RTManager { /** * Media file was picked - > process the result . */
@ Subscribe ( sticky = true , threadMode = ThreadMode . MAIN ) public void onEventMainThread ( MediaEvent event ) { } }

implementation: RTEditText editor = mEditors . get ( mActiveEditor ) ; RTMedia media = event . getMedia ( ) ; if ( editor != null && media instanceof RTImage ) { insertImage ( editor , ( RTImage ) media ) ; EventBus . getDefault ( ) . removeStickyEvent ( event ) ; mActiveEditor = Integer . MAX_VALUE ; }


signature:
public class RTManager { /** * LinkFragment has closed - > process the result . */
@ Subscribe ( threadMode = ThreadMode . MAIN ) public void onEventMainThread ( LinkEvent event ) { } }

implementation:
final String fragmentTag = event . getFragmentTag ( ) ; mRTApi . removeFragment ( fragmentTag ) ; if ( ! event . wasCancelled ( ) && ID_01_LINK_FRAGMENT . equals ( fragmentTag ) ) { RTEditText editor = getActiveEditor ( ) ; if ( editor != null ) { Link link = event . getLink ( ) ; String url = null ; if ( link != null && link . isValid ( ) ) { // the mLinkSelection . end ( ) < = editor . length ( ) check is necessary since
// the editor text can change when the link fragment is open
Selection selection = mLinkSelection != null && mLinkSelection . end ( ) <= editor . length ( ) ? mLinkSelection : new Selection ( editor ) ; String linkText = link . getLinkText ( ) ; // if no text is selected this inserts the entered link text
// if text is selected we replace it by the link text
Editable str = editor . getText ( ) ; str . replace ( selection . start ( ) , selection . end ( ) , linkText ) ; editor . setSelection ( selection . start ( ) , selection . start ( ) + linkText . length ( ) ) ; url = link . getUrl ( ) ; } editor . applyEffect ( Effects . LINK , url ) ; // if url = = null - > remove the link
} }


signature:
public class ImageViewTouchBase { /** * then translate it back into view ( i . e . eliminate black bars ) . */
protected void center ( boolean horizontal , boolean vertical ) { } }

implementation: if ( mBitmapDisplayed . getBitmap ( ) == null ) { return ; } Matrix m = getImageViewMatrix ( ) ; RectF rect = new RectF ( 0 , 0 , mBitmapDisplayed . getBitmap ( ) . getWidth ( ) , mBitmapDisplayed . getBitmap ( ) . getHeight ( ) ) ; m . mapRect ( rect ) ; float height = rect . height ( ) ; float width = rect . width ( ) ; float deltaX = 0 , deltaY = 0 ; if ( vertical ) { int viewHeight = getHeight ( ) ; if ( height < viewHeight ) { deltaY = ( viewHeight - height ) / 2 - rect . top ; } else if ( rect . top > 0 ) { deltaY = - rect . top ; } else if ( rect . bottom < viewHeight ) { deltaY = getHeight ( ) - rect . bottom ; } } if ( horizontal ) { int viewWidth = getWidth ( ) ; if ( width < viewWidth ) { deltaX = ( viewWidth - width ) / 2 - rect . left ; } else if ( rect . left > 0 ) { deltaX = - rect . left ; } else if ( rect . right < viewWidth ) { deltaX = viewWidth - rect . right ; } } postTranslate ( deltaX , deltaY ) ; setImageMatrix ( getImageViewMatrix ( ) ) ;


signature:
public class ImageViewTouchBase { /** * Setup the base matrix so that the image is centered and scaled properly . */
private void getProperBaseMatrix ( RotateBitmap bitmap , Matrix matrix ) { } }

implementation:
float viewWidth = getWidth ( ) ; float viewHeight = getHeight ( ) ; float w = bitmap . getWidth ( ) ; float h = bitmap . getHeight ( ) ; matrix . reset ( ) ; // We limit up - scaling to 2x otherwise the result may look bad if it ' s
// a small icon .
float widthScale = Math . min ( viewWidth / w , 2.0f ) ; float heightScale = Math . min ( viewHeight / h , 2.0f ) ; float scale = Math . min ( widthScale , heightScale ) ; matrix . postConcat ( bitmap . getRotateMatrix ( ) ) ; matrix . postScale ( scale , scale ) ; matrix . postTranslate ( ( viewWidth - w * scale ) / 2F , ( viewHeight - h * scale ) / 2F ) ;


signature:
public class ImageViewTouchBase { /** * rather than the current 1024x768 , this should be changed down to 200 % . */
protected float maxZoom ( ) { } }

implementation: if ( mBitmapDisplayed . getBitmap ( ) == null ) { return 1F ; } float fw = ( float ) mBitmapDisplayed . getWidth ( ) / ( float ) mThisWidth ; float fh = ( float ) mBitmapDisplayed . getHeight ( ) / ( float ) mThisHeight ; float max = Math . max ( fw , fh ) * 4 ; return max ;


signature:
public class Effect { /** * Check whether the effect exists in the currently selected text of the active RTEditText .
 * @ param editor The RTEditText we want the check .
 * @ return True if the effect exists in the current selection , False otherwise . */
final public boolean existsInSelection ( RTEditText editor ) { } }

implementation: Selection selection = getSelection ( editor ) ; List < RTSpan < V > > spans = getSpans ( editor . getText ( ) , selection , SpanCollectMode . SPAN_FLAGS ) ; return ! spans . isEmpty ( ) ;


signature:
public class Effect { /** * Returns the value ( s ) of this effect in the currently selected text of the active RTEditText .
 * @ return The returned list , must NEVER be null . */
final public List < V > valuesInSelection ( RTEditText editor ) { } }

implementation: List < V > result = new ArrayList < V > ( ) ; Selection selection = getSelection ( editor ) ; List < RTSpan < V > > spans = getSpans ( editor . getText ( ) , selection , SpanCollectMode . SPAN_FLAGS ) ; for ( RTSpan < V > span : spans ) { result . add ( span . getValue ( ) ) ; } return result ;


signature:
public class Effect { /** * Remove all effects of this type from the currently selected text of the active RTEditText .
 * If the selection is empty ( cursor ) , formatting for the whole text is removed . */
final public void clearFormattingInSelection ( RTEditText editor ) { } }

implementation:
Spannable text = editor . getText ( ) ; // if no selection - - > select the whole text
// otherwise use the getSelection method ( implented by sub classes )
Selection selection = new Selection ( editor ) ; selection = selection . isEmpty ( ) ? new Selection ( 0 , text . length ( ) ) : getSelection ( editor ) ; List < RTSpan < V > > spans = getSpans ( text , selection , SpanCollectMode . EXACT ) ; for ( Object span : spans ) { editor . getText ( ) . removeSpan ( span ) ; }


signature:
public class Effect { /** * Equivalent to the Spanned . getSpans ( int , int , Class < T > ) method .
 * Return the markup objects ( spans ) attached to the specified slice of a Spannable .
 * The type of the spans is defined in the SpanCollector .
 * @ param str The Spannable to search for spans .
 * @ param selection The selection within the Spannable to search for spans .
 * @ param mode details see SpanCollectMode .
 * @ return the list of spans in this Spannable / Selection , never Null */
final public List < RTSpan < V > > getSpans ( Spannable str , Selection selection , SpanCollectMode mode ) { } }

implementation:
if ( mSpanCollector == null ) { // lazy initialize the SpanCollector
Type [ ] types = ( ( ParameterizedType ) getClass ( ) . getGenericSuperclass ( ) ) . getActualTypeArguments ( ) ; Class < ? extends RTSpan < V > > spanClazz = ( Class < ? extends RTSpan < V > > ) types [ types . length - 1 ] ; mSpanCollector = newSpanCollector ( spanClazz ) ; } return mSpanCollector . getSpans ( str , selection , mode ) ;


signature:
public class ParagraphEffect { /** * Make sure applyToSelection works on whole paragraphs and call
 * Effects . cleanupParagraphs ( RTEditText ) afterwards . */
@ Override public final void applyToSelection ( RTEditText editor , V value ) { } }

implementation: Selection selection = getSelection ( editor ) ; applyToSelection ( editor , selection , value ) ; Effects . cleanupParagraphs ( editor , this ) ;


signature:
public class ParagraphEffect { /** * Find spans within that paragraph and add them to the ParagraphSpanProcessor to be removed
 * once the ParagraphSpanProcessor processes its spans . */
protected void findSpans2Remove ( Spannable str , Paragraph paragraph , ParagraphSpanProcessor < V > spanProcessor ) { } }

implementation: List < RTSpan < V > > spans = getSpans ( str , paragraph , SpanCollectMode . EXACT ) ; spanProcessor . removeSpans ( spans , paragraph ) ;


signature:
public class Helper { /** * This method encodes the query part of an url
 * @ param url an url ( e . g . http : / / www . 1gravity . com ? query = üö )
 * @ return The url with an encoded query , e . g . http : / / www . 1gravity . com ? query % 3D % C3 % BC % C3 % B6 */
public static String encodeUrl ( String url ) { } }

implementation: Uri uri = Uri . parse ( url ) ; try { Map < String , List < String > > splitQuery = splitQuery ( uri ) ; StringBuilder encodedQuery = new StringBuilder ( ) ; for ( String key : splitQuery . keySet ( ) ) { for ( String value : splitQuery . get ( key ) ) { if ( encodedQuery . length ( ) > 0 ) { encodedQuery . append ( "&" ) ; } encodedQuery . append ( key + "=" + URLEncoder . encode ( value , "UTF-8" ) ) ; } } String queryString = encodedQuery != null && encodedQuery . length ( ) > 0 ? "?" + encodedQuery : "" ; URI baseUri = new URI ( uri . getScheme ( ) , uri . getAuthority ( ) , uri . getPath ( ) , null , uri . getFragment ( ) ) ; return baseUri + queryString ; } catch ( UnsupportedEncodingException ignore ) { } catch ( URISyntaxException ignore ) { } return uri . toString ( ) ;


signature:
public class Helper { /** * This method decodes an url with encoded query string
 * @ param url an url with encoded query string ( e . g . http : / / www . 1gravity . com ? query % C3 % BC % C3 % B6)
 * @ return The decoded url , e . g . http : / / www . 1gravity . com ? query = üö */
public static String decodeQuery ( String url ) { } }

implementation: try { return URLDecoder . decode ( url , "UTF-8" ) ; } catch ( UnsupportedEncodingException ignore ) { } return url ;


signature:
public class Helper { /** * This method determines if the direction of a substring is right - to - left .
 * If the string is empty that determination is based on the default system language
 * Locale . getDefault ( ) .
 * The method can handle invalid substring definitions ( start > end etc . ) , in which case the
 * method returns False .
 * @ return True if the text direction is right - to - left , false otherwise . */
public static boolean isRTL ( CharSequence s , int start , int end ) { } }

implementation:
if ( s == null || s . length ( ) == 0 ) { // empty string - - > determine the direction from the default language
return isRTL ( Locale . getDefault ( ) ) ; } if ( start == end ) { // if no character is selected we need to expand the selection
start = Math . max ( 0 , -- start ) ; if ( start == end ) { end = Math . min ( s . length ( ) , ++ end ) ; } } try { Bidi bidi = new Bidi ( s . subSequence ( start , end ) . toString ( ) , Bidi . DIRECTION_DEFAULT_LEFT_TO_RIGHT ) ; return ! bidi . baseIsLeftToRight ( ) ; } catch ( IndexOutOfBoundsException e ) { return false ; }


signature:
public class FileHelper { /** * Tries to open a known file browsers to pick a directory .
 * @ return True if a filebrowser has been found ( the result will be in the onActivityResult ) , False otherwise */
public static boolean pickDirectory ( Activity activity , File startPath , int requestCode ) { } }

implementation: PackageManager packageMgr = activity . getPackageManager ( ) ; for ( String [ ] intent : PICK_DIRECTORY_INTENTS ) { String intentAction = intent [ 0 ] ; String uriPrefix = intent [ 1 ] ; Intent startIntent = new Intent ( intentAction ) . putExtra ( "org.openintents.extra.TITLE" , activity . getString ( R . string . save_as ) ) . setData ( Uri . parse ( uriPrefix + startPath . getPath ( ) ) ) ; try { if ( startIntent . resolveActivity ( packageMgr ) != null ) { activity . startActivityForResult ( startIntent , requestCode ) ; return true ; } } catch ( ActivityNotFoundException e ) { showNoFilePickerError ( activity , e ) ; } } return false ;


signature:
public class CropImageActivity { /** * * * * * * Lifecycle Methods * * * * * */
@ Override protected void onCreate ( Bundle savedInstanceState ) { } }

implementation: super . onCreate ( savedInstanceState ) ; setContentView ( R . layout . rte_crop_image ) ; mImageView = ( CropImageView ) findViewById ( R . id . image ) ; Intent intent = getIntent ( ) ; Bundle extras = intent . getExtras ( ) ; if ( extras != null ) { if ( extras . getString ( CIRCLE_CROP ) != null ) { mImageView . setLayerType ( View . LAYER_TYPE_SOFTWARE , null ) ; mCircleCrop = true ; mAspectX = 1 ; mAspectY = 1 ; } mImageSource = extras . getString ( IMAGE_SOURCE_FILE ) ; mBitmap = getBitmap ( mImageSource ) ; mImageDest = extras . getString ( IMAGE_DESTINATION_FILE ) ; if ( mImageDest == null ) { mImageDest = mImageSource ; } mSaveUri = Uri . fromFile ( new File ( mImageDest ) ) ; if ( extras . containsKey ( ASPECT_X ) && extras . get ( ASPECT_X ) instanceof Integer ) { mAspectX = extras . getInt ( ASPECT_X ) ; } else { throw new IllegalArgumentException ( "aspect_x must be integer" ) ; } if ( extras . containsKey ( ASPECT_Y ) && extras . get ( ASPECT_Y ) instanceof Integer ) { mAspectY = extras . getInt ( ASPECT_Y ) ; } else { throw new IllegalArgumentException ( "aspect_y must be integer" ) ; } mOutputX = extras . getInt ( OUTPUT_X ) ; mOutputY = extras . getInt ( OUTPUT_Y ) ; mScale = extras . getBoolean ( SCALE , true ) ; mScaleUp = extras . getBoolean ( SCALE_UP_IF_NEEDED , true ) ; } if ( mBitmap == null ) { finish ( ) ; return ; } startFaceDetection ( ) ;


signature:
public class CropImageActivity { /** * * * * * * Private Methods * * * * * */
private Bitmap getBitmap ( String path ) { } }

implementation:
Uri uri = MediaUtils . createFileUri ( path ) ; InputStream in = null ; try { in = getContentResolver ( ) . openInputStream ( uri ) ; // Decode image size
BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inJustDecodeBounds = true ; BitmapFactory . decodeStream ( in , null , options ) ; Helper . closeQuietly ( in ) ; // compute scale factor to ensure that the image is smaller than
// IMAGE _ MAX _ SIZE
float maxSize = Math . max ( options . outWidth , options . outHeight ) ; float scale = maxSize > IMAGE_MAX_SIZE ? maxSize / IMAGE_MAX_SIZE : 1.0f ; while ( ( maxSize / scale ) > 8 ) { try { return getBitmap ( in , uri , scale ) ; } catch ( Throwable e ) { Log . w ( getClass ( ) . getSimpleName ( ) , "bitmap could not be created (probably out of memory), decreasing size and retrying" ) ; scale *= 2f ; } } } catch ( IOException e ) { Log . e ( getClass ( ) . getSimpleName ( ) , "file " + path + " not found" ) ; } catch ( Exception e ) { Log . e ( getClass ( ) . getSimpleName ( ) , "error while opening image" , e ) ; } finally { Helper . closeQuietly ( in ) ; } return null ;


signature:
public class CropImageActivity { /** * Compute the sample size as a function of minSideLength and
 * maxNumOfPixels . minSideLength is used to specify that minimal width or
 * height of a bitmap . maxNumOfPixels is used to specify the maximal size in
 * pixels that are tolerable in terms of memory usage .
 * The function returns a sample size based on the constraints . Both size
 * and minSideLength can be passed in as IImage . UNCONSTRAINED , which
 * indicates no care of the corresponding constraint . The functions prefers
 * returning a sample size that generates a smaller bitmap , unless
 * minSideLength = IImage . UNCONSTRAINED . */
private Bitmap transform ( Matrix scaler , Bitmap source , int targetWidth , int targetHeight , boolean scaleUp ) { } }

implementation:
int deltaX = source . getWidth ( ) - targetWidth ; int deltaY = source . getHeight ( ) - targetHeight ; if ( ! scaleUp && ( deltaX < 0 || deltaY < 0 ) ) { /* * In this case the bitmap is smaller , at least in one dimension ,
 * than the target . Transform it by placing as much of the image as
 * possible into the target and leaving the top / bottom or left / right
 * ( or both ) black . */
Bitmap b2 = Bitmap . createBitmap ( targetWidth , targetHeight , Bitmap . Config . ARGB_8888 ) ; Canvas c = new Canvas ( b2 ) ; int deltaXHalf = Math . max ( 0 , deltaX / 2 ) ; int deltaYHalf = Math . max ( 0 , deltaY / 2 ) ; Rect src = new Rect ( deltaXHalf , deltaYHalf , deltaXHalf + Math . min ( targetWidth , source . getWidth ( ) ) , deltaYHalf + Math . min ( targetHeight , source . getHeight ( ) ) ) ; int dstX = ( targetWidth - src . width ( ) ) / 2 ; int dstY = ( targetHeight - src . height ( ) ) / 2 ; Rect dst = new Rect ( dstX , dstY , targetWidth - dstX , targetHeight - dstY ) ; c . drawBitmap ( source , src , dst , null ) ; return b2 ; } float bitmapWidthF = source . getWidth ( ) ; float bitmapHeightF = source . getHeight ( ) ; float bitmapAspect = bitmapWidthF / bitmapHeightF ; float viewAspect = ( float ) targetWidth / targetHeight ; if ( bitmapAspect > viewAspect ) { float scale = targetHeight / bitmapHeightF ; if ( scale < .9F || scale > 1F ) { scaler . setScale ( scale , scale ) ; } else { scaler = null ; } } else { float scale = targetWidth / bitmapWidthF ; if ( scale < .9F || scale > 1F ) { scaler . setScale ( scale , scale ) ; } else { scaler = null ; } } Bitmap b1 ; if ( scaler != null ) { // this is used for minithumb and crop , so we want to mFilter here .
b1 = Bitmap . createBitmap ( source , 0 , 0 , source . getWidth ( ) , source . getHeight ( ) , scaler , true ) ; } else { b1 = source ; } int dx1 = Math . max ( 0 , b1 . getWidth ( ) - targetWidth ) ; int dy1 = Math . max ( 0 , b1 . getHeight ( ) - targetHeight ) ; Bitmap b2 = Bitmap . createBitmap ( b1 , dx1 / 2 , dy1 / 2 , targetWidth , targetHeight ) ; if ( b1 != source ) { b1 . recycle ( ) ; } return b2 ;


signature:
public class CropImageActivity { /** * Thong added for rotate */
private Bitmap rotateImage ( Bitmap src , float degree ) { } }

implementation:
// create new matrix
Matrix matrix = new Matrix ( ) ; // setup rotation degree
matrix . postRotate ( degree ) ; Bitmap bmp = Bitmap . createBitmap ( src , 0 , 0 , src . getWidth ( ) , src . getHeight ( ) , matrix , true ) ; return bmp ;


signature:
public class MediaChooserActivity { /** * * * * * * Lifecycle Methods * * * * * */
@ Override protected void onCreate ( Bundle savedInstanceState ) { } }

implementation:
super . onCreate ( savedInstanceState ) ; Bundle extras = getIntent ( ) . getExtras ( ) ; if ( extras != null ) { String mediaAction = extras . getString ( EXTRA_MEDIA_ACTION ) ; mMediaAction = mediaAction == null ? null : MediaAction . valueOf ( mediaAction ) ; mMediaFactory = ( RTMediaFactory < RTImage , RTAudio , RTVideo > ) extras . getSerializable ( EXTRA_MEDIA_FACTORY ) ; } if ( mMediaAction != null ) { // retrieve parameters
if ( savedInstanceState != null ) { mSelectedMedia = ( RTMedia ) savedInstanceState . getSerializable ( "mSelectedMedia" ) ; } switch ( mMediaAction ) { case PICK_PICTURE : case CAPTURE_PICTURE : mMediaChooserMgr = new ImageChooserManager ( this , mMediaAction , mMediaFactory , this , savedInstanceState ) ; break ; case PICK_VIDEO : case CAPTURE_VIDEO : mMediaChooserMgr = new VideoChooserManager ( this , mMediaAction , mMediaFactory , this , savedInstanceState ) ; break ; case PICK_AUDIO : case CAPTURE_AUDIO : mMediaChooserMgr = new AudioChooserManager ( this , mMediaAction , mMediaFactory , this , savedInstanceState ) ; break ; } if ( mMediaChooserMgr == null ) { finish ( ) ; } else if ( ! isWorkInProgress ( ) ) { setWorkInProgress ( true ) ; if ( ! mMediaChooserMgr . chooseMedia ( ) ) { finish ( ) ; } } } else { finish ( ) ; }


signature:
public class MediaChooserActivity { /** * * * * * * Listener Methods * * * * * */
@ Override public void onActivityResult ( int requestCode , int resultCode , Intent data ) { } }

implementation:
if ( resultCode == Activity . RESULT_OK ) { if ( requestCode == MediaAction . PICK_PICTURE . requestCode ( ) && data != null ) { mMediaChooserMgr . processMedia ( MediaAction . PICK_PICTURE , data ) ; } else if ( requestCode == MediaAction . CAPTURE_PICTURE . requestCode ( ) ) { mMediaChooserMgr . processMedia ( MediaAction . CAPTURE_PICTURE , data ) ; // data may be null here
} else if ( requestCode == Constants . CROP_IMAGE ) { String path = data . getStringExtra ( CropImageActivity . IMAGE_DESTINATION_FILE ) ; if ( path != null && mSelectedMedia instanceof RTImage ) { EventBus . getDefault ( ) . postSticky ( new MediaEvent ( mSelectedMedia ) ) ; finish ( ) ; } } } else { setResult ( RESULT_CANCELED ) ; finish ( ) ; }


signature:
public class HTMLWriter { /** * Set a new output destination for the document .
 * @ param writer The output destination , or null to use standard output .
 * @ return The current output writer .
 * @ see # flush */
public void setOutput ( Writer writer ) { } }

implementation: if ( writer == null ) { output = new OutputStreamWriter ( System . out ) ; } else { output = writer ; }


signature:
public class HTMLWriter { /** * Force a Namespace declaration with a preferred prefix .
 * This is a convenience method that invokes { @ link # setPrefix setPrefix }
 * then { @ link # forceNSDecl ( java . lang . String ) forceNSDecl } .
 * @ param uri The Namespace URI to declare on the root element .
 * @ param prefix The preferred prefix for the Namespace , or " " for the default
 * Namespace .
 * @ see # setPrefix
 * @ see # forceNSDecl ( java . lang . String ) */
public void forceNSDecl ( String uri , String prefix ) { } }

implementation: setPrefix ( uri , prefix ) ; forceNSDecl ( uri ) ;


signature:
public class HTMLWriter { /** * Write the XML declaration at the beginning of the document .
 * Pass the event on down the filter chain for further processing .
 * @ throws org . xml . sax . SAXException If there is an error writing the XML declaration , or if a
 * handler further down the filter chain raises an exception .
 * @ see org . xml . sax . ContentHandler # startDocument */
public void startDocument ( ) throws SAXException { } }

implementation: writeText4Links ( ) ; reset ( ) ; if ( ! ( "yes" . equals ( outputProperties . getProperty ( OMIT_XML_DECLARATION , "no" ) ) ) ) { write ( "<?xml" ) ; if ( version == null ) { write ( " version=\"1.0\"" ) ; } else { write ( " version=\"" ) ; write ( version ) ; write ( "\"" ) ; } if ( outputEncoding != null && outputEncoding != "" ) { write ( " encoding=\"" ) ; write ( outputEncoding ) ; write ( "\"" ) ; } if ( standalone == null ) { write ( " standalone=\"yes\"?>\n" ) ; } else { write ( " standalone=\"" ) ; write ( standalone ) ; write ( "\"" ) ; } } super . startDocument ( ) ;


signature:
public class HTMLWriter { /** * Write a newline at the end of the document .
 * Pass the event on down the filter chain for further processing .
 * @ throws org . xml . sax . SAXException If there is an error writing the newline , or if a handler
 * further down the filter chain raises an exception .
 * @ see org . xml . sax . ContentHandler # endDocument */
public void endDocument ( ) throws SAXException { } }

implementation: writeText4Links ( ) ; write ( '\n' ) ; super . endDocument ( ) ; try { flush ( ) ; } catch ( IOException e ) { throw new SAXException ( e ) ; }


signature:
public class HTMLWriter { /** * Write a start tag .
 * Pass the event on down the filter chain for further processing .
 * @ param uri The Namespace URI , or the empty string if none is available .
 * @ param localName The element ' s local ( unprefixed ) name ( required ) .
 * @ param qName The element ' s qualified ( prefixed ) name , or the empty string
 * is none is available . This method will use the qName as a
 * template for generating a prefix if necessary , but it is not
 * guaranteed to use the same qName .
 * @ param atts The element ' s attribute list ( must not be null ) .
 * @ throws org . xml . sax . SAXException If there is an error writing the start tag , or if a
 * handler further down the filter chain raises an exception .
 * @ see org . xml . sax . ContentHandler # startElement */
@ Override public void startElement ( String uri , String localName , String qName , Attributes atts ) throws SAXException { } }

implementation: writeText4Links ( ) ; if ( ! ignoreElement ( uri , localName , qName , atts ) ) { elementLevel ++ ; nsSupport . pushContext ( ) ; if ( forceDTD && ! hasOutputDTD ) { startDTD ( localName == null ? qName : localName , "" , "" ) ; } write ( '<' ) ; writeName ( uri , localName , qName , true ) ; writeAttributes ( atts ) ; if ( elementLevel == 1 ) { forceNSDecls ( ) ; } if ( ! mOmitXHTMLNamespace || ! "html" . equalsIgnoreCase ( localName ) ) { writeNSDecls ( ) ; } write ( '>' ) ; if ( htmlMode && ( qName . equals ( "script" ) || qName . equals ( "style" ) ) ) { cdataElement = true ; } if ( htmlMode && localName . equals ( "a" ) ) { mIgnoreChars = true ; } super . startElement ( uri , localName , qName , atts ) ; }


signature:
public class HTMLWriter { /** * Write an end tag .
 * Pass the event on down the filter chain for further processing .
 * @ param uri The Namespace URI , or the empty string if none is available .
 * @ param localName The element ' s local ( unprefixed ) name ( required ) .
 * @ param qName The element ' s qualified ( prefixed ) name , or the empty string
 * is none is available . This method will use the qName as a
 * template for generating a prefix if necessary , but it is not
 * guaranteed to use the same qName .
 * @ throws org . xml . sax . SAXException If there is an error writing the end tag , or if a handler
 * further down the filter chain raises an exception .
 * @ see org . xml . sax . ContentHandler # endElement */
@ Override public void endElement ( String uri , String localName , String qName ) throws SAXException { } }

implementation: writeText4Links ( ) ; if ( ! mIgnoredTags . isEmpty ( ) && mIgnoredTags . peek ( ) . equalsIgnoreCase ( qName ) ) { mIgnoredTags . pop ( ) ; } else { if ( ! ( htmlMode && ( uri . equals ( "http://www.w3.org/1999/xhtml" ) || uri . equals ( "" ) ) && ( qName . equals ( "area" ) || qName . equals ( "base" ) || qName . equals ( "basefont" ) || qName . equals ( "br" ) || qName . equals ( "col" ) || qName . equals ( "frame" ) || qName . equals ( "hr" ) || qName . equals ( "img" ) || qName . equals ( "input" ) || qName . equals ( "isindex" ) || qName . equals ( "link" ) || qName . equals ( "meta" ) || qName . equals ( "param" ) ) ) ) { write ( "</" ) ; writeName ( uri , localName , qName , true ) ; write ( '>' ) ; } if ( elementLevel == 1 ) { write ( '\n' ) ; } if ( htmlMode && localName . equals ( "a" ) ) { mIgnoreChars = false ; } cdataElement = false ; super . endElement ( uri , localName , qName ) ; nsSupport . popContext ( ) ; elementLevel -- ; }


signature:
public class HTMLWriter { /** * Write character data .
 * Pass the event on down the filter chain for further processing .
 * @ param ch The array of characters to write .
 * @ param start The starting position in the array .
 * @ param length The number of characters to write .
 * @ throws org . xml . sax . SAXException If there is an error writing the characters , or if a
 * handler further down the filter chain raises an exception .
 * @ see org . xml . sax . ContentHandler # characters */
@ Override public void characters ( char ch [ ] , int start , int len ) throws SAXException { } }

implementation: if ( ! cdataElement ) { if ( mIgnoreChars ) { writeText4Links ( ) ; writeEscUTF16 ( new String ( ch ) , start , len , false ) ; } else { collectText4Links ( ch , start , len ) ; } } else { writeText4Links ( ) ; for ( int i = start ; i < start + len ; i ++ ) { write ( ch [ i ] ) ; } } super . characters ( ch , start , len ) ;


signature:
public class HTMLWriter { /** * Write ignorable whitespace .
 * Pass the event on down the filter chain for further processing .
 * @ param ch The array of characters to write .
 * @ param start The starting position in the array .
 * @ param length The number of characters to write .
 * @ throws org . xml . sax . SAXException If there is an error writing the whitespace , or if a
 * handler further down the filter chain raises an exception .
 * @ see org . xml . sax . ContentHandler # ignorableWhitespace */
@ Override public void ignorableWhitespace ( char ch [ ] , int start , int length ) throws SAXException { } }

implementation: writeText4Links ( ) ; writeEscUTF16 ( new String ( ch ) , start , length , false ) ; super . ignorableWhitespace ( ch , start , length ) ;


signature:
public class HTMLWriter { /** * Write a processing instruction .
 * Pass the event on down the filter chain for further processing .
 * @ param target The PI target .
 * @ param data The PI data .
 * @ throws org . xml . sax . SAXException If there is an error writing the PI , or if a handler
 * further down the filter chain raises an exception .
 * @ see org . xml . sax . ContentHandler # processingInstruction */
@ Override public void processingInstruction ( String target , String data ) throws SAXException { } }

implementation: writeText4Links ( ) ; write ( "<?" ) ; write ( target ) ; write ( ' ' ) ; write ( data ) ; write ( "?>" ) ; if ( elementLevel < 1 ) { write ( '\n' ) ; } super . processingInstruction ( target , data ) ;


signature:
public class HTMLWriter { /** * Force all Namespaces to be declared .
 * This method is used on the root element to ensure that the predeclared
 * Namespaces all appear . */
private void forceNSDecls ( ) { } }

implementation: Enumeration < String > prefixes = forcedDeclTable . keys ( ) ; while ( prefixes . hasMoreElements ( ) ) { String prefix = ( String ) prefixes . nextElement ( ) ; doPrefix ( prefix , null , true ) ; }


signature:
public class HTMLWriter { /** * Determine the prefix for an element or attribute name .
 * @ param uri The Namespace URI .
 * @ param qName The qualified name ( optional ) ; this will be used to indicate
 * the preferred prefix if none is currently bound .
 * @ param isElement true if this is an element name , false if it is an attribute
 * name ( which cannot use the default Namespace ) . */
private String doPrefix ( String uri , String qName , boolean isElement ) { } }

implementation: String defaultNS = nsSupport . getURI ( "" ) ; if ( "" . equals ( uri ) ) { if ( isElement && defaultNS != null ) nsSupport . declarePrefix ( "" , "" ) ; return null ; } String prefix ; if ( isElement && defaultNS != null && uri . equals ( defaultNS ) ) { prefix = "" ; } else { prefix = nsSupport . getPrefix ( uri ) ; } if ( prefix != null ) { return prefix ; } prefix = ( String ) doneDeclTable . get ( uri ) ; if ( prefix != null && ( ( ! isElement || defaultNS != null ) && "" . equals ( prefix ) || nsSupport . getURI ( prefix ) != null ) ) { prefix = null ; } if ( prefix == null ) { prefix = ( String ) prefixTable . get ( uri ) ; if ( prefix != null && ( ( ! isElement || defaultNS != null ) && "" . equals ( prefix ) || nsSupport . getURI ( prefix ) != null ) ) { prefix = null ; } } if ( prefix == null && qName != null && ! "" . equals ( qName ) ) { int i = qName . indexOf ( ':' ) ; if ( i == - 1 ) { if ( isElement && defaultNS == null ) { prefix = "" ; } } else { prefix = qName . substring ( 0 , i ) ; } } for ( ; prefix == null || nsSupport . getURI ( prefix ) != null ; prefix = "__NS" + ++ prefixCounter ) ; nsSupport . declarePrefix ( prefix , uri ) ; doneDeclTable . put ( uri , prefix ) ; return prefix ;


signature:
public class HTMLWriter { /** * Write a raw character .
 * @ param c The character to write .
 * @ throws org . xml . sax . SAXException If there is an error writing the character , this method
 * will throw an IOException wrapped in a SAXException . */
private void write ( char c ) throws SAXException { } }

implementation: try { output . write ( c ) ; } catch ( IOException e ) { throw new SAXException ( e ) ; }


signature:
public class HTMLWriter { /** * Write a raw string .
 * @ param s
 * @ throws org . xml . sax . SAXException If there is an error writing the string , this method will
 * throw an IOException wrapped in a SAXException */
private void write ( String s ) throws SAXException { } }

implementation: try { output . write ( s ) ; } catch ( IOException e ) { throw new SAXException ( e ) ; }