use of org.teiid.common.buffer.FileStoreInputStreamFactory in project teiid by teiid.
the class FunctionMethods method concat.
public static ClobType concat(CommandContext context, ClobType str1, ClobType str2) throws IOException, SQLException {
BufferManager bm = context.getBufferManager();
// $NON-NLS-1$
FileStore fs = bm.createFileStore("clob");
FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
boolean remove = true;
try (Reader characterStream = str1.getCharacterStream();
Reader characterStream2 = str2.getCharacterStream()) {
Writer writer = fsisf.getWriter();
int chars = ObjectConverterUtil.write(writer, characterStream, -1, false);
chars += ObjectConverterUtil.write(writer, characterStream2, -1, false);
writer.close();
if (fsisf.getStorageMode() == StorageMode.MEMORY) {
// detach if just in memory
byte[] bytes = fsisf.getMemoryBytes();
return new ClobType(new ClobImpl(new String(bytes, Streamable.ENCODING)));
}
remove = false;
context.addCreatedLob(fsisf);
return new ClobType(new ClobImpl(fsisf, chars));
} finally {
if (remove) {
fs.remove();
}
}
}
use of org.teiid.common.buffer.FileStoreInputStreamFactory in project teiid by teiid.
the class StringAgg method buildResult.
private FileStoreInputStreamFactory buildResult(CommandContext context) {
// $NON-NLS-1$
FileStore fs = context.getBufferManager().createFileStore("string_agg");
FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
return fisf;
}
use of org.teiid.common.buffer.FileStoreInputStreamFactory in project teiid by teiid.
the class TextAgg method buildResult.
private FileStoreInputStreamFactory buildResult(CommandContext context) throws TeiidProcessingException {
try {
// $NON-NLS-1$
FileStore fs = context.getBufferManager().createFileStore("textagg");
FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, textLine.getEncoding() == null ? Streamable.ENCODING : textLine.getEncoding());
Writer w = fisf.getWriter();
if (textLine.isIncludeHeader()) {
Object[] header = TextLine.evaluate(textLine.getExpressions(), new TextLine.ValueExtractor<DerivedColumn>() {
public Object getValue(DerivedColumn t) {
if (t.getAlias() == null && t.getExpression() instanceof ElementSymbol) {
return ((ElementSymbol) t.getExpression()).getShortName();
}
return t.getAlias();
}
}, textLine);
writeList(w, header);
}
w.flush();
return fisf;
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30420, e);
}
}
use of org.teiid.common.buffer.FileStoreInputStreamFactory in project teiid by teiid.
the class TestSaveOnReadInputStream method getSaveOnReadInputStream.
private SaveOnReadInputStream getSaveOnReadInputStream() {
FileStore fs = BufferManagerFactory.getStandaloneBufferManager().createFileStore("test");
FileStoreInputStreamFactory factory = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
InputStream is = new ByteArrayInputStream("hello world".getBytes(Streamable.CHARSET));
SaveOnReadInputStream soris = new SaveOnReadInputStream(is, factory);
return soris;
}
Aggregations