use of org.teiid.core.types.ClobImpl 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.ClobImpl in project teiid by teiid.
the class AccumuloDataTypeManager method deserialize.
public static Object deserialize(final byte[] value, final Class<?> expectedType) {
if (value == null || Arrays.equals(value, EMPTY_BYTES)) {
return null;
}
try {
if (expectedType.isAssignableFrom(Clob.class)) {
return new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
}, -1);
} else if (expectedType.isAssignableFrom(Blob.class)) {
return new BlobType(new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
}));
} else if (expectedType.isAssignableFrom(SQLXML.class)) {
return new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
});
} else if (expectedType.isAssignableFrom(BinaryType.class)) {
return new BinaryType(value);
} else if (expectedType.isAssignableFrom(GeometryType.class)) {
GeometryType result = new GeometryType(Arrays.copyOf(value, value.length - 4));
int srid = (((value[value.length - 4] & 0xff) << 24) + ((value[value.length - 3] & 0xff) << 16) + ((value[value.length - 2] & 0xff) << 8) + ((value[value.length - 1] & 0xff) << 0));
result.setSrid(srid);
return result;
} else if (expectedType.isAssignableFrom(byte[].class)) {
return value;
} else if (expectedType.isAssignableFrom(String.class) || expectedType.isAssignableFrom(Boolean.class) || expectedType.isAssignableFrom(Boolean.class) || expectedType.isAssignableFrom(Byte.class) || expectedType.isAssignableFrom(Short.class) || expectedType.isAssignableFrom(Character.class) || expectedType.isAssignableFrom(Integer.class) || expectedType.isAssignableFrom(Long.class) || expectedType.isAssignableFrom(BigInteger.class) || expectedType.isAssignableFrom(BigDecimal.class) || expectedType.isAssignableFrom(Float.class) || expectedType.isAssignableFrom(Double.class) || expectedType.isAssignableFrom(Date.class) || expectedType.isAssignableFrom(Time.class) || expectedType.isAssignableFrom(Timestamp.class)) {
return DataTypeManager.transformValue(new String(value, UTF_8), expectedType);
} else {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(value));
Object obj = ois.readObject();
ois.close();
return obj;
}
} catch (ClassNotFoundException e) {
throw new TeiidRuntimeException(e);
} catch (IOException e) {
throw new TeiidRuntimeException(e);
} catch (TransformationException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.core.types.ClobImpl 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.ClobImpl 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.ClobImpl 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);
}
}
Aggregations