use of com.revolsys.record.io.RecordWriterFactory in project com.revolsys.open by revolsys.
the class RecordWriterPerformanceTest method main.
public static void main(final String[] args) {
final Path basePath = Paths.getPath("target/test/performance/recordWriter");
Paths.createDirectories(basePath);
final RecordDefinition recordDefinition = newRecordDefinition(DataTypes.POINT);
for (final RecordWriterFactory writerFactory : IoFactory.factories(RecordWriterFactory.class)) {
writeRecords(basePath, recordDefinition, writerFactory);
}
// writeRecords(basePath, recordDefinition, new Kml());
}
use of com.revolsys.record.io.RecordWriterFactory in project com.revolsys.open by revolsys.
the class RecordIoTestSuite method addWriteReadTest.
public static void addWriteReadTest(final TestSuite suite, final String prefix, final String fileExtension) {
addGeometryTestSuites(suite, prefix, (geometryFactory, geometry, geometryDataType) -> {
final String geometryTypeString = geometryDataType.toString();
final File directory = new File("/tmp/revolsystest/io/" + fileExtension);
final File file = new File(directory, geometryTypeString + "_" + geometryFactory.getAxisCount() + "_" + geometry.getVertexCount() + "." + fileExtension);
file.delete();
file.getParentFile().mkdirs();
final PathResource resource = new PathResource(file);
final RecordWriterFactory recordWriterFactory = IoFactory.factory(RecordWriterFactory.class, resource);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(PathName.newPathName(geometryTypeString));
if (recordWriterFactory.isCustomFieldsSupported()) {
recordDefinition.addField("BOOLEAN", DataTypes.BOOLEAN, true);
recordDefinition.addField("BYTE", DataTypes.BYTE, true);
recordDefinition.addField("SHORT", DataTypes.SHORT, true);
recordDefinition.addField("INT", DataTypes.INT, true);
recordDefinition.addField("LONG", DataTypes.LONG, true);
recordDefinition.addField("FLOAT", DataTypes.FLOAT, 4, 3, true);
recordDefinition.addField("DOUBLE", DataTypes.DOUBLE, 10, 9, true);
recordDefinition.addField("STRING", DataTypes.STRING, true);
}
if (recordWriterFactory.isGeometrySupported()) {
recordDefinition.addField("GEOMETRY", geometryDataType, true);
}
recordDefinition.setGeometryFactory(geometryFactory);
final ArrayRecord record = new ArrayRecord(recordDefinition);
record.setValue("BOOLEAN", true);
record.setValue("BYTE", Byte.MAX_VALUE);
record.setValue("SHORT", Short.MAX_VALUE);
record.setValue("INT", Integer.MAX_VALUE);
record.setValue("LONG", 999999999999999999L);
record.setValue("FLOAT", 6.789);
record.setValue("DOUBLE", 1.234567890);
record.setValue("STRING", "test");
record.setGeometryValue(geometry);
doRecordWriteTest(resource, record);
doRecordReadTest(resource, record);
doGeometryReadTest(resource, record);
});
}
use of com.revolsys.record.io.RecordWriterFactory in project com.revolsys.open by revolsys.
the class RecordReaderHttpMessageConverter method write.
@Override
public void write(final RecordReader reader, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
if (!HttpServletUtils.getResponse().isCommitted()) {
MediaType actualMediaType;
if (mediaType == null) {
actualMediaType = getDefaultMediaType();
} else {
actualMediaType = mediaType;
}
if (actualMediaType != null) {
final Charset charset = HttpServletUtils.setContentTypeWithCharset(outputMessage, actualMediaType);
final String mediaTypeString = actualMediaType.getType() + "/" + actualMediaType.getSubtype();
final RecordWriterFactory writerFactory = IoFactory.factoryByMediaType(RecordWriterFactory.class, mediaTypeString);
if (writerFactory == null) {
throw new IllegalArgumentException("Media type " + actualMediaType + " not supported");
} else {
final RecordDefinition recordDefinition = reader.getRecordDefinition();
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
String baseName = (String) requestAttributes.getAttribute("contentDispositionFileName", RequestAttributes.SCOPE_REQUEST);
if (baseName == null) {
baseName = HttpServletUtils.getRequestBaseFileName();
}
String contentDisposition = (String) requestAttributes.getAttribute("contentDisposition", RequestAttributes.SCOPE_REQUEST);
if (contentDisposition == null) {
contentDisposition = "attachment";
}
final String fileName = baseName + "." + writerFactory.getFileExtension(mediaTypeString);
final HttpHeaders headers = outputMessage.getHeaders();
headers.set("Content-Disposition", contentDisposition + "; filename=" + fileName);
final OutputStream body = outputMessage.getBody();
final Writer<Record> writer = writerFactory.newRecordWriter(baseName, recordDefinition, body, charset);
if (Boolean.FALSE.equals(requestAttributes.getAttribute("wrapHtml", RequestAttributes.SCOPE_REQUEST))) {
writer.setProperty(IoConstants.WRAP_PROPERTY, false);
}
final HttpServletRequest request = HttpServletUtils.getRequest();
String callback = request.getParameter("jsonp");
if (callback == null) {
callback = request.getParameter("callback");
}
if (callback != null) {
writer.setProperty(IoConstants.JSONP_PROPERTY, callback);
}
for (final String attributeName : requestAttributes.getAttributeNames(RequestAttributes.SCOPE_REQUEST)) {
final Object value = requestAttributes.getAttribute(attributeName, RequestAttributes.SCOPE_REQUEST);
if (value != null && attributeName.startsWith("java:") || this.requestAttributeNames.contains(attributeName)) {
writer.setProperty(attributeName, value);
}
}
final Iterator<Record> iterator = reader.iterator();
if (iterator.hasNext()) {
Record record = iterator.next();
final Geometry geometry = record.getGeometry();
if (geometry != null) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
writer.setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
}
writer.write(record);
while (iterator.hasNext()) {
record = iterator.next();
writer.write(record);
}
}
writer.close();
}
}
}
}
Aggregations