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();
}
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);
}
}
}
}
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();
}
}
}
}
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");
}
}
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;
}
Aggregations