001// Licensed under the MIT license. See LICENSE file in the project root for full license information.
002
003package de.bytefish.pgbulkinsert.pgsql.handlers;
004
005import de.bytefish.pgbulkinsert.pgsql.handlers.utils.GeometricUtils;
006import de.bytefish.pgbulkinsert.pgsql.model.geometric.Path;
007import de.bytefish.pgbulkinsert.pgsql.model.geometric.Point;
008
009import java.io.DataOutputStream;
010
011public class PathValueHandler extends BaseValueHandler<Path> {
012
013    @Override
014    protected void internalHandle(DataOutputStream buffer, final Path value) throws Exception {
015        // Write a Byte to indicate if a Path is closed or not:
016        byte pathIsClosed = (byte) (value.isClosed() ? 1 : 0);
017
018        // The total number of bytes to write:
019        int totalBytesToWrite = 1 + 4 + 16 * value.size();
020
021        // The Number of Bytes to follow:
022        buffer.writeInt(totalBytesToWrite);
023        // Is the Circle close?
024        buffer.writeByte(pathIsClosed);
025        // Write Points:
026        buffer.writeInt(value.getPoints().size());
027        // Write each Point in List:
028        for (Point p : value.getPoints()) {
029            GeometricUtils.writePoint(buffer, p);
030        }
031
032    }
033
034    @Override
035    public int getLength(Path value) {
036        throw new UnsupportedOperationException();
037    }
038}