Class ClassPathSource
java.lang.Object
dev.langchain4j.data.document.source.ClassPathSource
- All Implemented Interfaces:
dev.langchain4j.data.document.DocumentSource
Specialization of a
DocumentSource
that knows how to read from the classpath.
Use ClassPathDocumentLoader
to load
Document
s using this.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionTheClassLoader
that was used to load thisClassPathSource
static ClassPathSource
Creates a new instance ofClassPathSource
from the given classpath resource string, usingThread.currentThread().getContextClassLoader()
as the class loader.static ClassPathSource
from
(String classPathResource, ClassLoader classLoader) Creates a new instance ofClassPathSource
from the given classpath resource and classloader.boolean
Determines if the resource represented by thisClassPathSource
is inside an archive.dev.langchain4j.data.document.Metadata
metadata()
url()
Retrieves the URL associated with thisClassPathSource
.
-
Constructor Details
-
ClassPathSource
-
-
Method Details
-
from
Creates a new instance ofClassPathSource
from the given classpath resource string, usingThread.currentThread().getContextClassLoader()
as the class loader.- Parameters:
classPathResource
- The path of the classpath resource to be loaded.- Returns:
- A
ClassPathSource
instance representing the classpath resource. - Throws:
IllegalArgumentException
- if the classpath resource is blank or cannot be found.- See Also:
-
from
Creates a new instance ofClassPathSource
from the given classpath resource and classloader.- Parameters:
classPathResource
- The path of the classpath resource to be loaded. Must not be blank.classLoader
- The class loader to use for loading the resource. Ifnull
then usesThread.currentThread().getContextClassLoader()
as the class loader.- Returns:
- A
ClassPathSource
instance representing the classpath resource. - Throws:
IllegalArgumentException
- If the classpath resource is blank or cannot be found, or if the class loader is null.
-
url
Retrieves the URL associated with thisClassPathSource
.- Returns:
- The
URL
instance representing the classpath resource.
-
classLoader
TheClassLoader
that was used to load thisClassPathSource
- Returns:
- The
ClassLoader
that was used to load thisClassPathSource
-
isInsideArchive
public boolean isInsideArchive()Determines if the resource represented by thisClassPathSource
is inside an archive.- Returns:
true
if the resource is packaged inside an archive, otherwisefalse
.
-
inputStream
- Specified by:
inputStream
in interfacedev.langchain4j.data.document.DocumentSource
- Throws:
IOException
-
metadata
public dev.langchain4j.data.document.Metadata metadata()- Specified by:
metadata
in interfacedev.langchain4j.data.document.DocumentSource
-