Search in sources :

Example 11 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class EsriCoordinateSystems method getVerticalCoordinateSystem.

public static VerticalCoordinateSystem getVerticalCoordinateSystem(final int id) {
    VerticalCoordinateSystem coordinateSystem = (VerticalCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
    if (coordinateSystem == null) {
        try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Vertical.cs")) {
            while (true) {
                final int coordinateSystemId = reader.getInt();
                final String csName = reader.getStringUtf8ByteCount();
                final String datumName = reader.getStringUtf8ByteCount();
                final Map<ParameterName, ParameterValue> parameters = readParameters(reader);
                final String linearUnitName = reader.getStringUtf8ByteCount();
                final double conversionFactor = reader.getDouble();
                if (id == coordinateSystemId) {
                    final VerticalDatum verticalDatum = new VerticalDatum(null, datumName, 0);
                    LinearUnit linearUnit = LINEAR_UNITS_BY_NAME.get(linearUnitName);
                    if (linearUnit == null) {
                        linearUnit = new LinearUnit(linearUnitName, conversionFactor, null);
                        LINEAR_UNITS_BY_NAME.put(linearUnitName, linearUnit);
                    }
                    final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
                    coordinateSystem = new VerticalCoordinateSystem(authority, csName, verticalDatum, parameters, linearUnit, Collections.emptyList());
                    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;
}
Also used : BaseAuthority(com.revolsys.geometry.cs.BaseAuthority) WrappedException(com.revolsys.util.WrappedException) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) Authority(com.revolsys.geometry.cs.Authority) BaseAuthority(com.revolsys.geometry.cs.BaseAuthority) ParameterName(com.revolsys.geometry.cs.ParameterName) SingleParameterName(com.revolsys.geometry.cs.SingleParameterName) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ChannelReader(com.revolsys.io.channels.ChannelReader) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EOFException(java.io.EOFException)

Example 12 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class EsriCoordinateSystems method getCoordinateSystemIdsByDigest.

private static List<Integer> getCoordinateSystemIdsByDigest(final CoordinateSystem coordinateSystem, final ByteArray digest) {
    List<Integer> ids = COORDINATE_SYSTEM_IDS_BY_DIGEST.get(digest);
    if (ids == null) {
        final byte[] bytes = new byte[16];
        final ByteArray newDigest = new ByteArray(bytes);
        final String type = coordinateSystem.getCoordinateSystemType();
        try (ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/" + type + ".digest")) {
            while (true) {
                reader.getBytes(bytes);
                final short count = reader.getShort();
                if (digest.equals(newDigest)) {
                    ids = new ArrayList<>();
                    for (int i = 0; i < count; i++) {
                        final int csId = reader.getInt();
                        ids.add(csId);
                    }
                    COORDINATE_SYSTEM_IDS_BY_DIGEST.put(digest, ids);
                    return ids;
                } else {
                    for (int i = 0; i < count; i++) {
                        reader.getInt();
                    }
                }
            }
        } catch (final WrappedException e) {
            if (Exceptions.isException(e, EOFException.class)) {
                return Collections.emptyList();
            } else {
                throw e;
            }
        }
    } else {
        return ids;
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException)

Example 13 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class ArcGisResponse method refresh.

@Override
public final void refresh() {
    synchronized (this.resfreshSync) {
        try (BaseCloseable noCache = FileResponseCache.disable()) {
            refreshDo();
            this.hasError = false;
        } catch (final WrappedException e) {
            this.hasError = true;
            final Throwable cause = Exceptions.unwrap(e);
            if (cause instanceof UnknownHostException) {
                Logs.error(this, "Cannot find host " + cause.getMessage());
            }
        } catch (final Throwable e) {
            this.hasError = true;
            throw Exceptions.wrap("Unable to initialize: " + this, e);
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) WrappedException(com.revolsys.util.WrappedException) UnknownHostException(java.net.UnknownHostException)

Example 14 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadCoordinateAxisNames.

private static void loadCoordinateAxisNames() {
    try (ChannelReader reader = newChannelReader("coordinateAxisName")) {
        while (true) {
            final int code = reader.getInt();
            final String name = reader.getStringUtf8ByteCount();
            final AxisName axisName = new AxisName(code, name);
            AXIS_NAMES.putInt(code, axisName);
            AXIS_NAME_BY_NAME.put(name.toLowerCase(), axisName);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
}
Also used : NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) AxisName(com.revolsys.geometry.cs.AxisName) WrappedException(com.revolsys.util.WrappedException) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString)

Example 15 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadCoordOperationParamUsage.

private static void loadCoordOperationParamUsage(final IntHashMap<List<ParameterName>> paramOrderByMethodId, final IntHashMap<List<Byte>> paramReversal) {
    try (ChannelReader reader = newChannelReader("coordOperationParamUsage")) {
        while (true) {
            final int methodId = reader.getInt();
            final ParameterName parameterName = readCode(reader, PARAM_NAME_BY_ID);
            final int sortOrder = reader.getInt();
            final byte signReversal = reader.getByte();
            Maps.addToList(paramOrderByMethodId, methodId, parameterName);
            Maps.addToList(paramReversal, methodId, signReversal);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            Logs.error(EpsgCoordinateSystems.class, "Error loading coordOperationParamValue", e);
        }
    }
}
Also used : NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) WrappedException(com.revolsys.util.WrappedException) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) ParameterName(com.revolsys.geometry.cs.ParameterName)

Aggregations

WrappedException (com.revolsys.util.WrappedException)28 ChannelReader (com.revolsys.io.channels.ChannelReader)20 EOFException (java.io.EOFException)19 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)14 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)12 ParameterName (com.revolsys.geometry.cs.ParameterName)7 Area (com.revolsys.geometry.cs.Area)4 Authority (com.revolsys.geometry.cs.Authority)4 ParameterValue (com.revolsys.geometry.cs.ParameterValue)4 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)3 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)3 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)3 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)3 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)3 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)3 AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)3 UnitOfMeasure (com.revolsys.geometry.cs.unit.UnitOfMeasure)3