use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.
the class EsriCoordinateSystems method getProjectedCoordinateSystem.
public static ProjectedCoordinateSystem getProjectedCoordinateSystem(final int id) {
ProjectedCoordinateSystem coordinateSystem = (ProjectedCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
if (coordinateSystem == null) {
try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Projected.cs")) {
while (true) {
final int coordinateSystemId = reader.getInt();
final String csName = reader.getStringUtf8ByteCount();
final int geographicCoordinateSystemId = reader.getInt();
final String projectionName = reader.getStringUtf8ByteCount();
final Map<ParameterName, ParameterValue> parameters = readParameters(reader);
final String unitName = reader.getStringUtf8ByteCount();
final double conversionFactor = reader.getDouble();
if (id == coordinateSystemId) {
LinearUnit linearUnit = LINEAR_UNITS_BY_NAME.get(unitName);
if (linearUnit == null) {
linearUnit = new LinearUnit(unitName, conversionFactor);
LINEAR_UNITS_BY_NAME.put(unitName, linearUnit);
}
final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
final GeographicCoordinateSystem geographicCoordinateSystem = getGeographicCoordinateSystem(geographicCoordinateSystemId);
coordinateSystem = new ProjectedCoordinateSystem(coordinateSystemId, csName, geographicCoordinateSystem, projectionName, parameters, linearUnit, authority);
COORDINATE_SYSTEM_BY_ID.put(id, coordinateSystem);
return coordinateSystem;
}
}
} catch (final WrappedException e) {
if (Exceptions.isException(e, EOFException.class)) {
return null;
} else {
Logs.error("Cannot load coordinate system=" + id, e);
throw e;
}
}
}
return coordinateSystem;
}
use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.
the class EsriCoordinateSystems method getGeographicCoordinateSystem.
public static GeographicCoordinateSystem getGeographicCoordinateSystem(final int id) {
GeographicCoordinateSystem coordinateSystem = (GeographicCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
if (coordinateSystem == null) {
try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Geographic.cs")) {
while (true) {
final int coordinateSystemId = reader.getInt();
final String csName = reader.getStringUtf8ByteCount();
final String datumName = reader.getStringUtf8ByteCount();
final String spheroidName = reader.getStringUtf8ByteCount();
final double semiMajorAxis = reader.getDouble();
final double inverseFlattening = reader.getDouble();
final String primeMeridianName = reader.getStringUtf8ByteCount();
final double longitude = reader.getDouble();
final String angularUnitName = reader.getStringUtf8ByteCount();
final double conversionFactor = reader.getDouble();
if (id == coordinateSystemId) {
final Ellipsoid ellipsoid = new Ellipsoid(spheroidName, semiMajorAxis, inverseFlattening, null);
final PrimeMeridian primeMeridian = new PrimeMeridian(primeMeridianName, longitude, null);
final GeodeticDatum geodeticDatum = new GeodeticDatum(null, datumName, null, false, ellipsoid, primeMeridian);
AngularUnit angularUnit = ANGULAR_UNITS_BY_NAME.get(angularUnitName);
if (angularUnit == null) {
angularUnit = new AngularUnit(angularUnitName, conversionFactor, null);
ANGULAR_UNITS_BY_NAME.put(angularUnitName, angularUnit);
}
final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
coordinateSystem = new GeographicCoordinateSystem(coordinateSystemId, csName, geodeticDatum, primeMeridian, angularUnit, null, authority);
COORDINATE_SYSTEM_BY_ID.put(id, coordinateSystem);
return coordinateSystem;
}
}
} catch (final WrappedException e) {
if (Exceptions.isException(e, EOFException.class)) {
return null;
} else {
Logs.error("Cannot load coordinate system=" + id, e);
throw e;
}
}
}
return coordinateSystem;
}
use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.
the class JsonParser method read.
@SuppressWarnings("unchecked")
public static <V> V read(final Object source) {
Reader reader;
if (source instanceof Clob) {
try {
reader = ((Clob) source).getCharacterStream();
} catch (final SQLException e) {
throw new RuntimeException("Unable to read clob", e);
}
} else if (source instanceof Reader) {
reader = (Reader) source;
} else if (source instanceof CharSequence) {
reader = new StringReader(source.toString());
} else {
try {
final Resource resource = Resource.getResource(source);
reader = resource.newBufferedReader();
} catch (final WrappedException e) {
reader = new StringReader(source.toString());
}
}
try {
final V value = (V) read(reader);
return value;
} finally {
if (source instanceof Clob) {
try {
final Clob clob = (Clob) source;
clob.free();
} catch (final SQLException e) {
throw new RuntimeException("Unable to free clob resources", e);
}
}
}
}
use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.
the class MavenRepositoryCache method copyRepositoryResource.
private boolean copyRepositoryResource(final MavenRepository repository, final Resource resource, final String groupId, final String artifactId, final String version, final String type, final String classifier, final String specificVersion, final String algorithm, final String path) {
final String sha1Digest = repository.getSha1(groupId, artifactId, version, type, classifier, specificVersion, algorithm);
final Resource repositoryResource = repository.getRoot().newChildResource(path);
try {
if (Property.hasValue(sha1Digest)) {
final InputStream in = repositoryResource.getInputStream();
final DigestInputStream digestIn = new DigestInputStream(in, MessageDigest.getInstance("SHA-1"));
resource.copyFrom(digestIn);
final MessageDigest messageDigest = digestIn.getMessageDigest();
final byte[] digest = messageDigest.digest();
final String fileDigest = Hex.toHex(digest);
if (!sha1Digest.equals(fileDigest)) {
Logs.error(this, ".sha1 digest is different for: " + repositoryResource);
resource.delete();
return false;
}
} else {
resource.copyFrom(repositoryResource);
}
Logs.info(this, "Download maven resource: " + repositoryResource);
return true;
} catch (Throwable e) {
resource.delete();
while (e instanceof WrappedException) {
e = e.getCause();
}
if (e instanceof FileNotFoundException) {
return false;
} else if (e instanceof IOException) {
final IOException ioException = (IOException) e;
if (ioException.getMessage().contains(" 404 ")) {
return false;
}
}
Logs.error(this, "Unable to download MVN resource " + repositoryResource + "\n " + e.getMessage(), e);
return false;
}
}
use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.
the class AbstractUpdateField method finish.
private void finish() {
if (this.recordCount > 100) {
final int confirm = JOptionPane.showConfirmDialog(this, "<html>Update <b style='color:#32CD32'>" + this.recordCountString + "</b> records? This may take a long time or fail if there are many records.</html>", "Update Records?", JOptionPane.OK_CANCEL_OPTION);
if (confirm != JOptionPane.OK_OPTION) {
setVisible(false);
return;
}
}
final ProgressMonitor progressMonitor = new ProgressMonitor(this, getProgressMonitorTitle(), "Updated 0 of " + this.recordCountString, 0, 100);
progressMonitor.setProgress(0);
setVisible(false);
final AtomicInteger progress = new AtomicInteger();
final SwingWorker<?, ?> task = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
final Set<String> fieldNames = new LinkedHashSet<>();
fieldNames.add(AbstractUpdateField.this.fieldDefinition.getName());
fieldNames.addAll(AbstractUpdateField.this.layer.getFieldNames());
final RecordLayerErrors errors = new RecordLayerErrors("Setting Field Values", AbstractUpdateField.this.layer, fieldNames);
AbstractUpdateField.this.tableModel.forEachRecord((record) -> {
if (progressMonitor.isCanceled()) {
throw new CancellationException();
} else {
try {
updateRecord(record);
} catch (final WrappedException e) {
errors.addRecord(record, e.getCause());
} catch (final Throwable e) {
errors.addRecord(record, e);
}
final int updateCount = progress.incrementAndGet();
if (updateCount < AbstractUpdateField.this.recordCount) {
final int updatePercent = (int) Math.floor(updateCount * 100 / (double) AbstractUpdateField.this.recordCount);
if (updatePercent < 100) {
setProgress(updatePercent);
}
}
}
});
setProgress(100);
if (!isCancelled()) {
errors.showErrorDialog();
}
return null;
}
@Override
protected void done() {
}
};
task.addPropertyChangeListener((event) -> {
if ("progress" == event.getPropertyName()) {
final int percent = (Integer) event.getNewValue();
progressMonitor.setProgress(percent);
progressMonitor.setNote("Updated " + progress + " of " + this.recordCountString);
}
});
Invoke.worker(task);
}
Aggregations