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.Point; 007import de.bytefish.pgbulkinsert.pgsql.model.geometric.Polygon; 008 009import java.io.DataOutputStream; 010 011public class PolygonValueHandler extends BaseValueHandler<Polygon> { 012 013 @Override 014 protected void internalHandle(DataOutputStream buffer, final Polygon value) throws Exception { 015 // The total number of bytes to write: 016 int totalBytesToWrite = 4 + 16 * value.size(); 017 018 // The Number of Bytes to follow: 019 buffer.writeInt(totalBytesToWrite); 020 021 // Write Points: 022 buffer.writeInt(value.getPoints().size()); 023 024 // Write each Point in List: 025 for (Point p : value.getPoints()) { 026 GeometricUtils.writePoint(buffer, p); 027 } 028 029 } 030 031 @Override 032 public int getLength(Polygon value) { 033 throw new UnsupportedOperationException(); 034 } 035}