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;
}
Aggregations