idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
3,700 | public String header ( ) { StringBuilder output = new StringBuilder ( ) ; output . append ( "GeoPackage File: " + geoPackage . getPath ( ) ) ; output . append ( "\nGeoPackage Name: " + geoPackage . getName ( ) ) ; return output . toString ( ) ; } | Get the GeoPackage file and name header text |
3,701 | public String tileTable ( String table ) { StringBuilder output = new StringBuilder ( ) ; TileDao tileDao = geoPackage . getTileDao ( table ) ; output . append ( "Table Name: " + tileDao . getTableName ( ) ) ; long minZoom = tileDao . getMinZoom ( ) ; long maxZoom = tileDao . getMaxZoom ( ) ; output . append ( "\nMin Zoom: " + minZoom ) ; output . append ( "\nMax Zoom: " + maxZoom ) ; output . append ( "\nTiles: " + tileDao . count ( ) ) ; TileMatrixSet tileMatrixSet = tileDao . getTileMatrixSet ( ) ; output . append ( "\n\nContents\n\n" ) . append ( textOutput ( tileMatrixSet . getContents ( ) ) ) ; output . append ( "\n\nTile Matrix Set\n\n" ) . append ( textOutput ( tileMatrixSet ) ) ; output . append ( "\n\n Tile Matrices" ) ; for ( long zoom = minZoom ; zoom <= maxZoom ; zoom ++ ) { TileMatrix tileMatrix = tileDao . getTileMatrix ( zoom ) ; if ( tileMatrix != null ) { output . append ( "\n\n" ) . append ( textOutput ( tileMatrix ) ) ; output . append ( "\n\tTiles: " + tileDao . count ( zoom ) ) ; BoundingBox boundingBox = tileDao . getBoundingBox ( zoom ) ; output . append ( "\n\tTile Bounds: \n" ) . append ( textOutput ( boundingBox ) ) ; } } return output . toString ( ) ; } | Build text from a tile table |
3,702 | public String textOutput ( SpatialReferenceSystem srs ) { StringBuilder output = new StringBuilder ( ) ; output . append ( "\tSRS " + SpatialReferenceSystem . COLUMN_ORGANIZATION + ": " + srs . getOrganization ( ) ) ; output . append ( "\n\tSRS " + SpatialReferenceSystem . COLUMN_ORGANIZATION_COORDSYS_ID + ": " + srs . getOrganizationCoordsysId ( ) ) ; output . append ( "\n\tSRS " + SpatialReferenceSystem . COLUMN_DEFINITION + ": " + srs . getDefinition ( ) ) ; return output . toString ( ) ; } | Text output from a SRS |
3,703 | public String textOutput ( Contents contents ) { StringBuilder output = new StringBuilder ( ) ; output . append ( "\t" + Contents . COLUMN_TABLE_NAME + ": " + contents . getTableName ( ) ) ; output . append ( "\n\t" + Contents . COLUMN_DATA_TYPE + ": " + contents . getDataType ( ) ) ; output . append ( "\n\t" + Contents . COLUMN_IDENTIFIER + ": " + contents . getIdentifier ( ) ) ; output . append ( "\n\t" + Contents . COLUMN_DESCRIPTION + ": " + contents . getDescription ( ) ) ; output . append ( "\n\t" + Contents . COLUMN_LAST_CHANGE + ": " + contents . getLastChange ( ) ) ; output . append ( "\n\t" + Contents . COLUMN_MIN_X + ": " + contents . getMinX ( ) ) ; output . append ( "\n\t" + Contents . COLUMN_MIN_Y + ": " + contents . getMinY ( ) ) ; output . append ( "\n\t" + Contents . COLUMN_MAX_X + ": " + contents . getMaxX ( ) ) ; output . append ( "\n\t" + Contents . COLUMN_MAX_Y + ": " + contents . getMaxY ( ) ) ; output . append ( "\n" + textOutput ( contents . getSrs ( ) ) ) ; return output . toString ( ) ; } | Text output from a Contents |
3,704 | public String textOutput ( TileMatrixSet tileMatrixSet ) { StringBuilder output = new StringBuilder ( ) ; output . append ( "\t" + TileMatrixSet . COLUMN_TABLE_NAME + ": " + tileMatrixSet . getTableName ( ) ) ; output . append ( "\n" + textOutput ( tileMatrixSet . getSrs ( ) ) ) ; output . append ( "\n\t" + TileMatrixSet . COLUMN_MIN_X + ": " + tileMatrixSet . getMinX ( ) ) ; output . append ( "\n\t" + TileMatrixSet . COLUMN_MIN_Y + ": " + tileMatrixSet . getMinY ( ) ) ; output . append ( "\n\t" + TileMatrixSet . COLUMN_MAX_X + ": " + tileMatrixSet . getMaxX ( ) ) ; output . append ( "\n\t" + TileMatrixSet . COLUMN_MAX_Y + ": " + tileMatrixSet . getMaxY ( ) ) ; return output . toString ( ) ; } | Text output from a TileMatrixSet |
3,705 | public String textOutput ( TileMatrix tileMatrix ) { StringBuilder output = new StringBuilder ( ) ; output . append ( "\t" + TileMatrix . COLUMN_TABLE_NAME + ": " + tileMatrix . getTableName ( ) ) ; output . append ( "\n\t" + TileMatrix . COLUMN_ZOOM_LEVEL + ": " + tileMatrix . getZoomLevel ( ) ) ; output . append ( "\n\t" + TileMatrix . COLUMN_MATRIX_WIDTH + ": " + tileMatrix . getMatrixWidth ( ) ) ; output . append ( "\n\t" + TileMatrix . COLUMN_MATRIX_HEIGHT + ": " + tileMatrix . getMatrixHeight ( ) ) ; output . append ( "\n\t" + TileMatrix . COLUMN_TILE_WIDTH + ": " + tileMatrix . getTileWidth ( ) ) ; output . append ( "\n\t" + TileMatrix . COLUMN_TILE_HEIGHT + ": " + tileMatrix . getTileHeight ( ) ) ; output . append ( "\n\t" + TileMatrix . COLUMN_PIXEL_X_SIZE + ": " + tileMatrix . getPixelXSize ( ) ) ; output . append ( "\n\t" + TileMatrix . COLUMN_PIXEL_Y_SIZE + ": " + tileMatrix . getPixelYSize ( ) ) ; return output . toString ( ) ; } | Text output from a Tile Matrix |
3,706 | public String textOutput ( BoundingBox boundingBox ) { StringBuilder output = new StringBuilder ( ) ; output . append ( "\tMin Longitude: " + boundingBox . getMinLongitude ( ) ) ; output . append ( "\n\tMin Latitude: " + boundingBox . getMinLatitude ( ) ) ; output . append ( "\n\tMax Longitude: " + boundingBox . getMaxLongitude ( ) ) ; output . append ( "\n\tMax Latitude: " + boundingBox . getMaxLatitude ( ) ) ; return output . toString ( ) ; } | Text output from a bounding box |
3,707 | public void writeTiff ( ) { if ( directory . getWriteRasters ( ) != null ) { TIFFImage tiffImage = new TIFFImage ( ) ; tiffImage . add ( directory ) ; try { imageBytes = TiffWriter . writeTiffToBytes ( tiffImage ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to write TIFF image" , e ) ; } } } | Write the TIFF file to the image bytes |
3,708 | public float getPixel ( int x , int y ) { float pixel = - 1 ; if ( rasters == null ) { readPixels ( ) ; } if ( rasters != null ) { pixel = rasters . getFirstPixelSample ( x , y ) . floatValue ( ) ; } else { throw new GeoPackageException ( "Could not retrieve pixel value" ) ; } return pixel ; } | Get the pixel at the coordinate |
3,709 | public void setStyle ( StyleRow styleRow , GeometryType geometryType ) { if ( geometryType != null ) { if ( styleRow != null ) { styles . put ( geometryType , styleRow ) ; } else { styles . remove ( geometryType ) ; } } else { defaultStyle = styleRow ; } } | Set the style for the geometry type |
3,710 | public StyleRow getStyle ( GeometryType geometryType ) { StyleRow styleRow = null ; if ( geometryType != null && ! styles . isEmpty ( ) ) { List < GeometryType > geometryTypes = GeometryUtils . parentHierarchy ( geometryType ) ; geometryTypes . add ( 0 , geometryType ) ; for ( GeometryType type : geometryTypes ) { styleRow = styles . get ( type ) ; if ( styleRow != null ) { break ; } } } if ( styleRow == null ) { styleRow = defaultStyle ; } if ( styleRow == null && geometryType == null && styles . size ( ) == 1 ) { styleRow = styles . values ( ) . iterator ( ) . next ( ) ; } return styleRow ; } | Get the style for the geometry type |
3,711 | protected int count ( UserCustomResultSet resultSet ) { int count = 0 ; try { count = resultSet . getCount ( ) ; } finally { resultSet . close ( ) ; } return count ; } | Get the count of the result set and close it |
3,712 | public static UserCustomDao readTable ( String database , GeoPackageConnection connection , String tableName ) { UserCustomConnection userDb = new UserCustomConnection ( connection ) ; UserCustomTable userCustomTable = UserCustomTableReader . readTable ( userDb , tableName ) ; UserCustomDao dao = new UserCustomDao ( database , connection , userDb , userCustomTable ) ; return dao ; } | Read the database table and create a DAO |
3,713 | private ResultSet integrityCheck ( ResultSet resultSet ) { try { if ( resultSet . next ( ) ) { String value = resultSet . getString ( 1 ) ; if ( value . equals ( "ok" ) ) { resultSet . close ( ) ; resultSet = null ; } } } catch ( SQLException e ) { throw new GeoPackageException ( "Integrity check failed on database: " + getName ( ) , e ) ; } return resultSet ; } | Check the result set returned from the integrity check to see if things are ok |
3,714 | public void setTileFormat ( TileFormatType tileFormat ) { if ( tileFormat == null ) { tileFormat = TileFormatType . STANDARD ; } else { switch ( tileFormat ) { case STANDARD : case TMS : this . tileFormat = tileFormat ; break ; default : throw new GeoPackageException ( "Unsupported Tile Format Type for URL Tile Generation: " + tileFormat ) ; } } } | Set the tile format |
3,715 | private String replaceXYZ ( String url , int z , long x , long y ) { url = url . replaceAll ( Z_VARIABLE , String . valueOf ( z ) ) ; url = url . replaceAll ( X_VARIABLE , String . valueOf ( x ) ) ; url = url . replaceAll ( Y_VARIABLE , String . valueOf ( y ) ) ; return url ; } | Replace x y and z in the url |
3,716 | private String replaceBoundingBox ( String url , BoundingBox boundingBox ) { url = url . replaceAll ( MIN_LAT_VARIABLE , String . valueOf ( boundingBox . getMinLatitude ( ) ) ) ; url = url . replaceAll ( MAX_LAT_VARIABLE , String . valueOf ( boundingBox . getMaxLatitude ( ) ) ) ; url = url . replaceAll ( MIN_LON_VARIABLE , String . valueOf ( boundingBox . getMinLongitude ( ) ) ) ; url = url . replaceAll ( MAX_LON_VARIABLE , String . valueOf ( boundingBox . getMaxLongitude ( ) ) ) ; return url ; } | Replace the url parts with the bounding box |
3,717 | private byte [ ] downloadTile ( String zoomUrl , URL url , int z , long x , long y ) { byte [ ] bytes = null ; HttpURLConnection connection = null ; try { connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . connect ( ) ; int responseCode = connection . getResponseCode ( ) ; if ( responseCode == HttpURLConnection . HTTP_MOVED_PERM || responseCode == HttpURLConnection . HTTP_MOVED_TEMP || responseCode == HttpURLConnection . HTTP_SEE_OTHER ) { String redirect = connection . getHeaderField ( "Location" ) ; connection . disconnect ( ) ; url = new URL ( redirect ) ; connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . connect ( ) ; } if ( connection . getResponseCode ( ) != HttpURLConnection . HTTP_OK ) { throw new GeoPackageException ( "Failed to download tile. URL: " + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y + ", Response Code: " + connection . getResponseCode ( ) + ", Response Message: " + connection . getResponseMessage ( ) ) ; } InputStream geoPackageStream = connection . getInputStream ( ) ; bytes = GeoPackageIOUtils . streamBytes ( geoPackageStream ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to download tile. URL: " + zoomUrl + ", z=" + z + ", x=" + x + ", y=" + y , e ) ; } finally { if ( connection != null ) { connection . disconnect ( ) ; } } return bytes ; } | Download the tile from the URL |
3,718 | private boolean drawFeature ( int zoom , BoundingBox boundingBox , BoundingBox expandedBoundingBox , ProjectionTransform transform , FeatureTileGraphics graphics , FeatureRow row ) { boolean drawn = false ; try { GeoPackageGeometryData geomData = row . getGeometry ( ) ; if ( geomData != null ) { Geometry geometry = geomData . getGeometry ( ) ; if ( geometry != null ) { GeometryEnvelope envelope = geomData . getOrBuildEnvelope ( ) ; BoundingBox geometryBoundingBox = new BoundingBox ( envelope ) ; BoundingBox transformedBoundingBox = geometryBoundingBox . transform ( transform ) ; if ( expandedBoundingBox . intersects ( transformedBoundingBox , true ) ) { double simplifyTolerance = TileBoundingBoxUtils . toleranceDistance ( zoom , tileWidth , tileHeight ) ; drawn = drawGeometry ( simplifyTolerance , boundingBox , transform , graphics , row , geometry ) ; } } } } catch ( Exception e ) { log . log ( Level . SEVERE , "Failed to draw feature in tile. Table: " + featureDao . getTableName ( ) , e ) ; } return drawn ; } | Draw the feature |
3,719 | private boolean drawLineString ( double simplifyTolerance , BoundingBox boundingBox , ProjectionTransform transform , FeatureTileGraphics graphics , LineString lineString , FeatureStyle featureStyle ) { Path2D path = getPath ( simplifyTolerance , boundingBox , transform , lineString ) ; return drawLine ( graphics , path , featureStyle ) ; } | Draw a LineString |
3,720 | private boolean drawPolygon ( double simplifyTolerance , BoundingBox boundingBox , ProjectionTransform transform , FeatureTileGraphics graphics , Polygon polygon , FeatureStyle featureStyle ) { Area polygonArea = getArea ( simplifyTolerance , boundingBox , transform , polygon ) ; return drawPolygon ( graphics , polygonArea , featureStyle ) ; } | Draw a Polygon |
3,721 | private Path2D getPath ( double simplifyTolerance , BoundingBox boundingBox , ProjectionTransform transform , LineString lineString ) { Path2D path = null ; List < Point > lineStringPoints = simplifyPoints ( simplifyTolerance , lineString . getPoints ( ) ) ; for ( Point point : lineStringPoints ) { Point projectedPoint = transform . transform ( point ) ; float x = TileBoundingBoxUtils . getXPixel ( tileWidth , boundingBox , projectedPoint . getX ( ) ) ; float y = TileBoundingBoxUtils . getYPixel ( tileHeight , boundingBox , projectedPoint . getY ( ) ) ; if ( path == null ) { path = new Path2D . Double ( ) ; path . moveTo ( x , y ) ; } else { path . lineTo ( x , y ) ; } } return path ; } | Get the path of the line string |
3,722 | private boolean drawLine ( FeatureTileGraphics graphics , Path2D line , FeatureStyle featureStyle ) { Graphics2D lineGraphics = graphics . getLineGraphics ( ) ; Paint paint = getLinePaint ( featureStyle ) ; lineGraphics . setColor ( paint . getColor ( ) ) ; lineGraphics . setStroke ( paint . getStroke ( ) ) ; boolean drawn = lineGraphics . hit ( new java . awt . Rectangle ( tileWidth , tileHeight ) , line , true ) ; if ( drawn ) { lineGraphics . draw ( line ) ; } return drawn ; } | Draw the line |
3,723 | private Area getArea ( double simplifyTolerance , BoundingBox boundingBox , ProjectionTransform transform , Polygon polygon ) { Area area = null ; for ( LineString ring : polygon . getRings ( ) ) { Path2D path = getPath ( simplifyTolerance , boundingBox , transform , ring ) ; Area ringArea = new Area ( path ) ; if ( area == null ) { area = ringArea ; } else { area . subtract ( ringArea ) ; } } return area ; } | Get the area of the polygon |
3,724 | private boolean drawPolygon ( FeatureTileGraphics graphics , Area polygon , FeatureStyle featureStyle ) { Graphics2D polygonGraphics = graphics . getPolygonGraphics ( ) ; Paint fillPaint = getPolygonFillPaint ( featureStyle ) ; if ( fillPaint != null ) { polygonGraphics . setColor ( fillPaint . getColor ( ) ) ; polygonGraphics . fill ( polygon ) ; } Paint paint = getPolygonPaint ( featureStyle ) ; polygonGraphics . setColor ( paint . getColor ( ) ) ; polygonGraphics . setStroke ( paint . getStroke ( ) ) ; boolean drawn = polygonGraphics . hit ( new java . awt . Rectangle ( tileWidth , tileHeight ) , polygon , true ) ; if ( drawn ) { polygonGraphics . draw ( polygon ) ; } return drawn ; } | Draw the polygon |
3,725 | public FeatureRow getFeatureRow ( UserCustomResultSet resultSet ) { RTreeIndexTableRow row = getRow ( resultSet ) ; return getFeatureRow ( row ) ; } | Get the feature row from the RTree Index Table row |
3,726 | public UserCustomResultSet query ( BoundingBox boundingBox , Projection projection ) { BoundingBox featureBoundingBox = projectBoundingBox ( boundingBox , projection ) ; return query ( featureBoundingBox ) ; } | Query for rows within the bounding box in the provided projection |
3,727 | public UserCustomResultSet query ( GeometryEnvelope envelope ) { return query ( envelope . getMinX ( ) , envelope . getMinY ( ) , envelope . getMaxX ( ) , envelope . getMaxY ( ) ) ; } | Query for rows within the geometry envelope |
3,728 | public UserCustomResultSet query ( double minX , double minY , double maxX , double maxY ) { validateRTree ( ) ; String where = buildWhere ( minX , minY , maxX , maxY ) ; String [ ] whereArgs = buildWhereArgs ( minX , minY , maxX , maxY ) ; return query ( where , whereArgs ) ; } | Query for rows within the bounds |
3,729 | public long count ( double minX , double minY , double maxX , double maxY ) { validateRTree ( ) ; String where = buildWhere ( minX , minY , maxX , maxY ) ; String [ ] whereArgs = buildWhereArgs ( minX , minY , maxX , maxY ) ; return count ( where , whereArgs ) ; } | Count the rows within the bounds |
3,730 | public void setData ( BufferedImage image , String imageFormat ) throws IOException { setData ( image , imageFormat , null ) ; } | Set the data from an image |
3,731 | public void setData ( BufferedImage image , String imageFormat , Float quality ) throws IOException { setData ( ImageUtils . writeImageToBytes ( image , imageFormat , quality ) ) ; } | Set the data from an image with optional quality |
3,732 | public TileResultSet queryForTilesInColumn ( long column , long zoomLevel ) { Map < String , Object > fieldValues = new HashMap < String , Object > ( ) ; fieldValues . put ( TileTable . COLUMN_TILE_COLUMN , column ) ; fieldValues . put ( TileTable . COLUMN_ZOOM_LEVEL , zoomLevel ) ; return queryForFieldValues ( fieldValues ) ; } | Query for Tiles at a zoom level and column |
3,733 | public TileResultSet queryForTilesInRow ( long row , long zoomLevel ) { Map < String , Object > fieldValues = new HashMap < String , Object > ( ) ; fieldValues . put ( TileTable . COLUMN_TILE_ROW , row ) ; fieldValues . put ( TileTable . COLUMN_ZOOM_LEVEL , zoomLevel ) ; return queryForFieldValues ( fieldValues ) ; } | Query for Tiles at a zoom level and row |
3,734 | public TileResultSet queryByTileGrid ( TileGrid tileGrid , long zoomLevel , String orderBy ) { TileResultSet tileCursor = null ; if ( tileGrid != null ) { StringBuilder where = new StringBuilder ( ) ; where . append ( buildWhere ( TileTable . COLUMN_ZOOM_LEVEL , zoomLevel ) ) ; where . append ( " AND " ) ; where . append ( buildWhere ( TileTable . COLUMN_TILE_COLUMN , tileGrid . getMinX ( ) , ">=" ) ) ; where . append ( " AND " ) ; where . append ( buildWhere ( TileTable . COLUMN_TILE_COLUMN , tileGrid . getMaxX ( ) , "<=" ) ) ; where . append ( " AND " ) ; where . append ( buildWhere ( TileTable . COLUMN_TILE_ROW , tileGrid . getMinY ( ) , ">=" ) ) ; where . append ( " AND " ) ; where . append ( buildWhere ( TileTable . COLUMN_TILE_ROW , tileGrid . getMaxY ( ) , "<=" ) ) ; String [ ] whereArgs = buildWhereArgs ( new Object [ ] { zoomLevel , tileGrid . getMinX ( ) , tileGrid . getMaxX ( ) , tileGrid . getMinY ( ) , tileGrid . getMaxY ( ) } ) ; tileCursor = query ( where . toString ( ) , whereArgs , null , null , orderBy ) ; } return tileCursor ; } | Query by tile grid and zoom level |
3,735 | public BufferedImage put ( IconRow iconRow , BufferedImage image ) { return put ( iconRow . getId ( ) , image ) ; } | Cache the icon image for the icon row |
3,736 | public static BufferedImage createIcon ( IconRow icon , float scale , IconCache iconCache ) { BufferedImage iconImage = null ; if ( icon != null ) { if ( iconCache != null ) { iconImage = iconCache . get ( icon . getId ( ) ) ; } if ( iconImage == null ) { try { iconImage = icon . getDataImage ( ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to get the Icon Row image. Id: " + icon . getId ( ) + ", Name: " + icon . getName ( ) , e ) ; } int dataWidth = iconImage . getWidth ( ) ; int dataHeight = iconImage . getHeight ( ) ; Double iconWidth = icon . getWidth ( ) ; Double iconHeight = icon . getHeight ( ) ; boolean scaleImage = iconWidth != null || iconHeight != null ; if ( ! scaleImage && scale != 1.0f ) { iconWidth = ( double ) dataWidth ; iconHeight = ( double ) dataHeight ; scaleImage = true ; } if ( scaleImage ) { if ( iconWidth == null ) { iconWidth = dataWidth * ( iconHeight / dataHeight ) ; } else if ( iconHeight == null ) { iconHeight = dataHeight * ( iconWidth / dataWidth ) ; } int scaledWidth = Math . round ( scale * iconWidth . floatValue ( ) ) ; int scaledHeight = Math . round ( scale * iconHeight . floatValue ( ) ) ; if ( scaledWidth != dataWidth || scaledHeight != dataHeight ) { Image scaledImage = iconImage . getScaledInstance ( scaledWidth , scaledHeight , Image . SCALE_SMOOTH ) ; iconImage = new BufferedImage ( scaledWidth , scaledHeight , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D graphics = iconImage . createGraphics ( ) ; graphics . drawImage ( scaledImage , 0 , 0 , null ) ; graphics . dispose ( ) ; } } if ( iconCache != null ) { iconCache . put ( icon . getId ( ) , iconImage ) ; } } } return iconImage ; } | Create or retrieve from cache an icon image for the icon row |
3,737 | private int indexRows ( TableIndex tableIndex , FeatureResultSet resultSet ) { int count = - 1 ; try { while ( ( progress == null || progress . isActive ( ) ) && resultSet . moveToNext ( ) ) { if ( count < 0 ) { count ++ ; } try { FeatureRow row = resultSet . getRow ( ) ; boolean indexed = index ( tableIndex , row . getId ( ) , row . getGeometry ( ) ) ; if ( indexed ) { count ++ ; } if ( progress != null ) { progress . addProgress ( 1 ) ; } } catch ( Exception e ) { log . log ( Level . SEVERE , "Failed to index feature. Table: " + tableIndex . getTableName ( ) + ", Position: " + resultSet . getPosition ( ) , e ) ; } } } finally { resultSet . close ( ) ; } return count ; } | Index the feature rows in the cursor |
3,738 | public UserCustomDao getUserDao ( String tableName ) { return UserCustomDao . readTable ( getGeoPackage ( ) . getName ( ) , connection , tableName ) ; } | Get a User Custom DAO from a table name |
3,739 | public MediaDao getMediaDao ( String tableName ) { MediaDao mediaDao = new MediaDao ( getUserDao ( tableName ) ) ; setContents ( mediaDao . getTable ( ) ) ; return mediaDao ; } | Get a related media table DAO |
3,740 | public List < Long > getMappingsForBase ( String tableName , long baseId ) { List < Long > relatedIds = new ArrayList < > ( ) ; UserMappingDao userMappingDao = getMappingDao ( tableName ) ; UserCustomResultSet resultSet = userMappingDao . queryByBaseId ( baseId ) ; try { while ( resultSet . moveToNext ( ) ) { UserMappingRow row = userMappingDao . getRow ( resultSet ) ; relatedIds . add ( row . getRelatedId ( ) ) ; } } finally { resultSet . close ( ) ; } return relatedIds ; } | Get the related id mappings for the base id |
3,741 | public List < Long > getMappingsForRelated ( String tableName , long relatedId ) { List < Long > baseIds = new ArrayList < > ( ) ; UserMappingDao userMappingDao = getMappingDao ( tableName ) ; UserCustomResultSet resultSet = userMappingDao . queryByRelatedId ( relatedId ) ; try { while ( resultSet . moveToNext ( ) ) { UserMappingRow row = userMappingDao . getRow ( resultSet ) ; baseIds . add ( row . getBaseId ( ) ) ; } } finally { resultSet . close ( ) ; } return baseIds ; } | Get the base id mappings for the related id |
3,742 | public boolean hasMapping ( String tableName , long baseId , long relatedId ) { UserMappingDao userMappingDao = getMappingDao ( tableName ) ; return userMappingDao . countByIds ( baseId , relatedId ) > 0 ; } | Determine if the base id and related id mapping exists |
3,743 | public static void execSQL ( Connection connection , String sql ) { Statement statement = null ; try { statement = connection . createStatement ( ) ; statement . execute ( sql ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to execute SQL statement: " + sql , e ) ; } finally { closeStatement ( statement , sql ) ; } } | Execute the SQL |
3,744 | public static ResultSet query ( Connection connection , String sql , String [ ] selectionArgs ) { PreparedStatement statement = null ; ResultSet resultSet = null ; try { statement = connection . prepareStatement ( sql ) ; setArguments ( statement , selectionArgs ) ; resultSet = statement . executeQuery ( ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to execute SQL statement: " + sql , e ) ; } finally { if ( resultSet == null ) { closeStatement ( statement , sql ) ; } } return resultSet ; } | Query for results |
3,745 | public static int count ( Connection connection , String sql , String [ ] selectionArgs ) { if ( ! sql . toLowerCase ( ) . contains ( " count(*) " ) ) { int index = sql . toLowerCase ( ) . indexOf ( " from " ) ; if ( index == - 1 ) { return - 1 ; } sql = "select count(*)" + sql . substring ( index ) ; } int count = querySingleInteger ( connection , sql , selectionArgs , true ) ; return count ; } | Attempt to count the results of the query |
3,746 | public static Integer max ( Connection connection , String table , String column , String where , String [ ] args ) { Integer max = null ; if ( count ( connection , table , where , args ) > 0 ) { StringBuilder maxQuery = new StringBuilder ( ) ; maxQuery . append ( "select max(" ) . append ( CoreSQLUtils . quoteWrap ( column ) ) . append ( ") from " ) . append ( CoreSQLUtils . quoteWrap ( table ) ) ; if ( where != null ) { maxQuery . append ( " where " ) . append ( where ) ; } String sql = maxQuery . toString ( ) ; max = querySingleInteger ( connection , sql , args , false ) ; } return max ; } | Get the max query result |
3,747 | private static int querySingleInteger ( Connection connection , String sql , String [ ] args , boolean allowEmptyResults ) { int result = 0 ; Object value = querySingleResult ( connection , sql , args , 0 , GeoPackageDataType . MEDIUMINT ) ; if ( value != null ) { result = ( ( Number ) value ) . intValue ( ) ; } else if ( ! allowEmptyResults ) { throw new GeoPackageException ( "Failed to query for single result. SQL: " + sql ) ; } return result ; } | Query the SQL for a single integer result |
3,748 | public static List < Object > querySingleColumnResults ( Connection connection , String sql , String [ ] args , int column , GeoPackageDataType dataType , Integer limit ) { ResultSetResult result = wrapQuery ( connection , sql , args ) ; List < Object > results = ResultUtils . buildSingleColumnResults ( result , column , dataType , limit ) ; return results ; } | Query for values from a single column up to the limit |
3,749 | public static List < List < Object > > queryResults ( Connection connection , String sql , String [ ] args , GeoPackageDataType [ ] dataTypes , Integer limit ) { ResultSetResult result = wrapQuery ( connection , sql , args ) ; List < List < Object > > results = ResultUtils . buildResults ( result , dataTypes , limit ) ; return results ; } | Query for values up to the limit |
3,750 | public static int delete ( Connection connection , String table , String where , String [ ] args ) { StringBuilder delete = new StringBuilder ( ) ; delete . append ( "delete from " ) . append ( CoreSQLUtils . quoteWrap ( table ) ) ; if ( where != null ) { delete . append ( " where " ) . append ( where ) ; } String sql = delete . toString ( ) ; PreparedStatement statement = null ; int count = 0 ; try { statement = connection . prepareStatement ( sql ) ; setArguments ( statement , args ) ; count = statement . executeUpdate ( ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to execute SQL delete statement: " + sql , e ) ; } finally { closeStatement ( statement , sql ) ; } return count ; } | Execute a deletion |
3,751 | public static int update ( Connection connection , String table , ContentValues values , String whereClause , String [ ] whereArgs ) { StringBuilder update = new StringBuilder ( ) ; update . append ( "update " ) . append ( CoreSQLUtils . quoteWrap ( table ) ) . append ( " set " ) ; int setValuesSize = values . size ( ) ; int argsSize = ( whereArgs == null ) ? setValuesSize : ( setValuesSize + whereArgs . length ) ; Object [ ] args = new Object [ argsSize ] ; int i = 0 ; for ( String colName : values . keySet ( ) ) { update . append ( ( i > 0 ) ? "," : "" ) ; update . append ( CoreSQLUtils . quoteWrap ( colName ) ) ; args [ i ++ ] = values . get ( colName ) ; update . append ( "=?" ) ; } if ( whereArgs != null ) { for ( i = setValuesSize ; i < argsSize ; i ++ ) { args [ i ] = whereArgs [ i - setValuesSize ] ; } } if ( whereClause != null ) { update . append ( " WHERE " ) ; update . append ( whereClause ) ; } String sql = update . toString ( ) ; PreparedStatement statement = null ; int count = 0 ; try { statement = connection . prepareStatement ( sql ) ; setArguments ( statement , args ) ; count = statement . executeUpdate ( ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to execute SQL update statement: " + sql , e ) ; } finally { closeStatement ( statement , sql ) ; } return count ; } | Update table rows |
3,752 | public static void setArguments ( PreparedStatement statement , Object [ ] selectionArgs ) throws SQLException { if ( selectionArgs != null ) { for ( int i = 0 ; i < selectionArgs . length ; i ++ ) { statement . setObject ( i + 1 , selectionArgs [ i ] ) ; } } } | Set the prepared statement arguments |
3,753 | public static void closeStatement ( Statement statement , String sql ) { if ( statement != null ) { try { statement . close ( ) ; } catch ( SQLException e ) { log . log ( Level . WARNING , "Failed to close SQL Statement: " + sql , e ) ; } } } | Close the statement |
3,754 | public static void closeResultSet ( ResultSet resultSet , String sql ) { if ( resultSet != null ) { try { resultSet . close ( ) ; } catch ( SQLException e ) { log . log ( Level . WARNING , "Failed to close SQL ResultSet: " + sql , e ) ; } } } | Close the ResultSet |
3,755 | public static void closeResultSetStatement ( ResultSet resultSet , String sql ) { if ( resultSet != null ) { try { resultSet . getStatement ( ) . close ( ) ; } catch ( SQLException e ) { log . log ( Level . WARNING , "Failed to close SQL ResultSet: " + sql , e ) ; } } } | Close the ResultSet Statement from which it was created which closes all ResultSets as well |
3,756 | public static ResultSetResult wrapQuery ( Connection connection , String sql , String [ ] selectionArgs ) { return new ResultSetResult ( query ( connection , sql , selectionArgs ) ) ; } | Perform the query and wrap as a result |
3,757 | public double [ ] getDerivedDimensions ( ) { Double width = getWidth ( ) ; Double height = getHeight ( ) ; if ( width == null || height == null ) { int dataWidth ; int dataHeight ; try { BufferedImage image = getDataImage ( ) ; dataWidth = image . getWidth ( ) ; dataHeight = image . getHeight ( ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to read the data image" , e ) ; } if ( width == null ) { width = ( double ) dataWidth ; if ( height != null ) { width *= ( height / dataHeight ) ; } } if ( height == null ) { height = ( double ) dataHeight ; if ( width != null ) { height *= ( width / dataWidth ) ; } } } return new double [ ] { width , height } ; } | Get the derived width and height from the values and icon data scaled as needed |
3,758 | public static void main ( String [ ] args ) throws Exception { boolean valid = true ; boolean requiredArguments = false ; String imageFormat = null ; boolean rawImage = false ; File inputDirectory = null ; TileFormatType tileType = null ; File geoPackageFile = null ; String tileTable = null ; for ( int i = 0 ; valid && i < args . length ; i ++ ) { String arg = args [ i ] ; if ( arg . startsWith ( ARGUMENT_PREFIX ) ) { String argument = arg . substring ( ARGUMENT_PREFIX . length ( ) ) ; switch ( argument ) { case ARGUMENT_IMAGE_FORMAT : if ( i < args . length ) { imageFormat = args [ ++ i ] ; } else { valid = false ; System . out . println ( "Error: Image Format argument '" + arg + "' must be followed by a image format" ) ; } break ; case ARGUMENT_RAW_IMAGE : rawImage = true ; break ; default : valid = false ; System . out . println ( "Error: Unsupported arg: '" + arg + "'" ) ; } } else { if ( inputDirectory == null ) { inputDirectory = new File ( arg ) ; } else if ( tileType == null ) { tileType = TileFormatType . valueOf ( arg . toUpperCase ( ) ) ; } else if ( geoPackageFile == null ) { geoPackageFile = new File ( arg ) ; } else if ( tileTable == null ) { tileTable = arg ; requiredArguments = true ; } else { valid = false ; System . out . println ( "Error: Unsupported extra argument: " + arg ) ; } } } if ( ! valid || ! requiredArguments ) { printUsage ( ) ; } else { try { readTiles ( geoPackageFile , tileTable , inputDirectory , imageFormat , tileType , rawImage ) ; } catch ( Exception e ) { printUsage ( ) ; throw e ; } } } | Main method to read tiles from the file system into a GeoPackage |
3,759 | public int update ( ContentValues values , String whereClause , String [ ] whereArgs ) { return SQLUtils . update ( connection , getTableName ( ) , values , whereClause , whereArgs ) ; } | Update all rows matching the where clause with the provided values |
3,760 | private static void finish ( ) { if ( progress . getMax ( ) != null ) { StringBuilder output = new StringBuilder ( ) ; output . append ( "\nTile Generation: " ) . append ( progress . getProgress ( ) ) . append ( " of " ) . append ( progress . getMax ( ) ) ; if ( geoPackage != null ) { try { GeoPackageTextOutput textOutput = new GeoPackageTextOutput ( geoPackage ) ; output . append ( "\n\n" ) ; output . append ( textOutput . header ( ) ) ; output . append ( "\n\n" ) ; output . append ( textOutput . tileTable ( tileTable ) ) ; } finally { geoPackage . close ( ) ; } } System . out . println ( output . toString ( ) ) ; } } | Finish tile generation |
3,761 | public short getPixelValue ( BufferedImage image , int x , int y ) { validateImageType ( image ) ; WritableRaster raster = image . getRaster ( ) ; short pixelValue = getPixelValue ( raster , x , y ) ; return pixelValue ; } | Get the pixel value as an unsigned short |
3,762 | public short getPixelValue ( WritableRaster raster , int x , int y ) { Object pixelData = raster . getDataElements ( x , y , null ) ; short sdata [ ] = ( short [ ] ) pixelData ; if ( sdata . length != 1 ) { throw new UnsupportedOperationException ( "This method is not supported by this color model" ) ; } short pixelValue = sdata [ 0 ] ; return pixelValue ; } | Get the pixel value as an unsigned short from the raster and the coordinate |
3,763 | public short [ ] getPixelValues ( BufferedImage image ) { validateImageType ( image ) ; WritableRaster raster = image . getRaster ( ) ; short [ ] pixelValues = getPixelValues ( raster ) ; return pixelValues ; } | Get the pixel values of the buffered image as unsigned shorts |
3,764 | public int [ ] getUnsignedPixelValues ( BufferedImage image ) { short [ ] pixelValues = getPixelValues ( image ) ; int [ ] unsignedPixelValues = getUnsignedPixelValues ( pixelValues ) ; return unsignedPixelValues ; } | Get the pixel values of the buffered image as 16 bit unsigned integer values |
3,765 | public short [ ] getPixelValues ( WritableRaster raster ) { DataBufferUShort buffer = ( DataBufferUShort ) raster . getDataBuffer ( ) ; short [ ] pixelValues = buffer . getData ( ) ; return pixelValues ; } | Get the pixel values of the raster as unsigned shorts |
3,766 | public int [ ] getUnsignedPixelValues ( WritableRaster raster ) { short [ ] pixelValues = getPixelValues ( raster ) ; int [ ] unsignedPixelValues = getUnsignedPixelValues ( pixelValues ) ; return unsignedPixelValues ; } | Get the pixel values of the raster as 16 bit unsigned integer values |
3,767 | public void validateImageType ( BufferedImage image ) { if ( image == null ) { throw new GeoPackageException ( "The image is null" ) ; } if ( image . getColorModel ( ) . getTransferType ( ) != DataBuffer . TYPE_USHORT ) { throw new GeoPackageException ( "The coverage data tile is expected to be a 16 bit unsigned short, actual: " + image . getColorModel ( ) . getTransferType ( ) ) ; } } | Validate that the image type is an unsigned short |
3,768 | public byte [ ] getImageBytes ( BufferedImage image ) { byte [ ] bytes = null ; try { bytes = ImageUtils . writeImageToBytes ( image , ImageUtils . IMAGE_FORMAT_PNG ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to write image to " + ImageUtils . IMAGE_FORMAT_PNG + " bytes" , e ) ; } return bytes ; } | Get the image as PNG bytes |
3,769 | public void setPixelValue ( WritableRaster raster , int x , int y , short pixelValue ) { short data [ ] = new short [ ] { pixelValue } ; raster . setDataElements ( x , y , data ) ; } | Set the unsigned short pixel value into the image raster |
3,770 | public void setPixelValue ( WritableRaster raster , int x , int y , int unsignedPixelValue ) { short pixelValue = getPixelValue ( unsignedPixelValue ) ; setPixelValue ( raster , x , y , pixelValue ) ; } | Set the unsigned 16 bit integer pixel value into the image raster |
3,771 | public Stroke getStroke ( ) { Stroke theStroke = stroke ; if ( theStroke == null ) { theStroke = new BasicStroke ( strokeWidth ) ; stroke = theStroke ; } return theStroke ; } | Get the stroke created from the stroke width |
3,772 | public List < StyleMappingRow > queryByBaseFeatureId ( long id ) { List < StyleMappingRow > rows = new ArrayList < > ( ) ; UserCustomResultSet resultSet = queryByBaseId ( id ) ; try { while ( resultSet . moveToNext ( ) ) { rows . add ( getRow ( resultSet ) ) ; } } finally { resultSet . close ( ) ; } return rows ; } | Query for style mappings by base id |
3,773 | public ImageRectangle round ( ) { return new ImageRectangle ( Math . round ( left ) , Math . round ( top ) , Math . round ( right ) , Math . round ( bottom ) ) ; } | Round the floating point rectangle to an integer rectangle |
3,774 | private static int writeGeoPackageFormatTiles ( TileDao tileDao , File directory , String imageFormat , Integer width , Integer height , boolean rawImage ) throws IOException { int tileCount = 0 ; for ( long zoomLevel = tileDao . getMinZoom ( ) ; zoomLevel <= tileDao . getMaxZoom ( ) ; zoomLevel ++ ) { TileMatrix tileMatrix = tileDao . getTileMatrix ( zoomLevel ) ; LOGGER . log ( Level . INFO , "Zoom Level: " + zoomLevel + ", Width: " + tileMatrix . getMatrixWidth ( ) + ", Height: " + tileMatrix . getMatrixHeight ( ) + ", Max Tiles: " + ( tileMatrix . getMatrixWidth ( ) * tileMatrix . getMatrixHeight ( ) ) ) ; File zDirectory = new File ( directory , String . valueOf ( zoomLevel ) ) ; int zoomCount = 0 ; TileResultSet tileResultSet = tileDao . queryForTile ( zoomLevel ) ; while ( tileResultSet . moveToNext ( ) ) { TileRow tileRow = tileResultSet . getRow ( ) ; if ( tileRow != null ) { byte [ ] tileData = tileRow . getTileData ( ) ; if ( tileData != null ) { File xDirectory = new File ( zDirectory , String . valueOf ( tileRow . getTileColumn ( ) ) ) ; xDirectory . mkdirs ( ) ; File imageFile = new File ( xDirectory , String . valueOf ( tileRow . getTileRow ( ) ) + "." + imageFormat ) ; if ( rawImage ) { FileOutputStream fos = new FileOutputStream ( imageFile ) ; fos . write ( tileData ) ; fos . close ( ) ; } else { BufferedImage tileImage = tileRow . getTileDataImage ( ) ; int tileWidth = width != null ? width : tileImage . getWidth ( ) ; int tileHeight = height != null ? height : tileImage . getHeight ( ) ; Image drawImage = null ; if ( tileImage . getWidth ( ) != tileWidth || tileImage . getHeight ( ) != tileHeight ) { drawImage = tileImage . getScaledInstance ( tileWidth , tileHeight , Image . SCALE_SMOOTH ) ; } else { drawImage = tileImage ; } BufferedImage image = ImageUtils . createBufferedImage ( tileWidth , tileHeight , imageFormat ) ; Graphics graphics = image . getGraphics ( ) ; graphics . drawImage ( drawImage , 0 , 0 , null ) ; ImageIO . write ( image , imageFormat , imageFile ) ; } zoomCount ++ ; if ( zoomCount % ZOOM_PROGRESS_FREQUENCY == 0 ) { LOGGER . log ( Level . INFO , "Zoom " + zoomLevel + " Tile Progress... " + zoomCount ) ; } } } } tileResultSet . close ( ) ; LOGGER . log ( Level . INFO , "Zoom " + zoomLevel + " Tiles: " + zoomCount ) ; tileCount += zoomCount ; } return tileCount ; } | Write GeoPackage formatted tiles |
3,775 | private static double getLength ( BoundingBox boundingBox , ProjectionTransform toWebMercatorTransform ) { BoundingBox transformedBoundingBox = boundingBox . transform ( toWebMercatorTransform ) ; return getLength ( transformedBoundingBox ) ; } | Get the length of the bounding box projected using the transformation |
3,776 | private static double getLength ( BoundingBox boundingBox ) { double width = boundingBox . getMaxLongitude ( ) - boundingBox . getMinLongitude ( ) ; double height = boundingBox . getMaxLatitude ( ) - boundingBox . getMinLatitude ( ) ; double length = Math . min ( width , height ) ; return length ; } | Get the length of the bounding box |
3,777 | public GeoPackage getOrOpen ( String name , File file ) { return getOrOpen ( name , file , true ) ; } | Get the cached GeoPackage or open and cache the GeoPackage file |
3,778 | public static ImageRectangle getRectangle ( long width , long height , BoundingBox boundingBox , BoundingBox boundingBoxSection ) { ImageRectangleF rectF = getFloatRectangle ( width , height , boundingBox , boundingBoxSection ) ; ImageRectangle rect = rectF . round ( ) ; return rect ; } | Get a rectangle using the tile width height bounding box and the bounding box section within the outer box to build the rectangle from |
3,779 | public static ImageRectangleF getRoundedFloatRectangle ( long width , long height , BoundingBox boundingBox , BoundingBox boundingBoxSection ) { ImageRectangle rect = getRectangle ( width , height , boundingBox , boundingBoxSection ) ; ImageRectangleF rectF = new ImageRectangleF ( rect ) ; return rectF ; } | Get a rectangle with rounded floating point boundaries using the tile width height bounding box and the bounding box section within the outer box to build the rectangle from |
3,780 | public static ImageRectangleF getFloatRectangle ( long width , long height , BoundingBox boundingBox , BoundingBox boundingBoxSection ) { float left = TileBoundingBoxUtils . getXPixel ( width , boundingBox , boundingBoxSection . getMinLongitude ( ) ) ; float right = TileBoundingBoxUtils . getXPixel ( width , boundingBox , boundingBoxSection . getMaxLongitude ( ) ) ; float top = TileBoundingBoxUtils . getYPixel ( height , boundingBox , boundingBoxSection . getMaxLatitude ( ) ) ; float bottom = TileBoundingBoxUtils . getYPixel ( height , boundingBox , boundingBoxSection . getMinLatitude ( ) ) ; ImageRectangleF rect = new ImageRectangleF ( left , top , right , bottom ) ; return rect ; } | Get a rectangle with floating point boundaries using the tile width height bounding box and the bounding box section within the outer box to build the rectangle from |
3,781 | public static synchronized String getProperty ( String key , boolean required ) { if ( mProperties == null ) { mProperties = initializeConfigurationProperties ( ) ; } String value = mProperties . getProperty ( key ) ; if ( value == null && required ) { throw new RuntimeException ( "Property not found: " + key ) ; } return value ; } | Get a property by key |
3,782 | public static String getProperty ( String base , String property ) { return getProperty ( base , property , true ) ; } | Get a required property by base property and property name |
3,783 | public static Integer getIntegerProperty ( String key , boolean required ) { Integer value = null ; String stringValue = getProperty ( key , required ) ; if ( stringValue != null ) { value = Integer . valueOf ( stringValue ) ; } return value ; } | Get an integer property by key |
3,784 | public static Float getFloatProperty ( String key , boolean required ) { Float value = null ; String stringValue = getProperty ( key , required ) ; if ( stringValue != null ) { value = Float . valueOf ( stringValue ) ; } return value ; } | Get a float by key |
3,785 | public static Boolean getBooleanProperty ( String key , boolean required ) { Boolean value = null ; String stringValue = getProperty ( key , required ) ; if ( stringValue != null ) { value = Boolean . valueOf ( stringValue ) ; } return value ; } | Get a boolean by key |
3,786 | public static Boolean getBooleanProperty ( String base , String property , boolean required ) { return getBooleanProperty ( base + JavaPropertyConstants . PROPERTY_DIVIDER + property , required ) ; } | Get a boolean property by base property and property name |
3,787 | public static Color getColorProperty ( String key , boolean required ) { Color value = null ; String redProperty = key + JavaPropertyConstants . PROPERTY_DIVIDER + JavaPropertyConstants . COLOR_RED ; String greenProperty = key + JavaPropertyConstants . PROPERTY_DIVIDER + JavaPropertyConstants . COLOR_GREEN ; String blueProperty = key + JavaPropertyConstants . PROPERTY_DIVIDER + JavaPropertyConstants . COLOR_BLUE ; String alphaProperty = key + JavaPropertyConstants . PROPERTY_DIVIDER + JavaPropertyConstants . COLOR_ALPHA ; Integer red = getIntegerProperty ( redProperty , required ) ; Integer green = getIntegerProperty ( greenProperty , required ) ; Integer blue = getIntegerProperty ( blueProperty , required ) ; Integer alpha = getIntegerProperty ( alphaProperty , required ) ; if ( red != null && green != null && blue != null && alpha != null ) { value = new Color ( red , green , blue , alpha ) ; } return value ; } | Get a color by key |
3,788 | public static Color getColorProperty ( String base , String property ) { return getColorProperty ( base , property , true ) ; } | Get a required color property by base property and property name |
3,789 | public void resize ( int maxCacheSize ) { setMaxCacheSize ( maxCacheSize ) ; for ( FeatureCache cache : tableCache . values ( ) ) { cache . resize ( maxCacheSize ) ; } } | Resize all caches and update the max cache size |
3,790 | public void setFlag ( CodecFlag flag ) throws JavaAVException { if ( flag == null ) throw new JavaAVException ( "Could not set codec flag. Null provided." ) ; flags . add ( flag ) ; } | Set a codec flag . |
3,791 | private void createImageBuffer ( ) throws JavaAVException { int format = pixelFormat . value ( ) ; int width = avContext . width ( ) ; int height = avContext . height ( ) ; picture = new AVPicture ( ) ; if ( avpicture_alloc ( picture , format , width , height ) < 0 ) throw new JavaAVException ( "Could not allocate picture." ) ; } | Create resampled picture buffer . This is only needed if the decoded picture format differs from the desired format . |
3,792 | public static Codec getEncoderById ( CodecID codecId ) throws JavaAVException { if ( codecId == null ) throw new NullPointerException ( "CodecID is null." ) ; AVCodec avCodec = avcodec_find_encoder ( codecId . value ( ) ) ; if ( avCodec == null || avCodec . isNull ( ) ) throw new JavaAVException ( "Encoder not found: " + codecId . toString ( ) ) ; Codec codec = new Codec ( ) ; codec . avCodec = avCodec ; return codec ; } | Create a new encoder with specified codec id . |
3,793 | public static Codec getDecoderById ( CodecID codecId ) throws JavaAVException { if ( codecId == null ) throw new NullPointerException ( "CodecID is null." ) ; AVCodec avCodec = avcodec_find_decoder ( codecId . value ( ) ) ; if ( avCodec == null || avCodec . isNull ( ) ) throw new JavaAVException ( "Decoder not found: " + codecId . toString ( ) ) ; Codec codec = new Codec ( ) ; codec . avCodec = avCodec ; return codec ; } | Create a new decoder with specified codec id . |
3,794 | public static Codec getEncoderByName ( String avCodecName ) throws JavaAVException { if ( avCodecName == null || avCodecName . isEmpty ( ) ) throw new NullPointerException ( "Codec name is null or empty." ) ; AVCodec avCodec = avcodec_find_encoder_by_name ( avCodecName ) ; if ( avCodec == null || avCodec . isNull ( ) ) throw new JavaAVException ( "Encoder not found: " + avCodecName ) ; Codec codec = new Codec ( ) ; codec . avCodec = avCodec ; return codec ; } | Create a new encoder with specified codec name . |
3,795 | public static Codec getDecoderByName ( String avCodecName ) throws JavaAVException { if ( avCodecName == null || avCodecName . isEmpty ( ) ) throw new NullPointerException ( "Codec name is null or empty." ) ; AVCodec avCodec = avcodec_find_decoder_by_name ( avCodecName ) ; if ( avCodec == null || avCodec . isNull ( ) ) throw new JavaAVException ( "Decoder not found: " + avCodecName ) ; Codec codec = new Codec ( ) ; codec . avCodec = avCodec ; return codec ; } | Create a new decoder with specified codec name . |
3,796 | public static String [ ] getInstalledCodecs ( ) { Set < String > names = new TreeSet < String > ( ) ; AVCodec codec = null ; while ( ( codec = av_codec_next ( codec ) ) != null ) { String shortName = codec . name ( ) . getString ( ) ; String type = MediaType . byId ( codec . type ( ) ) . toString ( ) . substring ( 0 , 1 ) ; String longName = codec . long_name ( ) . getString ( ) ; names . add ( String . format ( "%-17s [%s] %s" , shortName , type , longName ) ) ; } return names . toArray ( new String [ 0 ] ) ; } | Get all names of codecs that are compiled into FFmpeg . |
3,797 | public MediaFrame readFrame ( ) throws JavaAVException { MediaFrame mediaFrame = new MediaFrame ( ) ; while ( mediaFrame != null && ! mediaFrame . hasFrame ( ) ) { if ( av_read_frame ( formatContext , avPacket ) < 0 ) { if ( videoDecoders . get ( avPacket . stream_index ( ) ) != null ) { avPacket . data ( null ) ; avPacket . size ( 0 ) ; } else { return null ; } } MediaPacket mediaPacket = new MediaPacket ( avPacket ) ; Decoder decoder ; if ( ( decoder = videoDecoders . get ( avPacket . stream_index ( ) ) ) != null ) { mediaFrame = decoder . decodeVideo ( mediaPacket ) ; } else if ( ( decoder = audioDecoders . get ( avPacket . stream_index ( ) ) ) != null ) { mediaFrame = decoder . decodeAudio ( mediaPacket ) ; } av_free_packet ( avPacket ) ; mediaPacket . clear ( ) ; } return mediaFrame ; } | Consecutively retrieves media frames from previously specified input source . The media type of the returned frame may alter between consecutive calls . One call may return an audio frame and the next call may return a video frame . |
3,798 | public static int getFormatDepth ( SampleFormat format ) { switch ( format ) { case U8 : case U8P : return 1 ; case S16 : case S16P : return 2 ; case S32 : case S32P : return 4 ; case FLT : case FLTP : return 4 ; case DBL : case DBLP : return 8 ; default : return 0 ; } } | Get number of bytes per sample for specified sample format . |
3,799 | public synchronized void clear ( ) { for ( int i = 0 ; i < planes ; i ++ ) { readPointer [ i ] = writePointer [ i ] = 0 ; bytesToRead [ i ] = 0 ; bytesToWrite [ i ] = buffer [ i ] . capacity ( ) ; } } | Resets the read and write pointers . The internal buffer remains unaffected . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.