public JSONBuilder(BufferManager bm) { fs = bm.createFileStore("json"); //$NON-NLS-1$ fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); writer = fsisf.getWriter(); }
@Override public InputStream getInputStream() { return getInputStream(0, -1); }
public SaveOnReadInputStream(InputStream in, FileStoreInputStreamFactory fsisf) { super(in); this.fsisf = fsisf; fsos = fsisf.getOuputStream(); }
@Override public InputStream getInputStream() throws IOException { if (!saved) { if (!returned) { returned = true; return sis; } //save the rest of the stream SaveOnReadInputStream.this.fsos.flush(); long start = SaveOnReadInputStream.this.fsisf.getLength(); SaveOnReadInputStream.this.close(); //force the pending read InputStream is = SaveOnReadInputStream.this.fsisf.getInputStream(start, -1); sis.setIn(is); } return fsisf.getInputStream(); }
public static ClobType concat(CommandContext context, ClobType str1, ClobType str2) throws IOException, SQLException { BufferManager bm = context.getBufferManager(); FileStore fs = bm.createFileStore("clob"); //$NON-NLS-1$ 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(); } } }
public JsonType close(CommandContext cc) throws TeiidProcessingException { try { writer.close(); } catch (IOException e) { remove(); throw new TeiidProcessingException(QueryPlugin.Event.TEIID30442, e); } if (fsisf.getStorageMode() == StorageMode.MEMORY) { //detach if just in memory byte[] bytes = fsisf.getMemoryBytes(); fsisf.free(); JsonType result = new JsonType(new ClobImpl(new String(bytes, Streamable.CHARSET))); return result; } JsonType result = new JsonType(new ClobImpl(fsisf, -1)); if (cc != null) { cc.addCreatedLob(fsisf); } return result; }
@Test public void testInputStream() throws IOException { FileStore fs = BufferManagerFactory.getStandaloneBufferManager().createFileStore("test"); FileStoreInputStreamFactory factory = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); OutputStream os = factory.getOuputStream(0); os.write(new byte[2]); os.close(); InputStream is = factory.getInputStream(0, 1); is.read(); assertEquals(-1, is.read()); }
private FileStoreInputStreamFactory buildResult(CommandContext context) { FileStore fs = context.getBufferManager().createFileStore("string_agg"); //$NON-NLS-1$ FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); return fisf; }
if (binary) { if (val instanceof BinaryType) { result.getOuputStream().write(((BinaryType)val).getBytesDirect()); return; InputStream binaryStream = b.getBinaryStream(); try { ObjectConverterUtil.write(result.getOuputStream(), binaryStream, -1, false); } finally { binaryStream.close(); result.getWriter().write((String)val); return; Reader characterStream = c.getCharacterStream(); try { ObjectConverterUtil.write(result.getWriter(), characterStream, -1, false); } finally { characterStream.close();
public DocumentInProgress(FileStore store, String encoding) throws TeiidComponentException{ final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(store, encoding); this.xml = new SQLXMLImpl(fsisf); this.xml.setEncoding(encoding); SAXTransformerFactory factory = new TransformerFactoryImpl(); try { //SAX2.0 ContentHandler handler = factory.newTransformerHandler(); handler.setResult(new StreamResult(fsisf.getOuputStream())); } catch (Exception e) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30204, e); } transformer = handler.getTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, encoding); }
@Override public void free() throws IOException { fsisf.free(); ew.includes.clear(); }
if (isf.isTemporary()) { isf.free();
@Override public StorageMode getStorageMode() { if (!saved) { try { getInputStream().close(); } catch (IOException e) { return StorageMode.OTHER; } } return fsisf.getStorageMode(); } };
/** * Include the streamable value, rather than inlining. * @param s * @return true if the value could be included * @throws IOException */ public boolean include(Streamable<?> s) throws IOException { if (includes.size() == MAX_INCLUDES) { return false; } out.flush(); long length = fsisf.getLength(); includes.add(new Include(length, s)); return true; }
/** * @throws TeiidProcessingException * @throws TeiidComponentException * @see org.teiid.query.function.aggregate.AggregateFunction#addInputDirect(List, CommandContext, CommandContext) */ public void addInputDirect(Object input, List<?> tuple, CommandContext commandContext) throws TeiidComponentException, TeiidProcessingException { try { if (this.result == null) { this.result = buildResult(commandContext); } Array in = (Array)input; Writer w = result.getWriter(); writeList(w, (Object[])in.getArray()); w.flush(); } catch (SQLException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30421, e); } catch (IOException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30421, e); } }
public static ClobType concat(CommandContext context, ClobType str1, ClobType str2) throws IOException, SQLException { BufferManager bm = context.getBufferManager(); FileStore fs = bm.createFileStore("clob"); //$NON-NLS-1$ 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(); } } }
public JsonType close(CommandContext cc) throws TeiidProcessingException { try { writer.close(); } catch (IOException e) { remove(); throw new TeiidProcessingException(QueryPlugin.Event.TEIID30442, e); } if (fsisf.getStorageMode() == StorageMode.MEMORY) { //detach if just in memory byte[] bytes = fsisf.getMemoryBytes(); fsisf.free(); JsonType result = new JsonType(new ClobImpl(new String(bytes, Streamable.CHARSET))); return result; } JsonType result = new JsonType(new ClobImpl(fsisf, -1)); if (cc != null) { cc.addCreatedLob(fsisf); } return result; }
private FileStoreInputStreamFactory buildResult(CommandContext context) { FileStore fs = context.getBufferManager().createFileStore("string_agg"); //$NON-NLS-1$ FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); return fisf; }
if (binary) { if (val instanceof BinaryType) { result.getOuputStream().write(((BinaryType)val).getBytesDirect()); return; InputStream binaryStream = b.getBinaryStream(); try { ObjectConverterUtil.write(result.getOuputStream(), binaryStream, -1, false); } finally { binaryStream.close(); result.getWriter().write((String)val); return; Reader characterStream = c.getCharacterStream(); try { ObjectConverterUtil.write(result.getWriter(), characterStream, -1, false); } finally { characterStream.close();
FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs1, Streamable.ENCODING); FileStoreOutputStream fsos = fsisf.getOuputStream(); byte[] b = new byte[DataTypeManager.MAX_LOB_MEMORY_BYTES + 1]; fsos.write(b);