Package uk.gov.nationalarchives.droid.core.interfaces

Examples of uk.gov.nationalarchives.droid.core.interfaces.IdentificationResultCollection


    /**
     * {@inheritDoc}
     */
    @Override
    public IdentificationResultCollection matchBinarySignatures(IdentificationRequest request) {
        IdentificationResultCollection results = new IdentificationResultCollection(request);
        results.setRequestMetaData(request.getRequestMetaData());
        ByteReader byteReader = new IdentificationRequestByteReaderAdapter(request);
        sigFile.runFileIdentification(byteReader);
        final int numHits = byteReader.getNumHits();
        for (int i = 0; i < numHits; i++) {
            FileFormatHit hit = byteReader.getHit(i);
            IdentificationResultImpl result = new IdentificationResultImpl();
            result.setMimeType(hit.getMimeType());
            result.setName(hit.getFileFormatName());
            result.setVersion(hit.getFileFormatVersion());
            result.setPuid(hit.getFileFormatPUID());
            result.setMethod(IdentificationMethod.BINARY_SIGNATURE);
            results.addResult(result);
        }
        results.setFileLength(request.size());
        results.setRequestMetaData(request.getRequestMetaData());
        return results;
    }
View Full Code Here


     * {@inheritDoc}
     */
    @Override
    public IdentificationResultCollection matchExtensions(
            IdentificationRequest request, boolean allExtensions) {
        IdentificationResultCollection results = new IdentificationResultCollection(request);
        results.setRequestMetaData(request.getRequestMetaData());
        String fileExtension = request.getExtension();
        if (fileExtension != null && !fileExtension.isEmpty()) {
            List<FileFormat> fileFormats;
            if (allExtensions) {
                fileFormats = sigFile.getFileFormatsForExtension(fileExtension);
            } else {
                fileFormats = sigFile.getTentativeFormatsForExtension(fileExtension);
            }
            if (fileFormats != null) {
                for (FileFormat format : fileFormats) {
                    IdentificationResultImpl result = new IdentificationResultImpl();
                    result.setName(format.getName());
                    result.setVersion(format.getVersion());
                    result.setPuid(format.getPUID());
                    result.setMimeType(format.getMimeType());
                    result.setMethod(IdentificationMethod.EXTENSION);
                    results.addResult(result);
                }
            }
        }
        results.setFileLength(request.size());
        results.setRequestMetaData(request.getRequestMetaData());
        return results;
    }   
View Full Code Here

        identifier.setParentId(1L);
       
        IdentificationRequest request = new FileSystemIdentificationRequest(metaData, identifier);
        request.open(in);

        IdentificationResultCollection resultsCollection = droid.matchBinarySignatures(request);
        List<IdentificationResult> results = resultsCollection.getResults();
       
        assertEquals(EXPECTED_HITS, results.size());
        Iterator<IdentificationResult> iter = results.iterator();
        while (iter.hasNext()) {
            IdentificationResult result = iter.next();
View Full Code Here

        identifier.setParentId(1L);
       
        IdentificationRequest request = new FileSystemIdentificationRequest(metaData, identifier);
        request.open(in);

        IdentificationResultCollection resultsCollection = droid.matchBinarySignatures(request);
        List<IdentificationResult> results = resultsCollection.getResults();
       
        assertEquals(EXPECTED_HITS, results.size());
       
        Iterator<IdentificationResult> iter = results.iterator();
        while (iter.hasNext()) {
View Full Code Here

        identifier.setParentId(1L);
       
        IdentificationRequest request = new FileSystemIdentificationRequest(metaData, identifier);
        request.open(in);

        IdentificationResultCollection resultsCollection = droid.matchBinarySignatures(request);
        List<IdentificationResult> results = resultsCollection.getResults();
       
        assertEquals(EXPECTED_HITS, results.size());
       
        Iterator<IdentificationResult> iter = results.iterator();
        while (iter.hasNext()) {
View Full Code Here

       
        IdentificationRequest request = new FileSystemIdentificationRequest(metaData, identifier);
        request.open(in);
//        IdentificationRequest request = ResourceWrapperFactoryImpl.newResourceWrapper(resourceUri, 1L);
       
        IdentificationResultCollection results = droid.matchBinarySignatures(request);
       
//        ArgumentCaptor<IdentificationResultCollection> resultCaptor =
//            ArgumentCaptor.forClass(IdentificationResultCollection.class);
//        verify(resultHandler).handle(resultCaptor.capture());
       
        IdentificationResult result = results.getResults().iterator().next();
        assertEquals("fmt/18", result.getPuid());
        assertEquals(1L, results.getCorrelationId().getId());
        assertEquals(IdentificationMethod.BINARY_SIGNATURE, result.getMethod());
        assertEquals("application/pdf", result.getMimeType());
        assertEquals("Acrobat PDF 1.4 - Portable Document Format", result.getName());
       
    }
View Full Code Here

        // old code blocking identification:
        Callable<IdentificationResultCollection> callable = new Callable<IdentificationResultCollection>() {
            @Override
            public IdentificationResultCollection call() throws IOException {
                droidCore.setMaxBytesToScan(maxBytesToScan);
                IdentificationResultCollection results = droidCore.matchBinarySignatures(request);
                return results;
            }
        };
       
        FutureTask<IdentificationResultCollection> task = new SubmissionFutureTask(callable, request);
View Full Code Here

        }
    }

    private IdentificationResultCollection handleExtensions(IdentificationRequest request,
            IdentificationResultCollection results) {
        IdentificationResultCollection extensionResults = results;
        try {
            List<IdentificationResult> resultList = results.getResults();
            if (resultList != null && resultList.isEmpty()) {
                // If we call matchExtensions with "true", it will match
                // ALL files formats which have a given extension.
                // If "false", it will only match file formats for which
                // there is no other signature defined.
                IdentificationResultCollection checkExtensionResults =
                    droidCore.matchExtensions(request, matchAllExtensions);
                if (checkExtensionResults != null) {
                    extensionResults = checkExtensionResults;
                }
            } else {
View Full Code Here

        String containerFormat = getContainerFormat(results);
        try {
            if (containerFormatResolver != null && containerFormat != null) {
                ContainerIdentifier containerIdentifier = containerIdentifierFactory.getIdentifier(containerFormat);
                containerIdentifier.setMaxBytesToScan(maxBytesToScan);
                IdentificationResultCollection containerResults = containerIdentifier.submit(request);
                droidCore.removeLowerPriorityHits(containerResults);
                droidCore.checkForExtensionsMismatches(containerResults, request.getExtension());
                containerResults.setFileLength(request.size());
                containerResults.setRequestMetaData(request.getRequestMetaData());
                return containerResults.getResults().isEmpty() ? null : containerResults;
            }
        //CHECKSTYLE:OFF - rules say don't catch this, but other code keeps on throwing them.
            // Don't prejudice any results so far because other code isn't following 'the rules'.
        } catch (Exception e) {
        //CHECKSTYLE:ON
View Full Code Here

        @Override
        protected void done() {
            boolean jobCountDecremented = false;
            try {
                generateHash(request);
                IdentificationResultCollection results = get();
                IdentificationResultCollection containerResults = handleContainer(request, results);
                if (containerResults == null) {
                    // no container results - process the normal results.
                    droidCore.removeLowerPriorityHits(results);
                    results = handleExtensions(request, results);
                   
View Full Code Here

TOP

Related Classes of uk.gov.nationalarchives.droid.core.interfaces.IdentificationResultCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.