|
22 | 22 | import ucar.nc2.Variable; |
23 | 23 |
|
24 | 24 | import java.io.*; |
| 25 | +import java.nio.file.Files; |
25 | 26 | import java.util.ArrayList; |
26 | 27 | import java.util.Calendar; |
27 | 28 | import java.util.List; |
@@ -72,48 +73,11 @@ public AcquisitionInfo read() throws IOException { |
72 | 73 | final Polygon polygon = extractPolygonFromMinMax(longitudes, latitudes, readerContext.getGeometryFactory()); |
73 | 74 | acquisitionInfo.setBoundingGeometry(polygon); |
74 | 75 |
|
75 | | - final String location = netcdfFile.getLocation(); |
76 | | - final String filename = FileUtils.getFilenameFromPath(location); |
77 | | - final int[] ymd = extractYearMonthDayFromFilename(filename); |
78 | | - final Calendar utcCalendar = TimeUtils.getUTCCalendar(); |
79 | | - utcCalendar.set(Calendar.YEAR, ymd[0]); |
80 | | - utcCalendar.set(Calendar.MONTH, ymd[1] - 1); // month is zero-based tb 2022-09-15 |
81 | | - utcCalendar.set(Calendar.DAY_OF_MONTH, ymd[2]); |
82 | | - |
83 | | - acquisitionInfo.setSensingStart(utcCalendar.getTime()); |
84 | | - |
85 | | - utcCalendar.set(Calendar.HOUR, 23); |
86 | | - utcCalendar.set(Calendar.MINUTE, 59); |
87 | | - utcCalendar.set(Calendar.SECOND, 59); |
88 | | - |
89 | | - acquisitionInfo.setSensingStop(utcCalendar.getTime()); |
| 76 | + setSensingTimes(acquisitionInfo); |
90 | 77 |
|
91 | 78 | return acquisitionInfo; |
92 | 79 | } |
93 | 80 |
|
94 | | - // package access for testing only tb 2022-09-15 |
95 | | - static Polygon extractPolygonFromMinMax(Array longitudes, Array latitudes, GeometryFactory geometryFactory) { |
96 | | - int size = (int) longitudes.getSize(); |
97 | | - final double lonMin = longitudes.getDouble(0); |
98 | | - final double lonMax = longitudes.getDouble(size - 1); |
99 | | - |
100 | | - size = (int) latitudes.getSize(); |
101 | | - final double latMin = latitudes.getDouble(0); |
102 | | - final double latMax = latitudes.getDouble(size - 1); |
103 | | - |
104 | | - final Point ll = geometryFactory.createPoint(lonMin, latMin); |
105 | | - final Point ul = geometryFactory.createPoint(lonMin, latMax); |
106 | | - final Point ur = geometryFactory.createPoint(lonMax, latMax); |
107 | | - final Point lr = geometryFactory.createPoint(lonMax, latMin); |
108 | | - final ArrayList<Point> polygonPoints = new ArrayList<>(); |
109 | | - polygonPoints.add(ll); |
110 | | - polygonPoints.add(ul); |
111 | | - polygonPoints.add(ur); |
112 | | - polygonPoints.add(lr); |
113 | | - polygonPoints.add(ll); |
114 | | - return geometryFactory.createPolygon(polygonPoints); |
115 | | - } |
116 | | - |
117 | 81 | @Override |
118 | 82 | public String getRegEx() { |
119 | 83 | return "SM_RE07_MIR_CDF3T[AD]_(\\d{8}T\\d{6}_){2}\\d{3}_\\d{3}_\\d{1}.tgz"; |
@@ -185,7 +149,7 @@ private File extractFromTar(File file) throws IOException { |
185 | 149 | final int oneMb = 1024 * 1024; |
186 | 150 |
|
187 | 151 | try { |
188 | | - final BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file)); |
| 152 | + final BufferedInputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath())); |
189 | 153 | final GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(inputStream); |
190 | 154 | tarIn = new TarArchiveInputStream(gzipIn); |
191 | 155 |
|
@@ -214,4 +178,46 @@ private File extractFromTar(File file) throws IOException { |
214 | 178 | } |
215 | 179 | } |
216 | 180 | } |
| 181 | + |
| 182 | + private void setSensingTimes(AcquisitionInfo acquisitionInfo) { |
| 183 | + final String location = netcdfFile.getLocation(); |
| 184 | + final String filename = FileUtils.getFilenameFromPath(location); |
| 185 | + final int[] ymd = extractYearMonthDayFromFilename(filename); |
| 186 | + |
| 187 | + final Calendar utcCalendar = TimeUtils.getUTCCalendar(); |
| 188 | + utcCalendar.set(Calendar.YEAR, ymd[0]); |
| 189 | + utcCalendar.set(Calendar.MONTH, ymd[1] - 1); // month is zero-based tb 2022-09-15 |
| 190 | + utcCalendar.set(Calendar.DAY_OF_MONTH, ymd[2]); |
| 191 | + |
| 192 | + acquisitionInfo.setSensingStart(utcCalendar.getTime()); |
| 193 | + |
| 194 | + utcCalendar.set(Calendar.HOUR, 23); |
| 195 | + utcCalendar.set(Calendar.MINUTE, 59); |
| 196 | + utcCalendar.set(Calendar.SECOND, 59); |
| 197 | + |
| 198 | + acquisitionInfo.setSensingStop(utcCalendar.getTime()); |
| 199 | + } |
| 200 | + |
| 201 | + // package access for testing only tb 2022-09-15 |
| 202 | + static Polygon extractPolygonFromMinMax(Array longitudes, Array latitudes, GeometryFactory geometryFactory) { |
| 203 | + int size = (int) longitudes.getSize(); |
| 204 | + final double lonMin = longitudes.getDouble(0); |
| 205 | + final double lonMax = longitudes.getDouble(size - 1); |
| 206 | + |
| 207 | + size = (int) latitudes.getSize(); |
| 208 | + final double latMin = latitudes.getDouble(0); |
| 209 | + final double latMax = latitudes.getDouble(size - 1); |
| 210 | + |
| 211 | + final Point ll = geometryFactory.createPoint(lonMin, latMin); |
| 212 | + final Point ul = geometryFactory.createPoint(lonMin, latMax); |
| 213 | + final Point ur = geometryFactory.createPoint(lonMax, latMax); |
| 214 | + final Point lr = geometryFactory.createPoint(lonMax, latMin); |
| 215 | + final ArrayList<Point> polygonPoints = new ArrayList<>(); |
| 216 | + polygonPoints.add(ll); |
| 217 | + polygonPoints.add(ul); |
| 218 | + polygonPoints.add(ur); |
| 219 | + polygonPoints.add(lr); |
| 220 | + polygonPoints.add(ll); |
| 221 | + return geometryFactory.createPolygon(polygonPoints); |
| 222 | + } |
217 | 223 | } |
0 commit comments