@Test public void testFileIsProperlyClosed() throws Exception { Path path = Files.createTempFile(UUID.randomUUID().toString(), ".txt"); byte[] content = new byte[100]; Random random = new Random(); random.nextBytes(content); Files.write(path, content); File file = path.toFile(); NetCDFImageReaderSpi reader = new NetCDFImageReaderSpi(); reader.canDecodeInput(file); assertThat(file.delete(), is(true)); }
@Override public boolean canDecodeInput(Object source) throws IOException { URI input = null; if (source instanceof URI) { input = (URI) source; } else if (source instanceof File) { input = ((File) source).toURI(); } else if (source instanceof FileImageInputStreamExtImpl) { input = ((FileImageInputStreamExtImpl) source).getFile().toURI(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Found a valid FileImageInputStream"); } } else if (source instanceof URIImageInputStream) { input = ((URIImageInputStream) source).getUri(); } if (input != null) { return NetCDFUtilities.getFormat(input) != FileFormat.NONE; } else { return false; } }
NetCDFImageReaderSpi extends ImageReaderSpi { @Override public boolean canDecodeInput(Object source) throws IOException { URI input = null; if (source instanceof URI) { input = (URI) source; } else if (source instanceof File) { input = ((File) source).toURI(); } else if (source instanceof FileImageInputStreamExtImpl) { input = ((FileImageInputStreamExtImpl) source).getFile().toURI(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Found a valid FileImageInputStream"); } } else if (source instanceof URIImageInputStream) { input = ((URIImageInputStream) source).getUri(); } if (input != null) { return NetCDFUtilities.getFormat(input) != FileFormat.NONE; } else { return false; } } }
NetCDFImageReaderSpi extends ImageReaderSpi { @Override public boolean canDecodeInput(Object source) throws IOException { URI input = null; if (source instanceof URI) { input = (URI) source; } else if (source instanceof File) { input = ((File) source).toURI(); } else if (source instanceof FileImageInputStreamExtImpl) { input = ((FileImageInputStreamExtImpl) source).getFile().toURI(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Found a valid FileImageInputStream"); } } else if (source instanceof URIImageInputStream) { input = ((URIImageInputStream) source).getUri(); } if (input != null) { return NetCDFUtilities.getFormat(input) != FileFormat.NONE; } else { return false; } } NetCDFImageReaderSpi(); }
NetCDFImageReaderSpi extends ImageReaderSpi { @Override public boolean canDecodeInput(Object source) throws IOException { URI input = null; if (source instanceof URI) { input = (URI) source; } else if (source instanceof File) { input = ((File) source).toURI(); } else if (source instanceof FileImageInputStreamExtImpl) { input = ((FileImageInputStreamExtImpl) source).getFile().toURI(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Found a valid FileImageInputStream"); } } else if (source instanceof URIImageInputStream) { input = ((URIImageInputStream) source).getUri(); } if (input != null) { return NetCDFUtilities.getFormat(input) != FileFormat.NONE; } else { return false; } } NetCDFImageReaderSpi(); @Override ImageReader createReaderInstance(Object extension); @Override String getDescription(Locale locale); @Override boolean canDecodeInput(Object source); }
NetCDFImageReaderSpi extends ImageReaderSpi { @Override public boolean canDecodeInput(Object source) throws IOException { URI input = null; if (source instanceof URI) { input = (URI) source; } else if (source instanceof File) { input = ((File) source).toURI(); } else if (source instanceof FileImageInputStreamExtImpl) { input = ((FileImageInputStreamExtImpl) source).getFile().toURI(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Found a valid FileImageInputStream"); } } else if (source instanceof URIImageInputStream) { input = ((URIImageInputStream) source).getUri(); } if (input != null) { return NetCDFUtilities.getFormat(input) != FileFormat.NONE; } else { return false; } } NetCDFImageReaderSpi(); @Override ImageReader createReaderInstance(Object extension); @Override String getDescription(Locale locale); @Override boolean canDecodeInput(Object source); static final Class<?>[] STANDARD_INPUT_TYPES; static final String VENDOR_NAME; }