Search in sources :

Example 26 with Resource

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

the class MapGuideServerFeatureIterator method newParser.

protected StaxReader newParser() {
    if (this.closed) {
        throw new NoSuchElementException();
    } else {
        this.currentRecordCount = 0;
        if (this.supportsPaging) {
            this.queryParameters.put("resultOffset", this.queryOffset + this.totalRecordCount);
            if (this.serverLimit > 0) {
                this.queryParameters.put("resultRecordCount", this.serverLimit);
            }
        }
        final Resource resource = this.layer.getResource(this.queryParameters);
        this.reader = StaxReader.newXmlReader(resource);
        if (!this.reader.skipToStartElement("Features")) {
            throw new NoSuchElementException();
        }
        return this.reader;
    }
}
Also used : Resource(com.revolsys.spring.resource.Resource) NoSuchElementException(java.util.NoSuchElementException)

Example 27 with Resource

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

the class ArcGisResponse method refreshDo.

protected void refreshDo() {
    final UrlResource serviceUrl = getServiceUrl();
    final Resource resource;
    if (isUseProxy()) {
        final String url = serviceUrl.getUriString() + "%3ff%3djson";
        final String username = serviceUrl.getUsername();
        final String password = serviceUrl.getPassword();
        resource = new UrlResource(url, username, password);
    } else {
        resource = serviceUrl.newUrlResource(Collections.singletonMap("f", "json"));
    }
    final MapEx newProperties = Json.toMap(resource);
    initialize(newProperties);
}
Also used : UrlResource(com.revolsys.spring.resource.UrlResource) MapEx(com.revolsys.collection.map.MapEx) UrlResource(com.revolsys.spring.resource.UrlResource) WebServiceResource(com.revolsys.webservice.WebServiceResource) Resource(com.revolsys.spring.resource.Resource)

Example 28 with Resource

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

the class XbaseRecordWriter method init.

protected void init() throws IOException {
    if (!this.initialized) {
        this.initialized = true;
        final Resource resource = getResource();
        if (resource != null) {
            final Map<String, String> shortNames = getProperty("shortNames");
            if (shortNames != null) {
                this.shortNames = shortNames;
            }
            this.out = resource.newWritableByteChannel();
            writeHeader();
        }
        final Resource codePageResource = resource.newResourceChangeExtension("cpg");
        if (codePageResource != null) {
            try (final Writer writer = codePageResource.newWriter()) {
                writer.write(this.charset.name());
            }
        }
    }
}
Also used : Resource(com.revolsys.spring.resource.Resource) AbstractRecordWriter(com.revolsys.io.AbstractRecordWriter) Writer(java.io.Writer)

Example 29 with Resource

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

the class ShapefileRecordReader method initDo.

@Override
protected synchronized void initDo() {
    if (this.in == null) {
        try {
            try {
                if (this.resource.isFile()) {
                    final File file = this.resource.getFile();
                    this.in = new LittleEndianRandomAccessFile(file, "r");
                } else {
                    this.in = new EndianInputStream(this.resource.getInputStream());
                }
            } catch (final IllegalArgumentException | UnsupportedOperationException e) {
                this.in = new EndianInputStream(this.resource.getInputStream());
            }
            final Resource xbaseResource = this.resource.newResourceChangeExtension("dbf");
            if (xbaseResource != null && xbaseResource.exists()) {
                this.xbaseRecordReader = new XbaseRecordReader(xbaseResource, this.recordFactory, () -> updateRecordDefinition());
                this.xbaseRecordReader.setTypeName(this.typeName);
                this.xbaseRecordReader.setCloseFile(this.closeFile);
            }
            loadHeader();
            int axisCount;
            switch(this.shapeType) {
                // 1
                case ShapefileConstants.POINT_SHAPE:
                // 3
                case ShapefileConstants.POLYLINE_SHAPE:
                // 5
                case ShapefileConstants.POLYGON_SHAPE:
                case // 8
                ShapefileConstants.MULTI_POINT_SHAPE:
                    axisCount = 2;
                    break;
                // 9
                case ShapefileConstants.POINT_Z_SHAPE:
                // 10
                case ShapefileConstants.POLYLINE_Z_SHAPE:
                // 19
                case ShapefileConstants.POLYGON_Z_SHAPE:
                case // 20
                ShapefileConstants.MULTI_POINT_Z_SHAPE:
                    axisCount = 3;
                    break;
                // 11
                case ShapefileConstants.POINT_ZM_SHAPE:
                // 13
                case ShapefileConstants.POLYLINE_ZM_SHAPE:
                // 15
                case ShapefileConstants.POLYGON_ZM_SHAPE:
                // 18
                case ShapefileConstants.MULTI_POINT_ZM_SHAPE:
                // 21
                case ShapefileConstants.POINT_M_SHAPE:
                // 23
                case ShapefileConstants.POLYLINE_M_SHAPE:
                // 25
                case ShapefileConstants.POLYGON_M_SHAPE:
                case // 28
                ShapefileConstants.MULTI_POINT_M_SHAPE:
                    axisCount = 4;
                    break;
                default:
                    throw new RuntimeException("Unknown shape type:" + this.shapeType);
            }
            this.geometryFactory = getProperty(IoConstants.GEOMETRY_FACTORY);
            if (this.geometryFactory == null) {
                this.geometryFactory = GeometryFactory.floating(this.resource, axisCount);
            }
            if (this.geometryFactory == null) {
                this.geometryFactory = GeometryFactory.floating(0, axisCount);
            }
            setProperty(IoConstants.GEOMETRY_FACTORY, this.geometryFactory);
            if (this.xbaseRecordReader != null) {
                this.xbaseRecordReader.hasNext();
            }
            if (this.recordDefinition == null) {
                this.recordDefinition = Records.newGeometryRecordDefinition();
            }
            this.recordDefinition.setGeometryFactory(this.geometryFactory);
        } catch (final IOException e) {
            throw new RuntimeException("Error initializing mappedFile " + this.resource, e);
        }
    }
}
Also used : EndianInputStream(com.revolsys.io.endian.EndianInputStream) Resource(com.revolsys.spring.resource.Resource) XbaseRecordReader(com.revolsys.record.io.format.xbase.XbaseRecordReader) LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile) IOException(java.io.IOException) File(java.io.File) LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile)

Example 30 with Resource

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

the class ShapefileZip method newRecordWriter.

@Override
public RecordWriter newRecordWriter(final String baseName, final RecordDefinition recordDefinition, final OutputStream outputStream, final Charset charset) {
    File directory;
    try {
        directory = FileUtil.newTempDirectory(baseName, "zipDir");
    } catch (final Throwable e) {
        throw new RuntimeException("Unable to create temporary directory", e);
    }
    final Resource tempResource = new PathResource(new File(directory, baseName + ".shp"));
    final RecordWriter shapeWriter = new ShapefileRecordWriter(recordDefinition, tempResource);
    return new ZipRecordWriter(directory, shapeWriter, outputStream);
}
Also used : ZipRecordWriter(com.revolsys.record.io.format.zip.ZipRecordWriter) RecordWriter(com.revolsys.record.io.RecordWriter) ZipRecordWriter(com.revolsys.record.io.format.zip.ZipRecordWriter) PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) File(java.io.File)

Aggregations

Resource (com.revolsys.spring.resource.Resource)78 PathResource (com.revolsys.spring.resource.PathResource)23 MapEx (com.revolsys.collection.map.MapEx)9 File (java.io.File)9 IOException (java.io.IOException)8 InputStream (java.io.InputStream)6 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 UrlResource (com.revolsys.spring.resource.UrlResource)5 Writer (java.io.Writer)5 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 DataType (com.revolsys.datatype.DataType)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)3 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 RecordReader (com.revolsys.record.io.RecordReader)3 RecordWriter (com.revolsys.record.io.RecordWriter)3 Blob (java.sql.Blob)3