Skip to content

Commit 661edfa

Browse files
authored
Updates for storage, translate, unittests, and video. (#994)
* Updated storage/cloud-client. * Updated storage/json-api * Updated storage/storage-transfer. * Updated translate/ * Updated unittests/ * Updated video/
1 parent 5e6760e commit 661edfa

File tree

48 files changed

+248
-227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+248
-227
lines changed

storage/cloud-client/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Getting Started with Cloud Storage and the Google Cloud Client libraries
22

3+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=storage/cloud-client/README.md">
4+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
36
[Google Cloud Storage][storage] is unified object storage for developers and enterprises, from live
47
data serving to data analytics/ML to data archival.
58
These sample Java applications demonstrate how to access the Cloud Storage API using

storage/cloud-client/pom.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
<artifactId>storage-google-cloud-samples</artifactId>
2020
<packaging>jar</packaging>
2121

22-
<!-- Parent defines config for testing & linting. -->
22+
<!--
23+
The parent pom defines common style checks and testing strategies for our samples.
24+
Removing or replacing it should not affect the execution of the samples in anyway.
25+
-->
2326
<parent>
24-
<artifactId>doc-samples</artifactId>
25-
<groupId>com.google.cloud</groupId>
26-
<version>1.0.0</version>
27-
<relativePath>../..</relativePath>
27+
<groupId>com.google.cloud.samples</groupId>
28+
<artifactId>shared-configuration</artifactId>
29+
<version>1.0.8</version>
2830
</parent>
2931

3032
<properties>

storage/cloud-client/src/main/java/com/example/storage/QuickstartSample.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
Copyright 2016, Google, Inc.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
2+
* Copyright 2015 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
package com.example.storage;
1818

storage/cloud-client/src/test/java/com/example/storage/QuickstartSampleIT.java

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
/*
2-
Copyright 2016, Google, Inc.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
2+
* Copyright 2015 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
package com.example.storage;
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

2121
import com.google.cloud.storage.Storage;
2222
import com.google.cloud.storage.StorageOptions;
23+
import java.io.ByteArrayOutputStream;
24+
import java.io.PrintStream;
25+
import java.util.UUID;
2326
import org.junit.After;
2427
import org.junit.Before;
2528
import org.junit.Test;
2629
import org.junit.runner.RunWith;
2730
import org.junit.runners.JUnit4;
2831

29-
import java.io.ByteArrayOutputStream;
30-
import java.io.PrintStream;
31-
import java.util.UUID;
32-
3332
/**
3433
* Tests for quickstart sample.
3534
*/

storage/json-api/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Google Cloud Storage (GCS) and the Google Java API Client library
22

3+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=storage/cloud-client/README.md">
4+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
36
Google Cloud Storage Service features a REST-based API that allows developers to store and access arbitrarily-large objects. These sample Java applications demonstrate how to access the Google Cloud Storage JSON API using the Google Java API Client Libraries. For more information, read the [Google Cloud Storage JSON API Overview][1].
47

58
## Quickstart

storage/json-api/pom.xml

+11-7
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
limitations under the License.
1515
-->
1616
<project>
17-
<parent>
18-
<artifactId>doc-samples</artifactId>
19-
<groupId>com.google.cloud</groupId>
20-
<version>1.0.0</version>
21-
<relativePath>../..</relativePath>
22-
</parent>
23-
2417
<modelVersion>4.0.0</modelVersion>
2518
<groupId>com.google.apis-samples</groupId>
2619
<artifactId>storage-json-api</artifactId>
2720
<version>1</version>
2821

22+
<!--
23+
The parent pom defines common style checks and testing strategies for our samples.
24+
Removing or replacing it should not affect the execution of the samples in anyway.
25+
-->
26+
<parent>
27+
<groupId>com.google.cloud.samples</groupId>
28+
<artifactId>shared-configuration</artifactId>
29+
<version>1.0.8</version>
30+
</parent>
31+
2932
<properties>
3033
<maven.compiler.target>1.8</maven.compiler.target>
3134
<maven.compiler.source>1.8</maven.compiler.source>
@@ -61,6 +64,7 @@
6164
<groupId>junit</groupId>
6265
<artifactId>junit</artifactId>
6366
<scope>test</scope>
67+
<version>4.12</version>
6468
</dependency>
6569
<dependency>
6670
<groupId>com.google.truth</groupId>

storage/json-api/src/main/java/CustomerSuppliedEncryptionKeysSamples.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.api.client.http.InputStreamContent;
2020
import com.google.api.services.storage.Storage;
2121
import com.google.api.services.storage.model.RewriteResponse;
22-
2322
import java.io.IOException;
2423
import java.io.InputStream;
2524

@@ -75,17 +74,18 @@ public static InputStream downloadObject(
7574
String base64CseKey,
7675
String base64CseKeyHash)
7776
throws Exception {
78-
Storage.Objects.Get getObject = storage.objects().get(bucketName, objectName);
79-
80-
// If you're using AppEngine, turn off setDirectDownloadEnabled:
81-
// getObject.getMediaHttpDownloader().setDirectDownloadEnabled(false);
8277

83-
// Now set the CSEK headers
78+
// Set the CSEK headers
8479
final HttpHeaders httpHeaders = new HttpHeaders();
8580
httpHeaders.set("x-goog-encryption-algorithm", "AES256");
8681
httpHeaders.set("x-goog-encryption-key", base64CseKey);
8782
httpHeaders.set("x-goog-encryption-key-sha256", base64CseKeyHash);
8883

84+
Storage.Objects.Get getObject = storage.objects().get(bucketName, objectName);
85+
86+
// If you're using AppEngine, turn off setDirectDownloadEnabled:
87+
// getObject.getMediaHttpDownloader().setDirectDownloadEnabled(false);
88+
8989
getObject.setRequestHeaders(httpHeaders);
9090

9191
try {
@@ -166,10 +166,8 @@ public static void rotateKey(
166166
String newBase64Key,
167167
String newBase64KeyHash)
168168
throws Exception {
169-
Storage.Objects.Rewrite rewriteObject =
170-
storage.objects().rewrite(bucketName, objectName, bucketName, objectName, null);
171169

172-
// Now set the CSEK headers
170+
// Set the CSEK headers
173171
final HttpHeaders httpHeaders = new HttpHeaders();
174172

175173
// Specify the exiting object's current CSEK.
@@ -182,6 +180,9 @@ public static void rotateKey(
182180
httpHeaders.set("x-goog-encryption-key", newBase64Key);
183181
httpHeaders.set("x-goog-encryption-key-sha256", newBase64KeyHash);
184182

183+
Storage.Objects.Rewrite rewriteObject =
184+
storage.objects().rewrite(bucketName, objectName, bucketName, objectName, null);
185+
185186
rewriteObject.setRequestHeaders(httpHeaders);
186187

187188
try {

storage/json-api/src/main/java/StorageFactory.java

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.api.client.json.jackson2.JacksonFactory;
2222
import com.google.api.services.storage.Storage;
2323
import com.google.api.services.storage.StorageScopes;
24-
2524
import java.io.IOException;
2625
import java.security.GeneralSecurityException;
2726
import java.util.Collection;

storage/json-api/src/main/java/StorageSample.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
//[START all]
21
/*
3-
* Copyright (c) 2014 Google Inc.
2+
* Copyright 2014 Google Inc.
43
*
5-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6-
* in compliance with the License. You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
10-
* Unless required by applicable law or agreed to in writing, software distributed under the License
11-
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12-
* or implied. See the License for the specific language governing permissions and limitations under
13-
* the License.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1415
*/
1516

17+
//[START all]
18+
1619
import com.google.api.client.http.InputStreamContent;
1720
import com.google.api.services.storage.Storage;
1821
import com.google.api.services.storage.model.Bucket;
1922
import com.google.api.services.storage.model.ObjectAccessControl;
2023
import com.google.api.services.storage.model.Objects;
2124
import com.google.api.services.storage.model.StorageObject;
22-
2325
import java.io.File;
2426
import java.io.FileInputStream;
2527
import java.io.IOException;

storage/json-api/src/test/java/StorageSampleTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020

2121
import com.google.api.services.storage.model.Bucket;
2222
import com.google.api.services.storage.model.StorageObject;
23-
24-
import org.junit.Test;
25-
2623
import java.io.File;
2724
import java.nio.file.Files;
2825
import java.nio.file.Path;
2926
import java.util.List;
3027
import java.util.stream.Collectors;
28+
import org.junit.Test;
3129

3230
public class StorageSampleTest {
3331
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

storage/storage-transfer/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Transfer Service sample using Java
22

3+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=storage/storage-transfer/README.md">
4+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
36
This app creates two types of transfers using the Transfer Service tool.
47

58
<!-- auto-doc-link -->
69
These samples are used on the following documentation pages:
710

8-
>
11+
912
* https://cloud.google.com/storage/transfer/create-client
1013
* https://cloud.google.com/storage/transfer/create-manage-transfer-program
1114

storage/storage-transfer/pom.xml

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@
1818
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1919
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2020
<modelVersion>4.0.0</modelVersion>
21-
<parent>
22-
<artifactId>doc-samples</artifactId>
23-
<groupId>com.google.cloud</groupId>
24-
<version>1.0.0</version>
25-
<relativePath>../..</relativePath>
26-
</parent>
2721

2822
<groupId>com.google.storagetransfer.samples</groupId>
2923
<artifactId>storage-transfersample</artifactId>
3024
<version>0.1</version>
3125
<packaging>jar</packaging>
26+
<!--
27+
The parent pom defines common style checks and testing strategies for our samples.
28+
Removing or replacing it should not affect the execution of the samples in anyway.
29+
-->
30+
<parent>
31+
<groupId>com.google.cloud.samples</groupId>
32+
<artifactId>shared-configuration</artifactId>
33+
<version>1.0.8</version>
34+
</parent>
3235

3336
<properties>
37+
<maven.compiler.target>1.8</maven.compiler.target>
38+
<maven.compiler.source>1.8</maven.compiler.source>
3439
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3540
</properties>
3641

storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/AwsRequester.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
// [START all]
18+
1719
package com.google.cloud.storage.storagetransfer.samples;
1820

1921
import com.google.api.services.storagetransfer.v1.Storagetransfer;
@@ -25,7 +27,6 @@
2527
import com.google.api.services.storagetransfer.v1.model.TimeOfDay;
2628
import com.google.api.services.storagetransfer.v1.model.TransferJob;
2729
import com.google.api.services.storagetransfer.v1.model.TransferSpec;
28-
2930
import java.io.IOException;
3031
import java.io.PrintStream;
3132

storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/NearlineRequester.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
// [START all]
18+
1719
package com.google.cloud.storage.storagetransfer.samples;
1820

1921
import com.google.api.services.storagetransfer.v1.Storagetransfer;
@@ -25,7 +27,6 @@
2527
import com.google.api.services.storagetransfer.v1.model.TransferJob;
2628
import com.google.api.services.storagetransfer.v1.model.TransferOptions;
2729
import com.google.api.services.storagetransfer.v1.model.TransferSpec;
28-
2930
import java.io.IOException;
3031
import java.io.PrintStream;
3132

storage/storage-transfer/src/main/java/com/google/cloud/storage/storagetransfer/samples/RequestChecker.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2015 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,12 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
// [START all]
18+
1719
package com.google.cloud.storage.storagetransfer.samples;
1820

1921
import com.google.api.services.storagetransfer.v1.Storagetransfer;
2022
import com.google.api.services.storagetransfer.v1.model.ListOperationsResponse;
21-
2223
import java.io.IOException;
2324
import java.util.logging.Logger;
2425

0 commit comments

Comments
 (0)