Package aQute.libg.cafs
Class CAFS
java.lang.Object
aQute.libg.cafs.CAFS
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<SHA1>
CAFS implements a SHA-1 based file store. The basic idea is that every file
in the universe has a unique SHA-1. Hard to believe but people smarter than
me have come to that conclusion. This class maintains a compressed store of
SHA-1 identified files. So if you have the SHA-1, you can get the contents.
This makes it easy to store a SHA-1 instead of the whole file or maintain a
naming scheme. An added advantage is that it is always easy to verify you get
the right stuff. The SHA-1 Content Addressable File Store is the core
underlying idea in Git.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final String(package private) static final byte[](package private) static final byte[](package private) FileChannel(package private) static final int(package private) final File(package private) Index(package private) static final String(package private) static final int(package private) RandomAccessFile(package private) static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) shortchecksum(int flags, int compressedLength, int totalLength, byte[] sha1) voidclose()booleanexists(byte[] sha1) private InputStreamgetSha1Stream(SHA1 sha1, byte[] buffer, int total) booleanisEmpty()iterator()Read the contents of a sha 1 key.voidreindex()private voidupdate(byte[] sha1, byte[] compressed, int totalLength) Update a record in the store, assuming the store is at the right position.private SHA1private booleanverifySignature(DataInput din, byte[] org) write(InputStream in) Store an input stream in the CAFS while calculating and returning the SHA-1 code.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
CAFS
static final byte[] CAFS -
CAFE
static final byte[] CAFE -
INDEXFILE
- See Also:
-
STOREFILE
- See Also:
-
ALGORITHM
- See Also:
-
KEYLENGTH
static final int KEYLENGTH- See Also:
-
HEADERLENGTH
static final int HEADERLENGTH- See Also:
-
home
-
index
Index index -
store
RandomAccessFile store -
channel
FileChannel channel
-
-
Constructor Details
-
CAFS
Constructor for a Content Addressable File Store- Parameters:
home-create-- Throws:
Exception
-
-
Method Details
-
write
Store an input stream in the CAFS while calculating and returning the SHA-1 code.- Parameters:
in- The input stream to store.- Returns:
- The SHA-1 code.
- Throws:
Exception- if anything goes wrong
-
read
Read the contents of a sha 1 key.- Parameters:
sha1- The key- Returns:
- An Input Stream on the content or null of key not found
- Throws:
Exception
-
exists
- Throws:
Exception
-
reindex
- Throws:
Exception
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
verifyEntry
- Throws:
IOExceptionNoSuchAlgorithmException
-
verifySignature
- Throws:
IOException
-
getSha1Stream
private InputStream getSha1Stream(SHA1 sha1, byte[] buffer, int total) throws NoSuchAlgorithmException - Throws:
NoSuchAlgorithmException
-
update
Update a record in the store, assuming the store is at the right position.- Parameters:
sha1- The checksumcompressed- The compressed lengthtotalLength- The uncompressed length- Throws:
IOException- The exception
-
checksum
short checksum(int flags, int compressedLength, int totalLength, byte[] sha1) -
iterator
-
isEmpty
- Throws:
IOException
-