Search in sources :

Example 6 with FileStoreInputStreamFactory

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();
        }
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) FilterReader(java.io.FilterReader) Reader(java.io.Reader) BufferManager(org.teiid.common.buffer.BufferManager) ClobImpl(org.teiid.core.types.ClobImpl) Writer(java.io.Writer)

Example 7 with FileStoreInputStreamFactory

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;
}
Also used : FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory)

Example 8 with FileStoreInputStreamFactory

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);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) TextLine(org.teiid.query.sql.symbol.TextLine) IOException(java.io.IOException) DerivedColumn(org.teiid.query.sql.symbol.DerivedColumn) Writer(java.io.Writer) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 9 with FileStoreInputStreamFactory

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;
}
Also used : FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

FileStoreInputStreamFactory (org.teiid.common.buffer.FileStoreInputStreamFactory)9 FileStore (org.teiid.common.buffer.FileStore)7 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 Reader (java.io.Reader)2 Writer (java.io.Writer)2 SQLException (java.sql.SQLException)2 TeiidComponentException (org.teiid.core.TeiidComponentException)2 ReaderInputStream (org.teiid.core.util.ReaderInputStream)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FilterReader (java.io.FilterReader)1 StreamCorruptedException (java.io.StreamCorruptedException)1 ArrayList (java.util.ArrayList)1 DataSource (javax.activation.DataSource)1 ResourceException (javax.resource.ResourceException)1