@Override public void close() throws IOException { try { if (!saved && !read) { byte[] bytes = new byte[1<<13]; while (!saved) { read(bytes, 0, bytes.length); } } fsos.close(); } finally { if (!saved) { fsisf.free(); saved = true; } super.close(); } }
@Override public void close() throws IOException { if (closed) { return; } flush(); closed = true; if (bytesWritten) { this.buffer = null; } else { //truncate this.buffer = Arrays.copyOf(this.buffer, this.count); } }
public InputStream getInputStream(long start, long len) { if (fsos != null && !fsos.bytesWritten()) { if (start > Integer.MAX_VALUE) { throw new AssertionError("Invalid start " + start); //$NON-NLS-1$ } int s = (int)start; int intLen = fsos.getCount() - s; if (len >= 0) { intLen = (int)Math.min(len, len); } return new ByteArrayInputStream(fsos.getBuffer(), s, intLen); } return lobBuffer.createInputStream(start, len); }
if (binary) { if (val instanceof BinaryType) { result.getOuputStream().write(((BinaryType)val).getBytesDirect()); return;
if (binary) { if (val instanceof BinaryType) { result.getOuputStream().write(((BinaryType)val).getBytesDirect()); return;
if (binary) { if (val instanceof BinaryType) { result.getOuputStream().write(((BinaryType)val).getBytesDirect()); return;
/** * @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext) */ public Object getResult(CommandContext commandContext) throws TeiidProcessingException{ if (this.result == null) { return null; } try { this.result.getWriter().close(); FileStoreOutputStream fs = this.result.getOuputStream(); fs.close(); if (binary) { if (fs.bytesWritten()) { return new BlobType(new BlobImpl(result)); } return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount()))); } if (fs.bytesWritten()) { return new ClobType(new ClobImpl(result, -1)); } return new ClobType(new ClobImpl(new String(Arrays.copyOf(fs.getBuffer(), fs.getCount()), Streamable.ENCODING))); } catch (IOException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e); } catch (SQLException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e); } } }
/** * @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext) */ public Object getResult(CommandContext commandContext) throws TeiidProcessingException{ if (this.result == null) { this.result = buildResult(commandContext); } try { this.result.getWriter().close(); FileStoreOutputStream fs = this.result.getOuputStream(); fs.close(); if (binary) { if (fs.bytesWritten()) { return new BlobType(new BlobImpl(result)); } return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount()))); } if (fs.bytesWritten()) { return new ClobType(new ClobImpl(result, -1)); } return new ClobType(new ClobImpl(new String(Arrays.copyOf(fs.getBuffer(), fs.getCount()), Streamable.ENCODING))); } catch (IOException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e); } catch (SQLException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e); } } }
@Override public void write(byte[] b, int off, int len) throws IOException { checkOpen(); if (len > maxSize) { flushBuffer(); writeDirect(b, off, len); return; } if (!bytesWritten && buffer.length < maxSize && count + len > buffer.length) { byte[] nextBuffer = new byte[Math.min(maxSize, DataTypeManager.nextPowOf2(count + len))]; System.arraycopy(buffer, 0, nextBuffer, 0, count); buffer = nextBuffer; } int bufferedLength = Math.min(len, buffer.length - count); if (count < buffer.length) { System.arraycopy(b, off, buffer, count, bufferedLength); count += bufferedLength; if (bufferedLength == len) { return; } } flushBuffer(); System.arraycopy(b, off + bufferedLength, buffer, count, len - bufferedLength); count += len - bufferedLength; }
@Override public void write(byte[] b, int off, int len) throws IOException { checkOpen(); if (len > maxSize) { flushBuffer(); writeDirect(b, off, len); return; } if (!bytesWritten && buffer.length < maxSize && count + len > buffer.length) { byte[] nextBuffer = new byte[Math.min(maxSize, DataTypeManager.nextPowOf2(count + len))]; System.arraycopy(buffer, 0, nextBuffer, 0, count); buffer = nextBuffer; } int bufferedLength = Math.min(len, buffer.length - count); if (count < buffer.length) { System.arraycopy(b, off, buffer, count, bufferedLength); count += bufferedLength; if (bufferedLength == len) { return; } } flushBuffer(); System.arraycopy(b, off + bufferedLength, buffer, count, len - bufferedLength); count += len - bufferedLength; }
/** * @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext) */ public Object getResult(CommandContext commandContext) throws TeiidProcessingException{ if (this.result == null) { return null; } try { this.result.getWriter().close(); FileStoreOutputStream fs = this.result.getOuputStream(); fs.close(); if (binary) { if (fs.bytesWritten()) { return new BlobType(new BlobImpl(result)); } return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount()))); } if (fs.bytesWritten()) { return new ClobType(new ClobImpl(result, -1)); } return new ClobType(new ClobImpl(new String(Arrays.copyOf(fs.getBuffer(), fs.getCount()), Streamable.ENCODING))); } catch (IOException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e); } catch (SQLException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e); } } }
@Override public void write(byte[] b, int off, int len) throws IOException { checkOpen(); if (len > maxSize) { flushBuffer(); writeDirect(b, off, len); return; } if (!bytesWritten && buffer.length < maxSize && count + len > buffer.length) { byte[] nextBuffer = new byte[Math.min(maxSize, DataTypeManager.nextPowOf2(count + len))]; System.arraycopy(buffer, 0, nextBuffer, 0, count); buffer = nextBuffer; } int bufferedLength = Math.min(len, buffer.length - count); if (count < buffer.length) { System.arraycopy(b, off, buffer, count, bufferedLength); count += bufferedLength; if (bufferedLength == len) { return; } } flushBuffer(); System.arraycopy(b, off + bufferedLength, buffer, count, len - bufferedLength); count += len - bufferedLength; }
/** * @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext) */ public Object getResult(CommandContext commandContext) throws TeiidProcessingException{ if (this.result == null) { this.result = buildResult(commandContext); } try { FileStoreOutputStream fs = this.result.getOuputStream(); fs.close(); if (fs.bytesWritten()) { return new BlobType(new BlobImpl(result)); } return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount()))); } catch (IOException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e); } catch (SQLException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e); } } }
/** * @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext) */ public Object getResult(CommandContext commandContext) throws TeiidProcessingException{ if (this.result == null) { this.result = buildResult(commandContext); } try { FileStoreOutputStream fs = this.result.getOuputStream(); fs.close(); if (fs.bytesWritten()) { return new BlobType(new BlobImpl(result)); } return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount()))); } catch (IOException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e); } catch (SQLException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e); } } }
/** * @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext) */ public Object getResult(CommandContext commandContext) throws TeiidProcessingException{ if (this.result == null) { this.result = buildResult(commandContext); } try { FileStoreOutputStream fs = this.result.getOuputStream(); fs.close(); if (fs.bytesWritten()) { return new BlobType(new BlobImpl(result)); } return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount()))); } catch (IOException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e); } catch (SQLException e) { throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e); } } }
@Override public void close() throws IOException { try { if (!saved && !read) { byte[] bytes = new byte[1<<13]; while (!saved) { read(bytes, 0, bytes.length); } } fsos.close(); } finally { if (!saved) { fsisf.free(); saved = true; } super.close(); } }
@Override public void close() throws IOException { try { if (!saved && !read) { byte[] bytes = new byte[1<<13]; while (!saved) { read(bytes, 0, bytes.length); } } fsos.close(); } finally { if (!saved) { fsisf.free(); saved = true; } super.close(); } }
@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(); }
@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(); }