Esempio n. 1
0
 public MediaFileDescriptor buildMediaDescriptor(File f) {
   MediaFileDescriptor id = new MediaFileDescriptor();
   int[] data;
   String md5;
   try {
     id.setPath(f.getCanonicalPath());
     id.setMtime(f.lastModified());
     id.setSize(f.length());
     // generate thumbnails only for images, not video
     if (Utils.isValideImageName(f.getName())) {
       MetaDataFinder mdf = new MetaDataFinder(f);
       double[] latLon = mdf.getLatLong();
       if (latLon != null) {
         id.setLat(latLon[0]);
         id.setLon(latLon[1]);
       }
       // bufferize images in memory, read directly from file for others
       ByteArrayInputStream fbi = this.readFileToMemory(f);
       id.setHash(new ImageHash().generateSignature(fbi));
       fbi.reset();
       md5 = generateMD5(fbi);
       id.setMd5Digest(md5);
     } else {
       md5 = generateMD5(f);
       id.setMd5Digest(md5);
     }
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     System.err.println("Error processing  file " + f.getName());
     e.printStackTrace();
   }
   return id;
 }
Esempio n. 2
0
  public void generateAndSave(File f) {
    System.out.print(".");
    currentProgressSize += f.length() / 1024;
    try {
      MediaFileDescriptor mf = ts.getMediaFileDescriptor(f.getCanonicalPath());
      Logger.getLogger().err("MediaIndexer.generateAndSave " + f + " descriptor: " + mf);

      if ((mf != null) && (f.lastModified() == mf.getMtime())) {
        // Descriptor exists with same mtime
        Logger.getLogger()
            .err("MediaIndexer.generateImageDescriptor() Already in DB, ignoring with same mtime");
        Logger.getLogger().err("MediaIndexer.generateImageDescriptor() In   DB : " + mf.getMtime());
        Logger.getLogger()
            .err("MediaIndexer.generateImageDescriptor() On Disk : " + f.lastModified());
        boolean update = false;

        if (forceGPSUpdate) {
          //  MediaFileDescriptor mfd = ts.getMediaFileDescriptor(f.getCanonicalPath());
          MetaDataFinder mdf = new MetaDataFinder(f);
          double latLon[] = mdf.getLatLong();
          Logger.getLogger().err("MediaIndexer.generateAndSave working on " + f);
          if (latLon != null) {
            mf.setLat(latLon[0]);
            mf.setLon(latLon[1]);
            Logger.getLogger().err("MediaIndexer : forced update for GPS data for " + f);
            updateToDB(mf);
            update = true;
          }
        }
        if (forceHashUpdate || (mf.getHash() == null)) {
          if (Utils.isValideImageName(f.getName())) {
            mf.setHash(new ImageHash().generateSignature(f.getCanonicalPath()));
            updateToDB(mf);
            update = true;
          }
        }
        // if (update) {
        this.fileCreatedUpdated(false, update);
        // }
      } else {
        Logger.getLogger().err("MediaIndexer.generateAndSave building descriptor");
        MediaFileDescriptor id = this.buildMediaDescriptor(f);
        if (id != null) {
          if ((mf != null) && (f.lastModified() != mf.getMtime())) {
            // we need to update it
            updateToDB(id);
            this.fileCreatedUpdated(false, true);
          } else {
            saveToDB(id);
            this.fileCreatedUpdated(true, false);
          }
          if (log.isEnabled()) {
            log.log(
                f.getCanonicalPath()
                    + " ..... size  "
                    + (f.length() / 1024)
                    + " KiB OK "
                    + executorService.getActiveCount()
                    + " threads running");
          }
        } else {
          this.fileCreatedUpdated(false, false);
        }
      }
    } catch (IOException e) {
      System.err.println("Error processing  file " + f.getName());
      e.printStackTrace();
    }
  }