(String path)
| 100 | } |
| 101 | |
| 102 | public static FitsReader create(String path) throws IOException { |
| 103 | OpenDialog od = new OpenDialog("Open FITS...", path); |
| 104 | var directory = od.getDirectory(); |
| 105 | var fileName = od.getFileName(); |
| 106 | if (fileName == null) { |
| 107 | throw new FitsException("Null filename."); |
| 108 | } |
| 109 | |
| 110 | IJ.showStatus("Opening: " + directory + fileName); |
| 111 | |
| 112 | if (isFileWithinZip(path)) { |
| 113 | var s = path.split("\\.zip"); |
| 114 | |
| 115 | try (var zip = new ZipFile(s[0] + ".zip")) { |
| 116 | var m = new ProgressMonitorInputStream(IJ.getInstance(), |
| 117 | "Reading FITS image", zip.getInputStream(zip.getEntry(s[1].substring(1)))); |
| 118 | FitsFactory.setAllowHeaderRepairs(true); |
| 119 | return new FitsReader(new Fits(m), directory, fileName); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return new FitsReader(Path.of(path), directory, fileName); |
| 124 | } |
| 125 | |
| 126 | private static boolean isFileWithinZip(String path) { |
| 127 | if (path.contains(".zip")) { |
no test coverage detected