Class ClassPathSource
java.lang.Object
dev.langchain4j.data.document.source.ClassPathSource
- All Implemented Interfaces:
DocumentSource
Specialization of a
DocumentSource
that knows how to read from the classpath.
Use ClassPathDocumentLoader
to load
Document
s using this.
-
Constructor Summary
-
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.Provides anInputStream
to read the content of the document.boolean
Determines if the resource represented by thisClassPathSource
is inside an archive.metadata()
Returns the metadata associated with the source of the document.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
Description copied from interface:DocumentSource
Provides anInputStream
to read the content of the document. This method can be implemented to read from various sources like a local file or a network connection.- Specified by:
inputStream
in interfaceDocumentSource
- Returns:
- An InputStream from which the document content can be read.
- Throws:
IOException
- If an I/O error occurs while creating the InputStream.
-
metadata
Description copied from interface:DocumentSource
Returns the metadata associated with the source of the document. This could include details such as the source location, date of creation, owner, etc.- Specified by:
metadata
in interfaceDocumentSource
- Returns:
- A Metadata object containing information associated with the source of the document.
-