idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
155,900 | public static LargeBlockTask getStoreTask ( BlockId blockId , ByteBuffer block ) { return new LargeBlockTask ( ) { @ Override public LargeBlockResponse call ( ) throws Exception { Exception theException = null ; try { LargeBlockManager . getInstance ( ) . storeBlock ( blockId , block ) ; } catch ( Exception exc ) { the... | Get a new store task | 93 | 5 |
155,901 | public static LargeBlockTask getReleaseTask ( BlockId blockId ) { return new LargeBlockTask ( ) { @ Override public LargeBlockResponse call ( ) throws Exception { Exception theException = null ; try { LargeBlockManager . getInstance ( ) . releaseBlock ( blockId ) ; } catch ( Exception exc ) { theException = exc ; } ret... | Get a new release task | 87 | 5 |
155,902 | public static LargeBlockTask getLoadTask ( BlockId blockId , ByteBuffer block ) { return new LargeBlockTask ( ) { @ Override public LargeBlockResponse call ( ) throws Exception { Exception theException = null ; try { LargeBlockManager . getInstance ( ) . loadBlock ( blockId , block ) ; } catch ( Exception exc ) { theEx... | Get a new load task | 93 | 5 |
155,903 | public static < T , U > Pair < T , U > of ( T x , U y ) { return new Pair < T , U > ( x , y ) ; } | Convenience class method for constructing pairs using Java s generic type inference . | 37 | 15 |
155,904 | public static Routine newRoutine ( Method method ) { Routine routine = new Routine ( SchemaObject . FUNCTION ) ; int offset = 0 ; Class [ ] params = method . getParameterTypes ( ) ; String className = method . getDeclaringClass ( ) . getName ( ) ; StringBuffer sb = new StringBuffer ( ) ; sb . append ( "CLASSPATH:" ) ; ... | Returns a new function Routine object based solely on a Java Method object . | 418 | 15 |
155,905 | public ByteBuffer saveToBuffer ( InstanceId instId ) throws IOException { if ( instId == null ) { throw new IOException ( "Null instance ID." ) ; } if ( m_serData == null ) { throw new IOException ( "Uninitialized hashinator snapshot data." ) ; } // Assume config data is the last field. ByteBuffer buf = ByteBuffer . al... | Save to output buffer including header and config data . | 296 | 10 |
155,906 | public InstanceId restoreFromBuffer ( ByteBuffer buf ) throws IOException { buf . rewind ( ) ; // Assumes config data is the last field. int dataSize = buf . remaining ( ) - OFFSET_DATA ; if ( dataSize <= 0 ) { throw new IOException ( "Hashinator snapshot data is too small." ) ; } // Get the CRC, zero out its buffer fi... | Restore and check hashinator config data . | 315 | 9 |
155,907 | public void restoreFromFile ( File file ) throws IOException { byte [ ] rawData = new byte [ ( int ) file . length ( ) ] ; ByteBuffer bufData = null ; FileInputStream fis = null ; DataInputStream dis = null ; try { fis = new FileInputStream ( file ) ; dis = new DataInputStream ( fis ) ; dis . readFully ( rawData ) ; bu... | Restore and check hashinator config data from a file . | 143 | 12 |
155,908 | public static File createFileForSchema ( String ddlText ) throws IOException { File temp = File . createTempFile ( "literalschema" , ".sql" ) ; temp . deleteOnExit ( ) ; FileWriter out = new FileWriter ( temp ) ; out . write ( ddlText ) ; out . close ( ) ; return temp ; } | Creates a temporary file for the supplied schema text . The file is not left open and will be deleted upon process exit . | 77 | 25 |
155,909 | public void addLiteralSchema ( String ddlText ) throws IOException { File temp = createFileForSchema ( ddlText ) ; addSchema ( URLEncoder . encode ( temp . getAbsolutePath ( ) , "UTF-8" ) ) ; } | Adds the supplied schema by creating a temp file for it . | 61 | 12 |
155,910 | public void addStmtProcedure ( String name , String sql , String partitionInfoString ) { addProcedures ( new ProcedureInfo ( new String [ 0 ] , name , sql , ProcedurePartitionData . fromPartitionInfoString ( partitionInfoString ) ) ) ; } | compatible with old deprecated syntax for test ONLY | 59 | 8 |
155,911 | public static byte [ ] hexStringToByteArray ( String s ) throws IOException { int l = s . length ( ) ; byte [ ] data = new byte [ l / 2 + ( l % 2 ) ] ; int n , b = 0 ; boolean high = true ; int i = 0 ; for ( int j = 0 ; j < l ; j ++ ) { char c = s . charAt ( j ) ; if ( c == ' ' ) { continue ; } n = getNibble ( c ) ; if... | Converts a hexadecimal string into a byte array | 254 | 12 |
155,912 | public static BitMap sqlBitStringToBitMap ( String s ) throws IOException { int l = s . length ( ) ; int n ; int bitIndex = 0 ; BitMap map = new BitMap ( l ) ; for ( int j = 0 ; j < l ; j ++ ) { char c = s . charAt ( j ) ; if ( c == ' ' ) { continue ; } n = getNibble ( c ) ; if ( n != 0 && n != 1 ) { throw new IOExcept... | Compacts a bit string into a BitMap | 162 | 9 |
155,913 | public static String byteArrayToBitString ( byte [ ] bytes , int bitCount ) { char [ ] s = new char [ bitCount ] ; for ( int j = 0 ; j < bitCount ; j ++ ) { byte b = bytes [ j / 8 ] ; s [ j ] = BitMap . isSet ( b , j % 8 ) ? ' ' : ' ' ; } return new String ( s ) ; } | Converts a byte array into a bit string | 90 | 9 |
155,914 | public static String byteArrayToSQLBitString ( byte [ ] bytes , int bitCount ) { char [ ] s = new char [ bitCount + 3 ] ; s [ 0 ] = ' ' ; s [ 1 ] = ' ' ; int pos = 2 ; for ( int j = 0 ; j < bitCount ; j ++ ) { byte b = bytes [ j / 8 ] ; s [ pos ++ ] = BitMap . isSet ( b , j % 8 ) ? ' ' : ' ' ; } s [ pos ] = ' ' ; retur... | Converts a byte array into an SQL binary string | 123 | 10 |
155,915 | public static void writeHexBytes ( byte [ ] o , int from , byte [ ] b ) { int len = b . length ; for ( int i = 0 ; i < len ; i ++ ) { int c = ( ( int ) b [ i ] ) & 0xff ; o [ from ++ ] = HEXBYTES [ c >> 4 & 0xf ] ; o [ from ++ ] = HEXBYTES [ c & 0xf ] ; } } | Converts a byte array into hexadecimal characters which are written as ASCII to the given output stream . | 100 | 22 |
155,916 | public static int stringToUTFBytes ( String str , HsqlByteArrayOutputStream out ) { int strlen = str . length ( ) ; int c , count = 0 ; if ( out . count + strlen + 8 > out . buffer . length ) { out . ensureRoom ( strlen + 8 ) ; } char [ ] arr = str . toCharArray ( ) ; for ( int i = 0 ; i < strlen ; i ++ ) { c = arr [ i... | Writes a string to the specified DataOutput using UTF - 8 encoding in a machine - independent manner . | 357 | 21 |
155,917 | public static String inputStreamToString ( InputStream x , String encoding ) throws IOException { InputStreamReader in = new InputStreamReader ( x , encoding ) ; StringWriter writer = new StringWriter ( ) ; int blocksize = 8 * 1024 ; char [ ] buffer = new char [ blocksize ] ; for ( ; ; ) { int read = in . read ( buffer... | Using a Reader and a Writer returns a String from an InputStream . | 118 | 14 |
155,918 | static int count ( final String s , final char c ) { int pos = 0 ; int count = 0 ; if ( s != null ) { while ( ( pos = s . indexOf ( c , pos ) ) > - 1 ) { count ++ ; pos ++ ; } } return count ; } | Counts Character c in String s | 62 | 7 |
155,919 | public static void registerLog4jMBeans ( ) throws JMException { if ( Boolean . getBoolean ( "zookeeper.jmx.log4j.disable" ) == true ) { return ; } MBeanServer mbs = ManagementFactory . getPlatformMBeanServer ( ) ; // Create and Register the top level Log4J MBean HierarchyDynamicMBean hdm = new HierarchyDynamicMBean ( )... | Register the log4j JMX mbeans . Set environment variable zookeeper . jmx . log4j . disable to true to disable registration . | 289 | 31 |
155,920 | public void create ( final String path , byte data [ ] , List < ACL > acl , CreateMode createMode , StringCallback cb , Object ctx ) { verbotenThreadCheck ( ) ; final String clientPath = path ; PathUtils . validatePath ( clientPath , createMode . isSequential ( ) ) ; final String serverPath = prependChroot ( clientPath... | The Asynchronous version of create . The request doesn t actually until the asynchronous callback is called . | 213 | 19 |
155,921 | public void delete ( final String path , int version , VoidCallback cb , Object ctx ) { verbotenThreadCheck ( ) ; final String clientPath = path ; PathUtils . validatePath ( clientPath ) ; final String serverPath ; // maintain semantics even in chroot case // specifically - root cannot be deleted // I think this makes ... | The Asynchronous version of delete . The request doesn t actually until the asynchronous callback is called . | 225 | 19 |
155,922 | public void setData ( final String path , byte data [ ] , int version , StatCallback cb , Object ctx ) { verbotenThreadCheck ( ) ; final String clientPath = path ; PathUtils . validatePath ( clientPath ) ; final String serverPath = prependChroot ( clientPath ) ; RequestHeader h = new RequestHeader ( ) ; h . setType ( Z... | The Asynchronous version of setData . The request doesn t actually until the asynchronous callback is called . | 179 | 20 |
155,923 | public void getACL ( final String path , Stat stat , ACLCallback cb , Object ctx ) { verbotenThreadCheck ( ) ; final String clientPath = path ; PathUtils . validatePath ( clientPath ) ; final String serverPath = prependChroot ( clientPath ) ; RequestHeader h = new RequestHeader ( ) ; h . setType ( ZooDefs . OpCode . ge... | The Asynchronous version of getACL . The request doesn t actually until the asynchronous callback is called . | 164 | 21 |
155,924 | public void setACL ( final String path , List < ACL > acl , int version , StatCallback cb , Object ctx ) { verbotenThreadCheck ( ) ; final String clientPath = path ; PathUtils . validatePath ( clientPath ) ; final String serverPath = prependChroot ( clientPath ) ; RequestHeader h = new RequestHeader ( ) ; h . setType (... | The Asynchronous version of setACL . The request doesn t actually until the asynchronous callback is called . | 189 | 21 |
155,925 | public void sync ( final String path , VoidCallback cb , Object ctx ) { verbotenThreadCheck ( ) ; final String clientPath = path ; PathUtils . validatePath ( clientPath ) ; final String serverPath = prependChroot ( clientPath ) ; RequestHeader h = new RequestHeader ( ) ; h . setType ( ZooDefs . OpCode . sync ) ; SyncRe... | Asynchronous sync . Flushes channel between process and leader . | 149 | 12 |
155,926 | @ Override public final boolean callProcedureWithTimeout ( ProcedureCallback callback , int batchTimeout , String procName , Object ... parameters ) throws IOException , NoConnectionsException { //Time unit doesn't matter in this case since the timeout isn't being specifie return callProcedureWithClientTimeout ( callba... | Asynchronously invoke a procedure call with timeout . | 103 | 10 |
155,927 | private Object [ ] getUpdateCatalogParams ( File catalogPath , File deploymentPath ) throws IOException { Object [ ] params = new Object [ 2 ] ; if ( catalogPath != null ) { params [ 0 ] = ClientUtils . fileToBytes ( catalogPath ) ; } else { params [ 0 ] = null ; } if ( deploymentPath != null ) { params [ 1 ] = new Str... | Serializes catalog and deployment file for UpdateApplicationCatalog . Catalog is serialized into byte array deployment file is serialized into string . | 122 | 26 |
155,928 | @ Override public void close ( ) throws InterruptedException { if ( m_blessedThreadIds . contains ( Thread . currentThread ( ) . getId ( ) ) ) { throw new RuntimeException ( "Can't invoke backpressureBarrier from within the client callback thread " + " without deadlocking the client library" ) ; } m_isShutdown = true ;... | Shutdown the client closing all network connections and release all memory resources . | 235 | 14 |
155,929 | public boolean backpressureBarrier ( final long start , long timeoutNanos ) throws InterruptedException { if ( m_isShutdown ) { return false ; } if ( m_blessedThreadIds . contains ( Thread . currentThread ( ) . getId ( ) ) ) { throw new RuntimeException ( "Can't invoke backpressureBarrier from within the client callbac... | Wait on backpressure with a timeout . Returns true on timeout false otherwise . Timeout nanos is the initial timeout quantity which will be adjusted to reflect remaining time on spurious wakeups | 350 | 36 |
155,930 | public Object [ ] readData ( Type [ ] colTypes ) throws IOException , HsqlException { int l = colTypes . length ; Object [ ] data = new Object [ l ] ; Object o ; Type type ; for ( int i = 0 ; i < l ; i ++ ) { if ( checkNull ( ) ) { continue ; } o = null ; type = colTypes [ i ] ; switch ( type . typeCode ) { case Types ... | reads row data from a stream using the JDBC types in colTypes | 750 | 14 |
155,931 | public static int matchGenreDescription ( String description ) { if ( description != null && description . length ( ) > 0 ) { for ( int i = 0 ; i < ID3v1Genres . GENRES . length ; i ++ ) { if ( ID3v1Genres . GENRES [ i ] . equalsIgnoreCase ( description ) ) { return i ; } } } return - 1 ; } | Match provided description against genres ignoring case . | 87 | 8 |
155,932 | private int measureSize ( int specType , int contentSize , int measureSpec ) { int result ; int specMode = MeasureSpec . getMode ( measureSpec ) ; int specSize = MeasureSpec . getSize ( measureSpec ) ; if ( specMode == MeasureSpec . EXACTLY ) { result = Math . max ( contentSize , specSize ) ; } else { result = contentS... | measure view Size | 140 | 4 |
155,933 | public int getAllContentWidth ( ) { float width = getAllContentWidthBase ( mTimeTextWidth ) ; if ( ! isConvertDaysToHours && isShowDay ) { if ( isDayLargeNinetyNine ) { Rect rect = new Rect ( ) ; String tempDay = String . valueOf ( mDay ) ; mTimeTextPaint . getTextBounds ( tempDay , 0 , tempDay . length ( ) , rect ) ; ... | get all view width | 152 | 4 |
155,934 | private float initTimeTextBaselineAndTimeBgTopPadding ( int viewHeight , int viewPaddingTop , int viewPaddingBottom , int contentAllHeight ) { float topPaddingSize ; if ( viewPaddingTop == viewPaddingBottom ) { // center topPaddingSize = ( viewHeight - contentAllHeight ) / 2 ; } else { // padding top topPaddingSize = v... | initialize time text baseline and time background top padding | 341 | 10 |
155,935 | public int filterRGB ( int pX , int pY , int pARGB ) { // Get color components int r = pARGB >> 16 & 0xFF ; int g = pARGB >> 8 & 0xFF ; int b = pARGB & 0xFF ; // Scale to new contrast r = LUT [ r ] ; g = LUT [ g ] ; b = LUT [ b ] ; // Return ARGB pixel, leave transparency as is return ( pARGB & 0xFF000000 ) | ( r << 16... | Filters one pixel adjusting brightness and contrast according to this filter . | 126 | 13 |
155,936 | protected static String buildTimestamp ( final Calendar pCalendar ) { if ( pCalendar == null ) { return CALENDAR_IS_NULL_ERROR_MESSAGE ; } // The timestamp format StringBuilder timestamp = new StringBuilder ( ) ; //timestamp.append(DateUtil.getMonthName(new Integer(pCalendar.get(Calendar.MONTH)).toString(), "0", "us", ... | Builds a presentation of the given calendar s time . This method contains the common timestamp format used in this class . | 355 | 23 |
155,937 | public static long roundToHour ( final long pTime , final TimeZone pTimeZone ) { int offset = pTimeZone . getOffset ( pTime ) ; return ( ( pTime / HOUR ) * HOUR ) - offset ; } | Rounds the given time down to the closest hour using the given timezone . | 51 | 16 |
155,938 | public static long roundToDay ( final long pTime , final TimeZone pTimeZone ) { int offset = pTimeZone . getOffset ( pTime ) ; return ( ( ( pTime + offset ) / DAY ) * DAY ) - offset ; } | Rounds the given time down to the closest day using the given timezone . | 53 | 16 |
155,939 | private PropertyConverter getConverterForType ( Class pType ) { Object converter ; Class cl = pType ; // Loop until we find a suitable converter do { // Have a match, return converter if ( ( converter = getInstance ( ) . converters . get ( cl ) ) != null ) { return ( PropertyConverter ) converter ; } } while ( ( cl = c... | Gets the registered converter for the given type . | 104 | 10 |
155,940 | public Object toObject ( String pString , Class pType , String pFormat ) throws ConversionException { if ( pString == null ) { return null ; } if ( pType == null ) { throw new MissingTypeException ( ) ; } // Get converter PropertyConverter converter = getConverterForType ( pType ) ; if ( converter == null ) { throw new... | Converts the string to an object of the given type parsing after the given format . | 136 | 17 |
155,941 | public static void merge ( List < File > inputFiles , File outputFile ) throws IOException { ImageOutputStream output = null ; try { output = ImageIO . createImageOutputStream ( outputFile ) ; for ( File file : inputFiles ) { ImageInputStream input = null ; try { input = ImageIO . createImageInputStream ( file ) ; List... | Merges all pages from the input TIFF files into one TIFF file at the output location . | 141 | 20 |
155,942 | public static List < File > split ( File inputFile , File outputDirectory ) throws IOException { ImageInputStream input = null ; List < File > outputFiles = new ArrayList <> ( ) ; try { input = ImageIO . createImageInputStream ( inputFile ) ; List < TIFFPage > pages = getPages ( input ) ; int pageNo = 1 ; for ( TIFFPag... | Splits all pages from the input TIFF file to one file per page in the output directory . | 260 | 20 |
155,943 | public static String getStats ( ) { long total = sCacheHit + sCacheMiss + sCacheUn ; double hit = ( ( double ) sCacheHit / ( double ) total ) * 100.0 ; double miss = ( ( double ) sCacheMiss / ( double ) total ) * 100.0 ; double un = ( ( double ) sCacheUn / ( double ) total ) * 100.0 ; // Default locale java . text . Nu... | Gets a string containing the stats for this ObjectReader . | 201 | 12 |
155,944 | private Object [ ] readIdentities ( Class pObjClass , Hashtable pMapping , Hashtable pWhere , ObjectMapper pOM ) throws SQLException { sCacheUn ++ ; // Build SQL query string if ( pWhere == null ) pWhere = new Hashtable ( ) ; String [ ] keys = new String [ pWhere . size ( ) ] ; int i = 0 ; for ( Enumeration en = pWhere... | Get an array containing Objects of type objClass with the identity values for the given class set . | 518 | 19 |
155,945 | public Object readObject ( DatabaseReadable pReadable ) throws SQLException { return readObject ( pReadable . getId ( ) , pReadable . getClass ( ) , pReadable . getMapping ( ) ) ; } | Reads one object implementing the DatabaseReadable interface from the database . | 52 | 14 |
155,946 | public Object readObject ( Object pId , Class pObjClass , Hashtable pMapping ) throws SQLException { return readObject ( pId , pObjClass , pMapping , null ) ; } | Reads the object with the given id from the database using the given mapping . | 45 | 16 |
155,947 | public Object [ ] readObjects ( DatabaseReadable pReadable ) throws SQLException { return readObjects ( pReadable . getClass ( ) , pReadable . getMapping ( ) , null ) ; } | Reads all the objects of the given type from the database . The object must implement the DatabaseReadable interface . | 49 | 23 |
155,948 | private void setPropertyValue ( Object pObj , String pProperty , Object pValue ) { Method m = null ; Class [ ] cl = { pValue . getClass ( ) } ; try { //Util.setPropertyValue(pObj, pProperty, pValue); // Find method m = pObj . getClass ( ) . getMethod ( "set" + StringUtil . capitalize ( pProperty ) , cl ) ; // Invoke it... | Sets the property value to an object using reflection | 177 | 10 |
155,949 | private Object getPropertyValue ( Object pObj , String pProperty ) { Method m = null ; Class [ ] cl = new Class [ 0 ] ; try { //return Util.getPropertyValue(pObj, pProperty); // Find method m = pObj . getClass ( ) . getMethod ( "get" + StringUtil . capitalize ( pProperty ) , new Class [ 0 ] ) ; // Invoke it Object resu... | Gets the property value from an object using reflection | 174 | 10 |
155,950 | private void setChildObjects ( Object pParent , ObjectMapper pOM ) throws SQLException { if ( pOM == null ) { throw new NullPointerException ( "ObjectMapper in readChildObjects " + "cannot be null!!" ) ; } for ( Enumeration keys = pOM . mMapTypes . keys ( ) ; keys . hasMoreElements ( ) ; ) { String property = ( String ... | Reads and sets the child properties of the given parent object . | 791 | 13 |
155,951 | private String buildWhereClause ( String [ ] pKeys , Hashtable pMapping ) { StringBuilder sqlBuf = new StringBuilder ( ) ; for ( int i = 0 ; i < pKeys . length ; i ++ ) { String column = ( String ) pMapping . get ( pKeys [ i ] ) ; sqlBuf . append ( " AND " ) ; sqlBuf . append ( column ) ; sqlBuf . append ( " = ?" ) ; }... | Builds extra SQL WHERE clause | 113 | 6 |
155,952 | public static Properties loadMapping ( Class pClass ) { try { return SystemUtil . loadProperties ( pClass ) ; } catch ( FileNotFoundException fnf ) { // System.err... err... System . err . println ( "ERROR: " + fnf . getMessage ( ) ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } return new Properties ( ... | Utility method for reading a property mapping from a properties - file | 92 | 13 |
155,953 | protected Class getType ( String pType ) { Class cl = ( Class ) mTypes . get ( pType ) ; if ( cl == null ) { // throw new NoSuchTypeException(); } return cl ; } | Gets the class for a type | 45 | 7 |
155,954 | protected Object getObject ( String pType ) /*throws XxxException*/ { // Get class Class cl = getType ( pType ) ; // Return the new instance (requires empty public constructor) try { return cl . newInstance ( ) ; } catch ( Exception e ) { // throw new XxxException(e); throw new RuntimeException ( e . getMessage ( ) ) ;... | Gets a java object of the class for a given type . | 90 | 13 |
155,955 | protected void checkBounds ( int index ) throws IOException { assertInput ( ) ; if ( index < getMinIndex ( ) ) { throw new IndexOutOfBoundsException ( "index < minIndex" ) ; } int numImages = getNumImages ( false ) ; if ( numImages != - 1 && index >= numImages ) { throw new IndexOutOfBoundsException ( "index >= numImag... | Convenience method to make sure image index is within bounds . | 103 | 13 |
155,956 | protected static boolean hasExplicitDestination ( final ImageReadParam pParam ) { return pParam != null && ( pParam . getDestination ( ) != null || pParam . getDestinationType ( ) != null || ! ORIGIN . equals ( pParam . getDestinationOffset ( ) ) ) ; } | Tests if param has explicit destination . | 66 | 8 |
155,957 | public BufferedImage getImage ( ) throws IOException { if ( image == null ) { // No content, no image if ( bufferedOut == null ) { return null ; } // Read from the byte buffer InputStream byteStream = bufferedOut . createInputStream ( ) ; ImageInputStream input = null ; try { input = ImageIO . createImageInputStream ( ... | Gets the decoded image from the response . | 807 | 10 |
155,958 | private static QTDecompressor getDecompressor ( final ImageDesc pDescription ) { for ( QTDecompressor decompressor : sDecompressors ) { if ( decompressor . canDecompress ( pDescription ) ) { return decompressor ; } } return null ; } | Gets a decompressor that can decompress the described data . | 61 | 13 |
155,959 | public static BufferedImage decompress ( final ImageInputStream pStream ) throws IOException { ImageDesc description = ImageDesc . read ( pStream ) ; if ( PICTImageReader . DEBUG ) { System . out . println ( description ) ; } QTDecompressor decompressor = getDecompressor ( description ) ; if ( decompressor == null ) { ... | Decompresses the QuickTime image data from the given stream . | 129 | 13 |
155,960 | protected boolean trigger ( ServletRequest pRequest ) { boolean trigger = false ; if ( pRequest instanceof HttpServletRequest ) { HttpServletRequest request = ( HttpServletRequest ) pRequest ; String accept = getAcceptedFormats ( request ) ; String originalFormat = getServletContext ( ) . getMimeType ( request . getReq... | Makes sure the filter triggers for unknown file formats . | 190 | 11 |
155,961 | private static String findBestFormat ( Map < String , Float > pFormatQuality ) { String acceptable = null ; float acceptQuality = 0.0f ; for ( Map . Entry < String , Float > entry : pFormatQuality . entrySet ( ) ) { float qValue = entry . getValue ( ) ; if ( qValue > acceptQuality ) { acceptQuality = qValue ; acceptabl... | Finds the best available format . | 126 | 7 |
155,962 | private void adjustQualityFromAccept ( Map < String , Float > pFormatQuality , HttpServletRequest pRequest ) { // Multiply all q factors with qs factors // No q=.. should be interpreted as q=1.0 // Apache does some extras; if both explicit types and wildcards // (without qaulity factor) are present, */* is interpreted ... | Adjust quality from HTTP Accept header | 337 | 6 |
155,963 | private static void adjustQualityFromImage ( Map < String , Float > pFormatQuality , BufferedImage pImage ) { // NOTE: The values are all made-up. May need tuning. // If pImage.getColorModel() instanceof IndexColorModel // JPEG qs*=0.6 // If NOT binary or 2 color index // WBMP qs*=0.5 // Else // GIF qs*=0.02 // PNG qs*... | Adjusts source quality settings from image properties . | 415 | 9 |
155,964 | private static void adjustQuality ( Map < String , Float > pFormatQuality , String pFormat , float pFactor ) { Float oldValue = pFormatQuality . get ( pFormat ) ; if ( oldValue != null ) { pFormatQuality . put ( pFormat , oldValue * pFactor ) ; //System.out.println("New vallue after multiplying with " + pFactor + " is ... | Updates the quality in the map . | 97 | 8 |
155,965 | private float getKnownFormatQuality ( String pFormat ) { for ( int i = 0 ; i < sKnownFormats . length ; i ++ ) { if ( pFormat . equals ( sKnownFormats [ i ] ) ) { return knownFormatQuality [ i ] ; } } return 0.1f ; } | Gets the initial quality if this is a known format otherwise 0 . 1 | 66 | 15 |
155,966 | public void write ( final byte pBytes [ ] , final int pOff , final int pLen ) throws IOException { out . write ( pBytes , pOff , pLen ) ; } | Overide for efficiency | 40 | 4 |
155,967 | public int decode ( final InputStream stream , final ByteBuffer buffer ) throws IOException { if ( reachedEOF ) { return - 1 ; } // TODO: Don't decode more than single runs, because some writers add pad bytes inside the stream... while ( buffer . hasRemaining ( ) ) { int n ; if ( splitRun ) { // Continue run n = leftOf... | Decodes bytes from the given input stream to the given buffer . | 375 | 13 |
155,968 | private float [ ] LABtoXYZ ( float L , float a , float b , float [ ] xyzResult ) { // Significant speedup: Removing Math.pow float y = ( L + 16.0f ) / 116.0f ; float y3 = y * y * y ; // Math.pow(y, 3.0); float x = ( a / 500.0f ) + y ; float x3 = x * x * x ; // Math.pow(x, 3.0); float z = y - ( b / 200.0f ) ; float z3 =... | Convert LAB to XYZ . | 335 | 8 |
155,969 | public Object toObject ( final String pString , final Class pType , final String pFormat ) throws ConversionException { if ( StringUtil . isEmpty ( pString ) ) { return null ; } try { if ( pType . equals ( BigInteger . class ) ) { return new BigInteger ( pString ) ; // No format? } if ( pType . equals ( BigDecimal . cl... | Converts the string to a number using the given format for parsing . | 368 | 14 |
155,970 | public void setPenSize ( Dimension2D pSize ) { penSize . setSize ( pSize ) ; graphics . setStroke ( getStroke ( penSize ) ) ; } | Sets the pen size . PenSize | 41 | 8 |
155,971 | protected void setupForFill ( final Pattern pPattern ) { graphics . setPaint ( pPattern ) ; graphics . setComposite ( getCompositeFor ( QuickDraw . PAT_COPY ) ) ; } | Sets up paint context for fill . | 47 | 8 |
155,972 | private static Arc2D . Double toArc ( final Rectangle2D pRectangle , int pStartAngle , int pArcAngle , final boolean pClosed ) { return new Arc2D . Double ( pRectangle , 90 - pStartAngle , - pArcAngle , pClosed ? Arc2D . PIE : Arc2D . OPEN ) ; } | Converts a rectangle to an arc . | 82 | 8 |
155,973 | public void drawString ( String pString ) { setupForText ( ) ; graphics . drawString ( pString , ( float ) getPenPosition ( ) . getX ( ) , ( float ) getPenPosition ( ) . getY ( ) ) ; } | DrawString - draws the text of a Pascal string . | 54 | 11 |
155,974 | public static Dimension readDimension ( final DataInput pStream ) throws IOException { int h = pStream . readShort ( ) ; int v = pStream . readShort ( ) ; return new Dimension ( h , v ) ; } | Reads a dimension from the given stream . | 49 | 9 |
155,975 | public static String readStr31 ( final DataInput pStream ) throws IOException { String text = readPascalString ( pStream ) ; int length = 31 - text . length ( ) ; if ( length < 0 ) { throw new IOException ( "String length exceeds maximum (31): " + text . length ( ) ) ; } pStream . skipBytes ( length ) ; return text ; } | Reads a 32 byte fixed length Pascal string from the given input . The input stream must be positioned at the length byte of the text the text will be no longer than 31 characters long . | 83 | 38 |
155,976 | public static String readPascalString ( final DataInput pStream ) throws IOException { // Get as many bytes as indicated by byte count int length = pStream . readUnsignedByte ( ) ; byte [ ] bytes = new byte [ length ] ; pStream . readFully ( bytes , 0 , length ) ; return new String ( bytes , ENCODING ) ; } | Reads a Pascal String from the given stream . The input stream must be positioned at the length byte of the text which can thus be a maximum of 255 characters long . | 79 | 34 |
155,977 | protected void doFilterImpl ( ServletRequest pRequest , ServletResponse pResponse , FilterChain pChain ) throws IOException , ServletException { // TODO: Max size configuration, to avoid DOS attacks? OutOfMemory // Size parameters int width = ServletUtil . getIntParameter ( pRequest , sizeWidthParam , - 1 ) ; int heigh... | Extracts request parameters and sets the corresponding request attributes if specified . | 532 | 14 |
155,978 | public void setTimeout ( int pTimeout ) { if ( pTimeout < 0 ) { // Must be positive throw new IllegalArgumentException ( "Timeout must be positive." ) ; } timeout = pTimeout ; if ( socket != null ) { try { socket . setSoTimeout ( pTimeout ) ; } catch ( SocketException se ) { // Not much to do about that... } } } | Sets the read timeout for the undelying socket . A timeout of zero is interpreted as an infinite timeout . | 81 | 22 |
155,979 | public synchronized InputStream getInputStream ( ) throws IOException { if ( ! connected ) { connect ( ) ; } // Nothing to return if ( responseCode == HTTP_NOT_FOUND ) { throw new FileNotFoundException ( url . toString ( ) ) ; } int length ; if ( inputStream == null ) { return null ; } // "De-chunk" the output stream e... | Returns an input stream that reads from this open connection . | 220 | 11 |
155,980 | private Socket createSocket ( final URL pURL , final int pPort , int pConnectTimeout ) throws IOException { Socket socket ; final Object current = this ; SocketConnector connector ; Thread t = new Thread ( connector = new SocketConnector ( ) { private IOException mConnectException = null ; private Socket mLocalSocket =... | Creates a socket to the given URL and port with the given connect timeout . If the socket waits more than the given timout to connect an ConnectException is thrown . | 305 | 34 |
155,981 | private static void writeRequestHeaders ( OutputStream pOut , URL pURL , String pMethod , Properties pProps , boolean pUsingProxy , PasswordAuthentication pAuth , String pAuthType ) { PrintWriter out = new PrintWriter ( pOut , true ) ; // autoFlush if ( ! pUsingProxy ) { out . println ( pMethod + " " + ( ! StringUtil .... | Writes the HTTP request headers for HTTP GET method . | 682 | 11 |
155,982 | private static int findEndOfHeader ( byte [ ] pBytes , int pEnd ) { byte [ ] header = HTTP_HEADER_END . getBytes ( ) ; // Normal condition, check all bytes for ( int i = 0 ; i < pEnd - 4 ; i ++ ) { // Need 4 bytes to match if ( ( pBytes [ i ] == header [ 0 ] ) && ( pBytes [ i + 1 ] == header [ 1 ] ) && ( pBytes [ i + 2... | Finds the end of the HTTP response header in an array of bytes . | 384 | 15 |
155,983 | private static InputStream detatchResponseHeader ( BufferedInputStream pIS ) throws IOException { // Store header in byte array ByteArrayOutputStream bytes = new ByteArrayOutputStream ( ) ; pIS . mark ( BUF_SIZE ) ; byte [ ] buffer = new byte [ BUF_SIZE ] ; int length ; int headerEnd ; // Read from iput, store in bytes... | Reads the header part of the response and copies it to a different InputStream . | 299 | 17 |
155,984 | private static Properties parseHeaderFields ( String [ ] pHeaders ) { Properties headers = new Properties ( ) ; // Get header information int split ; String field ; String value ; for ( String header : pHeaders ) { //System.err.println(pHeaders[i]); if ( ( split = header . indexOf ( ":" ) ) > 0 ) { // Read & parse..? f... | Pareses the response header fields . | 155 | 8 |
155,985 | private static String [ ] parseResponseHeader ( InputStream pIS ) throws IOException { List < String > headers = new ArrayList < String > ( ) ; // Wrap Stream in Reader BufferedReader in = new BufferedReader ( new InputStreamReader ( pIS ) ) ; // Get response status String header ; while ( ( header = in . readLine ( ) ... | Parses the response headers . | 116 | 7 |
155,986 | public int filterRGB ( int pX , int pY , int pARGB ) { // Get color components int r = pARGB >> 16 & 0xFF ; int g = pARGB >> 8 & 0xFF ; int b = pARGB & 0xFF ; // ITU standard: Gray scale=(222*Red+707*Green+71*Blue)/1000 int gray = ( 222 * r + 707 * g + 71 * b ) / 1000 ; //int gray = (int) ((float) (r + g + b) / 3.0f); ... | Filters one pixel using ITU color - conversion . | 183 | 11 |
155,987 | public final int decode ( final InputStream stream , final ByteBuffer buffer ) throws IOException { // TODO: Allow decoding < row.length at a time and get rid of this assertion... if ( buffer . capacity ( ) < row . length ) { throw new AssertionError ( "This decoder needs a buffer.capacity() of at least one row" ) ; } ... | Decodes as much data as possible from the stream into the buffer . | 308 | 14 |
155,988 | public void init ( ) throws ServletException { // Get the name of the upload directory. String uploadDirParam = getInitParameter ( "uploadDir" ) ; if ( ! StringUtil . isEmpty ( uploadDirParam ) ) { try { URL uploadDirURL = getServletContext ( ) . getResource ( uploadDirParam ) ; uploadDir = FileUtil . toFile ( uploadDi... | This method is called by the server before the filter goes into service and here it determines the file upload directory . | 147 | 22 |
155,989 | private static boolean copyDir ( File pFrom , File pTo , boolean pOverWrite ) throws IOException { if ( pTo . exists ( ) && ! pTo . isDirectory ( ) ) { throw new IOException ( "A directory may only be copied to another directory, not to a file" ) ; } pTo . mkdirs ( ) ; // mkdir? boolean allOkay = true ; File [ ] files ... | Copies a directory recursively . If the destination folder does not exist it is created | 145 | 18 |
155,990 | public static boolean copy ( InputStream pFrom , OutputStream pTo ) throws IOException { Validate . notNull ( pFrom , "from" ) ; Validate . notNull ( pTo , "to" ) ; // TODO: Consider using file channels for faster copy where possible // Use buffer size two times byte array, to avoid i/o bottleneck // TODO: Consider let... | Copies all data from one stream to another . The data is copied from the fromStream to the toStream using buffered streams for efficiency . | 217 | 29 |
155,991 | public static String getDirectoryname ( final String pPath , final char pSeparator ) { int index = pPath . lastIndexOf ( pSeparator ) ; if ( index < 0 ) { return "" ; // Assume only filename } return pPath . substring ( 0 , index ) ; } | Extracts the directory path without the filename from a complete filename path . | 65 | 15 |
155,992 | public static String getFilename ( final String pPath , final char pSeparator ) { int index = pPath . lastIndexOf ( pSeparator ) ; if ( index < 0 ) { return pPath ; // Assume only filename } return pPath . substring ( index + 1 ) ; } | Extracts the filename of a complete filename path . | 65 | 11 |
155,993 | public static boolean isEmpty ( File pFile ) { if ( pFile . isDirectory ( ) ) { return ( pFile . list ( ) . length == 0 ) ; } return ( pFile . length ( ) == 0 ) ; } | Tests if a file or directory has no content . A file is empty if it has a length of 0L . A non - existing file is also considered empty . A directory is considered empty if it contains no files . | 50 | 45 |
155,994 | public static String getTempDir ( ) { synchronized ( FileUtil . class ) { if ( TEMP_DIR == null ) { // Get the 'java.io.tmpdir' property String tmpDir = System . getProperty ( "java.io.tmpdir" ) ; if ( StringUtil . isEmpty ( tmpDir ) ) { // Stupid fallback... // TODO: Delegate to FileSystem? if ( new File ( "/temp" ) .... | Gets the default temp directory for the system . | 143 | 10 |
155,995 | public static byte [ ] read ( File pFile ) throws IOException { // Custom implementation, as we know the size of a file if ( ! pFile . exists ( ) ) { throw new FileNotFoundException ( pFile . toString ( ) ) ; } byte [ ] bytes = new byte [ ( int ) pFile . length ( ) ] ; InputStream in = null ; try { // Use buffer size t... | Gets the contents of the given file as a byte array . | 203 | 13 |
155,996 | public static byte [ ] read ( InputStream pInput ) throws IOException { // Create byte array ByteArrayOutputStream bytes = new FastByteArrayOutputStream ( BUF_SIZE ) ; // Copy from stream to byte array copy ( pInput , bytes ) ; return bytes . toByteArray ( ) ; } | Reads all data from the input stream to a byte array . | 64 | 13 |
155,997 | public static boolean write ( File pFile , byte [ ] pData ) throws IOException { boolean success = false ; OutputStream out = null ; try { out = new BufferedOutputStream ( new FileOutputStream ( pFile ) ) ; success = write ( out , pData ) ; } finally { close ( out ) ; } return success ; } | Writes the contents from a byte array to a file . | 73 | 12 |
155,998 | public static boolean delete ( final File pFile , final boolean pForce ) throws IOException { if ( pForce && pFile . isDirectory ( ) ) { return deleteDir ( pFile ) ; } return pFile . exists ( ) && pFile . delete ( ) ; } | Deletes the specified file . | 58 | 6 |
155,999 | private static boolean fixProfileXYZTag ( final ICC_Profile profile , final int tagSignature ) { byte [ ] data = profile . getData ( tagSignature ) ; // The CMM expects 0x64 65 73 63 ('XYZ ') but is 0x17 A5 05 B8..? if ( data != null && intFromBigEndian ( data , 0 ) == CORBIS_RGB_ALTERNATE_XYZ ) { intToBigEndian ( ICC_... | Fixes problematic XYZ tags in Corbis RGB profile . | 138 | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.