@ Override public ProtoNetwork readProtoNetwork ( ProtoNetworkDescriptor protoNetworkDescriptor ) throws ProtoNetworkError { if ( ! BinaryProtoNetworkDescriptor . class . isAssignableFrom ( protoNetworkDescriptor . getClass ( ) ) ) { String err = "protoNetworkDescriptor cannot be of type " ; err = err . concat ( protoNetworkDescriptor . getClass ( ) . getName ( ) ) ; err = err . concat ( ", need type " ) ; err = err . concat ( BinaryProtoNetworkDescriptor . class . getName ( ) ) ; throw new InvalidArgument ( err ) ; } BinaryProtoNetworkDescriptor binaryProtoNetworkDescriptor = ( BinaryProtoNetworkDescriptor ) protoNetworkDescriptor ; File pn = binaryProtoNetworkDescriptor . getProtoNetwork ( ) ; ObjectInputStream ois = null ; try { ois = new ObjectInputStream ( new FileInputStream ( pn ) ) ; ProtoNetwork network = new ProtoNetwork ( ) ; network . readExternal ( ois ) ; return network ; } catch ( FileNotFoundException e ) { final String msg = "Cannot find binary proto-network for path" ; throw new ProtoNetworkError ( pn . getAbsolutePath ( ) , msg , e ) ; } catch ( IOException e ) { final String msg = "Cannot read binary proto-network for path" ; throw new ProtoNetworkError ( pn . getAbsolutePath ( ) , msg , e ) ; } catch ( ClassNotFoundException e ) { final String msg = "Cannot read proto-network for path" ; throw new ProtoNetworkError ( pn . getAbsolutePath ( ) , msg , e ) ; } finally { // clean up IO resources IOUtils . closeQuietly ( ois ) ; } }
Reads a proto network from a descriptor representing a binary file .