이 코드 샘플은 Protobuf 텍스트 형식으로 저장된 검사 결과에서 세부정보를 추출하는 방법을 보여줍니다. 검사 결과를 Cloud Storage에 저장한 경우 이 작업을 실행하세요.
이 예에서는 내보낸 SaveToGcsFindingsOutput 객체를 사람이 읽을 수 있는 형식으로 변환합니다. 그런 다음 출력을 사용하여 개별 검사 결과를 분석할 수 있습니다.
Sensitive Data Protection에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
importcom.google.privacy.dlp.v2.Finding;importcom.google.privacy.dlp.v2.SaveToGcsFindingsOutput;importcom.google.protobuf.ByteString;importcom.google.protobuf.TextFormat;importjava.io.FileInputStream;importjava.io.IOException;importjava.io.InputStreamReader;importjava.io.Reader;importjava.nio.charset.StandardCharsets;publicclassProcessInspectFindingsSavedToGcs{publicstaticvoidmain(String[]args)throwsException{// TODO(developer): Replace these variables before running the sample.StringinputPath="src/test/resources/save_to_gcs_findings.txt";processFindingsGcsFile(inputPath);}// Processes a file containing findings from a DLP inspect job.publicstaticvoidprocessFindingsGcsFile(StringinputPath)throwsIOException{SaveToGcsFindingsOutput.Builderbuilder=SaveToGcsFindingsOutput.newBuilder();try(Readerreader=newInputStreamReader(newFileInputStream(inputPath),StandardCharsets.UTF_8)){TextFormat.merge(reader,builder);}SaveToGcsFindingsOutputoutput=builder.build();// Parse the converted proto and process resultsSystem.out.println("Findings: "+output.getFindingsCount());for(Findingf:output.getFindingsList()){System.out.println("\tInfo type: "+f.getInfoType().getName());System.out.println("\tLikelihood: "+f.getLikelihood());}}}