Open topic with navigation

TIBCO® Enterprise Administrator 2.4.2

# Passing Data Streams to Operation Methods

TeaOperation methods can accept data streams (such as file data) from the server. The default GUI makes it easy to select a file and pass its data content to an agent method.

Procedure
1. Define an operation with a parameter of type javax.activation.DataSource, and annotate it as a @TeaParam.

       @TeaOperation(name = "upload", description = "Upload File")
       public void uploadFile(
           @TeaParam(name = "filepath", description = "File to Upload")final DataSource fileDataSource)
         throws IOException {
         ...
       }

   The default GUI lets a user select a file from the local file system. The server passes the file's contents to the agent as an argument to the operation method. The agent specifies this behavior with the example code shown in bold above—specifically, the parameter type.
2. Use the data stream in the method body.
   In this example, the method writes the data stream to a temporary file, effectively transferring the data from the user's host computer to the agent's host computer.

       {
         byte[] buffer = new byte[8 * 1024];
         String name = fileDataSource.getName();
         FileOutputStream writerStream = new FileOutputStream(name, true);
         final InputStream inputStream = fileDataSource.getInputStream();
         int read;
         while((read = inputStream.read(buffer)) > 0)
         {
            writerStream.write(buffer, 0, read);
         }
         inputStream.close();
         writerStream.flush();
         writerStream.close();
       }

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO® Enterprise Administrator

Copyright © 1996-2025. Cloud Software Group, Inc. All Rights Reserved.