Ignore:
Timestamp:
2014-01-15T14:35:55+13:00 (10 years ago)
Author:
ak19
Message:

Encoding issue now straightened out

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/von-sparql/collect/nz-natlib-cat/pre-import/marcXML_Split/src/split.java

    r28734 r28794  
    1313        //Default values for arguments
    1414        int NRecords = 250;
    15         String OutputPath = "./out/";
     15        String OutputPath = "./out/nz_out";
    1616        String InputPath = "./NZDataFull.xml";
     17        //String InputPath = "./NZ-small-macron-test.xml";
    1718
    1819        //Incorrect number of arguments supplied
    19         if(args.length!=4)
     20        if(args.length!=2)
    2021        {
    21             System.err.println("USAGE: java split [-n records_per_file] [-o output_path]");
     22            System.err.println("USAGE: ./RUN [records_per_file] [output_path]");
    2223            return;
    2324        }
    24         //read arguments   
    25         for(int i=0; i < args.length; i+=2)
     25       
     26        try{
     27            NRecords = Integer.parseInt(args[0]);
     28            OutputPath = args[1];
     29        }
     30        catch(Exception e)
    2631        {
    27             if(args[i].equals("-n"))
    28                 NRecords = Integer.parseInt(args[i+1]);
    29             else if(args[i].equals("-o"))
    30                 OutputPath = args[i+1];
    31         }
    32        
     32            System.err.println("Invalid Arguments");
     33            System.err.println("USAGE: ./RUN [records_per_file] [output_path]");
     34            return;
     35        }   
     36
    3337        InputStream in;
    3438        try{
     
    4448        File f;
    4549        int RecordCount = 0;
     50                int ParseErrorCount = 0;
    4651       
    4752        while(reader.hasNext())
    48         {      
     53        {   
    4954            f = new File(TempFilename);
    50             MarcWriter writer = new MarcXmlWriter(new FileOutputStream(f),true);
     55            MarcWriter writer = new MarcXmlWriter(new FileOutputStream(f),"UTF8",true);
    5156            Record record;
    5257
     
    5459            for(int i=0; (i<NRecords && reader.hasNext()); i++)
    5560            {
    56                 record = reader.next();
    57                 writer.write(record);
    58                 RecordCount++;
     61                try {
     62                    record = reader.next();
     63                }
     64                catch (Exception e) {
     65                    System.err.println("Warning: Failed to parse record number: " + RecordCount);
     66                    ParseErrorCount++;
     67                    continue;
     68                }
     69                                writer.write(record);
     70                                RecordCount++;
    5971            }
    6072            writer.close();
Note: See TracChangeset for help on using the changeset viewer.