01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jbpm.bytes;
23:
24: import java.io.Serializable;
25: import java.util.ArrayList;
26: import java.util.Arrays;
27: import java.util.List;
28:
29: /**
30: * is a persistable array of bytes. While there is no generic way of storing blobs
31: * that is supported by many databases, all databases are able to handle small chunks
32: * of bytes properly. It is the responsibility of this class to chop the large byte
33: * array into small chunks of 1K (and combine the chunks again in the reverse way).
34: * Hibernate will persist the list of byte-chunks in the database.
35: *
36: * ByteArray is used in process variableInstances and in the file module (that stores the
37: * non-parsed process archive files).
38: */
39: public class ByteArray implements Serializable {
40:
41: private static final long serialVersionUID = 1L;
42:
43: long id = 0;
44: protected String name = null;
45: protected List byteBlocks = null;
46:
47: public ByteArray() {
48: }
49:
50: public ByteArray(byte[] bytes) {
51: this .byteBlocks = ByteBlockChopper.chopItUp(bytes);
52: }
53:
54: public ByteArray(String name, byte[] bytes) {
55: this (bytes);
56: this .name = name;
57: }
58:
59: public ByteArray(ByteArray other) {
60: List otherByteBlocks = other.getByteBlocks();
61: if (otherByteBlocks != null) {
62: this .byteBlocks = new ArrayList(otherByteBlocks);
63: }
64: this .name = other.name;
65: }
66:
67: public byte[] getBytes() {
68: return ByteBlockChopper.glueChopsBackTogether(byteBlocks);
69: }
70:
71: public long getId() {
72: return id;
73: }
74:
75: public boolean equals(Object o) {
76: if (o == null)
77: return false;
78: if (!(o instanceof ByteArray))
79: return false;
80: ByteArray other = (ByteArray) o;
81: return Arrays.equals(ByteBlockChopper
82: .glueChopsBackTogether(byteBlocks), ByteBlockChopper
83: .glueChopsBackTogether(other.byteBlocks));
84: }
85:
86: public int hashCode() {
87: if (byteBlocks == null)
88: return 0;
89: return byteBlocks.hashCode();
90: }
91:
92: public List getByteBlocks() {
93: return byteBlocks;
94: }
95: }
|