use of com.revolsys.spring.resource.PathResource 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.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class RecordWriterPerformanceTest method writeRecords.
private static void writeRecords(final Path basePath, final RecordDefinition recordDefinition, final RecordWriterFactory writerFactory) {
final String fileExtension = writerFactory.getFileExtensions().get(0);
final Resource resource = new PathResource(basePath.resolve("records." + fileExtension));
final Record record = newRecord(recordDefinition, 0);
// Prime the code to avoid initialization in timings
try {
writeRecords(writerFactory, recordDefinition, resource, 1, record);
} finally {
resource.delete();
}
try {
final long time = System.currentTimeMillis();
final int numIterations = 1000000;
writeRecords(writerFactory, recordDefinition, resource, numIterations, record);
final long ellapsedTime = System.currentTimeMillis() - time;
final long millis = ellapsedTime % 1000;
final long seconds = ellapsedTime / 1000 % 60;
final long minutes = ellapsedTime / 60000 % 60;
System.out.println(writerFactory.getName() + "\t" + minutes + ":" + seconds + "." + millis + "\t" + resource.getFile().length());
} finally {
resource.delete();
}
for (int i = 0; i < 10; i++) {
System.gc();
synchronized (record) {
try {
record.wait(1000);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class Gdal method getDataset.
public static Dataset getDataset(final File file, final int mode) {
if (isAvailable()) {
final String path = file.getAbsolutePath();
if (file.exists()) {
final Dataset dataset = gdal.Open(path, mode);
if (dataset == null) {
throw new GdalException();
} else {
final Resource resource = new PathResource(file);
setProjectionFromPrjFile(dataset, resource);
final long modifiedTime = loadSettings(dataset, resource);
return dataset;
}
} else {
throw new IllegalArgumentException("File no found: " + path);
}
} else {
throw new IllegalStateException("GDAL is not available");
}
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class ProjectFrame method loadProject.
protected void loadProject(final Path projectPath) {
final PathResource resource = new PathResource(projectPath);
this.project.readProject(this.project, resource);
Invoke.later(() -> setTitle(this.project.getName() + " - " + this.frameTitle));
final Object frameBoundsObject = this.project.getProperty("frameBounds");
setBounds(frameBoundsObject, true);
setVisible(true);
final MapPanel mapPanel = getMapPanel();
final BoundingBox initialBoundingBox = this.project.getInitialBoundingBox();
final Viewport2D viewport = mapPanel.getViewport();
if (!RectangleUtil.isEmpty(initialBoundingBox)) {
this.project.setViewBoundingBoxAndGeometryFactory(initialBoundingBox);
viewport.setBoundingBoxAndGeometryFactory(initialBoundingBox);
}
viewport.setInitialized(true);
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class Project method getProjectDirectory.
public Path getProjectDirectory() {
if (this.resource == null) {
final Path directory = getSaveAsDirectory();
return directory;
}
if (this.resource instanceof PathResource) {
final PathResource fileResource = (PathResource) this.resource;
final File directory = fileResource.getFile();
if (!directory.exists()) {
directory.mkdirs();
}
if (directory.isDirectory()) {
return directory.toPath();
}
} else if (this.resource instanceof PathResource) {
final PathResource pathResource = (PathResource) this.resource;
final Path directory = pathResource.getPath();
if (!Files.exists(directory)) {
try {
Files.createDirectories(directory);
} catch (final IOException e) {
throw Exceptions.wrap(e);
}
}
if (Files.isDirectory(directory)) {
return directory;
}
}
return null;
}
Aggregations