001/*
002 * Copyright 2011 The Kuali Foundation.
003 * 
004 * Licensed under the Educational Community License, Version 1.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl1.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.batchingest;
017
018import java.io.BufferedReader;
019import java.io.FileInputStream;
020import java.io.InputStream;
021import java.io.InputStreamReader;
022import java.util.List;
023
024public class ProcessVendorFile {
025
026    public String transformStreamToRawData(InputStream inputStream) throws Exception{
027        return processRawDataToXml(readInputStream(inputStream));
028    }
029    
030    private String readInputStream(InputStream inputStream) throws Exception{
031        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
032        StringBuilder stringBuilder = new StringBuilder();
033        String line = null;
034        while ((line = reader.readLine()) != null) {
035            stringBuilder.append(line + "\n");
036        }
037        inputStream.close();
038        return stringBuilder.toString();
039    }
040    
041    public String getRawXml(InputStream inputStream,List bibinfoFailure) throws Exception{
042       return getFailureRawData(readInputStream(inputStream),bibinfoFailure);
043    }
044    
045    private String processRawDataToXml(String rawData) throws Exception{
046        return new MarcDataFormatTransformer().transformRawDataToXml(rawData);
047    }
048    
049    private String getFailureRawData(String rawData,List bibinfoFailure) throws Exception{
050        return new MarcDataFormatTransformer().getFailureRawData(rawData,bibinfoFailure);
051    }
052    
053    
054    
055    
056}