Package org.teiid.core.types

Examples of org.teiid.core.types.BlobType


      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(e);
    catch (SQLException e) {
      throw new TeiidProcessingException(e);
    }
View Full Code Here


       
        helpProcess(plan, createCommandContext(), dataManager, expected);
  }
 
  public static BlobType blobFromFile(final String file) {
    return new BlobType(new BlobImpl(new InputStreamFactory.FileInputStreamFactory(UnitTestUtil.getTestDataFile(file))));
  }
View Full Code Here

    public void testBlobValue() throws Exception {
        String testString = "this is test blob"; //$NON-NLS-1$
        SerialBlob blob = new SerialBlob(testString.getBytes());
       
        BlobType bv = new BlobType(blob);
        assertEquals(testString, new String(bv.getBytes(1L, (int)bv.length())));
    }
View Full Code Here

    public void testBlobValuePersistence() throws Exception {
        String testString = "this is test clob"; //$NON-NLS-1$
        SerialBlob blob = new SerialBlob(testString.getBytes());
       
        BlobType bv = new BlobType(blob);
        String key = bv.getReferenceStreamId();
       
        // now force to serialize
        File saved = new File(UnitTestUtil.getTestScratchPath()+"/blobassaved.bin"); //$NON-NLS-1$
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
        out.writeObject(bv);
        out.close();
       
        // now read back the object from serilized state
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
        BlobType read = (BlobType)in.readObject();
               
        // make sure we have kept the reference stream id
        assertEquals(key, read.getReferenceStreamId());
       
        // and lost the original object
        assertNull(read.getReference());
       
        saved.delete();
    }
View Full Code Here

        return new ReaderInputStream(new StringReader("Clob contents One"),  Charset.forName(Streamable.ENCODING));
      }
     
    }, -1));
   
    BlobType blob = new BlobType(new BlobImpl(new InputStreamFactory() {
      @Override
      public InputStream getInputStream() throws IOException {
        return new ReaderInputStream(new StringReader("Blob contents Two"),  Charset.forName(Streamable.ENCODING));
      }
     
    }));   
   
    LobManager lobManager = new LobManager();
    lobManager.updateReferences(new int[] {0,1}, Arrays.asList(clob, blob));
    lobManager.persist(fs);
   
    Streamable<?>lob = lobManager.getLobReference(clob.getReferenceStreamId());
    assertTrue(lob.getClass().isAssignableFrom(ClobType.class));
    ClobType clobRead = (ClobType)lob;
    assertEquals(ClobType.getString(clob), ClobType.getString(clobRead));
    assertTrue(clobRead.length() != -1);
   
    lob = lobManager.getLobReference(blob.getReferenceStreamId());
    assertTrue(lob.getClass().isAssignableFrom(BlobType.class));
    BlobType blobRead = (BlobType)lob;
    assertTrue(Arrays.equals(ObjectConverterUtil.convertToByteArray(blob.getBinaryStream()), ObjectConverterUtil.convertToByteArray(blobRead.getBinaryStream())));
   
  }
View Full Code Here

        String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
        assertEquals("<!--comment-->", xml);
    }
 
  @Test public void testToChars() throws Exception {
    Clob result = (Clob)helpInvokeMethod("to_chars", new Class<?>[] {DefaultDataClasses.BLOB, DefaultDataClasses.STRING}, new Object[] { new BlobType(new SerialBlob("hello world".getBytes("ASCII"))), "ASCII" }, null); //$NON-NLS-1$
    String string = result.getSubString(1, (int)result.length());
    assertEquals("hello world", string);
  }
View Full Code Here

    Blob result = (Blob)helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("hello world".toCharArray())), "UTF32" }, null); //$NON-NLS-1$
    assertEquals(44, result.length()); //4 bytes / char
  }
 
  @Test public void testToChars1() throws Exception {
    Clob result = (Clob)helpInvokeMethod("to_chars", new Class<?>[] {DefaultDataClasses.BLOB, DefaultDataClasses.STRING}, new Object[] { new BlobType(new SerialBlob("hello world".getBytes("ASCII"))), "BASE64" }, null); //$NON-NLS-1$
    String string = result.getSubString(1, (int)result.length());
    assertEquals("hello world", new String(Base64.decode(string), "ASCII"));
  }
View Full Code Here

    String string = result.getSubString(1, (int)result.length());
    assertEquals("hello world", new String(Base64.decode(string), "ASCII"));
  }
 
  @Test public void testToChars2() throws Exception {
    Clob result = (Clob)helpInvokeMethod("to_chars", new Class<?>[] {DefaultDataClasses.BLOB, DefaultDataClasses.STRING}, new Object[] { new BlobType(new SerialBlob("hello world".getBytes("ASCII"))), "HEX" }, null); //$NON-NLS-1$
    String string = result.getSubString(1, (int)result.length());
    assertEquals("68656C6C6F20776F726C64", string);
  }
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);
      } catch (IOException e) {
        throw new TransformationException(e, e.getMessage());
      }
      return new BlobType(new BlobImpl(fsisf));
    }
    if (value instanceof Source) {
      if (value instanceof InputStreamFactory) {
        return new XMLType(new SQLXMLImpl((InputStreamFactory)value));
      }
View Full Code Here

      }
    };     
   
    try {
      if (lob instanceof BlobType) {
        persistedLob = new BlobType(new BlobImpl(isf));
      }
      else if (lob instanceof ClobType) {
        persistedLob = new ClobType(new ClobImpl(isf, ((ClobType)lob).length()));
      }
      else {
View Full Code Here

TOP

Related Classes of org.teiid.core.types.BlobType

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.