Package eu.bandm.tools.util.files
Class SourceHabitats.SourceHabitat
java.lang.Object
eu.bandm.tools.util.files.SourceHabitats.SourceHabitat
- Direct Known Subclasses:
SourceHabitats.SourceHabitat_file
,SourceHabitats.SourceHabitat_resource
- Enclosing class:
SourceHabitats
Represents one of many potential sources which have
to be searched for library modules, etc.
The positions where the sources live is encoded in the name of this instance:
FILE_/xxxx/xxx/ absolute file position FILE_xxxx/xxx/ relative file position with instances xxxx/xxx/a.txt, etc. RES_a.b.c/d/e resource relative to class a.b.c., with relative file position d/e and instances a.b.c/d/e/f.txt, etc.These prefices are defined by
SourceHabitats.PREFIX_RESOURCE
and
SourceHabitats.PREFIX_FILE
. Other kinds of source habitats can be defined,
with their own searching rules, by subclassing from this class.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected @Opt SourceHabitats.FoundSource
test_for_inputStream
(String id, @Opt BiConsumer<String, Object[]> verbose, String[] suffices) Searches for the resource with the given name and one of the given suffices.protected abstract @Opt SourceHabitats.FoundSource
test_idExt
(String id, @Opt BiConsumer<String, Object[]> verbose, String ext) Searches for the resource with the given name and suffix.
-
Field Details
-
name
Must be encoded with the prefix rules, as described in the class documentation text. -
ok
protected boolean okSet once on initialization to indicate that this Habitat is usable for searching and can be added to the search list.
-
-
Constructor Details
-
SourceHabitat
Only constructor. Only called by subclasses.- Parameters:
name
- the position encoding of this habitat, seeSourceHabitats.appendNewHabitat(String,String)
.
-
-
Method Details
-
test_idExt
@Opt protected abstract @Opt SourceHabitats.FoundSource test_idExt(String id, @Opt @Opt BiConsumer<String, Object[]> verbose, String ext) Searches for the resource with the given name and suffix. This must be implemented differently for different kinds of Habitats. Fills in the found stream and "location" into the aSourceHabitats.FoundSource
object.- Parameters:
id
- name of the resource searched forverbose
- the target of log messagesext
- extension of the resource name / file name. It must include the leading dot (=".") or be completely empty.- Returns:
- the found resource or null if no such exists.
-
test_for_inputStream
@Opt protected @Opt SourceHabitats.FoundSource test_for_inputStream(String id, @Opt @Opt BiConsumer<String, Object[]> verbose, String[] suffices) Searches for the resource with the given name and one of the given suffices. These are tested in the given sequential order. This implementation works for all kinds of habitats by callingtest_idExt(java.lang.String,java.util.function.@eu.bandm.tools.annotations.Opt BiConsumer<java.lang.String,java.lang.Object[]>,java.lang.String)
.- Parameters:
id
- name of the resource searched forverbose
- the target of log messagessuffices
- the list of file name suffices to be tested. Each suffix must include the leading dot (=".") or be completely empty.- Returns:
- the found resource or null if no such exists.
-