private void closeRequest() {
   requests.remove(request);
   try {
     request.close();
   } catch (IOException e) {
     log.error(String.format("Error closing request [%s]", request.getIdentifier().getUri()), e);
   }
 }
 /**
  * Shuts down the executor service and closes any in-flight requests.
  *
  * @throws IOException if temp files could not be deleted.
  */
 public void close() throws IOException {
   executorService.shutdownNow();
   for (IdentificationRequest request : requests) {
     request.close();
   }
 }
예제 #3
0
    /**
     * Run droid identification on file
     *
     * @param filePath Absolute file path
     * @return Result list
     * @throws FileNotFoundException
     * @throws IOException
     */
    @Override
    public HashMap<String, String> identify(File file) throws FileNotFoundException {
        HashMap<String, String> droidIdRes = new HashMap<String, String>();
        InputStream in = null;
        IdentificationRequest request = null;

        try {
            URI resourceUri = file.toURI();
            in = new FileInputStream(file);
            LOG.debug("Identification of resource: " + resourceUri.toString());
            RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), file.getName());
            LOG.debug("File length: " + file.length());
            LOG.debug("File modified: " + file.lastModified());
            LOG.debug("File name: " + file.getName());
            RequestIdentifier identifier = new RequestIdentifier(resourceUri);
            request = new FileSystemIdentificationRequest(metaData, identifier);
            request.open(in);
            IdentificationResultCollection results = bsi.matchBinarySignatures(request);
            bsi.removeLowerPriorityHits(results);
            if (results == null || results.getResults() == null || results.getResults().isEmpty()) {
                LOG.debug("No identification result");
            } else {
                List<IdentificationResult> result = results.getResults();
                if (result != null && !result.isEmpty()) {
                    for (IdentificationResult ir : result) {
                        String mime = ir.getMimeType();
                        if (mime != null && !mime.isEmpty()) {
                            // take first mime, ignore others
                            if (!droidIdRes.containsKey("mime")) {
                                droidIdRes.put("mime", mime);
                            }
                        }
                        String puid = ir.getPuid();
                        if (puid != null && !puid.isEmpty()) {
                            // take first puid, ignore others
                            if (!droidIdRes.containsKey("puid")) {
                                droidIdRes.put("puid", puid);
                            }
                        }
                    }
                }
            }
            in.close();
            request.close();
        } catch (IOException ex) {
            LOG.error("I/O Exception", ex);
        } finally {
            try {
                in.close();
                request.close();
            } catch (IOException _) {
            }
        }
        if (!droidIdRes.containsKey("mime")) {
            droidIdRes.put("mime", MIME_UNKNOWN);
        }
        if (!droidIdRes.containsKey("puid")) {
            droidIdRes.put("puid", "fmt/0");
        }
        return droidIdRes;
    }