InetAddress addr = InetAddress.getLocalHost() ;
name = new String( addr.getCanonicalHostName() ) ;
} catch( final Exception e ) {
- System.err.println( "Unalbe to retrieve host name !" ) ;
+ System.err.println( "Unalbe to retrieve host's name !" ) ;
e.printStackTrace();
System.exit( 1 ) ;
}
*/
public static void writeGrid( Grid _gl, String _file, String _path )
{
- if ( ! _file.equals( "" ) && ! _file.endsWith( ".xml" ) )
+ if( _file.equals( "" ) )
+ {
+ System.err.println( "No file's name !\n" ) ;
+ return ;
+ }
+
+ if ( ! _file.endsWith( ".xml" ) )
{
_file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier
}
*/
public static void writeGraph( Graph _gr, String _file, String _path )
{
- if ( ! _file.equals( "" ) && ! _file.endsWith( ".xml" ) )
+ if( _file.equals( "" ) )
+ {
+ System.err.println( "No file's name !\n" ) ;
+ return ;
+ }
+
+ if ( ! _file.endsWith( ".xml" ) )
{
_file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier
}
/**
* Read an application Graph from a file.
* @param _file File's name
+ * @param _path File's path
* @return The application Graph read
*/
- public static Graph readGraph( String _file )
+ public static Graph readGraph( String _path, String _file )
{
- if ( _file.equals( "" ) || ! _file.endsWith( ".xml" ) )
+ if ( _file.equals( "" ) )
{
- System.err.println( "Bad file !\n" ) ;
+ System.err.println( "No file's name !\n" ) ;
return null ;
}
+ if ( ! _file.endsWith( ".xml" ) )
+ {
+ _file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier
+ }
+
+ String path = "" ;
+
+ if( _path.length() != 0 )
+ {
+ path = _path+"/"+_file ;
+ } else {
+ path = new String( "./" + _file ) ;
+ }
+
Graph gr = null ;
XStream xstream = new XStream( new DomDriver() ) ;
try {
- gr = (Graph) xstream.fromXML( new FileInputStream( _file ) ) ;
+ gr = (Graph) xstream.fromXML( new FileInputStream( path ) ) ;
} catch( FileNotFoundException e ) {
System.err.println( "File not found !\n" ) ;
e.printStackTrace();
return null ;
} catch( ClassCastException e ) {
- System.err.println( "The file does not contain a Graph" ) ;
+ System.err.println( "The file does not contain a valid Graph" ) ;
e.printStackTrace() ;
return null ;
}
/**
* Read a Grid graph from a file.
* @param _file File's name
+ * @param _path File's path
* @return The Grid graph read
*/
- public static Grid readGrid( String _file )
- {
- if ( _file.equals( "" ) || ! _file.endsWith( ".xml" ) )
+ public static Grid readGrid( String _path, String _file )
+ {
+ if ( _file.equals( "" ) )
{
- System.err.println( "Bad file !\n" ) ;
+ System.err.println( "No file's name !\n" ) ;
return null ;
}
+ if ( ! _file.endsWith( ".xml" ) )
+ {
+ _file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier
+ }
+
+ String path = "" ;
+
+ if( _path.length() != 0 )
+ {
+ path = _path+"/"+_file ;
+ } else {
+ path = new String( "./" + _file ) ;
+ }
+
Grid gr = null ;
XStream xstream = new XStream( new DomDriver() ) ;
try {
- gr = (Grid) xstream.fromXML( new FileInputStream( _file ) ) ;
+ gr = (Grid) xstream.fromXML( new FileInputStream( path ) ) ;
} catch( FileNotFoundException e ) {
System.err.println( "File not found !\n" ) ;
e.printStackTrace();
return null ;
} catch( ClassCastException e ) {
- System.err.println( "The file does not contain a Grid" ) ;
+ System.err.println( "The file does not contain a valid Grid" ) ;
e.printStackTrace() ;
return null ;
}