Java Reference
In-Depth Information
} catch ( IOException ex ) {
System . err . println ( ex );
} finally { // dispose
if ( socket != null ) {
try {
socket . close ();
} catch ( IOException ex ) {
// ignore
}
}
}
}
static void define ( String word , Writer writer , BufferedReader reader )
throws IOException , UnsupportedEncodingException {
writer . write ( "DEFINE eng-lat " + word + "\r\n" );
writer . flush ();
for ( String line = reader . readLine (); line != null ; line = reader . readLine ()) {
if ( line . startsWith ( "250 " )) { // OK
return ;
} else if ( line . startsWith ( "552 " )) { // no match
System . out . println ( "No definition found for " + word );
return ;
}
else if ( line . matches ( "\\d\\d\\d .*" )) continue ;
else if ( line . trim (). equals ( "." )) continue ;
else System . out . println ( line );
}
}
}
Here's a sample run:
$ java DictClient gold uranium silver copper lead
gold [gould]
aurarius; aureus; chryseus
aurum; chrysos
No definition found for uranium
silver [silv ə r]
argenteus
argentum
copper [k ɔ p ə r]
æneus; aheneus; ærarius; chalceus
æs
lead [led]
ducere
molybdus; plumbum
Search WWH ::




Custom Search