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:
Derek Hulley
2006-02-15 13:51:25 +00:00
parent b4abc1b8a1
commit 976fa1a09c
4 changed files with 25 additions and 7 deletions

View File

@@ -88,7 +88,7 @@ public abstract class AbstractContentAccessor implements ContentAccessor
{
StringBuilder sb = new StringBuilder(1024);
StackTraceUtil.buildStackTrace(
"Content IO Channel was opened but not closed",
"Content IO Channel was opened but not closed: \n" + this,
traceLoggerChannelAssignTrace,
sb,
-1);

View File

@@ -240,6 +240,18 @@ public abstract class AbstractContentTransformer implements ContentTransformer
" options: " + options,
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
long after = System.currentTimeMillis();

View File

@@ -70,6 +70,8 @@ public interface ContentTransformer
* The source and target mimetypes <b>must</b> be available on the
* {@link org.alfresco.service.cmr.repository.ContentAccessor#getMimetype()} methods of
* 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 writer the destination of the transformed content

View File

@@ -23,8 +23,6 @@ import java.util.Map;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentReader;
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;
/**
@@ -35,8 +33,6 @@ import org.textmining.text.extraction.WordExtractor;
*/
public class TextMiningContentTransformer extends AbstractContentTransformer
{
private static final Log logger = LogFactory.getLog(TextMiningContentTransformer.class);
private WordExtractor wordExtractor;
public TextMiningContentTransformer()
@@ -64,10 +60,11 @@ public class TextMiningContentTransformer extends AbstractContentTransformer
public void transformInternal(ContentReader reader, ContentWriter writer, Map<String, Object> options)
throws Exception
{
InputStream is = reader.getContentInputStream();
InputStream is = null;
String text = null;
try
{
is = reader.getContentInputStream();
text = wordExtractor.extractText(is);
}
catch (IOException e)
@@ -80,7 +77,14 @@ public class TextMiningContentTransformer extends AbstractContentTransformer
text = "";
}
}
// dump the text out
finally
{
if (is != null)
{
is.close();
}
}
// dump the text out. This will close the writer automatically.
writer.putContent(text);
}
}