Search in sources :

Example 46 with Resource

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

the class OsmDocument method newDocument.

public static OsmDocument newDocument(final String serverUrl, BoundingBox boundingBox) {
    if (boundingBox != null) {
        boundingBox = boundingBox.convert(OsmConstants.WGS84_2D);
        if (!boundingBox.isEmpty()) {
            final StringBuilder url = new StringBuilder(serverUrl);
            url.append("map?bbox=");
            url.append(boundingBox.getMinX());
            url.append(",");
            url.append(boundingBox.getMinY());
            url.append(",");
            url.append(boundingBox.getMaxX());
            url.append(",");
            url.append(boundingBox.getMaxY());
            final Resource resource = new UrlResource(url.toString());
            return new OsmDocument(resource);
        }
    }
    return new OsmDocument();
}
Also used : UrlResource(com.revolsys.spring.resource.UrlResource) Resource(com.revolsys.spring.resource.Resource) UrlResource(com.revolsys.spring.resource.UrlResource)

Example 47 with Resource

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

the class JsonParser method read.

@SuppressWarnings("unchecked")
public static <V> V read(final Object source) {
    Reader reader;
    if (source instanceof Clob) {
        try {
            reader = ((Clob) source).getCharacterStream();
        } catch (final SQLException e) {
            throw new RuntimeException("Unable to read clob", e);
        }
    } else if (source instanceof Reader) {
        reader = (Reader) source;
    } else if (source instanceof CharSequence) {
        reader = new StringReader(source.toString());
    } else {
        try {
            final Resource resource = Resource.getResource(source);
            reader = resource.newBufferedReader();
        } catch (final WrappedException e) {
            reader = new StringReader(source.toString());
        }
    }
    try {
        final V value = (V) read(reader);
        return value;
    } finally {
        if (source instanceof Clob) {
            try {
                final Clob clob = (Clob) source;
                clob.free();
            } catch (final SQLException e) {
                throw new RuntimeException("Unable to free clob resources", e);
            }
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) SQLException(java.sql.SQLException) StringReader(java.io.StringReader) Resource(com.revolsys.spring.resource.Resource) Reader(java.io.Reader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Clob(java.sql.Clob)

Example 48 with Resource

use of com.revolsys.spring.resource.Resource 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();
            }
        }
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Example 49 with Resource

use of com.revolsys.spring.resource.Resource 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");
    }
}
Also used : Dataset(org.gdal.gdal.Dataset) PathResource(com.revolsys.spring.resource.PathResource) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 50 with Resource

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

the class JdbcBlobFieldDefinition method setPreparedStatementValue.

@Override
public int setPreparedStatementValue(final PreparedStatement statement, final int parameterIndex, final Object value) throws SQLException {
    if (value == null) {
        final int sqlType = getSqlType();
        statement.setNull(parameterIndex, sqlType);
    } else {
        Blob blob;
        if (value instanceof Blob) {
            blob = (Blob) value;
        } else if (value instanceof byte[]) {
            final byte[] bytes = (byte[]) value;
            blob = new LocalBlob(bytes);
        } else if (value instanceof CharSequence) {
            final String string = ((CharSequence) value).toString();
            final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
            blob = new LocalBlob(bytes);
        } else {
            try {
                final Resource resource = Resource.getResource(value);
                blob = new LocalBlob(resource);
            } catch (final IllegalArgumentException e) {
                throw new IllegalArgumentException(value.getClass() + " not valid for a blob column");
            }
        }
        statement.setBlob(parameterIndex, blob);
    }
    return parameterIndex + 1;
}
Also used : Blob(java.sql.Blob) LocalBlob(com.revolsys.jdbc.LocalBlob) Resource(com.revolsys.spring.resource.Resource) LocalBlob(com.revolsys.jdbc.LocalBlob)

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