class T2Server::OutputPort

Represents an output port of a workflow.

Public Instance Methods

[int] → obj click to toggle source

This call provides access to the underlying structure of the OutputPort. It can only be used for ports of depth >= 1. For singleton ports, use OutputPort#value instead.

Example usage - To get part of a value from an output port with depth 3: port[0].value(10…100)

    # File lib/t2-server/port.rb
211 def [](i)
212   return @structure if depth == 0
213   @structure[i]
214 end
empty? → true or false click to toggle source

Is this output port empty?

Note that if the output port holds a list then it is not considered empty, even if that list is empty. This is because the port itself is not empty, there is a list there! A separate test should be performed to see if that list is empty or not.

    # File lib/t2-server/port.rb
196 def empty?
197   # Funnily enough, an empty list does *not* make a port empty!
198   return false if @structure.instance_of? Array
199   @structure.empty?
200 end
error? → true or false click to toggle source

Is there an error associated with this output port?

    # File lib/t2-server/port.rb
183 def error?
184   @error
185 end
reference → string click to toggle source
reference → array

Get URI references to the data values of this output port as strings.

For a singleton output a single uri is returned. For lists an array of uris is returned. For an individual reference from a list use 'port[].reference'.

    # File lib/t2-server/port.rb
288 def reference
289   @refs ||= strip(:reference)
290 end
size → fixnum click to toggle source
size → array

Get the data size of the data value in this output port.

For a singleton output a single size is returned. For lists an array of sizes is returned. For an individual size from a list use 'port[].size'.

    # File lib/t2-server/port.rb
312 def size
313   @sizes ||= strip(:size)
314 end
stream_value(stream) → fixnum click to toggle source
stream_value(stream, range) → fixnum

Stream a singleton port value directly to another stream and return the number of bytes written. If a range is supplied then only that range of data is streamed from the server. The stream passed in may be anything that provides a write method; instances of IO and File, for example. No data is cached by this method.

To stream parts of a list port, use PortValue#stream_value on the list item directly:

run.output_port("port_name")[0].stream_value(stream)
    # File lib/t2-server/port.rb
253 def stream_value(stream, range = nil)
254   return 0 unless depth == 0
255   raise ArgumentError,
256     "Stream passed in must provide a write method" unless
257       stream.respond_to? :write
258 
259   @structure.stream_value(stream, range)
260 end
total_size → fixnum click to toggle source

Return the total data size of all the data in this output port.

    # File lib/t2-server/port.rb
320 def total_size
321   return @total_size if @total_size
322   if @structure.instance_of? Array
323     return 0 if @structure.empty?
324     @total_size = strip(:size).flatten.inject { |sum, i| sum + i }
325   else
326     @total_size = size
327   end
328 end
type → string click to toggle source
type → array

Get the mime type of the data value in this output port.

For a singleton output a single type is returned. For lists an array of types is returned. For an individual type from a list use 'port[].type'.

    # File lib/t2-server/port.rb
300 def type
301   @types ||= strip(:type)
302 end
value → binary blob click to toggle source
value(range) → binary blob
value {|chunk| ...}
value(range) {|chunk| ...}
value → array

For singleton outputs download or stream the data (or part of it) held by the output port. Please see the documentation for PortValue#value for full details.

For list outputs all data values are downloaded into memory and returned in an Array structure that mirrors the structure of the output port. Do not use this form if the output port has large amounts of data! To get part of a value from a list use something like:

run.output_port("port_name")[0].value(0..100)
    # File lib/t2-server/port.rb
232 def value(range = nil, &block)
233   if depth == 0
234     @structure.value(range, &block)
235   else
236     @values ||= strip(:value)
237   end
238 end
write_value_to_file(filename) → fixnum click to toggle source
write_value_to_file(filename, range) → fixnum

Stream a singleton port value to a file and return the number of bytes written. If a range is supplied then only that range of data is downloaded from the server.

To save parts of a list port to a file, use PortValue#write_value_to_file on the list item directly:

run.output_port("port_name")[0].write_value_to_file
    # File lib/t2-server/port.rb
273 def write_value_to_file(filename, range = nil)
274   return 0 unless depth == 0
275 
276   @structure.write_value_to_file(filename, range)
277 end
zip → binary blob click to toggle source
zip(filename) → fixnum
zip(stream) → fixnum
zip {|chunk| ...}

Get the data in this output port directly from the server in zip format.

This method does not work with singleton ports. Taverna Server cannot currently return zip files of singleton ports on their own. If you wish to get a singleton port in a zip file then you can use Run#zip_output which will return all outputs in a single file.

If this method is called on a singleton port it will return nil and streaming from it will return nothing.

Calling this method with no parameters will simply return a blob of zipped data. Providing a filename will stream the data directly to that file and return the number of bytes written. Passing in an object that has a write method (for example, an instance of File or IO) will stream the zip data directly to that object and return the number of bytes that were streamed. Passing in a block will allow access to the underlying data stream:

port.zip do |chunk|
  print chunk
end

Raises RunStateError if the run has not finished running.

    # File lib/t2-server/port.rb
358 def zip(param = nil, &block)
359   return nil if depth == 0
360   @run.zip_output(param, name, &block)
361 end

Private Instance Methods

parse_data(node, current_depth = 0) click to toggle source

Parse the XML port description into a raw data value structure.

    # File lib/t2-server/port.rb
372 def parse_data(node, current_depth = 0)
373   case xml_node_name(node)
374   when 'list'
375     data = []
376     xml_children(node) do |child|
377       data << parse_data(child, current_depth + 1)
378     end
379     return data
380   when 'value'
381     return PortValue.new(self, xml_node_attribute(node, 'href'), false,
382       xml_node_attribute(node, 'contentByteLength').to_i,
383       xml_node_attribute(node, 'contentType'))
384   when 'error'
385     @error = true
386     return PortValue.new(self, xml_node_attribute(node, 'href'), true,
387       xml_node_attribute(node, 'errorByteLength').to_i)
388   when 'absent'
389     if current_depth == @depth
390       return PortValue.new(self, "", false, 0, "application/x-empty")
391     else
392       return []
393     end
394   end
395 end
strip(attribute, struct = @structure) click to toggle source

Strip the requested attribute from the raw values structure.

    # File lib/t2-server/port.rb
398 def strip(attribute, struct = @structure)
399   if struct.instance_of? Array
400     data = []
401     struct.each { |item| data << strip(attribute, item) }
402     return data
403   else
404     struct.method(attribute).call
405   end
406 end