Search in sources :

Example 1 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class MapObjectFactory method write.

static void write(final Path path, final MapSerializer serializer) {
    final PathResource resource = new PathResource(path);
    write(resource, serializer);
}
Also used : PathResource(com.revolsys.spring.resource.PathResource)

Example 2 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class MavenRepositoryCache method setRoot.

@Override
public void setRoot(final Resource root) {
    if (root != null) {
        try {
            final File file = root.getFile();
            if (!file.exists()) {
                if (!file.mkdirs()) {
                    throw new IllegalArgumentException("Cannot create maven cache directory " + file);
                }
            } else if (!file.isDirectory()) {
                throw new IllegalArgumentException("Maven cache is not a directory directory " + file);
            }
            final PathResource fileResource = new PathResource(file);
            super.setRoot(fileResource);
        } catch (final Throwable e) {
            throw new IllegalArgumentException("Maven cache must resolve to a local directory " + root);
        }
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) File(java.io.File)

Example 3 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class MavenRepository method getMavenMetadata.

public MapEx getMavenMetadata(final String groupId, final String artifactId, final String version) {
    final String mavenMetadataPath = "/" + Strings.toString("/", groupId.replace('.', '/'), artifactId, version, "maven-metadata.xml");
    final Resource resource = this.root;
    final Resource mavenMetadataResource = resource.newChildResource(mavenMetadataPath);
    if (mavenMetadataResource.exists()) {
        try {
            return Xml.toMap(mavenMetadataResource);
        } catch (final RuntimeException e) {
            Logs.error(this, "Error loading maven resource" + mavenMetadataResource, e);
            if (mavenMetadataResource instanceof PathResource) {
                try {
                    final File file = mavenMetadataResource.getFile();
                    if (file.delete()) {
                        Logs.error(this, "Deleting corrupt maven resource" + mavenMetadataResource, e);
                    }
                } catch (final Throwable ioe) {
                }
            }
            throw e;
        }
    } else {
        return MapEx.EMPTY;
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) File(java.io.File)

Example 4 with PathResource

use of com.revolsys.spring.resource.PathResource 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)

Example 5 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class ShapefileDirectoryWriter method getWriter.

private Writer<Record> getWriter(final Record object) {
    final RecordDefinition recordDefinition = object.getRecordDefinition();
    final String path = recordDefinition.getPath();
    Writer<Record> writer = this.writers.get(path);
    if (writer == null) {
        final File directory = getDirectory(recordDefinition);
        directory.mkdirs();
        final File file = new File(directory, getFileName(recordDefinition) + this.nameSuffix + ".shp");
        writer = RecordWriter.newRecordWriter(recordDefinition, new PathResource(file));
        ((XbaseRecordWriter) writer).setUseZeroForNull(this.useZeroForNull);
        final Geometry geometry = object.getGeometry();
        if (geometry != null) {
            setProperty(IoConstants.GEOMETRY_FACTORY, geometry.getGeometryFactory());
        }
        this.writers.put(path, writer);
        this.recordDefinitionMap.put(path, ((ShapefileRecordWriter) writer).getRecordDefinition());
    }
    return writer;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) XbaseRecordWriter(com.revolsys.record.io.format.xbase.XbaseRecordWriter) PathResource(com.revolsys.spring.resource.PathResource) Record(com.revolsys.record.Record) File(java.io.File) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

PathResource (com.revolsys.spring.resource.PathResource)24 File (java.io.File)15 Resource (com.revolsys.spring.resource.Resource)7 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 Geometry (com.revolsys.geometry.model.Geometry)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 FileNameExtensionFilter (com.revolsys.io.file.FileNameExtensionFilter)2 RecordWriter (com.revolsys.record.io.RecordWriter)2 Path (java.nio.file.Path)2 JFileChooser (javax.swing.JFileChooser)2 LasPointCloud (com.revolsys.elevation.cloud.las.LasPointCloud)1 TriangulatedIrregularNetwork (com.revolsys.elevation.tin.TriangulatedIrregularNetwork)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)1 PathName (com.revolsys.io.PathName)1 ExtensionFilenameFilter (com.revolsys.io.filter.ExtensionFilenameFilter)1 ObjectWithProperties (com.revolsys.properties.ObjectWithProperties)1 RecordWriterFactory (com.revolsys.record.io.RecordWriterFactory)1