public class BucketTools
extends java.lang.Object
Constructor and Description |
---|
BucketTools() |
Modifier and Type | Method and Description |
---|---|
static void |
copy(Bucket src,
Bucket dst)
Copy from the input stream of
src to the output stream of
dest . |
static void |
copyFrom(Bucket bucket,
java.io.InputStream is,
long truncateLength)
Copy data from an InputStream into a Bucket.
|
static long |
copyTo(Bucket decodedData,
java.io.OutputStream os,
long truncateLength)
Copy the given quantity of data from the given bucket to the given OutputStream.
|
static long |
copyTo(Bucket bucket,
RandomAccessBuffer raf,
long fileOffset,
long truncateLength)
Copy the contents of a Bucket to a RandomAccessBuffer at a specific offset.
|
static boolean |
equalBuckets(Bucket a,
Bucket b) |
static void |
fill(Bucket bucket,
long length)
Fill a bucket with hard to identify random data
|
static void |
fill(Bucket bucket,
java.util.Random random,
long length)
Deprecated.
Only for unit tests
|
static void |
fill(RandomAccessBuffer raf,
java.util.Random random,
long offset,
long length)
Deprecated.
Only for unit tests
|
static byte[] |
hash(Bucket data) |
static Bucket[] |
makeBuckets(BucketFactory bf,
int count,
int size) |
static RandomAccessBucket |
makeImmutableBucket(BucketFactory bucketFactory,
byte[] data) |
static RandomAccessBucket |
makeImmutableBucket(BucketFactory bucketFactory,
byte[] data,
int length) |
static RandomAccessBucket |
makeImmutableBucket(BucketFactory bucketFactory,
byte[] data,
int offset,
int length) |
static Bucket[] |
nonNullBuckets(Bucket[] array) |
static int[] |
nonNullIndices(Bucket[] array) |
static int[] |
nullIndices(Bucket[] array) |
static Bucket |
pad(Bucket oldBucket,
int blockLength,
BucketFactory bf,
int length)
Pad a bucket with random data
|
static byte[] |
pad(byte[] orig,
int blockSize,
int length) |
static void |
paddedCopy(Bucket from,
Bucket to,
long nBytes,
int blockSize) |
static Bucket |
restoreFrom(java.io.DataInputStream dis,
FilenameGenerator fg,
PersistentFileTracker persistentFileTracker,
MasterSecret masterKey)
Inverse of Bucket.storeTo().
|
static LockableRandomAccessBuffer |
restoreRAFFrom(java.io.DataInputStream dis,
FilenameGenerator fg,
PersistentFileTracker persistentFileTracker,
MasterSecret masterSecret)
Restore a LockableRandomAccessBuffer from a DataInputStream.
|
static Bucket[] |
split(Bucket origData,
int splitSize,
BucketFactory bf,
boolean freeData,
boolean persistent)
Split the data into a series of read-only Bucket's.
|
static byte[] |
toByteArray(Bucket bucket)
Read the entire bucket in as a byte array.
|
static int |
toByteArray(Bucket bucket,
byte[] output) |
static RandomAccessBucket |
toRandomAccessBucket(Bucket bucket,
BucketFactory bf) |
static void |
zeroPad(Bucket b,
long size) |
public static void copy(Bucket src, Bucket dst) throws java.io.IOException
src
to the output stream of
dest
.src
- dst
- java.io.IOException
public static void zeroPad(Bucket b, long size) throws java.io.IOException
java.io.IOException
public static void paddedCopy(Bucket from, Bucket to, long nBytes, int blockSize) throws java.io.IOException
java.io.IOException
public static Bucket[] makeBuckets(BucketFactory bf, int count, int size) throws java.io.IOException
java.io.IOException
public static int[] nullIndices(Bucket[] array)
public static int[] nonNullIndices(Bucket[] array)
public static byte[] toByteArray(Bucket bucket) throws java.io.IOException
java.io.IOException
- If there was an error reading from the bucket.java.lang.OutOfMemoryError
- If it was not possible to allocate enough
memory to contain the entire bucket.public static int toByteArray(Bucket bucket, byte[] output) throws java.io.IOException
java.io.IOException
public static RandomAccessBucket makeImmutableBucket(BucketFactory bucketFactory, byte[] data) throws java.io.IOException
java.io.IOException
public static RandomAccessBucket makeImmutableBucket(BucketFactory bucketFactory, byte[] data, int length) throws java.io.IOException
java.io.IOException
public static RandomAccessBucket makeImmutableBucket(BucketFactory bucketFactory, byte[] data, int offset, int length) throws java.io.IOException
java.io.IOException
public static byte[] hash(Bucket data) throws java.io.IOException
java.io.IOException
public static long copyTo(Bucket decodedData, java.io.OutputStream os, long truncateLength) throws java.io.IOException
java.io.IOException
- If there was an error reading from the bucket or writing to the stream.public static void copyFrom(Bucket bucket, java.io.InputStream is, long truncateLength) throws java.io.IOException
java.io.IOException
public static Bucket[] split(Bucket origData, int splitSize, BucketFactory bf, boolean freeData, boolean persistent) throws java.io.IOException
origData
- The original data Bucket.splitSize
- The number of bytes to put into each bucket.
If the passed-in Bucket is a FileBucket, will be efficiently
split into ReadOnlyFileSliceBuckets, otherwise new buckets are created
and the data written to them.
Note that this method will allocate a buffer of size splitSize.bf
- freeData
- persistent
- If true, the data is persistent. This method is responsible for ensuring that the returned
buckets HAVE ALREADY BEEN STORED TO THE DATABASE, using the provided handle. The point? SegmentedBCB's buckets
have already been stored!!java.io.IOException
- If there is an error creating buckets, reading from
the provided bucket, or writing to created buckets.public static Bucket pad(Bucket oldBucket, int blockLength, BucketFactory bf, int length) throws java.io.IOException
oldBucket
- blockLength
- bf
- length
- java.io.IOException
public static byte[] pad(byte[] orig, int blockSize, int length) throws java.io.IOException
java.io.IOException
public static boolean equalBuckets(Bucket a, Bucket b) throws java.io.IOException
java.io.IOException
@Deprecated public static void fill(Bucket bucket, java.util.Random random, long length) throws java.io.IOException
java.io.IOException
@Deprecated public static void fill(RandomAccessBuffer raf, java.util.Random random, long offset, long length) throws java.io.IOException
java.io.IOException
public static void fill(Bucket bucket, long length) throws java.io.IOException
java.io.IOException
public static long copyTo(Bucket bucket, RandomAccessBuffer raf, long fileOffset, long truncateLength) throws java.io.IOException
bucket
- The bucket to read data from.raf
- The RandomAccessBuffer to write to.fileOffset
- The offset within raf to start writing at.truncateLength
- The maximum number of bytes to transfer, or -1 to copy the whole
bucket.java.io.IOException
- If something breaks while copying the data.public static Bucket restoreFrom(java.io.DataInputStream dis, FilenameGenerator fg, PersistentFileTracker persistentFileTracker, MasterSecret masterKey) throws java.io.IOException, StorageFormatException, ResumeFailedException
java.io.IOException
StorageFormatException
ResumeFailedException
public static LockableRandomAccessBuffer restoreRAFFrom(java.io.DataInputStream dis, FilenameGenerator fg, PersistentFileTracker persistentFileTracker, MasterSecret masterSecret) throws java.io.IOException, StorageFormatException, ResumeFailedException
java.io.IOException
StorageFormatException
ResumeFailedException
public static RandomAccessBucket toRandomAccessBucket(Bucket bucket, BucketFactory bf) throws java.io.IOException
java.io.IOException