Cloud Data Loss Prevention (Cloud DLP) is now a part of Sensitive Data Protection. The API name remains the same: Cloud Data Loss Prevention API (DLP API). For information about the services that make up Sensitive Data Protection, see Sensitive Data Protection overview.
Stay organized with collections
Save and categorize content based on your preferences.
This code sample shows how to extract details from inspection findings that are
saved in Protobuf text format. Do this task if you saved your inspection
findings to
Cloud Storage.
This example converts the exported
SaveToGcsFindingsOutput object
into a human-readable format. You can then use the output to analyze individual
inspection findings.
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());}}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[],[],null,["# Parse findings stored as Protobuf text\n\nThis code sample shows how to extract details from inspection findings that are\nsaved in Protobuf text format. Do this task if you [saved your inspection\nfindings to\nCloud Storage](/sensitive-data-protection/concepts-actions#save-findings-cloud-storage).\nThis example converts the exported\n[`SaveToGcsFindingsOutput`](/sensitive-data-protection/docs/reference/rest/v2/SaveToGcsFindingsOutput) object\ninto a human-readable format. You can then use the output to analyze individual\ninspection findings. \n\n### Java\n\n\nTo learn how to install and use the client library for Sensitive Data Protection, see\n[Sensitive Data Protection client libraries](/sensitive-data-protection/docs/libraries).\n\n\nTo authenticate to Sensitive Data Protection, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.privacy.dlp.v2.https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.Finding.html;\n import com.google.privacy.dlp.v2.https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.SaveToGcsFindingsOutput.html;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString.html;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.html;\n import java.io.FileInputStream;\n import java.io.IOException;\n import java.io.InputStreamReader;\n import java.io.Reader;\n import java.nio.charset.StandardCharsets;\n\n public class ProcessInspectFindingsSavedToGcs {\n\n public static void main(String[] args) throws Exception {\n // TODO(developer): Replace these variables before running the sample.\n String inputPath = \"src/test/resources/save_to_gcs_findings.txt\";\n processFindingsGcsFile(inputPath);\n }\n\n // Processes a file containing findings from a DLP inspect job.\n public static void processFindingsGcsFile(String inputPath)\n throws IOException {\n https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.SaveToGcsFindingsOutput.html.Builder builder = https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.SaveToGcsFindingsOutput.html.newBuilder();\n try (Reader reader =\n new InputStreamReader(new FileInputStream(inputPath), StandardCharsets.UTF_8)) {\n https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormat.html.merge(reader, builder);\n }\n https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.SaveToGcsFindingsOutput.html output = https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TextFormatParseInfoTree.html#com_google_protobuf_TextFormatParseInfoTree_builder__.build();\n\n // Parse the converted proto and process results\n System.out.println(\"Findings: \" + output.https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.SaveToGcsFindingsOutput.html#com_google_privacy_dlp_v2_SaveToGcsFindingsOutput_getFindingsCount__());\n for (https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.Finding.html f : output.https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.SaveToGcsFindingsOutput.html#com_google_privacy_dlp_v2_SaveToGcsFindingsOutput_getFindingsList__()) {\n System.out.println(\"\\tInfo type: \" + f.getInfoType().getName());\n System.out.println(\"\\tLikelihood: \" + f.getLikelihood());\n }\n }\n }"]]