use of com.revolsys.io.channels.ChannelWriter in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelWriter method open.
@Override
public void open() {
if (this.writer == null) {
final String fileNameExtension = this.resource.getFileNameExtension();
if ("zip".equals(fileNameExtension) || ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION_ZIP.equals(fileNameExtension)) {
try {
final OutputStream bufferedOut = this.resource.newBufferedOutputStream();
final String fileName = this.resource.getBaseName();
final ZipOutputStream zipOut = new ZipOutputStream(bufferedOut);
final ZipEntry zipEntry = new ZipEntry(fileName);
zipOut.putNextEntry(zipEntry);
final WritableByteChannel channel = Channels.newChannel(zipOut);
this.writer = new ChannelWriter(channel, true, this.byteBuffer);
} catch (final IOException e) {
throw Exceptions.wrap("Error creating: " + this.resource, e);
}
} else if ("gz".equals(fileNameExtension)) {
try {
String fileName = this.resource.getBaseName();
if (!fileName.endsWith("." + ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION)) {
fileName += "." + ScaledIntegerGriddedDigitalElevation.FILE_EXTENSION;
}
final OutputStream bufferedOut = this.resource.newBufferedOutputStream();
final GZIPOutputStream zipOut = new GZIPOutputStream(bufferedOut);
final WritableByteChannel channel = Channels.newChannel(zipOut);
this.writer = new ChannelWriter(channel, true, this.byteBuffer);
} catch (final IOException e) {
throw Exceptions.wrap("Error creating: " + this.resource, e);
}
} else {
this.writer = this.resource.newChannelWriter(this.byteBuffer);
}
}
}
use of com.revolsys.io.channels.ChannelWriter in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelFile method createNewFile.
protected void createNewFile() throws IOException {
Paths.createParentDirectories(this.path);
this.channel = FileChannel.open(this.path, Paths.OPEN_OPTIONS_READ_WRITE_SET, this.fileAttributes);
try (final ChannelWriter writer = new ChannelWriter(this.channel)) {
final int gridWidth = getGridWidth();
final int gridHeight = getGridHeight();
final double gridCellSize = getGridCellSize();
final BoundingBox boundingBox = getBoundingBox();
final GeometryFactory geometryFactory = getGeometryFactory();
ScaledIntegerGriddedDigitalElevationModelWriter.writeHeader(writer, boundingBox, geometryFactory, gridWidth, gridHeight, (int) gridCellSize);
final int count = gridWidth * gridHeight;
for (int i = 0; i < count; i++) {
writer.putInt(Integer.MIN_VALUE);
}
}
}
use of com.revolsys.io.channels.ChannelWriter in project com.revolsys.open by revolsys.
the class ScaledIntegerPointCloudGeometryWriter method initialize.
private void initialize() throws IOException {
if (!this.initialized) {
this.initialized = true;
final ChannelWriter writer = this.resource.newChannelWriter(this.byteBuffer);
this.writer = writer;
final GeometryFactory geometryFactory = this.geometryFactory;
// File
writer.putBytes(ScaledIntegerPointCloud.FILE_TYPE_HEADER_BYTES);
// type
// version
writer.putShort(ScaledIntegerPointCloud.VERSION);
// Flags
writer.putShort((short) 0);
geometryFactory.writeOffsetScaled3d(writer);
}
}
use of com.revolsys.io.channels.ChannelWriter in project com.revolsys.open by revolsys.
the class ScaledIntegerPointCloudGeometryWriter method write.
public void write(final double x, final double y, final double z) {
try {
initialize();
final ChannelWriter writer = this.writer;
final GeometryFactory geometryFactory = this.geometryFactory;
final int xInt = geometryFactory.toIntX(x);
writer.putInt(xInt);
final int yInt = geometryFactory.toIntY(y);
writer.putInt(yInt);
final int zInt = geometryFactory.toIntZ(z);
writer.putInt(zInt);
} catch (final IOException e) {
throw Exceptions.wrap(e);
}
}
use of com.revolsys.io.channels.ChannelWriter in project com.revolsys.open by revolsys.
the class ScaledIntegerPointCloudGeometryWriter method close.
@Override
public void close() {
final ChannelWriter writer = this.writer;
this.writer = null;
if (writer != null) {
writer.close();
}
}
Aggregations