src/horaris/File2Horaro.java
changeset 12 3932322b7d83
equal deleted inserted replaced
11:27ba8edb3437 12:3932322b7d83
       
     1 package horaris;
       
     2 
       
     3 import javax.microedition.midlet.MIDlet;
       
     4 
       
     5 import ogdl.Graph;
       
     6 import ogdl.Ogdl2Graph;
       
     7 import ogdl.OgdlParser;
       
     8 import java.io.InputStream;
       
     9 import java.io.IOException;
       
    10 import java.io.UnsupportedEncodingException;
       
    11 import java.io.InputStreamReader;
       
    12 import java.lang.Class;
       
    13 
       
    14 public class File2Horaro
       
    15 {
       
    16 	public static Horaro load(String filename, MIDlet main)
       
    17 	{
       
    18 		/* Open file */
       
    19 		InputStream is = main.getClass().getResourceAsStream(filename);
       
    20 		if (is == null)
       
    21 		{
       
    22 			System.err.println("Resource "+ filename +
       
    23 					" not found");
       
    24 			return null;
       
    25 		}
       
    26 		InputStreamReader in;
       
    27 		try {
       
    28 			in = new InputStreamReader(is,
       
    29 					"UTF-8");
       
    30 		} catch (UnsupportedEncodingException e) {
       
    31 			System.err.println("Enconding error " + e);
       
    32 			return null;
       
    33 		}
       
    34 
       
    35 		Horaro horaroevents = new Horaro();
       
    36 		try {
       
    37 			OgdlParser parser = new OgdlParser(in, horaroevents);
       
    38 			parser.parse();
       
    39 		} catch (Exception e) {
       
    40 			System.err.println("Exception parsing." + e.getMessage());
       
    41 		}
       
    42 
       
    43 
       
    44 		try {
       
    45 			in.close();
       
    46 		} catch (IOException e)
       
    47 		{
       
    48 			System.err.println("Exception closing is");
       
    49 		}
       
    50 
       
    51 		return horaroevents;
       
    52 	}
       
    53 }