use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class OracleJdbcBlobFieldDefinition 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 {
if (value instanceof Blob) {
final Blob blob = (Blob) value;
statement.setBlob(parameterIndex, blob);
} else {
InputStream in;
if (value instanceof Blob) {
final Blob blob = (Blob) value;
in = blob.getBinaryStream();
} else if (value instanceof byte[]) {
final byte[] bytes = (byte[]) value;
in = new ByteArrayInputStream(bytes);
} else if (value instanceof CharSequence) {
final String string = ((CharSequence) value).toString();
final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
in = new ByteArrayInputStream(bytes);
} else {
try {
final Resource resource = Resource.getResource(value);
in = resource.newBufferedInputStream();
} catch (final IllegalArgumentException e) {
throw new IllegalArgumentException(value.getClass() + " not valid for a blob column");
}
}
statement.setBinaryStream(parameterIndex, in);
}
}
return parameterIndex + 1;
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class PostgreSQLJdbcBlobFieldDefinition 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;
statement.setBlob(parameterIndex, blob);
} else {
InputStream in;
if (value instanceof InputStream) {
in = (InputStream) value;
} else if (value instanceof byte[]) {
final byte[] bytes = (byte[]) value;
in = new ByteArrayInputStream(bytes);
} else if (value instanceof CharSequence) {
final String string = ((CharSequence) value).toString();
final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
in = new ByteArrayInputStream(bytes);
} else {
try {
final Resource resource = Resource.getResource(value);
in = resource.newBufferedInputStream();
} catch (final IllegalArgumentException e) {
throw new IllegalArgumentException(value.getClass() + " not valid for a blob column");
}
}
try {
final PGConnection pgConnection = (PGConnection) ((DelegatingConnection<?>) statement.getConnection()).getInnermostDelegate();
final LargeObjectManager lobManager = pgConnection.getLargeObjectAPI();
final long lobId = lobManager.createLO(LargeObjectManager.READ | LargeObjectManager.WRITE);
final LargeObject lob = lobManager.open(lobId, LargeObjectManager.WRITE);
try {
final byte[] buffer = new byte[2048];
int readCount = 0;
while ((readCount = in.read(buffer, 0, 2048)) > 0) {
lob.write(buffer, 0, readCount);
}
} finally {
lob.close();
}
statement.setLong(parameterIndex, lobId);
} catch (final IOException e) {
Exceptions.throwUncheckedException(e);
}
}
}
return parameterIndex + 1;
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class AbstractGeoreferencedImage method saveChanges.
@Override
public boolean saveChanges() {
try {
final Resource resource = this.imageResource;
final Resource rgResource = resource.newResourceAddExtension("rgobject");
MapObjectFactory.write(rgResource, this);
setHasChanges(false);
return true;
} catch (final Throwable e) {
Logs.error(this, "Unable to save: " + this.imageResource + ".rgobject", e);
return false;
}
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class AbstractGeoreferencedImage method loadSettings.
protected long loadSettings() {
final Resource resource = getImageResource();
final Resource settingsFile = resource.newResourceAddExtension("rgobject");
if (settingsFile.exists()) {
try {
Map<String, Object> settings;
try {
settings = Json.toMap(settingsFile);
} catch (final Throwable e) {
settings = new LinkedHashMapEx();
}
final String boundingBoxWkt = (String) settings.get("boundingBox");
if (Property.hasValue(boundingBoxWkt)) {
final BoundingBox boundingBox = BoundingBox.newBoundingBox(boundingBoxWkt);
if (!boundingBox.isEmpty()) {
setBoundingBox(boundingBox);
}
}
final List<?> tiePointsProperty = (List<?>) settings.get("tiePoints");
final List<MappedLocation> tiePoints = new ArrayList<>();
if (tiePointsProperty != null) {
for (final Object tiePointValue : tiePointsProperty) {
if (tiePointValue instanceof MappedLocation) {
tiePoints.add((MappedLocation) tiePointValue);
} else if (tiePointValue instanceof Map) {
@SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) tiePointValue;
tiePoints.add(new MappedLocation(map));
}
}
}
if (!tiePoints.isEmpty()) {
setTiePoints(tiePoints);
}
return settingsFile.getLastModified();
} catch (final Throwable e) {
Logs.error(this, "Unable to load:" + settingsFile, e);
return -1;
}
} else {
return -1;
}
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class AbstractGeoreferencedImage method loadWorldFile.
protected void loadWorldFile() {
final Resource resource = getImageResource();
final Resource worldFile = resource.newResourceChangeExtension(getWorldFileExtension());
loadWorldFile(worldFile);
}
Aggregations