Issue #1954 Revert HucLevelGeometriesFactory
Former-commit-id:dbb6e1abbf
[formerly 0be6bba1ac6db873c54f72bdb7e267bd6cc2ce5a] Former-commit-id:6f0fadbfbf
This commit is contained in:
parent
a10753ebe7
commit
87775a876d
1 changed files with 6 additions and 57 deletions
|
@ -19,21 +19,16 @@
|
||||||
**/
|
**/
|
||||||
package com.raytheon.uf.common.dataplugin.ffmp;
|
package com.raytheon.uf.common.dataplugin.ffmp;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
import com.raytheon.uf.common.localization.IPathManager;
|
import com.raytheon.uf.common.localization.IPathManager;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||||
|
@ -43,8 +38,6 @@ import com.raytheon.uf.common.localization.LocalizationFile;
|
||||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||||
import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException;
|
import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException;
|
||||||
import com.raytheon.uf.common.serialization.SerializationUtil;
|
import com.raytheon.uf.common.serialization.SerializationUtil;
|
||||||
import com.raytheon.uf.common.serialization.adapters.FloatWKBReader;
|
|
||||||
import com.raytheon.uf.common.serialization.adapters.FloatWKBWriter;
|
|
||||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||||
import com.raytheon.uf.common.status.UFStatus;
|
import com.raytheon.uf.common.status.UFStatus;
|
||||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||||
|
@ -71,6 +64,7 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
|
||||||
* Dec 9, 2010 rjpeter Initial creation
|
* Dec 9, 2010 rjpeter Initial creation
|
||||||
* Apr 25, 2013 1954 bsteffen Decompress ffmp geometries to save time
|
* Apr 25, 2013 1954 bsteffen Decompress ffmp geometries to save time
|
||||||
* loading them.
|
* loading them.
|
||||||
|
* Apr 25, 2013 1954 bsteffen Undo last commit to avoid invalid geoms.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -134,44 +128,9 @@ public class HucLevelGeometriesFactory {
|
||||||
|
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
try {
|
try {
|
||||||
File file = f.getFile();
|
|
||||||
byte[] bytes = FileUtil.file2bytes(file, false);
|
|
||||||
if (bytes[0] == (byte) 0x1f && bytes[1] == (byte) 0x8b) {
|
|
||||||
// GZIP magic number is present, before 13.4.1 these
|
|
||||||
// files were compressed and stored in a different
|
|
||||||
// format, to maintain backwards compatibility we check
|
|
||||||
// for compression and deserialize the old way. This
|
|
||||||
// code can be removed any time after 13.5.1.
|
|
||||||
System.out.println("Decompressing geometry files.");
|
|
||||||
InputStream is = new ByteArrayInputStream(bytes);
|
|
||||||
is = new GZIPInputStream(is, bytes.length);
|
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream(
|
|
||||||
bytes.length * 3 / 2);
|
|
||||||
byte[] buffer = new byte[1024 * 8];
|
|
||||||
int numRead = 0;
|
|
||||||
while ((numRead = is.read(buffer)) >= 0) {
|
|
||||||
os.write(buffer, 0, numRead);
|
|
||||||
}
|
|
||||||
bytes = os.toByteArray();
|
|
||||||
map = (Map<Long, Geometry>) SerializationUtil
|
map = (Map<Long, Geometry>) SerializationUtil
|
||||||
.transformFromThrift(Map.class, bytes);
|
.transformFromThrift(FileUtil.file2bytes(
|
||||||
// save them back the new way.
|
f.getFile(), true));
|
||||||
persistGeometryMap(dataKey, cwa, huc, map);
|
|
||||||
} else {
|
|
||||||
Map<Long, byte[]> serializableMap = (Map<Long, byte[]>) SerializationUtil
|
|
||||||
.transformFromThrift(Map.class, bytes);
|
|
||||||
FloatWKBReader reader = new FloatWKBReader(
|
|
||||||
new GeometryFactory());
|
|
||||||
map = new HashMap<Long, Geometry>(
|
|
||||||
serializableMap.size());
|
|
||||||
for (Entry<Long, byte[]> entry : serializableMap
|
|
||||||
.entrySet()) {
|
|
||||||
InputStream in = new ByteArrayInputStream(
|
|
||||||
entry.getValue());
|
|
||||||
Geometry geom = reader.readGeometry(in);
|
|
||||||
map.put(entry.getKey(), geom);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int sizeGuess = Math.max(
|
int sizeGuess = Math.max(
|
||||||
Math.abs(pfafs.size() - map.size()), 10);
|
Math.abs(pfafs.size() - map.size()), 10);
|
||||||
pfafsToGenerate = new ArrayList<Long>(sizeGuess);
|
pfafsToGenerate = new ArrayList<Long>(sizeGuess);
|
||||||
|
@ -388,23 +347,13 @@ public class HucLevelGeometriesFactory {
|
||||||
|
|
||||||
protected synchronized void persistGeometryMap(String dataKey, String cwa,
|
protected synchronized void persistGeometryMap(String dataKey, String cwa,
|
||||||
String huc, Map<Long, Geometry> map) throws Exception {
|
String huc, Map<Long, Geometry> map) throws Exception {
|
||||||
|
|
||||||
LocalizationContext lc = pathManager.getContext(
|
LocalizationContext lc = pathManager.getContext(
|
||||||
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
|
||||||
LocalizationFile lf = pathManager.getLocalizationFile(lc,
|
LocalizationFile lf = pathManager.getLocalizationFile(lc,
|
||||||
getGeomPath(dataKey, cwa, huc));
|
getGeomPath(dataKey, cwa, huc));
|
||||||
FloatWKBWriter writer = new FloatWKBWriter();
|
FileUtil.bytes2File(SerializationUtil.transformToThrift(map),
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
|
lf.getFile(), true);
|
||||||
Map<Long, byte[]> serializableMap = new HashMap<Long, byte[]>();
|
|
||||||
for (Entry<Long, Geometry> entry : map.entrySet()) {
|
|
||||||
writer.writeGeometry(entry.getValue(), bos);
|
|
||||||
serializableMap.put(entry.getKey(), bos.toByteArray());
|
|
||||||
bos.reset();
|
|
||||||
}
|
|
||||||
byte[] bytes = SerializationUtil.transformToThrift(serializableMap);
|
|
||||||
FileUtil.bytes2File(bytes, lf.getFile(), false);
|
|
||||||
lf.save();
|
lf.save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized String getGeomPath(String dataKey, String cwa,
|
protected synchronized String getGeomPath(String dataKey, String cwa,
|
||||||
|
|
Loading…
Add table
Reference in a new issue