code: 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");
          }
      }
docs: Read the PEM file and save the DER encoded octet
  stream and begin marker.
  
  @throws IOException