001 /* 002 * JBoss, Home of Professional Open Source. 003 * Copyright 2008, Red Hat Middleware LLC, and individual contributors 004 * as indicated by the @author tags. See the copyright.txt file in the 005 * distribution for a full listing of individual contributors. 006 * 007 * This is free software; you can redistribute it and/or modify it 008 * under the terms of the GNU Lesser General Public License as 009 * published by the Free Software Foundation; either version 2.1 of 010 * the License, or (at your option) any later version. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this software; if not, write to the Free 019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 021 */ 022 package org.jboss.dna.graph.properties; 023 024 import java.io.InputStream; 025 import java.io.Serializable; 026 import java.security.MessageDigest; 027 import net.jcip.annotations.Immutable; 028 029 /** 030 * Value holder for binary data. Binary instances are not mutable. 031 * 032 * @author Randall Hauch 033 */ 034 @Immutable 035 public interface Binary extends Comparable<Binary>, Serializable { 036 037 /** 038 * Get the length of this binary data. 039 * 040 * @return the number of bytes in this binary data 041 * @see #acquire() 042 */ 043 public long getSize(); 044 045 /** 046 * Get the SHA-1 hash of the contents. This hash can be used to determine whether two Binary instances contain the same 047 * content. 048 * <p> 049 * Repeatedly calling this method should generally be efficient, as it most implementations will compute the hash only once. 050 * </p> 051 * 052 * @return the hash of the contents as a byte array, or an empty array if the hash could not be computed. 053 * @see #acquire() 054 * @see MessageDigest#digest(byte[]) 055 * @see MessageDigest#getInstance(String) 056 */ 057 public byte[] getHash(); 058 059 /** 060 * Get the contents of this data as a stream. 061 * 062 * @return the stream to this data's contents 063 * @see #acquire() 064 */ 065 public InputStream getStream(); 066 067 /** 068 * Get the contents of this data as a byte array. 069 * 070 * @return the data as an array 071 * @see #acquire() 072 */ 073 public byte[] getBytes(); 074 075 /** 076 * Acquire any resources for this data. This method must be called before any other method on this object. 077 * 078 * @see #release() 079 */ 080 public void acquire(); 081 082 /** 083 * Release any acquired resources. This method must be called after a client is finished with this value. 084 * 085 * @see #acquire() 086 */ 087 public void release(); 088 089 }