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; }
@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 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(); } }
FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); context.addCreatedLob(fsisf); ((BaseLob) value).setStreamFactory(is.getInputStreamFactory()); } else { initial.close();
@Test public void testPartialReadSave() throws IOException { SaveOnReadInputStream soris = getSaveOnReadInputStream(); InputStreamFactory isf = soris.getInputStreamFactory(); InputStream is = isf.getInputStream(); is.read(); InputStream is2 = isf.getInputStream(); assertEquals("ello world", new String(ObjectConverterUtil.convertToByteArray(is), Streamable.CHARSET)); assertEquals("hello world", new String(ObjectConverterUtil.convertToByteArray(is2), Streamable.CHARSET)); InputStream is3 = isf.getInputStream(); assertEquals("hello world", new String(ObjectConverterUtil.convertToByteArray(is3), Streamable.CHARSET)); }
FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); context.addCreatedLob(fsisf); ((BaseLob) value).setStreamFactory(is.getInputStreamFactory()); } else { initial.close();
@Test public void testSave() throws IOException { SaveOnReadInputStream soris = getSaveOnReadInputStream(); InputStreamFactory isf = soris.getInputStreamFactory(); InputStream is = isf.getInputStream(); assertEquals("hello world", new String(ObjectConverterUtil.convertToByteArray(is), Streamable.CHARSET)); InputStream is2 = isf.getInputStream(); assertEquals("hello world", new String(ObjectConverterUtil.convertToByteArray(is2), Streamable.CHARSET)); }
FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); context.addCreatedLob(fsisf); ((BaseLob) value).setStreamFactory(is.getInputStreamFactory()); } else { initial.close();
@Test public void testStorageMode() throws IOException { SaveOnReadInputStream soris = getSaveOnReadInputStream(); InputStreamFactory isf = soris.getInputStreamFactory(); assertEquals(StorageMode.MEMORY, isf.getStorageMode()); InputStream is = isf.getInputStream(); assertEquals("hello world", new String(ObjectConverterUtil.convertToByteArray(is), Streamable.CHARSET)); }
@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 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(); } }
SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); if (context != null) { context.addCreatedLob(fsisf); return asLob(is.getInputStreamFactory(), desiredType); } catch (IOException e) { throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage()); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); final FileStore fs = bm.createFileStore("xml"); //$NON-NLS-1$ final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf);
@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 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(); } }
SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); if (context != null) { context.addCreatedLob(fsisf); return new BlobType(new BlobImpl(is.getInputStreamFactory())); } catch (IOException e) { throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage()); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); final FileStore fs = bm.createFileStore("xml"); //$NON-NLS-1$ final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf);
SaveOnReadInputStream is = new SaveOnReadInputStream(initial, fsisf); if (context != null) { context.addCreatedLob(fsisf); return asLob(is.getInputStreamFactory(), desiredType); } catch (IOException e) { throw new TransformationException(QueryPlugin.Event.TEIID30500, e, e.getMessage()); final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(is, fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf); final FileStore fs = bm.createFileStore("xml"); //$NON-NLS-1$ final FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING); value = new SaveOnReadInputStream(new XMLInputStream(ss, XMLSystemFunctions.getOutputFactory(true)), fsisf).getInputStreamFactory(); if (context != null) { context.addCreatedLob(fsisf);