Skip to content

Commit 8d9d2b6

Browse files
committed
Clean up comments.
1 parent 77ed524 commit 8d9d2b6

File tree

4 files changed

+35
-50
lines changed

4 files changed

+35
-50
lines changed

dlp/src/main/java/dlp/snippets/InspectImageFile.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Google LLC
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,14 +38,15 @@ public class InspectImageFile {
3838
public static void inspectImageFile(String projectId, String filePath) {
3939
// String projectId = "my-project-id";
4040
// String filePath = "path/to/image.png";
41-
// String fileType = "IMAGE"
4241

43-
// Initialize client with try-with-resources for automatic cleanup of background resources
42+
// Initialize client that will be used to send requests. This client only needs to be created
43+
// once, and can be reused for multiple requests. After completing all of your requests, call
44+
// the "close" method on the client to safely clean up any remaining background resources.
4445
try (DlpServiceClient dlp = DlpServiceClient.create()) {
45-
// Set project for request
46+
// Specify the project used for request.
4647
ProjectName project = ProjectName.of(projectId);
4748

48-
// Set content for request
49+
// Specify the type and content to be inspected.
4950
ByteString fileBytes = ByteString.readFrom(new FileInputStream(filePath));
5051
ByteContentItem byteItem = ByteContentItem.newBuilder()
5152
.setType(BytesType.IMAGE)
@@ -55,38 +56,38 @@ public static void inspectImageFile(String projectId, String filePath) {
5556
.setByteItem(byteItem)
5657
.build();
5758

58-
// Set required InfoTypes for inspection config
59+
// Specify the type of info the inspection will look for.
5960
List<InfoType> infoTypes = new ArrayList<>();
6061
// See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types
6162
for (String typeName : new String[] {"PHONE_NUMBER", "EMAIL_ADDRESS", "CREDIT_CARD_NUMBER"}) {
6263
infoTypes.add(InfoType.newBuilder().setName(typeName).build());
6364
}
6465

65-
// Set the inspect configuration for request
66+
// Construct the configuration for the Inspect request.
6667
InspectConfig config = InspectConfig.newBuilder()
6768
.addAllInfoTypes(infoTypes)
6869
.setIncludeQuote(true)
6970
.build();
7071

71-
// Construct the request to be sent by the client
72+
// Construct the Inspect request to be sent by the client.
7273
InspectContentRequest request = InspectContentRequest.newBuilder()
7374
.setParent(project.toString())
7475
.setItem(item)
7576
.setInspectConfig(config)
7677
.build();
7778

78-
// Use the client to send the API request
79+
// Use the client to send the API request.
7980
InspectContentResponse response = dlp.inspectContent(request);
8081

81-
// Parse the response and process results
82+
// Parse the response and process results.
8283
System.out.println("Findings: " + response.getResult().getFindingsCount());
8384
for (Finding f : response.getResult().getFindingsList()) {
8485
System.out.println("\tQuote: " + f.getQuote());
8586
System.out.println("\tInfo type: " + f.getInfoType().getName());
8687
System.out.println("\tLikelihood: " + f.getLikelihood());
8788
}
8889
} catch (Exception e) {
89-
System.out.println("Error during inspectFile: \n" + e.toString());
90+
System.out.println("Error during inspectImageFile: \n" + e.toString());
9091
}
9192
}
9293
}

dlp/src/main/java/dlp/snippets/InspectString.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Google LLC
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,39 +38,41 @@ public static void inspectString(String projectId, String textToInspect) {
3838
// String projectId = "my-project-id";
3939
// String textToInspect = "My name is Gary and my email is [email protected]";
4040

41-
// Initialize client with try-with-resources for automatic cleanup of background resources
41+
// Initialize client that will be used to send requests. This client only needs to be created
42+
// once, and can be reused for multiple requests. After completing all of your requests, call
43+
// the "close" method on the client to safely clean up any remaining background resources.
4244
try (DlpServiceClient dlp = DlpServiceClient.create()) {
43-
// Set project for request
45+
// Specify the project used for request.
4446
ProjectName project = ProjectName.of(projectId);
4547

46-
// Set content for request
48+
// Specify the type and content to be inspected.
4749
ByteContentItem byteItem = ByteContentItem.newBuilder()
4850
.setType(BytesType.TEXT_UTF8)
4951
.setData(ByteString.copyFromUtf8(textToInspect))
5052
.build();
5153
ContentItem item = ContentItem.newBuilder().setByteItem(byteItem).build();
5254

53-
// Set required InfoTypes for inspection config
55+
// Specify the type of info the inspection will look for.
5456
List<InfoType> infoTypes = new ArrayList<>();
5557
// See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types
5658
for (String typeName : new String[] {"PHONE_NUMBER", "EMAIL_ADDRESS", "CREDIT_CARD_NUMBER"}) {
5759
infoTypes.add(InfoType.newBuilder().setName(typeName).build());
5860
}
5961

60-
// Set the inspect configuration for request
62+
// Construct the configuration for the Inspect request.
6163
InspectConfig config = InspectConfig.newBuilder()
6264
.addAllInfoTypes(infoTypes)
6365
.setIncludeQuote(true)
6466
.build();
6567

66-
// Construct request
68+
// Construct the Inspect request to be sent by the client.
6769
InspectContentRequest request = InspectContentRequest.newBuilder()
6870
.setParent(project.toString())
6971
.setItem(item)
7072
.setInspectConfig(config)
7173
.build();
7274

73-
// Use the client to send the API request
75+
// Use the client to send the API request.
7476
InspectContentResponse response = dlp.inspectContent(request);
7577

7678
// Parse the response and process results

dlp/src/main/java/dlp/snippets/InspectTextFile.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Google LLC
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,14 +38,15 @@ public class InspectTextFile {
3838
public static void inspectTextFile(String projectId, String filePath) {
3939
// String projectId = "my-project-id";
4040
// String filePath = "path/to/image.png";
41-
// String fileType = "IMAGE"
4241

43-
// Initialize client with try-with-resources for automatic cleanup of background resources
42+
// Initialize client that will be used to send requests. This client only needs to be created
43+
// once, and can be reused for multiple requests. After completing all of your requests, call
44+
// the "close" method on the client to safely clean up any remaining background resources.
4445
try (DlpServiceClient dlp = DlpServiceClient.create()) {
45-
// Set project for request
46+
// Specify the project used for request.
4647
ProjectName project = ProjectName.of(projectId);
4748

48-
// Set content for request
49+
// Specify the type and content to be inspected.
4950
ByteString fileBytes = ByteString.readFrom(new FileInputStream(filePath));
5051
ByteContentItem byteItem = ByteContentItem.newBuilder()
5152
.setType(BytesType.TEXT_UTF8)
@@ -55,27 +56,27 @@ public static void inspectTextFile(String projectId, String filePath) {
5556
.setByteItem(byteItem)
5657
.build();
5758

58-
// Set required InfoTypes for inspection config
59+
// Specify the type of info the inspection will look for.
5960
List<InfoType> infoTypes = new ArrayList<>();
6061
// See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types
6162
for (String typeName : new String[] {"PHONE_NUMBER", "EMAIL_ADDRESS", "CREDIT_CARD_NUMBER"}) {
6263
infoTypes.add(InfoType.newBuilder().setName(typeName).build());
6364
}
6465

65-
// Set the inspect configuration for request
66+
// Construct the configuration for the Inspect request.
6667
InspectConfig config = InspectConfig.newBuilder()
6768
.addAllInfoTypes(infoTypes)
6869
.setIncludeQuote(true)
6970
.build();
7071

71-
// Construct the request to be sent by the client
72+
// Construct the Inspect request to be sent by the client.
7273
InspectContentRequest request = InspectContentRequest.newBuilder()
7374
.setParent(project.toString())
7475
.setItem(item)
7576
.setInspectConfig(config)
7677
.build();
7778

78-
// Use the client to send the API request
79+
// Use the client to send the API request.
7980
InspectContentResponse response = dlp.inspectContent(request);
8081

8182
// Parse the response and process results

dlp/src/test/java/dlp/snippets/RedactTests.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Google LLC
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,30 +62,11 @@ public void tearDown() {
6262
}
6363

6464
@Test
65-
public void testInspectString() {
66-
InspectString.inspectString(PROJECT_ID, "I'm Gary and my email is [email protected]");
65+
public void testRedactImage() {
66+
RedactImageFile.redactImageFile(PROJECT_ID, "src/test/resources/test.png");
6767

6868
String output = bout.toString();
6969
assertThat(output, CoreMatchers.containsString("Info type: EMAIL_ADDRESS"));
7070
}
7171

72-
@Test
73-
public void textInspectTestFile() {
74-
InspectTextFile.inspectTextFile(PROJECT_ID, "src/test/resources/test.txt");
75-
76-
String output = bout.toString();
77-
assertThat(output, CoreMatchers.containsString("Info type: PHONE_NUMBER"));
78-
assertThat(output, CoreMatchers.containsString("Info type: EMAIL_ADDRESS"));
79-
}
80-
81-
82-
@Test
83-
public void testInspectImageFile() {
84-
InspectImageFile.inspectImageFile(PROJECT_ID, "src/test/resources/test.png");
85-
86-
String output = bout.toString();
87-
assertThat(output, CoreMatchers.containsString("Info type: PHONE_NUMBER"));
88-
assertThat(output, CoreMatchers.containsString("Info type: EMAIL_ADDRESS"));
89-
}
90-
9172
}

0 commit comments

Comments
 (0)