2 Replies Latest reply on Nov 28, 2017 9:44 AM by shawkins

    java.lang.ClassCastException: org.teiid.common.buffer.FileStore$1 cannot be cast to java.io.SequenceInputStream

    aliimtiaz

      Hi I am working on streaming multiple files from source to target in call backs and due to some limitations of custom inputStream factory architecture (can only return inputStream object) I have to write all multiple files into single input Stream. So for that I am using SequenceInputStream which combines the multiple file inputStream into one single in a sequence. Now the problem is when i return SequenceInputStream object from source and receive at target its converted into org.teiid.common.buffer.FileStore$1 so i try to cast it into SequenceInputStream but its giving me exception.

      Please help me get this SequenceInputStream object again at target end

       

      READ CODE

       

       

      //OWTStreamFactory  extends InputStreamFactory

       

      public class ExternalFileHandler implements OWTStreamCallback {
          @Override
          public InputStream readStreamingData(Connection connection) throws IOException {
              try {
                  List < PipedInputStream > pipinList = new ArrayList < PipedInputStream > ();
                  for (String fileSingle: fileNames) {
                      PipedInputStream pipedInputStream = new PipedInputStream(PIPE_SIZE);
                      PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream);
      
                      Thread t1 = new FileDataReader(pipedOutputStream, fileSingle);
                      t1.start();
                      pipinList.add(pipedInputStream);
                  }
                  SequenceInputStream bin = new SequenceInputStream(Collections.enumeration(pipinList));
                  return bin;
              } catch (Exception e) {
                  throw new IOException("File to read external file. Error " + e.getMessage(), e);
              }
          }
      }

       

      Write CODE

       

      @Override
      public void writeStreamingData(OWTConnection connection, Object data) throws IOException {
          try {
              BlobType blobimp = (BlobType) data;
              SequenceInputStream bin = (SequenceInputStream) blobimp.getBinaryStream();
          } catch (Exception ex) {
              throw ex;
          }
      }
        • 1. Re: java.lang.ClassCastException: org.teiid.common.buffer.FileStore$1 cannot be cast to java.io.SequenceInputStream
          rareddy

          Ali,

           

          How did you model your return as blob? The above code, unless you are working with embedded Teiid it will not work. Embedded Teiid, the translator, server and client code are in *same* JVM where you can pass the object references and typecast at later stage, but in the full server mode, where client is assumed to be remote and marshaling of the results will occur where the object reference is lost.

           

          From your exception message, I see occurring in the server itself, but I would need to see the whole code for your translator not just fragment above to suggest what is going wrong.

           

          Ramesh..

          • 2. Re: java.lang.ClassCastException: org.teiid.common.buffer.FileStore$1 cannot be cast to java.io.SequenceInputStream
            shawkins

            > Please help me get this SequenceInputStream object again at target end

             

            You can't guarantee that BlobType will return your SequenceInputStream.  As Ramesh is indicating due to remoting, inlining, or other lob copying effects you may get a different stream.  There are two thoughts here - do you need to cast to SequenceInputStream when reading?  Can you just use InputStream.  And the other thought is are you looking for some specific handling - for example that the stream is only read once?