|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.deepfs.fsml.DeepFile
public final class DeepFile
Storage for metadata information and contents for a single file.
A DeepFile can represent a regular file in the file system or a "subfile" that is stored inside another file, e.g. a file in a ZIP-file or a picture that is included in an ID3 tag.
Nested Class Summary | |
---|---|
static class |
DeepFile.Content
File content. |
Constructor Summary | |
---|---|
DeepFile(BufferedFileChannel f)
Constructor. |
|
DeepFile(File file)
Constructor. |
|
DeepFile(ParserRegistry parserRegistry,
BufferedFileChannel bufferedFileChannel,
Context ctx)
Constructor. |
|
DeepFile(String file)
Constructor. |
Method Summary | |
---|---|
void |
addMeta(MetaElem elem,
byte[] value)
Adds a metadata key-value pair for the current file. |
void |
addMeta(MetaElem elem,
double value)
Adds a metadata key-value pair for the current file. |
void |
addMeta(MetaElem elem,
Duration value)
Adds a metadata key-value pair for the current file. |
void |
addMeta(MetaElem elem,
int value)
Adds a metadata key-value pair for the current file. |
void |
addMeta(MetaElem elem,
long value)
Adds a metadata key-value pair for the current file. |
void |
addMeta(MetaElem elem,
short value)
Adds a metadata key-value pair for the current file. |
void |
addMeta(MetaElem elem,
String value)
Adds a metadata key-value pair for the current file. |
void |
addMeta(MetaElem elem,
XMLGregorianCalendar xgc)
Adds a metadata key-value pair for the current file. |
void |
addText(long position,
int byteCount,
String text)
Adds a text section. |
void |
addXML(long position,
int byteCount,
Data data)
Adds a xml document or fragment to the DeepFile. |
void |
addXML(long pos,
int byteCount,
String xml)
Adds a xml document or fragment to the DeepFile. |
void |
debug(String str,
Object... ext)
Verbose debug message. |
void |
extract()
Extracts metadata and text/xml contents from the associated file. |
boolean |
extractMeta()
Returns true, if metadata should be extracted. |
boolean |
extractText()
Returns true, if text contents should be extracted. |
boolean |
extractXML()
Returns true, if xml contents should be extracted. |
void |
fallback()
Calls the fallback parser for the associated file to extract text contents. |
void |
finish()
Finishes the deep file. |
void |
finishMetaExtraction()
Finishes the extraction of metadata and extracts the file system attributes. |
BufferedFileChannel |
getBufferedFileChannel()
Returns the associated BufferedFileChannel that links this
DeepFile with a file in the file system. |
DeepFile[] |
getContent()
Returns all subfiles. |
Context |
getContext()
Returns the database context. |
Atts |
getFSAtts()
Returns the file system attributes for the deep file. |
TreeMap<MetaElem,ArrayList<String>> |
getMeta()
Returns all metadata key-value pairs or null if metadata
extraction is disabled. |
long |
getOffset()
Returns the offset of the deep file inside the regular file in the file system. |
long |
getSize()
Returns the size of the deep file. |
DeepFile.Content[] |
getTextContents()
Returns all text sections or null if no text content
extraction is disabled. |
String[] |
getValues(MetaElem elem)
Returns the string values for the MetaElem . |
DeepFile.Content[] |
getXMLContents()
Returns all xml sections or null if xml extraction is
disabled. |
boolean |
isFileTypeSet()
Returns true, if the file type is set for the current deep file. |
boolean |
isMetaSet(MetaElem elem)
Returns true, if a value is set for the given metadata element. |
int |
maxTextSize()
Returns the number of bytes that should be extracted from text and xml contents. |
DeepFile |
newContentSection(long position)
Creates a new content section for the current file, beginning at the given position with an unknown size. |
DeepFile |
newContentSection(String title,
long position,
int contentSize)
Creates a new content section for the current file, beginning at the given position with an unknown size. |
void |
setFileFormat(MimeType format)
Sets the MIME type of the file. |
void |
setFileType(FileType type)
Sets the type of the file (e.g. audio, video, ...). |
void |
setSize(long contentSize)
Sets the size value for the DeepFile. |
DeepFile |
subfile(int contentSize)
Clones the DeepFile to map only a part of the file. |
DeepFile |
subfile(String fileName,
int fileSize,
String... suffix)
Creates a new "subfile" inside the current DeepFile with the given size, beginning at the current position of the file channel. |
String |
toString()
|
String |
toXML()
Returns the xml representation for this deep file. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DeepFile(String file) throws IOException
Constructor.
Creates a DeepFile object for a file that can be used to extract metadata and text/xml contents. By default, metadata and all contents will be extracted.
This constructor should only be used to parse a single file. Use
DeepFile(ParserRegistry, BufferedFileChannel, Context)
for parsing several files for better performance.
file
- the name of the associated file in the file system
IOException
- if any I/O error occursIFileParser.extract(DeepFile)
public DeepFile(File file) throws IOException
Constructor.
Creates a DeepFile object for a file that can be used to extract metadata and text/xml contents. By default, metadata and all contents will be extracted.
This constructor should only be used to parse a single file. Use
DeepFile(ParserRegistry, BufferedFileChannel, Context)
for parsing several files for better performance.
file
- the associated file in the file system
IOException
- if any I/O error occursIFileParser.extract(DeepFile)
public DeepFile(BufferedFileChannel f) throws IOException
Constructor.
Creates a DeepFile object for a buffered file channel that can be used to extract metadata and text/xml contents. By default, metadata and all contents will be extracted.
This constructor should only be used to parse a single file. Use
DeepFile(ParserRegistry, BufferedFileChannel, Context)
for parsing multiple files for better performance.
f
- the BufferedFileChannel
IOException
- if any error occurspublic DeepFile(ParserRegistry parserRegistry, BufferedFileChannel bufferedFileChannel, Context ctx) throws IOException
Constructor.
Uses the given parser registry to retrieve the corresponding parser for the file which is represented by the buffered file channel. Depending on the properties of the context, metadata, text content and xml content is extracted.
The properties can be set as follows:
ctx.prop.set(Prop.FSMETA, true); // extract metadata
ctx.prop.set(Prop.FSCONT, true); // extract text content
ctx.prop.set(Prop.FSXML, true); // extract xml content
ctx.prop.set(Prop.FSTEXTMAX, 10240); // amount of text/xml content to
extract (in bytes)
parserRegistry
- a reference to the parser registry that can be used
to parse file fragmentsbufferedFileChannel
- BufferedFileChannel
to access the filectx
- the database context
IOException
- if any error occursMethod Detail |
---|
public void extract() throws IOException
IOException
- if any error occurs while reading from the filepublic void fallback() throws IOException, ParserException
IOException
- if any error occurs while reading from the file
ParserException
- if the fallback parser could not be loadedpublic boolean extractMeta()
public boolean extractText()
public boolean extractXML()
public int maxTextSize()
public Context getContext()
public long getOffset()
public long getSize()
public Atts getFSAtts()
null
if the metadata
extraction was not finished yetfinishMetaExtraction()
public TreeMap<MetaElem,ArrayList<String>> getMeta()
null
if metadata
extraction is disabled.
public DeepFile[] getContent()
public DeepFile.Content[] getTextContents()
null
if no text content
extraction is disabled.
public DeepFile.Content[] getXMLContents()
null
if xml extraction is
disabled.
public BufferedFileChannel getBufferedFileChannel()
BufferedFileChannel
that links this
DeepFile
with a file in the file system.
BufferedFileChannel
public void setFileType(FileType type)
type
- the file typepublic void setFileFormat(MimeType format)
format
- the MIME typepublic void addMeta(MetaElem elem, byte[] value)
elem
- metadata element (the key). Must be a string attributevalue
- string value as byte arraypublic void addMeta(MetaElem elem, String value)
elem
- metadata element (the key)value
- string valuepublic void addMeta(MetaElem elem, short value)
elem
- metadata element (the key)value
- integer valuepublic void addMeta(MetaElem elem, int value)
elem
- metadata element (the key)value
- integer valuepublic void addMeta(MetaElem elem, long value)
elem
- metadata element (the key)value
- long valuepublic void addMeta(MetaElem elem, double value)
elem
- metadata element (the key)value
- double valuepublic void addMeta(MetaElem elem, Duration value)
elem
- metadata element (the key)value
- duration valuepublic void addMeta(MetaElem elem, XMLGregorianCalendar xgc)
elem
- metadata element (the key)xgc
- calendar valuepublic void finishMetaExtraction() throws IOException
IOException
- if any error occurs while extracting the file system
attributespublic String[] getValues(MetaElem elem)
MetaElem
.
elem
- the metadata element
public boolean isMetaSet(MetaElem elem)
elem
- the metadata element
public boolean isFileTypeSet()
public void addText(long position, int byteCount, String text)
Adds a text section. text
MUST contain only valid UTF-8
characters! Otherwise the generated XML document may be not
well-formed.
position
- the absolute position of the first byte of the file
fragment represented by this content element inside the current
file. A negative value stands for an unknown offsetbyteCount
- the size of the content elementtext
- the text to addpublic void addXML(long position, int byteCount, Data data) throws IOException
position
- offset of the xml document/fragement inside the filebyteCount
- number of bytes of the xml document/fragmentdata
- the xml document/fragment
IOException
- if any error occurspublic void addXML(long pos, int byteCount, String xml)
pos
- offset of the xml document/fragement inside the filebyteCount
- number of bytes of the xml document/fragmentxml
- the xml document/fragmentpublic void finish() throws IOException
IOException
- if any error occursBufferedFileChannel.finish()
public DeepFile subfile(String fileName, int fileSize, String... suffix) throws IOException
Creates a new "subfile" inside the current DeepFile with the given size, beginning at the current position of the file channel. This method is intended to be used if the content of the subfile has to be parsed with a different parser implementation than the "main" file. The name of the subfile is set as title metadata.
If the content can be parsed with the same parser and this parser can use
the same BufferedFileChannel
, then the method
newContentSection(long)
can be used instead.
fileName
- the name of the subfilefileSize
- the size of the subfilesuffix
- the file suffix(es). More than one suffix means that the file
type is unknown. All given suffixes will be tested
IOException
- if any error occursnewContentSection(long)
public DeepFile subfile(int contentSize) throws IOException
contentSize
- the size of the file fragment (the size of the
BufferedFileChannel)
IOException
- if any error occursfinish()
public DeepFile newContentSection(String title, long position, int contentSize) throws IOException
Creates a new content section for the current file, beginning at the given position with an unknown size.
The returned DeepFile instance uses a subchannel to read from the file. The
subchannel has to be finished after usage (
BufferedFileChannel.finish()
).
title
- the title of the content sectionposition
- the offset in the regular file where the section startscontentSize
- the size of the content section
IOException
- if any error occurssubfile(String, int, String...)
,
BufferedFileChannel.subChannel(String, int)
public DeepFile newContentSection(long position)
Creates a new content section for the current file, beginning at the given
position with an unknown size. The size must be set afterwards with
setSize(long)
.
The returned DeepFile instance uses the same underlying BufferedFileChannel as the current DeepFile.
position
- the offset in the regular file where the section starts
subfile(String, int, String...)
,
setSize(long)
public void setSize(long contentSize)
contentSize
- the size value to set for the content sectionnewContentSection(long)
public String toXML() throws IOException
IOException
- if any error occurspublic String toString()
toString
in class Object
public void debug(String str, Object... ext)
str
- debug stringext
- text optional extensions
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |