|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectccs.beetree.BeeObject
ccs.cdb.CDBObject
ccs.cdb.CDBFileSysObject
ccs.cdb.CDBFile
public class CDBFile
A CDBFile wraps a java.io.File
and allows it to be stored in a
CDB. The keys of CDBFiles consist of a unix / URL type
"path"; thus the collection of CDBFiles forms a "virtual filesystem". Such a
collection will also include CDBDirectory objects with keys ending in "/", if
"directory" listings are required. These store the collection of strings
comprising the keys of CDBFiles and other CDBDirectory's in that "directory";
this allows efficient indexing. Without these it would be necessary to traverse
the entire set to list the root directory.
A CDBFile is marshalled and unmarshalled either into a real file, or into a SwappingBuffer. In the case of a real file, there is usually some relation between the key and the filename, but not invariably. Note. SwappingBuffer is not MT-safe. By extension, neither are any of the operations which involve it. If in doubt, treat this class as MT-UNSAFE.
CDBObject
,
BeeTree
,
SwappingBuffer
,
Serialized FormField Summary |
---|
Fields inherited from class ccs.cdb.CDBObject |
---|
clone, key, marshalVersion, owner |
Fields inherited from class ccs.beetree.BeeObject |
---|
cipher, encodedLength, isBodiless, isForceDirectDecrypt, isZip, slack |
Constructor Summary | |
---|---|
CDBFile()
Create a new default CDBFile with null key, writing to a null SwappingBuffer, with no compression and no case-lowering. |
Method Summary | |
---|---|
protected long |
cpgetMarshalledLength()
return the marshalled data length if known, just like getMarshalledLength |
protected void |
cpmarshal(java.io.DataOutputStream dos)
override this to marshal your data, just like marshal . |
protected void |
cppreMarshal()
Override this to check your object for validity just before marshalling it, just like preMarshal . |
protected void |
cppreUnmarshal()
override this to check that your object is fit to have information unmarshalled into it, just like preUnmarshal . |
protected void |
cpunmarshal(java.io.DataInputStream dis,
int marshalver)
override this to unmarshal your data, just like unmarshal . |
SwappingBuffer |
getBuffer()
Returns the SwappingBuffer used as the source / target for
virtual files. |
CallbackStreamConsumer |
getConsumer()
|
java.io.File |
getFile()
Returns the current target/source file. |
java.lang.String |
getInternalPath()
return the internal path inside the DB (i.e. the DB key). |
void |
setBuffer(SwappingBuffer sb)
Sets the swapping buffer used as the source / target for writes / reads. |
void |
setConsumer(CallbackStreamConsumer consumer)
Prepare to read this file via a callback. |
void |
setFile(java.io.File f)
Sets the current target/source file. |
void |
setInternalPath(java.lang.String path)
Set the internal path inside the DB (i.e. the DB key). |
static void |
setMimeRegistry(MimeRegistry mimeReg)
Sets the MimeRegistry to use when determining compressibility. |
void |
setReal(boolean isReal)
Deprecated. This is now managed automatically. This call does nothing. |
static void |
setTrialZipSizeLimits(long lower,
long upper)
When inserting a file of unknown compressibility, CDBFile will attempt to compress it anyway provided that its size lies between a pair of limits. |
long |
size()
|
void |
startStreamProduction()
Produces a stream, reading the file from the CDB which currently owns this. |
Methods inherited from class ccs.cdb.CDBObject |
---|
canChangeKeyProgrammatically, canDeleteProgrammatically, canUpdateProgrammatically, cpgetKey, cpsetKey, getCDB, getKey, getMarshalledLength, marshal, preMarshal, preUnmarshal, setCDB, setKey, transientMarshal, transientUnmarshal, unmarshal |
Methods inherited from class ccs.beetree.BeeObject |
---|
lock, unlock |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CDBFile()
Method Detail |
---|
public void setInternalPath(java.lang.String path)
public java.lang.String getInternalPath()
public void setReal(boolean isReal)
isReal
- true for a real file.public void setFile(java.io.File f)
setReal(false)
has been issued.
f
- The File.public java.io.File getFile()
public void setBuffer(SwappingBuffer sb)
SwappingBuffer
for find/next/prev, and
a full one (ready to be read) for insert. If null, the operations will
create a new buffer (ie. write operations will write the empty stream).
Note: SwappingBuffer is MT-unsafe. Use only in one thread, or
within a synchronized block.
sb
- The swapping buffer.public SwappingBuffer getBuffer()
SwappingBuffer
used as the source / target for
virtual files.
public void setConsumer(CallbackStreamConsumer consumer)
setConsumer
in interface CallbackStreamProducer
consumer
- The stream consumer which will be called back to take delivery
of the file data.public CallbackStreamConsumer getConsumer()
public void startStreamProduction() throws java.io.IOException
setCDB
explicitly, or do a
findExactKey
first.
startStreamProduction
in interface CallbackStreamProducer
java.io.IOException
public long size()
protected void cppreMarshal() throws java.io.IOException
CDBObject
preMarshal
. The default implementation does nothing.
cppreMarshal
in class CDBObject
java.io.IOException
- if the object is not fit to be marshalled.protected void cppreUnmarshal() throws java.io.IOException
CDBObject
preUnmarshal
. The default
implementation does nothing.Note: This method is not called on objects created through the "cloning" method employed when the supplied object is not of the correct class - see introductory essay. This is a misfeature. The reason that it persists is that if the method _were_ called and then threw, the CDB would be marked as corrupt, which would be highly undesirable. The method is therefore only really useful for set classes which have no sub-classes other than the set class itself (i.e. give a homogeneous set, where cloning is never needed).
cppreUnmarshal
in class CDBObject
java.io.IOException
- If the object is not fit to be unmarshalled into.protected long cpgetMarshalledLength()
CDBObject
getMarshalledLength
cpgetMarshalledLength
in class CDBObject
protected void cpmarshal(java.io.DataOutputStream dos) throws java.io.IOException
CDBObject
marshal
.
The data will be in the object's fields when this is called (rather than
within any UI objects).
cpmarshal
in class CDBFileSysObject
dos
- The stream to marshal onto.
java.io.IOException
- If this breaks (breaks the CDB too).protected void cpunmarshal(java.io.DataInputStream dis, int marshalver) throws java.io.IOException
CDBObject
unmarshal
.
cpunmarshal
in class CDBFileSysObject
dis
- The stream to unmarshal frommarshalver
- The marshal version of the data in src - i.e. the
version of this class which wrote the data. This may be
different from the current marshalVersion
. If so (i.e. the
stored data is the wrong version) your method should allow for it.
This allows comparatively painless data migration between versions of
your objects.
java.io.IOException
- if this breaks (breaks the CDB too).public static void setMimeRegistry(MimeRegistry mimeReg)
MimeRegistry
to use when determining compressibility.
If none is provided, CDBFile assumes that all types are of unknown
compressibility and acts accordingly.
public static void setTrialZipSizeLimits(long lower, long upper)
long
s, in practice sound values
will be much smaller - a few K for the lower limit, a few hundred K for
the upper. (Possibly for larger values of "a few" in the latter case).
The defaults are probably reasonable in most cases.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |