Package org.teiid.common.buffer

Examples of org.teiid.common.buffer.FileStore


      this.textLine = textLine;           
  }

  private FileStoreInputStreamFactory buildResult() throws TeiidProcessingException {
    try {
      FileStore fs = context.getBufferManager().createFileStore("textagg"); //$NON-NLS-1$
      FileStoreInputStreamFactory fisf = new FileStoreInputStreamFactory(fs, textLine.getEncoding()==null?Streamable.ENCODING:textLine.getEncoding());
      Writer w = fisf.getWriter();
      if (textLine.isIncludeHeader()) {
        w.write(TextLine.evaluate(textLine.getExpressions(), new TextLine.ValueExtractor<DerivedColumn>() {
          public Object getValue(DerivedColumn t) {
View Full Code Here


   * Documents less than the maxMemorySize will be held directly in memory
   */
  public static SQLXMLImpl saveToBufferManager(BufferManager bufferMgr, XMLTranslator translator)
      throws TeiidComponentException, TeiidProcessingException {       
      boolean success = false;
      final FileStore lobBuffer = bufferMgr.createFileStore("xml"); //$NON-NLS-1$
      FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(lobBuffer, Streamable.ENCODING);
      try
        Writer writer = fsisf.getWriter();
          translator.translate(writer);
          writer.close();
          success = true;
          return new SQLXMLImpl(fsisf);
      } catch(IOException e) {
          throw new TeiidComponentException(e);
      } catch(TransformerException e) {
          throw new TeiidProcessingException(e);
      } finally {
        if (!success && lobBuffer != null) {
          lobBuffer.remove();
        }
      }
  }
View Full Code Here

  }
   
    @Test public void testWrite() throws Exception {
        FileStorageManager sm = getStorageManager(null, null, null);       
        String tsID = "0";     //$NON-NLS-1$
        FileStore store = sm.createFileStore(tsID);
        writeBytes(store);
        assertEquals(2048, sm.getUsedBufferSpace());
        store.remove();
        assertEquals(0, sm.getUsedBufferSpace());
    }
View Full Code Here

  private Object convertToRuntimeType(Object value, Class<?> desiredType) throws TransformationException {
    if (value instanceof DataSource && (!(value instanceof Source) || desiredType != DataTypeManager.DefaultDataClasses.XML)) {
      if (value instanceof InputStreamFactory) {
        return new BlobType(new BlobImpl((InputStreamFactory)value));
      }
      FileStore fs = dtm.getBufferManager().createFileStore("bytes"); //$NON-NLS-1$
      //TODO: guess at the encoding from the content type
      FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
     
      try {
        ObjectConverterUtil.write(fsisf.getOuputStream(), ((DataSource)value).getInputStream(), -1);
View Full Code Here

        offset = store.getLength();
        //retest the condition to ensure that compaction is still needed
        if (!shouldCompact(offset)) {
          return offset;
        }
        FileStore newStore = createFileStore(id);
        newStore.setCleanupReference(this);
        byte[] buffer = new byte[IO_BUFFER_SIZE];
        List<long[]> values = new ArrayList<long[]>(physicalMapping.values());
        Collections.sort(values, new Comparator<long[]>() {
          @Override
          public int compare(long[] o1, long[] o2) {
            return Long.signum(o1[0] - o2[0]);
          }
        });
        for (long[] info : values) {
          long oldOffset = info[0];
          info[0] = newStore.getLength();
          int size = (int)info[1];
          while (size > 0) {
            int toWrite = Math.min(IO_BUFFER_SIZE, size);
            store.readFully(oldOffset, buffer, 0, toWrite);
            newStore.write(buffer, 0, toWrite);
            size -= toWrite;
          }
        }
        store.remove();
        store = newStore;
View Full Code Here

    }

  @Override
  public FileStore createFileStore(String name) {
    created.incrementAndGet();
    return new FileStore() {
      private ByteBuffer buffer = ByteBuffer.allocate(1 << 16);
     
      @Override
      public void writeDirect(byte[] bytes, int offset, int length) throws TeiidComponentException {
        if (getLength() + length > buffer.capacity()) {
View Full Code Here

           
    @Test public void testCreatesSpillFiles() throws Exception {
        FileStorageManager sm = getStorageManager(1024, null, null); // 1KB
        String tsID = "0";     //$NON-NLS-1$
        // Add one batch
        FileStore store = sm.createFileStore(tsID);
        writeBytes(store);
       
        Map<File, RandomAccessFile> cache = sm.getFileCache();
        assertEquals(1, cache.size());

        writeBytes(store);
       
        assertEquals(2, cache.size());
       
        store.remove();
       
        assertEquals(0, cache.size());
    }
View Full Code Here

    @Test(expected=TeiidComponentException.class) public void testMaxSpace() throws Exception {
      FileStorageManager sm = getStorageManager(null, null, null);
      sm.setMaxBufferSpace(1);
        String tsID = "0";     //$NON-NLS-1$
        // Add one batch
        FileStore store = sm.createFileStore(tsID);
        writeBytes(store);
    }
View Full Code Here

        writeBytes(store);
    }
   
    @Test public void testFlush() throws Exception {
      FileStorageManager sm = getStorageManager(null, null, null);
      FileStore store = sm.createFileStore("0");
      FileStoreOutputStream fsos = store.createOutputStream(2);
      fsos.write(new byte[3]);
      fsos.write(1);
      fsos.flush();
      assertEquals(0, fsos.getCount());
    }
View Full Code Here

 
    @Test public void testWritingMultipleFiles() throws Exception {
      FileStorageManager sm = getStorageManager(1024, null, null);
        String tsID = "0";     //$NON-NLS-1$
        // Add one batch
        FileStore store = sm.createFileStore(tsID);
        String contentOrig = new String("some file content this will stored in same tmp file with another");
        OutputStream out = store.createOutputStream();
        out.write(contentOrig.getBytes(), 0, contentOrig.getBytes().length);
        out.close();

        out = store.createOutputStream();
        long start = store.getLength();
        byte[] bytesOrig = new byte[2048];
        r.nextBytes(bytesOrig);
        out.write(bytesOrig, 0, 2048);
       
        byte[] readContent = new byte[2048];
        InputStream in = store.createInputStream(0, contentOrig.getBytes().length);       
      int c = in.read(readContent, 0, 3000);
         assertEquals(contentOrig, new String(readContent, 0, c));        
         c = in.read(readContent, 0, 3000);
         assertEquals(-1, c);
         in.close();
       
        in = store.createInputStream(start, 2048);
        c = in.read(readContent, 0, 3000);
        assertTrue(Arrays.equals(bytesOrig, readContent));
         c = in.read(readContent, 0, 3000);
         assertEquals(-1, c);
         in.close();       
View Full Code Here

TOP

Related Classes of org.teiid.common.buffer.FileStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.