use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.
the class EpsgCoordinateSystems method loadCoordOperationParam.
private static void loadCoordOperationParam() {
try (ChannelReader reader = newChannelReader("coordOperationParam")) {
while (true) {
final int id = reader.getInt();
String name = reader.getStringUtf8ByteCount();
if (name != null) {
name = name.toLowerCase().replaceAll(" ", "_");
}
readBoolean(reader);
final ParameterName parameterName = ParameterNames.getParameterName(id, name);
PARAM_NAME_BY_ID.put(id, parameterName);
}
} catch (final NoSuchResourceException e) {
} catch (final WrappedException e) {
if (Exceptions.isException(e, EOFException.class)) {
} else {
throw e;
}
}
}
use of com.revolsys.io.channels.ChannelReader 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;
}
use of com.revolsys.io.channels.ChannelReader 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;
}
}
use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelReader method read.
@Override
public GriddedElevationModel read() {
init();
if (this.exists) {
try {
final ChannelReader in = this.reader;
final int cellCount = this.gridWidth * this.gridHeight;
final int[] elevations = new int[cellCount];
final ReadableByteChannel channel = in.getChannel();
if (isMemoryMapped() && channel instanceof FileChannel) {
final FileChannel fileChannel = (FileChannel) channel;
final MappedByteBuffer mappedBytes = fileChannel.map(MapMode.READ_ONLY, ScaledIntegerGriddedDigitalElevation.HEADER_SIZE, cellCount * ScaledIntegerGriddedDigitalElevation.RECORD_SIZE);
final IntBuffer intBuffer = mappedBytes.asIntBuffer();
for (int index = 0; index < cellCount; index++) {
elevations[index] = intBuffer.get();
}
} else {
for (int index = 0; index < cellCount; index++) {
final int elevation = in.getInt();
elevations[index] = elevation;
}
}
final IntArrayScaleGriddedElevationModel elevationModel = new IntArrayScaleGriddedElevationModel(this.geometryFactory, this.boundingBox, this.gridWidth, this.gridHeight, this.gridCellSize, elevations);
elevationModel.setResource(this.resource);
return elevationModel;
} catch (final ClosedByInterruptException e) {
return null;
} catch (final IOException | RuntimeException e) {
if (Exceptions.isException(e, ClosedByInterruptException.class)) {
return null;
} else {
throw Exceptions.wrap("Unable to read DEM: " + this.resource, e);
}
}
} else {
return null;
}
}
use of com.revolsys.io.channels.ChannelReader in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelFile method getFileChannel.
private FileChannel getFileChannel() throws IOException {
if (this.channel == null && isOpen()) {
try {
this.channel = FileChannel.open(this.path, this.openOptions, this.fileAttributes);
this.reader = new ChannelReader(this.channel);
} catch (final NoSuchFileException e) {
if (this.createMissing) {
createNewFile();
} else {
throw e;
}
}
if (!isOpen()) {
close();
return null;
}
}
return this.channel;
}
Aggregations