use of org.olat.core.util.io.LimitedContentWriter in project OpenOLAT by OpenOLAT.
the class PowerPointDocument method readContent.
@Override
public FileContent readContent(VFSLeaf leaf) throws IOException, DocumentException {
if (log.isDebug())
log.debug("read PPT Content of leaf=" + leaf.getName());
try (BufferedInputStream bis = new BufferedInputStream(leaf.getInputStream())) {
LimitedContentWriter oStream = new LimitedContentWriter(100000, FileDocumentFactory.getMaxFileSize());
extractText(bis, oStream);
return new FileContent(oStream.toString());
} catch (Exception e) {
throw new DocumentException("Can not read PPT Content. File=" + leaf.getName(), e);
}
}
use of org.olat.core.util.io.LimitedContentWriter in project OpenOLAT by OpenOLAT.
the class TextDocument method readContent.
@Override
protected FileContent readContent(VFSLeaf leaf) throws IOException {
InputStreamReader in = new InputStreamReader(leaf.getInputStream());
LimitedContentWriter out = new LimitedContentWriter((int) leaf.getSize(), FileDocumentFactory.getMaxFileSize());
try {
copy(in, out);
} catch (Exception e) {
log.error("", e);
}
return new FileContent(out.toString());
}
use of org.olat.core.util.io.LimitedContentWriter in project OpenOLAT by OpenOLAT.
the class WordDocument method readContent.
@Override
protected FileContent readContent(VFSLeaf leaf) throws IOException, DocumentException {
LimitedContentWriter sb = new LimitedContentWriter((int) leaf.getSize(), FileDocumentFactory.getMaxFileSize());
try (InputStream bis = new BufferedInputStream(leaf.getInputStream())) {
POIFSFileSystem filesystem = new POIFSFileSystem(bis);
Iterator<?> entries = filesystem.getRoot().getEntries();
while (entries.hasNext()) {
Entry entry = (Entry) entries.next();
String name = entry.getName();
if (!(entry instanceof DocumentEntry)) {
// Skip directory entries
} else if ("WordDocument".equals(name)) {
collectWordDocument(leaf, filesystem, sb);
}
}
return new FileContent(sb.toString());
} catch (Exception e) {
log.warn("could not read in word document: " + leaf + " please check, that this is not an docx/rtf/html file!");
throw new DocumentException(e.getMessage());
}
}
use of org.olat.core.util.io.LimitedContentWriter in project OpenOLAT by OpenOLAT.
the class ExcelOOXMLDocument method parseSheets.
private String parseSheets(Map<String, String> sharedStrings, VFSLeaf leaf) throws IOException, DocumentException {
try (InputStream stream = leaf.getInputStream();
ZipInputStream zip = new ZipInputStream(stream)) {
ZipEntry entry = zip.getNextEntry();
LimitedContentWriter writer = new LimitedContentWriter(100000, FileDocumentFactory.getMaxFileSize());
while (entry != null) {
if (writer.accept()) {
String name = entry.getName();
if (name.startsWith(SHEET) && name.endsWith(".xml")) {
OfficeDocumentHandler dh = new OfficeDocumentHandler(writer, sharedStrings);
parse(new ShieldInputStream(zip), dh);
}
}
entry = zip.getNextEntry();
}
return writer.toString();
} catch (DocumentException e) {
throw e;
} catch (Exception e) {
throw new DocumentException(e.getMessage());
}
}
use of org.olat.core.util.io.LimitedContentWriter in project OpenOLAT by OpenOLAT.
the class PdfDocument method getPdfTextFromBuffer.
private FileContent getPdfTextFromBuffer(File pdfTextFile) throws IOException {
if (log.isDebug())
log.debug("readContent from text file start...");
try (BufferedReader br = new BufferedReader(new FileReader(pdfTextFile));
LimitedContentWriter sb = new LimitedContentWriter(5000, FileDocumentFactory.getMaxFileSize())) {
// search the title
char[] cbuf = new char[4096];
int length = br.read(cbuf);
int indexSep = 0;
String title = "";
if (length > 0) {
String firstChunk = new String(cbuf, 0, length);
indexSep = firstChunk.indexOf("\u00A0|\u00A0");
if (indexSep > 0) {
title = firstChunk.substring(0, indexSep);
sb.append(firstChunk.substring(indexSep + 3));
} else {
sb.append(firstChunk);
}
while ((length = br.read(cbuf)) > 0) {
sb.write(cbuf, 0, length);
}
}
return new FileContent(title, sb.toString());
} catch (IOException e) {
throw e;
}
}
Aggregations