Skip to content
Snippets Groups Projects
Commit 251410c2 authored by srosse's avatar srosse
Browse files

no-jira: fix javassist maven dependency (via hibernate-core and not...

no-jira: fix javassist maven dependency (via hibernate-core and not explicitly), limit the amout of text read by the TextDocument  indexer
parent ecfbfc9c
No related branches found
No related tags found
No related merge requests found
......@@ -1184,12 +1184,12 @@
<groupId>org.mnode.ical4j</groupId>
<artifactId>ical4j</artifactId>
<version>1.0.2</version>
</dependency>
</dependency><!--
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
</dependency> -->
<dependency><!-- Velocity dependency -->
<groupId>oro</groupId>
<artifactId>oro</artifactId>
......@@ -1439,6 +1439,10 @@
<groupId>xerces</groupId>
<artifactId>xmlParserAPIs</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
......
......@@ -25,13 +25,15 @@
package org.olat.search.service.document.file;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import org.apache.lucene.document.Document;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.search.service.SearchResourceContext;
......@@ -44,6 +46,10 @@ public class TextDocument extends FileDocument {
private static final OLog log = Tracing.createLoggerFor(TextDocument.class);
public final static String FILE_TYPE = "type.file.text";
/**
* Limit the maximal size of the content read to index.
*/
public static int MAX_SIZE = 200000;
public TextDocument() {
//
......@@ -60,9 +66,28 @@ public class TextDocument extends FileDocument {
@Override
protected FileContent readContent(VFSLeaf leaf) throws IOException {
BufferedInputStream bis = new BufferedInputStream(leaf.getInputStream());
String content = FileUtils.load(bis, "utf-8");
bis.close();
return new FileContent(content);
StringWriter out = new StringWriter();
InputStreamReader in = new InputStreamReader(leaf.getInputStream());
try {
copy(in, out);
} catch (Exception e) {
log.error("", e);
}
return new FileContent(out.toString());
}
private void copy(Reader input, Writer output)
throws IOException {
char[] buffer = new char[4096];
int count = 0;
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
if(count >= MAX_SIZE) {
break;
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment