Module: JMS::BytesMessage

Defined in:
lib/jms/bytes_message.rb

Overview

Interface javax.jms.BytesMessage

Instance Method Summary collapse

Instance Method Details

#dataObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jms/bytes_message.rb', line 3

def data
  # Puts the message body in read-only mode and repositions the stream of
  # bytes to the beginning
  self.reset

  available = self.body_length

  return nil if available == 0

  result     = ''
  bytes_size = 1024
  bytes      = Java::byte[bytes_size].new

  while (n = available < bytes_size ? available : bytes_size) > 0
    self.read_bytes(bytes, n)
    if n == bytes_size
      result << String.from_java_bytes(bytes)
    else
      result << String.from_java_bytes(bytes)[0..n-1]
    end
    available -= n
  end
  result
end

#data=(val) ⇒ Object



28
29
30
# File 'lib/jms/bytes_message.rb', line 28

def data=(val)
  self.write_bytes(val.respond_to?(:to_java_bytes) ? val.to_java_bytes : val)
end

#to_sObject



32
33
34
# File 'lib/jms/bytes_message.rb', line 32

def to_s
  data
end