Package org.apache.sis.storage

Examples of org.apache.sis.storage.ProbeResult


        /*
         * At this point, the readability status has been determined. The file version number
         * is unknown if we are able to open the file only through the UCAR library.
         */
        if (hasVersion) {
            return new ProbeResult(isSupported, MIME_TYPE, Version.valueOf(version));
        }
        return isSupported ? new ProbeResult(true, MIME_TYPE, null) : ProbeResult.UNSUPPORTED_STORAGE;
    }
View Full Code Here


     */
    @Test
    public void testProbeContentFromReader() throws DataStoreException {
        final XMLStoreProvider p = new XMLStoreProvider();
        final StorageConnector c = new StorageConnector(new StringReader(XMLStoreTest.XML));
        final ProbeResult      r = p.probeContent(c);
        c.closeAllExcept(null);
        assertTrue  ("isSupported()", r.isSupported());
        assertEquals("getMimeType()", "application/vnd.iso.19139+xml", r.getMimeType());
    }
View Full Code Here

            if (insufficientBytes) {
                return ProbeResult.INSUFFICIENT_BYTES;
            }
            mimeType = XMLStoreProvider.MIME_TYPE;
        }
        return new ProbeResult(true, mimeType, null);
    }
View Full Code Here

                    return ProbeResult.UNSUPPORTED_STORAGE;
                }
            }
            // Now check for a more accurate MIME type.
            buffer.position(HEADER.length);
            final ProbeResult result = new MimeTypeDetector() {
                @Override int read() {
                    if (buffer.hasRemaining()) {
                        return buffer.get();
                    }
                    insufficientBytes = (buffer.limit() != buffer.capacity());
                    return -1;
                }
            }.probeContent();
            buffer.position(0);
            return result;
        }
        /*
         * We should enter in this block only if the user gave us explicitely a Reader.
         * A common case is a StringReader wrapping a String object.
         */
        final Reader reader = storage.getStorageAs(Reader.class);
        if (reader != null) try {
            // Quick check for "<?xml " header.
            reader.mark(HEADER.length + READ_AHEAD_LIMIT);
            for (int i=0; i<HEADER.length; i++) {
                if (reader.read() != HEADER[i]) {
                    reader.reset();
                    return ProbeResult.UNSUPPORTED_STORAGE;
                }
            }
            // Now check for a more accurate MIME type.
            final ProbeResult result = new MimeTypeDetector() {
                private int remaining = READ_AHEAD_LIMIT;
                @Override int read() throws IOException {
                    return (--remaining >= 0) ? reader.read() : -1;
                }
            }.probeContent();
View Full Code Here

     */
    @Test
    public void testProbeContentFromStream() throws DataStoreException {
        final StorageConnector c = new StorageConnector(IOTestCase.getResourceAsStream(NCEP));
        final NetcdfStoreProvider provider = new NetcdfStoreProvider();
        final ProbeResult probe = provider.probeContent(c);
        assertTrue  ("isSupported", probe.isSupported());
        assertEquals("getMimeType", NetcdfStoreProvider.MIME_TYPE, probe.getMimeType());
        assertEquals("getVersion"new Version("1"), probe.getVersion());
        c.closeAllExcept(null);
    }
View Full Code Here

    @Test
    public void testProbeContentFromUCAR() throws IOException, DataStoreException {
        final NetcdfFile file = open(NCEP);
        final StorageConnector c = new StorageConnector(file);
        final NetcdfStoreProvider provider = new NetcdfStoreProvider();
        final ProbeResult probe = provider.probeContent(c);
        assertTrue  ("isSupported", probe.isSupported());
        assertEquals("getMimeType", NetcdfStoreProvider.MIME_TYPE, probe.getMimeType());
        assertNull  ("getVersion",  probe.getVersion());
        file.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.sis.storage.ProbeResult

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.