1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.graph.property;
25
26 import java.io.InputStream;
27 import java.io.Serializable;
28 import java.security.MessageDigest;
29 import net.jcip.annotations.Immutable;
30
31 /**
32 * Value holder for binary data. Binary instances are not mutable.
33 */
34 @Immutable
35 public interface Binary extends Comparable<Binary>, Serializable {
36
37 /**
38 * Get the length of this binary data.
39 *
40 * @return the number of bytes in this binary data
41 * @see #acquire()
42 */
43 public long getSize();
44
45 /**
46 * Get the SHA-1 hash of the contents. This hash can be used to determine whether two Binary instances contain the same
47 * content.
48 * <p>
49 * Repeatedly calling this method should generally be efficient, as it most implementations will compute the hash only once.
50 * </p>
51 *
52 * @return the hash of the contents as a byte array, or an empty array if the hash could not be computed.
53 * @see #acquire()
54 * @see MessageDigest#digest(byte[])
55 * @see MessageDigest#getInstance(String)
56 */
57 public byte[] getHash();
58
59 /**
60 * Get the contents of this data as a stream.
61 *
62 * @return the stream to this data's contents
63 * @see #acquire()
64 * @throws IoException if there is a problem returning the stream
65 */
66 public InputStream getStream();
67
68 /**
69 * Get the contents of this data as a byte array.
70 *
71 * @return the data as an array
72 * @see #acquire()
73 * @throws IoException if there is a problem returning the bytes
74 */
75 public byte[] getBytes();
76
77 /**
78 * Acquire any resources for this data. This method must be called before any other method on this object.
79 *
80 * @see #release()
81 */
82 public void acquire();
83
84 /**
85 * Release any acquired resources. This method must be called after a client is finished with this value.
86 *
87 * @see #acquire()
88 */
89 public void release();
90
91 }