use of org.teiid.core.types.ClobType in project teiid by teiid.
the class S3ProcedureExecution method next.
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (this.command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.SAVEFILE) || this.command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.DELETEFILE)) {
return null;
}
if (this.execution == null || this.execution.getResponseCode() < 200 || this.execution.getResponseCode() > 300) {
return null;
}
Blob contents = (Blob) execution.getOutputParameterValues().get(0);
BlobInputStreamFactory isf = new BlobInputStreamFactory(contents);
String length = getHeader("Content-Length");
if (length != null) {
isf.setLength(Long.parseLong(length));
}
Object value = null;
if (isText) {
ClobImpl clob = new ClobImpl(isf, -1);
clob.setCharset(Charset.forName(this.ef.getEncoding()));
value = new ClobType(clob);
if (!streaming) {
value = new InputStreamFactory.ClobInputStreamFactory(clob);
}
} else {
if (streaming) {
value = new BlobType(contents);
} else {
value = isf;
}
}
String lastModified = getHeader("Last-Modified");
ArrayList<Object> result = new ArrayList<Object>(2);
result.add(value);
if (!isList) {
result.add(endpoint);
try {
SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss zzz");
result.add(lastModified == null ? null : new Timestamp(df.parse(lastModified).getTime()));
} catch (ParseException e) {
result.add(null);
}
result.add(getHeader("ETag"));
result.add(length);
}
this.execution = null;
return result;
}
use of org.teiid.core.types.ClobType in project teiid by teiid.
the class FunctionMethods method toChars.
@TeiidFunction(category = FunctionCategoryConstants.CONVERSION, name = "to_chars")
public static ClobType toChars(BlobType value, String encoding, boolean wellFormed) throws SQLException, IOException {
Charset cs = getCharset(encoding);
BlobInputStreamFactory bisf = new BlobInputStreamFactory(value.getReference());
ClobImpl clob = new ClobImpl(bisf, -1);
clob.setCharset(cs);
if (!wellFormed && !CharsetUtils.BASE64_NAME.equalsIgnoreCase(encoding) && !CharsetUtils.HEX_NAME.equalsIgnoreCase(encoding)) {
// validate that the charcter conversion is possible
// TODO: cache the result in a filestore
Reader r = clob.getCharacterStream();
try {
while (r.read() != -1) {
}
} catch (IOException e) {
CharacterCodingException cce = ExceptionUtil.getExceptionOfType(e, CharacterCodingException.class);
if (cce != null) {
throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10082, cs.displayName()), cce);
}
throw e;
} finally {
r.close();
}
}
return new ClobType(clob);
}
use of org.teiid.core.types.ClobType in project teiid by teiid.
the class GeometryUtils method geometryToClob.
public static ClobType geometryToClob(GeometryType geometry, boolean withSrid) throws FunctionExecutionException {
Geometry jtsGeometry = getGeometry(geometry);
int srid = jtsGeometry.getSRID();
StringBuilder geomText = new StringBuilder();
if (withSrid && srid != GeometryType.UNKNOWN_SRID) {
// $NON-NLS-1$ //$NON-NLS-2$
geomText.append("SRID=").append(jtsGeometry.getSRID()).append(";");
}
geomText.append(jtsGeometry.toText());
return new ClobType(new ClobImpl(geomText.toString()));
}
use of org.teiid.core.types.ClobType in project teiid by teiid.
the class GeometryUtils method geometryToGeoJson.
public static ClobType geometryToGeoJson(GeometryType geometry) throws FunctionExecutionException {
Geometry jtsGeometry = getGeometry(geometry);
GeoJSONWriter writer = new GeoJSONWriter();
try {
GeoJSON geoJson = writer.write(jtsGeometry);
ClobType result = new ClobType(new ClobImpl(geoJson.toString()));
result.setType(Type.JSON);
return result;
} catch (Exception e) {
throw new FunctionExecutionException(e);
}
}
use of org.teiid.core.types.ClobType in project teiid by teiid.
the class GeometryUtils method geometryToGml.
public static ClobType geometryToGml(CommandContext ctx, GeometryType geometry, boolean withGmlPrefix) throws FunctionExecutionException {
Geometry jtsGeometry = getGeometry(geometry);
GMLWriter writer = new GMLWriter();
if (!withGmlPrefix) {
if (geometry.getSrid() != SRID_4326) {
if (geometry.getSrid() == GeometryType.UNKNOWN_SRID) {
throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31161));
}
jtsGeometry = GeometryTransformUtils.transform(ctx, jtsGeometry, SRID_4326);
}
writer.setPrefix(null);
} else if (geometry.getSrid() != GeometryType.UNKNOWN_SRID) {
// TODO: should include the srsName
// writer.setSrsName(String.valueOf(geometry.getSrid()));
}
String gmlText = writer.write(jtsGeometry);
return new ClobType(new ClobImpl(gmlText));
}
Aggregations