Index: src/test/java/org/apache/servicemix/components/util/SimpleFlatFileMarshalerTest.java
===================================================================
--- src/test/java/org/apache/servicemix/components/util/SimpleFlatFileMarshalerTest.java	(revision 654702)
+++ src/test/java/org/apache/servicemix/components/util/SimpleFlatFileMarshalerTest.java	(working copy)
@@ -20,47 +20,50 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.jbi.JBIException;
 import junit.framework.TestCase;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 
 public class SimpleFlatFileMarshalerTest extends TestCase {
 
-    public void testFixedLengthMarshalling() throws FileNotFoundException, IOException {
+    public void testFixedLengthMarshalling() throws FileNotFoundException, IOException, JBIException {
         SimpleFlatFileMarshaler marshaler = new SimpleFlatFileMarshaler();
         marshaler.setLineFormat(SimpleFlatFileMarshaler.LINEFORMAT_FIXLENGTH);
         marshaler.setColumnLengths(new String[] {"2", "3", "5" });
 
         String path = "./src/test/resources/org/apache/servicemix/components/util/fixedlength.txt";
-        String result = marshaler.convertLinesToString(null, new FileInputStream(new File(path)), path);
+        String result = convertLinesToString(marshaler, new FileInputStream(new File(path)), path);
         assertNotNull(result);
         assertTrue(result.length() > 0);
 
         assertTrue(result.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
         assertTrue(result.contains("<File"));
-        assertTrue(result.endsWith("</File>\n"));
+        assertTrue(result.endsWith("</File>"));
 
         assertTrue(StringUtils.countMatches(result, "<Line") == 3);
     }
 
-    public void testFixedLengthWithColNamesMarshalling() throws FileNotFoundException, IOException {
+    public void testFixedLengthWithColNamesMarshalling() throws FileNotFoundException, IOException, JBIException {
         SimpleFlatFileMarshaler marshaler = new SimpleFlatFileMarshaler();
         marshaler.setLineFormat(SimpleFlatFileMarshaler.LINEFORMAT_FIXLENGTH);
         marshaler.setColumnLengths(new String[] {"2", "3", "5" });
         marshaler.setColumnNames(new String[] {"First", "Second", "Third" });
 
         String path = "./src/test/resources/org/apache/servicemix/components/util/fixedlength.txt";
-        String result = marshaler.convertLinesToString(null, new FileInputStream(new File(path)), path);
+        String result = convertLinesToString(marshaler, new FileInputStream(new File(path)), path);
         assertNotNull(result);
         assertTrue(result.length() > 0);
 
         assertTrue(result.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
         assertTrue(result.contains("<File"));
-        assertTrue(result.endsWith("</File>\n"));
+        assertTrue(result.endsWith("</File>"));
 
         assertTrue(StringUtils.countMatches(result, "<Line") == 3);
         assertTrue(StringUtils.countMatches(result, "<First") == 3);
@@ -68,7 +71,7 @@
         assertTrue(StringUtils.countMatches(result, "<Third") == 3);
     }
 
-    public void testFixedLengthWithConversionMarshalling() throws FileNotFoundException, IOException {
+    public void testFixedLengthWithConversionMarshalling() throws FileNotFoundException, IOException, JBIException {
         SimpleFlatFileMarshaler marshaler = new SimpleFlatFileMarshaler();
         marshaler.setLineFormat(SimpleFlatFileMarshaler.LINEFORMAT_FIXLENGTH);
         marshaler.setColumnLengths(new String[] {"2", "3", "5", "8" });
@@ -82,13 +85,13 @@
         marshaler.setColumnConverters(columnConverters);
 
         String path = "./src/test/resources/org/apache/servicemix/components/util/fixedlength_morecomplex.txt";
-        String result = marshaler.convertLinesToString(null, new FileInputStream(new File(path)), path);
+        String result = convertLinesToString(marshaler, new FileInputStream(new File(path)), path);
         assertNotNull(result);
         assertTrue(result.length() > 0);
 
         assertTrue(result.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
         assertTrue(result.contains("<File"));
-        assertTrue(result.endsWith("</File>\n"));
+        assertTrue(result.endsWith("</File>"));
 
         assertTrue(StringUtils.countMatches(result, "<Line") == 3);
         assertTrue(StringUtils.countMatches(result, "<Number") == 3);
@@ -97,20 +100,70 @@
         assertTrue(StringUtils.countMatches(result, "<Date") == 2);
     }
 
-    public void testCSVMarshalling() throws FileNotFoundException, IOException {
+    public void testCSVMarshalling() throws FileNotFoundException, IOException, JBIException {
         SimpleFlatFileMarshaler marshaler = new SimpleFlatFileMarshaler();
         marshaler.setLineFormat(SimpleFlatFileMarshaler.LINEFORMAT_CSV);
 
         String path = "./src/test/resources/org/apache/servicemix/components/util/csv_simplesample.csv";
-        String result = marshaler.convertLinesToString(null, new FileInputStream(new File(path)), path);
+        String result = convertLinesToString(marshaler, new FileInputStream(new File(path)), path);
         assertNotNull(result);
         assertTrue(result.length() > 0);
 
         assertTrue(result.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
         assertTrue(result.contains("<File"));
-        assertTrue(result.endsWith("</File>\n"));
+        assertTrue(result.endsWith("</File>"));
 
         assertTrue(StringUtils.countMatches(result, "<Line") == 3);
     }
+    
+    class FileFewTimes extends InputStream {
+        byte [] buffer;
+        int pos;
+        int timesLeft;
+        public FileFewTimes(File file, int times) throws FileNotFoundException, IOException {
+            this.timesLeft = times;
+            buffer = new byte [(int)file.length()];
+            FileInputStream fs = new FileInputStream(file);
+            if (buffer.length != fs.read(buffer)) {
+                throw new IOException("Unexpected end of file " + file.getCanonicalPath());
+            }
+        }
 
+        @Override
+        public int read() throws IOException {
+            if (pos < buffer.length) {
+                return buffer[pos++];
+            }
+            if (timesLeft == 0) {
+                return -1;
+            }
+            timesLeft--;
+            pos = 0;
+            return buffer[pos++];
+        }
+    }
+    
+    public void testHugeStream() throws FileNotFoundException, IOException {
+        SimpleFlatFileMarshaler marshaler = new SimpleFlatFileMarshaler();
+        marshaler.setLineFormat(SimpleFlatFileMarshaler.LINEFORMAT_CSV);
+
+        String path = "./src/test/resources/org/apache/servicemix/components/util/csv_simplesample.csv";
+        InputStream in = new FileFewTimes(new File(path), 500000);
+        InputStream out = marshaler.convertLines(null, in, path);
+        int r = 0;
+        while (r != -1) {
+            r = out.read();
+        }
+    }
+
+    private String convertLinesToString(SimpleFlatFileMarshaler marshaler, FileInputStream fileInputStream,
+            String path) throws IOException, JBIException {
+        InputStream out = marshaler.convertLines(null, fileInputStream, path);
+        StringBuilder sb = new StringBuilder();
+        for (Object string : IOUtils.readLines(out)) {
+            sb.append(string);
+        }
+        return sb.toString();
+    }
+
 }
