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
Documents using this.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionTheClassLoaderthat was used to load thisClassPathSourcestatic ClassPathSourceCreates a new instance ofClassPathSourcefrom the given classpath resource string, usingThread.currentThread().getContextClassLoader()as the class loader.static ClassPathSourcefrom(String classPathResource, ClassLoader classLoader) Creates a new instance ofClassPathSourcefrom the given classpath resource and classloader.Provides anInputStreamto read the content of the document.booleanDetermines if the resource represented by thisClassPathSourceis 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 ofClassPathSourcefrom 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
ClassPathSourceinstance representing the classpath resource. - Throws:
IllegalArgumentException- if the classpath resource is blank or cannot be found.- See Also:
-
from
Creates a new instance ofClassPathSourcefrom 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. Ifnullthen usesThread.currentThread().getContextClassLoader()as the class loader.- Returns:
- A
ClassPathSourceinstance 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
URLinstance representing the classpath resource.
-
classLoader
TheClassLoaderthat was used to load thisClassPathSource- Returns:
- The
ClassLoaderthat was used to load thisClassPathSource
-
isInsideArchive
public boolean isInsideArchive()Determines if the resource represented by thisClassPathSourceis inside an archive.- Returns:
trueif the resource is packaged inside an archive, otherwisefalse.
-
inputStream
Description copied from interface:DocumentSourceProvides anInputStreamto 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:
inputStreamin 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:DocumentSourceReturns 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:
metadatain interfaceDocumentSource- Returns:
- A
Metadataobject containing information about the document source, such asDocument.FILE_NAMEandDocument.ABSOLUTE_DIRECTORY_PATH.
-