Index: test/edu/ucsb/nceas/metacat/restservice/ResourceHandlerTest.java
===================================================================
--- test/edu/ucsb/nceas/metacat/restservice/ResourceHandlerTest.java	(revision 5636)
+++ test/edu/ucsb/nceas/metacat/restservice/ResourceHandlerTest.java	(revision 5637)
@@ -67,9 +67,13 @@
             FileInputStream fis = new FileInputStream(f);
             ResourceHandler rh = new ResourceHandler(null, null, null);
             //Hashtable h = rh.processMMP(fis);
-            InputStream is = rh.processMMP(fis);
-            String s = IOUtils.toString(is);
-            System.out.println("Final Stream: " + s);
+            Vector<File> v = rh.processMMP(fis);
+            FileInputStream smFis = new FileInputStream(v.elementAt(0));
+            FileInputStream objFis = new FileInputStream(v.elementAt(1));
+            String sm = IOUtils.toString(smFis);
+            String obj = IOUtils.toString(objFis);
+            System.out.println("sm: " + sm);
+            System.out.println("obj: " + obj);
         }
         catch(Exception e)
         {
Index: src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java	(revision 5636)
+++ src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java	(revision 5637)
@@ -65,9 +65,12 @@
 import edu.ucsb.nceas.metacat.MetacatHandler;
 import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
 import edu.ucsb.nceas.metacat.dataone.CrudService;
+import edu.ucsb.nceas.metacat.properties.PropertyService;
 import edu.ucsb.nceas.metacat.service.SessionService;
 import edu.ucsb.nceas.metacat.util.RequestUtil;
 import edu.ucsb.nceas.metacat.util.SessionData;
+import edu.ucsb.nceas.utilities.PropertyNotFoundException;
+
 import org.dataone.service.streaming.util.StreamUtil;
 
 import com.gc.iotools.stream.is.InputStreamFromOutputStream;
@@ -1058,172 +1061,257 @@
         return h;
     }
     */
-    protected InputStream processMMP(final InputStream is)
-      throws IOException
+    
+    /**
+     * write the parts of an MMP to files.  The first file in the vector is
+     * a system metadata file, the 2nd is the object.
+     */
+    private static Vector<File> writeMMPPartsToFiles(InputStream is)
+        throws IOException
     {
-        Hashtable<String, InputStream> partsHash = new Hashtable<String, InputStream>();
-        final InputStreamFromOutputStream<String> objectStream = 
-            new InputStreamFromOutputStream<String>() 
+        System.out.println("producing data");
+        Logger logMetacat = Logger.getLogger(ResourceHandler.class);
+        
+        String[] searchStrings = {"boundary=", 
+                "Content-Disposition: attachment; filename=systemmetadata",
+                "Content-Disposition: attachment; filename=object"};
+        
+        String boundary = "";
+        String searchSegment = null;
+        byte[] b = new byte[1024];
+        int numread = is.read(b, 0, 1024);
+        String s = new String(b, 0, numread);
+        int ssi = 0;
+        boolean doneWithCurrentArray = false;
+        boolean searchForBoundary = false;
+        boolean writeMarker = true;
+        int currentArrayIndex = 0;
+        
+        File tmpDir;
+        try
         {
-            @Override
-            public String produce(final OutputStream dataSink) throws Exception 
+            tmpDir = new File(PropertyService.getProperty("application.tempDir"));
+        }
+        catch(PropertyNotFoundException pnfe)
+        {
+            logMetacat.error("ResourceHandler.writeMMPPartstoFiles: " +
+                    "application.tmpDir not found.  Using /tmp instead.");
+            tmpDir = new File("/tmp");
+        }
+        long datetimetag = new Date().getTime();
+        File smFile = new File(tmpDir, "sm." + datetimetag + ".tmp");
+        File objFile = new File(tmpDir, "obj." + datetimetag + ".tmp");
+        FileOutputStream smFos = new FileOutputStream(smFile);
+        FileOutputStream objFos = new FileOutputStream(objFile);
+        
+        boolean writeSM = true;
+        
+        while(numread != -1)
+        {
+            if(ssi == 2 && writeSM)
             {
-                System.out.println("producing data");
-                String[] searchStrings = {"boundary=", "Content-Disposition: attachment; filename=systemmetadata",
-                "Content-Disposition: attachment; filename=object"};
-                String boundary = "";
-                String searchSegment = null;
-                byte[] b = new byte[1024];
-                int numread = is.read(b, 0, 1024);
-                String s = new String(b, 0, numread);
-                int ssi = 0;
-                boolean doneWithCurrentArray = false;
-                boolean searchForBoundary = false;
-                int currentArrayIndex = 0;
-                
-                while(numread != -1)
+                writeSM = false;
+            }
+            
+            String searchString;
+            if(!searchForBoundary)
+            {
+                if(ssi == searchStrings.length)
                 {
-                    String searchString;
-                    if(!searchForBoundary)
+                    break;
+                }
+                searchString = searchStrings[ssi];
+            }
+            else
+            {
+                searchString = boundary;
+            }
+            
+            System.out.println("searchString: " + searchString);
+            System.out.println("done with array: " + doneWithCurrentArray);
+            System.out.println("searchForBoundary: " + searchForBoundary);
+            if(doneWithCurrentArray)
+            {
+                System.out.println("Getting new chunk");
+                numread = is.read(b, 0, 1024);
+                s = new String(b, 0, numread);
+            }
+            
+            System.out.println("/////////////////current chunk (s): \n" + s + "\n////////////end current chunk");
+            
+            int[] result = StreamUtil.lookForMatch(searchString, s);
+            System.out.println("got result from StreamUtil: " + result[0] + ", " + result[1]);
+            if(result[0] != -1 && result[1] == searchString.length())
+            { //we have the whole search string in this group of bytes
+                System.out.println("1");
+                if(searchForBoundary)
+                {
+                    System.out.println("2");
+                    //find the boundary, chop it off the end and inc ssi
+                    String strToWrite = s.substring(0, s.indexOf(boundary, currentArrayIndex));
+                    System.out.println("XXXX 1 writing string: " + strToWrite + "\nXXXX");
+                    
+                    //dataSink.write(strToWrite.getBytes());
+                    if(writeSM)
                     {
-                        if(ssi == searchStrings.length)
-                        {
-                            break;
-                        }
-                        searchString = searchStrings[ssi];
+                        smFos.write(strToWrite.getBytes());
                     }
                     else
                     {
-                        searchString = boundary;
+                        objFos.write(strToWrite.getBytes());
                     }
+                    doneWithCurrentArray = false; 
+                    currentArrayIndex = s.indexOf(boundary, currentArrayIndex) + 1;
+                    searchForBoundary = false;
+                    ssi++;
+                }
+                else if(ssi == 0)
+                { //we're looking for the boundary marker
+                    int searchStringIndex = s.indexOf(searchString);
+                    if(s.indexOf("\"", searchStringIndex + searchString.length() + 1) == -1)
+                    { //the end of the boundary is in the next byte array
+                        boundary = s.substring(searchStringIndex + searchString.length() + 1, s.length());
+                        doneWithCurrentArray = true;
+                    }
+                    else if(!boundary.startsWith("--"))
+                    { //we can read the whole boundary from this byte array
+                        boundary = s.substring(searchStringIndex + searchString.length() + 1, 
+                            s.indexOf("\"", searchStringIndex + searchString.length() + 1));
+                        boundary = "--" + boundary;
+                        ssi++;
+                        doneWithCurrentArray = false;
+                    }
+                    else
+                    { //we're now reading the 2nd byte array to get the rest of the boundary
+                        searchString = "\"";
+                        searchStringIndex = s.indexOf(searchString);
+                        boundary += s.substring(0, searchStringIndex);
+                        boundary = "--" + boundary;
+                        ssi++;
+                        doneWithCurrentArray = false;
+                    }
+                    System.out.println("boundary: " + boundary);
+                }
+                else if(ssi == 1 || ssi == 2)
+                { 
+                    int searchStringIndex = s.indexOf(searchString);
+                    //find the beginning of the system metadata or data object and 
+                    //start writing it to the dataSink
+                    int smBeginIndex = s.indexOf(searchString) + searchString.length() + 2;
+                    searchForBoundary = true;
+                    int boundaryIndex = s.indexOf(boundary, smBeginIndex);
+                    int end = s.length();
+                    if(boundaryIndex != -1)
+                    {
+                        end = boundaryIndex;
+                        ssi++;
+                        searchForBoundary = false;
+                    }
+                    currentArrayIndex = end + 1;
+                    String strToWrite = s.substring(smBeginIndex, end);
+                    System.out.println("XXXX 2 writing string: " + strToWrite + "\nXXXX");
                     
-                    System.out.println("searchString: " + searchString);
-                    System.out.println("done with array: " + doneWithCurrentArray);
-                    System.out.println("searchForBoundary: " + searchForBoundary);
-                    if(doneWithCurrentArray)
+                    //dataSink.write(strToWrite.getBytes());
+                    if(writeSM)
                     {
-                        System.out.println("Getting new chunk");
-                        numread = is.read(b, 0, 1024);
-                        s = new String(b, 0, numread);
+                        smFos.write(strToWrite.getBytes());
                     }
+                    else
+                    {
+                        objFos.write(strToWrite.getBytes());
+                    }
                     
-                    System.out.println("/////////////////current chunk (s): \n" + s + "\n////////////end current chunk");
+                    if(end == s.length())
+                    {
+                        System.out.println("DONE WITH ARRAY");
+                        doneWithCurrentArray = true;
+                        currentArrayIndex = 0;
+                    }
+                    else
+                    {
+                        System.out.println("NOT DONE WITH ARRAY");
+                        doneWithCurrentArray = false;
+                    }
+                }
+            }
+            else if(result[1] != searchString.length() && result[0] != 0)
+            {  //part of the search string is on the end of this byte group
+                doneWithCurrentArray = true;
+                searchForBoundary = false;
+                searchSegment = s.substring(result[0], s.length());
+                System.out.println("searchSegment1: " + searchSegment);
+            }
+            else if(result[1] != searchString.length() && result[0] == 0)
+            {  //we have the end of the searchString at the beginning of this byte group
+                if(searchSegment != null)
+                {
+                    searchSegment += s.substring(0, result[1]);
+                    System.out.println("searchSegment2: " + searchSegment);
+                    searchForBoundary = true;
+                    doneWithCurrentArray = true;
+                    ssi++;
+                    String strToWrite = s.substring(result[1] + 1, s.length());
+                    System.out.println("XXXX 3 writing string: " + strToWrite + "\nXXXX");
                     
-                    int[] result = StreamUtil.lookForMatch(searchString, s);
-                    System.out.println("got result from StreamUtil: " + result[0] + ", " + result[1]);
-                    if(result[0] != -1 && result[1] == searchString.length())
-                    { //we have the whole search string in this group of bytes
-                        System.out.println("1");
-                        if(searchForBoundary)
-                        {
-                            System.out.println("2");
-                            //find the boundary, chop it off the end and inc ssi
-                            String strToWrite = s.substring(0, s.indexOf(boundary, currentArrayIndex));
-                            System.out.println("XXXX 1 writing string: " + strToWrite + "\nXXXX");
-                            dataSink.write(strToWrite.getBytes());
-                            doneWithCurrentArray = false; 
-                            currentArrayIndex = s.indexOf(boundary, currentArrayIndex) + 1;
-                            searchForBoundary = false;
-                            ssi++;
-                        }
-                        else if(ssi == 0)
-                        { //we're looking for the boundary marker
-                            int searchStringIndex = s.indexOf(searchString);
-                            if(s.indexOf("\"", searchStringIndex + searchString.length() + 1) == -1)
-                            { //the end of the boundary is in the next byte array
-                                boundary = s.substring(searchStringIndex + searchString.length() + 1, s.length());
-                                doneWithCurrentArray = true;
-                            }
-                            else if(!boundary.startsWith("--"))
-                            { //we can read the whole boundary from this byte array
-                                boundary = s.substring(searchStringIndex + searchString.length() + 1, 
-                                    s.indexOf("\"", searchStringIndex + searchString.length() + 1));
-                                boundary = "--" + boundary;
-                                ssi++;
-                                doneWithCurrentArray = false;
-                            }
-                            else
-                            { //we're now reading the 2nd byte array to get the rest of the boundary
-                                searchString = "\"";
-                                searchStringIndex = s.indexOf(searchString);
-                                boundary += s.substring(0, searchStringIndex);
-                                boundary = "--" + boundary;
-                                ssi++;
-                                doneWithCurrentArray = false;
-                            }
-                            System.out.println("boundary: " + boundary);
-                        }
-                        else if(ssi == 1 || ssi == 2)
-                        { 
-                            int searchStringIndex = s.indexOf(searchString);
-                            //find the beginning of the system metadata or data object and 
-                            //start writing it to the dataSink
-                            int smBeginIndex = s.indexOf(searchString) + searchString.length() + 2;
-                            searchForBoundary = true;
-                            int boundaryIndex = s.indexOf(boundary, smBeginIndex);
-                            int end = s.length();
-                            if(boundaryIndex != -1)
-                            {
-                                end = boundaryIndex;
-                                ssi++;
-                                searchForBoundary = false;
-                            }
-                            currentArrayIndex = end + 1;
-                            String strToWrite = s.substring(smBeginIndex, end);
-                            System.out.println("XXXX 2 writing string: " + strToWrite + "\nXXXX");
-                            dataSink.write(strToWrite.getBytes());
-                            if(end == s.length())
-                            {
-                                System.out.println("DONE WITH ARRAY");
-                                doneWithCurrentArray = true;
-                                currentArrayIndex = 0;
-                            }
-                            else
-                            {
-                                System.out.println("NOT DONE WITH ARRAY");
-                                doneWithCurrentArray = false;
-                            }
-                        }
+                    //dataSink.write(strToWrite.getBytes());
+                    if(writeSM)
+                    {
+                        smFos.write(strToWrite.getBytes());
                     }
-                    else if(result[1] != searchString.length() && result[0] != 0)
-                    {  //part of the search string is on the end of this byte group
-                        doneWithCurrentArray = true;
-                        searchForBoundary = false;
-                        searchSegment = s.substring(result[0], s.length());
-                        System.out.println("searchSegment1: " + searchSegment);
+                    else
+                    {
+                        objFos.write(strToWrite.getBytes());
                     }
-                    else if(result[1] != searchString.length() && result[0] == 0)
-                    {  //we have the end of the searchString at the beginning of this byte group
-                        if(searchSegment != null)
-                        {
-                            searchSegment += s.substring(0, result[1]);
-                            System.out.println("searchSegment2: " + searchSegment);
-                            searchForBoundary = true;
-                            doneWithCurrentArray = true;
-                            ssi++;
-                            String strToWrite = s.substring(result[1] + 1, s.length());
-                            System.out.println("XXXX 3 writing string: " + strToWrite + "\nXXXX");
-                            dataSink.write(strToWrite.getBytes());
-                        }
+                }
+            }
+            else
+            {
+                if(searchForBoundary)
+                {
+                    //we're in between the start and end of a section 
+                    //so just write this to the stream
+                    System.out.println("XXXX 4 writing string: " + s + "\nXXXX");
+                    //dataSink.write(s.getBytes());
+                    if(writeSM)
+                    {
+                        smFos.write(s.getBytes());
                     }
                     else
                     {
-                        if(searchForBoundary)
-                        {
-                            //we're in between the start and end of a section 
-                            //so just write this to the stream
-                            System.out.println("XXXX 4 writing string: " + s + "\nXXXX");
-                            dataSink.write(s.getBytes());
-                        }
+                        objFos.write(s.getBytes());
                     }
                 }
-                dataSink.flush();
-                return "Completed";
             }
+        }
+        
+        Vector<File> v = new Vector<File>();
+        objFos.flush();
+        smFos.flush();
+        v.add(smFile);
+        v.add(objFile);
+        return v;
+    }
+    
+    /**
+     * return a vector where the first element is a string that represents the system
+     * metadata and the 2nd element is an InputStream that is the object
+     */
+    protected Vector<File> processMMP(final InputStream is)
+      throws IOException
+    {
+     /*   final InputStreamFromOutputStream<String> objectStream = 
+            new InputStreamFromOutputStream<String>() 
+        {
+            @Override
+            public String produce(final OutputStream dataSink) throws Exception 
+            {
+                
+                return produceInputStream(dataSink, is);
+            }
         };
         
-        //return partsHash;
-        return objectStream;
+        return objectStream;*/
+        return writeMMPPartsToFiles(is);
     }
     
     /**
