Search in sources :

Example 1 with AbstractRecordWriter

use of com.revolsys.io.AbstractRecordWriter in project com.revolsys.open by revolsys.

the class DirectoryRecordWriter method getWriter.

private Writer<Record> getWriter(final Record record) {
    final RecordDefinition recordDefinition = record.getRecordDefinition();
    final String path = recordDefinition.getPath();
    Writer<Record> writer = this.writers.get(path);
    if (writer == null) {
        final File directory = getDirectory(recordDefinition);
        directory.mkdirs();
        final String fileName = getFileName(recordDefinition);
        final File file = new File(directory, fileName + this.nameSuffix + "." + this.fileExtension);
        final PathResource resource = new PathResource(file);
        writer = RecordWriter.newRecordWriter(recordDefinition, resource);
        if (writer == null) {
            throw new IllegalArgumentException("Unable to create writer for " + resource);
        } else {
            final Map<String, Object> properties = getProperties();
            writer.setProperties(properties);
            final Geometry geometry = record.getGeometry();
            if (geometry != null) {
                final GeometryFactory geometryFactory = geometry.getGeometryFactory();
                setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
            }
            this.writers.put(path, writer);
            RecordDefinition writerRecordDefinition = recordDefinition;
            if (writer instanceof AbstractRecordWriter) {
                final AbstractRecordWriter recordWriter = (AbstractRecordWriter) writer;
                writerRecordDefinition = recordWriter.getRecordDefinition();
                if (writerRecordDefinition == null) {
                    writerRecordDefinition = recordDefinition;
                }
            }
            this.recordDefinitionMap.put(path, writerRecordDefinition);
        }
    }
    return writer;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) AbstractRecordWriter(com.revolsys.io.AbstractRecordWriter) PathResource(com.revolsys.spring.resource.PathResource) Record(com.revolsys.record.Record) File(java.io.File) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)1 Record (com.revolsys.record.Record)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 PathResource (com.revolsys.spring.resource.PathResource)1 File (java.io.File)1