protected void readFile ( ) throws IOException { String line ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ) { while ( ( line = reader . readLine ( ) ) != null ) { if ( line . contains ( BEGIN_MARKER ) ) { beginMarker = line . trim ( ) ; String endMarker = beginMarker . replace ( "BEGIN" , "END" ) ; derBytes = readBytes ( reader , endMarker ) ; return ; } } throw new IOException ( "Invalid PEM file: no begin marker" ) ; } }
Read the PEM file and save the DER encoded octet stream and begin marker .