19 package org.sleuthkit.autopsy.geolocation;
 
   21 import java.nio.file.Path;
 
   22 import java.nio.file.Paths;
 
   23 import java.sql.Connection;
 
   24 import java.sql.DriverManager;
 
   25 import java.sql.ResultSet;
 
   26 import java.sql.SQLException;
 
   27 import java.sql.Statement;
 
   28 import org.jxmapviewer.OSMTileFactoryInfo;
 
   29 import org.jxmapviewer.viewer.TileFactoryInfo;
 
   35 final class MBTilesFileConnector {
 
   37     private final static String DB_URL = 
"jdbc:sqlite:%s";
 
   38     private final static String TILE_QUERY = 
"SELECT tile_data FROM images WHERE tile_id = '%s'";
 
   39     private final static String FORMAT_QUERY = 
"SELECT value FROM metadata WHERE name='format'";
 
   40     private final TileFactoryInfo factoryInfo;
 
   41     private final String connectionString;
 
   52     static boolean isValidMBTileRasterFile(String filePath) 
throws SQLException {
 
   53         Path p = Paths.get(filePath);
 
   54         if (!p.toFile().exists()) {
 
   58         String path = filePath.replaceAll(
"\\\\", 
"/");
 
   59         String url = String.format(DB_URL, path);
 
   61         try (Connection connection = DriverManager.getConnection(url)) {
 
   62             try (Statement statement = connection.createStatement();
 
   63                     ResultSet resultSet = statement.executeQuery(FORMAT_QUERY)) {
 
   64                 if (resultSet.next()) {
 
   65                     String format = resultSet.getString(1);
 
   66                     return format.equals(
"jpg");
 
   80     MBTilesFileConnector(String tileFilePath) 
throws GeoLocationDataException {
 
   81        String path = tileFilePath.replaceAll(
"\\\\", 
"/");
 
   82        connectionString = String.format(DB_URL, path);
 
   83        factoryInfo = 
new MBTilesInfo();  
 
   91     TileFactoryInfo getInfo() {
 
  105     byte[] getTileBytes(String tileID) 
throws GeoLocationDataException {
 
  106         String query = String.format(TILE_QUERY, tileID);
 
  108         try (Connection connection = DriverManager.getConnection(connectionString)) {
 
  109             try (Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) {
 
  110                 if (resultSet.next()) {
 
  111                     return resultSet.getBytes(1);
 
  114         } 
catch (SQLException ex) {
 
  115             throw new GeoLocationDataException(String.format(
"Failed to get tile %s", tileID), ex);
 
  127             super(
"MBTilesFile", 
"");
 
  134             int osmZoom = getTotalMapZoom() - zoom;
 
  135             return String.format(
"%d/%d/%d", osmZoom, x, y);
 
String getTileUrl(int x, int y, int zoom)