Author: ruschein
Date: 2010-02-02 09:49:17 -0800 (Tue, 02 Feb 2010)
New Revision: 19121

Added:
   
csplugins/trunk/util.compression/src/org/cytoscape/util/compression/BytePacker.java
Log:
Renamed to better describe its function.

Copied: 
csplugins/trunk/util.compression/src/org/cytoscape/util/compression/BytePacker.java
 (from rev 19120, 
csplugins/trunk/util.compression/src/org/cytoscape/util/compression/Pack.java)
===================================================================
--- 
csplugins/trunk/util.compression/src/org/cytoscape/util/compression/BytePacker.java
                         (rev 0)
+++ 
csplugins/trunk/util.compression/src/org/cytoscape/util/compression/BytePacker.java
 2010-02-02 17:49:17 UTC (rev 19121)
@@ -0,0 +1,43 @@
+package org.cytoscape.util.compression;
+
+
+/**
+ * Class to convert between int and byte arrays.
+ */
+public class BytePacker {
+       /**
+        * Converts a byte array to an int array.  This requires that the byte 
array has a size that
+        * is a multiple of 4!  The byte order in the ints will be the first 
original byte being the
+        * most-significant byte in the first int and so on...
+        */
+       static public int[] pack(final byte[] data) throws 
IllegalStateException {
+               if ((data.length % 4) != 0)
+                       throw new IllegalStateException("data size must be a 
multiple of 4!");
+
+               final int[] retval = new int[data.length >> 2];
+
+               for (int i = 0; i < retval.length; ++i) {
+                       retval[i] = (int)data[i << 4] | (int) data[(i << 4) + 1]
+                                   | (int) data[(i << 4) + 2] |(int) data[(i 
<< 4) + 3];
+               }
+
+               return retval;
+       }
+
+       /**
+        * Converts an int array to a byte array.  The bytes will be in 
most-significant to least significant order.
+        */
+       static public byte[] unpack(final int[] data) {
+               final byte[] retval = new byte[data.length << 2];
+
+               for (int i = 0; i < data.length; ++i) {
+                       int value = data[i];
+                       retval[i << 2] = (byte)(value >> 24);
+                       retval[(i << 2) + 1] = (byte)((value >> 16) & 0xFF);
+                       retval[(i << 2) + 2] = (byte)((value >> 8) & 0xFF);
+                       retval[(i << 2) + 3] = (byte)(value & 0xFF);
+               }
+
+               return retval;
+       }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to