use of org.apache.commons.io.input.CloseShieldInputStream in project sling by apache.
the class ZipReader method parse.
/**
* @see org.apache.sling.jcr.contentloader.ContentReader#parse(java.io.InputStream, org.apache.sling.jcr.contentloader.ContentCreator)
*/
public void parse(InputStream ins, ContentCreator creator) throws IOException, RepositoryException {
try {
creator.createNode(null, NT_FOLDER, null);
final ZipInputStream zis = new ZipInputStream(ins);
ZipEntry entry;
do {
entry = zis.getNextEntry();
if (entry != null) {
if (!entry.isDirectory()) {
String name = entry.getName();
int pos = name.lastIndexOf('/');
if (pos != -1) {
creator.switchCurrentNode(name.substring(0, pos), NT_FOLDER);
}
creator.createFileAndResourceNode(name, new CloseShieldInputStream(zis), null, entry.getTime());
creator.finishNode();
creator.finishNode();
if (pos != -1) {
creator.finishNode();
}
}
zis.closeEntry();
}
} while (entry != null);
creator.finishNode();
} finally {
if (ins != null) {
try {
ins.close();
} catch (IOException ignore) {
}
}
}
}
use of org.apache.commons.io.input.CloseShieldInputStream in project gradle by gradle.
the class TarTaskOutputPacker method unpack.
private void unpack(TaskOutputsInternal taskOutputs, TarInputStream tarInput, TaskOutputOriginReader readOriginAction) throws IOException {
Map<String, TaskOutputFilePropertySpec> propertySpecs = Maps.uniqueIndex(taskOutputs.getFileProperties(), new Function<TaskFilePropertySpec, String>() {
@Override
public String apply(TaskFilePropertySpec propertySpec) {
return propertySpec.getPropertyName();
}
});
boolean originSeen = false;
TarEntry entry;
while ((entry = tarInput.getNextEntry()) != null) {
String name = entry.getName();
if (name.equals(METADATA_PATH)) {
// handle origin metadata
originSeen = true;
readOriginAction.execute(new CloseShieldInputStream(tarInput));
} else {
// handle output property
Matcher matcher = PROPERTY_PATH.matcher(name);
if (!matcher.matches()) {
throw new IllegalStateException("Cached result format error, invalid contents: " + name);
}
String propertyName = matcher.group(2);
CacheableTaskOutputFilePropertySpec propertySpec = (CacheableTaskOutputFilePropertySpec) propertySpecs.get(propertyName);
if (propertySpec == null) {
throw new IllegalStateException(String.format("No output property '%s' registered", propertyName));
}
boolean outputMissing = matcher.group(1) != null;
String childPath = matcher.group(3);
unpackPropertyEntry(propertySpec, tarInput, entry, childPath, outputMissing);
}
}
if (!originSeen) {
throw new IllegalStateException("Cached result format error, no origin metadata was found.");
}
}
use of org.apache.commons.io.input.CloseShieldInputStream in project tika by apache.
the class XMLParser method parse.
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
if (metadata.get(Metadata.CONTENT_TYPE) == null) {
metadata.set(Metadata.CONTENT_TYPE, "application/xml");
}
final XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
xhtml.startElement("p");
TaggedContentHandler tagged = new TaggedContentHandler(handler);
try {
context.getSAXParser().parse(new CloseShieldInputStream(stream), new OfflineContentHandler(new EmbeddedContentHandler(getContentHandler(tagged, metadata, context))));
} catch (SAXException e) {
tagged.throwIfCauseOf(e);
throw new TikaException("XML parse error", e);
} finally {
xhtml.endElement("p");
xhtml.endDocument();
}
}
use of org.apache.commons.io.input.CloseShieldInputStream in project tika by apache.
the class SXSLFPowerPointExtractorDecorator method handleSlidePart.
private void handleSlidePart(PackagePart slidePart, XHTMLContentHandler xhtml) throws IOException, SAXException {
Map<String, String> linkedRelationships = loadLinkedRelationships(slidePart, false, metadata);
// Map<String, String> hyperlinks = loadHyperlinkRelationships(packagePart);
xhtml.startElement("div", "class", "slide-content");
try (InputStream stream = slidePart.getInputStream()) {
context.getSAXParser().parse(new CloseShieldInputStream(stream), new OfflineContentHandler(new EmbeddedContentHandler(new OOXMLWordAndPowerPointTextHandler(new OOXMLTikaBodyPartHandler(xhtml), linkedRelationships))));
} catch (TikaException e) {
metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e));
}
xhtml.endElement("div");
handleBasicRelatedParts(XSLFRelation.SLIDE_LAYOUT.getRelation(), "slide-master-content", slidePart, new PlaceHolderSkipper(new OOXMLWordAndPowerPointTextHandler(new OOXMLTikaBodyPartHandler(xhtml), linkedRelationships)));
handleBasicRelatedParts(XSLFRelation.NOTES.getRelation(), "slide-notes", slidePart, new OOXMLWordAndPowerPointTextHandler(new OOXMLTikaBodyPartHandler(xhtml), linkedRelationships));
handleBasicRelatedParts(XSLFRelation.NOTES_MASTER.getRelation(), "slide-notes-master", slidePart, new OOXMLWordAndPowerPointTextHandler(new OOXMLTikaBodyPartHandler(xhtml), linkedRelationships));
handleBasicRelatedParts(XSLFRelation.COMMENTS.getRelation(), null, slidePart, new XSLFCommentsHandler(xhtml));
}
use of org.apache.commons.io.input.CloseShieldInputStream in project tika by apache.
the class XWPFEventBasedWordExtractor method handlePart.
private void handlePart(PackagePart packagePart, XWPFListManager xwpfListManager, StringBuilder buffer) throws IOException, SAXException {
Map<String, String> hyperlinks = loadHyperlinkRelationships(packagePart);
try (InputStream stream = packagePart.getInputStream()) {
XMLReader reader = SAXHelper.newXMLReader();
reader.setContentHandler(new OOXMLWordAndPowerPointTextHandler(new XWPFToTextContentHandler(buffer), hyperlinks));
reader.parse(new InputSource(new CloseShieldInputStream(stream)));
} catch (ParserConfigurationException e) {
LOG.warn("Can't configure XMLReader", e);
}
}
Aggregations