mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-17 14:21:39 +00:00
Fixed TextMining (Word to Text) transformer that was not closing an input stream after use
Added checks to the Abstract transformer to log an error non-closures of streams. This won't halt execution. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2384 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -88,7 +88,7 @@ public abstract class AbstractContentAccessor implements ContentAccessor
|
|||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder(1024);
|
StringBuilder sb = new StringBuilder(1024);
|
||||||
StackTraceUtil.buildStackTrace(
|
StackTraceUtil.buildStackTrace(
|
||||||
"Content IO Channel was opened but not closed",
|
"Content IO Channel was opened but not closed: \n" + this,
|
||||||
traceLoggerChannelAssignTrace,
|
traceLoggerChannelAssignTrace,
|
||||||
sb,
|
sb,
|
||||||
-1);
|
-1);
|
||||||
|
@@ -240,6 +240,18 @@ public abstract class AbstractContentTransformer implements ContentTransformer
|
|||||||
" options: " + options,
|
" options: " + options,
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// check that the reader and writer are both closed
|
||||||
|
if (!reader.isClosed())
|
||||||
|
{
|
||||||
|
logger.error("Content reader not closed by transformer: \n" + reader);
|
||||||
|
}
|
||||||
|
if (!writer.isClosed())
|
||||||
|
{
|
||||||
|
logger.error("Content writer not closed by transformer: \n" + writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// record time
|
// record time
|
||||||
long after = System.currentTimeMillis();
|
long after = System.currentTimeMillis();
|
||||||
|
@@ -70,6 +70,8 @@ public interface ContentTransformer
|
|||||||
* The source and target mimetypes <b>must</b> be available on the
|
* The source and target mimetypes <b>must</b> be available on the
|
||||||
* {@link org.alfresco.service.cmr.repository.ContentAccessor#getMimetype()} methods of
|
* {@link org.alfresco.service.cmr.repository.ContentAccessor#getMimetype()} methods of
|
||||||
* both the reader and the writer.
|
* both the reader and the writer.
|
||||||
|
* <p>
|
||||||
|
* Both reader and writer will be closed after the transformation completes.
|
||||||
*
|
*
|
||||||
* @param reader the source of the content
|
* @param reader the source of the content
|
||||||
* @param writer the destination of the transformed content
|
* @param writer the destination of the transformed content
|
||||||
|
@@ -23,8 +23,6 @@ import java.util.Map;
|
|||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.textmining.text.extraction.WordExtractor;
|
import org.textmining.text.extraction.WordExtractor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,8 +33,6 @@ import org.textmining.text.extraction.WordExtractor;
|
|||||||
*/
|
*/
|
||||||
public class TextMiningContentTransformer extends AbstractContentTransformer
|
public class TextMiningContentTransformer extends AbstractContentTransformer
|
||||||
{
|
{
|
||||||
private static final Log logger = LogFactory.getLog(TextMiningContentTransformer.class);
|
|
||||||
|
|
||||||
private WordExtractor wordExtractor;
|
private WordExtractor wordExtractor;
|
||||||
|
|
||||||
public TextMiningContentTransformer()
|
public TextMiningContentTransformer()
|
||||||
@@ -64,10 +60,11 @@ public class TextMiningContentTransformer extends AbstractContentTransformer
|
|||||||
public void transformInternal(ContentReader reader, ContentWriter writer, Map<String, Object> options)
|
public void transformInternal(ContentReader reader, ContentWriter writer, Map<String, Object> options)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
InputStream is = reader.getContentInputStream();
|
InputStream is = null;
|
||||||
String text = null;
|
String text = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
is = reader.getContentInputStream();
|
||||||
text = wordExtractor.extractText(is);
|
text = wordExtractor.extractText(is);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
@@ -80,7 +77,14 @@ public class TextMiningContentTransformer extends AbstractContentTransformer
|
|||||||
text = "";
|
text = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// dump the text out
|
finally
|
||||||
|
{
|
||||||
|
if (is != null)
|
||||||
|
{
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// dump the text out. This will close the writer automatically.
|
||||||
writer.putContent(text);
|
writer.putContent(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user