question: private byte [ ] decodePEM ( InputStream inStream , byte [ ] boundary_suffix ) throws IOException { int ch ; for ( int i = 1 ; i < PEM_BEGIN . length ; ++ i ) { if ( PEM_BEGIN [ i ] != ( ch = inStream . read ( ) ) ) { throw new IOException ( "Incorrect PEM encoding: '-----BEGIN" + ( ( boundary_suffix == null ) ? "" : new String ( boundary_suffix ) ) + "' is expected as opening delimiter boundary." ) ; } } if ( boundary_suffix == null ) { while ( ( ch = inStream . read ( ) ) != '\n' ) { if ( ch == - 1 ) { throw new IOException ( "Incorrect PEM encoding: EOF before content" ) ; } } } else { for ( int i = 0 ; i < boundary_suffix . length ; i ++ ) { if ( boundary_suffix [ i ] != inStream . read ( ) ) { throw new IOException ( "Incorrect PEM encoding: '-----BEGIN" + new String ( boundary_suffix ) + "' is expected as opening delimiter boundary." ) ; } } if ( ( ch = inStream . read ( ) ) == '\r' ) { ch = inStream . read ( ) ; } if ( ch != '\n' ) { throw new IOException ( "Incorrect PEM encoding: newline expected after " + "opening delimiter boundary" ) ; } } int size = 1024 ; byte [ ] buff = new byte [ size ] ; int index = 0 ; while ( ( ch = inStream . read ( ) ) != '-' ) { if ( ch == - 1 ) { throw new IOException ( "Incorrect Base64 encoding: EOF without closing delimiter" ) ; } buff [ index ++ ] = ( byte ) ch ; if ( index == size ) { byte [ ] newbuff = new byte [ size + 1024 ] ; System . arraycopy ( buff , 0 , newbuff , 0 , size ) ; buff = newbuff ; size += 1024 ; } } if ( buff [ index - 1 ] != '\n' ) { throw new IOException ( "Incorrect Base64 encoding: newline expected before " + "closing boundary delimiter" ) ; } for ( int i = 1 ; i < PEM_END . length ; ++ i ) { if ( PEM_END [ i ] != inStream . read ( ) ) { throw badEnd ( boundary_suffix ) ; } } if ( boundary_suffix == null ) { while ( ( ( ch = inStream . read ( ) ) != - 1 ) && ( ch != '\n' ) && ( ch != '\r' ) ) { } } else { for ( int i = 0 ; i < boundary_suffix . length ; i ++ ) { if ( boundary_suffix [ i ] != inStream . read ( ) ) { throw badEnd ( boundary_suffix ) ; } } } inStream . mark ( 1 ) ; while ( ( ( ch = inStream . read ( ) ) != - 1 ) && ( ch == '\n' || ch == '\r' ) ) { inStream . mark ( 1 ) ; } inStream . reset ( ) ; buff = Base64 . decode ( buff , index ) ; if ( buff == null ) { throw new IOException ( "Incorrect Base64 encoding" ) ; } return buff ; }
target:  Method retrieves the PEM encoded data from the stream and returns its decoded representation. Method checks correctness of PEM boundaries. It supposes that the first '-' of the opening boundary has already been read from the stream. So first of all it checks that the leading bytes are equal to "-----BEGIN" boundary prefix. Than if boundary_suffix is not null, it checks that next bytes equal to boundary_suffix + new line char[s] ([CR]LF). If boundary_suffix parameter is null, method supposes free suffix format and skips any bytes until the new line.<br> After the opening boundary has been read and checked, the method read Base64 encoded data until closing PEM boundary is not reached.<br> Than it checks closing boundary - it should start with new line + "-----END" + boundary_suffix. If boundary_suffix is null, any characters are skipped until the new line.<br> After this any trailing new line characters are skipped from the stream, Base64 encoding is decoded and returned.