KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bytes > ByteArray


1 package org.jbpm.bytes;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Arrays JavaDoc;
5 import java.util.List JavaDoc;
6
7 /**
8  * is a persistable array of bytes. While there is no generic way of storing blobs
9  * that is supported by many databases, all databases are able to handle small chunks
10  * of bytes properly. It is the responsibility of this class to chop the large byte
11  * array into small chunks of 1K (and combine the chunks again in the reverse way).
12  * Hibernate will persist the list of byte-chunks in the database.
13  *
14  * ByteArray is used in process variables and in the file module (that stores the
15  * non-parsed process archive files).
16  */

17 public class ByteArray implements Serializable JavaDoc {
18   
19   private static final long serialVersionUID = 1L;
20   
21   private long id = 0;
22   protected String JavaDoc name = null;
23   protected List JavaDoc byteBlocks = null;
24   
25   public ByteArray() {
26   }
27
28   public ByteArray(byte[] bytes) {
29     this.byteBlocks = ByteBlockChopper.chopItUp(bytes);
30   }
31
32   public ByteArray(String JavaDoc name, byte[] bytes) {
33     this(bytes);
34     this.name = name;
35   }
36
37   public ByteArray(ByteArray other) {
38     this.byteBlocks = other.byteBlocks;
39     this.name = other.name;
40   }
41
42   public byte[] getBytes() {
43     return ByteBlockChopper.glueChopsBackTogether(byteBlocks);
44   }
45
46   public long getId() {
47     return id;
48   }
49
50   public boolean equals(Object JavaDoc o) {
51     if (o==null) return false;
52     if (! (o instanceof ByteArray)) return false;
53     ByteArray other = (ByteArray) o;
54     return Arrays.equals(ByteBlockChopper.glueChopsBackTogether(byteBlocks), ByteBlockChopper.glueChopsBackTogether(other.byteBlocks));
55   }
56
57   public int hashCode() {
58     if (byteBlocks==null) return 0;
59     return byteBlocks.hashCode();
60   }
61 }
62
Popular Tags