Search in sources :

Example 1 with ChannelWriter

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);
        }
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipEntry(java.util.zip.ZipEntry) WritableByteChannel(java.nio.channels.WritableByteChannel) IOException(java.io.IOException) ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Example 2 with ChannelWriter

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);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Example 3 with ChannelWriter

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);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Example 4 with ChannelWriter

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);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) IOException(java.io.IOException) Point(com.revolsys.geometry.model.Point) ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Example 5 with ChannelWriter

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();
    }
}
Also used : ChannelWriter(com.revolsys.io.channels.ChannelWriter)

Aggregations

ChannelWriter (com.revolsys.io.channels.ChannelWriter)27 Record (com.revolsys.record.Record)19 RecordReader (com.revolsys.record.io.RecordReader)19 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Maps (com.revolsys.collection.map.Maps)3 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)2 ParameterName (com.revolsys.geometry.cs.ParameterName)2 ParameterValue (com.revolsys.geometry.cs.ParameterValue)2 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 IOException (java.io.IOException)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)1 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)1 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)1 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)1