Skip to content
Snippets Groups Projects
Commit 597ef5ba authored by srosse's avatar srosse
Browse files

no-jira: close inputstream in QTI ParserManager and in ServletUtil

parent 08d3be74
No related branches found
No related tags found
No related merge requests found
...@@ -180,22 +180,23 @@ public class ServletUtil { ...@@ -180,22 +180,23 @@ public class ServletUtil {
} }
if (ranges != null && ranges.size() == 1) { if (ranges != null && ranges.size() == 1) {
Range range = ranges.get(0);
httpResp.addHeader("Content-Range", "bytes " + range.start + "-" + range.end + "/" + range.length); Range range = ranges.get(0);
long length = range.end - range.start + 1; httpResp.addHeader("Content-Range", "bytes " + range.start + "-" + range.end + "/" + range.length);
if (length < Integer.MAX_VALUE) { long length = range.end - range.start + 1;
httpResp.setContentLength((int) length); if (length < Integer.MAX_VALUE) {
} else { httpResp.setContentLength((int) length);
// Set the content-length as String to be able to use a long } else {
httpResp.setHeader("content-length", "" + length); // Set the content-length as String to be able to use a long
} httpResp.setHeader("content-length", "" + length);
httpResp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); }
try { httpResp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
httpResp.setBufferSize(2048); try {
} catch (IllegalStateException e) { httpResp.setBufferSize(2048);
// Silent catch } catch (IllegalStateException e) {
} // Silent catch
copy(out, in, range); }
copy(out, in, range);
} else { } else {
if (size != null) { if (size != null) {
httpResp.setContentLength(size.intValue()); httpResp.setContentLength(size.intValue());
...@@ -211,8 +212,6 @@ public class ServletUtil { ...@@ -211,8 +212,6 @@ public class ServletUtil {
} }
} }
} catch (IOException e) { } catch (IOException e) {
FileUtils.closeSafely(in);
FileUtils.closeSafely(bis);
FileUtils.closeSafely(out); FileUtils.closeSafely(out);
String className = e.getClass().getSimpleName(); String className = e.getClass().getSimpleName();
if("ClientAbortException".equals(className)) { if("ClientAbortException".equals(className)) {
...@@ -220,6 +219,9 @@ public class ServletUtil { ...@@ -220,6 +219,9 @@ public class ServletUtil {
} else { } else {
log.error("client browser probably abort when serving media resource", e); log.error("client browser probably abort when serving media resource", e);
} }
} finally {
IOUtils.closeQuietly(bis);
IOUtils.closeQuietly(in);
} }
} }
......
...@@ -25,47 +25,50 @@ ...@@ -25,47 +25,50 @@
package org.olat.ims.qti.editor.beecom.parser; package org.olat.ims.qti.editor.beecom.parser;
import java.io.InputStream;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.io.IOUtils;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.Element; import org.dom4j.Element;
import org.olat.core.logging.OLATRuntimeException; import org.olat.core.logging.OLATRuntimeException;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
/** /**
* @author rkulow * @author rkulow
*/ */
public class ParserManager implements IParser { public class ParserManager implements IParser {
private static final OLog log = Tracing.createLoggerFor(ParserManager.class);
private static String PROPERTIES_FILENAME = "org/olat/ims/qti/editor/beecom/parser/qtiparser.properties"; private static String PROPERTIES_FILENAME = "org/olat/ims/qti/editor/beecom/parser/qtiparser.properties";
private HashMap parserMap = null; private static final Map<String,String> parserMap = new ConcurrentHashMap<>();
private static String PARSER_DEFAULT = "defaultparser"; private static String PARSER_DEFAULT = "defaultparser";
/**
*
*/
public ParserManager() { public ParserManager() {
this.init(); init();
} }
private void init() { private void init() {
this.parserMap = new HashMap(); if(parserMap.isEmpty()) {
InputStream in = null;
try { try {
Properties prop = new Properties(); in = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
prop.load(this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILENAME)); Properties prop = new Properties();
Enumeration enumeration = prop.keys(); prop.load(in);
while (enumeration.hasMoreElements()) { for(Enumeration<Object> enumeration = prop.keys(); enumeration.hasMoreElements(); ) {
String key = (String) enumeration.nextElement(); String key = (String) enumeration.nextElement();
String value = prop.getProperty(key); String value = prop.getProperty(key);
this.parserMap.put(key, value); parserMap.put(key, value);
}
} catch (Exception e) {
log.error("Could not load qtiparser.properties", e);
} finally {
IOUtils.closeQuietly(in);
} }
} catch (Exception e) {
//
} }
} }
/** /**
...@@ -74,7 +77,7 @@ public class ParserManager implements IParser { ...@@ -74,7 +77,7 @@ public class ParserManager implements IParser {
*/ */
public Object parse(Document doc) { public Object parse(Document doc) {
Element rootElement = doc.getRootElement(); Element rootElement = doc.getRootElement();
return this.parse(rootElement); return parse(rootElement);
} }
/** /**
...@@ -85,16 +88,16 @@ public class ParserManager implements IParser { ...@@ -85,16 +88,16 @@ public class ParserManager implements IParser {
if (element == null) return null; if (element == null) return null;
String name = element.getName(); String name = element.getName();
String parserClassName = null; String parserClassName = null;
Object tmpName = this.parserMap.get(name); String tmpName = parserMap.get(name);
if (tmpName == null) { if (tmpName == null) {
parserClassName = (String) this.parserMap.get(PARSER_DEFAULT); parserClassName = parserMap.get(PARSER_DEFAULT);
} else { } else {
parserClassName = (String) tmpName; parserClassName = tmpName;
} }
if(Tracing.isDebugEnabled(ParserManager.class)){ if(log.isDebug()){
Tracing.logDebug("ELEMENTNAME:" + name + "PARSERNAME" + parserClassName,ParserManager.class); log.debug("ELEMENTNAME:" + name + "PARSERNAME" + parserClassName);
} }
Class parserClass = this.getClass().getClassLoader().loadClass(parserClassName); Class<?> parserClass = this.getClass().getClassLoader().loadClass(parserClassName);
IParser parser = (IParser) parserClass.newInstance(); IParser parser = (IParser) parserClass.newInstance();
return parser.parse(element); return parser.parse(element);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
...@@ -105,5 +108,4 @@ public class ParserManager implements IParser { ...@@ -105,5 +108,4 @@ public class ParserManager implements IParser {
throw new OLATRuntimeException(this.getClass(), "Illegal Access in QTI editor", e); throw new OLATRuntimeException(this.getClass(), "Illegal Access in QTI editor", e);
} }
} }
} }
\ No newline at end of file
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