[MOBY-guts] biomoby commit
Paul Gordon
gordonp at pub.open-bio.org
Thu Aug 4 15:48:35 UTC 2005
gordonp
Thu Aug 4 11:48:35 EDT 2005
Update of /home/repository/moby/moby-live/Java/docs
In directory pub.open-bio.org:/tmp/cvs-serv8591
Modified Files:
SimpleClient.html
Log Message:
Included binary data manipulation samples
moby-live/Java/docs SimpleClient.html,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/docs/SimpleClient.html,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/docs/SimpleClient.html 2005/08/04 14:12:48 1.6
+++ /home/repository/moby/moby-live/Java/docs/SimpleClient.html 2005/08/04 15:48:35 1.7
@@ -190,6 +190,40 @@
</pre></code></blockquote>
</p>
+
+<h3>Dealing with binary data</h3>
+<p>Because there is no byte array equivalent in MOBY, all binary data must be encoded as a text string. The
+most used text encoding is <a href="http://en.wikipedia.org/wiki/Base64">Base64</a>, and jMOBY contains a convenience
+class (<code>MobyDataBytes</code>) that will encode and decode for you. For example, to create a
+<em>b64_encoded_gif</em> using the URL based constructor:
+
+<blockquote><code><pre>
+String imageLocation = "images/foo.gif";
+try{
+ MobyDataBytes encodedImage = new MobyDataBytes("myFavoriteImage",
+ getClass().getClassLoader().getResource(imageLocation));
+}catch(IOException ioe){
+ System.err.println("Could not load image data: " + ioe);
+}
+</pre></code></blockquote>
+
+or to read the base64 encoded binary image data from a <em>NCBI_Blast_XML_Gif</em>:
+
+<blockquote><code><pre>
+// Assume we have a MOBY NCBI_Blast_XML_Gif in the MobyComposite variable called "blastData"
+MobyDataBytes encodedImage = (MobyDataBytes) blastData.get("hitGraph");
+javax.swing.ImageIcon image = new ImageIcon(encodedImage.getBytes());
+</pre></code></blockquote>
+</p>
+
+
+Not directly related to jMOBY, but note that <code>ClassLoader.getResource(String)</code> is a convenient
+way in Java to create URLs appropriate to the context. For example, if the code was in a
+<abbrev title="Java ARchive">jar</abbrev> or <abbrev title="Web ARchive">war</abbrev>, the response would
+be "jar:bar.jar!images/foo.gif", in an application "file:images/foo.gif", in an applet
+"http://www.applet.org/base/url/images/foo.gif", etc..
+</p>
+
<hr/>
<a name="manipulatingjMOBYData"></a>
@@ -270,13 +304,22 @@
<h3>Create a MOBY XML response or query envelope with multiple invocations</h3>
<p>
Use the default constructor for <code>MobyContentInstance</code>, then add at least one <code>MobyDataInstance</code>
-to it using the <code>java.lang.Map</code> interface or the convenient one-arg <code>put</code> method. To clarify, sending the content block to a service provider is requesting that a service acting on a <code>gi</code> namespace object be invoked for two separate input data. We are not calling a service that takes two MOBY <em>Object</em>s as input.
+to it using the <code>java.lang.Map</code> interface or the convenient one-arg <code>put</code> method. To clarify,
+sending the content block to a service provider is requesting that a service acting on a <code>gi</code> namespace
+object be invoked for two separate input data. We are not calling a service that takes two MOBY <em>Object</em>s
+as input.
<blockquote><code><pre>
MobyContentInstance queries = new MobyContentInstance();
data.put(new MobyDataObject("gi", "100089"));
data.put(new MobyDataObject("gi", "324442"));
MobyDataUtils.toXMLDocument(System.out, queries);
</pre></code></blockquote>
+
+The one argument <code>put</code> method essentially calls the standard <code>Map.put(Object key, Object value)</code>
+method with an autogenerated unique key (corresponding to a MOBY <em>queryID</em>). As a service provider you would
+always want to use the two argument <code>put</code> method to build a response object, as the keys MUST correspond
+one-to-one with the <em>queryID</em>s you received from the client.
+</p>
<hr/>
<a name="parsingMOBYXML"></a>
<h2>Parsing MOBY XML</h2>
@@ -294,7 +337,7 @@
<address><a href="mailto:gordonp at ucalgary.ca">Paul Gordon</a></address>
<!-- Created: Wed Jul 20 11:44:30 MDT 2005 -->
<!-- hhmts start -->
-Last modified: Thu Aug 4 09:04:40 MDT 2005
+Last modified: Thu Aug 4 10:38:48 MDT 2005
<!-- hhmts end -->
</body>
</html>
More information about the MOBY-guts
mailing list