Path createCacheDirRoot(Path inputFile) throws IOException { Path versionFile = ResourceInstaller.findModuleCodeBasePath(getClass()).resolve("version/version.properties"); Properties versionProp = new Properties(); try (InputStream inputStream = Files.newInputStream(versionFile)){ versionProp.load(inputStream); } catch (IOException e) { SystemUtils.LOG.severe("JP2-reader configuration error: Failed to read " + versionFile.toString()); return null; } String version = versionProp.getProperty("project.version"); if (version == null) { throw new IOException("Unable to get project.version property from " + versionFile); } String md5sum = getMD5sum(inputFile.toString()); if (md5sum == null) { throw new IOException("Unable to get md5sum of path " + inputFile.toString()); } tmpFolder = PathUtils.get(SystemUtils.getCacheDir(), "s2tbx", "jp2-reader", version, md5sum, PathUtils.getFileNameWithoutExtension(inputFile).toLowerCase() + "_cached"); if (!Files.exists(tmpFolder)) { Files.createDirectories(tmpFolder); } return tmpFolder; }
public static VirtualPath transformToSentinel2VirtualPath (Path path) throws IOException{ VirtualPath virtualPath; if(VirtualDirEx.isPackedFile(path.toFile())) { VirtualDirEx virtualDirEx = VirtualDirEx.create(path.toFile()); if(virtualDirEx == null) { throw new IOException(String.format("Unable to read %s",path.toString())); } String folderName = PathUtils.getFileNameWithoutExtension(path); if(!folderName.endsWith(".SAFE")) { folderName = folderName +".SAFE"; } if(virtualDirEx.exists(folderName)) { virtualPath = new VirtualPath(folderName, virtualDirEx); } else { virtualPath = new VirtualPath(".", virtualDirEx); } } else { virtualPath = new VirtualPath(path); } return virtualPath; } }
private Path decompressTile(int tileIndex, int level) throws IOException { Path tileFile = PathUtils.get(cacheDir, PathUtils.getFileNameWithoutExtension(imageFile).toLowerCase() + "_tile_" + String.valueOf(tileIndex) + "_" + String.valueOf(level) + ".tif"); if ((!Files.exists(tileFile)) || (diffLastModifiedTimes(tileFile.toFile(), imageFile.toFile()) < 0L)) { final OpjExecutor decompress = new OpjExecutor(OpenJpegExecRetriever.getOpjDecompress()); final Map<String, String> params = new HashMap<String, String>() {{ put("-i", GetIterativeShortPathNameW(imageFile.toString())); put("-r", String.valueOf(level)); put("-l", "20"); }}; String tileFileName; if (org.apache.commons.lang.SystemUtils.IS_OS_WINDOWS && (tileFile.getParent() != null)) { tileFileName = Utils.GetIterativeShortPathNameW(tileFile.getParent().toString()) + File.separator + tileFile.getName(tileFile.getNameCount()-1); } else { tileFileName = tileFile.toString(); } params.put("-o", tileFileName); params.put("-t", String.valueOf(tileIndex)); params.put("-p", String.valueOf(DataBuffer.getDataTypeSize(this.getSampleModel().getDataType()))); params.put("-threads", "ALL_CPUS"); if (decompress.execute(params) != 0) { logger.severe(decompress.getLastError()); tileFile = null; } else { logger.fine("Decompressed tile #" + String.valueOf(tileIndex) + " @ resolution " + String.valueOf(level)); } } return tileFile; }
OpjDumpFile dumpFile = new OpjDumpFile(PathUtils.get(tmpFolder, String.format(JP2ProductReaderConstants.JP2_INFO_FILE, PathUtils.getFileNameWithoutExtension(inputFile)))); Map<String, String> params = new HashMap<String, String>() {{ put("-i", GetIterativeShortPathNameW(inputFile.toAbsolutePath().toString()));